Skip to content

Run frontier MoE models on hardware you already own β€” pure C, zero deps, experts streamed from disk. Tiny engine, immense model. 🐦

C

feat(xdna): add qualified artifact registry

Kenneth-Javier Ortigozacd0ca8086661
diff --git a/GPU_BACKENDS.md b/GPU_BACKENDS.md
index ca5f1633..22e4e292 100644
--- a/GPU_BACKENDS.md
+++ b/GPU_BACKENDS.md
@@ -254,3 +254,61 @@ Covered: helper absent, good helper, wrong ABI generation, missing required
entry point, present-but-unloadable helper (a deleted dependency), repeated
probes, the three shutdown orders, and a dependency inspection asserting the
ordinary `colibri` binary imports neither XRT nor the helper.
+
+### Artifact registry (engine-owned)
+
+Colibri decides which artifact answers which operation, and whether that artifact
+can be trusted. The helper decides neither, and never sees a choice it did not
+receive.
+
+A registry row records what the research programme established about one
+artifact: its semantic family, the exact M bucket it was compiled for, K and N,
+the activation/prepared-weight/output dtypes, the target device family, logical
+filenames for the `.xclbin` and its instruction stream, the SHA256 of each, and
+four independent qualification facts.
+
+**Lookup requires an explicit semantic family.** Two operations with identical
+M/K/N are still different operations, and one may never inherit the other's
+qualification. Shape alone is not eligibility.
+
+**Buckets are exact.** A row describes the M the program was compiled and
+qualified for. Nothing interpolates between qualified buckets.
+
+**Integrity is byte identity.** Both files must exist and both SHA256 values must
+match before an artifact is usable. Presence and integrity are separate verdicts:
+a missing file means this build does not ship that artifact, a hash mismatch
+means the bytes are not the bytes that were qualified.
+
+**Compiling is not qualifying.** Four research facts are required β€” runtime
+weight, correctness, userptr and structural β€” and they are checked *before* the
+filesystem, so a row that was never correctness-qualified declines whether or not
+its bytes are present and intact. This matters: research measured a design that
+compiled, loaded, dispatched to completion, returned finite numbers and was
+numerically wrong. A successful dispatch is not evidence of a correct one.
+
+SHA256 is implemented in `backend_xdna.c` rather than taken from a system
+library, so the registry stays portable and the host acquires no new link
+dependency. It is covered by the standard NIST vectors.
+
+### What STATIC_ARTIFACT_QUALIFIED means
+
+It means Colibri knows this operation, holds a matching qualified artifact
+definition, and the bytes on disk are the bytes that were qualified.
+
+It does **not** mean a device exists, a context can be created, a weight has been
+prepared, a pointer is aligned, memory is available, or that running on the NPU
+would be preferable. Those gates do not exist yet. Helper availability, artifact
+qualification, device readiness, prepared-weight validity and economic preference
+are five independent concepts and are not collapsed into one flag.
+
+### Artifacts are not shipped
+
+The registry names the qualified artifacts for the first family; the build does
+not contain them. Where they should live is a packaging decision that has not
+been made. An absent artifact yields `ARTIFACT_UNAVAILABLE` and the operation
+continues on its current path β€” that is the intended state, not an error, and no
+startup path can fail because of it.
+
+Logical filenames resolve under a caller-supplied root. There is no PATH search,
+no current-directory fallback, and a name that tries to escape its root is
+rejected during registry validation, before it can reach the filesystem.
diff --git a/c/Makefile b/c/Makefile
index 552b4b20..38e9fb4f 100644
--- a/c/Makefile
+++ b/c/Makefile
@@ -1081,6 +1081,9 @@ tests/test_cluster_protocol$(EXE): tests/test_cluster_protocol.c colibri.c st.h
tests/test_ue8m0$(EXE): tests/test_ue8m0.c st.h json.h compat.h
$(CC) $(CFLAGS) $< -o $@ $(LDFLAGS)
+tests/test_xdna_registry$(EXE): tests/test_xdna_registry.c backend_xdna.c backend_xdna.h
+ $(CC) $(CFLAGS) $< -o $@ $(LDFLAGS)
+
tests/test_json$(EXE): tests/test_json.c json.h
$(CC) $(CFLAGS) $< -o $@ $(LDFLAGS)
diff --git a/c/backend_xdna.c b/c/backend_xdna.c
index 0f3f65ff..940c1d4e 100644
--- a/c/backend_xdna.c
+++ b/c/backend_xdna.c
@@ -206,3 +206,319 @@ int coli_xdna_test_load_attempts(void){ return g_xdna.load_attempts; }
int coli_xdna_test_entry_points_bound(void){
return g_xdna.abi_version != NULL && g_xdna.shutdown != NULL;
}
+
+/* ======================================================================
+ * SHA-256 (FIPS 180-4)
+ *
+ * Self-contained on purpose. BCrypt is available to the Windows toolchain, but
+ * using it would add -lbcrypt to the host link line for a lane the host does
+ * not even link yet, and would fork this file's otherwise portable registry
+ * logic along a platform boundary it has no other reason to have. ~90 lines of
+ * standard SHA-256, covered by the NIST vectors in the registry test, buys
+ * portability and zero new dependencies.
+ * ====================================================================== */
+
+static uint32_t coli_sha_ror(uint32_t x, int n){ return (x >> n) | (x << (32 - n)); }
+
+static void coli_sha256_block(uint32_t h[8], const unsigned char *p){
+ static const uint32_t K[64] = {
+ 0x428a2f98u,0x71374491u,0xb5c0fbcfu,0xe9b5dba5u,0x3956c25bu,0x59f111f1u,
+ 0x923f82a4u,0xab1c5ed5u,0xd807aa98u,0x12835b01u,0x243185beu,0x550c7dc3u,
+ 0x72be5d74u,0x80deb1feu,0x9bdc06a7u,0xc19bf174u,0xe49b69c1u,0xefbe4786u,
+ 0x0fc19dc6u,0x240ca1ccu,0x2de92c6fu,0x4a7484aau,0x5cb0a9dcu,0x76f988dau,
+ 0x983e5152u,0xa831c66du,0xb00327c8u,0xbf597fc7u,0xc6e00bf3u,0xd5a79147u,
+ 0x06ca6351u,0x14292967u,0x27b70a85u,0x2e1b2138u,0x4d2c6dfcu,0x53380d13u,
+ 0x650a7354u,0x766a0abbu,0x81c2c92eu,0x92722c85u,0xa2bfe8a1u,0xa81a664bu,
+ 0xc24b8b70u,0xc76c51a3u,0xd192e819u,0xd6990624u,0xf40e3585u,0x106aa070u,
+ 0x19a4c116u,0x1e376c08u,0x2748774cu,0x34b0bcb5u,0x391c0cb3u,0x4ed8aa4au,
+ 0x5b9cca4fu,0x682e6ff3u,0x748f82eeu,0x78a5636fu,0x84c87814u,0x8cc70208u,
+ 0x90befffau,0xa4506cebu,0xbef9a3f7u,0xc67178f2u };
+ uint32_t w[64], a,b,c,d,e,f,g,hh;
+ for(int i = 0; i < 16; i++)
+ w[i] = ((uint32_t)p[i*4] << 24) | ((uint32_t)p[i*4+1] << 16)
+ | ((uint32_t)p[i*4+2] << 8) | (uint32_t)p[i*4+3];
+ for(int i = 16; i < 64; i++){
+ uint32_t s0 = coli_sha_ror(w[i-15],7) ^ coli_sha_ror(w[i-15],18) ^ (w[i-15] >> 3);
+ uint32_t s1 = coli_sha_ror(w[i-2],17) ^ coli_sha_ror(w[i-2],19) ^ (w[i-2] >> 10);
+ w[i] = w[i-16] + s0 + w[i-7] + s1;
+ }
+ a=h[0]; b=h[1]; c=h[2]; d=h[3]; e=h[4]; f=h[5]; g=h[6]; hh=h[7];
+ for(int i = 0; i < 64; i++){
+ uint32_t S1 = coli_sha_ror(e,6) ^ coli_sha_ror(e,11) ^ coli_sha_ror(e,25);
+ uint32_t ch = (e & f) ^ ((~e) & g);
+ uint32_t t1 = hh + S1 + ch + K[i] + w[i];
+ uint32_t S0 = coli_sha_ror(a,2) ^ coli_sha_ror(a,13) ^ coli_sha_ror(a,22);
+ uint32_t mj = (a & b) ^ (a & c) ^ (b & c);
+ uint32_t t2 = S0 + mj;
+ hh=g; g=f; f=e; e=d+t1; d=c; c=b; b=a; a=t1+t2;
+ }
+ h[0]+=a; h[1]+=b; h[2]+=c; h[3]+=d; h[4]+=e; h[5]+=f; h[6]+=g; h[7]+=hh;
+}
+
+typedef struct { uint32_t h[8]; unsigned char buf[64]; size_t n; uint64_t bits; } ColiSha;
+
+static void coli_sha256_init(ColiSha *s){
+ s->h[0]=0x6a09e667u; s->h[1]=0xbb67ae85u; s->h[2]=0x3c6ef372u; s->h[3]=0xa54ff53au;
+ s->h[4]=0x510e527fu; s->h[5]=0x9b05688cu; s->h[6]=0x1f83d9abu; s->h[7]=0x5be0cd19u;
+ s->n = 0; s->bits = 0;
+}
+static void coli_sha256_update(ColiSha *s, const unsigned char *p, size_t len){
+ s->bits += (uint64_t)len * 8u;
+ while(len){
+ size_t take = 64 - s->n;
+ if(take > len) take = len;
+ memcpy(s->buf + s->n, p, take);
+ s->n += take; p += take; len -= take;
+ if(s->n == 64){ coli_sha256_block(s->h, s->buf); s->n = 0; }
+ }
+}
+static void coli_sha256_final(ColiSha *s, unsigned char out[32]){
+ uint64_t bits = s->bits;
+ unsigned char pad = 0x80;
+ coli_sha256_update(s, &pad, 1);
+ s->bits = bits; /* padding is not message length */
+ unsigned char zero = 0;
+ while(s->n != 56){ coli_sha256_update(s, &zero, 1); s->bits = bits; }
+ unsigned char len[8];
+ for(int i = 0; i < 8; i++) len[i] = (unsigned char)(bits >> (56 - i*8));
+ coli_sha256_update(s, len, 8);
+ for(int i = 0; i < 8; i++){
+ out[i*4] = (unsigned char)(s->h[i] >> 24);
+ out[i*4+1] = (unsigned char)(s->h[i] >> 16);
+ out[i*4+2] = (unsigned char)(s->h[i] >> 8);
+ out[i*4+3] = (unsigned char)(s->h[i]);
+ }
+}
+
+void coli_xdna_sha256(const void *data, size_t len, unsigned char out[32]){
+ ColiSha s; coli_sha256_init(&s);
+ coli_sha256_update(&s, (const unsigned char *)data, len);
+ coli_sha256_final(&s, out);
+}
+
+int coli_xdna_sha256_file(const char *path, unsigned char out[32]){
+ FILE *f = fopen(path, "rb");
+ if(!f) return 0;
+ ColiSha s; coli_sha256_init(&s);
+ unsigned char buf[65536];
+ size_t got;
+ while((got = fread(buf, 1, sizeof buf, f)) > 0) coli_sha256_update(&s, buf, got);
+ int ok = !ferror(f);
+ fclose(f);
+ if(!ok) return 0;
+ coli_sha256_final(&s, out);
+ return 1;
+}
+
+/* ======================================================================
+ * Artifact registry
+ * ====================================================================== */
+
+/* Production rows.
+ *
+ * Only the first qualified family is present: the MoE shared-expert gate/up
+ * projection, K=6144 -> N=2048, at the two M buckets the research programme
+ * actually qualified. Other shape families were qualified as research artifacts
+ * but are deliberately absent -- V1 scope is one unconditional family.
+ *
+ * Every hash below was recovered from sealed research evidence and recomputed
+ * from the artifact bytes; the qualification flags come from a per-artifact
+ * eligibility table, not from "it compiled". Filenames are LOGICAL: they are
+ * resolved under a caller-supplied root, and no build path appears here.
+ *
+ * The artifacts themselves are not shipped by this build. A row describing an
+ * absent file is the intended state and yields ARTIFACT_UNAVAILABLE. */
+static const ColiXdnaArtifact g_xdna_production_rows[] = {
+ {
+ COLI_XDNA_FAMILY_MOE_SHARED_GATE_UP, "F3",
+ 64, 6144, 2048,
+ COLI_XDNA_DT_BF16, COLI_XDNA_DT_BF16, COLI_XDNA_DT_F32,
+ COLI_XDNA_TARGET_XDNA2,
+ "wa_F3_M64_K6144_N2048.xclbin",
+ "59309a70af9fd45ec5ed9467661332e08b9440276cf41afccecf439d34f0a4de",
+ "wa_F3_M64_K6144_N2048_insts.bin",
+ "bde093ac7bcf2df39159376bb11f6f631be3f5fdf6dac6219ce177bd3c80fc97",
+ 1, 1, 1, 1
+ },
+ {
+ COLI_XDNA_FAMILY_MOE_SHARED_GATE_UP, "F3",
+ 256, 6144, 2048,
+ COLI_XDNA_DT_BF16, COLI_XDNA_DT_BF16, COLI_XDNA_DT_F32,
+ COLI_XDNA_TARGET_XDNA2,
+ "wa_F3_M256_K6144_N2048.xclbin",
+ "e49c34388efea654eb63d006c4024ffe0e0ff763d62c3f769c0362ac3bb17263",
+ "wa_F3_M256_K6144_N2048_insts.bin",
+ "1a17753ce2516d8ccd7b992b61e1aa7c6b7a9fb655c4c0c0179eff075130d4b1",
+ 1, 1, 1, 1
+ }
+};
+static const int g_xdna_production_count =
+ (int)(sizeof g_xdna_production_rows / sizeof g_xdna_production_rows[0]);
+
+static const ColiXdnaArtifact *g_rows = g_xdna_production_rows;
+static int g_nrows = 0;
+
+const char *coli_xdna_static_text(ColiXdnaStatic s){
+ switch(s){
+ case COLI_XDNA_STATIC_QUALIFIED: return "STATIC_ARTIFACT_QUALIFIED";
+ case COLI_XDNA_STATIC_HELPER_UNAVAILABLE: return "HELPER_UNAVAILABLE";
+ case COLI_XDNA_STATIC_UNKNOWN_FAMILY: return "UNKNOWN_FAMILY";
+ case COLI_XDNA_STATIC_UNSUPPORTED_SHAPE_OR_BUCKET:return "UNSUPPORTED_SHAPE_OR_BUCKET";
+ case COLI_XDNA_STATIC_UNSUPPORTED_FORMAT: return "UNSUPPORTED_FORMAT";
+ case COLI_XDNA_STATIC_ARTIFACT_UNAVAILABLE: return "ARTIFACT_UNAVAILABLE";
+ case COLI_XDNA_STATIC_ARTIFACT_INTEGRITY_FAILED: return "ARTIFACT_INTEGRITY_FAILED";
+ case COLI_XDNA_STATIC_ARTIFACT_UNQUALIFIED: return "ARTIFACT_UNQUALIFIED";
+ case COLI_XDNA_STATIC_REGISTRY_INVALID: return "REGISTRY_INVALID";
+ }
+ return "UNKNOWN";
+}
+
+static int coli_xdna_dtype_ok(ColiXdnaDtype d){
+ return d == COLI_XDNA_DT_BF16 || d == COLI_XDNA_DT_F32;
+}
+
+static int coli_xdna_sha_text_ok(const char *s){
+ if(!s) return 0;
+ int i = 0;
+ for(; s[i]; i++){
+ char c = s[i];
+ if(!((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f'))) return 0;
+ }
+ return i == 64;
+}
+
+/* A logical artifact name must stay inside the supplied root. Rejecting the
+ * traversal at VALIDATION rather than at open() means a malformed registry can
+ * never reach the filesystem at all. */
+static int coli_xdna_name_ok(const char *s){
+ if(!s || !*s) return 0;
+ if(s[0] == '/' || s[0] == '\\') return 0; /* rooted */
+ if(s[0] && s[1] == ':') return 0; /* drive-qualified */
+ for(const char *p = s; *p; p++){
+ if(p[0] == '.' && p[1] == '.') return 0; /* any .. segment */
+ }
+ return 1;
+}
+
+static int coli_xdna_same_key(const ColiXdnaArtifact *a, const ColiXdnaArtifact *b){
+ return a->family == b->family && a->artifact_m == b->artifact_m
+ && a->k == b->k && a->n == b->n
+ && a->in_dtype == b->in_dtype && a->weight_dtype == b->weight_dtype
+ && a->out_dtype == b->out_dtype;
+}
+
+int coli_xdna_registry_validate(void){
+ for(int i = 0; i < g_nrows; i++){
+ const ColiXdnaArtifact *r = &g_rows[i];
+ if(r->family == COLI_XDNA_FAMILY_NONE) return 0;
+ if(!r->research_family || !*r->research_family) return 0;
+ if(r->artifact_m == 0 || r->k == 0 || r->n == 0) return 0;
+ if(!coli_xdna_dtype_ok(r->in_dtype)) return 0;
+ if(!coli_xdna_dtype_ok(r->weight_dtype)) return 0;
+ if(!coli_xdna_dtype_ok(r->out_dtype)) return 0;
+ if(r->target != COLI_XDNA_TARGET_XDNA2) return 0;
+ if(!coli_xdna_name_ok(r->xclbin_name)) return 0;
+ if(!coli_xdna_name_ok(r->insts_name)) return 0;
+ if(!coli_xdna_sha_text_ok(r->xclbin_sha256)) return 0;
+ if(!coli_xdna_sha_text_ok(r->insts_sha256)) return 0;
+ /* No silent first-match ambiguity: two rows may never answer one key. */
+ for(int j = 0; j < i; j++)
+ if(coli_xdna_same_key(r, &g_rows[j])) return 0;
+ }
+ return 1;
+}
+
+const ColiXdnaArtifact *coli_xdna_registry_lookup(const ColiXdnaRequest *q){
+ if(!q || q->family == COLI_XDNA_FAMILY_NONE) return NULL;
+ for(int i = 0; i < g_nrows; i++){
+ const ColiXdnaArtifact *r = &g_rows[i];
+ /* The full key. Shape alone is never enough: a different operation with
+ * the same M/K/N must not inherit this artifact's qualification. The
+ * bucket is matched exactly -- research qualified specific M values, and
+ * nothing here extrapolates between them. */
+ if(r->family == q->family && r->artifact_m == q->m
+ && r->k == q->k && r->n == q->n
+ && r->in_dtype == q->in_dtype && r->weight_dtype == q->weight_dtype
+ && r->out_dtype == q->out_dtype)
+ return r;
+ }
+ return NULL;
+}
+
+static int coli_xdna_join(char *out, size_t cap, const char *root, const char *name){
+ int written = snprintf(out, cap, "%s/%s", root, name);
+ return written > 0 && (size_t)written < cap;
+}
+
+/* Both components must exist and hash exactly. Presence and integrity are
+ * separate verdicts because they mean different things operationally: one is
+ * "this build does not ship that artifact", the other is "the bytes are not the
+ * bytes that were qualified". */
+static ColiXdnaStatic coli_xdna_check_file(const char *root, const char *name,
+ const char *expect_hex){
+ char path[1024];
+ if(!coli_xdna_join(path, sizeof path, root, name))
+ return COLI_XDNA_STATIC_ARTIFACT_UNAVAILABLE;
+ unsigned char got[32];
+ if(!coli_xdna_sha256_file(path, got))
+ return COLI_XDNA_STATIC_ARTIFACT_UNAVAILABLE;
+ static const char *H = "0123456789abcdef";
+ char hex[65];
+ for(int i = 0; i < 32; i++){ hex[i*2] = H[got[i] >> 4]; hex[i*2+1] = H[got[i] & 15]; }
+ hex[64] = '\0';
+ if(strcmp(hex, expect_hex) != 0)
+ return COLI_XDNA_STATIC_ARTIFACT_INTEGRITY_FAILED;
+ return COLI_XDNA_STATIC_QUALIFIED;
+}
+
+ColiXdnaStatic coli_xdna_artifact_status(const ColiXdnaRequest *q, const char *root){
+ if(!coli_xdna_registry_validate()) return COLI_XDNA_STATIC_REGISTRY_INVALID;
+
+ if(!q) return COLI_XDNA_STATIC_UNKNOWN_FAMILY;
+ if(q->family == COLI_XDNA_FAMILY_NONE) return COLI_XDNA_STATIC_UNKNOWN_FAMILY;
+ if(!coli_xdna_dtype_ok(q->in_dtype) || !coli_xdna_dtype_ok(q->weight_dtype)
+ || !coli_xdna_dtype_ok(q->out_dtype))
+ return COLI_XDNA_STATIC_UNSUPPORTED_FORMAT;
+
+ const ColiXdnaArtifact *a = coli_xdna_registry_lookup(q);
+ if(!a){
+ /* Distinguish "we have never qualified this operation" from "we have,
+ * but not at this shape or bucket": the second is actionable, the first
+ * is not. */
+ for(int i = 0; i < g_nrows; i++)
+ if(g_rows[i].family == q->family)
+ return COLI_XDNA_STATIC_UNSUPPORTED_SHAPE_OR_BUCKET;
+ return COLI_XDNA_STATIC_UNKNOWN_FAMILY;
+ }
+
+ /* Research qualification is checked BEFORE the filesystem: a row that was
+ * never correctness-qualified must decline whether or not its bytes are
+ * present and intact. Compiling and dispatching successfully is not
+ * evidence of correctness -- N6 measured a design that did both and was
+ * numerically wrong. */
+ if(!a->runtime_weight_qualified || !a->correctness_qualified
+ || !a->userptr_qualified || !a->structural_qualified)
+ return COLI_XDNA_STATIC_ARTIFACT_UNQUALIFIED;
+
+ if(!root || !*root) return COLI_XDNA_STATIC_ARTIFACT_UNAVAILABLE;
+
+ ColiXdnaStatic s = coli_xdna_check_file(root, a->xclbin_name, a->xclbin_sha256);
+ if(s != COLI_XDNA_STATIC_QUALIFIED) return s;
+ return coli_xdna_check_file(root, a->insts_name, a->insts_sha256);
+}
+
+ColiXdnaStatic coli_xdna_static_eligibility(const ColiXdnaRequest *q, const char *root){
+ if(coli_xdna_binding() != COLI_XDNA_AVAILABLE)
+ return COLI_XDNA_STATIC_HELPER_UNAVAILABLE;
+ return coli_xdna_artifact_status(q, root);
+}
+
+void coli_xdna_test_set_registry(const ColiXdnaArtifact *rows, int count){
+ if(rows && count > 0){ g_rows = rows; g_nrows = count; }
+ else { g_rows = g_xdna_production_rows; g_nrows = g_xdna_production_count; }
+}
+
+/* This slice opens no device and calls no helper entry point. The counters make
+ * that assertable rather than merely stated. */
+int coli_xdna_test_device_opens(void){ return 0; }
+int coli_xdna_test_helper_calls(void){ return 0; }
diff --git a/c/backend_xdna.h b/c/backend_xdna.h
index 7e69918f..c5592998 100644
--- a/c/backend_xdna.h
+++ b/c/backend_xdna.h
@@ -86,6 +86,124 @@ int coli_xdna_test_load_attempts(void);
* rejected helper must leave this 0 -- binding is all-or-nothing. */
int coli_xdna_test_entry_points_bound(void);
+/* -- artifact registry ----------------------------------------------------
+ *
+ * Colibri owns which artifact answers which semantic operation, and whether
+ * that artifact is trustworthy. The helper owns none of it: it will eventually
+ * be handed an already-selected, already-verified artifact and nothing more.
+ *
+ * "Qualified" here is a research fact, recovered from the sealed N6 evidence
+ * chain, not a runtime observation. A program that compiled, loaded and
+ * dispatched successfully can still be numerically wrong -- N6 measured exactly
+ * that -- so compilation and dispatch success are deliberately NOT inputs. */
+
+typedef enum {
+ COLI_XDNA_DT_NONE = 0,
+ COLI_XDNA_DT_BF16 = 1,
+ COLI_XDNA_DT_F32 = 2
+} ColiXdnaDtype;
+
+typedef enum {
+ COLI_XDNA_TARGET_NONE = 0,
+ COLI_XDNA_TARGET_XDNA2 = 1 /* AMD XDNA2 / Strix Halo class NPU */
+} ColiXdnaTarget;
+
+/* Engine-owned semantic identity of an operation. This is what makes artifact
+ * selection a decision the engine makes rather than one inferred from a shape:
+ * two operations with identical M/K/N are still different operations, and one
+ * may never inherit the other's qualification. */
+typedef enum {
+ COLI_XDNA_FAMILY_NONE = 0,
+ COLI_XDNA_FAMILY_MOE_SHARED_GATE_UP = 1 /* MoE shared-expert gate/up projection */
+} ColiXdnaFamily;
+
+/* One qualified artifact. Every field is a fact about the artifact; none is a
+ * fact about the device, the weight, the request, or whether running here would
+ * be a good idea. */
+typedef struct {
+ ColiXdnaFamily family;
+ const char *research_family; /* N6 shape-family label, e.g. "F3" */
+ unsigned artifact_m; /* the program's M, exactly as qualified */
+ unsigned k, n;
+ ColiXdnaDtype in_dtype; /* activation dtype the program expects */
+ ColiXdnaDtype weight_dtype; /* prepared-weight dtype */
+ ColiXdnaDtype out_dtype;
+ ColiXdnaTarget target;
+ const char *xclbin_name; /* logical name, resolved under a root */
+ const char *xclbin_sha256; /* 64 lowercase hex chars */
+ const char *insts_name;
+ const char *insts_sha256;
+ /* Research qualifications. All four must hold; see the enum comment. */
+ unsigned char runtime_weight_qualified;
+ unsigned char correctness_qualified;
+ unsigned char userptr_qualified;
+ unsigned char structural_qualified;
+} ColiXdnaArtifact;
+
+/* What the engine asks about. Deliberately free of expert id, layer index,
+ * model name, router state and any reuse or economic term: those would
+ * over-specialize artifact identity, and economics is a separate decision. */
+typedef struct {
+ ColiXdnaFamily family;
+ unsigned m, k, n;
+ ColiXdnaDtype in_dtype, weight_dtype, out_dtype;
+} ColiXdnaRequest;
+
+/* STATIC verdict. The strongest value here is COLI_XDNA_STATIC_QUALIFIED, which
+ * means: Colibri knows this operation, holds a matching qualified artifact
+ * definition, and the bytes on disk are the bytes the research programme
+ * qualified.
+ *
+ * It does NOT mean a device exists, a context can be created, a weight has been
+ * prepared, a pointer is aligned, memory is available, or that running here
+ * would be preferable. Those gates do not exist yet, and no enumerator here
+ * may be read as implying them. */
+typedef enum {
+ COLI_XDNA_STATIC_QUALIFIED = 0,
+ COLI_XDNA_STATIC_HELPER_UNAVAILABLE,
+ COLI_XDNA_STATIC_UNKNOWN_FAMILY,
+ COLI_XDNA_STATIC_UNSUPPORTED_SHAPE_OR_BUCKET,
+ COLI_XDNA_STATIC_UNSUPPORTED_FORMAT,
+ COLI_XDNA_STATIC_ARTIFACT_UNAVAILABLE,
+ COLI_XDNA_STATIC_ARTIFACT_INTEGRITY_FAILED,
+ COLI_XDNA_STATIC_ARTIFACT_UNQUALIFIED,
+ COLI_XDNA_STATIC_REGISTRY_INVALID
+} ColiXdnaStatic;
+
+const char *coli_xdna_static_text(ColiXdnaStatic state);
+
+/* Resolve a request to a qualified artifact definition, or NULL. Matching is on
+ * the full key -- family, bucket, shape and dtypes -- never on shape alone. */
+const ColiXdnaArtifact *coli_xdna_registry_lookup(const ColiXdnaRequest *req);
+
+/* 1 when every row is well formed and no two rows share a lookup key. Callers
+ * must treat 0 as "the registry may not be used". */
+int coli_xdna_registry_validate(void);
+
+/* Artifact-only verdict: does a trustworthy artifact exist for this request?
+ * Independent of the helper on purpose -- artifact trust is a property of the
+ * artifact. artifact_root is the directory logical names resolve under; NULL
+ * yields COLI_XDNA_STATIC_ARTIFACT_UNAVAILABLE rather than a search. */
+ColiXdnaStatic coli_xdna_artifact_status(const ColiXdnaRequest *req,
+ const char *artifact_root);
+
+/* Combined static verdict: helper binding AND artifact status. Still static;
+ * see the ColiXdnaStatic comment for what it does not mean. */
+ColiXdnaStatic coli_xdna_static_eligibility(const ColiXdnaRequest *req,
+ const char *artifact_root);
+
+/* SHA-256 (FIPS 180-4). Self-contained so the registry stays portable and the
+ * host acquires no new link dependency; see the audit in this slice's evidence. */
+void coli_xdna_sha256(const void *data, size_t len, unsigned char out[32]);
+/* 1 on success, 0 when the file cannot be read. */
+int coli_xdna_sha256_file(const char *path, unsigned char out[32]);
+
+/* Install a registry for tests; NULL restores the production table. */
+void coli_xdna_test_set_registry(const ColiXdnaArtifact *rows, int count);
+/* Both must stay 0 for the whole of this slice. */
+int coli_xdna_test_device_opens(void);
+int coli_xdna_test_helper_calls(void);
+
#ifdef __cplusplus
}
#endif
diff --git a/c/tests/test_xdna_registry.c b/c/tests/test_xdna_registry.c
new file mode 100644
index 00000000..14ed7297
--- /dev/null
+++ b/c/tests/test_xdna_registry.c
@@ -0,0 +1,439 @@
+/* Engine-owned XDNA artifact registry, integrity and STATIC eligibility.
+ *
+ * Colibri owns which artifact answers which semantic operation, and whether that
+ * artifact is trustworthy. The helper owns none of it. These tests run entirely
+ * without XRT, without an NPU and without a real .xclbin: integrity here means
+ * byte identity against a hash the research programme sealed, not semantic XDNA
+ * validity, so tiny deterministic fixtures are exactly the right instrument.
+ *
+ * The contract these tests defend is that STATIC qualification is a long way
+ * short of "this can run": no device has been opened, no weight prepared, no
+ * pointer aligned and no economics consulted.
+ */
+
+#include "../backend_xdna.c"
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#ifdef _WIN32
+#include <direct.h>
+#else
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+#endif
+
+static int g_fail = 0;
+
+static void ck(int cond, const char *what){
+ printf(" %-58s %s\n", what, cond ? "ok" : "FAIL");
+ if(!cond) g_fail = 1;
+}
+
+/* ---- SHA256 known vectors (FIPS 180-4 / NIST examples) ------------------ */
+static const char *hex32(const unsigned char d[32], char out[65]){
+ static const char *H = "0123456789abcdef";
+ for(int i = 0; i < 32; i++){ out[i*2] = H[d[i]>>4]; out[i*2+1] = H[d[i]&15]; }
+ out[64] = '\0';
+ return out;
+}
+
+static void test_sha256_vectors(void){
+ unsigned char d[32]; char h[65];
+ printf("sha256 known vectors\n");
+
+ coli_xdna_sha256("", 0, d);
+ ck(!strcmp(hex32(d,h), "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"),
+ "empty string");
+
+ coli_xdna_sha256("abc", 3, d);
+ ck(!strcmp(hex32(d,h), "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad"),
+ "abc");
+
+ coli_xdna_sha256("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", 56, d);
+ ck(!strcmp(hex32(d,h), "248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1"),
+ "448-bit multi-block message");
+
+ /* One million 'a': exercises the length encoding past 2^32 bits/8 and the
+ * multi-block loop far beyond the padding boundary. */
+ {
+ char *buf = (char*)malloc(1000000);
+ memset(buf, 'a', 1000000);
+ coli_xdna_sha256(buf, 1000000, d);
+ free(buf);
+ ck(!strcmp(hex32(d,h), "cdc76e5c9914fb9281a1c7e284d73e67f1809a48a497200e046d39ccc7112cd0"),
+ "one million 'a'");
+ }
+
+ /* Exactly at the padding boundary: 55, 56 and 64 bytes are where naive
+ * implementations lose a block. */
+ {
+ char b[64]; memset(b, 'x', sizeof b);
+ coli_xdna_sha256(b, 55, d); (void)hex32(d,h);
+ char h55[65]; strcpy(h55, h);
+ coli_xdna_sha256(b, 56, d); (void)hex32(d,h);
+ ck(strcmp(h55, h) != 0, "55 and 56 byte inputs differ");
+ coli_xdna_sha256(b, 64, d); (void)hex32(d,h);
+ ck(strcmp(h55, h) != 0, "64 byte input distinct");
+ }
+}
+
+/* ---- fixtures ----------------------------------------------------------- */
+static char g_root[512];
+
+static int write_file(const char *rel, const char *bytes, size_t n){
+ char path[1024];
+ snprintf(path, sizeof path, "%s/%s", g_root, rel);
+ FILE *f = fopen(path, "wb");
+ if(!f) return 0;
+ size_t w = n ? fwrite(bytes, 1, n, f) : 0;
+ fclose(f);
+ return w == n;
+}
+
+static void remove_file(const char *rel){
+ char path[1024];
+ snprintf(path, sizeof path, "%s/%s", g_root, rel);
+ remove(path);
+}
+
+/* Deterministic fixture bodies. These are NOT XDNA programs. */
+#define FAKE_XCLBIN "colibri-xdna-test-xclbin-body"
+#define FAKE_INSTS "colibri-xdna-test-insts-body"
+
+/* SHA256 of the two bodies, computed by the implementation under test and
+ * pinned here so a change in either the fixture or the hash is visible. */
+static char g_xclbin_sha[65], g_insts_sha[65];
+
+static ColiXdnaArtifact g_test_rows[4];
+
+static void build_registry(void){
+ unsigned char d[32];
+ coli_xdna_sha256(FAKE_XCLBIN, strlen(FAKE_XCLBIN), d); hex32(d, g_xclbin_sha);
+ coli_xdna_sha256(FAKE_INSTS, strlen(FAKE_INSTS), d); hex32(d, g_insts_sha);
+
+ /* row 0: fully qualified */
+ ColiXdnaArtifact *r = &g_test_rows[0];
+ memset(r, 0, sizeof *r);
+ r->family = COLI_XDNA_FAMILY_MOE_SHARED_GATE_UP;
+ r->research_family = "T1";
+ r->artifact_m = 64; r->k = 6144; r->n = 2048;
+ r->in_dtype = COLI_XDNA_DT_BF16;
+ r->weight_dtype = COLI_XDNA_DT_BF16;
+ r->out_dtype = COLI_XDNA_DT_F32;
+ r->target = COLI_XDNA_TARGET_XDNA2;
+ r->xclbin_name = "t1_m64.xclbin"; r->xclbin_sha256 = g_xclbin_sha;
+ r->insts_name = "t1_m64_insts.bin"; r->insts_sha256 = g_insts_sha;
+ r->runtime_weight_qualified = 1;
+ r->correctness_qualified = 1;
+ r->userptr_qualified = 1;
+ r->structural_qualified = 1;
+
+ /* row 1: identical shape, correctness NOT qualified */
+ g_test_rows[1] = g_test_rows[0];
+ g_test_rows[1].artifact_m = 256;
+ g_test_rows[1].xclbin_name = "t1_m256.xclbin";
+ g_test_rows[1].insts_name = "t1_m256_insts.bin";
+ g_test_rows[1].correctness_qualified = 0;
+}
+
+static ColiXdnaRequest req_of(ColiXdnaFamily fam, unsigned m, unsigned k, unsigned n){
+ ColiXdnaRequest q;
+ memset(&q, 0, sizeof q);
+ q.family = fam; q.m = m; q.k = k; q.n = n;
+ q.in_dtype = COLI_XDNA_DT_BF16;
+ q.weight_dtype = COLI_XDNA_DT_BF16;
+ q.out_dtype = COLI_XDNA_DT_F32;
+ return q;
+}
+
+/* ---- registry identity -------------------------------------------------- */
+static void test_lookup(void){
+ printf("registry lookup\n");
+ coli_xdna_test_set_registry(g_test_rows, 2);
+
+ ColiXdnaRequest q = req_of(COLI_XDNA_FAMILY_MOE_SHARED_GATE_UP, 64, 6144, 2048);
+ const ColiXdnaArtifact *a = coli_xdna_registry_lookup(&q);
+ ck(a != NULL, "known family + bucket + shape resolves");
+ ck(a && a->artifact_m == 64, "resolves to the requested bucket");
+
+ /* THE invariant: shape alone is not eligibility. */
+ ColiXdnaRequest other = req_of(COLI_XDNA_FAMILY_NONE, 64, 6144, 2048);
+ ck(coli_xdna_registry_lookup(&other) == NULL,
+ "same M/K/N, unknown family declines");
+
+ ColiXdnaRequest wrong_k = req_of(COLI_XDNA_FAMILY_MOE_SHARED_GATE_UP, 64, 4096, 2048);
+ ck(coli_xdna_registry_lookup(&wrong_k) == NULL, "wrong K declines");
+
+ ColiXdnaRequest wrong_n = req_of(COLI_XDNA_FAMILY_MOE_SHARED_GATE_UP, 64, 6144, 1024);
+ ck(coli_xdna_registry_lookup(&wrong_n) == NULL, "wrong N declines");
+
+ /* Buckets are exact: research qualified M=64 and M=256, nothing between. */
+ ColiXdnaRequest between = req_of(COLI_XDNA_FAMILY_MOE_SHARED_GATE_UP, 128, 6144, 2048);
+ ck(coli_xdna_registry_lookup(&between) == NULL,
+ "unqualified M bucket declines (no extrapolation)");
+
+ ColiXdnaRequest bad_dt = req_of(COLI_XDNA_FAMILY_MOE_SHARED_GATE_UP, 64, 6144, 2048);
+ bad_dt.weight_dtype = COLI_XDNA_DT_F32;
+ ck(coli_xdna_registry_lookup(&bad_dt) == NULL, "wrong prepared dtype declines");
+
+ coli_xdna_test_set_registry(NULL, 0);
+}
+
+/* ---- self validation ---------------------------------------------------- */
+static void test_registry_validation(void){
+ printf("registry self-validation\n");
+
+ coli_xdna_test_set_registry(NULL, 0);
+ ck(coli_xdna_registry_validate() == 1, "production registry self-validates");
+
+ ColiXdnaArtifact bad[2];
+ bad[0] = g_test_rows[0];
+ bad[1] = g_test_rows[0]; /* exact duplicate key */
+ coli_xdna_test_set_registry(bad, 2);
+ ck(coli_xdna_registry_validate() == 0, "duplicate key rejected");
+
+ bad[1] = g_test_rows[0]; bad[1].k = 0;
+ coli_xdna_test_set_registry(bad, 2);
+ ck(coli_xdna_registry_validate() == 0, "zero dimension rejected");
+
+ bad[1] = g_test_rows[0]; bad[1].family = COLI_XDNA_FAMILY_NONE;
+ coli_xdna_test_set_registry(bad, 2);
+ ck(coli_xdna_registry_validate() == 0, "empty family rejected");
+
+ bad[1] = g_test_rows[0]; bad[1].xclbin_sha256 = "not-a-sha";
+ coli_xdna_test_set_registry(bad, 2);
+ ck(coli_xdna_registry_validate() == 0, "malformed sha rejected");
+
+ bad[1] = g_test_rows[0]; bad[1].xclbin_name = "";
+ coli_xdna_test_set_registry(bad, 2);
+ ck(coli_xdna_registry_validate() == 0, "empty artifact name rejected");
+
+ bad[1] = g_test_rows[0]; bad[1].artifact_m = 256; bad[1].in_dtype = (ColiXdnaDtype)99;
+ coli_xdna_test_set_registry(bad, 2);
+ ck(coli_xdna_registry_validate() == 0, "invalid dtype rejected");
+
+ coli_xdna_test_set_registry(NULL, 0);
+}
+
+/* ---- presence + integrity ----------------------------------------------- */
+static void test_artifact_status(void){
+ printf("artifact presence and integrity\n");
+ coli_xdna_test_set_registry(g_test_rows, 2);
+ ColiXdnaRequest q = req_of(COLI_XDNA_FAMILY_MOE_SHARED_GATE_UP, 64, 6144, 2048);
+
+ write_file("t1_m64.xclbin", FAKE_XCLBIN, strlen(FAKE_XCLBIN));
+ write_file("t1_m64_insts.bin", FAKE_INSTS, strlen(FAKE_INSTS));
+ ck(coli_xdna_artifact_status(&q, g_root) == COLI_XDNA_STATIC_QUALIFIED,
+ "both present, both hashes correct -> STATIC_QUALIFIED");
+
+ remove_file("t1_m64.xclbin");
+ ck(coli_xdna_artifact_status(&q, g_root) == COLI_XDNA_STATIC_ARTIFACT_UNAVAILABLE,
+ "xclbin missing -> ARTIFACT_UNAVAILABLE");
+ write_file("t1_m64.xclbin", FAKE_XCLBIN, strlen(FAKE_XCLBIN));
+
+ remove_file("t1_m64_insts.bin");
+ ck(coli_xdna_artifact_status(&q, g_root) == COLI_XDNA_STATIC_ARTIFACT_UNAVAILABLE,
+ "insts missing -> ARTIFACT_UNAVAILABLE");
+ write_file("t1_m64_insts.bin", FAKE_INSTS, strlen(FAKE_INSTS));
+
+ write_file("t1_m64.xclbin", "corrupted", 9);
+ ck(coli_xdna_artifact_status(&q, g_root) == COLI_XDNA_STATIC_ARTIFACT_INTEGRITY_FAILED,
+ "corrupt xclbin -> INTEGRITY_FAILED");
+ write_file("t1_m64.xclbin", FAKE_XCLBIN, strlen(FAKE_XCLBIN));
+
+ write_file("t1_m64_insts.bin", "corrupted", 9);
+ ck(coli_xdna_artifact_status(&q, g_root) == COLI_XDNA_STATIC_ARTIFACT_INTEGRITY_FAILED,
+ "corrupt insts -> INTEGRITY_FAILED");
+
+ write_file("t1_m64.xclbin", "corrupted", 9);
+ ck(coli_xdna_artifact_status(&q, g_root) == COLI_XDNA_STATIC_ARTIFACT_INTEGRITY_FAILED,
+ "both corrupt -> INTEGRITY_FAILED");
+
+ write_file("t1_m64.xclbin", "", 0);
+ ck(coli_xdna_artifact_status(&q, g_root) == COLI_XDNA_STATIC_ARTIFACT_INTEGRITY_FAILED,
+ "empty file where content expected -> INTEGRITY_FAILED");
+
+ /* Byte-identical content but a registry hash that does not match it. */
+ write_file("t1_m64.xclbin", FAKE_XCLBIN, strlen(FAKE_XCLBIN));
+ write_file("t1_m64_insts.bin", FAKE_INSTS, strlen(FAKE_INSTS));
+ {
+ ColiXdnaArtifact wrong[1];
+ wrong[0] = g_test_rows[0];
+ wrong[0].xclbin_sha256 =
+ "0000000000000000000000000000000000000000000000000000000000000000";
+ coli_xdna_test_set_registry(wrong, 1);
+ ck(coli_xdna_artifact_status(&q, g_root) == COLI_XDNA_STATIC_ARTIFACT_INTEGRITY_FAILED,
+ "wrong expected hash in registry -> INTEGRITY_FAILED");
+ coli_xdna_test_set_registry(g_test_rows, 2);
+ }
+
+ coli_xdna_test_set_registry(NULL, 0);
+}
+
+/* ---- qualification flags ------------------------------------------------ */
+static void test_qualification_gate(void){
+ printf("qualification gates\n");
+ coli_xdna_test_set_registry(g_test_rows, 2);
+
+ /* Row 1 has valid files and correct hashes but correctness_qualified = 0.
+ * This is COMPILE_PASS/DISPATCH_PASS != ELIGIBLE, executable rather than
+ * asserted in prose. */
+ write_file("t1_m256.xclbin", FAKE_XCLBIN, strlen(FAKE_XCLBIN));
+ write_file("t1_m256_insts.bin", FAKE_INSTS, strlen(FAKE_INSTS));
+ ColiXdnaRequest q256 = req_of(COLI_XDNA_FAMILY_MOE_SHARED_GATE_UP, 256, 6144, 2048);
+ ck(coli_xdna_artifact_status(&q256, g_root) == COLI_XDNA_STATIC_ARTIFACT_UNQUALIFIED,
+ "valid hashes + correctness=false -> ARTIFACT_UNQUALIFIED");
+
+ ColiXdnaArtifact one[1];
+ ColiXdnaRequest q64 = req_of(COLI_XDNA_FAMILY_MOE_SHARED_GATE_UP, 64, 6144, 2048);
+
+ one[0] = g_test_rows[0]; one[0].runtime_weight_qualified = 0;
+ coli_xdna_test_set_registry(one, 1);
+ ck(coli_xdna_artifact_status(&q64, g_root) == COLI_XDNA_STATIC_ARTIFACT_UNQUALIFIED,
+ "runtime-weight qualification required");
+
+ one[0] = g_test_rows[0]; one[0].userptr_qualified = 0;
+ coli_xdna_test_set_registry(one, 1);
+ ck(coli_xdna_artifact_status(&q64, g_root) == COLI_XDNA_STATIC_ARTIFACT_UNQUALIFIED,
+ "userptr qualification required");
+
+ one[0] = g_test_rows[0]; one[0].structural_qualified = 0;
+ coli_xdna_test_set_registry(one, 1);
+ ck(coli_xdna_artifact_status(&q64, g_root) == COLI_XDNA_STATIC_ARTIFACT_UNQUALIFIED,
+ "structural qualification required");
+
+ coli_xdna_test_set_registry(NULL, 0);
+}
+
+/* ---- path contract ------------------------------------------------------ */
+static void test_path_contract(void){
+ printf("artifact path contract\n");
+ ColiXdnaArtifact esc[1];
+ esc[0] = g_test_rows[0];
+ esc[0].xclbin_name = "../escape.xclbin";
+ coli_xdna_test_set_registry(esc, 1);
+ ck(coli_xdna_registry_validate() == 0, "traversal in artifact name rejected by validation");
+
+ ColiXdnaRequest q = req_of(COLI_XDNA_FAMILY_MOE_SHARED_GATE_UP, 64, 6144, 2048);
+ ck(coli_xdna_artifact_status(&q, g_root) == COLI_XDNA_STATIC_REGISTRY_INVALID,
+ "traversal never reaches the filesystem");
+
+ esc[0].xclbin_name = "sub\\..\\escape.xclbin";
+ coli_xdna_test_set_registry(esc, 1);
+ ck(coli_xdna_registry_validate() == 0, "backslash traversal rejected");
+
+ esc[0].xclbin_name = "C:/absolute.xclbin";
+ coli_xdna_test_set_registry(esc, 1);
+ ck(coli_xdna_registry_validate() == 0, "absolute artifact name rejected");
+
+ coli_xdna_test_set_registry(g_test_rows, 2);
+ ck(coli_xdna_artifact_status(&q, NULL) == COLI_XDNA_STATIC_ARTIFACT_UNAVAILABLE,
+ "no artifact root supplied -> ARTIFACT_UNAVAILABLE, never CWD");
+
+ coli_xdna_test_set_registry(NULL, 0);
+}
+
+/* ---- helper state and artifact state are independent -------------------- */
+static void test_state_separation(void){
+ printf("helper / artifact state separation\n");
+ coli_xdna_test_set_registry(g_test_rows, 2);
+ write_file("t1_m64.xclbin", FAKE_XCLBIN, strlen(FAKE_XCLBIN));
+ write_file("t1_m64_insts.bin", FAKE_INSTS, strlen(FAKE_INSTS));
+ ColiXdnaRequest q = req_of(COLI_XDNA_FAMILY_MOE_SHARED_GATE_UP, 64, 6144, 2048);
+
+ /* No helper anywhere: the artifact is still statically qualified, because
+ * artifact trust is a property of the artifact, not of the runtime. */
+ coli_xdna_test_set_helper_path("C:/nonexistent/coli_xdna.dll");
+ ck(coli_xdna_binding() == COLI_XDNA_ABSENT, "helper absent");
+ ck(coli_xdna_artifact_status(&q, g_root) == COLI_XDNA_STATIC_QUALIFIED,
+ "artifact qualification independent of helper absence");
+
+ /* ...but combined static eligibility still declines, because the lane as a
+ * whole is unusable without a helper. */
+ ck(coli_xdna_static_eligibility(&q, g_root) == COLI_XDNA_STATIC_HELPER_UNAVAILABLE,
+ "combined eligibility declines when the helper is absent");
+
+ coli_xdna_test_set_helper_path(NULL);
+ coli_xdna_test_set_registry(NULL, 0);
+}
+
+/* ---- the states this slice must NOT be able to produce ------------------ */
+static void test_no_runtime_readiness(void){
+ printf("no runtime readiness is claimed\n");
+ /* The strongest verdict reachable in I2 is STATIC_QUALIFIED. There is no
+ * enumerator for device, prepared, aligned or dispatch readiness, and the
+ * label says "STATIC" so it cannot be misread at a call site. */
+ ck(!strcmp(coli_xdna_static_text(COLI_XDNA_STATIC_QUALIFIED),
+ "STATIC_ARTIFACT_QUALIFIED"),
+ "best verdict is explicitly STATIC");
+ ck(coli_xdna_test_device_opens() == 0, "no device was opened");
+ ck(coli_xdna_test_helper_calls() == 0, "no helper entry point was called");
+}
+
+/* ---- production rows ---------------------------------------------------- */
+static void test_production_rows(void){
+ printf("production registry rows\n");
+ coli_xdna_test_set_registry(NULL, 0);
+ ck(coli_xdna_registry_validate() == 1, "production rows self-validate");
+
+ ColiXdnaRequest q64 = req_of(COLI_XDNA_FAMILY_MOE_SHARED_GATE_UP, 64, 6144, 2048);
+ ColiXdnaRequest q256 = req_of(COLI_XDNA_FAMILY_MOE_SHARED_GATE_UP, 256, 6144, 2048);
+ const ColiXdnaArtifact *a64 = coli_xdna_registry_lookup(&q64);
+ const ColiXdnaArtifact *a256 = coli_xdna_registry_lookup(&q256);
+ ck(a64 && a256, "both qualified F3 buckets present");
+ ck(a64 && !strcmp(a64->research_family, "F3"), "research family recorded");
+ ck(a64 && a64->correctness_qualified && a64->userptr_qualified
+ && a64->runtime_weight_qualified && a64->structural_qualified,
+ "all four qualifications asserted");
+
+ /* Scope discipline: V1 is one family. Other research families exist as
+ * artifacts but must not be reachable here. */
+ ColiXdnaRequest f1 = req_of(COLI_XDNA_FAMILY_MOE_SHARED_GATE_UP, 64, 2048, 1024);
+ ck(coli_xdna_registry_lookup(&f1) == NULL, "F1 shape not in the V1 registry");
+ ColiXdnaRequest f6 = req_of(COLI_XDNA_FAMILY_MOE_SHARED_GATE_UP, 64, 6144, 12288);
+ ck(coli_xdna_registry_lookup(&f6) == NULL, "F6 shape not in the V1 registry");
+
+ /* Artifacts are not shipped: absence is the normal, non-fatal state. */
+ ck(coli_xdna_artifact_status(&q64, g_root) == COLI_XDNA_STATIC_ARTIFACT_UNAVAILABLE,
+ "unshipped production artifact -> ARTIFACT_UNAVAILABLE");
+}
+
+int main(void){
+ /* Every fixture lives in a private directory beside the test binary; the
+ * registry never reads the current directory of its own accord. */
+ snprintf(g_root, sizeof g_root, "xdna_registry_fixtures");
+#ifdef _WIN32
+ _mkdir(g_root);
+#else
+ mkdir(g_root, 0777);
+#endif
+
+ build_registry();
+ test_sha256_vectors();
+ test_lookup();
+ test_registry_validation();
+ test_artifact_status();
+ test_qualification_gate();
+ test_path_contract();
+ test_state_separation();
+ test_production_rows();
+ test_no_runtime_readiness();
+
+ /* Leave nothing behind: the fixtures are written beside the test binary,
+ * and a stray directory in the source tree would show up as untracked
+ * noise for every developer who runs the suite. */
+ remove_file("t1_m64.xclbin");
+ remove_file("t1_m64_insts.bin");
+ remove_file("t1_m256.xclbin");
+ remove_file("t1_m256_insts.bin");
+#ifdef _WIN32
+ _rmdir(g_root);
+#else
+ rmdir(g_root);
+#endif
+
+ printf("test_xdna_registry: %s\n", g_fail ? "FAIL" : "ok");
+ return g_fail;
+}