Skip to content

Commit d975a66

Browse files
committed
Fix recursive is building check
1 parent 0eede28 commit d975a66

2 files changed

Lines changed: 20 additions & 7 deletions

File tree

cuda_core/cuda/core/experimental/_graph.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,9 +239,8 @@ def is_building(self) -> bool:
239239
elif capture_status == driver.CUstreamCaptureStatus.CU_STREAM_CAPTURE_STATUS_ACTIVE:
240240
return True
241241
elif capture_status == driver.CUstreamCaptureStatus.CU_STREAM_CAPTURE_STATUS_INVALIDATED:
242-
self.end_building()
243242
raise RuntimeError(
244-
"Build process encountered an error and has been invalidated. Build process has been ended."
243+
"Build process encountered an error and has been invalidated. Build process must now be ended."
245244
)
246245
else:
247246
raise NotImplementedError(f"Unsupported capture status type received: {capture_status}")
@@ -277,6 +276,14 @@ def complete(self, options: Optional[CompleteOptions] = None) -> Graph:
277276
if not self._building_ended:
278277
raise RuntimeError("Graph has not finished building.")
279278

279+
if _driver_ver < 12000:
280+
flags = 0
281+
if options.auto_free_on_launch:
282+
flags |= driver.CUgraphInstantiate_flags.CUDA_GRAPH_INSTANTIATE_FLAG_AUTO_FREE_ON_LAUNCH
283+
if options.use_node_priority:
284+
flags |= driver.CUgraphInstantiate_flags.CUDA_GRAPH_INSTANTIATE_FLAG_USE_NODE_PRIORITY
285+
graph = Graph._init(handle_return(driver.cuGraphInstantiateWithFlags(self._mnff.graph, flags)))
286+
280287
params = driver.CUDA_GRAPH_INSTANTIATE_PARAMS()
281288
if options:
282289
flags = 0

cuda_core/tests/test_graph.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,13 @@ def test_graph_conditional_if(init_cuda, condition_value):
225225
gb = Device().create_graph_builder().begin_building()
226226

227227
# Add Node A (sets condition)
228-
handle = gb.create_conditional_handle()
228+
try:
229+
handle = gb.create_conditional_handle()
230+
except RuntimeError as e:
231+
with pytest.raises(RuntimeError, match="^Driver version \d+ does not support conditional handles"):
232+
raise e
233+
gb.end_building()
234+
pytest.skip("Driver does not support conditional handle")
229235
launch(gb, LaunchConfig(grid=1, block=1), set_handle, handle, condition_value)
230236

231237
# # Add Node B (if condition)
@@ -283,7 +289,7 @@ def test_graph_conditional_if_else(init_cuda, condition_value):
283289
try:
284290
gb_if, gb_else = gb.if_else(handle)
285291
except RuntimeError as e:
286-
with pytest.raises(RuntimeError, match="does not support conditional"):
292+
with pytest.raises(RuntimeError, match="^Driver version \d+ does not support conditional if-else"):
287293
raise e
288294
gb.end_building()
289295
pytest.skip("Driver does not support conditional if-else")
@@ -351,7 +357,7 @@ def test_graph_conditional_switch(init_cuda, condition_value):
351357
try:
352358
gb_case = list(gb.switch(handle, 3))
353359
except RuntimeError as e:
354-
with pytest.raises(RuntimeError, match="does not support conditional"):
360+
with pytest.raises(RuntimeError, match="^Driver version \d+ does not support conditional switch"):
355361
raise e
356362
gb.end_building()
357363
pytest.skip("Driver does not support conditional switch")
@@ -485,7 +491,7 @@ def test_graph_child_graph(init_cuda):
485491
except NotImplementedError as e:
486492
with pytest.raises(
487493
NotImplementedError,
488-
match="^Launching child graphs is not implemented for versions older than CUDA 12. Found driver version is",
494+
match="^Launching child graphs is not implemented for versions older than CUDA 12",
489495
):
490496
raise e
491497
gb_parent.end_building()
@@ -528,7 +534,7 @@ def build_graph(condition_value):
528534
try:
529535
gb_case = list(gb.switch(handle, 3))
530536
except RuntimeError as e:
531-
with pytest.raises(RuntimeError, match="does not support conditional"):
537+
with pytest.raises(RuntimeError, match="^Driver version \d+ does not support conditional switch"):
532538
raise e
533539
gb.end_building()
534540
pytest.skip("Driver does not support conditional switch")

0 commit comments

Comments
 (0)