LUT-free Mini-Float Upcasting#310
Draft
ashvardanian wants to merge 4 commits into
Draft
Conversation
This patch explores the idea of LUT-free arithmetic upcasts for mini-float representations into F32. The current results look inconclusive and should be later investigated together with a GEMM redesign to hoist the upcasts & fuse them with loads.
3 tasks
Closes #328 On x86 Sapphire Rapids cores - denormal values choke FMA: - F32 slows from ~3cy to ~86cy (28x slower) - F64 slows from ~3cy to ~104cy (34x slower) That's why previous versions of this library suggested changing FTX/DAZ settings to ensure high throughput. We now always use mixed-precision schemes that are safe even against such inputs. All of F32 denormals become normal in F64 accumulators and it's a similar story for other inputs.
With denormal f32 intermediates now safe, replace the two-path integer-add + subnormal-LUT upcast with Giesen's magic-multiply trick across all backends (Haswell, Skylake, NEON, RVV, WASM, serial). A single float multiply — reinterpret magnitude bits as a tiny f32, multiply by 2^(127-bias) — correctly handles zero, subnormals, and normals in one instruction, eliminating per-format LUT constants and subnormal mask+blend logic (-169 lines net).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This patch explores the idea of LUT-free arithmetic upcasts for mini-float representations into F32. The current results look inconclusive and should be later investigated together with a GEMM redesign to hoist the upcasts & fuse them with loads.