Question

I want to use some of cula functionality like LU factorization or Matrix inverse but I have some problem regarding the pointer inputs. for example for doing LU factorization with scikits.cuda.cula.culaDeviceSgetrf(m, n, a, lda, ipiv) , one need to use pointer f "a" argument but there is no pointer in python explicitly(I know all variables in python are by ref) . So what should I do in this case? should I use ctype library to create python?

this is what I am trying to do:

   import numpy as np

   import scikits.cuda.cula as cula
   import pycuda.gpuarray as gpuarray

   cula.culaInitialize()

   //I create a square matrix for simplicity 
   a=np.array([[1,2,3,4],[6,7,8,9],[7,2,3,5],[2,4,5,6]])

   n=b.shape[0]
   ida=ipv=m

   scikits.cuda.cula.culaDeviceSgetrf(m,n,a,n,n)

status = _libcula.culaDeviceSgetrf(m, n, int(a), lda, int(ipiv)) TypeError: only length-1 arrays can be converted to Python scalars

and when I try

a_gpu = gpuarray.to_gpu(a)
scikits.cuda.cula.culaDeviceSgetrf(m,n,a_gpu,n,n) :

Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python2.7/dist-packages/scikits.cuda-0.042-py2.7.egg/scikits/cuda/cula.py", line 329, in culaDeviceSgetrf status = _libcula.culaDeviceSgetrf(m, n, int(a), lda, int(ipiv)) TypeError: int() argument must be a string or a number, not 'GPUArray'

any solution ?

Was it helpful?

Solution

The error message is pretty self explanatory. You cannot pass a gpuarray directly to these routines, the array argument is expected to be a device pointer which is internally cast to a Python ctypes.c_void_p for passing to the CULA library. PyCUDA's gpuarray includes a member ptr which will return the underlying pointer to the GPU memory.

If you do something like:

a_gpu = gpuarray.to_gpu(a)
scikits.cuda.cula.culaDeviceSgetrf(m,n,a_gpu.ptr,n,n)

it should work correctly [disclaimer: never compiled, or tested, use at own risk].

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top