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

test(cuda): host-testable weight_at format predicate + device-side trap coverage

monotophic8560724f7fe1
diff --git a/c/.gitignore b/c/.gitignore
index c843d62a..d103820e 100644
--- a/c/.gitignore
+++ b/c/.gitignore
@@ -22,6 +22,7 @@ tests/bench_omp_grain
tests/mxfp4_ref.o
mxfp4_cuda_test
absorb_determinism_test
+cuda_fmt_trap_test
tests/*.dSYM/
tests/test_dsa_select
tests/test_i4_grouped
diff --git a/c/Makefile b/c/Makefile
index fb8c6722..6bda50b6 100644
--- a/c/Makefile
+++ b/c/Makefile
@@ -840,12 +840,19 @@ rans: $(RANSLIB)
$(RANSLIB): tools/rans_ctypes.c rans.h
$(CC) $(CFLAGS) -fPIC -shared $< -o $@ $(LDFLAGS)
-cuda-test: backend_cuda.cu backend_cuda.h backend_gpu_compat.h tests/test_backend_cuda.cu tests/test_ragged_attention.cu tests/test_absorb_determinism.cu tests/test_mxfp4_cuda.cu tests/mxfp4_ref.c tests/test_fp8_warp_cuda.cu
+cuda-test: backend_cuda.cu backend_cuda.h backend_gpu_compat.h tests/test_backend_cuda.cu tests/test_ragged_attention.cu tests/test_absorb_determinism.cu tests/test_mxfp4_cuda.cu tests/mxfp4_ref.c tests/test_fp8_warp_cuda.cu tests/test_cuda_fmt_trap_cuda.cu
@command -v "$(GPUCC)" >/dev/null 2>&1 || { echo "$(GPUCC_NAME) not found" >&2; exit 1; }
"$(GPUCC)" $(GPUFLAGS) backend_cuda.cu tests/test_backend_cuda.cu -o backend_cuda_test$(EXE) $(ANS_NVCC_LIBS)
./backend_cuda_test$(EXE)
"$(GPUCC)" $(GPUFLAGS) backend_cuda.cu tests/test_ragged_attention.cu -o ragged_attention_test$(EXE)
./ragged_attention_test$(EXE)
+ # weight_at's device-side refusal (the __trap()) on real silicon. The
+ # host-side half is tests/test_cuda_fmt_guard.c, which runs in the CPU
+ # suite and cannot execute device code. Includes backend_cuda.cu itself:
+ # weight_at is file-static, and the trap is unreachable through the public
+ # API by design. Re-execs itself per probe (the trap poisons the context).
+ "$(GPUCC)" $(GPUFLAGS) tests/test_cuda_fmt_trap_cuda.cu -o cuda_fmt_trap_test$(EXE) $(ANS_NVCC_LIBS)
+ ./cuda_fmt_trap_test$(EXE)
# fmt=8 warp kernels (COLI_CUDA_F8_WARP): decode sweep, census + tail
# shapes, S-invariance, NaN/denormal policy. Includes backend_cuda.cu
# itself (kernel-level oracle), so only the test file is compiled.
@@ -901,6 +908,7 @@ gpu-compile: backend_cuda.o
"$(GPUCC)" $(GPUFLAGS) backend_cuda.cu tests/test_ragged_attention.cu -o ragged_attention_test$(EXE)
"$(GPUCC)" $(GPUFLAGS) backend_cuda.cu tests/test_absorb_determinism.cu -o absorb_determinism_test$(EXE)
"$(GPUCC)" $(GPUFLAGS) tests/test_fp8_warp_cuda.cu -o fp8_warp_test$(EXE) $(ANS_NVCC_LIBS)
+ "$(GPUCC)" $(GPUFLAGS) tests/test_cuda_fmt_trap_cuda.cu -o cuda_fmt_trap_test$(EXE) $(ANS_NVCC_LIBS)
cuda-bench: backend_cuda.cu backend_cuda.h backend_gpu_compat.h tests/bench_tensor_core.cu
@command -v "$(GPUCC)" >/dev/null 2>&1 || { echo "$(GPUCC_NAME) not found" >&2; exit 1; }
@@ -1147,6 +1155,12 @@ tests/test_int3_load$(EXE): tests/test_int3_load.c colibri.c st.h uring.h json.h
tests/test_fp8_passthrough$(EXE): tests/test_fp8_passthrough.c quant.h
$(CC) $(CFLAGS) $< -o $@ $(LDFLAGS)
+# Host-only: backend_cuda.h's format predicate is plain C, so its truth table is
+# a portable gate even where there is no CUDA toolchain. Same arrangement as
+# metal_fused_fmt_ok's CPU-testable truth table.
+tests/test_cuda_fmt_guard$(EXE): tests/test_cuda_fmt_guard.c backend_cuda.h
+ $(CC) $(CFLAGS) $< -o $@ $(LDFLAGS)
+
tests/test_fp8_load$(EXE): tests/test_fp8_load.c colibri.c 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
$(CC) $(CFLAGS) $< -o $@ $(LDFLAGS)
diff --git a/c/backend_cuda.h b/c/backend_cuda.h
index d614aa6b..f42c71f8 100644
--- a/c/backend_cuda.h
+++ b/c/backend_cuda.h
@@ -21,6 +21,35 @@ extern "C" {
#define COLI_CUDA_MAX_DEVICES 16
+/* Weight formats the generic per-element device decoder (weight_at,
+ * backend_cuda.cu) can actually decode: f32, int8-row, int4 nibbles (fmt=2 and
+ * the grouped fmt=4, same packing), and int2. Nothing else.
+ *
+ * WHY THIS IS A PREDICATE AND NOT A COMMENT. weight_at used to END in the int2
+ * decode as an unguarded fall-through, so ANY other format handed to it -- a
+ * format with a different element width, a different scale geometry, or no
+ * device decoder at all -- was silently read as 2-bit values and returned
+ * plausible-looking numbers. The CPU twins refuse the same input loudly:
+ * qt_addrow and qt_matvec_rows (colibri.c) both exit(1) naming the function and
+ * the fmt. Two backends given identical unsupported input, one refusing and one
+ * fabricating, is the defect -- not the missing decoder.
+ *
+ * Defined here, in the host header, rather than inside the .cu: the host gates
+ * that keep unsupported formats off the device (absorb_fmt_ok and friends) and
+ * the device-side backstop must agree by construction rather than by two people
+ * writing the same list twice, and a CPU test build can then unit-test the truth
+ * table without a GPU or a CUDA toolchain (tests/test_cuda_fmt_guard.c) -- the
+ * same arrangement colibri.c uses for metal_fused_fmt_ok.
+ *
+ * NOT a statement about which formats the CUDA BACKEND supports: quant_matmul
+ * has its own explicit branches for fmt=6 (E8/IQ3), fmt=7 (MXFP4) and fmt=8
+ * (fp8-e4m3) that never route through weight_at. This predicate is scoped to
+ * weight_at's own dispatch, which is what the absorb and grouped-expert kernels
+ * decode through. */
+static inline int coli_cuda_weight_at_supported(int fmt) {
+ return fmt == 0 || fmt == 1 || fmt == 2 || fmt == 3 || fmt == 4;
+}
+
/* Opaque, persistent device copy of one resident quantized tensor. */
typedef struct ColiCudaTensor ColiCudaTensor;
diff --git a/c/tests/test_cuda_fmt_guard.c b/c/tests/test_cuda_fmt_guard.c
new file mode 100644
index 00000000..056d6853
--- /dev/null
+++ b/c/tests/test_cuda_fmt_guard.c
@@ -0,0 +1,79 @@
+/* The CUDA generic-decoder format guard, unit-tested WITHOUT a GPU or a CUDA
+ * toolchain.
+ *
+ * THE DEFECT THIS PINS. backend_cuda.cu's weight_at() decoded fmt 0/1/2/4
+ * explicitly and then FELL THROUGH to a 2-bit decode for everything else, with
+ * no guard. So a tensor in any other format handed to the absorb or
+ * grouped-expert kernels came back as plausible numbers derived from reading
+ * its bytes two bits at a time. The CPU functions doing the same job on the
+ * same tensor -- qt_addrow and qt_matvec_rows in colibri.c -- both exit(1)
+ * naming the function and the fmt. Two backends, identical unsupported input,
+ * one refusing and one fabricating.
+ *
+ * weight_at now decodes fmt=3 in an explicit branch and __trap()s on the
+ * fall-through, and the host-side gate that keeps unsupported formats off the
+ * device reads its admissible set from the SAME predicate rather than
+ * restating it (`fmt <= 4`, which also admitted negative fmt). That predicate,
+ * coli_cuda_weight_at_supported, is an ordinary C function in backend_cuda.h,
+ * so its truth table is checkable on any host -- the same arrangement
+ * colibri.c uses for metal_fused_fmt_ok ("Defined unconditionally (not #ifdef
+ * COLI_METAL) so the CPU test build can unit-test the truth table").
+ *
+ * WHAT THIS TEST CANNOT DO, stated rather than implied: it does not execute
+ * weight_at, because that is device code. It pins the predicate the host gates
+ * consult and the boundary of the set weight_at's explicit branches cover. The
+ * device-side __trap() firing on a real launch needs CUDA hardware and is
+ * verified there, not here.
+ *
+ * ENUMERATED, NOT SAMPLED: every fmt value a container can carry (0..8 --
+ * qt_resolve_fmt's own documented return set, colibri.c) is asserted by name,
+ * plus the out-of-range values a corrupt or hostile descriptor could present. */
+#include "../backend_cuda.h"
+
+#include <stdio.h>
+
+static int fails = 0;
+#define CHECK(c) do{ if(!(c)){ printf("FAIL %s:%d: %s\n", __FILE__, __LINE__, #c); fails++; } }while(0)
+
+int main(void) {
+ /* Decodable by weight_at's explicit branches. */
+ CHECK(coli_cuda_weight_at_supported(0)); /* f32 */
+ CHECK(coli_cuda_weight_at_supported(1)); /* int8-row */
+ CHECK(coli_cuda_weight_at_supported(2)); /* int4 nibbles */
+ CHECK(coli_cuda_weight_at_supported(3)); /* int2 */
+ CHECK(coli_cuda_weight_at_supported(4)); /* grouped int4 */
+
+ /* NOT decodable. Each of these has a real in-tree meaning, and each used to
+ * be read as int2 by the fall-through. fmt=5 and fmt=6 are the ones that
+ * could already reach a CUDA tensor; fmt=8 is the one this branch is about;
+ * fmt=7 (MXFP4) has its own quant_matmul branch and never routes here. */
+ CHECK(!coli_cuda_weight_at_supported(5)); /* int3-g64 */
+ CHECK(!coli_cuda_weight_at_supported(6)); /* E8/IQ3 */
+ CHECK(!coli_cuda_weight_at_supported(7)); /* MXFP4 */
+ CHECK(!coli_cuda_weight_at_supported(8)); /* fp8-e4m3-b128 */
+
+ /* Out of range in both directions. The negative cases are the ones the
+ * previous `fmt <= 4` host gate admitted: a descriptor whose fmt field is
+ * garbage passed that inequality and then fell through weight_at into the
+ * int2 decode. */
+ CHECK(!coli_cuda_weight_at_supported(-1));
+ CHECK(!coli_cuda_weight_at_supported(-1000));
+ CHECK(!coli_cuda_weight_at_supported(9));
+ CHECK(!coli_cuda_weight_at_supported(100)); /* PRIVATE ORDINAL BLOCK base */
+ CHECK(!coli_cuda_weight_at_supported(1 << 30));
+
+ /* The set is exactly {0,1,2,3,4} and nothing else in a wide sweep -- so a
+ * later edit that widens the predicate has to change this line too. */
+ for (int fmt = -2048; fmt <= 2048; fmt++) {
+ int expect = (fmt >= 0 && fmt <= 4);
+ if (!!coli_cuda_weight_at_supported(fmt) != expect) {
+ printf("FAIL fmt=%d: supported=%d, expected %d\n",
+ fmt, coli_cuda_weight_at_supported(fmt), expect);
+ fails++;
+ }
+ }
+
+ if (fails) { printf("cuda fmt guard tests: %d FAILED\n", fails); return 1; }
+ printf("cuda fmt guard tests: ok\n");
+ return 0;
+}
diff --git a/c/tests/test_cuda_fmt_trap_cuda.cu b/c/tests/test_cuda_fmt_trap_cuda.cu
new file mode 100644
index 00000000..7028fd06
--- /dev/null
+++ b/c/tests/test_cuda_fmt_trap_cuda.cu
@@ -0,0 +1,282 @@
+/* The DEVICE half of the weight_at format guard: the __trap() itself, on real
+ * silicon.
+ *
+ * WHY THIS FILE EXISTS SEPARATELY FROM tests/test_cuda_fmt_guard.c. That test
+ * pins the truth table of coli_cuda_weight_at_supported -- the HOST predicate
+ * the launch-site gates consult -- and says so in its own header: "it does not
+ * execute weight_at, because that is device code". So deleting the __trap() at
+ * the end of weight_at left that suite entirely green. The refusal that the
+ * whole change is about was pinned by nothing. This file is that pin.
+ *
+ * HOW THE TRAP IS REACHED. It is a BACKSTOP: in normal operation the host gates
+ * (the upload row_bytes check, quant_matmul's explicit branches, the grouped
+ * path's gf/uf/df>3 refusal, absorb_fmt_ok) reject unsupported formats before a
+ * launch happens, so no public API call can get there. Reaching it therefore has
+ * to be deliberate. weight_at is `__device__ static`, i.e. private to
+ * backend_cuda.cu's translation unit, so this test #includes backend_cuda.cu --
+ * the same arrangement tests/test_fp8_warp_cuda.cu and tests/test_fp8_cuda.cu
+ * already use to test kernel internals -- and launches its own one-thread kernel
+ * against it with an fmt the host would never have let through. No product gate
+ * is weakened or bypassed in the engine; the test simply stands where a buggy
+ * launch site would stand.
+ *
+ * WHY CHILD PROCESSES. __trap() aborts the kernel and poisons the CUDA context:
+ * every subsequent call on that context returns an error, so a second probe in
+ * the same process could not tell "weight_at trapped" from "the context was
+ * already dead". Each unsupported-format probe therefore runs in a fresh
+ * process (fork + execv of this same binary with --a6-probe FMT), and the parent
+ * reads the verdict off the child's exit status. fork alone would not do: a CUDA
+ * context does not survive fork, so the child re-execs to get a clean one.
+ *
+ * WHAT MAKES THIS TEST BITE RATHER THAN MERELY PASS. Three controls, because an
+ * exit code that says "the child failed" is worthless if the child fails no
+ * matter what:
+ * 1. IN-PROCESS control: every supported fmt (0,1,2,3,4) is launched in the
+ * parent and must complete cleanly. If weight_at trapped on those, the
+ * trap would be firing on valid input and this test would fail here.
+ * 2. CHILD-HARNESS control: two SUPPORTED formats also go through the child
+ * path and must come back A6_EXIT_DECODED. This is what distinguishes a
+ * working harness from one that reports "aborted" unconditionally.
+ * 3. THE PROBES: every unsupported fmt must come back A6_EXIT_TRAPPED. With
+ * the __trap() removed and the int2 fall-through restored, the kernel
+ * returns a number instead, the child exits A6_EXIT_DECODED, and this test
+ * fails -- which is the whole point of it.
+ *
+ * The fmt set probed is the complement of coli_cuda_weight_at_supported over the
+ * formats a container can actually carry (5,6,7,8), plus the out-of-range values
+ * a corrupt descriptor could present (-1, 9, 1<<30) -- the ones the previous
+ * `fmt <= 4` host gate admitted.
+ *
+ * make -C c cuda-test CUDA_ARCH=native (runs this among the CUDA tests)
+ */
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
+
+/* No direct <cuda_runtime.h>: the backend include below pulls
+ * backend_gpu_compat.h, which supplies the runtime surface for BOTH vendors. */
+#include "../backend_cuda.cu"
+
+#ifndef _WIN32
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <unistd.h>
+#endif
+
+/* Child exit codes. Deliberately not 0/1: a child that dies before reaching the
+ * probe (missing binary, exec failure, CUDA init failure) must not be mistaken
+ * for either verdict. */
+#define A6_EXIT_TRAPPED 42 /* the launch aborted -- the refusal fired */
+#define A6_EXIT_DECODED 43 /* the kernel returned a value -- no refusal */
+#define A6_EXIT_HARNESS 44 /* could not run the probe at all */
+
+#define A6_PROBE_FLAG "--a6-probe"
+
+/* A byte pattern that is a finite float under the fmt=0 branch and a nonzero
+ * value under every packed branch, so an unguarded fall-through produces a
+ * visible number rather than something that could be mistaken for "no output". */
+#define A6_FILL 0xA5
+
+/* The deliberate bad launch. weight_at is file-static device code; this is the
+ * only caller in this TU, and it passes fmt straight through as a runtime
+ * argument so nvcc cannot constant-fold the dispatch away. */
+__global__ static void a6_probe_kernel(const void *w, int fmt, float *out) {
+ if (threadIdx.x == 0 && blockIdx.x == 0) out[0] = weight_at(w, fmt, 0, 0);
+}
+
+/* ---- child mode ---------------------------------------------------------- */
+
+static int a6_probe_child(int fmt) {
+ void *w = NULL;
+ float *out = NULL;
+
+ if (cudaMalloc(&w, 256) != cudaSuccess) {
+ printf(" [child fmt=%d] cudaMalloc(weights) failed\n", fmt);
+ return A6_EXIT_HARNESS;
+ }
+ if (cudaMemset(w, A6_FILL, 256) != cudaSuccess) {
+ printf(" [child fmt=%d] cudaMemset failed\n", fmt);
+ return A6_EXIT_HARNESS;
+ }
+ if (cudaMalloc((void **)&out, sizeof(float)) != cudaSuccess) {
+ printf(" [child fmt=%d] cudaMalloc(out) failed\n", fmt);
+ return A6_EXIT_HARNESS;
+ }
+ if (cudaMemset(out, 0, sizeof(float)) != cudaSuccess) {
+ printf(" [child fmt=%d] cudaMemset(out) failed\n", fmt);
+ return A6_EXIT_HARNESS;
+ }
+ (void)cudaGetLastError(); /* start from a clean slate */
+
+ a6_probe_kernel<<<1, 1>>>(w, fmt, out);
+ cudaError_t launch = cudaGetLastError();
+ cudaError_t sync = cudaDeviceSynchronize();
+
+ if (launch != cudaSuccess || sync != cudaSuccess) {
+ printf(" [child fmt=%d] launch aborted: launch=%s sync=%s\n", fmt,
+ cudaGetErrorString(launch), cudaGetErrorString(sync));
+ return A6_EXIT_TRAPPED;
+ }
+
+ /* The context survived the launch. Read the value back: only a decode that
+ * actually completed can produce one, so this is the "no refusal" verdict.
+ * A copy that fails here means the context died after all -- still a trap. */
+ float v = 0.f;
+ cudaError_t cp = cudaMemcpy(&v, out, sizeof(float), cudaMemcpyDeviceToHost);
+ if (cp != cudaSuccess) {
+ printf(" [child fmt=%d] readback failed after a clean sync: %s\n",
+ fmt, cudaGetErrorString(cp));
+ return A6_EXIT_TRAPPED;
+ }
+ printf(" [child fmt=%d] weight_at RETURNED %g\n", fmt, (double)v);
+ return A6_EXIT_DECODED;
+}
+
+/* ---- parent mode --------------------------------------------------------- */
+
+static int fails = 0;
+
+/* Run one probe in a fresh process. Returns the child's exit code, or -signum if
+ * it died on a signal, or -1000 if it could not be run at all. */
+#ifndef _WIN32
+static int a6_run_child(const char *self, int fmt) {
+ char arg[32];
+ snprintf(arg, sizeof arg, "%d", fmt);
+
+ fflush(stdout);
+ pid_t pid = fork();
+ if (pid < 0) return -1000;
+ if (pid == 0) {
+ /* execv, not a bare fork: a CUDA context does not survive fork, so the
+ * child needs a fresh process image to get a usable one. */
+ char *argv[4];
+ argv[0] = (char *)self;
+ argv[1] = (char *)A6_PROBE_FLAG;
+ argv[2] = arg;
+ argv[3] = NULL;
+ execv(self, argv);
+ _exit(A6_EXIT_HARNESS); /* execv only returns on error */
+ }
+ int status = 0;
+ if (waitpid(pid, &status, 0) != pid) return -1000;
+ if (WIFEXITED(status)) return WEXITSTATUS(status);
+ if (WIFSIGNALED(status)) return -WTERMSIG(status);
+ return -1000;
+}
+#else
+/* MSVC (nvcc's host compiler on Windows) has no fork/waitpid. system() returns
+ * the child's exit code directly there. NOTE: `make cuda-test` is unreachable on
+ * Windows (the Makefile errors out and directs you to `make CUDA_DLL=1
+ * cuda-dll`), so this branch exists to keep the file COMPILING on that
+ * toolchain, and has not been executed. */
+static int a6_run_child(const char *self, int fmt) {
+ char cmd[1024];
+ snprintf(cmd, sizeof cmd, "\"%s\" %s %d", self, A6_PROBE_FLAG, fmt);
+ fflush(stdout);
+ int rc = system(cmd);
+ return rc < 0 ? -1000 : rc;
+}
+#endif
+
+static void expect_child(const char *self, int fmt, int want, const char *why) {
+ int got = a6_run_child(self, fmt);
+ if (got == want) {
+ printf("ok fmt=%-6d %s (child exit %d)\n", fmt, why, got);
+ return;
+ }
+ if (got == A6_EXIT_DECODED && want == A6_EXIT_TRAPPED) {
+ printf("FAIL fmt=%-6d weight_at DECODED an unsupported format instead of "
+ "refusing it -- the device-side __trap() is not firing\n", fmt);
+ } else if (got == A6_EXIT_TRAPPED && want == A6_EXIT_DECODED) {
+ printf("FAIL fmt=%-6d the probe harness reports 'aborted' for a SUPPORTED "
+ "format -- the harness cannot tell the two verdicts apart, so its "
+ "unsupported-format results mean nothing\n", fmt);
+ } else if (got < 0 && got != -1000 && want == A6_EXIT_TRAPPED) {
+ /* A trap that takes the whole process down rather than surfacing as a
+ * CUDA error is still a refusal, but say so rather than folding it into
+ * the clean verdict. */
+ printf("ok fmt=%-6d %s (child killed by signal %d -- the launch did not "
+ "return a value)\n", fmt, why, -got);
+ return;
+ } else {
+ printf("FAIL fmt=%-6d probe did not run: child result %d (wanted %d)\n",
+ fmt, got, want);
+ }
+ fails++;
+}
+
+/* The in-process control: supported formats must decode cleanly right here, so a
+ * trap firing on valid input fails the test before any child runs. */
+static void inprocess_supported_control(void) {
+ void *w = NULL;
+ float *out = NULL;
+ if (cudaMalloc(&w, 256) != cudaSuccess ||
+ cudaMemset(w, A6_FILL, 256) != cudaSuccess ||
+ cudaMalloc((void **)&out, sizeof(float)) != cudaSuccess) {
+ printf("FAIL could not allocate the probe buffers\n");
+ fails++;
+ return;
+ }
+ (void)cudaGetLastError();
+ for (int fmt = 0; fmt <= 4; fmt++) {
+ if (!coli_cuda_weight_at_supported(fmt)) { /* keeps the two in step */
+ printf("FAIL fmt=%d is in this loop but the host predicate rejects it\n", fmt);
+ fails++;
+ continue;
+ }
+ a6_probe_kernel<<<1, 1>>>(w, fmt, out);
+ cudaError_t launch = cudaGetLastError();
+ cudaError_t sync = cudaDeviceSynchronize();
+ float v = 0.f;
+ cudaError_t cp = (launch == cudaSuccess && sync == cudaSuccess)
+ ? cudaMemcpy(&v, out, sizeof(float), cudaMemcpyDeviceToHost)
+ : cudaErrorUnknown;
+ if (launch != cudaSuccess || sync != cudaSuccess || cp != cudaSuccess) {
+ printf("FAIL fmt=%d is SUPPORTED but the launch did not complete: "
+ "launch=%s sync=%s\n", fmt,
+ cudaGetErrorString(launch), cudaGetErrorString(sync));
+ fails++;
+ return; /* the context is poisoned; nothing after this is valid */
+ }
+ printf("ok fmt=%-6d supported: decoded in-process, weight_at = %g\n",
+ fmt, (double)v);
+ }
+ cudaFree(w);
+ cudaFree(out);
+}
+
+int main(int argc, char **argv) {
+ if (argc >= 3 && strcmp(argv[1], A6_PROBE_FLAG) == 0)
+ return a6_probe_child(atoi(argv[2]));
+
+ int ndev = 0;
+ if (cudaGetDeviceCount(&ndev) != cudaSuccess || ndev < 1) {
+ /* NOT a skip. This test's entire subject is what the hardware does, so
+ * reporting success without hardware would be the one outcome worse than
+ * failing. */
+ printf("cuda fmt trap test: NO CUDA DEVICE -- the device-side refusal "
+ "cannot be verified here\n");
+ return 1;
+ }
+
+ printf("-- control: supported formats decode (in-process)\n");
+ inprocess_supported_control();
+
+ printf("-- control: the child harness can report a successful decode\n");
+ expect_child(argv[0], 0, A6_EXIT_DECODED, "supported, decoded in a child");
+ expect_child(argv[0], 3, A6_EXIT_DECODED, "supported, decoded in a child");
+
+ printf("-- the guard: unsupported formats must refuse, not fabricate\n");
+ expect_child(argv[0], 5, A6_EXIT_TRAPPED, "int3-g64 refused");
+ expect_child(argv[0], 6, A6_EXIT_TRAPPED, "E8/IQ3 refused");
+ expect_child(argv[0], 7, A6_EXIT_TRAPPED, "MXFP4 refused");
+ expect_child(argv[0], 8, A6_EXIT_TRAPPED, "fp8-e4m3-b128 refused");
+ expect_child(argv[0], 9, A6_EXIT_TRAPPED, "past the last defined fmt, refused");
+ expect_child(argv[0], -1, A6_EXIT_TRAPPED, "negative fmt refused (the old "
+ "`fmt <= 4` gate admitted this)");
+ expect_child(argv[0], 1 << 30, A6_EXIT_TRAPPED, "garbage fmt refused");
+
+ if (fails) { printf("cuda fmt trap tests: %d FAILED\n", fails); return 1; }
+ printf("cuda fmt trap tests: ok\n");
+ return 0;
+}