Using CMake with NVidia's CUDA

Hello, I have a cuda file (.cu) which does not have a main point of entry. I am able to compile it on the terminal using nvcc and a bunch of nvcc compile options to a .cubin (CUDA binary).

Could someone please tell me how I can do that in CMake. I am able to go from .cu to .ptx (an intermediate object), but not .cu to .cubin. What commands do I have to use in my CMakeLists.txt. I know that you can either use FindCUDA (deprecated) or the built-in CUDA language support to use CUDA. I am using the built-in CUDA language support and CMake 3.17. What commands to I need to compile my .cu file to a .cubin.

Thank you.

1 Like

The built-in CUDA language support only offers .cu to .ptx and .cu to .obj support, it doesn’t offer .cu to .cubin.

You could use the support to go from .cu to .ptx and use something like custom POST_BUILD commands to transform the PTX files to .cubin

1 Like

Hi Robert,

Given your response and the fact that that --ptx option is not allowed when compiling for multiple GPU architectures. If a user wants to compile a fatbin for architectures, would that have to be accomplished with foreach or something?

This seems like a limitation to CMake… Can you provide any insight to why the functionality was removed from findCUDAToolkit?

If you are not interested in generating a full object file the best option is to have multiple targets with the same sources but different architectures specified.

Goal was to provide support for the common code generation types. PTX and full object files matched that goal. Nothing is stopping CMake from supporting fatbin generation it just hasn’t been a priority for contributors.