culaDeviceMalloc

General CULA Dense (LAPACK & BLAS) support and troubleshooting. Use this forum if you are having a general problem or have encountered a bug.

culaDeviceMalloc

Postby psillymathhead » Wed Mar 31, 2010 6:28 pm

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
psillymathhead
 
Posts: 29
Joined: Wed Mar 31, 2010 6:14 pm

Re:culaDeviceMalloc

Postby dan » Thu Apr 01, 2010 6:24 am

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
dan
Administrator
 
Posts: 61
Joined: Thu Jul 23, 2009 2:29 pm

Re:culaDeviceMalloc

Postby psillymathhead » Thu Apr 01, 2010 4:01 pm

excellent, that helps a lot. I was confused about pitch. I will try it out and see how goes it!

Thanks a lot :)
psillymathhead
 
Posts: 29
Joined: Wed Mar 31, 2010 6:14 pm

Re:culaDeviceMalloc

Postby psillymathhead » Thu Apr 01, 2010 4:23 pm

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.
psillymathhead
 
Posts: 29
Joined: Wed Mar 31, 2010 6:14 pm

Re:culaDeviceMalloc

Postby kyle » Thu Apr 01, 2010 5:02 pm

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
kyle
Administrator
 
Posts: 301
Joined: Fri Jun 12, 2009 7:47 pm

Re:culaDeviceMalloc

Postby psillymathhead » Thu Apr 01, 2010 5:27 pm

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
psillymathhead
 
Posts: 29
Joined: Wed Mar 31, 2010 6:14 pm

Re:culaDeviceMalloc

Postby kyle » Thu Apr 01, 2010 5:48 pm

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
kyle
Administrator
 
Posts: 301
Joined: Fri Jun 12, 2009 7:47 pm

Re:culaDeviceMalloc

Postby psillymathhead » Thu Apr 01, 2010 6:03 pm

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!
psillymathhead
 
Posts: 29
Joined: Wed Mar 31, 2010 6:14 pm


Return to CULA Dense Support

Who is online

Users browsing this forum: No registered users and 1 guest

cron