CUDA: Need a way to specify device link flags
CMake-3.10.2 on linux (Ubuntu LTS 18.04)
I have a static library and the following command:
enable_language(cuda)
add_library(lib SHARED sources...)
set_target_properties(lib PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
target_compile_options(lib
PUBLIC
# Maxwell Gen1
$<$<COMPILE_LANGUAGE:CUDA>:-gencode=arch=compute_50,code=sm_50>
# Maxwell Gen2
$<$<COMPILE_LANGUAGE:CUDA>:-gencode=arch=compute_52,code=sm_52>
# Pascal P100
$<$<COMPILE_LANGUAGE:CUDA>:-gencode=arch=compute_60,code=sm_60>
# Pascal
$<$<COMPILE_LANGUAGE:CUDA>:-gencode=arch=compute_61,code=sm_61>
# Volta
$<$<COMPILE_LANGUAGE:CUDA>:-gencode=arch=compute_70,code=compute_70>
)
# this seems to be needed at least on cmake-3.10
target_compile_options(lib
PUBLIC
$<$<COMPILE_LANGUAGE:CUDA>:-Xcompiler -fPIC>
)
The device link stage (setup using CMAKE_CUDA_DEVICE_LINK_LIBRARY CMakeCUDAInformation.cmake) however seems to not take those flags into account - those flags are ignored. If I however set those flags globally using
list(APPEND CMAKE_CUDA_FLAGS "-gencode=arch=compute_50,code=sm_50 -gencode=arch=compute_52,code=sm_52 -gencode=arch=compute_60,code=sm_60 -gencode=arch=compute_61,code=sm_61 -gencode=arch=compute_70,code=compute_70")
Then the flags are forwarded. If the flags are not forwarded, the cuda code is not going to work at all
Edited by Brad King