Skip to content
Open
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ This release drops support for Python 3.10, making Python 3.11 the minimum requi
* Fixed building with the open source DPC++ compiler and CMake 4.5 or newer, which identifies it as `DPClang` instead of `Clang` [#3216](https://github.com/IntelPython/dpnp/pull/3216)
* Fixed the comparison functions, `dpnp.divide`, the logical functions and the binary functions that compute in floating point for an integer or boolean array, such as `dpnp.arctan2`, raising `OverflowError` or `ValueError` for a Python integer outside the range of the array data type. The logical functions now raise `OverflowError` for a Python integer outside the `int64` range for any data type [#3202](https://github.com/IntelPython/dpnp/pull/3202)
* Fixed the misleading `ValueError` about an unsupported data type that `dpnp.tensor` comparison functions, `dpnp.tensor.divide`, `dpnp.tensor.isin` and `dpnp.tensor.searchsorted` raised for a Python integer outside the `int64` and `uint64` ranges, which now raise `OverflowError` [#3202](https://github.com/IntelPython/dpnp/pull/3202)
* Fixed `ValueError` in `dpnp.from_dlpack` and `dpnp.tensor.from_dlpack` when copying an empty host array to a SYCL device [#3208](https://github.com/IntelPython/dpnp/pull/3208)

### Security

Expand Down
8 changes: 8 additions & 0 deletions dpnp/tensor/_dlpack.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -956,6 +956,14 @@ cdef usm_ndarray _to_usm_ary_from_host_blob(object host_blob, dev : Device):
np_ary = np_ary.astype(Xusm_dtype)
else:
Xusm_dtype = dt
if np_ary.size == 0:
# MemoryUSMDevice and copy_from_host reject zero bytes
return usm_ndarray(
np_ary.shape,
dtype=Xusm_dtype,
buffer="device",
buffer_ctor_kwargs={"queue": q},
)
usm_mem = dpmem.MemoryUSMDevice(np_ary.nbytes, queue=q)
usm_ary = usm_ndarray(np_ary.shape, dtype=Xusm_dtype, buffer=usm_mem)
# 0-d and non-C-contiguous arrays have no flat uint8 view
Expand Down
18 changes: 18 additions & 0 deletions dpnp/tests/tensor/test_usm_ndarray_dlpack.py
Original file line number Diff line number Diff line change
Expand Up @@ -889,6 +889,24 @@ def test_dlpack_size_0_on_kdlcpu():
assert y.ctypes.data == x_np.ctypes.data


@pytest.mark.parametrize("dtype", ["i4", "f8", "c16"])
@pytest.mark.parametrize("shape", [(0,), (0, 3), (3, 0)])
def test_copy_via_host_size_0(shape, dtype):
q = get_queue_or_skip()
x_np = np.ones(shape, dtype=dtype)

y = dpt.from_dlpack(x_np, device=q.sycl_device)
exp_dt = x_np.dtype
if exp_dt.kind in "fc" and not q.sycl_device.has_aspect_fp64:
# cast on the host, as dpnp.tensor.asarray does
exp_dt = np.float32 if exp_dt.kind == "f" else np.complex64
assert isinstance(y, dpt.usm_ndarray)
assert y.shape == shape
assert y.dtype == exp_dt
assert y.usm_type == "device"
assert y.sycl_device == q.sycl_device


def test_copy_via_host():
get_queue_or_skip()
x = dpt.ones(1, dtype="i4")
Expand Down
Loading