code wiki / (root) / nx_swarm_pack.nx

nx_swarm_pack.nx

buildroot/runtime/nx_swarm_pack.nx

31238 B578 linesdepth 4pulls 6 transitivereach 1 importersview sourcekind tooltopic swarm
docsdependenciesstructsconstsfunctions

about

nx_swarm_pack.nx -- SWARM FABRIC heterogeneous MAX-UTILIZATION scheduler (SF-R-PACK): get the MOST out of EVERY participant by exploiting ALL of its resources at once -- RAM, CPU cores, GPU, VRAM -- not routing a job to one class (operator 2026-07-15: "gpu was just an example ... use the ram cpu gpu whatever is available to get the most out of what participates in the supercomputer", the NIST/heterogeneous-compute model). A single participant can host MANY demands using DIFFERENT resources concurrently; work spreads to fill every participant's spare capacity. RESOURCE VECTOR (aligned to the beacon telemetry = the FEED): per participant pcpu = spare CPU milli-cores (beacon: (1000-lpc)*ncpu) · pram = free RAM MB (beacon mem_avail_mb) pgpu = GPU present 0/1 · pvram = free VRAM MB (the axis to wire from a GPU collector) DEMAND VECTOR: per chunk dcpu (milli-cores) · dram (MB) · dgpu (needs GPU 0/1) · dvram (MB) COMPOSES (check-before-build 2026-07-15): nx_resource_arbiter ALREADY models VRAM/RAM/CPU/GPU/net/disk as first-class allocatable kinds with fairness+preempt -- but is "fed by nothing". This packer IS that feed + the placement loop; the fairness/preempt/treaty LAYER wires to nx_resource_arbiter (nx_ra_request/grant) as the allocation policy SSOT. Hard-constraint classify = nx_swarm_coord. Telemetry = nx_node_beacon. ★★THE LIAR-KILLERS (the operator's principle, mechanized): (1) NO participant is ever over-allocated on ANY resource (sum assigned <= supply, per axis). (2) a demand is NEVER placed on a participant that lacks its REQUIRED resource -- a needs-GPU chunk never lands on a GPU-less node (GPU generalized to "whatever it requires"). (3) packing beats naive round-robin on placed-count (measured). (4) HETEROGENEOUS EXPLOITATION proven: one participant hosts DIFFERENT resource-type demands at once; no participant sits idle while a demand it could serve is queued. pack <poolfile> <jobsfile> -- pool line "name cpu_milli ram_mb gpu vram_mb"; job line "id cpu ram gpu vram" [gate] -- self-gate: the heterogeneous scenario + all four liar-killers license_tier: ORIGINAL expect_exit:0

dependencies 3 imports · 1 importers

nx_swarm_lib.nx nx_swarm_gpu.nx nx_readcap_lib.nx nx_swarm_pack.nx nx_swarm_pack_units_baseline_t70.n

imports: nx_swarm_lib.nxnx_swarm_gpu.nxnx_readcap_lib.nx

imported by: nx_swarm_pack_units_baseline_t70.nx

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main sg_eq sk_puts sb_path_ok fa_len sk2_int sk2_live sk2_pool sk2_read rc_fill_file rc_fill sys_read sys_mmap nxa_die nxa_lock_take nxa_lock_give nxa_report_overrun sys_read ↻ rc_complete sk2_row sk2_int ↻ sb_fields sys_mmap ↻ sb_validate sys_mmap ↻ sb_pint sb_pint ↻ sk2_name_equal sk2_copyname sk2_fresh sg_validate sys_mmap ↻ sg_pint sg_eq ↻ fa_cat fa_catn sys_mmap ↻ sk2_state sk2_jobs sk2_read ↻

structs

none

consts

31const SK_MAGIC_8000: i64 = 8000
32const SK_MAGIC_16000: i64 = 16000
33const SK_MAGIC_12000: i64 = 12000
34const SK_MAGIC_3000: i64 = 3000
35const SK_MAGIC_32000: i64 = 32000
36const SK_MAGIC_4000: i64 = 4000
37const SK_MAGIC_5000: i64 = 5000
38const SK_MAGIC_20000: i64 = 20000
39const SK_MAGIC_2000: i64 = 2000
40const SK_MAGIC_65536: i64 = 65536
41const SK_MAGIC_8192: i64 = 8192
42const SK_MAGIC_1000000: i64 = 1000000
44const SK_MAXP: i64 = 256
45const SK_MAXD: i64 = 4096
440const SK2_VERSION:i64=2
441const SK2_FIELDS:i64=10
442const SK2_NAME:i64=32
443const SK2_MAX:i64=9223372036854775807
444const SK2_UNIT:i64=1000000
445const SK2_UNKNOWN:i64=0
446const SK2_FRESH:i64=1
447const SK2_STALE:i64=2
448const SK2_REFUSED:i64=3
449const SK2_IO:i64=0-40
450const SK2_TRUNCATED:i64=0-41
451const SK2_FRAME:i64=0-42
452const SK2_ROW:i64=0-43
453const SK2_DUPLICATE:i64=0-44
454const SK2_CAPACITY:i64=0-45
455const SK2_POLICY:i64=0-46
456const SK2_MISSING:i64=0-47

