Repository navigation
Fix copying fp64 host arrays to a device without fp64 in from_dlpack - #3209
Merged
Merged
Conversation
… `from_dlpack` On a device without fp64 support, `_to_usm_ary_from_host_blob` made the result `float32` or `complex64` for a `float64` or `complex128` host array, but copied the host bytes into it unchanged, so `dpnp.from_dlpack` and `dpnp.tensor.from_dlpack` returned wrong values. The host array is now cast to the result's data type before the copy, as `dpnp.tensor.asarray` does. `test_copy_via_host_fp64` copies `float64` and `complex128` host arrays to the device and checks the data type and values of the result.
antonwolfy
requested review from
ndgrigorian and
vlad-perevezentsev
as code owners
November 30, 2026 12:21
Contributor
|
View rendered docs @ https://intelpython.github.io/dpnp/index.html |
Contributor
|
Array API standard conformance tests for dpnp=0.22.0dev3=np2py314h8d9cdd5_67 ran successfully. |
Collaborator
Contributor
Author
|
Tested on Intel Iris Xe Graphics, which has no fp64 support (Level Zero, compute runtime 26.40.40196.15), and on a 12th Gen Intel Core i7 CPU (OpenCL, with fp64), with DPC++ 2026.2 and NumPy 2.5.5:
Host arrays whose last axis is not contiguous still raise |
github-actions Bot
added a commit
that referenced
this pull request
Nov 30, 2026
#3209) This PR fixes 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. When the producer cannot export to the requested oneAPI device, as NumPy cannot, `from_dlpack` imports the array on the host and copies it to the device with `_to_usm_ary_from_host_blob`. On a device without fp64, that helper makes the result `float32` or `complex64`, but it copied the bytes of the `float64` or `complex128` host array into it unchanged, with no error. For example, `[1.5, -2.25, 3.0]` came out as `[0, 1.9375, 0]`. The host array is now cast to the result's data type before the copy, as `dpnp.tensor.asarray` does for host arrays. `test_copy_via_host_fp64` copies `float64` and `complex128` host arrays to the device. It expects the same data type on a device with fp64 and `float32` or `complex64` on one without, and compares the values in both cases. The CI devices all support fp64, so there it only checks the fp64 case. - [x] Have you provided a meaningful PR description? - [x] Have you added a test, reproducer or referred to an issue with a reproducer? - [x] Have you tested your changes locally for CPU and GPU devices? - [x] Have you made sure that new changes do not introduce compiler warnings? - [ ] Have you checked performance impact of proposed changes? - [ ] Have you added documentation for your changes, if necessary? - [x] Have you added your changes to the changelog?
4 of 7 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR fixes wrong values from
dpnp.from_dlpackanddpnp.tensor.from_dlpackwhen copying afloat64orcomplex128host array to a SYCL device without fp64 support.When the producer cannot export to the requested oneAPI device, as NumPy cannot,
from_dlpackimports the array on the host and copies it to the device with_to_usm_ary_from_host_blob. On a device without fp64, that helper makes the resultfloat32orcomplex64, but it copied the bytes of thefloat64orcomplex128host array into it unchanged, with no error. For example,[1.5, -2.25, 3.0]came out as[0, 1.9375, 0]. The host array is now cast to the result's data type before the copy, asdpnp.tensor.asarraydoes for host arrays.test_copy_via_host_fp64copiesfloat64andcomplex128host arrays to the device. It expects the same data type on a device with fp64 andfloat32orcomplex64on one without, and compares the values in both cases. The CI devices all support fp64, so there it only checks the fp64 case.