【发布时间】:2014-03-26 07:13:38
【问题描述】:
我正在尝试编译从here 复制的简单 helloworld 示例。我使用的是 CentOS 6.4 环境。
// 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 \0\0\0\0\0\0";
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;
}
尝试编译它工作正常:
$ nvcc hello_world.cu -o hello_world.bin
但是当我运行它时:
$ ./hello_world.bin
Hello Hello
它不会打印预期的“Hello World”,而是“Hello Hello”。如果我从 __global__ 函数中注释掉一些代码,则根本没有影响,甚至将 printf 添加到 hello() 函数中也不会产生任何结果。似乎没有调用该函数。我错过了什么?我可以检查什么?
我还尝试了一些其他示例源代码,它们适用于另一个盒子。问题似乎是一样的,所以这台电脑有问题。
编辑:
$ nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2013 NVIDIA Corporation
Built on Wed_Jul_17_18:36:13_PDT_2013
Cuda compilation tools, release 5.5, V5.5.0
$ nvidia-smi -a
-bash: nvidia-smi: command not found
$ cat /proc/driver/nvidia/version
NVRM version: NVIDIA UNIX x86_64 Kernel Module 319.60 Wed Sep 25 14:28:26 PDT 2013
GCC version: gcc version 4.4.7 20120313 (Red Hat 4.4.7-3) (GCC)
$ dmesg | grep NVRM
NVRM: loading NVIDIA UNIX x86_64 Kernel Module 319.60 Wed Sep 25 14:28:26 PDT 2013
NVRM: loading NVIDIA UNIX x86_64 Kernel Module 319.60 Wed Sep 25 14:28:26 PDT 2013
【问题讨论】:
-
代码对我来说很好用。您的机器设置可能有问题。将proper cuda error checking 添加到您的代码中,您可能会知道哪里出了问题。
-
在我看来,“a”数组中有11个字符,而int数组中有16个整数..他不是通过访问未初始化的内存从主机复制吗?
-
@RobertCrovella 谢谢。到处添加,现在得到
GPUassert: CUDA driver version is insufficient for CUDA runtime version hello_world.cu -
哦,好吧..这是一个不同的故事,解决问题:)
-
什么是驱动版本和运行时版本?您可以使用
nvcc --version轻松获得运行时版本。您可以通过运行nvidia-smi -a获取驱动程序版本
标签: c cuda compilation