dpnp icon indicating copy to clipboard operation
dpnp copied to clipboard

`dpnp.ndarray.data.ptr` always returns the base allocation pointer

Open abagusetty opened this issue 2 months ago • 1 comments

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)

abagusetty avatar Oct 28 '25 03:10 abagusetty

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

abagusetty avatar Oct 28 '25 15:10 abagusetty

Is there any update here?

alvarovm avatar Dec 05 '25 04:12 alvarovm