functions

47func sk_puts(s: *u8) -> i64 { sys_write(1, s, fa_len(s)); return 0 }
called by 3: sk_gatesk_livemain
53func sk_place_one(pcpu: *i64, pram: *i64, pgpu: *i64, pvram: *i64, n: i64, dcpu: i64, dram: i64, dgpu: i64, dvram: i64) -> i64
called by 1: sk_pack
81func sk_pack(pcpu: *i64, pram: *i64, pgpu: *i64, pvram: *i64, n: i64,
called by 3: sk_gatesk_livesk2_live calls 1: sk_place_one
120func sk_naive(pcpu: *i64, pram: *i64, pgpu: *i64, pvram: *i64, n: i64,
called by 1: sk_gate
142func sk_report(names: *i64, pcpu0: *i64, pram0: *i64, pgpu: *i64, pcpu: *i64, pram: *i64, n: i64,
called by 2: sk_gatesk_live calls 2: fa_catfa_catn
172func sk_types_on(part: i64, dram: *i64, dgpu: *i64, m: i64, assign: *i64) -> i64
called by 1: sk_gate
186func sk_gate() -> i64
303func sk_skipsp(buf: *u8, n: i64, p: i64) -> i64
called by 1: sk_load_jobs
311func sk_roster_has(roster: *u8, name: *u8, nl: i64) -> i64
called by 1: sk_load_pool
333func sk_load_pool(snap: *u8, roster: *u8, names: *i64, pcpu: *i64, pram: *i64, pgpu: *i64, pvram: *i64, maxn: i64) -> i64
377func sk_load_jobs(jobs: *u8, dcpu: *i64, dram: *i64, dgpu: *i64, dvram: *i64, maxm: i64) -> i64
called by 1: sk_live calls 3: sb_readsk_skipspsb_pint
402func sk_live(snap: *u8, jobs: *u8, roster: *u8) -> i64
458func sk2_int(b:*u8,n:i64,p:i64,out:*i64)->i64
called by 3: sk2_rowsk2_jobsmain
465func sk2_row(b:*u8,n:i64,prefix:*u8,numbers:i64,values:*i64,name:*i64)->i64
called by 1: sk2_pool calls 1: sk2_int
475func sk2_read(path:*u8,b:*u8)->i64
481func sk2_fresh(ts:i64,now:i64,window:i64,skew:i64)->i64
called by 1: sk2_pool
485func sk2_name_equal(a:*u8,b:*u8,n:i64)->i64{var i:i64=0;while i<n{if a[i]!=b[i]{return 0};i=i+1};if a[n]!=(0 as u8){return 0};return 1}
called by 1: sk2_pool
486func sk2_copyname(b:*u8,start:i64,n:i64)->*u8{let p:*u8=sys_mmap(SK2_NAME+1);var i:i64=0;while i<n{p[i]=b[start+i];i=i+1};p[n]=0 as u8;return p}
called by 1: sk2_pool
489func sk2_pool(nodes:*u8,gpus:*u8,now:i64,nwin:i64,gwin:i64,skew:i64,out:*i64,cap:i64,meta:*i64)->i64
529func sk2_state(v:i64)->*u8{if v==SK2_FRESH{return "fresh" as *u8};if v==SK2_STALE{return "stale" as *u8};if v==SK2_REFUSED{return "refused" as *u8};return "unknown" as *u8}
called by 1: sk2_live
530func sk2_jobs(path:*u8,cpu:*i64,ram:*i64,gpu:*i64,vram:*i64,cap:i64)->i64
called by 1: sk2_live calls 2: sk2_readsk2_int
539func sk2_live(nodes:*u8,gpus:*u8,jobs:*u8,now:i64,nwin:i64,gwin:i64,skew:i64)->i64
557func main(argc: i64, argv: *i64) -> i64