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?
Open the Visual Studio project, right click on the project name, and select Build Dependencies->Build Customizations..., then select the CUDA Toolkit version you would like to target. Alternatively, you can configure your project always to build with the most recently installed version of the CUDA Toolkit.
[Step1] Download CUDA Toolkit 10.2 from https://developer.nvidia.com/cuda-downloads [Step 2] Directly edit . vcxproj file and replace 10.1 with 10.2. [Step 3] In the project properties tab of VS2109, change the platform tool set value to 'Visual Studio 2019 (v142)'. [Step 4] Build!
Add a new source file to the project, as follows. In Solution Explorer, right-click the Source Files folder, point to Add, and then click New Item. In the Code node, click C++ File (. cpp), type a name for the file, and then click Add.
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!)
I can't go through it all at the moment but I think those steps are necessary:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With