You haven't called GPU arrayfun here, you've called CPU arrayfun and in the arrayfun function you are doing stuff on the GPU. This is because none of the arguments to your arrayfun call is a gpuArray.
You could force it to use GPU arrayfun by converting your input:
c = arrayfun(@(i) sum(a(:,i),1), gpuArray(1:N));
However, you'll immediately find it errors, because sum is not supported for GPU arrayfun. Obviously this is just a toy example, but the solution here is sum(a,1), not arrayfun.
1 Comment
Hao Zhang (view profile)
Direct link to this comment
https://de.mathworks.com/matlabcentral/answers/435152-gpu-arrayfun-is-so-slow-what-is-going-on#comment_650189
Sign in to comment.