我正在與CUDA一起開發項目。爲了掌握它,我有以下代碼。初學CUDA - 簡單的無效增量不起作用
#include <iostream>
using namespace std;
__global__ void inc(int *foo) {
++(*foo);
}
int main() {
int count = 0, *cuda_count;
cudaMalloc((void**)&cuda_count, sizeof(int));
cudaMemcpy(cuda_count, &count, sizeof(int), cudaMemcpyHostToDevice);
cout << "count: " << count << '\n';
inc <<< 100, 25 >>> (&count);
cudaMemcpy(&count, cuda_count, sizeof(int), cudaMemcpyDeviceToHost);
cudaFree(cuda_count);
cout << "count: " << count << '\n';
return 0;
}
輸出是
count: 0
count: 0
什麼問題?
提前致謝!
你應該通過一些在節目指南的例子也許可以工作。您的語法與編程指南中建議的內容不一致。 – Marm0t 2010-12-10 18:10:24