code wiki / _hdl_build / nx_tgrad_core.nx

nx_tgrad_core.nx

buildroot/runtime/_hdl_build/nx_tgrad_core.nx

10461 B263 linesdepth 5pulls 8 transitivereach 5 importersview sourcekind library
docsdependenciesstructsconstsfunctions

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

nx_syscalls.nx nx_f32.nx nx_f32_div.nx nx_f32_cvt.nx nx_f32_exp.nx nx_f32_log.nx nx_tgrad_core.nx _ce_grad_gate_authored.nx _t2_bigram_lm_authored.nx _t4_first_model_authored.nx _t4b_closed_loop_authored.nx nx_lowrank_train.nx

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

12const TG_MAGIC_16777216: i64 = 16777216
30const TG_NCAP: i64 = 256
31const TG_ACAP: i64 = 16384

functions

13func _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 }
called by 9: mainlm_bpmaint4_bpmainb4_bp+3 calls 1: sys_write
14func _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 }
15func tg_q(n: i64, d: i64) -> i64 { return nx_f32_div(nx_i32_to_f32(n), nx_i32_to_f32(d)) }
16func tg_milli(v: i64) -> i64
32func tg_alloc(arena: *i64, ab: *i64, n: i64) -> *i64
41func tg_node(tape: *i64, nb: *i64, op: i64, ai: i64, bi: i64, rows: i64, cols: i64, valp: *i64, gradp: *i64) -> i64
55func tg_valp(tape: *i64, x: i64) -> *i64 { return tape[x*8+5] as *i64 }
56func tg_gradp(tape: *i64, x: i64) -> *i64 { return tape[x*8+6] as *i64 }
57func tg_leaf(tape: *i64, nb: *i64, arena: *i64, ab: *i64, p: *i64, rows: i64, cols: i64) -> i64
60func tg_matvec(tape: *i64, nb: *i64, arena: *i64, ab: *i64, a: i64, x: i64) -> i64
76func tg_addvec(tape: *i64, nb: *i64, arena: *i64, ab: *i64, x: i64, y: i64) -> i64
85func tg_reluvec(tape: *i64, nb: *i64, arena: *i64, ab: *i64, x: i64) -> i64
98func tg_mse(tape: *i64, nb: *i64, arena: *i64, ab: *i64, p: i64, t: i64) -> i64
117func tg_celoss(tape: *i64, nb: *i64, arena: *i64, ab: *i64, p: i64, t: i64) -> i64
149func tg_smul(tape: *i64, nb: *i64, arena: *i64, ab: *i64, x: i64, y: i64) -> i64
156func tg_backward(tape: *i64, nt: i64, root: i64) -> i64
243func 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