Reputation: 1897
My process I am trying to accomplish in Matlab:
Return the vector to the CPU
% My stab at it:
Array = gpuArray(ones(3,3,5));
Array = pagefun(@sum,array);
Array = gather(Array);
% Desired output: Array = 1x1x5 vector of 9's
This throws an error that pagefun does not like the summation function.
On the CPU, a similar process works just fine. It works in a FOR loop as well on the GPU, but this does not vectorize the process for ideal speed. Would a CUDA kernel be more able to do something like this? Is there a better way to do this? Is this more suitable for a cluster rather than a GPU?
Help appreciated, Will
Setup: ASUS i7 quadcore, GTX Geforce 960 running CUDA driver
Upvotes: 1
Views: 100
Reputation: 25160
Here's my answer that I also posted on MATLAB answers.
array = ones(3, 3, 5, 'gpuArray');
result = sum(reshape(array, [], size(array, 3)));
result = gather(reshape(result, 1, 1, []));
Upvotes: 0
Reputation: 12109
Well, you could try out the uglier way:
Array = reshape(sum(Array(:,:)), 1, 1, k); %k is whatever third dimension is
Upvotes: 2