【问题标题】:CUDA nvcc compiler fails when using C++11 (Linux; clang 3.8)使用 C++11 (Linux; clang 3.8) 时 CUDA nvcc 编译器失败
【发布时间】:2017-12-21 23:24:25
【问题描述】:

我正在尝试在我的 Debian GNU/Linux 系统上使用 CUDA 工具包进行编译,但即使在极其简单的程序中,C++11 支持显然也被破坏了。

首先,这里是相关软件版本的列表:

  • Linux 内核:4.13.0
  • CUDA 工具包:8.0.61
  • Clang:3.8.1
  • libc:2.25
  • libstdc++: 7.2.0

使用一个非常基本的测试文件test.cu,如下:

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

并使用命令编译:

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

我得到一长串declaration conflicts with target of using declaration already in scope 错误。我将在下面显示两个 - 它会在 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;
           ^

我是否使用了与 CUDA 不兼容的编译器/库版本?似乎很难找到这些信息,尤其是在 Nvidia 没有正式支持 Debian 的情况下。我只使用由 Debian 存储库分发的软件包(我在测试分发中)。

【问题讨论】:

  • 也许您应该在受支持的发行版上试用它。由于您尝试使用 clang,这看起来不正确:..lib/gcc/.. 请参阅 here
  • 感谢@RobertCrovella,如果我安装 libc++ 并使用 --compiler-options -stdlib=libc++ 而不是让 clang 使用 gcc 库(对于 CUDA 8.0 来说太新而无法支持),它似乎工作正常。我会写一个答案。

标签: linux c++11 cuda debian clang


【解决方案1】:

CUDA 8.0 最多只支持 gcc-5;因为这在 Debian 9 中不可用,所以我改用了 clang-3.8。但是,默认情况下,clang 使用 gcc C++ 标准库,并且尝试使用 7.2.0 版本。由于 CUDA 8 不支持 gcc-7,它正在崩溃。

安装 libc++(clang 创建者的替代 C++ 库实现)并使用它手动修复问题。命令是:

nvcc -ccbin clang++-3.8 -std=c++11 --compiler-options -stdlib=libc++ -o test test.cu

【讨论】:

    【解决方案2】:

    您的安装出现问题,或者您使用的 Debian 版本与支持的平台相差太远,以至于无法运行。

    如果我在 Ubuntu 14.04 上使用 CUDA 8 编译您的示例,我会得到:

    $ 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
    

    因此,您要么需要修复您的 clang 安装,要么使用受支持的发行版,因为这确实受支持并且确实有效。

    【讨论】:

    • 我的 clang 安装没有损坏,但它使用的是 gcc C++ 标准库,它在 7.2.0 版本中对于 CUDA 8.0 来说太新了。手动使用 clang 的 libc++ 即可。
    猜你喜欢
    • 1970-01-01
    • 2010-10-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-09
    • 2016-02-27
    • 2012-09-29
    • 2016-03-20
    相关资源
    最近更新 更多