Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Confused Using scikits.cuda.cula #20

Closed
llvll0hsen opened this issue Aug 31, 2012 · 10 comments
Closed

Confused Using scikits.cuda.cula #20

llvll0hsen opened this issue Aug 31, 2012 · 10 comments

Comments

@llvll0hsen
Copy link

Hello all,

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)

but I'm getting this error:

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: 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 ?

Thanks ,

Mohsen

@lebedov
Copy link
Owner

lebedov commented Aug 31, 2012

You can pass a_gpu.gpudata to the wrapper function; it gets cast to an integer that corresponds to the pointer value.

@lebedov lebedov closed this as completed Aug 31, 2012
@llvll0hsen
Copy link
Author

still not working :

cula.culaDeviceSgetrf(m,n,a_gpu.gpudata,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 330, in culaDeviceSgetrf
culaCheckStatus(status)
File "/usr/local/lib/python2.7/dist-packages/scikits.cuda-0.042-py2.7.egg/scikits/cuda/cula.py", line 210, in culaCheckStatus
raise culaExceptionsstatus
scikits.cuda.cula.culaDataError: 3

@lebedov
Copy link
Owner

lebedov commented Sep 3, 2012

Can you please post the code that you are trying to run? The snippet in your initial posting is incomplete.

@lebedov lebedov reopened this Sep 3, 2012
@llvll0hsen
Copy link
Author

This is what I'm trying to do:

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

Can you run that on your system? I'm using cula 12 full version.

cula.culaInitialize()

a=np.array([[1,2,3,4],[6,7,8,9],[7,2,3,5],[2,4,5,6]])

n=m=ida=ipiv=a.shape[0]

a_gpu=gpuarray.to_gpu(a)

result=cula.culaDeviceSgetrf(m, n, a_gpu.gpudata, ida, ipiv)

print result

cula.culaShutdown()

@lebedov
Copy link
Owner

lebedov commented Sep 3, 2012

Thanks. You are getting the data error because the array a doesn't contain single precision floats. Also, the ipiv parameter must be a pointer to an integer array, not a scalar.

@lebedov lebedov closed this as completed Sep 3, 2012
@llvll0hsen
Copy link
Author

Thanks for your reply. Ok so for fixing the first problem I should make "a" like :

a=np.array([[1,2,3,4],[6,7,8,9],[7,2,3,5],[2,4,5,6]], dtype=np.float32)

but I dont know how to fix the ipiv. Actually I dont understand what is ipiv . can tell me more about it?

@lebedov
Copy link
Owner

lebedov commented Sep 3, 2012

ipiv contains the 1-offset indices of the pivots determined during the decomposition. You don't need to set ipiv; just allocate an empty int32 array in GPU memory and pass its gpudata attribute to the function. See the GETRF entry in the CULA Reference manual for more information.

@llvll0hsen
Copy link
Author

I get "None" after that . this is my code(I think I allocate the empty array in wrong way ):

a=np.array([[1,2,3,4],[6,7,8,9],[7,2,3,5],[2,4,5,6]], dtype=np.float32)
n=m=ida=a.shape[0]
ipiv=np.empty(n,dtype=np.int32)
ipiv_gpu=gpuarray.to_gpu(ipiv)
a_gpu=gpuarray.to_gpu(a)
result=cula.culaDeviceSgetrf(m, n, a_gpu.gpudata, ida, ipiv_gpu.gpudata)
print result


when I define it like :
ipiv=np.array([],dtype=np.int32)

I get:

status = _libcula.culaDeviceSgetrf(m, n, int(a), lda, int(ipiv))
TypeError: int() argument must be a string or a number, not 'NoneType'

@lebedov
Copy link
Owner

lebedov commented Sep 5, 2012

Your code is correct; the CULA reference manual indicates that ipiv should have length min(m,n). Note also that the returned value of the function is its execution status, not the result of the computation.

@llvll0hsen
Copy link
Author

yes It's working now.I expected the result to have the answer not status. Thanks alot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants