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.contractMojoProof.Sem.contractMojoProof.Sem.contract_casesMojoProof.Sem.contract_unfusedMojoProof.Sem.contract_errorMojoProof.Sem.contract_estMojoProof.Sem.floatBin_contractMojoProof.Sem.floatBin_contract_estFloatLib.Floats.Formats.BinaryInterchange.Model.fma
- Corpus files
14 kernel files (
.ll) in the corpus.- Tests
MojoProofTest.FloatRel.contract_est_instMojoProofTest.FloatRel.contract_est_twinMojoProofTest.SymContractMojoProofTest.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.
- tests/gpu/naive/record.txt: the naive matmul kernel's loop computes each product with
fmul contractand adds it to the sum withfadd contract, up to 768 rounds per cell. The grid evaluator ran every thread with the oracle that is always 2, which takes at everyfadd contractthe fused multiply-add of the product into the sum (Model.fma), and at eight launches every word of C is the same as on one A100, bit for bit (1356 cells written, 476 of them infinite). So the GPU's words are those the model gives when every pair fuses. - tests/gpu/vadd/record.txt and tests/gpu/vsub/record.txt: one
fadd contractorfsub contractof two loaded words per thread. No operand is anfmul contract, so every oracle number gives the separately rounded result, and the evaluator and the GPU agree on every word at six launches.
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.