I am using gcc 14.2.1 on my Arch linux machine, with CMake version 3.30. After I upgrading cuda toolkit to 12.8 I cannot use CMake with cuda anymore.
In a simple example, CMakeLists like this
cmake_minimum_required(VERSION 3.30)
project(demo)
enable_language(CXX CUDA)
add_executable(demo demo.cu)
and demo.cu
#include <cuda_runtime.h>
#include <cstdio>
int main() {
printf("hello!\n");
}
the cmake config step failed with the following error message:
CMake Error at /usr/share/cmake/Modules/CMakeDetermineCompilerId.cmake:865 (message):
Compiling the CUDA compiler identification source file
"CMakeCUDACompilerId.cu" failed.
Compiler: /opt/cuda/bin/nvcc
Build flags:
Id flags: --keep;--keep-dir;tmp -v
The output was:
1
nvcc warning : Support for offline compilation for architectures prior to
'<compute/sm/lto>_75' will be removed in a future release (Use
-Wno-deprecated-gpu-targets to suppress warning).
#$ _NVVM_BRANCH_=nvvm
#$ _SPACE_=
#$ _CUDART_=cudart
#$ _HERE_=/opt/cuda/bin
#$ _THERE_=/opt/cuda/bin
#$ _TARGET_SIZE_=
#$ _TARGET_DIR_=
#$ _TARGET_DIR_=targets/x86_64-linux
#$ TOP=/opt/cuda/bin/..
#$ CICC_PATH=/opt/cuda/bin/../nvvm/bin
#$ NVVMIR_LIBRARY_DIR=/opt/cuda/bin/../nvvm/libdevice
#$ LD_LIBRARY_PATH=/opt/cuda/bin/../lib:
#$
PATH=/opt/cuda/bin/../nvvm/bin:/opt/cuda/bin:/opt/anaconda/bin:/opt/anaconda/condabin:/home/creeper/.cargo/bin:/home/creeper/.nix-profile/bin:/nix/var/nix/profiles/default/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/opt/anaconda/bin:/opt/cuda/bin:/opt/cuda/nsight_compute:/opt/cuda/nsight_systems/bin:/var/lib/flatpak/exports/bin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:/home/creeper/.local/share/JetBrains/Toolbox/scripts:/home/creeper/nsight-systems-2024.6.1/bin:/usr/local/NVIDIA-Nsight-Compute-2024.3
#$ INCLUDES="-I/opt/cuda/bin/../targets/x86_64-linux/include"
#$ LIBRARIES= "-L/opt/cuda/bin/../targets/x86_64-linux/lib/stubs"
"-L/opt/cuda/bin/../targets/x86_64-linux/lib"
#$ CUDAFE_FLAGS=
#$ PTXAS_FLAGS=
#$ rm tmp/a_dlink.reg.c
#$ "/usr/bin"/g++-13 -D__CUDA_ARCH_LIST__=520 -D__NV_LEGACY_LAUNCH -E -x
c++ -D__CUDACC__ -D__NVCC__
"-I/opt/cuda/bin/../targets/x86_64-linux/include" -D__CUDACC_VER_MAJOR__=12
-D__CUDACC_VER_MINOR__=8 -D__CUDACC_VER_BUILD__=61
-D__CUDA_API_VER_MAJOR__=12 -D__CUDA_API_VER_MINOR__=8
-D__NVCC_DIAG_PRAGMA_SUPPORT__=1 -D__CUDACC_DEVICE_ATOMIC_BUILTINS__=1
-include "cuda_runtime.h" -m64 "CMakeCUDACompilerId.cu" -o
"tmp/CMakeCUDACompilerId.cpp4.ii"
#$ cudafe++ --c++17 --gnu_version=130301 --display_error_number
--orig_src_file_name "CMakeCUDACompilerId.cu" --orig_src_path_name
"/home/creeper/demo/build/CMakeFiles/3.31.2/CompilerIdCUDA/CMakeCUDACompilerId.cu"
--allow_managed --m64 --parse_templates --gen_c_file_name
"tmp/CMakeCUDACompilerId.cudafe1.cpp" --stub_file_name
"CMakeCUDACompilerId.cudafe1.stub.c" --gen_module_id_file
--module_id_file_name "tmp/CMakeCUDACompilerId.module_id"
"tmp/CMakeCUDACompilerId.cpp4.ii"
#$ "/usr/bin"/g++-13 -D__CUDA_ARCH__=520 -D__CUDA_ARCH_LIST__=520
-D__NV_LEGACY_LAUNCH -E -x c++ -DCUDA_DOUBLE_MATH_FUNCTIONS -D__CUDACC__
-D__NVCC__ "-I/opt/cuda/bin/../targets/x86_64-linux/include"
-D__CUDACC_VER_MAJOR__=12 -D__CUDACC_VER_MINOR__=8
-D__CUDACC_VER_BUILD__=61 -D__CUDA_API_VER_MAJOR__=12
-D__CUDA_API_VER_MINOR__=8 -D__NVCC_DIAG_PRAGMA_SUPPORT__=1
-D__CUDACC_DEVICE_ATOMIC_BUILTINS__=1 -include "cuda_runtime.h" -m64
"CMakeCUDACompilerId.cu" -o "tmp/CMakeCUDACompilerId.cpp1.ii"
#$ "$CICC_PATH/cicc" --c++17 --gnu_version=130301 --display_error_number
--orig_src_file_name "CMakeCUDACompilerId.cu" --orig_src_path_name
"/home/creeper/demo/build/CMakeFiles/3.31.2/CompilerIdCUDA/CMakeCUDACompilerId.cu"
--allow_managed -arch compute_52 -m64 --no-version-ident -ftz=0 -prec_div=1
-prec_sqrt=1 -fmad=1 --include_file_name "CMakeCUDACompilerId.fatbin.c"
-tused --module_id_file_name "tmp/CMakeCUDACompilerId.module_id"
--gen_c_file_name "tmp/CMakeCUDACompilerId.cudafe1.c" --stub_file_name
"tmp/CMakeCUDACompilerId.cudafe1.stub.c" --gen_device_file_name
"tmp/CMakeCUDACompilerId.cudafe1.gpu" "tmp/CMakeCUDACompilerId.cpp1.ii" -o
"tmp/CMakeCUDACompilerId.ptx"
#$ ptxas -arch=sm_52 -m64 "tmp/CMakeCUDACompilerId.ptx" -o
"tmp/CMakeCUDACompilerId.sm_52.cubin"
#$ fatbinary --create="tmp/CMakeCUDACompilerId.fatbin" -64
--cicc-cmdline="-ftz=0 -prec_div=1 -prec_sqrt=1 -fmad=1 "
"--image3=kind=elf,sm=52,file=tmp/CMakeCUDACompilerId.sm_52.cubin"
"--image3=kind=ptx,sm=52,file=tmp/CMakeCUDACompilerId.ptx"
--embedded-fatbin="tmp/CMakeCUDACompilerId.fatbin.c"
#$ "/usr/bin"/g++-13 -D__CUDA_ARCH__=520 -D__CUDA_ARCH_LIST__=520
-D__NV_LEGACY_LAUNCH -c -x c++ -DCUDA_DOUBLE_MATH_FUNCTIONS -Wno-psabi
"-I/opt/cuda/bin/../targets/x86_64-linux/include" -m64
"tmp/CMakeCUDACompilerId.cudafe1.cpp" -o "tmp/CMakeCUDACompilerId.o"
In file included from
/opt/cuda/targets/x86_64-linux/include/crt/math_functions.h:5978,
from /opt/cuda/targets/x86_64-linux/include/crt/common_functions.h:303,
from /opt/cuda/bin/../targets/x86_64-linux/include/crt/host_runtime.h:285,
from tmp/CMakeCUDACompilerId.cudafe1.stub.c:8,
from CMakeCUDACompilerId.cudafe1.stub.c:1:
/opt/cuda/targets/x86_64-linux/include/crt/math_functions.h:5990:1: error:
declaration of ‘double sinpi(double)’ has a different exception
specifier
5990 | __func__(double sinpi(double a));
| ^~~~~~~~
/opt/cuda/bin/../targets/x86_64-linux/include/crt/math_functions.h:2556:15:
note: from previous declaration ‘double sinpi(double) noexcept’
2556 | extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ double sinpi(double x) noexcept (true);
| ^~~~~
/opt/cuda/targets/x86_64-linux/include/crt/math_functions.h:5992:1: error:
declaration of ‘double cospi(double)’ has a different exception
specifier
5992 | __func__(double cospi(double a));
| ^~~~~~~~
/opt/cuda/bin/../targets/x86_64-linux/include/crt/math_functions.h:2601:15:
note: from previous declaration ‘double cospi(double) noexcept’
2601 | extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ double cospi(double x) noexcept (true);
| ^~~~~
/opt/cuda/targets/x86_64-linux/include/crt/math_functions.h:6010:1: error:
declaration of ‘float sinpif(float)’ has a different exception
specifier
6010 | __func__(float sinpif(float a));
| ^~~~~~~~
/opt/cuda/bin/../targets/x86_64-linux/include/crt/math_functions.h:2579:14:
note: from previous declaration ‘float sinpif(float) noexcept’
2579 | extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ float sinpif(float x) noexcept (true);
| ^~~~~~
/opt/cuda/targets/x86_64-linux/include/crt/math_functions.h:6012:1: error:
declaration of ‘float cospif(float)’ has a different exception
specifier
6012 | __func__(float cospif(float a));
| ^~~~~~~~
/opt/cuda/bin/../targets/x86_64-linux/include/crt/math_functions.h:2623:14:
note: from previous declaration ‘float cospif(float) noexcept’
2623 | extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ float cospif(float x) noexcept (true);
| ^~~~~~
# --error 0x1 --
Call Stack (most recent call first):
/usr/share/cmake/Modules/CMakeDetermineCompilerId.cmake:8 (CMAKE_DETERMINE_COMPILER_ID_BUILD)
/usr/share/cmake/Modules/CMakeDetermineCompilerId.cmake:53 (__determine_compiler_id_test)
/usr/share/cmake/Modules/CMakeDetermineCUDACompiler.cmake:131 (CMAKE_DETERMINE_COMPILER_ID)
CMakeLists.txt:3 (enable_language)
From the description, I guessed that it was because math_functions.h
included by CMakeCUDACompilerId.cu failed to compile. So I reinstalled cuda 12.8 several times using sudo pacman -S cuda
but this cannot solve the problem. What might be the cause and how to solve it?