Skip to content

Commit 4e71a1e

Browse files
committed
fix(cuda.core): break _stream/_device <-> graph._graph_builder import cycle
cimport-ing GraphBuilder at the top of _stream.pyx and _device.pyx made Cython emit a Python-level import of cuda.core.graph._graph_builder during _stream module init. That triggered the chain graph -> _graph_node -> _kernel_arg_handler -> _memory._buffer -> _device, which then re-entered the still-initializing _stream module via "from cuda.core._stream import IsStreamT", failing with ImportError: cannot import name IsStreamT. Restore the original lazy "import GraphBuilder" inside create_graph_builder (Stream and Device) and Stream_accept. The return annotations stay as bare names; "from __future__ import annotations" in both files defers their evaluation, so they need not resolve at function-definition time. Made-with: Cursor
1 parent ae974af commit 4e71a1e

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

cuda_core/cuda/core/_device.pyx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import threading
1414
from cuda.core._context cimport Context
1515
from cuda.core._context import ContextOptions
1616
from cuda.core._event cimport Event as cyEvent
17-
from cuda.core.graph._graph_builder cimport GraphBuilder
1817
from cuda.core._event import Event, EventOptions
1918
from cuda.core._memory._buffer cimport Buffer, MemoryResource
2019
from cuda.core._resource_handles cimport (
@@ -1371,6 +1370,8 @@ class Device:
13711370
Newly created graph builder object.
13721371

13731372
"""
1373+
from cuda.core.graph._graph_builder import GraphBuilder
1374+
13741375
self._check_context_initialized()
13751376
return GraphBuilder._init(self.create_stream())
13761377

cuda_core/cuda/core/_stream.pyx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ from libc.stdlib cimport strtol, getenv
1010
from cuda.bindings cimport cydriver
1111

1212
from cuda.core._event cimport Event as cyEvent
13-
from cuda.core.graph._graph_builder cimport GraphBuilder
1413
from cuda.core._utils.cuda_utils cimport (
1514
check_or_create_options,
1615
HANDLE_RETURN,
@@ -372,6 +371,8 @@ cdef class Stream:
372371
Newly created graph builder object.
373372

374373
"""
374+
from cuda.core.graph._graph_builder import GraphBuilder
375+
375376
return GraphBuilder._init(self)
376377

377378

@@ -473,6 +474,8 @@ cdef cydriver.CUstream _handle_from_stream_protocol(obj) except*:
473474
# Helper for API functions that accept either Stream or GraphBuilder. Performs
474475
# needed checks and returns the relevant stream.
475476
cdef Stream Stream_accept(arg, bint allow_stream_protocol=False):
477+
from cuda.core.graph._graph_builder import GraphBuilder
478+
476479
if isinstance(arg, Stream):
477480
return <Stream>(arg)
478481
elif isinstance(arg, GraphBuilder):

0 commit comments

Comments
 (0)