Skip to content

Commit 0eede28

Browse files
committed
Check for both old versions of NVRTC and driver
1 parent c1c0c05 commit 0eede28

2 files changed

Lines changed: 48 additions & 10 deletions

File tree

cuda_core/cuda/core/experimental/_graph.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ def __init__(self, graph_builder_obj, stream_obj, is_stream_owner, conditional_g
144144
def close(self):
145145
if self.stream:
146146
if not self.is_join_required:
147-
capture_status, _, _, _, _ = handle_return(driver.cuStreamGetCaptureInfo(self.stream.handle))
147+
capture_status = handle_return(driver.cuStreamGetCaptureInfo(self.stream.handle))[0]
148148
if capture_status != driver.CUstreamCaptureStatus.CU_STREAM_CAPTURE_STATUS_NONE:
149149
# Note how this condition only occures for the primary graph builder
150150
# This is because calling cuStreamEndCapture streams that were split off of the primary
@@ -233,7 +233,7 @@ def begin_building(self, mode="global") -> GraphBuilder:
233233
@property
234234
def is_building(self) -> bool:
235235
"""Returns True if the graph builder is currently building."""
236-
capture_status, _, _, _, _ = handle_return(driver.cuStreamGetCaptureInfo(self._mnff.stream.handle))
236+
capture_status = handle_return(driver.cuStreamGetCaptureInfo(self._mnff.stream.handle))[0]
237237
if capture_status == driver.CUstreamCaptureStatus.CU_STREAM_CAPTURE_STATUS_NONE:
238238
return False
239239
elif capture_status == driver.CUstreamCaptureStatus.CU_STREAM_CAPTURE_STATUS_ACTIVE:
@@ -734,6 +734,12 @@ def launch_graph(parent_graph: GraphBuilder, child_graph: GraphBuilder):
734734
735735
"""
736736

737+
if _driver_ver < 12000 or _py_major_ver < 12:
738+
raise NotImplementedError(
739+
f"Launching child graphs is not implemented for versions older than CUDA 12."
740+
f"Found driver version is {_driver_ver} and binding major version is {_py_major_ver}"
741+
)
742+
737743
if not child_graph._building_ended:
738744
raise ValueError("Child graph has not finished building.")
739745

cuda_core/tests/test_graph.py

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
import numpy as np
66
import pytest
77

8+
try:
9+
from cuda.bindings import driver
10+
except ImportError:
11+
from cuda import cuda as driver
812
from cuda.core.experimental import (
913
CompleteOptions,
1014
DebugPrintOptions,
@@ -17,9 +21,22 @@
1721
launch_graph,
1822
)
1923
from cuda.core.experimental._memory import _DefaultPinnedMemorySource
24+
from cuda.core.experimental._utils.cuda_utils import NVRTCError, handle_return
2025

2126

2227
def _common_kernels():
28+
code = """
29+
__global__ void empty_kernel() {}
30+
__global__ void add_one(int *a) { *a += 1; }
31+
"""
32+
arch = "".join(f"{i}" for i in Device().compute_capability)
33+
program_options = ProgramOptions(std="c++17", arch=f"sm_{arch}")
34+
prog = Program(code, code_type="c++", options=program_options)
35+
mod = prog.compile("cubin", name_expressions=("empty_kernel", "add_one"))
36+
return mod
37+
38+
39+
def _common_kernels_conditional():
2340
code = """
2441
extern "C" __device__ __cudart_builtin__ void CUDARTAPI cudaGraphSetConditional(cudaGraphConditionalHandle handle,
2542
unsigned int value);
@@ -35,7 +52,13 @@ def _common_kernels():
3552
arch = "".join(f"{i}" for i in Device().compute_capability)
3653
program_options = ProgramOptions(std="c++17", arch=f"sm_{arch}")
3754
prog = Program(code, code_type="c++", options=program_options)
38-
mod = prog.compile("cubin", name_expressions=("empty_kernel", "add_one", "set_handle", "loop_kernel"))
55+
try:
56+
mod = prog.compile("cubin", name_expressions=("empty_kernel", "add_one", "set_handle", "loop_kernel"))
57+
except NVRTCError as e:
58+
with pytest.raises(RuntimeError, match='error: identifier "cudaGraphConditionalHandle" is undefined'):
59+
raise e
60+
nvrtcVersion = handle_return(driver.nvrtcVersion())
61+
pytest.skip(f"NVRTC version {nvrtcVersion} does not support conditionals")
3962
return mod
4063

4164

@@ -186,7 +209,7 @@ def test_graph_capture_errors(init_cuda):
186209
@pytest.mark.parametrize("condition_value", [True, False])
187210
@pytest.mark.skipif(tuple(int(i) for i in np.__version__.split(".")[:2]) < (2, 1), reason="need numpy 2.1.0+")
188211
def test_graph_conditional_if(init_cuda, condition_value):
189-
mod = _common_kernels()
212+
mod = _common_kernels_conditional()
190213
add_one = mod.get_kernel("add_one")
191214
set_handle = mod.get_kernel("set_handle")
192215

@@ -237,7 +260,7 @@ def test_graph_conditional_if(init_cuda, condition_value):
237260
@pytest.mark.parametrize("condition_value", [True, False])
238261
@pytest.mark.skipif(tuple(int(i) for i in np.__version__.split(".")[:2]) < (2, 1), reason="need numpy 2.1.0+")
239262
def test_graph_conditional_if_else(init_cuda, condition_value):
240-
mod = _common_kernels()
263+
mod = _common_kernels_conditional()
241264
add_one = mod.get_kernel("add_one")
242265
set_handle = mod.get_kernel("set_handle")
243266

@@ -304,7 +327,7 @@ def test_graph_conditional_if_else(init_cuda, condition_value):
304327
@pytest.mark.parametrize("condition_value", [0, 1, 2, 3])
305328
@pytest.mark.skipif(tuple(int(i) for i in np.__version__.split(".")[:2]) < (2, 1), reason="need numpy 2.1.0+")
306329
def test_graph_conditional_switch(init_cuda, condition_value):
307-
mod = _common_kernels()
330+
mod = _common_kernels_conditional()
308331
add_one = mod.get_kernel("add_one")
309332
set_handle = mod.get_kernel("set_handle")
310333

@@ -390,7 +413,7 @@ def test_graph_conditional_switch(init_cuda, condition_value):
390413
@pytest.mark.parametrize("condition_value", [True, False])
391414
@pytest.mark.skipif(tuple(int(i) for i in np.__version__.split(".")[:2]) < (2, 1), reason="need numpy 2.1.0+")
392415
def test_graph_conditional_while(init_cuda, condition_value):
393-
mod = _common_kernels()
416+
mod = _common_kernels_conditional()
394417
add_one = mod.get_kernel("add_one")
395418
loop_kernel = mod.get_kernel("loop_kernel")
396419
empty_kernel = mod.get_kernel("empty_kernel")
@@ -457,7 +480,16 @@ def test_graph_child_graph(init_cuda):
457480
launch(gb_parent, LaunchConfig(grid=1, block=1), add_one, arr.ctypes.data)
458481

459482
## Add child
460-
launch_graph(gb_parent, gb_child)
483+
try:
484+
launch_graph(gb_parent, gb_child)
485+
except NotImplementedError as e:
486+
with pytest.raises(
487+
NotImplementedError,
488+
match="^Launching child graphs is not implemented for versions older than CUDA 12. Found driver version is",
489+
):
490+
raise e
491+
gb_parent.end_building()
492+
pytest.skip("Launching child graphs is not implemented for versions older than CUDA 12")
461493

462494
launch(gb_parent, LaunchConfig(grid=1, block=1), add_one, arr.ctypes.data)
463495
graph = gb_parent.end_building().complete()
@@ -473,7 +505,7 @@ def test_graph_child_graph(init_cuda):
473505

474506
@pytest.mark.skipif(tuple(int(i) for i in np.__version__.split(".")[:2]) < (2, 1), reason="need numpy 2.1.0+")
475507
def test_graph_update(init_cuda):
476-
mod = _common_kernels()
508+
mod = _common_kernels_conditional()
477509
add_one = mod.get_kernel("add_one")
478510

479511
# Allocate memory
@@ -586,7 +618,7 @@ def test_graph_stream_lifetime(init_cuda):
586618

587619

588620
def test_graph_dot_print_options(init_cuda, tmp_path):
589-
mod = _common_kernels()
621+
mod = _common_kernels_conditional()
590622
set_handle = mod.get_kernel("set_handle")
591623
empty_kernel = mod.get_kernel("empty_kernel")
592624

0 commit comments

Comments
 (0)