GPU and CPU computing results different

4 views (last 30 days)
peter on 13 Jul 2011
Hi, I have tested FFT2 function for both workspace and GPU data. The difference in result is very small but still disturbs me. Does anyone have why that is and any suggested solutions?
im = phantom(512);
k = fft2(im);
kim = fft2(gpuArray(complex(im)));
OK = isequal(k,kim);

Answers (2)

Ben Tordoff
Ben Tordoff on 13 Jul 2011
if you look at the magnitude of the difference compared to the magnitude of the values, it is pretty small:
>> max(max(gather(abs(k-kim)))) / max(max(abs(k)))
ans = 1.0144e-016
Infact, it is similar to the limit of accuracy for any calculation on the input:
>> eps(max(max(abs(im))))
ans = 2.2204e-016
(the two are not measuring the same thing, but hopefully you get the idea).
The CPU and GPU implementations of FFT/FFT2 are necessarily quite different in order to take best advantage of the hardware. The GPU version needs to be massively parallel. I believe that the difference you are seeing is well within what one should expect from any two different implementations of FFT/FFT2.
Whilst we can aspire to identical results from the CPU and GPU versions, sometimes it simply isn't possible without massive compromises on speed.

Daniel Shub
Daniel Shub on 13 Jul 2011
When you say very small, do you mean 1e-16 small? If so, that is close to the precision of double precision numbers. Check out:

Community Treasure Hunt

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

Start Hunting!