@@ -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
462385LEGACY_DEFAULT_STREAM = C_LEGACY_DEFAULT_STREAM
0 commit comments