Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/tests/test_omega_gpu_engine_gb10.c # 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 Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / tests / test_omega_gpu_engine_gb10.c` 184 lines ยท 7051 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 * Phase B only: needs the GB10, queen's go, quiet flag via chip_run; never run in Phase A. 19 * 20 * Chip test of the Omega GPU Engine (docs/numeric/OMEGA_GPU_ENGINE.md), cut A3b2. 21 * Phase A only COMPILES it (make test-gpu-engine-gb10-compile). It was written 22 * against the real API (src/omega_gpu_engine.h, src/omega_blackwell_submit.h) and 23 * never compiled or executed by its author. It is a fresh rewrite: the first-cut 24 * test by GPT-6 Astra (commit `21392ee` on fix/omega-gpu-engine-first-cut) used an 25 * older API, so it served as the outline only. 26 * 27 * What it does with --chip on the GB10, through tools/chip_run.sh and 28 * tools/manifests/gpu_engine.chiprun: 29 * 1. Runs omega_blackwell_execute_vector (engine core + Blackwell backend + the 30 * real driver) for element counts 1, 63, 64, 65, 4096 and 65537, ten times 31 * each. One extra pattern per size uses a[i] = 0xdeadbeef, b[i] = 0 (a sum 32 * that equals the old constant poison word, which must not fool the engine). 33 * 2. Negative control: the vector program with its one store instruction 34 * replaced by the instruction after it (an EXIT), so no lane writes. The 35 * engine must report OUTPUT_UNCHANGED for all 65 words, after the run 36 * completed and the output became visible, with nothing retained and no 37 * cleanup failure. The offsets are the fixture locations in 38 * src/omega_blackwell_encoder.c (0x120 store, 0x130 exit). 39 * Verdict lines (the only lines chip_run reads): "GPU_ENGINE: PASS" or 40 * "GPU_ENGINE: FAIL"; without --chip it prints "GPU_ENGINE: NOT_RUN ..." and 41 * exits 2. An uncertain completion blocks the process by design: this test then 42 * parks instead of exiting, because exiting would close the device under a GPU 43 * that may still be running. 44 */ 45 #include "omega_gpu_engine.h" 46 #include "omega_blackwell_engine.h" 47 #include "omega_blackwell_submit.h" 48 #include "omega_blackwell_encoder.h" 49 #include "omega_blackwell_realize.h" 50 #include "omega_vector.h" 51 52 #include 53 #include 54 #include 55 #include 56 #include 57 58 #define REPEATS 10u 59 60 /* An uncertain completion leaves the context and the device memory alive on 61 * purpose. Never exit in that state. */ 62 static void park_if_blocked(void) 63 { 64 if (!omega_gpu_engine_is_blocked()) return; 65 fprintf(stderr, "GPU_ENGINE_BLOCKED uncertain completion, parking (do not close the device)\n"); 66 puts("GPU_ENGINE: FAIL"); 67 fflush(stdout); 68 for (;;) pause(); 69 } 70 71 static int run_size(uint32_t n, int deadbeef) 72 { 73 OmegaVectorSpec spec; 74 OmegaBlackwellRealization real; 75 OmegaBlackwellVectorExecution info; 76 uint32_t *a = (uint32_t *)malloc((size_t)n * 4u); 77 uint32_t *b = (uint32_t *)malloc((size_t)n * 4u); 78 uint32_t *c = (uint32_t *)malloc((size_t)n * 4u); 79 uint32_t i; 80 unsigned rep; 81 int ok = (a && b && c); 82 83 memset(&spec, 0, sizeof spec); 84 memset(&real, 0, sizeof real); 85 real.sm_architecture = OMEGA_BW_SM_ARCH_121; 86 if (ok && omega_vector_spec_init(&spec, "engine_chip", n) != 0) ok = 0; 87 for (i = 0; ok && i < n; i++) { 88 a[i] = deadbeef ? 0xdeadbeefu : (uint32_t)(i * 2654435761u + 1u); 89 b[i] = deadbeef ? 0u : (uint32_t)(i * 40503u + 7u); 90 } 91 for (rep = 0; ok && rep < REPEATS; rep++) { 92 int rc; 93 memset(c, 0, (size_t)n * 4u); 94 memset(&info, 0, sizeof info); 95 rc = omega_blackwell_execute_vector(&spec, &real, a, b, c, &info); 96 park_if_blocked(); 97 if (rc != 0 || !info.parity_verified) { 98 fprintf(stderr, "vector run failed n=%u deadbeef=%d repeat=%u rc=%d\n", n, deadbeef, rep, rc); 99 ok = 0; 100 } 101 } 102 free(a); 103 free(b); 104 free(c); 105 return ok; 106 } 107 108 static int no_store_control(void) 109 { 110 uint8_t code[OMEGA_BW_VECADD_CODE_SIZE]; 111 size_t code_bytes = 0; 112 uint32_t a[65], b[65], out[65], poison[65]; 113 OmegaGpuJob job; 114 OmegaGpuResult res; 115 uint32_t i; 116 int rc; 117 118 if (omega_blackwell_verify_encoder_fixtures() != 0) return 0; 119 if (omega_blackwell_encode_vecadd(code, sizeof code, &code_bytes) != 0 || code_bytes < 0x140u) return 0; 120 /* Replace only the store with the exit that follows it. */ 121 memcpy(code + 0x120, code + 0x130, OMEGA_BW_INSTRUCTION_BYTES); 122 for (i = 0; i < 65u; i++) { 123 a[i] = i + 1u; 124 b[i] = 3u * i; 125 poison[i] = ~(a[i] + b[i]); 126 } 127 memset(out, 0, sizeof out); 128 memset(&job, 0, sizeof job); 129 job.program = code; 130 job.program_len = code_bytes; 131 job.layout = OMEGA_GPU_LAYOUT_VECTOR_1D; 132 job.element_count = 65u; 133 job.input_a = a; 134 job.input_a_len = sizeof a; 135 job.input_b = b; 136 job.input_b_len = sizeof b; 137 job.output = out; 138 job.output_len = sizeof out; 139 job.poison = poison; 140 job.poison_count = 65u; 141 job.timeouts.marker_ms = 5000; 142 job.timeouts.release_semaphore_ms = 5000; 143 job.timeouts.marker2_ms = 5000; 144 job.timeouts.visibility_ms = 5000; 145 job.flags = 0; 146 147 omega_gpu_engine_set_backend(omega_blackwell_engine_backend()); 148 rc = omega_gpu_execute(&job, &res); 149 park_if_blocked(); 150 if (rc != OMEGA_GPU_ENGINE_OUTPUT_UNCHANGED || res.last_state != OMEGA_GPU_ENGINE_STATE_OUTPUT_VISIBLE || 151 res.n_outputs != 1u || res.output_unchanged_words[0] != 65u || res.cleanup_failed != 0 || 152 res.retained != 0) { 153 fprintf(stderr, "no-store control failed rc=%d state=%d unchanged=%llu cleanup_failed=%d retained=%d\n", 154 rc, res.last_state, (unsigned long long)res.output_unchanged_words[0], 155 res.cleanup_failed, res.retained); 156 return 0; 157 } 158 return 1; 159 } 160 161 int main(int argc, char **argv) 162 { 163 static const uint32_t sizes[] = {1u, 63u, 64u, 65u, 4096u, 65537u}; 164 size_t s; 165 unsigned runs = 0; 166 int failed = 0; 167 168 if (argc < 2 || strcmp(argv[1], "--chip") != 0) { 169 puts("GPU_ENGINE: NOT_RUN (pass --chip; needs the GB10, via tools/chip_run.sh)"); 170 return 2; 171 } 172 for (s = 0; !failed && s < sizeof sizes / sizeof sizes[0]; s++) { 173 if (!run_size(sizes[s], 0) || !run_size(sizes[s], 1)) failed = 1; 174 else runs += 2u * REPEATS; 175 } 176 if (!failed && !no_store_control()) failed = 1; 177 if (failed) { 178 puts("GPU_ENGINE: FAIL"); 179 return 1; 180 } 181 printf("GPU_ENGINE_CASES vector_runs=%u no_store_control=detected\n", runs); 182 puts("GPU_ENGINE: PASS"); 183 return 0; 184 }