Skip to content

Commit 04586be

Browse files
committed
Revert "feat: Make legacy_default and per_thread_default public - Fixes NVIDIA#1445"
This reverts commit 61b5de2.
1 parent ff9b8af commit 04586be

2 files changed

Lines changed: 10 additions & 119 deletions

File tree

‎cuda_core/cuda/core/_stream.pyx‎

Lines changed: 8 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -107,91 +107,14 @@ cdef class Stream:
107107
return s
108108

109109
@classmethod
110-
def legacy_default(cls):
111-
"""Return the legacy default stream.
112-
113-
The legacy default stream is an implicit stream which synchronizes
114-
with all other streams in the same CUDA context except for non-blocking
115-
streams. When any operation is launched on the legacy default stream,
116-
it waits for all previously launched operations in blocking streams to
117-
complete, and all subsequent operations in blocking streams wait for
118-
the legacy default stream operation to complete.
119-
120-
This stream is useful for ensuring strict ordering of operations but
121-
may limit concurrency. For better performance in concurrent scenarios,
122-
consider using per_thread_default() or creating explicit streams.
123-
124-
This method returns the same singleton instance on every call for the
125-
base Stream class. Subclasses will receive new instances of the subclass
126-
type that wrap the same underlying CUDA stream.
127-
128-
Returns
129-
-------
130-
Stream
131-
The legacy default stream singleton instance for the current context.
132-
133-
See Also
134-
--------
135-
per_thread_default : Per-thread default stream alternative.
136-
from_handle : Create stream from existing handle.
137-
138-
Examples
139-
--------
140-
>>> from cuda.core import Stream
141-
>>> stream1 = Stream.legacy_default()
142-
>>> stream2 = Stream.legacy_default()
143-
>>> stream1 is stream2 # True - returns same singleton
144-
True
145-
"""
146-
# Return the singleton for the base Stream class
147-
if cls is Stream:
148-
return C_LEGACY_DEFAULT_STREAM
149-
# For subclasses, create a new instance of the subclass type
150-
else:
151-
return Stream._from_handle(cls, get_legacy_stream())
110+
def _legacy_default(cls):
111+
"""Return the legacy default stream (supports subclassing)."""
112+
return Stream._from_handle(cls, get_legacy_stream())
152113

153114
@classmethod
154-
def per_thread_default(cls):
155-
"""Return the per-thread default stream.
156-
157-
The per-thread default stream is local to both the calling thread and
158-
the CUDA context. Unlike the legacy default stream, it does not
159-
synchronize with other streams and behaves like an explicitly created
160-
non-blocking stream. This allows for better concurrency in multi-threaded
161-
applications.
162-
163-
Each thread has its own per-thread default stream, enabling true
164-
concurrent execution without implicit synchronization barriers.
165-
166-
This method returns the same singleton instance on every call for the
167-
base Stream class. Subclasses will receive new instances of the subclass
168-
type that wrap the same underlying CUDA stream.
169-
170-
Returns
171-
-------
172-
Stream
173-
The per-thread default stream singleton instance for the current
174-
thread and context.
175-
176-
See Also
177-
--------
178-
legacy_default : Legacy default stream alternative.
179-
from_handle : Create stream from existing handle.
180-
181-
Examples
182-
--------
183-
>>> from cuda.core import Stream
184-
>>> stream1 = Stream.per_thread_default()
185-
>>> stream2 = Stream.per_thread_default()
186-
>>> stream1 is stream2 # True - returns same singleton
187-
True
188-
"""
189-
# Return the singleton for the base Stream class
190-
if cls is Stream:
191-
return C_PER_THREAD_DEFAULT_STREAM
192-
# For subclasses, create a new instance of the subclass type
193-
else:
194-
return Stream._from_handle(cls, get_per_thread_stream())
115+
def _per_thread_default(cls):
116+
"""Return the per-thread default stream (supports subclassing)."""
117+
return Stream._from_handle(cls, get_per_thread_stream())
195118

196119
@classmethod
197120
def _init(cls, obj: IsStreamT | None = None, options=None, device_id: int = None,
@@ -455,8 +378,8 @@ cdef class Stream:
455378

456379

457380
# c-only python objects, not public
458-
cdef Stream C_LEGACY_DEFAULT_STREAM = Stream._from_handle(Stream, get_legacy_stream())
459-
cdef Stream C_PER_THREAD_DEFAULT_STREAM = Stream._from_handle(Stream, get_per_thread_stream())
381+
cdef Stream C_LEGACY_DEFAULT_STREAM = Stream._legacy_default()
382+
cdef Stream C_PER_THREAD_DEFAULT_STREAM = Stream._per_thread_default()
460383

461384
# standard python objects, public
462385
LEGACY_DEFAULT_STREAM = C_LEGACY_DEFAULT_STREAM

‎cuda_core/tests/test_stream.py‎

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -117,50 +117,18 @@ def test_stream_legacy_default_subclassing():
117117
class MyStream(Stream):
118118
pass
119119

120-
stream = MyStream.legacy_default()
120+
stream = MyStream._legacy_default()
121121
assert isinstance(stream, MyStream)
122122

123123

124124
def test_stream_per_thread_default_subclassing():
125125
class MyStream(Stream):
126126
pass
127127

128-
stream = MyStream.per_thread_default()
128+
stream = MyStream._per_thread_default()
129129
assert isinstance(stream, MyStream)
130130

131131

132-
def test_stream_legacy_default_public_api(init_cuda):
133-
"""Test public legacy_default() method returns singleton."""
134-
stream1 = Stream.legacy_default()
135-
stream2 = Stream.legacy_default()
136-
137-
assert isinstance(stream1, Stream)
138-
assert isinstance(stream2, Stream)
139-
140-
# Verify singleton behavior - same Python object
141-
assert stream1 is stream2, "Should return same singleton instance"
142-
143-
# Verify it's the same as the module constant
144-
assert stream1 is LEGACY_DEFAULT_STREAM, "Should be the same object as LEGACY_DEFAULT_STREAM"
145-
assert stream2 is LEGACY_DEFAULT_STREAM, "Should be the same object as LEGACY_DEFAULT_STREAM"
146-
147-
148-
def test_stream_per_thread_default_public_api(init_cuda):
149-
"""Test public per_thread_default() method returns singleton."""
150-
stream1 = Stream.per_thread_default()
151-
stream2 = Stream.per_thread_default()
152-
153-
assert isinstance(stream1, Stream)
154-
assert isinstance(stream2, Stream)
155-
156-
# Verify singleton behavior - same Python object
157-
assert stream1 is stream2, "Should return same singleton instance"
158-
159-
# Verify it's the same as the module constant
160-
assert stream1 is PER_THREAD_DEFAULT_STREAM, "Should be the same object as PER_THREAD_DEFAULT_STREAM"
161-
assert stream2 is PER_THREAD_DEFAULT_STREAM, "Should be the same object as PER_THREAD_DEFAULT_STREAM"
162-
163-
164132
# ============================================================================
165133
# Stream Equality Tests
166134
# ============================================================================

0 commit comments

Comments
 (0)