<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/88695>88695</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[CUDA] Clang 17+ in CUDA mode does not compile with gnu extension and libstdc++
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
SimeonEhrig
</td>
</tr>
</table>
<pre>
Since Clang 17+, the default C++ standard of Clang for the CUDA mode is `gnu++17` [1]. But this does not compile together with the `libstdc++` because CUDA does not support float 128 bit.
```bash
$ touch empty.cu
$ clang++ -c empty.cu --cuda-gpu-arch=sm_52
In file included from <built-in>:1:
In file included from /opt/spack-modules/opt/spack/linux-ubuntu22.04-zen2/gcc-11.3.0/llvm-18.1.1-ulsiaj6fzcc36manvhg3rtgjy4z7w56d/lib/clang/18/include/__clang_cuda_runtime_wrapper.h:41:
In file included from /opt/spack-modules/opt/spack/linux-ubuntu22.04-zen2/gcc-11.3.0/llvm-18.1.1-ulsiaj6fzcc36manvhg3rtgjy4z7w56d/lib/clang/18/include/cuda_wrappers/cmath:27:
In file included from /opt/spack-modules/opt/spack/linux-ubuntu22.04-zen2/gcc-11.3.0/gcc-11.3.0-uhujaf27y72d4ic2yowfgz5slofuagt5/lib/gcc/x86_64-pc-linux-gnu/11.3.0/../../../../include/c++/11.3.0/cmath:47:
/opt/spack-modules/opt/spack/linux-ubuntu22.04-zen2/gcc-11.3.0/gcc-11.3.0-uhujaf27y72d4ic2yowfgz5slofuagt5/lib/gcc/x86_64-pc-linux-gnu/11.3.0/../../../../include/c++/11.3.0/bits/std_abs.h:103:7: error: __float128 is not supported on this target
103 | abs(__float128 __x)
| ^
/opt/spack-modules/opt/spack/linux-ubuntu22.04-zen2/gcc-11.3.0/gcc-11.3.0-uhujaf27y72d4ic2yowfgz5slofuagt5/lib/gcc/x86_64-pc-linux-gnu/11.3.0/../../../../include/c++/11.3.0/bits/std_abs.h:102:3: error: __float128 is not supported on this target
102 | __float128
| ^
/opt/spack-modules/opt/spack/linux-ubuntu22.04-zen2/gcc-11.3.0/gcc-11.3.0-uhujaf27y72d4ic2yowfgz5slofuagt5/lib/gcc/x86_64-pc-linux-gnu/11.3.0/../../../../include/c++/11.3.0/bits/std_abs.h:103:18: note: '__x' defined here
103 | abs(__float128 __x)
| ^
/opt/spack-modules/opt/spack/linux-ubuntu22.04-zen2/gcc-11.3.0/gcc-11.3.0-uhujaf27y72d4ic2yowfgz5slofuagt5/lib/gcc/x86_64-pc-linux-gnu/11.3.0/../../../../include/c++/11.3.0/bits/std_abs.h:103:18: note: '__x' defined here
/opt/spack-modules/opt/spack/linux-ubuntu22.04-zen2/gcc-11.3.0/gcc-11.3.0-uhujaf27y72d4ic2yowfgz5slofuagt5/lib/gcc/x86_64-pc-linux-gnu/11.3.0/../../../../include/c++/11.3.0/bits/std_abs.h:103:18: note: '__x' defined here
In file included from <built-in>:1:
In file included from /opt/spack-modules/opt/spack/linux-ubuntu22.04-zen2/gcc-11.3.0/llvm-18.1.1-ulsiaj6fzcc36manvhg3rtgjy4z7w56d/lib/clang/18/include/__clang_cuda_runtime_wrapper.h:41:
In file included from /opt/spack-modules/opt/spack/linux-ubuntu22.04-zen2/gcc-11.3.0/llvm-18.1.1-ulsiaj6fzcc36manvhg3rtgjy4z7w56d/lib/clang/18/include/cuda_wrappers/cmath:27:
In file included from /opt/spack-modules/opt/spack/linux-ubuntu22.04-zen2/gcc-11.3.0/gcc-11.3.0-uhujaf27y72d4ic2yowfgz5slofuagt5/lib/gcc/x86_64-pc-linux-gnu/11.3.0/../../../../include/c++/11.3.0/cmath:1935:
In file included from /opt/spack-modules/opt/spack/linux-ubuntu22.04-zen2/gcc-11.3.0/gcc-11.3.0-uhujaf27y72d4ic2yowfgz5slofuagt5/lib/gcc/x86_64-pc-linux-gnu/11.3.0/../../../../include/c++/11.3.0/bits/specfun.h:45:
In file included from /opt/spack-modules/opt/spack/linux-ubuntu22.04-zen2/gcc-11.3.0/gcc-11.3.0-uhujaf27y72d4ic2yowfgz5slofuagt5/lib/gcc/x86_64-pc-linux-gnu/11.3.0/../../../../include/c++/11.3.0/bits/stl_algobase.h:64:
In file included from /opt/spack-modules/opt/spack/linux-ubuntu22.04-zen2/gcc-11.3.0/gcc-11.3.0-uhujaf27y72d4ic2yowfgz5slofuagt5/lib/gcc/x86_64-pc-linux-gnu/11.3.0/../../../../include/c++/11.3.0/bits/stl_pair.h:59:
In file included from /opt/spack-modules/opt/spack/linux-ubuntu22.04-zen2/gcc-11.3.0/gcc-11.3.0-uhujaf27y72d4ic2yowfgz5slofuagt5/lib/gcc/x86_64-pc-linux-gnu/11.3.0/../../../../include/c++/11.3.0/bits/move.h:57:
/opt/spack-modules/opt/spack/linux-ubuntu22.04-zen2/gcc-11.3.0/gcc-11.3.0-uhujaf27y72d4ic2yowfgz5slofuagt5/lib/gcc/x86_64-pc-linux-gnu/11.3.0/../../../../include/c++/11.3.0/type_traits:415:39: error: __float128 is not supported on this target
415 | struct __is_floating_point_helper<__float128>
| ^
In file included from <built-in>:1:
In file included from /opt/spack-modules/opt/spack/linux-ubuntu22.04-zen2/gcc-11.3.0/llvm-18.1.1-ulsiaj6fzcc36manvhg3rtgjy4z7w56d/lib/clang/18/include/__clang_cuda_runtime_wrapper.h:41:
In file included from /opt/spack-modules/opt/spack/linux-ubuntu22.04-zen2/gcc-11.3.0/llvm-18.1.1-ulsiaj6fzcc36manvhg3rtgjy4z7w56d/lib/clang/18/include/cuda_wrappers/cmath:27:
In file included from /opt/spack-modules/opt/spack/linux-ubuntu22.04-zen2/gcc-11.3.0/gcc-11.3.0-uhujaf27y72d4ic2yowfgz5slofuagt5/lib/gcc/x86_64-pc-linux-gnu/11.3.0/../../../../include/c++/11.3.0/cmath:1935:
In file included from /opt/spack-modules/opt/spack/linux-ubuntu22.04-zen2/gcc-11.3.0/gcc-11.3.0-uhujaf27y72d4ic2yowfgz5slofuagt5/lib/gcc/x86_64-pc-linux-gnu/11.3.0/../../../../include/c++/11.3.0/bits/specfun.h:45:
/opt/spack-modules/opt/spack/linux-ubuntu22.04-zen2/gcc-11.3.0/gcc-11.3.0-uhujaf27y72d4ic2yowfgz5slofuagt5/lib/gcc/x86_64-pc-linux-gnu/11.3.0/../../../../include/c++/11.3.0/bits/stl_algobase.h:1049:21: error: __float128 is not supported on this target
1049 | __size_to_integer(__float128 __n) { return (long long)__n; }
| ^
4 errors generated when compiling for sm_52.
```
The bug is already fixed, if the `libstdc++` is installed via `apt` on Debian (based) systems, because the maintainer provides a patch which makes the `libstdc++` compatible with CUDA:
* https://bugs.launchpad.net/ubuntu/+source/glibc/+bug/1717257
* https://salsa.debian.org/toolchain-team/gcc/-/blob/32556e0c070cdd077a1289caa85d990080cd43c0/debian/patches/cuda-float128.diff
The major problem is, that CMake expected that the compiler works out of the box with it's default C++ standard, therefore the CMake CUDA compiler detection does not work with Clang 17+: https://gitlab.kitware.com/cmake/cmake/-/issues/25861
Is it possible to fix the bug in Clang/LLVM? Maybe by changing the default standard from `gnu++17` to `c++17`.
[1] https://reviews.llvm.org/D155539
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsWV1vqzoW_TXOy1YQGAjkIQ9pciJd6Z6nO3dekTEbcAs28kfT9NePbGia005HGh3NSOe0VZW0ZnvjtVjebFjMGNFJxB3J70h-XDFne6V3f4kRlfzWa9GtatVcdn8JyREOA5MdJAWhd4QewPYIDbbMDRYOYewOjGWyYboB1S7hrdIh8vD3cQ-jahCEAbKJO-nmOUlBNjGQ_C4h-TGCO2fB9sJAo9CAVBa4GicxIFjVoe1Rw1nYPuQkm3gQtbENn1P5RDVy5sxyvmsO46ZJaQvtoJiFhJZQCxuR-Eji_fK5ieffmpl-GaIZWOV4DzhO9hJx9zrOPbgF9JpfA2C95q5h625ya6Z5T9KjGauczhP_kNB6JELywTXYQKvVCCQ91E4Mdi0kSb-RdJ-QdP8fJ9CTmiyhJz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