Odd Profiler GPU Bug?
1 次查看(过去 30 天)
显示 更早的评论
I have a loop that does some operations on the GPU. When I call the function from the command line, each epoch runs in 96 seconds. When I call it from profiler, each epoch takes about 4 seconds. The CPU version of the code runs in about 63 seconds. Any ideas on how to fix this so that I get the GPU speed up without profiler? I could call it from profiler exclusively, but that seems silly. Here is the portion of code that seems to be affected by this phenomenon. The r array is large, e.g., 4000x78000.
tic
r = gpuArray(single(r));
U_grad = gpuArray(single(0));
W = gpuArray(single(W'));
for k = 1:max_class
U_grad = U_grad + bsxfun(@times, W(:, k), r);
end
U_grad = double(gather(U_grad)) * (q');
toc
2 个评论
Edric Ellis
2015-11-2
Any chance you could post a standalone reproduction? What version of MATLAB are you using? What OS? What GPU?
回答(1 个)
Joss Knight
2015-11-27
When you have the profiler on (from MATLAB R2015a onwards), to get realistic timings the GPU is forced to run synchronously.
My guess is that without the profiler, your second call to bsxfun is executed before the first finishes (this is possible because it can compute it without needing the output from the previous loop). MATLAB attempts to allocate space for an output array of appropriate size, but there isn't enough space available for two arrays of that size.
With the profiler on, the space from the first call to bsxfun has been freed up and made available to the second bsxfun.
You can confirm this is the case by calling wait(gpuDevice) inside your loop to prevent this execution overlap.
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!