【发布时间】:2010-12-10 12:12:47
【问题描述】:
我正在使用 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
有什么问题?
提前致谢!
【问题讨论】:
-
您可能应该完成编程指南中的一些示例。您的语法与编程指南中建议的有出入。