quokka-astro / quokka

Two-moment AMR radiation hydrodynamics (with self-gravity, particles, and chemistry) on CPUs/GPUs for astrophysics
https://quokka-astro.github.io/quokka/
MIT License
45 stars 12 forks source link

add support for running entirely in single precision #666

Open BenWibking opened 2 months ago

BenWibking commented 2 months ago

Describe the proposal Support running amrex::Real as float (compile with -DAMReX_PRECISION=SINGLE) and replace all uses of double with amrex::Real. Ensure that all tests still pass.

Describe alternatives you've considered We have so far relied on users running on GPUs with hardware support for double precision arithmetic.

Additional context Due to AI, future-generation GPUs may completely drop hardware support for double precision arithmetic.

chongchonghe commented 2 months ago

I totally agree and support this plan. I recently learned about another code under development that uses mixed precision and achieves extremely high speed, about 100 Mupdates/s/GPU on game cards (RTX 3080/3090). They use single precision for the approximate Riemann solver but use double precision in the conservation step.

BenWibking commented 2 months ago

That's interesting.

Over the next couple of years, the code needs to run without double precision at all. If we need extra precision, we can do Kahan summation or represent numbers as the sum of two single precision values (then overload arithmetic operators such as + and * to emulate double precision).