Skip to content

Commit e1265b4

Browse files
committed
cython compilation fixes
1 parent c3c2420 commit e1265b4

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

cuda_core/cuda/core/experimental/_device.pyx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1190,17 +1190,15 @@ class Device:
11901190
True if other is a Device with the same device_id, False if not equal,
11911191
NotImplemented if other is not a Device.
11921192
"""
1193-
# Use cast with exception handling instead of isinstance(other, Device)
1193+
# Use attribute access with exception handling instead of isinstance(other, Device)
11941194
# for performance: isinstance with Python classes still involves type checking
1195-
# overhead. In contrast, a direct cast succeeds immediately in the common
1195+
# overhead. In contrast, a direct attribute access succeeds immediately in the common
11961196
# case (other is a Device), and exception handling has very low overhead
11971197
# when no exception occurs.
1198-
cdef Device _other
11991198
try:
1200-
_other = <Device>other
1201-
except TypeError:
1199+
return self._id == other._id
1200+
except AttributeError:
12021201
return NotImplemented
1203-
return self._id == _other._id
12041202

12051203
def __reduce__(self):
12061204
return Device, (self.device_id,)

cuda_core/cuda/core/experimental/_stream.pyx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,12 @@ cdef class Stream:
148148
@classmethod
149149
def _init(cls, obj: Optional[IsStreamT] = None, options=None, device_id: int = None):
150150
cdef Stream self = Stream.__new__(cls)
151+
cdef cydriver.CUcontext ctx
152+
cdef cydriver.CUresult err
151153

152154
if obj is not None and options is not None:
153155
raise ValueError("obj and options cannot be both specified")
154156
if obj is not None:
155-
cdef cydriver.CUcontext ctx
156-
cdef cydriver.CUresult err
157157
self._handle = _try_to_get_stream_ptr(obj)
158158
# TODO: check if obj is created under the current context/device
159159
self._owner = obj
@@ -182,7 +182,6 @@ cdef class Stream:
182182
prio = high
183183

184184
cdef cydriver.CUstream s
185-
cdef cydriver.CUcontext ctx
186185
with nogil:
187186
HANDLE_RETURN(cydriver.cuStreamCreateWithPriority(&s, flags, prio))
188187
HANDLE_RETURN(cydriver.cuStreamGetCtx(s, &ctx))

0 commit comments

Comments
 (0)