How to separately compile a kernel in Visual Studio

This is not a question, but rather something I learned and I want other developers to find the information if they look for it.

I created a VS project (VS 17) by copying a project file from one of the CUDA Samples, then removed the source files and added my own files. One file, Kernel.cu, contained kernel code, which I call in another file, Main.cu.

Things built and ran just fine, until one day I somehow changed the properties on Kernel.cu, from --compile to --cubin. I thought that since Kernel.cu contained no host code, only the global void Kernel (), then I didn’t need to create a host object file.

Well that was wrong. When I built the project, the host linker said that void Kernel () was missing. It seems that there’s no Kernel.cu.obj in the link step.

So the lesson is: If your file contains a kernel that will be referenced from host code elsewhere in the program, you must specify --compile in the Properties (CUDA/C++ : Common : Compilation Type).

[url=“NVCC :: CUDA Toolkit Documentation”]NVCC :: CUDA Toolkit Documentation