1

请原谅我的菜鸟。我们的研究小组最近购买了一台装有 2 个 NVIDIA Tesla 设备的服务器,我负责设置它。

服务器单元正在运行 Rocks 6.0。

所以我根据这个指令安装从 NVIDIA 下载的 CUDA SDK:http: //docs.nvidia.com/cuda/cuda-getting-started-guide-for-linux/index.html

我尝试编译 NVIDIA 随 SDK 提供的示例代码,但遇到了一堆错误。我想也许 Makefile 可能没有配置,所以我在 Stack Overflow 上看了一圈,发现了这段测试代码:

using namespace std;

#include <iostream>
#include <string.h>
#include <unistd.h>

int main (int argc, const char *argv[]) {

    //our message
    const char *message = "hello world!";
    size_t size = strlen(message)+1;

    //delcare and allocate a buffer on the device
    char *d_buffer;
    if (cudaMalloc(&d_buffer,size) != cudaSuccess){
        cerr << cudaGetErrorString(cudaGetLastError()) << endl;
        exit(1);
    }

    //copy our message to the device buffer
    if (cudaMemcpy(d_buffer,message,size,cudaMemcpyHostToDevice)
        != cudaSuccess){
        cerr << cudaGetErrorString(cudaGetLastError()) << endl;
        exit(1);
    }

    //declare and allocate a buffer on the host
    char *h_buffer = (char*)malloc(size);
    if (h_buffer == 0){
        cerr << "malloc failed" << endl;
        exit(1);
    }

    //copy the device buffer back to the host
    if (cudaMemcpy(h_buffer,d_buffer,size,cudaMemcpyDeviceToHost)
        != cudaSuccess) {
        cerr << cudaGetErrorString(cudaGetLastError()) << endl;
        exit(1);
    }

    cout << h_buffer << endl;
    cudaFree(d_buffer);
    free(h_buffer);
}

所以按照说明,我编译了代码:

nvcc -o hello_cuda hello_cuda.cu

并得到以下错误:

In file included from /usr/local/cuda-5.0/bin/../include/cuda_runtime.h:76,
                 from <command-line>:0:
/usr/local/cuda-5.0/bin/../include/common_functions.h:76:15: error: new: No such file or directory
In file included from /usr/local/cuda-5.0/bin/../include/common_functions.h:162,
                 from /usr/local/cuda-5.0/bin/../include/cuda_runtime.h:76,
                 from <command-line>:0:
/usr/local/cuda-5.0/bin/../include/math_functions.h:7555:17: error: cmath: No such file or directory
/usr/local/cuda-5.0/bin/../include/math_functions.h:7556:19: error: cstdlib: No such file or directory
hello_cuda.cu:11:20: error: iostream: No such file or directory

这些基本上与我在编译示例代码时收到的错误消息相同。我的猜测是编译器配置不正确,因为 iostream 应该只是 C 的标准库。

有什么想法或指针可以解决这个问题吗?这似乎是一个非常简单的问题,但我已经为此烦恼了好几天!

4

1 回答 1

1

看来您没有正确安装 gcc/g++。样本不需要 boost,错误消息指出它找不到标准库(new、cmath、cstdlib)。

从第 2.8.1 节http://docs.nvidia.com/cuda/cuda-compiler-driver-nvcc/index.html#proper-compiler-install

在 Linux 和 Windows 上,正确安装的编译器具有某种形式的内部知识,使它们能够定位系统包含文件、系统库和 dll、与编译器安装本身相关的包含文件和库,以及实现 libc 和 libc++ 的包含文件和库。

于 2014-05-08T07:41:08.550 回答