Run frontier MoE models on hardware you already own — pure C, zero deps, experts streamed from disk. Tiny engine, immense model. 🐦
C
tests: link $(VK_OBJ) into the rest of the engine-including rules
Kenneth-Javier Ortigoza9312b077ba87
diff --git a/c/Makefile b/c/Makefileindex 370160e7..ddc3ea5d 100644--- a/c/Makefile+++ b/c/Makefile@@ -1354,8 +1354,8 @@ tests/test_ue8m0$(EXE): tests/test_ue8m0.c st.h json.h compat.h# Compiles the engine with -DCOLI_XDNA so the QT side pointer, its reset helper# and the expert-slot wiring are exercised as the engine actually builds them.-tests/test_xdna_qt_state$(EXE): tests/test_xdna_qt_state.c colibri.c backend_xdna.c backend_xdna.h st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h sample.h kv_persist.h telemetry.h route_trace.h- $(CC) $(CFLAGS) -DCOLI_XDNA $< backend_xdna.c -o $@ $(LDFLAGS)+tests/test_xdna_qt_state$(EXE): tests/test_xdna_qt_state.c colibri.c backend_xdna.c backend_xdna.h st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h sample.h kv_persist.h telemetry.h route_trace.h $(VK_OBJ)+ $(CC) $(CFLAGS) -DCOLI_XDNA $< backend_xdna.c $(VK_OBJ) -o $@ $(LDFLAGS)tests/test_xdna_prepared_state$(EXE): tests/test_xdna_prepared_state.c backend_xdna.c backend_xdna.h compat.h$(CC) $(CFLAGS) $< -o $@ $(LDFLAGS)@@ -1381,8 +1381,8 @@ tests/test_xdna_execution$(EXE): tests/test_xdna_execution.c backend_xdna.c back# Failure/fallback owner. Needs BOTH the engine (matmul_qt is the fallback# target it verifies against) and the synthetic ABI-2 helpers, which is why it# is a separate owner from test_xdna_execution.-tests/test_xdna_failure$(EXE): tests/test_xdna_failure.c colibri.c backend_xdna.c backend_xdna.h st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h sample.h kv_persist.h telemetry.h route_trace.h $(XDNA_FAKE_HELPERS)- $(CC) $(CFLAGS) -DCOLI_XDNA $< backend_xdna.c -o $@ $(LDFLAGS)+tests/test_xdna_failure$(EXE): tests/test_xdna_failure.c colibri.c backend_xdna.c backend_xdna.h st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h sample.h kv_persist.h telemetry.h route_trace.h $(XDNA_FAKE_HELPERS) $(VK_OBJ)+ $(CC) $(CFLAGS) -DCOLI_XDNA $< backend_xdna.c $(VK_OBJ) -o $@ $(LDFLAGS)# NOT a test gate -- intentionally absent from TEST_BINS (its name does not match# the tests/test_*$(EXE) pattern the gate list is derived from). It needs a real@@ -1393,8 +1393,8 @@ tests/test_xdna_failure$(EXE): tests/test_xdna_failure.c colibri.c backend_xdna.## M-list defaults to 1,32,64 (the M64 bucket); pass 65,130,256 to qualify# the M256 bucket through the same owner.-tests/xdna_physical_probe$(EXE): tests/xdna_physical_probe.c colibri.c backend_xdna.c backend_xdna.h st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h sample.h kv_persist.h telemetry.h route_trace.h- $(CC) $(CFLAGS) -DCOLI_XDNA $< backend_xdna.c -o $@ $(LDFLAGS)+tests/xdna_physical_probe$(EXE): tests/xdna_physical_probe.c colibri.c backend_xdna.c backend_xdna.h st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h sample.h kv_persist.h telemetry.h route_trace.h $(VK_OBJ)+ $(CC) $(CFLAGS) -DCOLI_XDNA $< backend_xdna.c $(VK_OBJ) -o $@ $(LDFLAGS)tests/test_json$(EXE): tests/test_json.c json.h$(CC) $(CFLAGS) $< -o $@ $(LDFLAGS)@@ -1540,14 +1540,14 @@ tests/test_grammar_cache$(EXE): tests/test_grammar_cache.c sse41_kernels.h colib# agreement check against the plain logprob_target the sampling path uses# on rows a float subtraction cannot mis-round, and a double-precision# check against a second double computation on rows that do.-tests/test_logprob_status$(EXE): tests/test_logprob_status.c colibri.c sse41_kernels.h exact_dot.h oracle.h sample.h evidence_digest.h st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h fp8_format.h idot.h kv_persist.h telemetry.h route_trace.h- $(CC) $(CFLAGS) $< -o $@ $(LDFLAGS)+tests/test_logprob_status$(EXE): tests/test_logprob_status.c colibri.c sse41_kernels.h exact_dot.h oracle.h sample.h evidence_digest.h st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h fp8_format.h idot.h kv_persist.h telemetry.h route_trace.h $(VK_OBJ)+ $(CC) $(CFLAGS) $< $(VK_OBJ) -o $@ $(LDFLAGS)# The ablation mode's manifest loader, evidence writer and dispatch contract.# The adapter build bypasses only the model computation, so the parser/writer# path is exercised for real with no model and no weights.-tests/test_ablate_mode$(EXE): tests/test_ablate_mode.c colibri.c sse41_kernels.h exact_dot.h oracle.h sample.h evidence_digest.h abl.h st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h fp8_format.h idot.h kv_persist.h telemetry.h route_trace.h- $(CC) $(CFLAGS) $< -o $@ $(LDFLAGS)+tests/test_ablate_mode$(EXE): tests/test_ablate_mode.c colibri.c sse41_kernels.h exact_dot.h oracle.h sample.h evidence_digest.h abl.h st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h fp8_format.h idot.h kv_persist.h telemetry.h route_trace.h $(VK_OBJ)+ $(CC) $(CFLAGS) $< $(VK_OBJ) -o $@ $(LDFLAGS)# Standalone: drives a faithful miniature of moe()'s routing+accumulate and links# the SAME abl.h the engine links -- no model/weights needed (the ablation-logic gate).@@ -1648,8 +1648,8 @@ tests/test_topp$(EXE): tests/test_topp.c sse41_kernels.h colibri.c oracle.h st.h# bench_topp is a microbenchmark (old qsort vs new heap partial-select, #335), NOT a test# gate -- intentionally absent from TEST_BINS. Build on demand: make tests/bench_topp-tests/bench_topp$(EXE): tests/bench_topp.c sse41_kernels.h colibri.c oracle.h st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h fp8_format.h idot.h sample.h kv_persist.h telemetry.h route_trace.h- $(CC) $(CFLAGS) $< -o $@ $(LDFLAGS)+tests/bench_topp$(EXE): tests/bench_topp.c sse41_kernels.h colibri.c oracle.h st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h fp8_format.h idot.h sample.h kv_persist.h telemetry.h route_trace.h $(VK_OBJ)+ $(CC) $(CFLAGS) $< $(VK_OBJ) -o $@ $(LDFLAGS)tests/test_sample_nan$(EXE): tests/test_sample_nan.c sse41_kernels.h colibri.c oracle.h st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h fp8_format.h idot.h sample.h kv_persist.h telemetry.h route_trace.h $(VK_OBJ)$(CC) $(CFLAGS) $< $(VK_OBJ) -o $@ $(LDFLAGS)@@ -2168,13 +2168,13 @@ tests/test_ssd_probe$(EXE): tests/test_ssd_probe.c sse41_kernels.h colibri.c ora# bench_dsa_select is a microbenchmark (old qsort vs new quickselect partial-select, #356),# NOT a test gate -- intentionally absent from TEST_BINS. Build on demand: make tests/bench_dsa_select-tests/bench_dsa_select$(EXE): tests/bench_dsa_select.c sse41_kernels.h colibri.c oracle.h st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h fp8_format.h idot.h sample.h kv_persist.h telemetry.h route_trace.h- $(CC) $(CFLAGS) $< -o $@ $(LDFLAGS)+tests/bench_dsa_select$(EXE): tests/bench_dsa_select.c sse41_kernels.h colibri.c oracle.h st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h fp8_format.h idot.h sample.h kv_persist.h telemetry.h route_trace.h $(VK_OBJ)+ $(CC) $(CFLAGS) $< $(VK_OBJ) -o $@ $(LDFLAGS)# bench_router_select is a microbenchmark (duplicate-prefix scan vs marked-score scan),# not a test gate. Build on demand: make tests/bench_router_select.-tests/bench_router_select$(EXE): tests/bench_router_select.c sse41_kernels.h colibri.c oracle.h st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h fp8_format.h idot.h sample.h kv_persist.h telemetry.h route_trace.h- $(CC) $(CFLAGS) $< -o $@ $(LDFLAGS)+tests/bench_router_select$(EXE): tests/bench_router_select.c sse41_kernels.h colibri.c oracle.h st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h fp8_format.h idot.h sample.h kv_persist.h telemetry.h route_trace.h $(VK_OBJ)+ $(CC) $(CFLAGS) $< $(VK_OBJ) -o $@ $(LDFLAGS)# bench_indexer_allocations: microbenchmark (DeepSeek V4 indexer malloc vs persistent arena scratch), NOT a test gate.# Build on demand: make tests/bench_indexer_allocations@@ -2183,24 +2183,24 @@ tests/bench_indexer_allocations$(EXE): tests/bench_indexer_allocations.c# bench_idot: microbenchmark (single-acc vs independent-acc AVX-VNNI idot), NOT a test gate.# Build on demand on an AVX-VNNI CPU: make tests/bench_idot ARCH=native-tests/bench_idot$(EXE): tests/bench_idot.c sse41_kernels.h colibri.c oracle.h st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h fp8_format.h idot.h sample.h kv_persist.h telemetry.h route_trace.h- $(CC) $(CFLAGS) $< -o $@ $(LDFLAGS)+tests/bench_idot$(EXE): tests/bench_idot.c sse41_kernels.h colibri.c oracle.h st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h fp8_format.h idot.h sample.h kv_persist.h telemetry.h route_trace.h $(VK_OBJ)+ $(CC) $(CFLAGS) $< $(VK_OBJ) -o $@ $(LDFLAGS)# bench_i4p_gidot: microbenchmark (per-row vs multi-row/AMX K1b grouped planar IDOT), NOT a test gate.# Build on demand: make tests/bench_i4p_gidot ARCH=native-tests/bench_i4p_gidot$(EXE): tests/bench_i4p_gidot.c sse41_kernels.h colibri.c oracle.h st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h fp8_format.h idot.h sample.h kv_persist.h telemetry.h route_trace.h- $(CC) $(CFLAGS) $< -o $@ $(LDFLAGS)+tests/bench_i4p_gidot$(EXE): tests/bench_i4p_gidot.c sse41_kernels.h colibri.c oracle.h st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h fp8_format.h idot.h sample.h kv_persist.h telemetry.h route_trace.h $(VK_OBJ)+ $(CC) $(CFLAGS) $< $(VK_OBJ) -o $@ $(LDFLAGS)# bench_gemv_stream: microbenchmark (decode-regime GEMV bandwidth vs the read ceiling;# frozen-baseline + deinterleaved-x candidate A/B), NOT a test gate.# Build on demand: make tests/bench_gemv_stream ARCH=native-tests/bench_gemv_stream$(EXE): tests/bench_gemv_stream.c sse41_kernels.h colibri.c oracle.h st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h fp8_format.h idot.h sample.h kv_persist.h telemetry.h route_trace.h- $(CC) $(CFLAGS) $< -o $@ $(LDFLAGS)+tests/bench_gemv_stream$(EXE): tests/bench_gemv_stream.c sse41_kernels.h colibri.c oracle.h st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h fp8_format.h idot.h sample.h kv_persist.h telemetry.h route_trace.h $(VK_OBJ)+ $(CC) $(CFLAGS) $< $(VK_OBJ) -o $@ $(LDFLAGS)# bench_mla_simd: microbenchmark (scalar vs AVX2/NEON MLA-absorb reductions, #442),# NOT a test gate. Build on demand: make tests/bench_mla_simd-tests/bench_mla_simd$(EXE): tests/bench_mla_simd.c sse41_kernels.h colibri.c oracle.h st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h fp8_format.h idot.h sample.h kv_persist.h telemetry.h route_trace.h- $(CC) $(CFLAGS) $< -o $@ $(LDFLAGS)+tests/bench_mla_simd$(EXE): tests/bench_mla_simd.c sse41_kernels.h colibri.c oracle.h st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h fp8_format.h idot.h sample.h kv_persist.h telemetry.h route_trace.h $(VK_OBJ)+ $(CC) $(CFLAGS) $< $(VK_OBJ) -o $@ $(LDFLAGS)tests/test_uring$(EXE): tests/test_uring.c sse41_kernels.h colibri.c oracle.h st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h fp8_format.h idot.h sample.h kv_persist.h telemetry.h route_trace.h $(VK_OBJ)$(CC) $(CFLAGS) $< $(VK_OBJ) -o $@ $(LDFLAGS)@@ -2270,8 +2270,8 @@ tests/test_shard_kvb_refuse$(EXE): tests/test_shard_kvb_refuse.c colibri.c st.h# exists so it also compiles under the suite's own $(CFLAGS) rather than only# under the driver's hand-copied flag list, and so a warning regression in it# fails the normal build.-tests/test_e8x4g64_loader$(EXE): tests/test_e8x4g64_loader.c st.h quant.h fp8_format.h compat.h- $(CC) $(CFLAGS) $< -o $@ $(LDFLAGS)+tests/test_e8x4g64_loader$(EXE): tests/test_e8x4g64_loader.c st.h quant.h fp8_format.h compat.h $(VK_OBJ)+ $(CC) $(CFLAGS) $< $(VK_OBJ) -o $@ $(LDFLAGS)# Reachable build-only entry point for the harness above: `make check` never# calls this (it stays out of TEST_BINS/test-c, per TEST_EXCLUDE), so this addsdiff --git a/c/tests/test_makefile_vk_obj.py b/c/tests/test_makefile_vk_obj.pynew file mode 100644index 00000000..2891a7be--- /dev/null+++ b/c/tests/test_makefile_vk_obj.py@@ -0,0 +1,205 @@+"""A rule that compiles a Vulkan-hooked engine must link $(VK_OBJ).++Under VK=1, CFLAGS carries -DCOLI_VULKAN. A translation unit that includes an+engine with `#ifdef COLI_VULKAN` hooks (colibri.c, kimi_k3.c, ...) then calls+coli_vk_*, and the link fails unless the rule also links $(VK_OBJ). That+variable is empty unless VK=1, so the default build and every default CI job+stay green while `make test-c VK=1` is broken. #1728 fixed the 43 rules that+`make -k test-c VK=1` reported. Four more gates (test_xdna_qt_state,+test_xdna_failure, test_logprob_status, test_ablate_mode) arrived in pull+requests merged after it, and nine on-demand rules outside TEST_BINS -- the+benches, the XDNA physical probe, the e8x4g64 loader harness -- were never+built by test-c, so no such run could report them.++Nothing here is a hand-kept list. The hooked sources are the files with a+preprocessor conditional on COLI_VULKAN. A link recipe needs $(VK_OBJ) when a+.c file it compiles reaches one of them through quoted #includes, and the rule+must list $(VK_OBJ) as a prerequisite too: otherwise a clean build can reach+the link before backend_vulkan.o exists (#1728 found six rules like that). Flag+variables whose definition filters -DCOLI_VULKAN out, such as+SEGMENT_CPU_CFLAGS, are recognised from that definition, and `-c` compiles+are not links.+"""+import re+import unittest+from pathlib import Path++C_DIR = Path(__file__).resolve().parent.parent++VK_HOOK_RE = re.compile(+ r"(?m)^[ \t]*#[ \t]*(?:if|ifdef|ifndef|elif)\b.*\bCOLI_VULKAN\b")+INCLUDE_RE = re.compile(r'(?m)^[ \t]*#[ \t]*include[ \t]*"([^"]+)"')+ASSIGN_RE = re.compile(+ r"^(?:override[ \t]+)?([A-Za-z0-9_]+)[ \t]*(?:\+|\?|!|::?)?=[ \t]*(.*)$")+RULE_RE = re.compile(r"^([^\t#][^=]*?)[ \t]*:(?![=:])[ \t]*(.*)$")+VAR_RE = re.compile(r"\$\(([A-Za-z0-9_]+)\)")+# Lines that are not rules even when they contain a colon, e.g.+# `$(warning mixed HIP_ARCH list: ...)`. A rule may still START with `$(`:+# `$(SEGMENT_BUILD_DIR)/glm.o: colibri.c ...`.+DIRECTIVE_RE = re.compile(+ r"^(?:ifeq|ifneq|ifdef|ifndef|else|endif|(?:-|s)?include|export"+ r"|unexport|vpath)\b|^\$\((?:error|warning|info|file|shell|eval|call)\b")+++def _parse_makefile():+ """(rules, variables) from c/Makefile, continuations folded.++ rules: [(targets, prerequisites, recipe_lines)], prerequisites being the+ normal ones only (an order-only $(VK_OBJ) would not relink on change).+ variables: name -> every value it is assigned anywhere; the union is+ enough to find .c files and COLI_VULKAN filters, whatever the platform.+ """+ text = (C_DIR / "Makefile").read_text(encoding="utf-8")+ text = re.sub(r"\\\n[ \t]*", " ", text)+ rules, variables, current, in_define = [], {}, None, False+ for line in text.splitlines():+ if in_define:+ in_define = not line.startswith("endef")+ continue+ if line.startswith("define "):+ in_define, current = True, None+ continue+ if line.startswith("\t"):+ if current is not None:+ current[2].append(line.strip())+ continue+ stripped = line.split("#", 1)[0].strip()+ if not stripped:+ continue+ assign = ASSIGN_RE.match(stripped)+ if assign:+ variables.setdefault(assign.group(1), []).append(assign.group(2))+ current = None+ continue+ if DIRECTIVE_RE.match(stripped):+ continue+ rule = RULE_RE.match(stripped)+ if rule:+ prereqs = rule.group(2).split(";", 1)[0].split("|", 1)[0].split()+ current = (rule.group(1).split(), prereqs, [])+ rules.append(current)+ return rules, variables+++def _expand_words(word, variables, depth=0):+ """Every word a $(VAR) can stand for, across all its definitions."""+ match = VAR_RE.fullmatch(word)+ if not match or depth > 8:+ return [word]+ words = []+ for value in variables.get(match.group(1), []):+ for part in value.split():+ words.extend(_expand_words(part, variables, depth + 1))+ return words+++def _vk_stripping_vars(variables):+ return {name for name, values in variables.items()+ if any("filter-out" in v and "-DCOLI_VULKAN" in v for v in values)}+++class _IncludeGraph:+ """Quoted-#include reachability, reading each file once."""++ def __init__(self):+ self._files = {}++ def _scan(self, path):+ if path not in self._files:+ text = path.read_text(encoding="utf-8", errors="replace")+ includes = []+ for name in INCLUDE_RE.findall(text):+ for base in (path.parent, C_DIR):+ candidate = (base / name).resolve()+ if candidate.is_file():+ includes.append(candidate)+ break+ self._files[path] = (bool(VK_HOOK_RE.search(text)), includes)+ return self._files[path]++ def reaches_vk_hook(self, source):+ """True when `source` or anything it quote-includes has a hook."""+ seen, stack = set(), [source.resolve()]+ while stack:+ path = stack.pop()+ if path in seen or not path.is_file():+ continue+ seen.add(path)+ hooked, includes = self._scan(path)+ if hooked:+ return True+ stack.extend(includes)+ return False+++def _rules_needing_vk_obj():+ """[(target, has_prerequisite, has_link_argument)] for every rule whose+ link recipe compiles a translation unit that reaches a COLI_VULKAN hook."""+ rules, variables = _parse_makefile()+ stripping = _vk_stripping_vars(variables)+ graph = _IncludeGraph()+ found = []+ for targets, prereqs, recipe in rules:+ for line in recipe:+ words = line.split()+ if "$(CC)" not in words or "-c" in words or "-UCOLI_VULKAN" in words:+ continue+ if stripping & {m.group(1) for m in map(VAR_RE.fullmatch, words) if m}:+ continue+ sources = []+ for word in words:+ if word == "$<":+ sources.extend(prereqs[:1])+ elif word == "$^":+ sources.extend(prereqs)+ else:+ sources.extend(_expand_words(word, variables))+ if any(s.endswith(".c") and graph.reaches_vk_hook(C_DIR / s)+ for s in sources):+ found.append((" ".join(targets), "$(VK_OBJ)" in prereqs,+ "$(VK_OBJ)" in words or "$^" in words))+ return found+++class MakefileVkObjTest(unittest.TestCase):+ def test_the_scan_is_derived_and_not_vacuous(self):+ """A parse that matches nothing would pass the check below silently.++ Cross-check against the engines themselves: every NAME.c carrying a+ COLI_VULKAN hook that has a `NAME$(EXE):` rule must be found by the+ same scan, since that rule compiles it directly.+ """+ hooked = sorted(p.stem for p in C_DIR.glob("*.c")+ if VK_HOOK_RE.search(p.read_text(encoding="utf-8",+ errors="replace")))+ self.assertTrue(hooked, "no .c file under c/ has a COLI_VULKAN "+ "conditional -- the hook syntax changed and "+ "this file now checks nothing")+ rules, _ = _parse_makefile()+ engine_rules = {name for name in hooked+ if any(f"{name}$(EXE)" in t for t, _, _ in rules)}+ self.assertTrue(engine_rules, f"no `NAME$(EXE):` rule for {hooked}")+ found = {target for target, _, _ in _rules_needing_vk_obj()}+ for name in sorted(engine_rules):+ self.assertIn(f"{name}$(EXE)", found,+ f"the scan missed {name}$(EXE), which compiles "+ f"{name}.c itself -- the recipe parse is broken")+ self.assertTrue(any(t.startswith("tests/") for t in found),+ "the scan found no test rule including an engine")++ def test_every_rule_compiling_a_hooked_engine_links_vk_obj(self):+ missing = []+ for target, has_prereq, has_link in _rules_needing_vk_obj():+ if not has_prereq:+ missing.append(f"{target}: $(VK_OBJ) not a prerequisite")+ if not has_link:+ missing.append(f"{target}: $(VK_OBJ) not on the link line")+ self.assertFalse(+ missing,+ "these rules compile a source with COLI_VULKAN hooks, so under "+ "VK=1 they reference coli_vk_* and must link backend_vulkan.o:\n "+ + "\n ".join(missing))+++if __name__ == "__main__":+ unittest.main()