推力::减少操作(GPU RAM或CPU RAM)的输出位置在哪里?

时间:2018-11-21 10:10:08

标签: cuda reduce ram thrust

在以下示例中,当我们使用推力:: reduce时,输出为int。此输出(代码中的 sum 变量)是否位于GPU或CPU RAM上?

如果它位于CPU RAM中,如何在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>());

}

1 个答案:

答案 0 :(得分:1)

结果sum在CPU上,您可以引用此documentation

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