interplane.Get Omega
Read in your language

CUDApp

CUDA++: AIEN’s GPU machine-code toolchain, runtime and driver client for NVIDIA GPUs without the CUDA toolkit. Hardware coverage and driver replacement limits are explicit.

Brought by drakestapleton

branch main Branches Tags History

CUDApp / tests / test_omega_gpu_engine_gb10.c

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