Skip to content

Commit f57a06d

Browse files
committed
fix: only pluck out device id if the data buffer pointer coming from CAI is valid
1 parent cc46a11 commit f57a06d

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

cuda_core/cuda/core/experimental/_memoryview.pyx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -582,10 +582,13 @@ cpdef StridedMemoryView view_as_cai(obj, stream_ptr, view=None):
582582
buf.dl_tensor = NULL
583583
buf.ptr, buf.readonly = cai_data["data"]
584584
buf.is_device_accessible = True
585-
buf.device_id = handle_return(
586-
driver.cuPointerGetAttribute(
587-
driver.CUpointer_attribute.CU_POINTER_ATTRIBUTE_DEVICE_ORDINAL,
588-
buf.ptr))
585+
if buf.ptr != 0:
586+
buf.device_id = handle_return(
587+
driver.cuPointerGetAttribute(
588+
driver.CUpointer_attribute.CU_POINTER_ATTRIBUTE_DEVICE_ORDINAL,
589+
buf.ptr))
590+
else:
591+
buf.device_id = -1
589592

590593
cdef intptr_t producer_s, consumer_s
591594
stream_ptr = int(stream_ptr)

0 commit comments

Comments
 (0)