Date: Feb 6, 2013 5:40 AM
Author: Edric Ellis
Subject: Re: compiling cuda file to create ptx file + passing matrices from matlab to cuda kernels

"AL_math " <anatlibman1@gmail.com> 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','file_name.cu','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:

edit(fullfile(matlabroot,'toolbox/distcomp/examples/gpu/life/life_kernel_dynblock.cu'))

Cheers,

Edric.