nx_vitpose_forward.nx
buildroot/runtime/nx_vitpose_forward.nx
about
nx_vitpose_forward.nx -- THE CULMINATING RUNG: the full faithful f32 ViTPose-base forward, composing every gated
rung on the REAL downloaded weights. Reads the 343MB safetensors into RAM once, loads tensors by name (per-layer
buffers reused across the 12 layers so only ~57MB of expanded weights live at a time), then:
patch-embed conv -> 192 tokens + pos_embed[:,1:] -> 12x nx_vit_encoder_layer -> final backbone.layernorm ->
reshape 192->768x16x12 -> ReLU -> bilinear x4 -> head.conv(768->17,k3,p1) -> ReLU -> nx_pose_extract -> 17 kpts.
(ReLU before the integer keypoint argmax: the trained heatmap peak is positive, so it preserves the peak cell.)
Structural validation on a synthetic image: runs end-to-end, 17 finite heatmaps, 17 keypoints in the 48x64 (x4)
quarter-pixel range. Semantic validation (keypoints on a real person) = the follow-on image pipeline. expect_exit: 0
dependencies 10 imports · 0 importers
imports: nx_syscalls.nxnx_f32.nxnx_f32_cvt.nxnx_f32_conv2d.nxnx_f32_layernorm.nxnx_f32_upsample_bilinear.nxnx_pose_cnn.nxnx_pose_keypoints.nxnx_safetensors_load.nxnx_vit_encoder_layer.nx
imported by: nobody (leaf or entry point)
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| none |
consts
| 19 | const K_MAGIC_4096: i64 = 4096 |
| 20 | const K_MAGIC_345000000: i64 = 345000000 |
| 21 | const K_MAGIC_3072: i64 = 3072 |
| 22 | const K_MAGIC_1000000000: i64 = 1000000000 |
functions
| 24 | func w(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } |
| 25 | func wn(v: i64) -> i64 { var m: i64=v; if m<0{w("-" as *u8);m=0-m} let t:*u8=sys_mmap(24); var k:i64=0; if m==0{t[0]=48 as u8;k=1} while m>0{t[k]=(48+(m%10)) as u8;m=m/10;k=k+1} var i:i64=0; let o:*u8=sys_mmap(24); while i<k{o[i]=t[k-1-i];i=i+1} sys_write(1,o,k); return 0 } |
| 26 | func rdcfg(path: *u8, buf: *u8, cap: i64) -> i64 { let fd: i64=sys_openat_rd(path); if fd<0{return 0-1} var n: i64=sys_read(fd,buf,cap-1); sys_close(fd); if n<0{return 0-1} var go: i64=1; while go==1{go=0; if n>0{ let c: i64=buf[n-1] as i64; if c==10{n=n-1;go=1} if c==13{n=n-1;go=1} if c==32{n=n-1;go=1} }} buf[n]=0 as u8; return n } |
| 27 | func u64le(buf: *u8, off: i64) -> i64 { var v: i64=0; var i: i64=0; while i<8 { v=v|((buf[off+i]&0xff)<<(i*8)); i=i+1 } return v } called by 1: main |
| 28 | func catn(dst: *u8, off: i64, s: *u8) -> i64 { var o: i64=off; var i: i64=0; while s[i]!=(0 as u8){dst[o]=s[i];o=o+1;i=i+1} return o } called by 1: main |
| 29 | func catnum(dst: *u8, off: i64, v: i64) -> i64 { var m: i64=v; let t: *u8=sys_mmap(24); var k: i64=0; if m==0{t[0]=48 as u8;k=1} while m>0{t[k]=(48+(m%10)) as u8;m=m/10;k=k+1} var o: i64=off; var i: i64=0; while i<k{dst[o]=t[k-1-i];o=o+1;i=i+1} return o } |
| 32 | func loadt(fb: *u8, hlen: i64, ds: i64, name: *u8, out: *i64) -> i64 |
| 38 | func main() -> i64 |