The Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Math Forum » Discussions » Software » comp.soft-sys.matlab

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: compiling cuda file to create ptx file + passing matrices from matlab to cuda kernels
Replies: 1   Last Post: Feb 6, 2013 5:40 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View  
Edric Ellis

Posts: 721
Registered: 12/7/04
Re: compiling cuda file to create ptx file + passing matrices from matlab to cuda kernels
Posted: Feb 6, 2013 5:40 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

"AL_math " <> writes:

> I have another issue though, maybe you can help me with this one:
> I am trying to create a cuda kernel that works on matrices.
> in the visual studio the function has parameters of the type double **matrix.
> When I called:
> ker = parallel.gpu.CUDAKernel(file_name.ptx','','kernel_name');
> from matlab,
> I got the errors:
> "
> Error using iParseToken (line 313)
> Unable to parse declaration: double * * restored_image
> Error in C:\Program Files\MATLAB\R2012a\toolbox\distcomp\gpu\+parallel\+internal\+gpu\handleKernelArgs.p>iParseCPrototype (line 181)
> Error in C:\Program Files\MATLAB\R2012a\toolbox\distcomp\gpu\+parallel\+internal\+gpu\handleKernelArgs.p>handleKernelArgs (line 70)
> "
> I assume that the pointer to pointer is the problem?
> But how can I pass the matrix in other way?

In MATLAB, all matrices (both on the CPU and on the GPU) are stored as
simple 1-dimensional arrays in column-major format. Your CUDA kernel
should accept 'double *' regardless of the number of dimensions of your
data in MATLAB.

When writing a CUDA kernel to access the elements of a matrix, you need
to pass in both the pointer to the array and the dimensions of the array
so that your CUDA code knows how to dereference the array. For simple
elementwise operations, you can simply pass in the number of elements of
your array and treat it as if it is a one-dimensional array.

There's an example kernel implementing the 'game of life' on the GPU
that ships with MATLAB which relies on 2-dimensional addressing. You can
see the CUDA code by executing this in MATLAB:




Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.