GPU much slower in existing code
9 次查看(过去 30 天)
显示 更早的评论
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 个评论
Daniel Shub
2011-11-21
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.
回答(3 个)
Jan
2011-11-21
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 个评论
Jason Ross
2011-11-21
What GPU are you using? The range of computing power varies considerably across the range of GPU hardware.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Get Started with GPU Coder 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!