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…?