code wiki / (root) / nx_numeric_oracle.nx

nx_numeric_oracle.nx

buildroot/runtime/nx_numeric_oracle.nx

17109 B429 linesdepth 3pulls 4 transitivereach 8 importersview sourcekind librarytopic numeric
docsdependenciesstructsconstsfunctions

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

nx_syscalls.nx nx_tier.nx nx_tensor.nx nx_prng.nx nx_numeric_oracle.nx nx_attention_test.nx nx_compute_runner_test.nx nx_flash_attention_test.nx nx_numeric_oracle_test.nx nx_quant_block_test.nx nx_quant_q4k_test.nx nx_sparse_tensor_test.nx nx_winograd_conv_test.nx

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

57const NX_MAGIC_1024: i64 = 1024
79const NX_NO_CMP_BIT_EXACT: nx_int = 0
80const NX_NO_CMP_ULP_BOUNDED: nx_int = 1
81const NX_NO_CMP_EPSILON_REL: nx_int = 2
82const NX_NO_CMP_METAMORPHIC: nx_int = 3
83const NX_NO_CMP_STRUCTURAL: nx_int = 4
84const NX_NO_CMP_N_KINDS: nx_int = 5
97const NX_NO_VERDICT_EQUAL: nx_int = 0 // exact match in chosen mode
98const NX_NO_VERDICT_DIFFERS: nx_int = 1 // values differ beyond tolerance
99const NX_NO_VERDICT_SHAPE_MISMATCH: nx_int = 2 // shapes don't match
100const NX_NO_VERDICT_DTYPE_MISMATCH: nx_int = 3 // dtypes don't match
101const NX_NO_VERDICT_NOT_COMPARABLE: nx_int = 4 // dtype not yet supported in chosen mode
102const NX_NO_VERDICT_INVARIANT_BROKEN: nx_int = 5 // metamorphic check failed
103const NX_NO_VERDICT_N_KINDS: nx_int = 6
129const NX_NO_WITNESS_F_IDX0: nx_int = 0
130const NX_NO_WITNESS_F_IDX1: nx_int = 1
131const NX_NO_WITNESS_F_IDX2: nx_int = 2
132const NX_NO_WITNESS_F_IDX3: nx_int = 3
133const NX_NO_WITNESS_F_ACTUAL: nx_int = 4
134const NX_NO_WITNESS_F_EXPECTED: nx_int = 5
135const NX_NO_WITNESS_F_ABS_DIFF: nx_int = 6
136const NX_NO_WITNESS_F_ULP_DISTANCE: nx_int = 7
137const NX_NO_WITNESS_FIELDS: nx_int = 8
420const NX_NO_WITNESS_JSON_CAP: nx_int = 256

functions

86func nx_no_cmp_kind_is_valid(k: nx_int) -> nx_int
called by 1: main
105func nx_no_verdict_is_valid(v: nx_int) -> nx_int
called by 1: main
139func nx_no_witness_clear(w: *i64) -> nx_int
153func _no_structural_check(a: *NxTensor, b: *NxTensor) -> nx_int
164func nx_no_check_structural(a: *NxTensor, b: *NxTensor) -> nx_int
called by 1: main calls 1: _no_structural_check
173func nx_no_check_bit_exact_i64(a: *NxTensor, b: *NxTensor,
223func nx_no_check_epsilon_rel_q10(a: *NxTensor, b: *NxTensor,
279func nx_no_check_double_transpose_id(t: *NxTensor, witness_out: *i64) -> nx_int
326func nx_no_gen_random_i64(shape: *i64, ndim: nx_int,
called by 1: main calls 2: nx_t_allocnx_prng_range_lo_hi
349func nx_no_differential_verdict(out_a: *NxTensor, out_b: *NxTensor,
376func nx_no_check_reproducible(hash_run_1: *u8, hash_run_2: *u8,
called by 1: main
403func nx_no_kahan_sum_i64(values: *i64, n: nx_int) -> nx_int
called by 1: main
422func nx_no_witness_to_buf(w: *i64, buf: *u8) -> nx_int