I must be doing something horribly wrong to face this problem. This is currently the project’s structure:
project
|--CMakeLists.txt
|--app
| |-- CMakeLists.txt
| |-- test_cuda
| |--CMakeLists.txt
| |--test_cuda.cu
|--src
|--lib
|--doc
Inside app/CMakeLists:
add_subdirectory(test_cuda)
Inside app/test_cuda/CMakeLists.txt
find_package(CUDA REQUIRED)
if (CUDA_FOUND)
# CUDA falgs
include_directories(${CUDA_INCLUDE_DIRS})
set(ALL_CUDA_LIBS ${CUDA_LIBRARIES} ${CUDA_cusparse_LIBRARY} ${CUDA_cublas_LIBRARY})
set(LIBS ${LIBS} ${ALL_CUDA_LIBS})
set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS};--maxrregcount 32)
# set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS};-gencode arch=compute_70,code=sm_70)
# Link to executable
cuda_add_executable(test_cuda test_cuda.cu)
# set_target_properties(test_cuda PROPERTIES COMPILE_FLAGS "-DTHRUST_DEVICE_SYSTEM=THRUST_DEVICE_SYSTEM_CUDA")
set_target_properties(test_cuda PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
set_target_properties(test_cuda PROPERTIES CUDA_PROPAGATE_HOST_FLAGS OFF)
target_link_libraries(test_cuda ${LIBS} ${EXTRA_LIBS})
endif()
And then, test_cuda.cu:
#include <stdio.h>
// #include <iostream>
__global__
void kernel (void){
int main(void ) {
kernel<<<1,1>>>();
return 0;
If I leave commented, everything compiles fine. The moment I uncomment the errors are weird:
/projects/opt/centos7/gcc/6.4.0/include/c++/6.4.0/bits/stl_algobase.h(200): error: statement may not appear in a constexpr function
/projects/opt/centos7/gcc/6.4.0/include/c++/6.4.0/bits/stl_algobase.h(202): error: a constexpr function must contain exactly one return statement
/projects/opt/centos7/gcc/6.4.0/include/c++/6.4.0/bits/stl_algobase.h(224): error: statement may not appear in a constexpr function
/projects/opt/centos7/gcc/6.4.0/include/c++/6.4.0/bits/stl_algobase.h(226): error: a constexpr function must contain exactly one return statement
/projects/opt/centos7/gcc/6.4.0/include/c++/6.4.0/bits/stl_algobase.h(246): error: statement may not appear in a constexpr function
/projects/opt/centos7/gcc/6.4.0/include/c++/6.4.0/bits/stl_algobase.h(248): error: a constexpr function must contain exactly one return statement
/projects/opt/centos7/gcc/6.4.0/include/c++/6.4.0/bits/stl_algobase.h(268): error: statement may not appear in a constexpr function
/projects/opt/centos7/gcc/6.4.0/include/c++/6.4.0/bits/stl_algobase.h(270): error: a constexpr function must contain exactly one return statement
8 errors detected in the compilation of "/tmp/tmpxft_00003cf6_00000000-4_test_cuda.cpp4.ii".
CMake Error at test_cuda_generated_test_cuda.cu.o.Release.cmake:279 (message):
Error generating file
/home/qth20/develop/project/build/app/test_cuda/CMakeFiles/test_cuda.dir//./test_cuda_generated_test_cuda.cu.o
make[2]: *** [app/test_cuda/CMakeFiles/test_cuda.dir/test_cuda_generated_test_cuda.cu.o] Error 1
make[1]: *** [app/test_cuda/CMakeFiles/test_cuda.dir/all] Error 2
make: *** [all] Error 2
Any suggestions…?
what CUDA version?
It appears that the CUDA version you are using doesn’t like your host compiler setup.
Depending on which CUDA version you are using, gcc 6.4 may or may not be supported. And there may be other issues with the host compiler as well.
~$ nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Built on Fri_Nov__3_21:07:56_CDT_2017
Cuda compilation tools, release 9.1, V9.1.85
And it complains with gcc/5.4.0 as well:
[ 75%] Building NVCC (Device) object app/test_cuda/CMakeFiles/test_cuda.dir/test_cuda_generated_test_cuda.cu.o
/projects/opt/centos7/gcc/5.4.0/packages/gcc-5.4.0/include/c++/5.4.0/bits/stl_algobase.h(200): error: statement may not appear in a constexpr function
/projects/opt/centos7/gcc/5.4.0/packages/gcc-5.4.0/include/c++/5.4.0/bits/stl_algobase.h(202): error: a constexpr function must contain exactly one return statement
/projects/opt/centos7/gcc/5.4.0/packages/gcc-5.4.0/include/c++/5.4.0/bits/stl_algobase.h(224): error: statement may not appear in a constexpr function
/projects/opt/centos7/gcc/5.4.0/packages/gcc-5.4.0/include/c++/5.4.0/bits/stl_algobase.h(226): error: a constexpr function must contain exactly one return statement
/projects/opt/centos7/gcc/5.4.0/packages/gcc-5.4.0/include/c++/5.4.0/bits/stl_algobase.h(246): error: statement may not appear in a constexpr function
/projects/opt/centos7/gcc/5.4.0/packages/gcc-5.4.0/include/c++/5.4.0/bits/stl_algobase.h(248): error: a constexpr function must contain exactly one return statement
/projects/opt/centos7/gcc/5.4.0/packages/gcc-5.4.0/include/c++/5.4.0/bits/stl_algobase.h(268): error: statement may not appear in a constexpr function
/projects/opt/centos7/gcc/5.4.0/packages/gcc-5.4.0/include/c++/5.4.0/bits/stl_algobase.h(270): error: a constexpr function must contain exactly one return statement
CUDA 9.1 on CentOS 7 has no trouble compiling that with or without so I think CMake is getting in the way.
If you turn on verbose output from CMake and study the generated commands carefully, it may help to identify the issue.