Skip to content

dpnp.ndarray.data.ptr always returns the base allocation pointer #2641

Closed

Description

@abagusetty

dpnp.ndarray.data.ptr always returns the base allocation pointer, not the view start pointer.

Expected: data.ptr should reflect the view’s actual first-element address (base + offset * itemsize), matching NumPy/CuPy semantics.

import dpnp as dp

nao, ngrids = 24, 4096
elems_plane = nao * ngrids

arena  = dp.empty(4 * elems_plane, dtype=dp.float64)
slice1 = arena[elems_plane:]  # non-zero offset view

# Construct shaped array over the *view*:
plane1 = dp.ndarray((nao, ngrids), dtype=arena.dtype, buffer=slice1)

def ptr(a):
    return int(a.data.ptr)

print("arena ptr :", hex(ptr(arena)))
print("slice1 ptr:", hex(ptr(slice1)))   # expected start for plane1
print("plane1 ptr:", hex(ptr(plane1)))   # BUG: equals arena ptr (offset lost)

# This should hold if buffer=view were respected:
print("EXPECT plane1.ptr == slice1.ptr:", ptr(plane1) == ptr(slice1))

One should expect slice1 and plane1 (since plane1 is constructed from slice1) share the same pointer but since the offset is lost plane1 points to the parent base memory pointer (i.e., arena)

Activity

  1. abagusetty commented on Oct 28, 2025

    @abagusetty
    ContributorAuthor

    With the cupy's equivalent results in: (slice1 & plane1 are the same)

    arena ptr : 0x7fa474800000
    slice1 ptr: 0x7fa4748c0000
    plane1 ptr: 0x7fa4748c0000
    EXPECT plane1.ptr == slice1.ptr: True
    

    With numpy:

    arena ptr : 0x7fc4d9aff010
    slice1 ptr: 0x7fc4d9bbf010
    plane1 ptr: 0x7fc4d9bbf010
    EXPECT plane1.ptr == slice1.ptr: True
    

    With DPNP:

    arena ptr : 0xff00ffffffc00000
    slice1 ptr: 0xff00ffffffcc0000
    plane1 ptr: 0xff00ffffffc00000
    EXPECT plane1.ptr == slice1.ptr: False
    
  2. self-assigned this
    on Nov 4, 2025
  3. added theissue type on Nov 4, 2025
  4. added this to the 0.20.0 release milestone on Nov 4, 2025
  5. alvarovm commented on Dec 5, 2025

    @alvarovm

    Is there any update here?

  6. antonwolfy commented on Dec 13, 2025

    @antonwolfy
    Contributor

    It was agreed that the issue will be resolved in dpctl.
    @ndgrigorian could you please share if there is any progress on updating the logic in usm_ndarray constructor to mitigate the issue?

  7. ndgrigorian commented on Dec 17, 2025

    @ndgrigorian
    Collaborator

    Is there any update here?

    yes, the issue will be resolved in the development version of dpctl soon. The focus has been on the 0.21.1 release at the moment, but when that's completed, it will be fixed soon after

  8. ndgrigorian commented on Jan 7, 2026

    @ndgrigorian
    Collaborator

    A PR is now open that accounts for the offset when a view is provided to the usm_ndarray constructor. This also means non-contiguous views are disallowed (works the same in NumPy):
    IntelPython/dpctl#2226

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions