NVCC 忽略 CUDA 代码?

NVCC ignoring CUDA code?

我刚刚在我的笔记本电脑上安装了 CUDA 5.5,并尝试使用 NVCC 从这个 link http://computer-graphics.se/hello-world-for-cuda.html

编译一个基本的 hello world 程序

我正在尝试的代码是这样的:

// This is the REAL "hello world" for CUDA!
// It takes the string "Hello ", prints it, then passes it to CUDA with an array
// of offsets. Then the offsets are added in parallel to produce the string "World!"
// By Ingemar Ragnemalm 2010

#include <stdio.h>

const int N = 16; 
const int blocksize = 16; 

__global__ 
void hello(char *a, int *b) 
{
    a[threadIdx.x] += b[threadIdx.x];
}

int main()
{
    char a[N] = "Hello [=10=][=10=][=10=][=10=][=10=][=10=]";
    int b[N] = {15, 10, 6, 0, -11, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};

    char *ad;
    int *bd;
    const int csize = N*sizeof(char);
    const int isize = N*sizeof(int);

    printf("%s", a);

    cudaMalloc( (void**)&ad, csize ); 
    cudaMalloc( (void**)&bd, isize ); 
    cudaMemcpy( ad, a, csize, cudaMemcpyHostToDevice ); 
    cudaMemcpy( bd, b, isize, cudaMemcpyHostToDevice ); 

    dim3 dimBlock( blocksize, 1 );
    dim3 dimGrid( 1, 1 );
    hello<<<dimGrid, dimBlock>>>(ad, bd);
    cudaMemcpy( a, ad, csize, cudaMemcpyDeviceToHost ); 
    cudaFree( ad );
    cudaFree( bd );

    printf("%s\n", a);
    return EXIT_SUCCESS;
}

本来应该打印出"Hello world!",但是我使用"nvcc hello.cu -o a.out"编译后,我的输出是"Hello Hello",有人能告诉我这是怎么回事吗?

这是由损坏的 CUDA 驱动程序安装引起的。更正的安装允许 运行 正确的代码没有错误。

[此社区 wiki 条目是根据评论汇集而成的,目的是将此问题从未回答的队列中删除]