How to fix error : unrecognized token in Cuda code with nvcc compiler

I wrote this simple code Cuda in Notepad, which I followed in example: http://www.mathworks.com/help/distcomp/executing-cuda-or-ptx-code-on-the-gpu.html
_global_ void add1( double * pi, double c ) { *pi += c; }
>>then I run it on command line in the current directory: nvcc test.cu I received error with a lot of line "error : unrecognized token"
I don't know what is it and how to fix it. Please help me! I use Cuda 5.0, GPU 720M with Cuda-capable 2.0 Thanks!

 採用された回答

Ben Tordoff
Ben Tordoff 2013 年 7 月 26 日

0 投票

There are two problems with what you have attempted, one just a typo and the solution to the other will depend on what you are trying to do. First the typo: you are missing an underscore from each side of the global decorator - they should be double underscores:
__global__ void add1(double * pi, double c)
{
*pi += c;
}
Now the more important question: what are you trying to achieve? If you are trying to create a PTX file for use with parallel.gpu.CUDAKernel then you need to compile to PTX:
$ nvcc -ptx -arch=sm_20 <filename>.cu
which will procude <filename>.ptx. If you are trying to make a standalone executable then you need to also define a main function as you would for any C++ program.

4 件のコメント

HongTu Nguyen
HongTu Nguyen 2013 年 7 月 28 日
Thanks for your answer!
But...I corrected it, it's still that error? I don't know what the reason? :(
I just want to compile this file to use in Matlab.
I use Cuda version 5.0, GPU Geforce 720M with Matlab R2012b
Ben Tordoff
Ben Tordoff 2013 年 7 月 29 日
Can you post what the code now looks like, the new command you used to compile it and what the error was?
HongTu Nguyen
HongTu Nguyen 2013 年 7 月 29 日
Here is my code (I wrote it following the instruction of website: http://www.mathworks.com/help/distcomp/executing-cuda-or-ptx-code-on-the-gpu.html)
__global__ void add1( double * pi, double c )
{
*pi += c;
}
I saved it in notepad named: test.cu Then I compiled it in command line, with command:
>>nvcc -ptx test.cu
or I try to use your command:
>>nvcc -ptx -arch=sm_20 test.cu
It has the same error, and the error shows the same picture I've posted.
I do what's wrong? Please help me.
Thanks!
HongTu Nguyen
HongTu Nguyen 2013 年 7 月 29 日
編集済み: HongTu Nguyen 2013 年 7 月 29 日
Oh...I'm sorry...I'm so silly...
I've created the new notepad file and wrote it again myself.
And it's ok!
I think the old file I copy from website, so it had something wrong :(
Many thanks for your help!
Then...I have question:
**The command: nvcc -ptx -arch=sm_20 < filename.cu>
What "-arch=sm_20" mean?
**And when I compile by command: nvcc -ptx < filenam.cu> (not -arch=sm_20), it still creates test.ptx file.
>>so what is difference?
**And then, when I compile by command: nvcc < filenam.cu>, it has error look like:

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange で GPU Computing についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by