Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

compiling cuda file to create ptx file

1,225 views
Skip to first unread message

AL_math

unread,
Feb 4, 2013, 2:58:08 AM2/4/13
to
Hi,
I am trying to compile a cuda file (file_name.cu) to create a ptx file
in order to call cuda kernels from matlab.
I am using visual studio 2010, cuda 5 and windows 7, 64 bit operating system.
I had tried to compile through the command prompt as was explained in this web
about creating kernels from cu files:

"you can create a compiled PTX file with the shell command:

nvcc -ptx myfun.cu

This generates the file named myfun.ptx."

But this gave me a lot of errors that I couldn't fix.

I would really appreciate some help.

Edric M Ellis

unread,
Feb 4, 2013, 3:52:23 AM2/4/13
to
You need to have downloaded and installed the CUDA toolkit from NVIDIA's
website <https://developer.nvidia.com/cuda-toolkit> . If you've
installed that, and got nvcc on your path, perhaps you could post more
details about precisely what error you're receiving.

Cheers,

Edric.

AL_math

unread,
Feb 6, 2013, 5:02:07 AM2/6/13
to
Edric M Ellis <eel...@mathworks.com> wrote in message <ytwwquo...@uk-eellis0l.dhcp.mathworks.com>...
Hi
Thanks a lot for your reply but the problem was solved.
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?

thanks again

Edric M Ellis

unread,
Feb 6, 2013, 5:40:10 AM2/6/13
to
"AL_math " <anatl...@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.

AL_math

unread,
Feb 10, 2013, 6:17:10 AM2/10/13
to
Edric M Ellis <eel...@mathworks.com> wrote in message <ytwsj59...@uk-eellis0l.dhcp.mathworks.com>...
Thanks alot for your answer and link.
They really helped.

Dhanya Pankaj

unread,
Feb 13, 2013, 3:36:09 AM2/13/13
to
Hi,

Could you please let me know how to create a .ptx file from a cuda file using visual studio 2010.

Thanks,
Dhanya

"AL_math" wrote in message <kenpmg$84j$1...@newscl01ah.mathworks.com>...

AL_math

unread,
Feb 16, 2013, 4:41:06 AM2/16/13
to
Hi
I am sorry for the delay. I haven't been here for a few days.
I am sure that my solution is pretty clumsy, and that it should be easier, but after a lot of trying, this worked for me, though I cannot guarantee that it will work on your computer. It is shorter and more simple than it seems, I just tried to explain it in details, because I don't how much you know.
so these are the steps:
1. Open the command prompt (go to start and run a search for cmd).
2. Run a search on your computer for a file named vsvars32.bat.
3. After you found it, with right click, open its properties and copy its path.
4. Go to the command prompt and run the command:
cd paste here the path of vsvars32.bat
on my computer it looks like that:
cd C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\Tools
and press enter. (cd = change directory)
5. after that, go to the location of the file vsvars32.bat ,and put there
the CUDA file (file with .cu suffix) that you want to compile.
6. Run a search on your computer for a file named cl.exe. I found a few with that
name. I guess you should take the one that is associated with
visual studio 2010.
when you find the file, copy it also to the directory with vsvars32.bat
and the CUDA file.
7. Now that the CUDA file and vsvars32.bat file and cl.exe file are all in the same
location and you changed the directory in the command prompt to this
location (with the cd command), go to the command prompt and run the
following command:
nvcc -ptx cuda_file_name.cu

of course that you should change the cuda_file_name in this command
to the name of your CUDA file. and press enter.
8. If it was successful, the PTX file should appear now in the same location with
the vsvars32.bat, the CUDA file and the cl.exe file.

I hope it helped.
Ask again if something is unclear.

"Dhanya Pankaj" wrote in message <kffj9p$924$1...@newscl01ah.mathworks.com>...

srira...@gmail.com

unread,
May 28, 2014, 2:47:56 AM5/28/14
to
use this format its works.
0 new messages