Skip to content

Commit 668a8ce

Browse files
committed
launch_graph -> gb.add_child
1 parent 812bcbe commit 668a8ce

3 files changed

Lines changed: 40 additions & 46 deletions

File tree

cuda_core/cuda/core/experimental/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
GraphBuilder,
1111
GraphCompleteOptions,
1212
GraphDebugPrintOptions,
13-
launch_graph,
1413
)
1514
from cuda.core.experimental._launch_config import LaunchConfig
1615
from cuda.core.experimental._launcher import launch

cuda_core/cuda/core/experimental/_graph.py

Lines changed: 39 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,45 @@ def close(self):
654654
"""
655655
self._mnff.close()
656656

657+
def add_child(self, child_graph: GraphBuilder):
658+
"""Adds the child :obj:`~_graph.GraphBuilder` builder into self.
659+
660+
The child graph builder will be added as a child node to the parent graph builder.
661+
662+
Parameters
663+
----------
664+
child_graph : :obj:`~_graph.GraphBuilder`
665+
The child graph builder. Must have finished building.
666+
"""
667+
if (_driver_ver < 12000) or (_py_major_minor < (12, 0)):
668+
raise NotImplementedError(
669+
f"Launching child graphs is not implemented for versions older than CUDA 12."
670+
f"Found driver version is {_driver_ver} and binding version is {_py_major_minor}"
671+
)
672+
673+
if not child_graph._building_ended:
674+
raise ValueError("Child graph has not finished building.")
675+
676+
if not self.is_building:
677+
raise ValueError("Parent graph is being built.")
678+
679+
stream_handle = self._mnff.stream.handle
680+
_, _, graph_out, dependencies_out, num_dependencies_out = handle_return(
681+
driver.cuStreamGetCaptureInfo(stream_handle)
682+
)
683+
684+
child_node = handle_return(
685+
driver.cuGraphAddChildGraphNode(graph_out, dependencies_out, num_dependencies_out, child_graph._mnff.graph)
686+
)
687+
handle_return(
688+
driver.cuStreamUpdateCaptureDependencies(
689+
stream_handle,
690+
[child_node],
691+
1,
692+
driver.CUstreamUpdateCaptureDependencies_flags.CU_STREAM_SET_CAPTURE_DEPENDENCIES,
693+
)
694+
)
695+
657696

658697
class Graph:
659698
"""Represents an executable graph.
@@ -733,46 +772,3 @@ def launch(self, stream: Stream):
733772
734773
"""
735774
handle_return(driver.cuGraphLaunch(self._mnff.graph, stream.handle))
736-
737-
738-
def launch_graph(parent_graph: GraphBuilder, child_graph: GraphBuilder):
739-
"""Adds the child :obj:`~_graph.GraphBuilder` builder into parent graph builder.
740-
741-
The child graph builder will be added as a child node to the parent graph builder.
742-
743-
Parameters
744-
----------
745-
parent_graph : :obj:`~_graph.GraphBuilder`
746-
The parent graph builder. Must be in building state.
747-
child_graph : :obj:`~_graph.GraphBuilder`
748-
The child graph builder. Must have finished building.
749-
750-
"""
751-
752-
if (_driver_ver < 12000) or (_py_major_minor < (12, 0)):
753-
raise NotImplementedError(
754-
f"Launching child graphs is not implemented for versions older than CUDA 12."
755-
f"Found driver version is {_driver_ver} and binding version is {_py_major_minor}"
756-
)
757-
758-
if not child_graph._building_ended:
759-
raise ValueError("Child graph has not finished building.")
760-
761-
if not parent_graph.is_building:
762-
raise ValueError("Parent graph is being built.")
763-
764-
_, _, graph_out, dependencies_out, num_dependencies_out = handle_return(
765-
driver.cuStreamGetCaptureInfo(parent_graph.stream.handle)
766-
)
767-
768-
child_node = handle_return(
769-
driver.cuGraphAddChildGraphNode(graph_out, dependencies_out, num_dependencies_out, child_graph._mnff.graph)
770-
)
771-
handle_return(
772-
driver.cuStreamUpdateCaptureDependencies(
773-
parent_graph.stream.handle,
774-
[child_node],
775-
1,
776-
driver.CUstreamUpdateCaptureDependencies_flags.CU_STREAM_SET_CAPTURE_DEPENDENCIES,
777-
)
778-
)

cuda_core/tests/test_graph.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
Program,
1919
ProgramOptions,
2020
launch,
21-
launch_graph,
2221
)
2322
from cuda.core.experimental._memory import _DefaultPinnedMemorySource
2423
from cuda.core.experimental._utils.cuda_utils import NVRTCError, handle_return
@@ -517,7 +516,7 @@ def test_graph_child_graph(init_cuda):
517516

518517
## Add child
519518
try:
520-
launch_graph(gb_parent, gb_child)
519+
gb_parent.add_child(gb_child)
521520
except NotImplementedError as e:
522521
with pytest.raises(
523522
NotImplementedError,

0 commit comments

Comments
 (0)