OpenMP Contaminates CUDA/NVCC build flags
Using gcc7, the required openmp flag is -fopenmp. The cuda9 compiler (and likely other versions) crashes with an error when it sees the flag. This is related to the treatment of flags here #15392.
- CMakeLists.txt
cmake_minimum_required(VERSION 3.8)
project(BROKE CXX CUDA)
add_executable(broke test.cc kernel.cu)
find_package(OpenMP)
if(OpenMP_CXX_FOUND)
target_link_libraries(broke PUBLIC OpenMP::OpenMP_CXX)
endif()
- test.cc
int main() { return 0; }
- kernel.cu
__global__ void kern(int n) { int m = threadIdx.x; }
- cmake .. && make
--
Properties for TARGET broke:
broke.INTERFACE_INCLUDE_DIRS = <NOTFOUND>
broke.INTERFACE_LINK_LIBRARIES = "OpenMP::OpenMP_CXX"
broke.COMPILE_DEFINITIONS = <NOTFOUND>
broke.INTERFACE_COMPILE_DEFINITIONS = <NOTFOUND>
broke.INTERFACE_COMPILE_OPTIONS = <NOTFOUND>
-- Configuring done
-- Generating done
-- Build files have been written to: $BROKE_DIR/build
[ 25%] Building CXX object CMakeFiles/broke.dir/test.cc.o
[ 50%] Building CUDA object CMakeFiles/broke.dir/kernel.cu.o
nvcc fatal : Unknown option 'fopenmp'
CMakeFiles/broke.dir/build.make:86: recipe for target 'CMakeFiles/broke.dir/kernel.cu.o' failed
make[2]: *** [CMakeFiles/broke.dir/kernel.cu.o] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/broke.dir/all' failed
make[1]: *** [CMakeFiles/broke.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2