interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / docs / numeric / E1_REDUCTION_CONTRACT.md

140 lines · 10142 bytes Raw Blame History Source

E1 reduction contract (WP-D)

Closes gap table row 5 (docs/numeric/E1_GAP_TABLE.md) on the CPU tiers and on GB10 for SUM, MAX, MIN and MEAN (MEAN = chip SUM levels plus one chip division). Code: src/omega_numeric_reduce.h, src/omega_numeric_reduce.c (reference + CPU realization), src/omega_numeric_reduce_gb10.c (GB10), tests tests/test_omega_reduce.c, chip runner tests/run_reduce_chip.sh.

Declared order

RECURSIVE_TILE32_PAIRWISE_TREE_LANE_DELTA_16_8_4_2_1_PAD_IDENTITY_MIN_ONE_LEVEL

The order depends only on n and the element index. Scheduling, thread count, CTA count and launch chunking cannot change it.

  1. Level 0 is x[0..n).
  2. One level maps len values to ceil(len/32) values. Value j of the next level is the existing warp tree PAIRWISE_TREE_LANE_DELTA_16_8_4_2_1 (OMEGA_WARP_REDUCTION_DECLARED_ORDER) over values [32j, 32j+32): for d = 16, 8, 4, 2, 1, lane i becomes lane[i] (op) lane[i+d], the lower lane on the left; the tile result is lane 0. Positions >= len hold the identity of the op.
  3. At least one level is applied, and levels repeat until one value is left. The number of levels is the smallest L >= 1 with 32^L >= n (1..32 -> 1, 33..1024 -> 2, 1025..32768 -> 3, up to 2^20 -> 4).

Why tiles of 32 at every level: each level is exactly what the chip-proven REDUCE_SUM warp kernel computes per warp, and two levels are exactly what a single 1024-thread CTA (32 warps: warp tree, lane 0 to shared memory, barrier, warp 0 runs the same tree over the 32 warp results) computes. A later shared-memory CTA kernel can therefore realize the same order without changing any bits.

Ops

OpCombineIdentity (padding)n = 0
SUMIEEE a + b, RNE, subnormals kept, no FTZ-0.0 (x + -0 == x bit for bit for every non-NaN x, including +0 + -0 = +0)+0.0 (defined, not computed)
MAXFMNMX_MAX rule: NaN is missing data (the other operand wins; both NaN gives NaN), -0 < +0quiet NaN 0x7fc00000quiet NaN
MINFMNMX_MIN rule, same NaN and zero rulesquiet NaNquiet NaN
MEANomega_math_div(SUM, u2f(n)), correctly rounded, for 1 <= n <= 2^24 (n exact in FP32)as SUMquiet NaN; n > 2^24 refused (OMEGA_NUMERIC_ERR_OPERANDS)

Notes:

Worked examples (expected bits written by hand in the test)

Tiers

Tests (make test-numeric-reduce-cpu, chip: tests/run_reduce_chip.sh)

IDWhat it proves
RED_ORDER_DECLAREDorder string, level counts, hand-derived worked-example bits on both tiers
RED_EMPTY_IDENTITY_SPECIAL_VALUESn = 0 results, identities exact, signed zeros, subnormal sums, overflow, inf/NaN rules, MEAN rounding and bounds, bad-argument refusals
RED_CPU_EQUALS_REFERENCErandomized differential, 61 lengths (0, 1, 2, primes, 31/32/33 ... 32769, 65537, 1000003, 10^6, 24 random) x 5 input classes x 4 ops, plus batched rows
RED_INDEPENDENT_ORACLEexact integer sums, MEAN of exact sums, MAX/MIN against a sequential scan
RED_DIFFERENT_ORDER_CAUGHTleft-to-right, reversed deltas and flat fold each give different bits on crafted inputs and are flagged; left-to-right also differs on random data
RED_DETERMINISMn = 1000003, repeated runs and shifted buffers give identical bits
RED_GB10_PRESUBMIT_CHECKSrefusals (NULL, too large, MEAN n > 2^24) and acceptance of every tested n for all four ops, without a device
RED_CRAFTED_TABLE14 crafted vectors (all -0, signed zeros, overflow, inf, subnormal, all NaN, NaN with one number, sNaN, negative NaN, +-FLT_MAX cancel) with hand-written SUM, MAX, MIN and MEAN bits on reference and CPU
RED_GB10_MINMAX_PATCHthe MAX and MIN patches pass their checks; 30 mutants (reversed or swapped deltas, delta 3, shuffle into R2 or R6, first shuffle not waiting for the input load, swapped shuffle pairs, MAX and MIN predicate flipped, swapped FMNMX operands, wrong last destination, missing wait, short stall, wrong shuffle clamp, stray modifier bit, and the other op's patch) are each refused; a host model that decodes the patch words equals the reference on 110 cases
RED_WRONG_PAD_CAUGHTwrong pads (-inf or +0 for MAX, +inf or -0 for MIN) give different bits on crafted inputs and are caught; MEAN worked example n = 33 is 0x48F83E2F and differs from the sequential order
RED_GB10_PARITY_<OP>chip only, per op SUM, MAX, MIN, MEAN: GB10 bits equal the reference for 21 lengths (0, 1, 2, 31, 32, 33, 63, 64, 65, 97, 1000, 1023, 1024, 1025, 4097, 32768, 32769, 65536, 65537, 10^6, 1000003) x 4 input classes (n > 70000: 2), plus the crafted table and the worked examples. NaN equals NaN (payload not semantic)
RED_GB10_PARITYchip only: overall line, PASS only when every op has 0 mismatches
make test-numeric-reduce-nvdisasmoffline: the MAX and MIN patch words disassemble (nvdisasm, -b SM121) to exactly the text the code declares