beacon-biosignals / Onda.jl

A Julia package for high-throughput manipulation of structured signal data across arbitrary domain-specific encodings, file formats and storage layers
Other
68 stars 5 forks source link

use fma in decoding #148

Closed ericphanson closed 9 months ago

ericphanson commented 11 months ago

closes https://github.com/beacon-biosignals/Onda.jl/issues/146

Here the main question is whether to use muladd or fma. Quoting the muladd doctsring,

help?> Base.muladd muladd(x, y, z)

Combined multiply-add: computes x*y+z, but allowing the add and multiply to be merged with each other or with surrounding operations for performance. For example, this may be implemented as an fma if the hardware supports it efficiently. The result can be different on different machines and can also be different on the same machine due to constant propagation or other optimizations. See fma.

The result being different on different machines sounds like the kind of thing we don't want to have to worry about with encode/decode when trying to track down reproducibility issues etc. Moreover, fma is widely available now. So I think it makes sense to stick with fma for an accuracy boost and speedup on most hardware, at the potential cost of a big slowdown for software emulation on unsupported hardware. I think all the hardware used at Beacon supports fma.

Note the existing tests pass as-is, including some floating point == tests, which I guess means we were already rounding correctly on the test data (?).