Page 1 of 1

culaDeviceMalloc

PostPosted: Wed Mar 31, 2010 6:28 pm
by psillymathhead
Is there any documentation available for the culaDeviceMalloc and culaDeviceFree beyond the mentioning in the programming reference manual? (I found it less thorough than other functions.)

I am writing a code to expand a reduced sparse matrix onto GPU memory in order to calculate its eigenvalues and am stuck having trouble with culaDeviceMalloc. Ideally I just want to allocate this matrix one time using culaDeviceMalloc, follow with device geev, make small adjustments to matrix, repeat.... thus avoiding costly allocation/transmission time, which is not necessary for my task.

Any example code tidbits for culaDeviceMalloc?

Thanks

Re:culaDeviceMalloc

PostPosted: Thu Apr 01, 2010 6:24 am
by dan
Here is an example:
Code: Select all
culaStatus s;
    double* A;
    int pitch;
    int M = 52;
    int N = 16;
    s = culaDeviceMalloc((void**)&A, &pitch, M, N, sizeof(double));
    . . .
    s = culaDeviceFree(A);


Pitch is the leading dimension of the allocated array. If you were to continue to pass A to a CULA function, you would pass pitch as LDA.

Dan

Re:culaDeviceMalloc

PostPosted: Thu Apr 01, 2010 4:01 pm
by psillymathhead
excellent, that helps a lot. I was confused about pitch. I will try it out and see how goes it!

Thanks a lot :)

Re:culaDeviceMalloc

PostPosted: Thu Apr 01, 2010 4:23 pm
by psillymathhead
I am getting error 7. I see you have 5 arguements? My ref manual lists only 4 param as:

rows, cols, elesize, pitch.

Perhaps this is my trouble?

Thanks for helping.

Re:culaDeviceMalloc

PostPosted: Thu Apr 01, 2010 5:02 pm
by kyle
Here are the two relevant sections from the API and Programmer's Guide:

http://www.culatools.com/html_api/#culadevicemalloc
http://www.culatools.com/html_guide/#us ... -interface

Re:culaDeviceMalloc

PostPosted: Thu Apr 01, 2010 5:27 pm
by psillymathhead
yes, I see this has been updated since my 1,1 copy of manual. Thanks. Unfortunately I am getting Seg Fault. I am still learning, so perhaps I am making stupid error. I would really appreciate any help as this step is holding up my coding, and I am just now getting access to the CULA/CUDA machine.

Here is my wrapper:
Code: Select all
_culaDeviceMalloc = libcula.culaDeviceMalloc
_culaDeviceMalloc.restype = int
_culaDeviceMalloc.argtypes = [numpy.ctypeslib.ndpointer(dtype=numpy.float32,flags='C_CONTIGUOUS'),
            ctypes.c_int,
            ctypes.c_int,
            ctypes.c_int,
            ctypes.c_int]

def culaDeviceMalloc(A,pitch,rows,cols,elesize):
  _culaDeviceMalloc(A,pitch,rows,cols,elesize)


and I get:

Code: Select all
>>> import numpy
>>> from manula import *
>>> A = numpy.array([1],numpy.float32)
>>> libcula.culaInitialize()
0
>>> libcula.culaDeviceMalloc(A,1,1,1,4)
Segmentation fault

Re:culaDeviceMalloc

PostPosted: Thu Apr 01, 2010 5:48 pm
by kyle
I don't have any experience using Python wrappers for CULA, but a quick guess would be that you're handling the pitch value wrong. It's an output value returned by reference (in C/C++ terms).

libcula.culaDeviceMalloc(A,1,1,1,4)

This is probably trying to write the pitch value to memory location '1'. A clear segmentation fault in C. You should be writing to a variable there, not reading in anything.

I hope this helps. I know that in Python all arguments, with the exception of strings and numeric values, are passed by reference. This should make the function simple to implement.

-Kyle

Re:culaDeviceMalloc

PostPosted: Thu Apr 01, 2010 6:03 pm
by psillymathhead
Not only did that make perfect sense, but it solved my problem completely.

Code: Select all
>>> p=ctypes.c_int()
>>> libcula.culaDeviceMalloc(A,p,1,1,4)
0


Heh, told you I am still learning ;)
Awesome! Thanks much for your time. Onto eigenvalues once again!