c - 我只看到主机的 "world hello"而不是设备

标签 c parallel-processing cuda gpu

我使用这个网站在 cuda 中复制了一个 hello world 程序 http://code.google.com/p/stanford-cs193g-sp2010/wiki/TutorialHelloWorld

代码是

#include "util/cuPrintf.cu"
#include <stdio.h>

__global__ void device_greetings(void)
{
  cuPrintf("Hello, world from the device!\n");
}

int main(void)
{
  // greet from the host
  printf("Hello, world from the host!\n");

  // initialize cuPrintf
  cudaPrintfInit();

  // launch a kernel with a single thread to greet from the device
  device_greetings<<<1,1>>>();

  // display the device's greeting
  cudaPrintfDisplay();

  // clean up after cuPrintf
  cudaPrintfEnd();

  return 0;
}

然后使用 nvcc hello_world.cu -o hello_world 编译,但是我只看到主机的 hello 而不是设备。

我试过了

printf("{CudaPrintfInt => %s}\n",cudaGetErrorString(cudaPrintfInit()));
printf("{cudaPrintfDisplay => %s}\n",cudaGetErrorString(cudaPrintfDisplay(stdout, true)));

并使用 nvcc -arch=sm_11 hello_world.cu -o hello_world 编译,但是我得到:

$ ./hello_world
Hello, world from the host!
{CudaPrintfInt => initialization error}
{cudaPrintfDisplay => __global__ function call is not configured}
$

图形模型为:

$/sbin/lspci -v | grep VGA
07:01.0 VGA compatible controller: Matrox Graphics, Inc. MGA G200eW WPCM450 (rev 0a) (prog-if 00 [VGA controller])

cuda版本是4:

$ ls /usr/local/cuda/lib/
libcublas.so         libcudart.so.4.0.17  libcurand.so.4         libnpp.so
libcublas.so.4       libcufft.so          libcurand.so.4.0.17    libnpp.so.4
libcublas.so.4.0.17  libcufft.so.4        libcusparse.so         libnpp.so.4.0.17
libcudart.so         libcufft.so.4.0.17   libcusparse.so.4
libcudart.so.4       libcurand.so         libcusparse.so.4.0.17

最佳答案

“如果您使用的是 CC 2.0 GPU,则根本不需要 cuPrintf——CUDA 为 CC-2.0 和更高版本的 GPU 内置了 printf。因此,只需将对 cuPrintf 的调用替换为实际的 prinft”( source )

以这种方式编写代码只是为了检查导致此问题的原因。

#include <cuda_runtime.h>
#include "util/cuPrintf.cu"
#include <stdio.h>
__global__ void device_greetings(void)
{
  cuPrintf("Hello, world from the device!\n");
}

  int main(void)
  {
  // greet from the host
  printf("Hello, world from the host!\n");

  // initialize cuPrintf
  printf("{CudaPrintfInt => %s}\n",cudaGetErrorString(cudaPrintfInit()));

  // launch a kernel with a single thread to greet from the device
  device_greetings<<<1,1>>>();

  // display the device's greeting
  printf("{cudaPrintfDisplay => %s}\n",cudaGetErrorString(cudaPrintfDisplay()));

  // clean up after cuPrintf
  cudaPrintfEnd();

  return 0;
}

Here说发生这种情况是因为: “被调用的设备功能(通常通过 cudaLaunch())之前未通过 cudaConfigureCall() 函数配置。”

关于c - 我只看到主机的 "world hello"而不是设备,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13326115/

相关文章:

linux - 为什么 CUDA 的示例联编文件找不到 CUDA 库?

c - 如何将 GSList 放入 GHashTable 中?

c - C 语言中的基本加/减/乘/除程序有问题吗?

c# - 使用单个并行 for 循环获取 Min、Max、Sum

具有早期中止的 Haskell 并行搜索

c++ - 优化的 CUDA 矩阵汉明距离

c - 如何在c中存储具有相同内存位置的值?

c - STM32定时器自动重载预载

c - 当使用 openMP 并行化代码时,哪些变量应该是私有(private)的和/或firstprivate,什么时候合适?

cuda - 当大小不是 2 的幂时向量和的减少?