diff --git a/CHANGELOG.md b/CHANGELOG.md index 3957a444ffc..918d9f20e79 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/dpnp/tensor/_dlpack.pyx b/dpnp/tensor/_dlpack.pyx index 31a68774628..323a7ceceb0 100644 --- a/dpnp/tensor/_dlpack.pyx +++ b/dpnp/tensor/_dlpack.pyx @@ -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 diff --git a/dpnp/tests/tensor/test_usm_ndarray_dlpack.py b/dpnp/tests/tensor/test_usm_ndarray_dlpack.py index 7339248e6c5..d5e5fccf70a 100644 --- a/dpnp/tests/tensor/test_usm_ndarray_dlpack.py +++ b/dpnp/tests/tensor/test_usm_ndarray_dlpack.py @@ -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")