code wiki / (root) / nx_nofloat_serve_core.nx

nx_nofloat_serve_core.nx

buildroot/runtime/nx_nofloat_serve_core.nx

69093 B1382 linesdepth 9pulls 26 transitivereach 42 importersview sourcekind librarytopic nofloat
docsdependenciesstructsconstsfunctions

about

nx_nofloat_serve_core.nx -- the PURE CORE of the no-float LLM serve organ (2026-07-10): model session + greedy generation + HTTP request handler, NO sockets (the daemon shell owns those; the gate exercises this core in-process with synthetic requests -- the proven pure-core+gate+daemon idiom). nsv_init(path) one-time: load GGUF, tokenizer meta, dequant-once i32 (lossless hero) + i8 (fast) caches. nsv_generate(gp) ctx-bundle: sequential CACHED prefill (decode_step per prompt token -- mathematically identical to batch prefill under causal masking) then greedy decode; text out through the byte-level-BPE inverse (nx_nofloat_tokdec) so ' Paris' renders as real text. nsv_handle(...) routes: GET / (app page) GET /health GET /api POST /gen {prompt,max_new,mode}. license_tier: ORIGINAL No hw writes (Rule 26).

dependencies 12 imports · 19 importers

nx_syscalls.nx nx_tier.nx nx_le.nx nx_tensor.nx nx_gguf.nx nx_gguf_load.nx nx_gguf_meta.nx nx_nofloat_llm.nx nx_nofloat_tok.nx nx_nofloat_tokdec.nx nx_nofloat_serve_core.nx nx_bright_rewrite_lib.nx nx_code_embed_gate.nx nx_coder_gen_nf.nx nx_forge_bestof.nx nx_forge_local_gen.nx nx_forge_repair.nx nx_gpu_embed_gate.nx nx_gramdec_lib.nx nx_jina_embed_gate.nx nx_nofloat_prefill_gate.nx

diagram shows first 10 each side; +2 more imports, +9 more importers in the complete lists below.

imports: nx_syscalls.nxnx_tier.nxnx_le.nxnx_tensor.nxnx_gguf.nxnx_gguf_load.nxnx_gguf_meta.nxnx_nofloat_llm.nxnx_nofloat_tok.nxnx_nofloat_tokdec.nxnx_nofloat_arch.nxnx_nofloat_q4k.nx

imported by: nx_bright_rewrite_lib.nxnx_code_embed_gate.nxnx_coder_gen_nf.nxnx_forge_bestof.nxnx_forge_local_gen.nxnx_forge_repair.nxnx_gpu_embed_gate.nxnx_gramdec_lib.nxnx_jina_embed_gate.nxnx_nofloat_prefill_gate.nxnx_nofloat_prefix_cache_gate.nxnx_nofloat_qgap_probe.nxnx_nofloat_serve.nxnx_nofloat_serve_gate.nxnx_nofloat_speed_bench.nxnx_propose_verify_lib.nxnx_qwen_extract.nxnx_qwen_reader_bench_gate.nxnx_research_synth_qwen.nx

structs

none

consts

23const NSV_MAXT: i64 = 2048 // final prompt+gen TOKEN cap (KV cache rows). L2 raise 384->2048 (FORGE 2026-07-12)
27const NSV_MAXIN: i64 = 16384 // max prompt BYTES for the tokenizer's byte-level pretokenize scratch (tok_ptr/tok_len).
31const NSV_MAXNEW: i64 = 512 // per-request generation cap (L2 raise 96->512 for whole small organs)
32const NSV_CHATML_IDS: i64 = 8 // ids the ChatML wrapper adds around the content (two markers plus the user, newline and assistant pieces)
33const NSV_ERR_TOO_LONG: i64 = 3 // meta[5] for a prompt past the byte cap or the token cap: refused at the door, never half-encoded
34const NSV_PREFILL_BATCHED_DEFAULT: i64 = 1 // R0r: the i8 route prefills in blocks through nf_prefill_batched (nx_nofloat_prefill_gate proves it bit-identical); declared here because its first reader is the scratch allocator
35const NSV_EOS1: i64 = 151643
36const NSV_EOS2: i64 = 151645
330const NSV_MODE_I32: i64 = 0
331const NSV_MODE_I8: i64 = 1
332const NSV_MODE_Q4K: i64 = 3 // 2 is the GPU embed grading mode (nsv_embed) -- never reuse it for a decode route

