How to implement ptr in ArrayBase backed by GPU memory? #1256
Unanswered
AlienKevin
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm trying to extend ndarray with GPU support through wgpu. So far, I got basic binary operations like addition to work with default strides and offset. The problem is that ArrayBase requires me to provide a ptr to the start of the buffer. Since the buffer is stored on the GPU memory, it's impossible to return a pointer to it. I read further into the documentation and found that a dangling ptr is safe for zero offsets and doesn't need to be dereferenced when S = RawData. So I'm currently providing
std::ptr::NonNull::dangling()
as the ptr.However, is the dangling pointer suitable for non-zero offsets? In my view, the ptr is a virtual address into the GPU buffer. When I do the calculation in GPU, I can pass the ptr along with the dim and strides so I can properly iterate through the elements in the buffer. As such, the ptr can point to any fake address as long as alignment and offset work as usual in ndarray. Then, I can simply subtract the starting fake address from the ptr and pass that as the offset to the GPU compute shader. Here's my current imlementation with the dangling ptr:
Beta Was this translation helpful? Give feedback.
All reactions