nx_safetensors_load.nx
buildroot/runtime/nx_safetensors_load.nx
about
nx_safetensors_load.nx -- the STANDARD, reusable safetensors -> f32 LOADER library (importable, no main), the
model-port driver's stage-4/5 for safetensors models (ViTPose etc.). The existing nx_safetensors.nx is a
main()-based demo (bounded-header-read proof) and cannot be imported; this is the clean lib the port + any HF
safetensors model uses. Format: [0..8) u64le header_len N; [8..8+N) JSON header {"tname":{"dtype","shape",
"data_offsets":[a,b]},...}; [8+N..) data, tensor bytes at [8+N+a, 8+N+b). Reads F32 (bits direct), F16
(nx_f16_to_f32), BF16 (= high 16 bits of an f32 -> <<16) into an i64-held-f32 buffer. license_tier: ORIGINAL
dependencies 2 imports · 4 importers
imports: nx_syscalls.nxnx_f32_cvt.nx
imported by: nx_safetensors_load_gate.nxnx_vitpose_forward.nxnx_vitpose_loadtest.nxnx_vitpose_patchembed.nx
structs
| none |
consts
| none |
functions
| 10 | func stl_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 } |
| 11 | func stl_u32le(buf: *u8, off: i64) -> i64 { return (buf[off]&0xff) | ((buf[off+1]&0xff)<<8) | ((buf[off+2]&0xff)<<16) | ((buf[off+3]&0xff)<<24) } called by 1: stl_read_f32 |
| 12 | func stl_u16le(buf: *u8, off: i64) -> i64 { return (buf[off]&0xff) | ((buf[off+1]&0xff)<<8) } called by 1: stl_read_f32 |
| 14 | func stl_streq(a: *u8, b: *u8) -> i64 { var i: i64=0; while a[i]!=(0 as u8){ if a[i]!=b[i]{return 0} i=i+1 } if b[i]!=(0 as u8){return 0} return 1 } |
| 17 | func stl_find(buf: *u8, n: i64, from: i64, needle: *u8) -> i64 called by 1: stl_tensor |
| 31 | func stl_parse_int(buf: *u8, pos: i64, endp: *i64) -> i64 called by 1: stl_tensor |
| 41 | func stl_header_len(buf: *u8) -> i64 { return stl_u64le(buf, 0) } |
| 42 | func stl_data_start(buf: *u8) -> i64 { return 8 + stl_u64le(buf, 0) } |
| 46 | func stl_tensor(buf: *u8, hlen: i64, name: *u8, dtype_out: *u8, offs: *i64) -> i64 |
| 68 | func stl_read_f32(buf: *u8, data_start: i64, offs: *i64, dtype: *u8, out: *i64) -> i64 |