MATLAB Answers

Darryl
0

Executing CUDA or PTX Code on the GPU

Asked by Darryl
on 18 May 2011
Hello,
I have a question regarding to CUDA code on the GPU.
I use Matlab 2011a parallel tool kit trial version, VS 2008 and CUDA 3.2.
I just tried to compile the sample CUDA code from parallel tool kit tutorial. (Following is the CUDA kernel code)
File name: test.cu global void add1( double * pi, double c ) { *pi += c; }
I just tried to compile by using following command as described in tutorial.
nvcc -ptx test.cu
but it showed me following error message.
nvcc fatal : Visual Studio configuration file 'vsvars32.bat' could not be foun d for installation at './../../..'
I could fix this error message by using following command
nvcc -ccbin "C:\Program Files (x86)\Mic rosoft Visual Studio 9.0\VC\bin" -I"C:\Program Files (x86)\NVIDIA GPU Computing Toolkit\CUDA\v3.2\include" -ptx test.cu
Then, I could get the test.ptx file and
I just tried to excute this file by using following command.
k=parallel.gpu.CUDAKernel('test.ptx', 'test.cu');
But, it is not runnable. I see this error message.
Could you tell me what should I do to run this code?
??? Error using ==> iCheckPTXEntryAgainstCProto at 384 The number of inputs to the PTX code (2) is NOT the same as the number of inputs in the C prototype (0)
Error in ==> C:\Program Files\MATLAB\R2011a\toolbox\distcomp\gpu\+parallel\+internal\+gpu\handleKernelArgs.p>handleKernelArgs at 81

  0 Comments

Sign in to comment.

3 Answers

Edric Ellis 님의 답변 19 May 2011

I'm not quite sure why that's failing, but you may be able to work around that by constructing the kernel like so:
k = parallel.gpu.CUDAKernel( 'test.ptx', 'double *, double' )
(The formatting of your "test.cu" is hasn't come out right above - we attempt to parse the prototype from the .cu code, and perhaps something is confusing our parsing...)

  3 Comments

I tried to attemp as you said, but it shows following error message.
??? Error using ==> iCheckPTXEntryAgainstCProto at 411
Expected pointer type but found .u32
Error in ==> C:\Program
Files\MATLAB\R2011a\toolbox\distcomp\gpu\+parallel\+internal\+gpu\handleKernelArgs.p>handleKernelArgs at 81
Do you think this is because I am using a trial version?
It should have nothing to do with a trial version. Also, if you're running on a 64-bit platform, you might need to compile the PTX in 64-bit mode by adding "-m 64" to your nvcc command-line
Thanks!!! -m 64 was the right method to solve this program!

Sign in to comment.


Gaszton 님의 답변 19 May 2011

"??? Error using ==> iCheckPTXEntryAgainstCProto at 384 The number of inputs to the PTX code (2) is NOT the same as the number of inputs in the C prototype (0)"
i got this error when my .ptx file was not recomplied after modifying the .cu source file
Other tip: I suggest you, to modify the nvcc profile file, located here: ...\NVIDIA GPU Computing Toolkit\CUDA\v3.2\bin\
put this extras in it:
#
# Location of Microsoft Visual Studio compiler
#
compiler-bindir = d:\Programs\Microsoft Visual Studio 9.0\VC\bin
include-path = "d:\Programs\Microsoft Visual Studio 9.0\VC\include"
(Copy paste the path of your VStudio folder)
I dont know why, but the "include-path" has no effect, so you still have to specify the VS include directory to nvcc.
I you want to avoid typing it in the cmd, create a .bat batch file:
@ECHO OFF
cmd /k nvcc -I "D:\programs\Microsoft Visual Studio 9.0\VC\include" -gencode=arch=compute_20,code=\"sm_21,compute_20\" -ptx yourcudacode.cu

  1 Comment

I checked the compiling. I recompiled if there is any modification in the code. I tried as what you said.
I don't know why, but it stil keep showing the error message.
??? Error using ==> iCheckPTXEntryAgainstCProto at 384
The number of inputs to the PTX code (2) is NOT the same as the number of inputs in the C prototype (0)
Error in ==> C:\Program
Files\MATLAB\R2011a\toolbox\distcomp\gpu\+parallel\+internal\+gpu\handleKernelArgs.p>handleKernelArgs at 81

Sign in to comment.


King Fisher 님의 답변 27 Nov 2011

I have exactly the same problem :(

  0 Comments

Sign in to comment.