0
我是CUDA的新手。這是我遇到的第一個問題:CUDA hello world failed
我測試了這樣一段代碼從網頁:
#include "stdio.h"
__global__ void add(int a, int b, int *c)
{
*c = a + b;
}
int main()
{
int a,b,c;
int *dev_c;
a=3;
b=4;
cudaMalloc((void**)&dev_c, sizeof(int));
add<<<1,1>>>(a,b,dev_c);
cudaMemcpy(&c, dev_c, sizeof(int), cudaMemcpyDeviceToHost);
printf("%d + %d is %d\n", a, b, c);
cudaFree(dev_c);
return 0;
}
它給了:3 + 4 is 1
我編譯:nvcc eg.cu
然後跑:./a.out
哪裏不對了?
FYI:
EVN:Ubuntu的14.04,NVCC 5.5,機器:的NVIDIA Quadro K600(開普勒)
通過添加調用cudaGetLastError()來檢查內核啓動/執行錯誤。當我編譯並運行這個時,我看到3 + 4是7.檢查nvidia-smi或從samples目錄運行deviceQuery,以確保GPU的一切正常。 – 2014-09-26 11:47:46