Reputation: 2083
I am trying to add a CUDA file to my existing C++ Visual Studio project. I have the CUDA 5.0 SDK installed, I have created a new .cu file and also set its Item Type to CUDA/C++ in the CUDA file properties. But it looks like it just does not compile giving errors that say that the compiler does not recognize the CUDA keywords. One of the errors I get is:
error C2065: 'threadIdx' : undeclared identifier
Any suggestions?
Upvotes: 11
Views: 19136
Reputation: 1087
I found that the best way to do this is to perform the following in the existing CPU project
1) Build Dependencies -> Build Customisations
click the Cuda checkbox
2) Create a new simple CUDA project using the wizard (you anyway probably want to test your CUDA project builds ok firstly), load both projects into the IDE and then compare settings between the two projects, you will need to add the following in project settings
$(CudaToolkitLibDir) to additional libraries settings (linker tab) $(CudaToolkitIncludeDir) to additional include directories (c++ tab)
cudart.lib to additional dependencies (linker tab)
Then compare the CUDA tabs
I found that 32 bit had been pre-selected for the target machine architecture for some reason so I changed that to 64 bit.
After this I added a define _CUDA_CODE_COMPILE_ to preprocessor definitions to switch between CUDA or CPU compilation.
#ifdef _CUDA_CODE_COMPILE_
cudaCodeFunction();
#else
cpuCodeFunction();
#endif
Not ideal but necessary since there seem to be no defines set to indicate that NVCC is installed (other than performing a shell command!)
Upvotes: 8
Reputation: 24946
I can't go through it all at the moment but I think those steps are necessary:
Upvotes: 6
Reputation: 48330
You have to select the right Compiler for the .cu files
Are you following any of the tutorial on how to setup it on visual studio ?
http://blog.norture.com/2012/10/gpu-parallel-programming-in-vs2012-with-nvidia-cuda/
Upvotes: 0