To compile CUDA source files (
*.cu) in Visual Studio, a custom build rule is necessary. The following CUDA build rules are provided by NVIDIA:
Cuda.rules: This file is installed by the GPU Computing SDK (not the CUDA Toolkit). This is a general build rule that is applicable to all CUDA source files.
NvCudaRuntimeApi.rules and NvCudaRuntimeApi.vX.Y.rules: These files are installed by the CUDA Toolkit. This is a build rule applicable to CUDA source files that use the CUDA Runtime API.
NvCudaRuntimeApi.rules is applicable to any version of the Runtime API, while
NvCudaRuntimeApi.vX.Y.rules is specific to a version. For example,
NvCudaRuntimeApi.v3.2.rules is specific to CUDA 3.2.
NvCudaDriverApi.rules and NvCudaDriverApi.vX.Y.rules: These files are installed by the CUDA Toolkit. This is a build rule applicable to CUDA source files that use the CUDA Driver API.
NvCudaDriverApi.rules is applicable to any version of the Driver API, while
NvCudaDriverApi.vX.Y.rules is specific to a version. For example,
NvCudaDriverApi.v3.2.rules is specific to CUDA v3.2.
All these build rule files are installed into the
C:\Program Files\Microsoft Visual Studio 9.0\VC\VCProjectDefaults directory by the CUDA Toolkit or the GPU Computing SDK. In Visual Studio language, this is the
To add a CUDA build rule, right-click on the Project name in the Solution Explorer pane and choose Custom Build Rules. The above build rules should be visible in the Visual C++ Custom Build Rules Files dialog that pops up. Choose the build rule you want and compile the CUDA files.
Note: It is recommended to choose
NvCudaDriverApi.rules over the generic
Tried with: CUDA 3.2 and Visual Studio 2008.