Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

Visual Studio: Dependency for .cu Files

📅 2011-Feb-16 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ cuda, visual studio ⬩ 📚 Archive

Problem

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!

Solution

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:

 

Assume that Kernels/Foo.cu includes Kernels/FooKernel.h. To make the dependency between these files explicit:

  1. Right-click on Kernels/Foo.cu and choose Properties.

  2. In the Properties dialog, choose CUDA Runtime APISource Dependencies.

  3. 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 Kernels/

  4. 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


© 2022 Ashwin Nanjappa • All writing under CC BY-SA license • 🐘 @codeyarns@hachyderm.io📧