Skip to content

Commit a93ea03

Browse files
cuda.core: import graph submodule after extension modules to avoid circular load
Importing cuda.core.graph from the top of cuda/core/__init__.py triggers a load of cuda.core.graph._graph_builder, which cimports cuda.core._stream and other extensions. While cuda.core itself is still initializing, those circular loads leave the graph submodules partially initialized when `from ._graph_builder import *` runs in cuda/core/graph/__init__.py, and Graph, GraphBuilder, GraphCompleteOptions, and GraphDebugPrintOptions silently fail to surface on cuda.core.graph. Defer `import cuda.core.graph` until after every cuda.core._* extension has been loaded so the inner `from ._graph_builder import *` finds a fully initialized module. The standalone `import` form (rather than `from cuda.core import graph`) keeps it from being collapsed back into the checkpoint/system/utils block by ruff's import sorter; an `# isort: split` marker pins the placement. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent cebc75b commit a93ea03

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

cuda_core/cuda/core/__init__.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def _import_versioned_module():
2828
del _import_versioned_module
2929

3030

31-
from cuda.core import checkpoint, graph, system, utils
31+
from cuda.core import checkpoint, system, utils
3232
from cuda.core._context import Context, ContextOptions
3333
from cuda.core._device import Device
3434
from cuda.core._device_resources import (
@@ -66,3 +66,10 @@ def _import_versioned_module():
6666
StreamOptions,
6767
)
6868
from cuda.core._tensor_map import TensorMapDescriptor, TensorMapDescriptorOptions
69+
70+
# isort: split
71+
# Must come after the cuda.core._* extension imports above: loading graph
72+
# earlier interacts badly with the merged-wheel __path__ rewrite and leaves
73+
# Graph/GraphBuilder/GraphCompleteOptions/GraphDebugPrintOptions missing from
74+
# cuda.core.graph.
75+
import cuda.core.graph

0 commit comments

Comments
 (0)