Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions cuda_core/cuda/core/_memoryview.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -582,10 +582,13 @@ cpdef StridedMemoryView view_as_cai(obj, stream_ptr, view=None):
buf.dl_tensor = NULL
buf.ptr, buf.readonly = cai_data["data"]
buf.is_device_accessible = True
buf.device_id = handle_return(
driver.cuPointerGetAttribute(
driver.CUpointer_attribute.CU_POINTER_ATTRIBUTE_DEVICE_ORDINAL,
buf.ptr))
if buf.ptr != 0:
buf.device_id = handle_return(
driver.cuPointerGetAttribute(
driver.CUpointer_attribute.CU_POINTER_ATTRIBUTE_DEVICE_ORDINAL,
buf.ptr))
else:
buf.device_id = handle_return(driver.cuCtxGetDevice())

cdef intptr_t producer_s, consumer_s
stream_ptr = int(stream_ptr)
Expand Down
1 change: 1 addition & 0 deletions cuda_core/docs/source/release/0.5.0-notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ None.
Fixes and enhancements
----------------------

- Zero-size arrays are now supported as inputs when constructing ``StridedMemoryView``.
- Most CUDA resources can be hashed now.
- Python ``bool`` objects are now converted to C++ ``bool`` type when passed as kernel arguments (previously converted to ``int``).
- Restored v0.3.x :class:`MemoryResource` behaviors and missing MR attributes for backward compatibility.
Expand Down
20 changes: 20 additions & 0 deletions cuda_core/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,3 +413,23 @@ def test_view_sliced_external_negative_offset(stride_order, view_as):
assert sliced_view._layout.itemsize == a_sliced.itemsize == layout.itemsize
assert sliced_view.shape == a_sliced.shape
assert sliced_view._layout.strides_in_bytes == a_sliced.strides


@pytest.mark.parametrize(
"api",
[
StridedMemoryView.from_dlpack,
StridedMemoryView.from_cuda_array_interface,
],
)
@pytest.mark.parametrize("shape", [(0,), (0, 0), (0, 0, 0)])
@pytest.mark.parametrize("dtype", [np.int64, np.uint8, np.float64])
def test_view_zero_size_array(api, shape, dtype):
cp = pytest.importorskip("cupy")

x = cp.empty(shape, dtype=dtype)
smv = api(x, stream_ptr=0)

assert smv.size == 0
assert smv.shape == shape
assert smv.dtype == np.dtype(dtype)
Loading