0

When we use thrust::reduce in the following example, the output is an int. Is this output (sum variable in code) located on the GPU or CPU RAM?

If it is in CPU RAM, how to access/retain the variable in the gpu? The reduce operation happens on the device(GPU) so at some point the output should be in the 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>());

}
user27665
  • 673
  • 7
  • 27

1 Answers1

1

The result sum is on the CPU, you can refer to this documentation.

The result was probably at some point on the GPU, if the final result was computed on it. I didn't checked the implementation, but it could be possible that the final result is computed on the CPU. If you need to access it on the GPU, just pass it as a kernel argument, or copy it into global memory.

Robin Thoni
  • 1,651
  • 13
  • 22