@@ -126,52 +126,27 @@ cdef class Stream:
126126 @classmethod
127127 def _legacy_default (cls ):
128128 cdef Stream self = Stream.__new__ (cls )
129- cdef cydriver.CUcontext ctx
130- cdef cydriver.CUresult err
131129 self ._handle = < cydriver.CUstream> (cydriver.CU_STREAM_LEGACY)
132130 self ._builtin = True
133- with nogil:
134- err = cydriver.cuCtxGetCurrent(& ctx)
135- if err == cydriver.CUresult.CUDA_SUCCESS:
136- self ._ctx_handle = ctx
137- else :
138- # CUDA not initialized yet, will be lazily initialized later
139- self ._ctx_handle = CU_CONTEXT_INVALID
140131 return self
141132
142133 @classmethod
143134 def _per_thread_default (cls ):
144135 cdef Stream self = Stream.__new__ (cls )
145- cdef cydriver.CUcontext ctx
146- cdef cydriver.CUresult err
147136 self ._handle = < cydriver.CUstream> (cydriver.CU_STREAM_PER_THREAD)
148137 self ._builtin = True
149- with nogil:
150- err = cydriver.cuCtxGetCurrent(& ctx)
151- if err == cydriver.CUresult.CUDA_SUCCESS:
152- self ._ctx_handle = ctx
153- else :
154- # CUDA not initialized yet, will be lazily initialized later
155- self ._ctx_handle = CU_CONTEXT_INVALID
156138 return self
157139
158140 @classmethod
159141 def _init (cls , obj: Optional[IsStreamT] = None , options = None , device_id: int = None ):
160142 cdef Stream self = Stream.__new__ (cls )
161- cdef cydriver.CUcontext ctx
162- cdef cydriver.CUresult err
163143
164144 if obj is not None and options is not None :
165145 raise ValueError (" obj and options cannot be both specified" )
166146 if obj is not None :
167147 self ._handle = _try_to_get_stream_ptr(obj)
168148 # TODO: check if obj is created under the current context/device
169149 self ._owner = obj
170- with nogil:
171- err = cydriver.cuStreamGetCtx(self ._handle, & ctx)
172- if err != cydriver.CUresult.CUDA_SUCCESS:
173- HANDLE_RETURN(cydriver.cuCtxGetCurrent(& ctx))
174- self ._ctx_handle = ctx
175150 return self
176151
177152 cdef StreamOptions opts = check_or_create_options(StreamOptions, options, " Stream options" )
@@ -194,12 +169,10 @@ cdef class Stream:
194169 cdef cydriver.CUstream s
195170 with nogil:
196171 HANDLE_RETURN(cydriver.cuStreamCreateWithPriority(& s, flags, prio))
197- HANDLE_RETURN(cydriver.cuStreamGetCtx(s, & ctx))
198172 self ._handle = s
199173 self ._nonblocking = int (nonblocking)
200174 self ._priority = prio
201175 self ._device_id = device_id if device_id is not None else self ._device_id
202- self ._ctx_handle = ctx
203176 return self
204177
205178 def __dealloc__ (self ):
@@ -364,12 +337,7 @@ cdef class Stream:
364337
365338 cdef int _get_context(self ) except?-1 nogil:
366339 if self._ctx_handle == CU_CONTEXT_INVALID:
367- if self._builtin:
368- # For builtin streams (LEGACY/PER_THREAD ), use cuCtxGetCurrent
369- # since cuStreamGetCtx doesn't work on these special handles
370- HANDLE_RETURN(cydriver.cuCtxGetCurrent(&(self._ctx_handle )))
371- else:
372- HANDLE_RETURN(cydriver.cuStreamGetCtx(self._handle , &(self._ctx_handle )))
340+ HANDLE_RETURN(cydriver.cuStreamGetCtx(self._handle , &(self._ctx_handle )))
373341 return 0
374342
375343 cdef int _get_device_and_context(self ) except?-1:
0 commit comments