thrust::reduce 操作(GPU RAM 或 CPU RAM)的输出位置是什么?

What is the location of output of thrust::reduce operation(GPU RAM or CPU RAM)?

当我们在下面的例子中使用thrust::reduce时,输出是一个int。此输出(sum 代码中的变量)位于 GPU 还是 CPU RAM 上?

如果在CPU RAM中,如何access/retain gpu中的变量? reduce 操作发生在设备 (GPU) 上,因此在某些时候输出应该在 GPU 中。

#include <thrust/reduce.h>
#include <thrust/execution_policy.h>
#include <thrust/device_vector.h>

int main()
{
thrust::device_vector<int> D(6);
D[0]=0;
D[1]=1;
D[2]=2;
D[3]=3;
D[4]=4;
D[5]=5;
int sum = thrust::reduce(thrust::device,D.begin(), D.end(), (int) 0, thrust::plus<int>());

}

结果sum在CPU上,可以参考这个documentation

如果最终结果是在 GPU 上计算的,结果可能在 GPU 上的某个时刻。我没有检查实现,但最终结果可能是在 CPU 上计算的。如果你需要在 GPU 上访问它,只需将它作为内核参数传递,或者 copy 将它传递到全局内存中。