GPU much slower in existing code
9 views (last 30 days)
Show older comments
Hi,
I'm working on an aerodynamics simulation, and have a function that needs speeding up. I have rewritten that function to utilize a GPU, and compared the results to a case run without the GPU, and the results are terrible. I used the profiler to compare time spent in particular functions...as a simple example, at one point I take the square root of the sum of the squares:
r1=sqrt(pxx1.^2+pyy1.^2_pzz1.^2);
and in the code without the GPU, MATLAB spends 0.22 seconds on this calculation (over the entire simulation), whereas in the code with the GPU, MATLAB spends 2.31 seconds on this calculation. An order of magnitude higher!
The only difference is that one set of variables is on the GPU, and the other is not. This does not include any time spent gathering the variable from the GPU...this is strictly time spent on the calculation.
And to make matters even more confusing, I pulled out the square root of the sum of the squares to compare performance of that function alone, and I get a completely different result. The GPU is 30% faster when calculating that function alone.
What reasons, within a larger body of code, would cause a GPU to perform so poorly compared to the CPU? Why would the GPU perform so much better on a single calculation?
1 Comment
Daniel Shub
on 21 Nov 2011
I am sure it is a typo but I am pretty sure .^2_pzz1 is not valid syntax. Also, what do you mean by pull out the square root. Do you mean something like:
temp = pxx1.^2+pyy1.^2+pzz1.^2;
r1 = sqrt(temp);
If so, which steps take more time and which ones take less time.
Answers (3)
Jan
on 21 Nov 2011
Do the temporarily created arrays match into the available RAM on the graphics card? 0.22 sec on the CPU sounds like a large arrays.
Please measure the time for this also:
r1 = sqrt(pxx1 .* pxx1 + pyy1 .* pyy1 + pzz1 .* pzz1);
and
r1 = pxx1 .* pxx1 + pyy1 .* pyy1 + pzz1 .* pzz1;
r1 = sqrt(r1);
0 Comments
Jason Ross
on 21 Nov 2011
What GPU are you using? The range of computing power varies considerably across the range of GPU hardware.
0 Comments
See Also
Categories
Find more on Get Started with GPU Coder in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!