MATLAB: MATLAB and Simulink results are different (GPU Coder)

gpuGPU CoderMATLABsimulink

Hello all,
For my project I had integrated GPU coder into simulink for evaluvating State space equation and I got the output.
Also using the function in MATLAB, I got the results.
While comparing both the results, the difference should be 0, but I am getting the difference in output as 1e-13(approx.)
So can anyone please explain me why there is difference in the results???
Thanks in advance !!!

Best Answer

You should not expect the exact same results between CPU and GPU for floating point arithmetic.
CPU and GPU have different instruction sets. When you compile for GPU, the order of operations can be different than for CPU, including because of differences in the optimization capabilities of the different compilers. For efficiency, a number of operations on GPU use vendor high-performance libraries, which use different implementations than the high-performance libraries used for CPU. Whether the high performance libraries are even invoked on CPU depends on the problem size (there is a cost to starting up those library calls, so MATLAB does the calculations more directly for smaller calculations.)
Related Question