nx_ribosome_test.nx source
↩ module page · 72 lines · 3103 B
1// nx_ribosome_test.nx -- smoke for nx_ribosome.
2
3import "nx_syscalls.nx"
4import "nx_tier.nx"
5import "nx_attention_class.nx"
6import "nx_metabolism.nx"
7import "nx_ribosome.nx"
8
9func main() -> i64 {
10 // 1: enum sealed 15 targets
11 if NX_RBT_N_TARGETS != 15 { return 1 }
12
13 // 2: validation
14 if nx_rbt_is_valid(NX_RBT_X86_64) != 1 { return 2 }
15 if nx_rbt_is_valid(NX_RBT_SILICON_HDL) != 1 { return 3 }
16 if nx_rbt_is_valid(-1) != 0 { return 4 }
17 if nx_rbt_is_valid(15) != 0 { return 5 }
18
19 // 3: family classification
20 if nx_rbt_family(NX_RBT_X86_64) != NX_RBF_CPU { return 6 }
21 if nx_rbt_family(NX_RBT_AARCH64) != NX_RBF_CPU { return 7 }
22 if nx_rbt_family(NX_RBT_CORTEX_M) != NX_RBF_MCU { return 8 }
23 if nx_rbt_family(NX_RBT_PTX) != NX_RBF_GPU { return 9 }
24 if nx_rbt_family(NX_RBT_GCN) != NX_RBF_GPU { return 10 }
25 if nx_rbt_family(NX_RBT_METAL) != NX_RBF_GPU { return 11 }
26 if nx_rbt_family(NX_RBT_WASM) != NX_RBF_WASM { return 12 }
27 if nx_rbt_family(NX_RBT_SILICON_HDL) != NX_RBF_SILICON { return 13 }
28
29 // 4: is_cpu/is_gpu predicates
30 if nx_rbt_is_cpu(NX_RBT_X86_64) != 1 { return 14 }
31 if nx_rbt_is_gpu(NX_RBT_X86_64) != 0 { return 15 }
32 if nx_rbt_is_gpu(NX_RBT_PTX) != 1 { return 16 }
33 if nx_rbt_is_cpu(NX_RBT_PTX) != 0 { return 17 }
34
35 // 5: default for tier
36 if nx_ribosome_default_for_tier(NX_TIER_MCU) != NX_RBT_CORTEX_M { return 18 }
37 if nx_ribosome_default_for_tier(NX_TIER_SOVEREIGN_CHIP) != NX_RBT_SILICON_HDL { return 19 }
38 if nx_ribosome_default_for_tier(NX_TIER_FAMILY_DEVICE) != NX_RBT_AARCH64 { return 20 }
39 if nx_ribosome_default_for_tier(NX_TIER_WORKSTATION) != NX_RBT_X86_64 { return 21 }
40 if nx_ribosome_default_for_tier(NX_TIER_HPC) != NX_RBT_PTX { return 22 }
41
42 // 6: pick honors explicit pathway preference
43 let nullm: *NxMetabolism = (0 as i64) as *NxMetabolism
44 let r1: nx_int = nx_ribosome_pick(NX_TIER_WORKSTATION,
45 nullm, 0, NX_RBT_PTX)
46 if r1 != NX_RBT_PTX { return 23 }
47
48 // 7: pick falls back to tier default when prefer is invalid sentinel
49 let r2: nx_int = nx_ribosome_pick(NX_TIER_MCU,
50 nullm, 0, NX_RBT_N_TARGETS)
51 if r2 != NX_RBT_CORTEX_M { return 24 }
52
53 // 8: metabolism promotes target above tier baseline
54 let m: *NxMetabolism = nx_metab_new(8)
55 var i: nx_int = 0
56 while i < 4200 { // crosses VECTOR threshold -> SERVER tier
57 nx_metab_record(m, 1234, 10, 0, NX_AC_DEV)
58 i = i + 1
59 }
60 let r3: nx_int = nx_ribosome_pick(NX_TIER_WORKSTATION,
61 m, 1234, NX_RBT_N_TARGETS)
62 if nx_rbt_is_valid(r3) != 1 { return 25 }
63
64 // 9: cost-q10 ordering: silicon < gpu < cpu < mcu
65 if nx_ribosome_cost_q10(NX_RBT_SILICON_HDL) >= nx_ribosome_cost_q10(NX_RBT_PTX) { return 26 }
66 if nx_ribosome_cost_q10(NX_RBT_PTX) >= nx_ribosome_cost_q10(NX_RBT_X86_64) { return 27 }
67 if nx_ribosome_cost_q10(NX_RBT_X86_64) >= nx_ribosome_cost_q10(NX_RBT_CORTEX_M) { return 28 }
68 if nx_ribosome_cost_q10(NX_RBT_X86_64) != 1024 { return 29 }
69 if nx_ribosome_cost_q10(NX_RBT_SILICON_HDL) != 64 { return 30 }
70
71 return 0
72}