1

このサイトhttp://code.google.com/p/stanford-cs193g-sp2010/wiki/TutorialHelloWorldを使用して、cudaでhelloworldプログラムをコピーしました。

コードは

#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ましたが、デバイスではなくhellofomホストのみが表示されます。

私も試しました

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
4

1 に答える 1

2

「CC2.0GPUを使用している場合は、cuPrintfはまったく必要ありません。CUDAにはCC-2.0以降のGPU用のprintfが組み込まれています。したがって、実際のプリンフトのcuPrintfへの呼び出しを置き換えるだけです」(ソース

この問題の原因を確認するためだけに、このようにコーディングしてください。

#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;
}

ここで、次の理由で発生したと言います:「呼び出されているデバイス関数(通常はcudaLaunch()を介して)は、以前はcudaConfigureCall()関数を介して構成されていませんでした。」

于 2012-11-10T21:46:00.343 に答える