Skip to content

Commit 8c9a466

Browse files
committed
feat: Make legacy_default and per_thread_default public - Fixes NVIDIA#1445
Signed-off-by: Monishver Chandrasekaran <[email protected]>
1 parent 61b5de2 commit 8c9a466

2 files changed

Lines changed: 24 additions & 26 deletions

File tree

‎cuda_core/cuda/core/_stream.pyx‎

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -109,54 +109,46 @@ cdef class Stream:
109109
@classmethod
110110
def legacy_default(cls):
111111
"""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
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
118118
the legacy default stream operation to complete.
119-
119+
120120
Returns
121121
-------
122122
Stream
123123
The legacy default stream instance for the current context.
124-
124+
125125
See Also
126126
--------
127127
per_thread_default : Per-thread default stream alternative.
128-
129-
Examples
130-
--------
131-
>>> stream = Stream.legacy_default()
132-
>>> stream.sync() # Synchronize all operations
128+
133129
"""
134130
return Stream._from_handle(cls, get_legacy_stream())
135131

136132
@classmethod
137133
def per_thread_default(cls):
138134
"""Return the per-thread default stream.
139-
140-
The per-thread default stream is local to both the calling thread and
141-
the CUDA context. Unlike the legacy default stream, it does not
142-
synchronize with other streams and behaves like an explicitly created
143-
non-blocking stream. This allows for better concurrency in multi-threaded
135+
136+
The per-thread default stream is local to both the calling thread and
137+
the CUDA context. Unlike the legacy default stream, it does not
138+
synchronize with other streams and behaves like an explicitly created
139+
non-blocking stream. This allows for better concurrency in multi-threaded
144140
applications.
145-
141+
146142
Returns
147143
-------
148144
Stream
149-
The per-thread default stream instance for the current thread
145+
The per-thread default stream instance for the current thread
150146
and context.
151-
147+
152148
See Also
153149
--------
154150
legacy_default : Legacy default stream alternative.
155-
156-
Examples
157-
--------
158-
>>> stream = Stream.per_thread_default()
159-
>>> stream.sync() # Synchronize only this thread's operations
151+
160152
"""
161153
return Stream._from_handle(cls, get_per_thread_stream())
162154

‎cuda_core/tests/test_stream.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,29 +116,35 @@ class MyStream(Stream):
116116
def test_stream_legacy_default_subclassing():
117117
class MyStream(Stream):
118118
pass
119+
119120
stream = MyStream.legacy_default()
120121
assert isinstance(stream, MyStream)
121122

123+
122124
def test_stream_per_thread_default_subclassing():
123125
class MyStream(Stream):
124126
pass
127+
125128
stream = MyStream.per_thread_default()
126129
assert isinstance(stream, MyStream)
127130

131+
128132
def test_stream_legacy_default_public_api():
129133
"""Test public legacy_default() method."""
130134
stream = Stream.legacy_default()
131135
assert isinstance(stream, Stream)
132136
# Verify it's the same as LEGACY_DEFAULT_STREAM
133137
assert stream == LEGACY_DEFAULT_STREAM
134138

139+
135140
def test_stream_per_thread_default_public_api():
136141
"""Test public per_thread_default() method."""
137142
stream = Stream.per_thread_default()
138143
assert isinstance(stream, Stream)
139144
# Verify it's the same as PER_THREAD_DEFAULT_STREAM
140145
assert stream == PER_THREAD_DEFAULT_STREAM
141146

147+
142148
# ============================================================================
143149
# Stream Equality Tests
144150
# ============================================================================

0 commit comments

Comments
 (0)