我想使用一些cula功能,如LU分解或矩陣反轉,但我有一些關於指針輸入的問題。例如用scikits.cuda.cula.culaDeviceSgetrf(m,n,a,lda,ipiv)做LU分解,需要使用指針f「a」參數,但是顯式地指定python中沒有指針(我知道所有變量都在Python是由裁判)。那麼在這種情況下我應該怎麼做?我應該使用ctype庫來創建python嗎?困惑使用scikits.cuda.cula
這就是我想要做的事:
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
,當我嘗試
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'
任何解決方案?
感謝您的回覆我通過使用a_gpu.gpudata解決了此問題。這是與此問題有關的鏈接https://github.com/lebedov/scikits.cuda/issues/20#issuecomment-8202795 – Moj