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 / gpu_tc_peak_test.c

100 lines · 8180 bytes Raw Blame History
1/* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */
2/* gpu_tc_peak_test.c (OWN-30B T3, 2026-10-13): tensor-core throughput ceiling on GB10 (HMMA.16816.F32.BF16).
3 * --host-only the generator in the warp simulator: every accumulator 16 * iters
4 * (default) the chip (caller holds flock /tmp/aien-gb10.lock): a sweep of issue stall x accumulator chains x warps x CTAs;
5 * each point checks every stored value (16 * iters) and reports TFLOPS = 4096 flop per HMMA / chip time
6 * (median of 5). Halving the chains must roughly halve the time when the tensor pipe is the limit.
7 * Verdict line last: "GPU_TC_PEAK: PASS|FAIL". */
8#include "omega_blackwell_codegen_tc.h"
9#include "omega_gpu_session.h"
10#include "bw_warp_sim_tc.h"
11#include <stdio.h>
12#include <stdlib.h>
13#include <string.h>
14
15static int cmp_u64(const void *a, const void *b) { uint64_t x = *(const uint64_t *)a, y = *(const uint64_t *)b; return x < y ? -1 : x > y; }
16
17static int host_only(void) {
18 static BlackwellIRProgram p; int fail = 0;
19 for (uint32_t chains = 8; chains <= 16; chains += 8) {
20 if (omega_blackwell_codegen_tc_peak_prog(5, chains, 2, 64, &p) != 0) { printf("codegen refused chains %u\n", chains); return 1; }
21 static float out[2 * 64 * 64]; for (size_t i = 0; i < sizeof out / 4; i++) out[i] = -1;
22 static WsSim s; memset(&s, 0, sizeof s); s.p = &p; s.threads = 64;
23 uint64_t va = (uintptr_t)out; s.cbank[0x380 / 4] = (uint32_t)va; s.cbank[0x384 / 4] = (uint32_t)(va >> 32);
24 s.ranges[0].lo = va; s.ranges[0].hi = va + 2u * 64u * 16u * chains; s.nranges = 1;
25 int err = ws_run(&s, 2, 1); size_t bad = 0;
26 for (size_t i = 0; i < 2u * 64u * 4u * chains; i++) if (out[i] != 80.0f) bad++;
27 printf("sim chains %u: %s, peak %u registers, %zu instructions, %zu wrong\n", chains, err ? s.msg : "ran", p.regalloc.peak_gpr_usage, p.count, bad);
28 if (err || bad) fail++;
29 }
30 return fail;
31}
32
33int main(int argc, char **argv) {
34 int fail = host_only();
35 if (argc > 1 && !strcmp(argv[1], "--host-only")) { printf("GPU_TC_PEAK: %s\n", fail ? "FAIL" : "PASS"); return fail ? 1 : 0; }
36 if (fail) { printf("GPU_TC_PEAK: FAIL\n"); return 1; }
37 static const struct { uint32_t stall, chains, threads, ctas; } pts[] = {
38 { 8, 16, 128, 192 }, { 4, 16, 128, 192 }, { 2, 16, 128, 192 }, { 2, 8, 128, 192 },
39 { 2, 16, 256, 192 }, { 2, 16, 128, 384 }, { 2, 16, 512, 96 }, { 4, 8, 256, 384 }, { 1, 16, 256, 384 },
40 };
41 const uint32_t iters = 4096;
42 omega_gpu_session_lock();
43 if (!omega_gpu_session_open()) { printf("open failed: %s\n", omega_gpu_session_last_error()); omega_gpu_session_unlock(); return 1; }
44 for (size_t i = 0; i < sizeof pts / sizeof pts[0]; i++) {
45 static BlackwellIRProgram p; OmegaGpuMem code = { 0 }, out = { 0 }; OmegaBlackwellKernel k;
46 if (omega_blackwell_codegen_tc_peak_prog(iters, pts[i].chains, pts[i].stall, pts[i].threads, &p) != 0) { printf("codegen refused\n"); fail++; continue; }
47 size_t need = omega_bw_program_code_bytes(&p), ob = (size_t)pts[i].ctas * pts[i].threads * 16u * pts[i].chains;
48 uint32_t decl = omega_bw_gpr_declared(p.regalloc.peak_gpr_usage);
49 if (omega_gpu_session_alloc_code(need, &code) != 0 || omega_blackwell_kernel_encode_into(&p, code.cpu, need, &k) != 0 || omega_gpu_session_sync_to_gpu(&code) != 0 ||
50 omega_gpu_session_alloc(ob, &out) != 0) { printf("upload failed: %s\n", omega_gpu_session_last_error()); fail++; break; }
51 uint64_t ns[5]; int ok = 1; size_t bad = 0;
52 for (int r = 0; r < 5 && ok; r++) {
53 ns[r] = 0; /* omega_gpu_session_launch adds the elapsed time */
54 float *o = out.cpu; for (size_t q = 0; q < ob / 4; q++) o[q] = -1.0f;
55 uint32_t args[2] = { (uint32_t)out.va, (uint32_t)(out.va >> 32) };
56 OmegaGpuLaunch L = { .code_va = code.va, .gpr_count = decl, .threads_x = pts[i].threads, .threads_y = 1, .grid_x = pts[i].ctas, .grid_y = 1,
57 .num_elements = ob / 4, .args = args, .n_args = 2, .timeout_ms = 20000 };
58 if (omega_gpu_session_sync_to_gpu(&out) != 0 || omega_gpu_session_launch(&L, &ns[r], NULL) != 0 || omega_gpu_session_sync_to_cpu(&out) != 0) { printf("launch failed: %s\n", omega_gpu_session_last_error()); ok = 0; break; }
59 for (size_t q = 0; q < ob / 4; q++) if (o[q] != 16.0f * iters) bad++;
60 }
61 if (!ok) { fail++; omega_gpu_session_free(&code); omega_gpu_session_free(&out); break; }
62 qsort(ns, 5, 8, cmp_u64);
63 double hm = (double)pts[i].ctas * (pts[i].threads / 32u) * iters * pts[i].chains;
64 printf("peak stall %u chains %u threads %u ctas %u (declared %u): median %.1f us, %.2f TFLOPS, %zu wrong values\n", pts[i].stall, pts[i].chains, pts[i].threads, pts[i].ctas, decl,
65 ns[2] / 1e3, hm * 4096.0 / ns[2] / 1e3, bad);
66 if (bad) fail++;
67 omega_gpu_session_free(&code); omega_gpu_session_free(&out);
68 }
69 /* read bandwidth: every CTA distinct vs every CTA the same bytes (any cache reuse of these GPU-uncached buffers) */
70 for (int mode = 0; mode < 4 && !fail; mode++) {
71 const uint32_t T = 256, grid = 384, iters = mode < 2 ? 32u : 8u, groups = (mode & 1) ? 1u : grid;
72 static BlackwellIRProgram p; OmegaGpuMem code = { 0 }, src = { 0 }, out = { 0 }; OmegaBlackwellKernel k;
73 if (omega_blackwell_codegen_tc_bw_prog(iters, groups, T, &p) != 0) { printf("bw codegen refused\n"); fail++; break; }
74 size_t need = omega_bw_program_code_bytes(&p), region = (size_t)iters * T * 128u, sb = region * groups, ob = (size_t)grid * T * 4u;
75 if (omega_gpu_session_alloc_code(need, &code) != 0 || omega_blackwell_kernel_encode_into(&p, code.cpu, need, &k) != 0 || omega_gpu_session_sync_to_gpu(&code) != 0 ||
76 omega_gpu_session_alloc(sb, &src) != 0 || omega_gpu_session_alloc(ob, &out) != 0) { printf("bw upload failed: %s\n", omega_gpu_session_last_error()); fail++; break; }
77 uint32_t *sw = src.cpu; for (size_t q = 0; q < sb / 4; q++) sw[q] = (uint32_t)(q * 2654435761u);
78 uint32_t *want = calloc((size_t)grid * T, 4);
79 for (uint32_t c = 0; c < grid; c++) for (uint32_t t = 0; t < T; t++) { uint32_t a = 0; const uint32_t *r = sw + (size_t)(groups == 1 ? 0 : c) * region / 4;
80 for (uint32_t it = 0; it < iters; it++) for (uint32_t q = 0; q < 8; q++) for (uint32_t s = 0; s < 4; s++) a ^= r[((size_t)it * T * 128u + (size_t)q * T * 16u + t * 16u) / 4 + s];
81 want[(size_t)c * T + t] = a; }
82 uint64_t ns[5]; size_t bad = 0; int ok = 1;
83 if (omega_gpu_session_sync_to_gpu(&src) != 0) ok = 0;
84 for (int r = 0; r < 5 && ok; r++) {
85 ns[r] = 0; uint32_t *o = out.cpu; memset(o, 0xee, ob);
86 uint32_t args[4] = { (uint32_t)src.va, (uint32_t)(src.va >> 32), (uint32_t)out.va, (uint32_t)(out.va >> 32) };
87 OmegaGpuLaunch L = { .code_va = code.va, .gpr_count = omega_bw_gpr_declared(p.regalloc.peak_gpr_usage), .threads_x = T, .threads_y = 1, .grid_x = grid, .grid_y = 1,
88 .num_elements = ob / 4, .args = args, .n_args = 4, .timeout_ms = 20000 };
89 if (omega_gpu_session_sync_to_gpu(&out) != 0 || omega_gpu_session_launch(&L, &ns[r], NULL) != 0 || omega_gpu_session_sync_to_cpu(&out) != 0) { printf("bw launch failed: %s\n", omega_gpu_session_last_error()); ok = 0; break; }
90 for (size_t q = 0; q < (size_t)grid * T; q++) if (o[q] != want[q]) bad++;
91 }
92 if (ok) { qsort(ns, 5, 8, cmp_u64); double bytes = (double)grid * region;
93 printf("bw %s, %zu KB per CTA, %u CTAs: median %.1f us, %.1f GB/s delivered (%zu MB distinct), %zu wrong\n", groups == 1 ? "SAME bytes for every CTA" : "distinct bytes per CTA", region >> 10, grid, ns[2] / 1e3, bytes / ns[2], sb >> 20, bad);
94 if (bad) fail++; } else fail++;
95 free(want); omega_gpu_session_free(&code); omega_gpu_session_free(&src); omega_gpu_session_free(&out);
96 }
97 omega_gpu_session_unlock();
98 printf("GPU_TC_PEAK: %s\n", fail ? "FAIL" : "PASS");
99 return fail ? 1 : 0;
100}