interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / tests / runtime / rx_compose_gpu_skill.h

119 lines · 5056 bytes Raw Blame History
1/* SPDX-License-Identifier: Apache-2.0
2 * Copyright 2026 Drake Stapleton (AIEN / aien-dev)
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17/*
18 * rx_compose_gpu_skill.h -- the COMPOSITION-2 gate's two Skills executed on
19 * the GB10 (GPU tier). Same contract and same faults as the host Skills in
20 * rx_compose_fixture.h, but the arithmetic runs on the chip.
21 *
22 * A Skill is the affine map y = w0 * x + w1 with its own weights: Skill A
23 * (3, 1), or (3, 2) when made to break the contract; Skill B (3, 1), or
24 * (3, 6). Each call builds one INT32 matrix product C = A * B with the
25 * synthesized sm_121 kernel and submits it through the sovereign M16 native
26 * path (omega_blackwell_execute_matmul: nvrm channel, no CUDA): A is 16x2
27 * with row 0 = [x, 1], B is 2x16 with column 0 = [w0, w1], every other entry
28 * zero, so every chip thread stays inside the arrays. The Skill result is
29 * C[0][0] read back from chip memory. The host reference product is used
30 * only to check the chip (a mismatch fails the call); it is never returned.
31 *
32 * A call that cannot reach the chip, or whose input or result does not fit
33 * the exact 32-bit product, reports failed and returns 0: the gate then
34 * fails, it never falls back to host arithmetic.
35 */
36#ifndef RX_COMPOSE_GPU_SKILL_H
37#define RX_COMPOSE_GPU_SKILL_H
38
39#include "rx_compose_fixture.h"
40#include "omega_blackwell_matmul.h"
41#include "omega_blackwell_submit.h"
42
43#define GPU_SK_DIM 16u
44#define GPU_SK_K 2u
45
46typedef struct {
47 uint32_t runs[2]; /* chip executions per Skill (A, B) */
48 uint32_t failures; /* chip calls that did not return a checked result */
49 uint32_t out_of_range; /* inputs refused before the chip */
50 uint32_t last_marker, last_semaphore;
51 uint64_t elapsed_ns; /* sum over chip executions */
52 int zero_libcuda_linkage, zero_cuda_symbols, zero_libcuda_runtime;
53 int have_kernel;
54 uint8_t kernel_digest[32];
55 size_t kernel_insns;
56 OmegaBlackwellKernel kernel;
57 OmegaMatMulSpec spec;
58} GpuSkillLedger;
59
60static GpuSkillLedger g_gpu;
61
62static __attribute__((unused)) int gpu_sk_init(void) {
63 memset(&g_gpu, 0, sizeof g_gpu);
64 g_gpu.zero_libcuda_linkage = g_gpu.zero_cuda_symbols = g_gpu.zero_libcuda_runtime = 1;
65 if (omega_matmul_spec_init(&g_gpu.spec, GPU_SK_DIM, GPU_SK_K, GPU_SK_DIM,
66 OMEGA_MATMUL_PRECISION_INT32) != 0)
67 return -1;
68 if (omega_blackwell_codegen_matmul(&g_gpu.spec, &g_gpu.kernel) != 0) return -2;
69 memcpy(g_gpu.kernel_digest, g_gpu.kernel.code_digest, 32);
70 g_gpu.kernel_insns = g_gpu.kernel.insn_count;
71 g_gpu.have_kernel = 1;
72 return 0;
73}
74
75static __attribute__((unused)) void gpu_sk_free(void) {
76 if (g_gpu.have_kernel) omega_blackwell_kernel_free(&g_gpu.kernel);
77 g_gpu.have_kernel = 0;
78}
79
80static uint64_t gpu_sk_affine(int which, uint64_t x, uint32_t w0, uint32_t w1, int *failed) {
81 *failed = 1;
82 if (!g_gpu.have_kernel) { g_gpu.failures++; return 0; }
83 if (x > (UINT32_MAX - w1) / w0) { g_gpu.out_of_range++; return 0; }
84 uint32_t a[GPU_SK_DIM * GPU_SK_K], b[GPU_SK_K * GPU_SK_DIM], c[GPU_SK_DIM * GPU_SK_DIM];
85 memset(a, 0, sizeof a);
86 memset(b, 0, sizeof b);
87 a[0] = (uint32_t)x;
88 a[1] = 1;
89 b[0] = w0; /* B[0][0] */
90 b[GPU_SK_DIM] = w1; /* B[1][0] */
91 OmegaBlackwellMatMulExecution ex;
92 memset(&ex, 0, sizeof ex);
93 int rc = omega_blackwell_execute_matmul(&g_gpu.spec, &g_gpu.kernel, a, b, c, &ex);
94 g_gpu.last_marker = ex.completion_marker;
95 g_gpu.last_semaphore = ex.intermediate_semaphore;
96 if (!ex.zero_libcuda_linkage) g_gpu.zero_libcuda_linkage = 0;
97 if (!ex.zero_cuda_symbols) g_gpu.zero_cuda_symbols = 0;
98 if (!ex.zero_libcuda_runtime) g_gpu.zero_libcuda_runtime = 0;
99 if (rc != 0 || !ex.parity_verified || ex.completion_marker != OMEGA_BW_MARKER_COMPLETION_PAYLOAD ||
100 ex.intermediate_semaphore != OMEGA_BW_SEMAPHORE_INTERMEDIATE_DONE) {
101 g_gpu.failures++;
102 return 0;
103 }
104 g_gpu.runs[which]++;
105 g_gpu.elapsed_ns += ex.elapsed_ns;
106 *failed = 0;
107 return c[0];
108}
109
110static __attribute__((unused)) uint64_t gpu_sk_a(const uint64_t *in, uint32_t n, uint32_t attempt, int *failed) {
111 (void)attempt;
112 return gpu_sk_affine(0, n ? in[0] : 0, 3, fx_a_bad ? 2 : 1, failed);
113}
114static __attribute__((unused)) uint64_t gpu_sk_b(const uint64_t *in, uint32_t n, uint32_t attempt, int *failed) {
115 (void)attempt;
116 return gpu_sk_affine(1, n ? in[0] : 0, 3, fx_b_bad ? 6 : 1, failed);
117}
118
119#endif