我想使用一些cula功能,比如LU分解或矩阵求逆,但是在指针输入方面我有一些问题。例如,使用库拉库拉套件.culaDeviceSgetrf(m,n,a,lda,ipiv),需要使用指针f“a”参数,但python中没有显式的指针(我知道python中的所有变量都是通过ref)。那么在这种情况下我该怎么办?我应该使用ctype库来创建python吗?在
我要做的是:
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
当我试着
^{pr2}$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'
有什么解决办法吗?在
错误信息是不言而喻的。不能将
gpuarray
直接传递给这些例程,数组参数应该是一个设备指针,该指针被内部转换为Pythonctypes.c_void_p
,以便传递给CULA库。PyCUDA的gpuarray
包含一个成员ptr
,该成员将返回指向GPU内存的底层指针。在如果你做一些类似的事情:
它应该能正常工作[免责声明:从不编译或测试,使用风险自负]。在
相关问题 更多 >
编程相关推荐