I would like to construct a Cupy GPU array view of the array that already exists on the GPU and I'm handed the following:
- Pointer to the array.
- I know the data type and the size of the data.
- I'm also given a pitch.
How one would construct an array view (avoiding copies preferably)? I tried the following:
import cupy as cp
import numpy as np
shape = (w, h, c, b) # example
s = np.product(shape)*4 # this is 1D
mem = cp.cuda.UnownedMemory(ptr=image_batch_ptr,
owner=None,
size=s)
memptr = cp.cuda.MemoryPointer(mem, 0)
d = cp.ndarray(shape=shape,
dtype=np.float32,
memptr=memptr)
But this does not seem to produce the correct alignment. Specifically, I'm having trouble with integrating pitch into the picture -- is it even possible?