Skip to content

Commit af5c52e

Browse files
committed
reverting change that prevented lazy init
1 parent 377ff5b commit af5c52e

File tree

2 files changed

+3
-39
lines changed

2 files changed

+3
-39
lines changed

cuda_core/cuda/core/experimental/_event.pyx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -192,20 +192,16 @@ cdef class Event:
192192
def from_ipc_descriptor(cls, ipc_descriptor: IPCEventDescriptor) -> Event:
193193
"""Import an event that was exported from another process."""
194194
cdef cydriver.CUipcEventHandle data
195-
cdef cydriver.CUcontext curr_ctx
196-
cdef cydriver.CUdevice dev
197195
memcpy(data.reserved, <const void*><const char*>(ipc_descriptor._reserved), sizeof(data.reserved))
198196
cdef Event self = Event.__new__(cls)
199197
with nogil:
200198
HANDLE_RETURN(cydriver.cuIpcOpenEventHandle(&self._handle, data))
201-
HANDLE_RETURN(cydriver.cuCtxGetCurrent(&curr_ctx))
202-
HANDLE_RETURN(cydriver.cuCtxGetDevice(&dev))
203199
self._timing_disabled = True
204200
self._busy_waited = ipc_descriptor._busy_waited
205201
self._ipc_enabled = True
206202
self._ipc_descriptor = ipc_descriptor
207-
self._device_id = <int>dev
208-
self._ctx_handle = driver.CUcontext(<uintptr_t>curr_ctx)
203+
self._device_id = -1 # ??
204+
self._ctx_handle = None # ??
209205
return self
210206

211207
@property

cuda_core/cuda/core/experimental/_stream.pyx

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)