Fix create view usm offset - #3037
Open
abagusetty wants to merge 5 commits into
Open
Conversation
_create_view() (introduced in IntelPython#2815) rebuilds the view with dpt.usm_ndarray(shape, dtype, buffer=self._array_obj, strides=...), and the constructor rebases such a view onto the whole underlying USM allocation with a default offset of 0. Any source array that does not start at the base of its allocation (e.g. a slice) therefore got a view onto the wrong memory, silently returning values from the base of the parent buffer. This is the same class of bug as the ones fixed in IntelPython#2651 (ndarray constructor with buffer=) and IntelPython#2812 (.data.ptr on views), but for the _create_view() helper added later for ndarray subclassing support. The impact is not limited to explicit .view() calls: dpnp.einsum() takes a "returns_view" fast path for a single operand with no summed index (any pure permutation, including the identity 'abc->abc') and calls .view() on each operand, so einsum over a sliced operand silently returned wrong values. The fix forwards the source array's element offset (converted to units of the view's dtype) to the usm_ndarray constructor, and raises a clear ValueError in the one case a usm_ndarray cannot represent: a byte offset that is not a multiple of the new itemsize. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Parametrize over all supported dtypes and several slice patterns (positive/negative steps, empty result), and add cases for 0-d views, chained views with accumulated offsets, memory sharing / write-through, complex<->real reinterpretation with an offset, and a second misaligned-offset error case. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
abagusetty
requested review from
antonwolfy,
ndgrigorian and
vlad-perevezentsev
as code owners
August 21, 2026 17:14
|
Can one of the admins verify this patch? |
Widen the dtype sweep to 1- and 2-byte integer types and float16, which exercise the byte-offset / itemsize arithmetic far more than the default dtype list (4, 8 and 16-byte types only). Add cases for 3-D slices, F-ordered arrays, non-contiguous sources (transposed and column slices, including the numpy-compatible refusal to change the itemsize when the last axis is not contiguous), usm_type and sycl_queue preservation, write-through via a dtype-changing view, arithmetic and reduction kernels reading through an offset view, and an array built with both a `buffer=` offset and a constructor `offset=`. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
…setty/dpnp into fix-create-view-usm-offset
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.
Fixes #3036