0
votes

I am trying to create a Cuda project in VisualStudio 2010. I have created one simple test .cu file which takes an array and adds 1 to all its element and sends the result back to the host.

I have added cudart.lib file to the Linker.

In the .cu code I have included #include cuda_runtime.h header.

But when I am trying to compile it, it's giving the two errors.

error C2065 :'threadIdx': undeclared identifier
error C2059: syntax error:'<'

After installing Nvidia Nsight Visual Studio edition and setting the item type of .cu file as CUDA C/C++,it starts giving two additional errors:

error D8003:missing source filename

error MSB3721: The command ""C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v4.2\bin\nvcc.exe" -gencode=arch=compute_10,code=\"sm_10,compute_10\" --use-local-env --cl-version 2010 -ccbin "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin" -I"C:\ProgramData\NVIDIA Corporation\NVIDIA GPU Computing SDK 4.2\C\common\inc" -I"C:\ProgramData\NVIDIA Corporation\NVIDIA GPU Computing SDK 4.2\shared\inc" -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v4.2\include" -G --keep-dir "Debug" -maxrregcount=0 --machine 32 --compile -g -Xcompiler "/EHsc /nologo /Od /Zi /MDd " -o "Debug\test.cu.obj" "\ucigrad.local\Users\AGill\My Documents\Visual Studio 2010\Projects\cudatest\cudatest\test.cu"" exited with code 2.

Please help me how to resolve it. I think there may be some issue with nvcc compiler in VS2010 but I'm not able to figure it out.

3
Also I am using CUDA 4.2.I have selected the Cuda 4.2 in the Build Customization option by right clicking on the project. - uci_grad
Are you linking the appropriate libraries? - Adam27X
Yeah I included the cudart.lib.Also when I set the Item Type of .cu file to CUDA C/C++,it gives two additional errors:D8003:missing source filename and error MSB3721. - uci_grad
You said, #include cuda_runtime.h but your real code has quotes around cuda_runtime.h, right? :) - Roger Dahl
Searching online for "error D8003:missing source filename" indicates that one thing that triggers it is mismatched quotes, for instance around preprocessor definitions. Can you give us the command line for cl? Property Pages | C/C++ | Command Line. - Roger Dahl

3 Answers

1
votes

The errors you get most likely indicate that you're not compiling your CUDA sources with NVCC. Make sure that you are, either by selecting the appropriate item type (CUDA C/C++) if you have installed the Visual Studio integration when installing the toolkit. Or make sure you have set up appropriate build rules for your sources.

4
votes

If you are annoyed by the IDE errors (which still lets your code work without errors) just like I was, try to do plain text search in the SDK`s include folder for the (seemingly) undefined symbols and you will find the right header to include in no time. "threadIdx" for example resides in "device_launch_parameters.h" header file.

0
votes
  1. There are 2 types of errors - Build errors and IDE errors. Check if build succeeded (you can ignore IDE errors)

  2. Try #include "cuda.h" (or with angle brackets)

  3. Re-building sometimes solves the problem