Building with clang + CUDA 11.3.0 works but with CUDA 11.3.1 fails. Regression?

The following file

// t2.cu
template<typename T>
struct __numeric_traits_integer
{
  static const bool __is_signed = true;

  static const bool bar = __is_signed;
};

Cannot be built with clang with nvcc from CUDA 11.3.1

$ /opt/cuda/bin/nvcc --version                                                                        
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2021 NVIDIA Corporation
Built on Mon_May__3_19:15:13_PDT_2021
Cuda compilation tools, release 11.3, V11.3.109
Build cuda_11.3.r11.3/compiler.29920130_0

$ /opt/cuda/bin/nvcc -std=c++14 -ccbin=/usr/bin/clang -c t2.cu -o /dev/null
t2.cu(4): warning: __is_signed is no longer a keyword from this point

t2.cu(6): error: expected a "("

t2.cu(6): error: expected a type specifier

t2.cu(6): error: expected a ")"

3 errors detected in the compilation of "t2.cu".

The issue seems related to the identifier __is_signed. If I replace it with something else (e.g., one more leading underscore), compiling works:

/opt/cuda/bin/nvcc -D__is_signed=___is_signed -std=c++14 -ccbin=/usr/bin/clang -c t2.cu -o /dev/null

The same file builds fine with the same nvcc command from CUDA 11.3.0.

$ /opt/cuda/bin/nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2021 NVIDIA Corporation
Built on Sun_Mar_21_19:15:46_PDT_2021
Cuda compilation tools, release 11.3, V11.3.58
Build cuda_11.3.r11.3/compiler.29745058_0

$ /opt/cuda/bin/nvcc -std=c++14 -ccbin=/usr/bin/clang -c t2.cu -o /dev/null          
t2.cu:4:19: warning: keyword '__is_signed' will be made available as an identifier for the remainder of the translation unit [-Wkeyword-compat]
static const bool __is_signed = true; 
                  ^
1 warning generated.

Is it a regression?

I got this issue when I was building onnxruntime 1.8.0 on Arch Linux. GCC crashes with internal compiler errors at some other files, so I tried clang. The struct in t2.cu is from <ext/numeric_traits.h> of libstdc++, which is in turn included by <bits/stl_algobase.h> and <algorithm>. Complete build logs can be found at here

System environment:

  • Arch Linux up-to-date
  • gcc 11.1.0
  • clang 12.0.0

The latest clang that is supported with CUDA 11.3.1 is 11.0. You’re using an unsupported build combination for CUDA 11.3.1 (also an unsupported linux OS for CUDA development). Also I think it may be recommended to use the llvm version of libc++ with clang, rather than the libstdc++ that ships with gnu compilers.

1 Like

Thanks a lot for the hints! I tried this file with Clang 11 on Ubuntu 18.04.7, and it works fine with libstdc++!

$ cat t.cu
#include <algorithm>

$ "$PWD/cuda-11.3/bin/nvcc" --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2021 NVIDIA Corporation
Built on Mon_May__3_19:15:13_PDT_2021
Cuda compilation tools, release 11.3, V11.3.109
Build cuda_11.3.r11.3/compiler.29920130_0

$ "$PWD/cuda-11.3/bin/nvcc" -std=c++14 -ccbin "$PWD/clang+llvm-11.0.1-x86_64-linux-gnu-ubuntu-16.04/bin/clang" -c t.cu

$ ls t.o 
t.o

Looking at libstdc++ on Ubuntu 16.04, it’s from GCC 7.5 and its <ext/numeric_traits.h> is slightly different from the one in libstdc++ from GCC 11.0. I guess this is instead an regression in libstdc++. I will ask there.

Didn’t tried libc++ - there are many differences between those two C++ libraries and I don’t think it will work with big projects like onnxruntime.

I have the same problem with CUDA 11.4, which does support (supposedly) Clang 12.