2013-02-09 327 views
7

我得到這個錯誤CUDA和gcc兼容性問題

/usr/local/cuda-5.0/bin/../include/host_config.h:82:2: error: #error -- unsupported GNU version! gcc 4.7 and up are not supported! make: * [src/Throughput.o] Error 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

[email protected]:/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。

所以我做

[email protected]:/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; 
} 
+0

除了CUDA之外,您是在處理純C代碼嗎?或者它可能是C++? – Bart 2013-02-09 10:32:30

+0

@bart:nvcc需要一個支持工作的C++編譯器 – talonmies 2013-02-09 10:45:37

+0

@Bart現在純C(我加了一些額外的代碼) – elect 2013-02-09 10:46:18

回答

5

編譯教程代碼問題源於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] 

這可能是用在不支持的系統編譯器編譯器替代的最安全,最侵入性的方式。

+0

好吧,但如果它說gcc-4.6兼容,我已經gcc-4.6,我是否只缺少g ++ - 4.6,不是嗎? – elect 2013-02-09 12:37:20

+0

是的,工作,我錯過了g ++ - 4.6的鏈接,然後我安裝了它並在/usr/bin/g++-4.6創建了一個鏈接/cuda-5.0/bin/g++。謝謝talonmies – elect 2013-02-09 12:47:17

+0

順便說一句,如果原始的g ++和gcc鏈接分別指向/ usr/bin/g ++和/ usr/bin/gcc,您能否確認我? – elect 2013-02-09 12:48:24

2

至於其他地方找到:

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

爲我工作。我正在編譯CudaMiner。