GPU multiplication slowdown after ~500 ops. (Image Attached)

An optimization task requires I perform many large matrix multiplication operations sequentially. However, when I do many multiplication operations in sequence, after roughly the 500th operation the GPU multiplication becomes much slower. The code I used to demonstrate this is as follows:
A = gpuArray(rand(1000));
x = gpuArray(rand(1000,1));
fff=0;
i=1;
while(i<=1000)
tic;
A*x;
fff = [fff,toc];
i=i+1;
end
figure
semilogy(fff)
When we examine the time it took for each individual operation to complete, we observe the following behaviour:
Why does the time cost suddenly spike to normal CPU speeds at about 500 operations in? Is there any way I can prevent this?
[N.B. I'm using a GeForce 940MX and MATLAB 2016b]

댓글 수: 1

Sharath Chandran
Sharath Chandran 2017년 10월 26일
편집: Sharath Chandran 2017년 10월 26일
Does this behavior consistently occur every-time you run the script?
I tried running your script on my system with NVIDIA Quadro K620 using R2016B and plotted about 150 graphs. There was not much deviation in time taken per iteration. There were couple of spikes indicating that time taken for that particular iteration was more than '1e-4', however I could not reproduce the behavior, that you've reported above, consistently.
I reckon that this is an exception and if you try running the script multiple times and obtain the plot for each of them, you'd observe the expected behavior.
Please let us know the results after you've carried this experiment on your system.

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

답변 (1개)

Joss Knight
Joss Knight 2017년 10월 29일

1 개 추천

This is just because you are not accounting for the asynchronous behaviour of the GPU in your timing. This question is asked regularly on this forum, refer for instance to this recent post.

카테고리

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

질문:

2017년 10월 19일

답변:

2017년 10월 29일

Community Treasure Hunt

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

Start Hunting!

Translated by