1

I am trying to compile with the CUDA toolkit on my Debian GNU/Linux system, but even in extremely simple programs, C++11 support is apparently broken.

Firstly, here is a list of relevant software versions:

  • Linux kernel: 4.13.0
  • CUDA toolkit: 8.0.61
  • Clang: 3.8.1
  • libc: 2.25
  • libstdc++: 7.2.0

Using a really basic test file, test.cu, as below:

__global__ void testfunc(float *a, float *b, int N)
{
    for (int i = 0; i < N; ++i) {
        b[i] += a[i];
    }
}

And compiling with the command:

nvcc -ccbin clang-3.8 -std c++11 -o test test.cu

I get a long list of declaration conflicts with target of using declaration already in scope errors. I'll show two below - it cut off automatically at 20.

/usr/include/math_functions.h:8925:41: error: declaration conflicts with target of using declaration already in scope
__attribute((always_inline)) inline int signbit(float x);
                                        ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/cmath:668:16: note: target of using declaration
constexpr bool signbit(float __x)
               ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/math.h:68:12: note: using declaration
using std::signbit;
           ^
/usr/include/math_functions.h:8929:41: error: declaration conflicts with target of using declaration already in scope
__attribute((always_inline)) inline int signbit(double x);
                                        ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/cmath:672:16: note: target of using declaration
constexpr bool signbit(double __x)
               ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/math.h:68:12: note: using declaration
using std::signbit;
           ^

Am I using compiler/library versions incompatible with CUDA? It's seemingly difficult to find this information, especially as Debian is not officially supported by Nvidia. I am only using packages as distributed by Debian repositories (I am on the testing distribution).

Archimaredes
  • 1,397
  • 12
  • 26
  • 2
    maybe you should try it on a supported distro. Since you're attempting to use clang, this doesn't look right: `..lib/gcc/..` See [here](https://stackoverflow.com/questions/24342312/clang-seems-to-use-the-gcc-libraries) – Robert Crovella Dec 22 '17 at 00:17
  • Thanks @RobertCrovella, it seems to work fine if I install libc++ and use `--compiler-options -stdlib=libc++` instead of letting clang use the gcc libraries (which are too new for CUDA 8.0 to support). I will write an answer. – Archimaredes Dec 22 '17 at 13:20

2 Answers2

3

CUDA 8.0 only supports up to gcc-5; since this is unavailable in Debian 9, I used clang-3.8 instead. However, by default, clang uses the gcc C++ standard libraries, and it was trying to use version 7.2.0. Since CUDA 8 does not support gcc-7, it was breaking.

Installing libc++ (an alternative C++ library implementation by the creators of clang) and using that manually fixes the issue. The command is:

nvcc -ccbin clang++-3.8 -std=c++11 --compiler-options -stdlib=libc++ -o test test.cu
Archimaredes
  • 1,397
  • 12
  • 26
2

Something is either broken in your installation, or the Debian version you are using deviates far enough away from the supported platforms that it can't work.

If I compile your example on Ubuntu 14.04 with CUDA 8 I get this:

$ cat clangtest.cu
__global__ void testfunc(float *a, float *b, int N)
{
    for (int i = 0; i < N; ++i) {
        b[i] += a[i];
    }
}

$ nvcc -arch=sm_52 -std=c++11 -c clangtest.cu 
$ nvcc -ccbin=/usr/bin/clang-3.8 -std=c++11 -arch=sm_52 -c clangtest.cu
$ nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2016 NVIDIA Corporation
Built on Sun_Sep__4_22:14:01_CDT_2016
Cuda compilation tools, release 8.0, V8.0.44

$ g++ --version
g++ (Ubuntu 4.8.5-2ubuntu1~14.04.1) 4.8.5
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ clang-3.8 --version
clang version 3.8.0-2ubuntu3~trusty5 (tags/RELEASE_380/final)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

So you either need to fix your clang installation, or use a supported distro, because this really is supported and does work.

talonmies
  • 70,661
  • 34
  • 192
  • 269
  • My clang installation wasn't broken, but it was using the gcc C++ standard library, which at version 7.2.0 is too new for CUDA 8.0. Using clang's libc++ manually works. – Archimaredes Dec 22 '17 at 13:22