Hello - I see GPU computation underperforming when used for vector manipulation with short lengths.
>> a = rand(1000000, 100,'gpuArray');
>> b= gather(a);
>> tic; for i=1:100 ; eval('q = zeros(1000000,1);for i = 1:100; q = b(:,i)+q;end') ; end;doc
Elapsed time is 45.489811 seconds.
>>tic; for i=1:100 ; eval('qq = zeros(1000000,1);for i = 1:100; q = a(:,i)+q;end') ; end;toc
Elapsed time is 0.875140 seconds.
same when done for short vectors see GPU computation under performing:
>> a = rand(200, 100,'gpuArray');
>>b= gather(a);
>> tic; for i=1:100 ; eval('q = zeros(200,1);for i = 1:100; q = b(:,i)+q;end') ; end;doc
Elapsed time is 0.021727 seconds.
>>tic; for i=1:100 ; eval('qq = zeros(200,1);for i = 1:100; q = a(:,i)+q;end') ; end;toc
Elapsed time is 0.833865 seconds.
Any insight will be appreciated.
Thank you.

 채택된 답변

Joss Knight
Joss Knight 2016년 4월 20일
편집: Joss Knight 2016년 4월 20일

0 개 추천

Computation in a GPU core is significantly slower than in a modern CPU core. It makes up for that by having a lot of them - thousands. If you don't give it thousands of things to do at once, you're never going to beat the CPU.
In your simple computation above you are unnecessarily using a loop. This may have been for illustrative purposes, but if it reflects your actual code, you will gain back your performance by removing the loop, i.e.
q = sum(a, [], 2);

추가 답변 (1개)

Walter Roberson
Walter Roberson 2016년 3월 30일

0 개 추천

Do not use eval() for this. use timeit()

댓글 수: 3

Edric Ellis
Edric Ellis 2016년 3월 30일
... and for GPU timings, use gputimeit.
Walter Roberson
Walter Roberson 2016년 3월 30일
Good point.
MatlabNinja
MatlabNinja 2016년 3월 30일
Thank you for your insight. time and gputimeit gives very similar results and shows similar trend where smaller vector(a & b above) had worse run performance when run on GPU.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 GPU Computing에 대해 자세히 알아보기

태그

질문:

2016년 3월 30일

편집:

2016년 4월 20일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by