code wiki / _hdl_build / nx_vcodec_nf_train.nx

nx_vcodec_nf_train.nx

buildroot/runtime/_hdl_build/nx_vcodec_nf_train.nx

19698 B396 linesdepth 6pulls 17 transitivereach 0 importersview sourcekind tooltopic vcodec
docsdependenciesstructsconstsfunctions

about

nx_vcodec_nf_train.nx -- TRAINER for the learned decoder-side restoration filter (NEURAL track rung 1). Sovereign, integer-only, no floats anywhere. For every (codec-mode in {legacy tf=1, t8-rich}, qp in {12,20,32}) it runs OUR real codec (key + P chain, in-loop deblock -- exactly the live display path) over the REAL frames 0..7 of bframe_test_decoded.yuv (576x1024 luma; frames 8..11 stay HELD OUT for the gate), accumulates per (qp-band, gradient-class) integer normal equations over (3x3 deblocked-recon context -> source pixel) pairs, then solves each class's 3x3+bias Q12 filter: step 1 CLOSED FORM: the center-vs-3x3-mean Wiener blend a* = S_cm_s / S_cm2 (scale-free integer) step 2 REFINE: damped diagonally-preconditioned integer gradient descent on the full 10-tap least squares (J tracked from the moments; a step that raises J is reverted + step halved), starting AT the blend -> the result can only match or beat it on the training distribution. Classes with too few pairs keep the IDENTITY filter (never invent weights from noise). Emits the table as GENERATED SOURCE runtime/nx_vcodec_nf_table.nx (vc_nf_load) -- generators, not hand-authored data. license_tier: ORIGINAL

dependencies 4 imports · 0 importers

nx_syscalls.nx nx_video_codec_wasm.nx nx_vcodec_nf.nx nx_quality_metric.nx nx_vcodec_nf_train.nx

imports: nx_syscalls.nxnx_video_codec_wasm.nxnx_vcodec_nf.nxnx_quality_metric.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main tw_ sys_write sys_mmap sys_read_file sys_openat_rd sys_lseek sys_mmap ↻ sys_read sys_close vc_t8_init nx_dct8_init vc_t8p tn sys_mmap ↻ sys_write ↻ nf_run vc_nf_band vc_enc_frame_packed_t8 nx_bw_put vc_aq_level vc_mb_mad vc_mb_t8_ok vc_enc_block_packed_e vc_enc_block_packed_i vm_sad_zero vm_sad vs_skip nx_bw_put ↻ vc_intra_dc_sad vm_search vm_scan vc_enc_mb4r_intra vc_t8p ↻ vc_gather_edges vc_mpm_pred vc_pred_rich vc_mpm_put vc_coeff_enc vm_sad ↻

structs

none

consts

18const MIN_MAGIC_4096: i64 = 4096
19const MIN_MAGIC_3078: i64 = 3078
20const MIN_MAGIC_4194304: i64 = 4194304
21const MIN_MAGIC_5120: i64 = 5120
22const MIN_MAGIC_5000: i64 = 5000
23const MIN_MAGIC_65536: i64 = 65536
25const TW: i64 = 576
26const TH: i64 = 1024
27const TFRAMES: i64 = 8
28const MIN_PAIRS: i64 = 20000 // below this a class keeps identity (no training on noise)
29const GD_ITERS: i64 = 240
39const A_ATA: i64 = 0
40const A_ATB: i64 = 2700
41const A_BTB: i64 = 2970
42const A_CNT: i64 = 2997
43const A_SCM2: i64 = 3024
44const A_SCMS: i64 = 3051

functions

31func tw_(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
called by 1: main calls 1: sys_write
32func tn(v: i64) -> i64
called by 1: main calls 2: sys_mmapsys_write
49func nf_run(yuv: *u8, mode: i64, qp: i64, accT: *i64, accV: *i64, fsplit: i64, enc: *u8, dprev: *u8, dout: *u8, stream: *u8, blk: *i64, mv: *i64, rctx: *i64) -> i64
183func nf_mirror(acc: *i64, bc: i64, M: *i64) -> i64
called by 1: main
201func nf_j(M: *i64, atb: *i64, w: *i64) -> i64
called by 1: main
220func main() -> i64