【问题标题】:CUDA and gcc compatibility issueCUDA 和 gcc 兼容性问题
【发布时间】:2013-01-25 01:54:23
【问题描述】:

我遇到了这个错误

/usr/local/cuda-5.0/bin/../include/host_config.h:82:2: 错误:#error -- 不支持的 GNU 版本!不支持 gcc 4.7 及更高版本! make: * [src/Throughput.o] 错误 1

在 host_config.h 中,它们确保兼容 4.6

#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 6)

#error -- unsupported GNU version! gcc 4.7 and up are not supported!

我有 4.6 和 4.7

elect@elect-desktop:/usr/local/cuda-5.0/bin$ gcc gcc
gcc-4.7 gcc-nm-4.7 gcc-4.6 gcc-ar-4.7
gcc-ranlib-4.7

查看互联网,他们建议在 cuda bin 目录中添加指向 gcc-4.6 的链接。

原来如此

elect@elect-desktop:/usr/local/cuda-5.0/bin$ sudo ln -s /usr/bin/gcc-4.6 gcc

我得到另一个错误

**** Build of configuration Debug for project Throughput ****

make all 
Building file: ../src/Throughput.cu
Invoking: NVCC Compiler
nvcc -G -g -O0 -gencode arch=compute_20,code=sm_20 -odir "src" -M -o "src/Throughput.d"     "../src/Throughput.cu"
gcc: error trying to exec 'cc1plus': execvp: No such file or directory
make: *** [src/Throughput.o] Error 1

**** Build Finished ****

再次谷歌搜索并没有给我带来一些明确的情况(gcc 降级等)

所以我在这里问现在问题是什么,因为 CUDA 应该与 gcc-4.6 兼容...

我的系统:

  • Ubuntu 12.10 64b
  • cuda_5.0.35_linux_64_ubuntu11.10-1

这是我目前正在尝试编译的教程代码

/**
 * Copyright 1993-2012 NVIDIA Corporation.  All rights reserved.
 *
 * Please refer to the NVIDIA end user license agreement (EULA) associated
 * with this source code for terms and conditions that govern your use of
 * this software. Any use, reproduction, disclosure, or distribution of
 * this software and related documentation outside the terms of the EULA
 * is strictly prohibited.
 */
#include <stdio.h>
#include <stdlib.h>

static const int WORK_SIZE = 256;

/**
 * This macro checks return value of the CUDA runtime call and exits
 * the application if the call failed.
 */
#define CUDA_CHECK_RETURN(value) {                                          \
    cudaError_t _m_cudaStat = value;                                        \
    if (_m_cudaStat != cudaSuccess) {                                       \
        fprintf(stderr, "Error %s at line %d in file %s\n",                 \
                cudaGetErrorString(_m_cudaStat), __LINE__, __FILE__);       \
        exit(1);                                                            \
    } }

__device__ unsigned int bitreverse(unsigned int number) {
    number = ((0xf0f0f0f0 & number) >> 4) | ((0x0f0f0f0f & number) << 4);
    number = ((0xcccccccc & number) >> 2) | ((0x33333333 & number) << 2);
    number = ((0xaaaaaaaa & number) >> 1) | ((0x55555555 & number) << 1);
    return number;
}

/**
 * CUDA kernel function that reverses the order of bits in each element of the array.
 */
__global__ void bitreverse(void *data) {
    unsigned int *idata = (unsigned int*) data;
    idata[threadIdx.x] = bitreverse(idata[threadIdx.x]);
}

/**
 * Host function that prepares data array and passes it to the CUDA kernel.
 */
