diff --git a/cuda_core/cuda/core/_stream.pxd b/cuda_core/cuda/core/_stream.pxd index 4a7d4510d1a..0c9a0ec0c93 100644 --- a/cuda_core/cuda/core/_stream.pxd +++ b/cuda_core/cuda/core/_stream.pxd @@ -37,13 +37,14 @@ cdef inline bint Stream_handle_is_default_token(cydriver.CUstream s) noexcept no These tokens carry no context of their own; they refer to whatever context is current, so nothing resolved from one may be cached on the object. + The NULL stream (handle 0) is such a token too. """ cdef uintptr_t h = s - return h == cydriver.CU_STREAM_LEGACY or h == cydriver.CU_STREAM_PER_THREAD + return h == 0 or h == cydriver.CU_STREAM_LEGACY or h == cydriver.CU_STREAM_PER_THREAD cdef inline bint Stream_is_default_token(Stream self) noexcept nogil: - """Return True when this stream is CU_STREAM_LEGACY or CU_STREAM_PER_THREAD.""" + """Return True when this stream is the NULL stream, CU_STREAM_LEGACY or CU_STREAM_PER_THREAD.""" return Stream_handle_is_default_token(as_cu(self._h_stream)) diff --git a/cuda_core/docs/source/release/1.3.0-notes.rst b/cuda_core/docs/source/release/1.3.0-notes.rst index a9c24a420ed..9d09d1c400c 100644 --- a/cuda_core/docs/source/release/1.3.0-notes.rst +++ b/cuda_core/docs/source/release/1.3.0-notes.rst @@ -347,6 +347,13 @@ Fixes and enhancements physical allocations. (`#2694 `__) +- A :class:`Stream` over the NULL stream (handle 0), such as + ``Stream.from_handle(0)``, no longer caches the first context and device it + observes. Like ``LEGACY_DEFAULT_STREAM`` and ``PER_THREAD_DEFAULT_STREAM`` + since 1.2.0, it now resolves ``Stream.context``, ``Stream.device``, + ``Stream.resources`` and ``Stream.record()`` against the current context. + (`#3242 `__) + Deprecations ------------ diff --git a/cuda_core/tests/test_green_context.py b/cuda_core/tests/test_green_context.py index a51e8e0bc2b..af2794721eb 100644 --- a/cuda_core/tests/test_green_context.py +++ b/cuda_core/tests/test_green_context.py @@ -15,6 +15,7 @@ ProgramOptions, SMResource, SMResourceOptions, + Stream, WorkqueueResource, WorkqueueResourceOptions, launch, @@ -560,6 +561,17 @@ def test_stream_and_event_track_green_context(self, green_ctx): stream.sync() event.sync() + @pytest.mark.agent_authored(model="claude-opus-5-5") + def test_null_stream_follows_current_context(self, init_cuda, green_ctx): + stream = Stream.from_handle(0) + assert stream.context == init_cuda.context + + with use_context(init_cuda, green_ctx): + assert stream.context == green_ctx + assert stream.record().context == green_ctx + + assert stream.context == init_cuda.context + @pytest.mark.agent_authored(model="gpt-5.6") def test_device_receiver_targets_stored_green_context(self, init_cuda, green_ctx): primary_ctx = init_cuda.context