matlab if statements with CUDA

前端 未结 4 1422
鱼传尺愫
鱼传尺愫 2021-01-20 01:59

I have the following matlab code:

randarray = gpuArray(rand(N,1));
N = 1000;

tic
g=0;
for i=1:N

    if randarray(i)>10
        g=g+1;
    end

end
toc

         


        
4条回答
  •  佛祖请我去吃肉
    2021-01-20 02:46

    No expert on the Matlab gpuArray implementation, but I would suspect that each randarray(i) access in the first loop triggers a PCI-e transaction to retrieve a value from GPU memory, which will incur a very large latency penalty. You might be better served by calling gather to transfer the whole array in a single transaction instead and then loop over a local copy in host memory.

提交回复
热议问题