使用C ++ 11时CUDA nvcc编译器失败(Linux; clang 3.8)

问题描述 投票:1回答:2

我正在尝试使用我的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存储库分发的包(我正在测试发行版)。

linux c++11 cuda debian clang
2个回答
3
投票

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版本偏离了支持的平台,它无法正常工作。

如果我使用CUDA 8在Ubuntu 14.04上编译你的例子,我得到这个:

$ 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安装,要么使用支持的发行版,因为这确实是支持并且确实有效。

© www.soinside.com 2019 - 2024. All rights reserved.