简体   繁体   English

混淆使用scikits.cuda.cula

[英]Confused Using scikits.cuda.cula

I want to use some of cula functionality like LU factorization or Matrix inverse but I have some problem regarding the pointer inputs. 我想使用一些cula功能,例如LU分解或矩阵求逆,但是我对指针输入有一些问题。 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) . 例如对于使用scikits.cuda.cula.culaDeviceSgetrf(m,n,a,lda,ipiv)进行LU分解,则需要使用指针f“ a”参数,但是python中没有指针(我知道其中的所有变量python是由ref)提供的。 So what should I do in this case? 那么在这种情况下我该怎么办? should I use ctype library to create python? 我应该使用ctype库创建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 status = _libcula.culaDeviceSgetrf(m,n,int(a),lda,int(ipiv))TypeError:只有length-1数组可以转换为Python标量

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' 追溯(最近一次通话):文件“ /usr/local/lib/python2.7/dist-packages/scikits.cuda-0.042-py2.7.egg/scikits/cuda/cula中的文件“”,行1 .py“,第329行,位于culaDeviceSgetrf状态= _libcula.culaDeviceSgetrf(m,n,int(a),lda,int(ipiv))TypeError:int()参数必须为字符串或数字,而不是'GPUArray'

any 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. 您不能将gpuarray直接传递给这些例程,array参数应该是设备指针,该设备指针在内部ctypes.c_void_p为Python ctypes.c_void_p以传递给CULA库。 PyCUDA's gpuarray includes a member ptr which will return the underlying pointer to the GPU memory. PyCUDA的gpuarray包含一个成员ptr ,它将把基础指针返回到GPU内存。

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]. 它应该可以正常工作[免责声明:未经编译或测试,使用后果自负]。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM