HPCE / hpce-2018-cw3

1 stars 5 forks source link

Loss of precision with StepWorldV3OpenCL #83

Closed XavKearney closed 5 years ago

XavKearney commented 5 years ago

I've just implemented StepWorldV3OpenCL. I've been testing as I go by diffing:

bin/make_world 10 0.1 | bin/step_world 0.1 10000

and

bin/make_world 10 0.1 | bin/[implementation name] 0.1 10000

Until now, the results have been consistent. After finishing the kernelised implementation, the results are no longer identical. They're the same up to ~5 decimal places, but differ after that. If I reduce the number of time steps to < 6, then they're equal again.

For 10k time steps, here's a comparison:

Reference output:

 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000
 0.00000000 1.00000000 1.00000000 1.00000000 1.00000000 1.00000000 1.00000000 1.00000000 1.00000000 0.00000000
 0.00000000 0.99983490 0.99968255 0.99922949 0.99801791 0.99483669 0.98650062 0.96469027 0.95947474 0.00000000
 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000 0.91283673 0.91379231 0.00000000
 0.00000000 0.28816822 0.32211152 0.41613516 0.51060194 0.55805624 0.00000000 0.86014545 0.86918324 0.00000000
 0.00000000 0.25465134 0.26246512 0.00000000 0.55805635 0.60593808 0.70210397 0.79859656 0.83378446 0.00000000
 0.00000000 0.21372968 0.21104029 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000
 0.00000000 0.17587022 0.15729024 0.10427196 0.05483591 0.00000000 0.00920590 0.01161556 0.01219925 0.00000000
 0.00000000 0.15692157 0.13827851 0.10089788 0.06034895 0.02543980 0.01602677 0.01347452 0.01281843 0.00000000
 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000

OpenCL output:

 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000
 0.00000000 1.00000000 1.00000000 1.00000000 1.00000000 1.00000000 1.00000000 1.00000000 1.00000000 0.00000000
 0.00000000 0.99983597 0.99968195 0.99922520 0.99801302 0.99483120 0.98649782 0.96468771 0.95947218 0.00000000
 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000 0.91283298 0.91378868 0.00000000
 0.00000000 0.28816685 0.32211012 0.41613472 0.51060158 0.55805618 0.00000000 0.86014152 0.86917949 0.00000000
 0.00000000 0.25464934 0.26246312 0.00000000 0.55805618 0.60593700 0.70210230 0.79859346 0.83378172 0.00000000
 0.00000000 0.21372762 0.21103823 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000
 0.00000000 0.17586839 0.15728848 0.10427062 0.05483516 0.00000000 0.00920575 0.01161538 0.01219908 0.00000000
 0.00000000 0.15691996 0.13827689 0.10089658 0.06034810 0.02543942 0.01602651 0.01347430 0.01281825 0.00000000
 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000

Is this expected? I've also tried switching devices between my GPU and CPU, to no avail.

Thanks!

jjd06 commented 5 years ago

Do either of #5 and #25 help? This looks to be floating-point-related issue to me. Do remember that precision and accuracy are not synonymous!

XavKearney commented 5 years ago

Yes, thank you. It seems to align exactly with those issues. I should've searched better!