int main(void) {
    void *d = NULL;
    int i;
    unsigned int idata[WORK_SIZE], odata[WORK_SIZE];

    for (i = 0; i < WORK_SIZE; i++)
        idata[i] = (unsigned int) i;

    CUDA_CHECK_RETURN(cudaMalloc((void**) &d, sizeof(int) * WORK_SIZE));

    CUDA_CHECK_RETURN(cudaMemcpy(d, idata, sizeof(int) * WORK_SIZE, cudaMemcpyHostToDevice));

    bitreverse<<<1, WORK_SIZE, WORK_SIZE * sizeof(int)>>>(d);

    CUDA_CHECK_RETURN(cudaThreadSynchronize());
    // Wait for the GPU launched work to complete
    CUDA_CHECK_RETURN(cudaGetLastError());
    CUDA_CHECK_RETURN(cudaMemcpy(odata, d, sizeof(int) * WORK_SIZE, cudaMemcpyDeviceToHost));

    for (i = 0; i < WORK_SIZE; i++)
        printf("Input value: %u, device output: %u\n", idata[i], odata[i]);

    CUDA_CHECK_RETURN(cudaFree((void*) d));
    CUDA_CHECK_RETURN(cudaDeviceReset());

    return 0;
}

【问题讨论】:

  • 除了CUDA,你在处理纯C代码吗?还是可能是 C++?
  • @bart: nvcc 需要一个受支持的 c++ 编译器
  • @Bart 目前纯C(我添加了一些额外的代码)
  • @talonmies 啊,但这不是问题吗? g++ 有问题(或没有)?
  • 那我不应该把链接添加到gcc吗?

标签: gcc ubuntu cuda


【解决方案1】:

问题源于 CUDA 工具链无法找到有效的 C++ 编译器。 nvcc 只是一个编译器驱动程序,它需要一个工作的 C++ 编译器来编译任何代码。

执行此操作的最正确方法 [注意您使用的是不受支持的 Linux 版本,因此使用此建议需要您自担风险] 是设置一个本地目录,其中包含指向受支持的编译器套件的链接(这意味着匹配,受支持gcc 和 g++ 的版本)并在编译时将 --compiler-bindir 参数传递给 nvcc。例如:

$ ls -l $HOME/cuda/bin
total 16
lrwxr-xr-x  1 talonmies  koti  16 Feb  9 12:41 g++ -> /usr/bin/g++-4.2
lrwxr-xr-x  1 talonmies  koti  16 Feb  9 12:41 gcc -> /usr/bin/gcc-4.2

这里有一组指向受支持编译器的链接。然后我可以这样编译:

$ nvcc --compiler-bindir=$HOME/cuda/bin -c -arch=sm_12 -Xptxas="-v" nanobench.cu 
ptxas info    : 0 bytes gmem
ptxas info    : Compiling entry function '_Z5benchIfLi128000EEvPjPT_i' for 'sm_12'
ptxas info    : Used 5 registers, 28 bytes smem, 12 bytes cmem[1]

在不支持系统编译器的情况下,这可能是使用替代编译器的最安全和侵入性最小的方法。

【讨论】:

  • 好的,但是如果它说 gcc-4.6 是兼容的并且我已经有 gcc-4.6,我是不是只缺少 g++-4.6,不是吗?
  • 是的,工作,我错过了 g++-4.6 的链接,然后我安装了它并在 /cuda-5.0/bin/g++ 中创建了一个指向 /usr/bin/g++-4.6 的链接。感谢 talonmies
  • 顺便说一句,您能否确认一下原始 g++ 和 gcc 链接是否分别指向 /usr/bin/g++ 和 /usr/bin/gcc?
  • @elect:我不明白你问的是什么原始链接
  • 是的,对不起,我说的是原始链接,因为我急于让它工作,我没有使用保存链接的目录,但我覆盖了 cuda-5.0/bin/ 中的原始链接
【解决方案2】:

在别处发现:

su -c 'update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.6 10'  
sudo update-alternatives --config gcc

为我工作。不过我正在编译 CudaMiner。

【讨论】:

    猜你喜欢
    • 2012-09-19
    • 2021-11-27
    • 2018-01-07
    • 2021-11-26
    • 2013-12-11
    • 2011-03-07
    • 1970-01-01
    相关资源
    最近更新 更多