Visual Studio understands that if a C++ file includes a header file, then it means that the C++ file is dependent on that header file. That is, when the .h file is changed, Visual Studio recompiles the .cpp file.
Much like in C++, it is common in CUDA to spread the code across .cu and .h files. However, Visual Studio cannot understand the dependency between a .cu file and a .h file that it might include. Thus, when the .h file is changed, the .cu file is not recompiled!
The dependency between a given .cu file and the .h files it includes needs to be specified explicity to Visual Studio. Consider the Visual Studio solution shown below:
Kernels/FooKernel.h. To make the dependency between these files explicit:
Kernels/Foo.cu and choose Properties.
In the Properties dialog, choose CUDA Runtime API → Source Dependencies.
Add the files that
Kernels/Foo.cu depends on. For us, this is
Kernels/FooKernel.h. Make sure the path is correct, like I have done here by using
If there are multiple dependencies, separate them using semicolons (;). Using space, comma or anything else will be silently ignored with no errors!
Foo.cu should now be recompiled whenever
FooKernel.h is changed! 😊
Tried with: CUDA 3.2 and Visual Studio 2008