Repository navigation
Make scalar operands of binary elementwise functions asynchronous - #3182
Open
ndgrigorian wants to merge 2 commits into
Open
ndgrigorian wants to merge 2 commits into
ndgrigorian wants to merge 2 commits into
Conversation
A Python or NumPy scalar was turned into a 0-d array, or assigned through basic indexing, with _copy_numpy_ndarray_into_usm_ndarray. That copy waits for all work submitted to the queue, so every binary operation with a scalar operand (2 * x, x == 0), clip, where and x[0] = 1 blocked the host until the device was idle (gh-3148). _copy_from_numpy_into and asarray now fill 0-d input with _full_usm_ndarray. The value is cast on the host the way the copy kernel casts it: through float32/complex64 on devices without fp64, the real part of complex values, float-to-integer through int64 so that it wraps, and without NumPy's cast warnings.
ndgrigorian
requested review from
antonwolfy and
vlad-perevezentsev
as code owners
November 8, 2026 20:44
Contributor
|
View rendered docs @ https://intelpython.github.io/dpnp/pull/3182/index.html |
Contributor
|
Array API standard conformance tests for dpnp=0.22.0dev1=np2py314h8d9cdd5_7 ran successfully. |
Collaborator
This branch has not been deployed
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 makes binary elementwise functions with a Python or NumPy scalar operand asynchronous, closes #3148
A scalar operand (
2 * x,x == 0,x * np.float32(2)), the scalar ofclipandwhere, and a scalar assigned through basic indexing (x[0] = 1) were turned into a 0-d array by_copy_numpy_ndarray_into_usm_ndarray. That copy waits for all work already submitted to the queue, so each of these calls blocked the host until the device was idle._copy_from_numpy_intoanddpnp.tensor.asarraynow fill 0-d input with_full_usm_ndarray, ordered after the queue's submitted events, instead. Arrays withndim > 0still go through the copyThe value is cast on the host the way the copy kernel would cast it, so results don't change
float32/complex64on devices without fp64int64, so it wraps like the copy kernel where a direct NumPy cast saturates (e.g.1e10intoint16gives-7168)The new tests patch
_copy_numpy_ndarray_into_usm_ndarrayto raise, and coverasarrayof Python scalars, NumPy scalars and 0-d arrays of every dtype, casts to another dtype, fp64 scalars on devices without fp64, indexed assignment, and binary operators,out=and in-place operators with a scalar operand. They fail without the fix (131 cases). The affecteddpnp.tensortests anddpnp/tests/test_arraycreation.pypass on a Level Zero iGPU and the OpenCL CPU device. The fp64-less test only skipped here, since both devices support fp64With the reproducer from #3148 on the iGPU, the host time of one call issued right after a ~75 ms matmul:
x * x2 * xx == 0x * np.float32(2)x[0] = 1