Discussion:
[PyCUDA] device pointer to cudaArray?
Luke Pfister
2015-10-23 01:11:45 UTC
Permalink
I'm trying to allocate a 3D cudaArray in PyCUDA, then pass the pointer to
this array through Cython. T

This is easy to do with 'regular' memory on the device via the GPUarray
class; I can just cast GPUarray.gpudata to long and then pass through
Cython.

Is there a way to do something similar with a pycuda.driver.Array? I don't
see a way to get to the device pointer.

Thanks,
Luke
Andreas Kloeckner
2015-10-23 04:36:16 UTC
Permalink
Post by Luke Pfister
I'm trying to allocate a 3D cudaArray in PyCUDA, then pass the pointer to
this array through Cython. T
This is easy to do with 'regular' memory on the device via the GPUarray
class; I can just cast GPUarray.gpudata to long and then pass through
Cython.
Is there a way to do something similar with a pycuda.driver.Array? I don't
see a way to get to the device pointer.
There isn't currently, but it's not hard to patch in.

Add a handle_int (or some such) function here:
https://github.com/inducer/pycuda/blob/0797e9390c8c85034cf71ccc46f54fa158da92c4/src/cpp/cuda.hpp#L1060

that returns the handle pointer cast to an integer. Realize that you
just assumed part of the responsibility for management of the lifetime
of the handle.

Wrap you new handle_int here:

https://github.com/inducer/pycuda/blob/master/src/wrapper/wrap_cudadrv.cpp#L1422

Leave handle_int undocumented. Submit a pull request.

HTH,
Andreas

Loading...