nx_numeric_oracle.nx
buildroot/runtime/nx_numeric_oracle.nx
about
nx_numeric_oracle.nx -- the tool that verifies every future kernel.
Per the "build the tools that build the systems" cardinal + user's
"use the most modern research so we can really do incredible things
with the math and performance" direction.
Synthesises:
* Csmith / EMI (Yang+ 2011, Le+ 2014) -- differential
testing: feed the same input to two
implementations of the same spec, refuse
to ship if they disagree.
* Kahan compensated (Kahan 1965) + Neumaier (1974) -- maintain
summation a separate running error term so naive
floating sum loss-of-precision is recovered.
* Metamorphic testing (Chen+ 1998) -- when no ground-truth oracle
exists, verify INVARIANTS the answer must
satisfy (matmul(A, I) == A, T(T(A)) == A,
sum-then-square vs square-then-sum, etc.)
* Property-based (Claessen+Hughes QuickCheck 2000) --
testing generate many random inputs from a typed
spec; failure produces a shrunken witness.
* ULP bounds (IEEE 754 standard, 2008/2019) -- when
comparing FP, count units-in-last-place
distance instead of absolute / relative
epsilon hacks.
* Reproducible BLAS (Demmel+ 2013) -- bit-identical reduction
(ReproBLAS) regardless of thread/order; achievable
via deterministic accumulators.
* Boldo+Melquiond formal FP verification framework that
(Flocq, 2011) informs which properties are decidable.
* Herbie (Panchekha+ 2015) -- given a FP expression,
find an equivalent expression with smaller
rounding error. Inverse direction useful
for kernel optimization audits.
The oracle does NOT pick ONE comparison mode -- it offers the
sealed taxonomy and lets the kernel author pick the right one for
the op. Substrate refuses to call something WIN unless the oracle
has a structural verdict to back it.
dependencies 4 imports · 8 importers
imports: nx_syscalls.nxnx_tier.nxnx_tensor.nxnx_prng.nx
imported by: nx_attention_test.nxnx_compute_runner_test.nxnx_flash_attention_test.nxnx_numeric_oracle_test.nxnx_quant_block_test.nxnx_quant_q4k_test.nxnx_sparse_tensor_test.nxnx_winograd_conv_test.nx
structs
| none |
consts
| 57 | const NX_MAGIC_1024: i64 = 1024 |
| 79 | const NX_NO_CMP_BIT_EXACT: nx_int = 0 |
| 80 | const NX_NO_CMP_ULP_BOUNDED: nx_int = 1 |
| 81 | const NX_NO_CMP_EPSILON_REL: nx_int = 2 |
| 82 | const NX_NO_CMP_METAMORPHIC: nx_int = 3 |
| 83 | const NX_NO_CMP_STRUCTURAL: nx_int = 4 |
| 84 | const NX_NO_CMP_N_KINDS: nx_int = 5 |
| 97 | const NX_NO_VERDICT_EQUAL: nx_int = 0 // exact match in chosen mode |
| 98 | const NX_NO_VERDICT_DIFFERS: nx_int = 1 // values differ beyond tolerance |
| 99 | const NX_NO_VERDICT_SHAPE_MISMATCH: nx_int = 2 // shapes don't match |
| 100 | const NX_NO_VERDICT_DTYPE_MISMATCH: nx_int = 3 // dtypes don't match |
| 101 | const NX_NO_VERDICT_NOT_COMPARABLE: nx_int = 4 // dtype not yet supported in chosen mode |
| 102 | const NX_NO_VERDICT_INVARIANT_BROKEN: nx_int = 5 // metamorphic check failed |
| 103 | const NX_NO_VERDICT_N_KINDS: nx_int = 6 |
| 129 | const NX_NO_WITNESS_F_IDX0: nx_int = 0 |
| 130 | const NX_NO_WITNESS_F_IDX1: nx_int = 1 |
| 131 | const NX_NO_WITNESS_F_IDX2: nx_int = 2 |
| 132 | const NX_NO_WITNESS_F_IDX3: nx_int = 3 |
| 133 | const NX_NO_WITNESS_F_ACTUAL: nx_int = 4 |
| 134 | const NX_NO_WITNESS_F_EXPECTED: nx_int = 5 |
| 135 | const NX_NO_WITNESS_F_ABS_DIFF: nx_int = 6 |
| 136 | const NX_NO_WITNESS_F_ULP_DISTANCE: nx_int = 7 |
| 137 | const NX_NO_WITNESS_FIELDS: nx_int = 8 |
| 420 | const NX_NO_WITNESS_JSON_CAP: nx_int = 256 |
functions
| 86 | func nx_no_cmp_kind_is_valid(k: nx_int) -> nx_int called by 1: main |
| 105 | func nx_no_verdict_is_valid(v: nx_int) -> nx_int called by 1: main |
| 139 | func nx_no_witness_clear(w: *i64) -> nx_int |
| 153 | func _no_structural_check(a: *NxTensor, b: *NxTensor) -> nx_int |
| 164 | func nx_no_check_structural(a: *NxTensor, b: *NxTensor) -> nx_int |
| 173 | func nx_no_check_bit_exact_i64(a: *NxTensor, b: *NxTensor, |
| 223 | func nx_no_check_epsilon_rel_q10(a: *NxTensor, b: *NxTensor, |
| 279 | func nx_no_check_double_transpose_id(t: *NxTensor, witness_out: *i64) -> nx_int |
| 326 | func nx_no_gen_random_i64(shape: *i64, ndim: nx_int, |
| 349 | func nx_no_differential_verdict(out_a: *NxTensor, out_b: *NxTensor, |
| 376 | func nx_no_check_reproducible(hash_run_1: *u8, hash_run_2: *u8, called by 1: main |
| 403 | func nx_no_kahan_sum_i64(values: *i64, n: nx_int) -> nx_int called by 1: main |
| 422 | func nx_no_witness_to_buf(w: *i64, buf: *u8) -> nx_int |