code wiki / _hdl_build / nx_tgrad_core.nx
nx_tgrad_core.nx
buildroot/runtime/_hdl_build/nx_tgrad_core.nx
about
nx_tgrad_core.nx -- the T6/T5 tensor-autograd CORE extracted VERBATIM from the GATED
_tensor_grad_authored.nx (T6 gate A-F PASS 2026-06-09) so higher rungs (T4 first model)
COMPOSE it instead of copy-pasting. The gated artifact is UNTOUCHED and stays the proof;
this file is the reusable library form: tape/arena, matvec/addvec/relu/mse/smul forward,
one-sweep backward, AdamW ad_step. license_tier: ORIGINAL (extraction, zero new logic).
dependencies 6 imports · 5 importers
imports: nx_syscalls.nxnx_f32.nxnx_f32_div.nxnx_f32_cvt.nxnx_f32_exp.nxnx_f32_log.nx
imported by: _ce_grad_gate_authored.nx_t2_bigram_lm_authored.nx_t4_first_model_authored.nx_t4b_closed_loop_authored.nxnx_lowrank_train.nx
structs
| none |
consts
| 12 | const TG_MAGIC_16777216: i64 = 16777216 |
| 30 | const TG_NCAP: i64 = 256 |
| 31 | const TG_ACAP: i64 = 16384 |
functions
| 13 | func _tg_puts(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } |
| 14 | func _tg_num(v: i64) -> i64 { let bb: *u8=sys_mmap(28); var m: i64=v; if m<0{m=0-m;sys_write(1,"-" as *u8,1)}; let t: *u8=sys_mmap(28); var k: i64=0; if m==0{t[0]=48;k=1}; while m>0{t[k]=48+(m%10);m=m/10;k=k+1}; var i: i64=0; while i<k{bb[i]=t[k-1-i];i=i+1}; sys_write(1,bb,k); return 0 } |
| 15 | func tg_q(n: i64, d: i64) -> i64 { return nx_f32_div(nx_i32_to_f32(n), nx_i32_to_f32(d)) } |
| 16 | func tg_milli(v: i64) -> i64 called by 7: mainlm_trainmaint4_cen_trainmainb4_train+1 calls 4: nx_f32_ltnx_f32_absnx_f32_mulnx_i32_to_f32 |
| 32 | func tg_alloc(arena: *i64, ab: *i64, n: i64) -> *i64 |
| 41 | func tg_node(tape: *i64, nb: *i64, op: i64, ai: i64, bi: i64, rows: i64, cols: i64, valp: *i64, gradp: *i64) -> i64 |
| 55 | func tg_valp(tape: *i64, x: i64) -> *i64 { return tape[x*8+5] as *i64 } |
| 56 | func tg_gradp(tape: *i64, x: i64) -> *i64 { return tape[x*8+6] as *i64 } |
| 57 | func tg_leaf(tape: *i64, nb: *i64, arena: *i64, ab: *i64, p: *i64, rows: i64, cols: i64) -> i64 |
| 60 | func tg_matvec(tape: *i64, nb: *i64, arena: *i64, ab: *i64, a: i64, x: i64) -> i64 |
| 76 | func tg_addvec(tape: *i64, nb: *i64, arena: *i64, ab: *i64, x: i64, y: i64) -> i64 |
| 85 | func tg_reluvec(tape: *i64, nb: *i64, arena: *i64, ab: *i64, x: i64) -> i64 |
| 98 | func tg_mse(tape: *i64, nb: *i64, arena: *i64, ab: *i64, p: i64, t: i64) -> i64 |
| 117 | func tg_celoss(tape: *i64, nb: *i64, arena: *i64, ab: *i64, p: i64, t: i64) -> i64 called by 3: mainlm_trainb4_train calls 10: tg_valpnx_f32_gttg_allocnx_f32_subnx_f32_expnx_f32_add+4 |
| 149 | func tg_smul(tape: *i64, nb: *i64, arena: *i64, ab: *i64, x: i64, y: i64) -> i64 |
| 156 | func tg_backward(tape: *i64, nt: i64, root: i64) -> i64 |
| 243 | func ad_step(w: *i64, g: *i64, m: *i64, v: *i64, n: i64, lr: i64, b1: i64, b2: i64, eps: i64, wd: i64, t: i64) -> i64 |