I can't figure out how to get clang CUDA specific flags for only CUDA files:
# building all except 20
set(BUILD_CUDA_ARCH "30;32;35;50;52;53")
# According to the docs, we need static cudart:
# http://llvm.org/docs/CompileCudaWithLLVM.html#compiling-cuda-code
list(APPEND EXTRA_LIBS "cudart_static")
# Let clang know exactly where cuda came from
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --cuda-path=${CUDA_TOOLKIT_ROOT_DIR}")
# Add the compilation trajectories for different architectures
# go to the docs linked above
foreach(arch ${BUILD_CUDA_ARCH})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --cuda-gpu-arch=sm_${arch}")
endforeach()
# Add the executable like normal, now that CMAKE_CXX_FLAGS has been adjusted.
# clang will compile the .cu files separately
add_library(${LIB_NAME} ${LIBRARY_TYPE} ${CXX_INC} ${CXX_SRC} ${CUDA_INC} ${CUDA_SRC})
Where elsewhere in the file is defined
LIB_NAME: the name of the library being builtLIBRARY_TYPE: eitherSHAREDorSTATICCXX_INCandCXX_SRC: pure C++ headers / source codeCUDA_INCandCUDA_SRC: straight CUDA codeEXTRA_LIBS: just used intarget_link_librarieswith other stuff
The problem is that this approach results in:
clang-4.0: warning: argument unused during compilation: '--cuda-gpu-arch=sm_30' [-Wunused-command-line-argument]
clang-4.0: warning: argument unused during compilation: '--cuda-gpu-arch=sm_32' [-Wunused-command-line-argument]
clang-4.0: warning: argument unused during compilation: '--cuda-gpu-arch=sm_35' [-Wunused-command-line-argument]
clang-4.0: warning: argument unused during compilation: '--cuda-gpu-arch=sm_50' [-Wunused-command-line-argument]
clang-4.0: warning: argument unused during compilation: '--cuda-gpu-arch=sm_52' [-Wunused-command-line-argument]
clang-4.0: warning: argument unused during compilation: '--cuda-gpu-arch=sm_53' [-Wunused-command-line-argument]
warnings for every non-cuda compilation. Do I have to separate this out into two separate libraries, or is there some way of telling clang? The linked docs in the comments seem to indicate that it should only be doing cuda stuff with .cu files, but I can't seem to find specific flags for only that mode. It feels awkward to split it into two libraries with how things are split up logically - the CPU version includes different files that effectively do the same thing w/o the gpu.