okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
e4309aaf3
main
1"""tools/image/gate/dit_step_check.py - TEST-ONLY (OWN-5B D4): strata-dit-step's velocities against the reference. 2 3For each case: velocity rel L2 to the f32 reference (dit_ref.py) for ours (strata-dit-step), the emulation with 4float32 sums (dit_ref mode f16acc32, the stage rule's comparison since 11-11) and with exact sums (f16op), the D1+D2 5test build (sd.cpp's native runner with our GEMMs), stock sd.cpp and its native runner; and ours against the D1+D2 6build directly. Then the stage rule over the cases given: (i) mean ours <= 1.25 x mean emulation, (ii) no case above 71.5 x its emulation value, (iii) every case closer than stock and native - against both emulations. 8 9python -I -B dit_step_check.py --root R --ours O [--cases "512 p0,512 p5"] 10R = the Spark own5b folder (pics/, d0ref/ with d0ref/acc32 from dit_acc32_cases.py); O = strata-dit-step's out dir. 11""" 12from __future__import annotations 13 14import argparse 15import sys 16from pathlib import Path 17 18import numpy as np 19 20_HERE = Path (__file__ ).resolve ().parent 21if str (_HERE )not in sys .path : 22sys .path .insert (0 ,str (_HERE )) 23from te_ref import compare # noqa: E402 24 25 26def vel (path )-> np .ndarray : 27"""a velocity file ([C][H][W] float32, sd.cpp's vel_<k>.bin layout) as [H*W][C] rows""" 28return np .fromfile (path ,dtype = "<f4" ).reshape (64 ,- 1 ).T 29 30 31def case_paths (root :Path ,name :str )-> dict : 32size ,p = name .split () 33p = int (p [1 :]) 34dn = f"dump_p { p } _s42" 35if size == "1024" : 36return {"dump" :root / "pics/d0_stock_1024" / dn ,"ref" :root / "d0ref/r1024" / dn , 37"acc32" :root / "d0ref/acc32/1024_p0_acc32.npy" ,"stock" :root / "pics/d0_stock_1024" / dn / "vel_0.bin" , 38"native" :root / "pics/d0_native_1024" / dn / "vel_0.bin" , 39"d1d2" :root / "pics/z_ours_1024" / dn / "vel_0.bin" } 40lo = "d0" if p < 4 else "z" 41return {"dump" :root / f"pics/ { lo } _stock_512" / dn ,"ref" :root / "d0ref" / dn , 42"acc32" :root / f"d0ref/acc32/512_p { p } _acc32.npy" ,"stock" :root / f"pics/ { lo } _stock_512" / dn / "vel_0.bin" , 43"native" :root / f"pics/ { lo } _native_512" / dn / "vel_0.bin" , 44"d1d2" :root / ("pics/d2_g15" if p < 4 else "pics/z_ours_512" )/ dn / "vel_0.bin" } 45 46 47def rule (rows :list ,k :int )-> str : 48O = np .mean ([r ["ours" ]for r in rows ]) 49E = np .mean ([r [k ]for r in rows ]) 50worst = max (rows ,key = lambda r :r ["ours" ]/ r [k ]) 51ii = all (r ["ours" ]<= 1.5 * r [k ]for r in rows ) 52iii = all (r ["ours" ]< r ["stock" ]and r ["ours" ]< r ["native" ]for r in rows ) 53return (f"(i) mean { O :.5f } / { E :.5f } = { O / E :.3f } ( { 'PASS' if O <= 1.25 * E else 'FAIL' } ); (ii) largest " 54f" { worst [ 'ours' ] / worst [ k ]:.3f } at { worst [ 'name' ] } ( { 'PASS' if ii else 'FAIL' } ); (iii) " 55f" { 'PASS' if iii else 'FAIL' } " ) 56 57 58def main (argv = None )-> int : 59ap = argparse .ArgumentParser () 60ap .add_argument ("--root" ,required = True ) 61ap .add_argument ("--ours" ,required = True ) 62ap .add_argument ("--cases" ,default = "512 p0,512 p5" ) 63a = ap .parse_args (argv ) 64root ,ours_dir = Path (a .root ),Path (a .ours ) 65rows = [] 66for name in [c .strip ()for c in a .cases .split ("," )if c .strip ()]: 67P = case_paths (root ,name ) 68f32 = np .load (str (P ["ref" ])+ "_f32.npy" ).reshape (64 ,- 1 ).T 69o = vel (ours_dir / P ["dump" ].parent .name / P ["dump" ].name / "vel.bin" ) 70r = {"name" :name ,"ours" :compare (o ,f32 )["rel_l2" ], 71"f16acc32" :compare (np .load (P ["acc32" ]).reshape (64 ,- 1 ).T ,f32 )["rel_l2" ], 72"f16op" :compare (np .load (str (P ["ref" ])+ "_f16op.npy" ).reshape (64 ,- 1 ).T ,f32 )["rel_l2" ], 73"d1d2" :compare (vel (P ["d1d2" ]),f32 )["rel_l2" ],"stock" :compare (vel (P ["stock" ]),f32 )["rel_l2" ], 74"native" :compare (vel (P ["native" ]),f32 )["rel_l2" ],"ours_vs_d1d2" :compare (o ,vel (P ["d1d2" ]))["rel_l2" ]} 75rows .append (r ) 76"| case | ours (strata-dit-step) | f32-sum emulation | ratio | exact-sum emulation | ratio | D1+D2 test build " 77"| stock | native | ours vs D1+D2 build |" ) 78"|---|---|---|---|---|---|---|---|---|---|" ) 79for r in rows : 80f"| { r [ 'name' ] } | { r [ 'ours' ]:.5f } | { r [ 'f16acc32' ]:.5f } | { r [ 'ours' ] / r [ 'f16acc32' ]:.3f } | " 81f" { r [ 'f16op' ]:.5f } | { r [ 'ours' ] / r [ 'f16op' ]:.3f } | { r [ 'd1d2' ]:.5f } | { r [ 'stock' ]:.5f } | " 82f" { r [ 'native' ]:.5f } | { r [ 'ours_vs_d1d2' ]:.5f } |" ) 83"RULE vs the float32-sum emulation: " + rule (rows ,"f16acc32" )) 84"RULE vs the exact-sum emulation: " + rule (rows ,"f16op" )) 85return 0 86 87 88if __name__ == "__main__" : 89sys .exit (main ())