Roadmap / Floats

contract

contract, the fast-math flag that lets fmul and fadd fuse into one rounding

Area
Floats
Kind
construct
Level
L3, the top level.
Evidence present above the level
None above the level.
Evidence
Reference
LLVM LangRef 24.0.0git #fast-math-flags
Quote
No quote yet.
Lean declarations
  • MojoProof.LLVM.FastMath.contract
  • MojoProof.Sem.contract
  • MojoProof.Sem.contract_cases
  • MojoProof.Sem.contract_unfused
  • MojoProof.Sem.contract_error
  • MojoProof.Sem.contract_est
  • MojoProof.Sem.floatBin_contract
  • MojoProof.Sem.floatBin_contract_est
  • FloatLib.Floats.Formats.BinaryInterchange.Model.fma
Corpus files

14 kernel files (.ll) in the corpus.

Tests
  • MojoProofTest.FloatRel.contract_est_inst
  • MojoProofTest.FloatRel.contract_est_twin
  • MojoProofTest.SymContract
  • MojoProofTest.Gpu
Upstream issue
None filed.
Depends on
floats/binary-op-rounding

The rule. With contract on an fmul and the fadd that uses it, the pair may be computed with one rounding (a fused multiply-add) or with two.

In Lean. In MojoProof.Sem.contract the oracle number selects the separately rounded operation or FloatLib's Model.fma of one of the recorded products and the other operand; contract_cases says the result is one of these, contract_unfused when to expect the unfused one, and contract_error and contract_est bound a finite result's distance from the exact value, fused or not, for every IEEE format. The block checker records the products of fmul contract (MojoProofTest.SymContract). The naive matmul's specializations built with contraction on have it.

Tested against a GPU (L2). A conformance test, not a proof.

Not tested: the separately rounded choice where a product is offered (no record's oracle takes it), formats other than binary32, and NaN operands (the naive record's sums reach infinity in 476 cells, but no operand is a NaN).

Used by a proved kernel (L3). naive-matmul: NaiveKernel.correct, matmul_nanEq and matmul_error are about the kernel built with contraction on, for every oracle family, so for every choice, fused or not, at each fadd contract. vadd and vsub: their fadd contract and fsub contract have no product to fuse, so every choice is the one rounding.

Out of scope. The other fast-math flags (reassoc, afn and the rest) are a separate matter.

Open. The construct ladder's top level. A GPU run whose code does not fuse (or an oracle that does not) would test the other choice. Ref: quote to be added.