Repository navigation
Fix copying 0-d and non-contiguous host arrays to a device in from_dlpack - #3207
Merged
Merged
Conversation
…lpack` `_to_usm_ary_from_host_blob` took a `uint8` view of the host array before flattening it, and NumPy refuses a view to a smaller itemsize on a 0-d array or on an array whose last axis is not contiguous. So `dpnp.from_dlpack` and `dpnp.tensor.from_dlpack` raised `ValueError` when they copied such a host array to a SYCL device, unless its items are one byte. The array is now made C-contiguous and at least 1-d before the view. `test_ndim0_host_round_trip` moves a 0-d array of every dtype to the host with `numpy.from_dlpack(x, device="cpu")` and back with `dpnp.from_dlpack(y, device=x.device)`. `test_copy_via_host_layouts` copies 0-d, strided, reversed and F-contiguous host arrays to the device.
antonwolfy
requested review from
ndgrigorian and
vlad-perevezentsev
as code owners
November 30, 2026 12:06
This was referenced Nov 30, 2026
Contributor
|
View rendered docs @ https://intelpython.github.io/dpnp/index.html |
Contributor
|
Array API standard conformance tests for dpnp=0.22.0dev3=np2py314h8d9cdd5_65 ran successfully. |
Collaborator
ndgrigorian
approved these changes
Nov 30, 2026
github-actions Bot
added a commit
that referenced
this pull request
Nov 30, 2026
…lpack` (#3207) This PR fixes a `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. 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`. That helper took a `uint8` view of the host array before flattening it, and NumPy refuses a view to a smaller itemsize on a 0-d array (`Changing the dtype of a 0d array is only supported if the itemsize is unchanged`) or on an array whose last axis is not contiguous (`To change to a dtype of a different size, the last axis must be contiguous`). Only arrays with one-byte items, such as `bool`, got through. The array is now made C-contiguous, and at least 1-d, before the view. The 0-d case is the round trip scikit-learn makes for Array API inputs: it moves an array to the host with `numpy.from_dlpack(x, device="cpu")` and back with `xp.from_dlpack(y, device=device)`. The first direction already worked. `test_ndim0_host_round_trip` makes both calls for a 0-d array of every dtype, and `test_copy_via_host_layouts` copies 0-d, strided, reversed and F-contiguous host arrays to the device with `dpnp.tensor.from_dlpack`. Without the fix, every case of both tests fails except `bool`. - [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 a
ValueErrorindpnp.from_dlpackanddpnp.tensor.from_dlpackwhen copying a 0-d or non-C-contiguous host array to a SYCL device.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. That helper took auint8view of the host array before flattening it, and NumPy refuses a view to a smaller itemsize on a 0-d array (Changing the dtype of a 0d array is only supported if the itemsize is unchanged) or on an array whose last axis is not contiguous (To change to a dtype of a different size, the last axis must be contiguous). Only arrays with one-byte items, such asbool, got through. The array is now made C-contiguous, and at least 1-d, before the view.The 0-d case is the round trip scikit-learn makes for Array API inputs: it moves an array to the host with
numpy.from_dlpack(x, device="cpu")and back withxp.from_dlpack(y, device=device). The first direction already worked.test_ndim0_host_round_tripmakes both calls for a 0-d array of every dtype, andtest_copy_via_host_layoutscopies 0-d, strided, reversed and F-contiguous host arrays to the device withdpnp.tensor.from_dlpack. Without the fix, every case of both tests fails exceptbool.