CUDA: Clang fails due to GNU extensions flag -std=gnu++17
When using clang++
as the CMAKE_CUDA_COMPILER
and CMAKE_CUDA_STANDARD 17
CMake enables GNU language extensions via -std=gnu++17
and as a result CMake fails with
-- Check for working CUDA compiler: /home/bloring/work/llvm/llvm-install/bin/clang++ - broken
CMake Error at /usr/share/cmake/Modules/CMakeTestCUDACompiler.cmake:100 (message):
The CUDA compiler
"/home/bloring/work/llvm/llvm-install/bin/clang++"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: /work/SENSEI/HAMR/bin_cpu/CMakeFiles/CMakeScratch/TryCompile-hL0tKr
Run Build Command(s):/usr/bin/cmake -E env VERBOSE=1 /bin/gmake -f Makefile cmTC_027ff/fast && /bin/gmake -f CMakeFiles/cmTC_027ff.dir/build.make CMakeFiles/cmTC_027ff.dir/build
gmake[1]: Entering directory '/work/SENSEI/HAMR/bin_cpu/CMakeFiles/CMakeScratch/TryCompile-hL0tKr'
Building CUDA object CMakeFiles/cmTC_027ff.dir/main.cu.o
/home/bloring/work/llvm/llvm-install/bin/clang++ -std=gnu++17 --cuda-gpu-arch=sm_52 --cuda-path=/usr/local/cuda-12.0 -fPIE -MD -MT CMakeFiles/cmTC_027ff.dir/main.cu.o -MF CMakeFiles/cmTC_027ff.dir/main.cu.o.d -x cuda -c /work/SENSEI/HAMR/bin_cpu/CMakeFiles/CMakeScratch/TryCompile-hL0tKr/main.cu -o CMakeFiles/cmTC_027ff.dir/main.cu.o
clang++: warning: CUDA version is newer than the latest partially supported version 11.8 [-Wunknown-cuda-version]
In file included from <built-in>:1:
In file included from /home/bloring/work/llvm/llvm-install/lib/clang/17/include/__clang_cuda_runtime_wrapper.h:41:
In file included from /home/bloring/work/llvm/llvm-install/lib/clang/17/include/cuda_wrappers/cmath:27:
In file included from /usr/lib/gcc/x86_64-redhat-linux/12/../../../../include/c++/12/cmath:47:
/usr/lib/gcc/x86_64-redhat-linux/12/../../../../include/c++/12/bits/std_abs.h:103:7: error: __float128 is not supported on this target
abs(__float128 __x)
^
/usr/lib/gcc/x86_64-redhat-linux/12/../../../../include/c++/12/bits/std_abs.h:102:3: error: __float128 is not supported on this target
__float128
^
/usr/lib/gcc/x86_64-redhat-linux/12/../../../../include/c++/12/bits/std_abs.h:103:18: note: '__x' defined here
abs(__float128 __x)
^
/usr/lib/gcc/x86_64-redhat-linux/12/../../../../include/c++/12/bits/std_abs.h:103:18: note: '__x' defined here
/usr/lib/gcc/x86_64-redhat-linux/12/../../../../include/c++/12/bits/std_abs.h:103:18: note: '__x' defined here
In file included from <built-in>:1:
In file included from /home/bloring/work/llvm/llvm-install/lib/clang/17/include/__clang_cuda_runtime_wrapper.h:41:
In file included from /home/bloring/work/llvm/llvm-install/lib/clang/17/include/cuda_wrappers/cmath:27:
In file included from /usr/lib/gcc/x86_64-redhat-linux/12/../../../../include/c++/12/cmath:1935:
In file included from /usr/lib/gcc/x86_64-redhat-linux/12/../../../../include/c++/12/bits/specfun.h:45:
In file included from /usr/lib/gcc/x86_64-redhat-linux/12/../../../../include/c++/12/bits/stl_algobase.h:64:
In file included from /usr/lib/gcc/x86_64-redhat-linux/12/../../../../include/c++/12/bits/stl_pair.h:60:
/usr/lib/gcc/x86_64-redhat-linux/12/../../../../include/c++/12/type_traits:436:39: error: __float128 is not supported on this target
struct __is_floating_point_helper<__float128>
^
In file included from <built-in>:1:
In file included from /home/bloring/work/llvm/llvm-install/lib/clang/17/include/__clang_cuda_runtime_wrapper.h:41:
In file included from /home/bloring/work/llvm/llvm-install/lib/clang/17/include/cuda_wrappers/cmath:27:
In file included from /usr/lib/gcc/x86_64-redhat-linux/12/../../../../include/c++/12/cmath:1935:
In file included from /usr/lib/gcc/x86_64-redhat-linux/12/../../../../include/c++/12/bits/specfun.h:45:
/usr/lib/gcc/x86_64-redhat-linux/12/../../../../include/c++/12/bits/stl_algobase.h:1048:21: error: __float128 is not supported on this target
__size_to_integer(__float128 __n) { return (long long)__n; }
^
4 errors generated when compiling for sm_52.
gmake[1]: *** [CMakeFiles/cmTC_027ff.dir/build.make:79: CMakeFiles/cmTC_027ff.dir/main.cu.o] Error 1
gmake[1]: Leaving directory '/work/SENSEI/HAMR/bin_cpu/CMakeFiles/CMakeScratch/TryCompile-hL0tKr'
gmake: *** [Makefile:127: cmTC_027ff/fast] Error 2
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:77 (enable_language)
-- Configuring incomplete, errors occurred!
Adding set(CMAKE_CUDA_EXTENSIONS OFF)
to my CMake lists works around this issue.
I see 2 issues with the current CMake behavior, 1) applying the GNU extensions with Clang is not safe thing to do as the above error illustrates the Clang CUDA compiler doesn't fully support the GNU extensions. 2) more generally when I set CMAKE_<LANG>_STANDARD XX
I am not expecting compiler specific extensions but rather the base standard. the default for compiler specific extensions to the language standard should be off, one needs to ask to get them not the other way.
cmake version 3.26.2 clang version 17.0.0