When trying to compile with CUDA I get the following error:
cmake .. -DIMRESH_DEBUG=ON -DCMAKE_CXX_COMPILER=$(which g++-4.9) -DCMAKE_C_COMPILER=$(which gcc-4.9) -DBUILD_DOC=OFF -DALPAKA_ACC_GPU_CUDA_ENABLE=ON
make
[ 16%] Built target alpaka
Scanning dependencies of target cupla
[ 25%] Linking CXX static library libcupla.a
[ 25%] Built target cupla
[ 33%] Building NVCC (Device) object CMakeFiles/imresh.dir/cupla/src/imresh_generated_stream.cpp.o
nvcc fatal : redefinition of argument 'std'
CMake Error at imresh_generated_stream.cpp.o.cmake:207 (message):
Error generating ./imresh/build/CMakeFiles/imresh.dir/cupla/src/./imresh_generated_stream.cpp.o
CMakeFiles/imresh.dir/build.make:112: recipe for target 'CMakeFiles/imresh.dir/cupla/src/imresh_generated_stream.cpp.o' failed
make[2]: *** [CMakeFiles/imresh.dir/cupla/src/imresh_generated_stream.cpp.o] Error 1
CMakeFiles/Makefile2:141: recipe for target 'CMakeFiles/imresh.dir/all' failed
make[1]: *** [CMakeFiles/imresh.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
I'm using CMake 3.4.1. I guess the problem is related to http://stackoverflow.com/questions/29121211/cuda-compilation-issue-with-cmake
CUDA_PROPAGATE_HOST_FLAGS is explicitly set to ON in alpakaConfig.cmake suggesting turning off won't be a good idea. It really isn't; when turning it off the following error occurs
[ 16%] Built target alpaka
[ 25%] Built target cupla
[ 33%] Building NVCC (Device) object CMakeFiles/imresh.dir/cupla/src/imresh_generated_stream.cpp.o
nvcc fatal : redefinition of argument 'gpu-architecture'
CMake Error at imresh_generated_stream.cpp.o.cmake:203 (message):
Error generating ./imresh/build/CMakeFiles/imresh.dir/cupla/src/./imresh_generated_stream.cpp.o
Could you please execute CMake in verbose mode and post the error message? Without the command line for the specific file, I can not say anything specific.
Are you manually setting the -std=c++XX compiler flag globally in your CMakeLists.txt? If yes, to which value?
Ah yes, I'm setting it manually, see here
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 -DNDEBUG -std=c++11 -fPIC -pthread ${OpenMP_CXX_FLAGS}")
I'm pretty sure the problem is something like this
nvcc -std=c++11 -std=c++11 file.cpp
I'll run CMake verbose later.
Yes, I thought the same.
Currently alpaka sets -std=c++11 internally for CUDA here and as general define here.
I can see that this could lead to problems in the future where users want to use c++14 or higher for host code. Such std settings conflicting with the alpaka one will certainly lead to compile errors. At least the second occurence should probably be deleted to let the user freedom to choose even higher standard versions.
Here is the output of
make VERBOSE=1
/opt/cuda-7.0/bin/nvcc -M -D__CUDACC__ "./imresh/cupla/src/stream.cpp" -o "./imresh/build/CMakeFiles/imresh.dir/cupla/src/imresh_generated_stream.cpp.o.NVCC-depend" -ccbin /usr/bin/g++-4.9 -m64 --std c++11 -DALPAKA_ACC_CPU_B_SEQ_T_OMP2_ENABLED -DALPAKA_ACC_GPU_CUDA_ENABLED -DALPAKA_DEBUG=0 -DIMRESH_DEBUG -Xcompiler ,\"-fopenmp\",\"-Wall\",\"-Wextra\",\"-Wshadow\",\"-Wno-unused-parameter\",\"-O2\",\"-g\",\"-fPIC\",\"-pthread\",\"-fopenmp\",\"-g\" -arch=sm_20 -std=c++11 --use_fast_math --ftz=false -Xcompiler -Wall,-Wextra,-Wshadow -G -lineinfo -Xptxas=-v -arch=sm_30 -DNVCC -I/opt/cuda-7.0/include "-I./imresh/src/imresh" -I/opt/cuda-7.0/include -I/usr/include "-I./imresh/cupla/alpaka/include" "-I./imresh/cupla/include"
nvcc fatal : redefinition of argument 'std'
CMake Error at imresh_generated_stream.cpp.o.cmake:207 (message):
Error generating ./imresh/build/CMakeFiles/imresh.dir/cupla/src/./imresh_generated_stream.cpp.o
Deleting all manual -std=c++11 set in CMAKE_CXX_FLAGS quelches the above error message, but gives me:
nvcc fatal : redefinition of argument 'gpu-architecture'
This is because I forgot to delete remnants of using find_package(CUDA), i.e. this line:
set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -arch=sm_30")
After deleting this line it begins to compile, but I get still other errors unrelated to this ticket, so I'm not 100% sure it will work.
My suggestion is, that alpaka checks wheter -std= was already set and if yes, then it doesn't set it itself (or if set to something smaller than c++11 it sets it to c++11). Checking arch in the same manner shouldn't be necessary, because this is an accelerator option which alpaka wants to hide in the first place.
Edit: Although I have to say, allowing to set CUDA_NVCC_FLAGS by the alpaka user could be helpful. In the moment I set it to
set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -Xcompiler -Wall,-Wextra,-Wshadow -G -lineinfo -Xptxas=-v")
Especially for getting information about register usage and the ptxas code could be needed in the future for debugging purposes. The options are not overwritten by alpaka in the moment.
Solved with #189
Most helpful comment
Here is the output of
Deleting all manual
-std=c++11set inCMAKE_CXX_FLAGSquelches the above error message, but gives me:This is because I forgot to delete remnants of using
find_package(CUDA), i.e. this line:After deleting this line it begins to compile, but I get still other errors unrelated to this ticket, so I'm not 100% sure it will work.
My suggestion is, that alpaka checks wheter
-std=was already set and if yes, then it doesn't set it itself (or if set to something smaller thanc++11it sets it toc++11). Checkingarchin the same manner shouldn't be necessary, because this is an accelerator option which alpaka wants to hide in the first place.Edit: Although I have to say, allowing to set
CUDA_NVCC_FLAGSby the alpaka user could be helpful. In the moment I set it toEspecially for getting information about register usage and the ptxas code could be needed in the future for debugging purposes. The options are not overwritten by alpaka in the moment.