functions

72func nsv_slen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n }
73func nsv_cat(dst: *u8, off: i64, s: *u8) -> i64 { var i: i64=0; while s[i]!=(0 as u8){dst[off+i]=s[i];i=i+1} return off+i }
74func nsv_catb(dst: *u8, off: i64, s: *u8, n: i64) -> i64 { var i: i64=0; while i<n {dst[off+i]=s[i];i=i+1} return off+n }
75func nsv_catn(dst: *u8, off: i64, v: i64) -> i64
88func nsv_log(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
96func nsv_load_meta(path: *u8) -> i64
172func nsv_alloc_scratch() -> i64
called by 1: nsv_init calls 3: nsv_logsys_mmaprope_freqs
238func nsv_init_i8(path: *u8) -> i64
called by 9: mainmainmainmainmainmain+3 calls 1: nsv_init
245func nsv_init_i32only(path: *u8) -> i64
called by 1: qg_run calls 1: nsv_init
253func nsv_init_q4k(path: *u8) -> i64
called by 2: qg_runmain calls 1: nsv_init
258func nsv_init(path: *u8) -> i64
277func nsv_build_caches() -> i64
327func nsv_logn(v: i64) -> i64 { let t: *u8 = sys_mmap(32); let n: i64 = nsv_catn(t, 0, v); sys_write(1, t, n); return 0 }
333func nsv_step(pos: i64, mode: i64) -> i64
347func nsv_prefill_seq(nprompt: i64, mode: i64) -> i64
called by 1: nsv_generate calls 2: dequant_rownsv_step
360func nsv_prefill_i8_batched(nprompt: i64) -> i64
379func nsv_rand(sp: *i64) -> i64
called by 1: nsv_sample
393func nsv_sample(sp: *i64) -> i64
466func nsv_next_token(np: *i64) -> i64
486func nsv_emit_piece(tok: i64, ep: *i64) -> i64
515func nsv_chatml_ids(content: *u8, clen: i64) -> i64
555func nsv_prompt_admit(plen: i64) -> i64
563func nsv_generate(gp: *i64) -> i64
651func nsv_kv_snapshot(P: i64) -> i64
called by 1: nsv_generate_pfx calls 1: sys_mmap
675func nsv_kv_restore() -> i64
called by 1: nsv_generate_pfx
700func nsv_kv_snapshot_save(path: *u8) -> i64
718func nsv_kv_snapshot_load(path: *u8) -> i64
750func nsv_generate_pfx(gp: *i64, prefix_len: i64, use_snap: i64) -> i64
863func nsv_gwall(fd: i64, buf: *u8, count: i64) -> i64
called by 1: nsv_embed calls 1: sys_write
874func nsv_grall(fd: i64, buf: *u8, count: i64) -> i64
called by 1: nsv_embed calls 1: sys_read
885func nsv_gpu_connect() -> i64
905func nsv_embed(text: *u8, tlen: i64, mode: i64, outvec: *i64) -> i64
945func nsv_resp(resb: *u8, rescap: i64, code: i64, ctype: *u8, body: *u8, blen: i64) -> i64
called by 1: nsv_handle calls 3: nsv_catnsv_catnnsv_catb
959func nsv_jesc1(dst: *u8, o: i64, c: i64) -> i64
called by 1: nsv_jesc
970func nsv_jesc(dst: *u8, off: i64, src: *u8, n: i64) -> i64
977func nsv_jkey(body: *u8, n: i64, key: *u8) -> i64
995func nsv_jstr(body: *u8, n: i64, p: i64, dst: *u8, dcap: i64) -> i64
1021func nsv_jint(body: *u8, n: i64, p: i64, def: i64) -> i64
1045func nsv_page(dst: *u8, cap: i64) -> i64
called by 1: nsv_handle calls 1: nsv_cat
1053func nsv_parse_gen(req: *u8, rn: i64, gp: *i64) -> i64
1108func nsv_embed_prefix(task: *u8, tl: i64, kq: i64) -> *u8
called by 1: nsv_handle
1131func nsv_parse_embed(req: *u8, rn: i64, ep: *i64) -> i64
called by 1: nsv_handle calls 3: sys_mmapnsv_jkeynsv_jstr
1183func nsv_handle_stream(fd: i64, req: *u8, rn: i64) -> i64
1228func nsv_handle(req: *u8, rn: i64, resb: *u8, rescap: i64) -> i64