Skip to content

Fix create view usm offset - #3037

Open
abagusetty wants to merge 5 commits into
IntelPython:masterfrom
abagusetty:fix-create-view-usm-offset
Open

Fix create view usm offset#3037
abagusetty wants to merge 5 commits into
IntelPython:masterfrom
abagusetty:fix-create-view-usm-offset

Conversation

@abagusetty

Copy link
Copy Markdown
Contributor
  • Have you provided a meaningful PR description?
  • Have you added a test, reproducer or referred to an issue with a reproducer?
  • Have you tested your changes locally for CPU and GPU devices?
  • 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?
  • Have you added your changes to the changelog?

Fixes #3036

abagusetty and others added 2 commits August 21, 2026 11:52
_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>
@intel-python-devops

Copy link
Copy Markdown

Can one of the admins verify this patch?

abagusetty and others added 3 commits August 21, 2026 12:16
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ndarray.view() ignores the array's USM element offset (silently wrong results, incl. einsum)

2 participants