CMake + Cuda: compile cpp files in Cuda mode (-x = cu)

Suppose I have a file, call it foo.cpp , my goal is to compile this file using nvcc in cuda mode. This can be easily done from the command line by calling:

nvcc --x=cu foo.cpp

What I'm struggling with is to get CMake to do it the exact same way. It turns out that the CMake cuda_add_executable(foo foo.cpp) will filter * .cpp files and use the C ++ compiler (instead of nvcc).

Please note that renaming all files to * .cu is not an option, since the code base must also support non-cuda assemblies. A.

+5
source share
1 answer

In FindCUDA source code, I found the ability to activate CUDA compilation for certain non .cu . Although it seems that the documentation is not enough (outside the source code).

You can configure file-level CUDA compilation with

 set_source_files_properties( foo.cpp PROPERTIES CUDA_SOURCE_PROPERTY_FORMAT OBJ ) 

in CMAKE 3.3 or later.

The rest works as usual:

 cuda_add_executable(foo foo.cpp) 

Actually, I expected that there should be a simple solution, for example, to use CUDA_NVCC_FLAGS or cuda_add_executable( ... OPTIONS --x=cu ) to pass the flag --x=cu . Unfortunately, it does not work. The reason is probably because the installation area at this level will not be useful, as it will affect all files.

+4
source

Source: https://habr.com/ru/post/1245114/


All Articles