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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ This release drops support for Python 3.10, making Python 3.11 the minimum requi
* Fixed `dpnp.from_dlpack` and `dpnp.tensor.from_dlpack` sizing the memory of an empty DLPack tensor on a oneAPI device by its nonzero dimensions, which allocated that size for a NULL data pointer (8 GiB for shape `(0, 2**31)` of `int32`) and otherwise claimed more memory than the producer allocated [#3203](https://github.com/IntelPython/dpnp/pull/3203)
* Fixed a segfault in `dpnp.from_dlpack` and `dpnp.tensor.from_dlpack` when importing a DLPack tensor on a oneAPI device with NULL strides, which DLPack before 1.2 allows for a C-contiguous tensor [#3183](https://github.com/IntelPython/dpnp/pull/3183)
* Fixed `ValueError` in `dpnp.from_dlpack` and `dpnp.tensor.from_dlpack` when copying a 0-d or non-C-contiguous host array to a SYCL device, unless its items are one byte [#3207](https://github.com/IntelPython/dpnp/pull/3207)
* Fixed wrong values from `dpnp.from_dlpack` and `dpnp.tensor.from_dlpack` when copying a `float64` or `complex128` host array to a SYCL device without fp64 support, which copied its bytes unchanged into the `float32` or `complex64` result [#3209](https://github.com/IntelPython/dpnp/pull/3209)

### Security

Expand Down
2 changes: 2 additions & 0 deletions dpnp/tensor/_dlpack.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -952,6 +952,8 @@ cdef usm_ndarray _to_usm_ary_from_host_blob(object host_blob, dev : Device):
Xusm_dtype = (
"float32" if dt.char == "d" else "complex64"
)
# the bytes are copied as is, so cast on the host first
np_ary = np_ary.astype(Xusm_dtype)
else:
Xusm_dtype = dt
usm_mem = dpmem.MemoryUSMDevice(np_ary.nbytes, queue=q)
Expand Down
17 changes: 17 additions & 0 deletions dpnp/tests/tensor/test_usm_ndarray_dlpack.py
Original file line number Diff line number Diff line change
Expand Up @@ -946,6 +946,23 @@ def test_copy_via_host_gh_1789():
dpt.from_dlpack(x_np, device=(14, 0))


@pytest.mark.parametrize(
"x_np",
[np.array([1.5, -2.25, 3.0]), np.array([1.5 - 2j, 0.25j])],
ids=["float64", "complex128"],
)
def test_copy_via_host_fp64(x_np):
q = get_queue_or_skip()

y = dpt.from_dlpack(x_np, device=q.sycl_device)
exp_dt = x_np.dtype
if 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 y.dtype == exp_dt
assert np.array_equal(dpt.asnumpy(y), x_np)


class LegacyContainer:
"Helper class implementing legacy `__dlpack__` protocol"

Expand Down
Loading