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_bw_qmd_shared.c

80 lines · 4796 bytes Raw Blame History
1/* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */
2/* test_omega_bw_qmd_shared: the shared-memory field of the Blackwell QMD (word 36), host only.
3 *
4 * Word 36 carries NVCEC0_QMDV05_00_SHARED_MEMORY_SIZE_SHIFTED7 (clcec0qmd.h, MW(1162:1152)): 11
5 * bits in units of 128 bytes. Next to it sit MIN_/MAX_/TARGET_SM_CONFIG_SHARED_MEM_SIZE (6 bits
6 * each), which this builder keeps at its fixed values 9 / 26 / 9 (32 KiB / 100 KiB / 32 KiB under
7 * Mesa NVK's size_kb / 4 + 1 rule). Checks:
8 * - 0 keeps the long-standing 1024 (field value 8); the cap itself is accepted;
9 * - the encoded value is size / 128 and never changes the SM-config fields;
10 * - one byte over the cap is refused, so the cap is a real gate (negative control) and not
11 * just a comment;
12 * - the production tensor-core FP8 grouped GEMM shape (rt 8 -> 32768 bytes) is inside the cap,
13 * which is why the cap moved from 16384 (gpu_pfgemm_test --chip failed at "qmd build
14 * (shared_bytes)" on every shape, 2026-10-25).
15 * No device is opened. */
16#include "omega_blackwell_qmd.h"
17#include <stdio.h>
18#include <string.h>
19
20static int g_checks, g_failed;
21#define CHECK(cond, ...) do { g_checks++; if (!(cond)) { g_failed++; printf("FAIL: "); printf(__VA_ARGS__); printf("\n"); } } while (0)
22
23#define FIELD_SHARED7(w) ((w) & 0x7ffu) /* MW(1162:1152) */
24#define FIELD_MIN(w) (((w) >> 11) & 0x3fu) /* MW(1168:1163) */
25#define FIELD_MAX(w) (((w) >> 17) & 0x3fu) /* MW(1174:1169) */
26#define FIELD_TARGET(w) (((w) >> 23) & 0x3fu) /* MW(1180:1175) */
27
28static OmegaBlackwellQmdConfig base(void) {
29 OmegaBlackwellQmdConfig c;
30 memset(&c, 0, sizeof c);
31 c.code_va = 0x100000; c.cbank_va = 0x200000; c.scratch_va = 0x300000; c.sem_va = 0x400000;
32 c.qmd0_va = 0x500000; c.qmd1_va = 0x600000;
33 c.num_elements = 128; c.threads_x = 128; c.grid_x = 1; c.gpr_count = 64;
34 return c;
35}
36
37/* Build one QMD for `shared` bytes; 0 when the builder accepted it, -1 when it refused. */
38static int build(uint32_t shared, uint32_t q[OMEGA_BW_QMD_WORDS]) {
39 OmegaBlackwellQmdConfig c = base();
40 c.shared_bytes = shared;
41 memset(q, 0, OMEGA_BW_QMD_BYTES);
42 return omega_blackwell_build_qmd1(q, &c) == 0 ? 0 : -1;
43}
44
45int main(void) {
46 uint32_t q[OMEGA_BW_QMD_WORDS], q_def[OMEGA_BW_QMD_WORDS];
47
48 if (build(0, q_def) != 0) { printf("FAIL: the default QMD was refused\n"); return 1; }
49 const uint32_t min = FIELD_MIN(q_def[36]), mx = FIELD_MAX(q_def[36]), target = FIELD_TARGET(q_def[36]);
50 printf("word 36 default: shared7 %u min %u max %u target %u\n", FIELD_SHARED7(q_def[36]), min, mx, target);
51 CHECK(FIELD_SHARED7(q_def[36]) == 8, "shared_bytes 0 keeps 1024 bytes (field 8), got %u", FIELD_SHARED7(q_def[36]));
52
53 /* Every size the builder accepts encodes size / 128 exactly and leaves the SM config alone. */
54 static const uint32_t sizes[] = { 1024, 4096, 16384, 32768 };
55 for (size_t i = 0; i < sizeof sizes / sizeof sizes[0]; i++) {
56 int rc = build(sizes[i], q);
57 CHECK(rc == 0, "%u bytes refused", sizes[i]);
58 if (rc) continue;
59 CHECK(FIELD_SHARED7(q[36]) == sizes[i] / 128u, "%u bytes encode as %u (want %u)", sizes[i], FIELD_SHARED7(q[36]), sizes[i] / 128u);
60 CHECK(FIELD_MIN(q[36]) == min && FIELD_MAX(q[36]) == mx && FIELD_TARGET(q[36]) == target,
61 "%u bytes left the SM config fields alone (min %u max %u target %u)", sizes[i], FIELD_MIN(q[36]), FIELD_MAX(q[36]), FIELD_TARGET(q[36]));
62 }
63
64 /* The rest of the descriptor must not move with the shared size: bytes 0..35 and 37.. are the
65 * same words as the 0-byte build (word 36 is the only shared-memory carrier). */
66 build(32768, q);
67 for (int w = 0; w < OMEGA_BW_QMD_WORDS; w++) if (w != 36) CHECK(q[w] == q_def[w], "word %d changed with the shared size", w);
68
69 /* Negative control: one byte over the cap is refused, and the same request rounded down to the
70 * cap is accepted, so the refusal is the cap and not something else. */
71 CHECK(build(OMEGA_BW_QMD_MAX_SHARED_BYTES + 1u, q) == -1, "%u bytes (cap + 1) was accepted", OMEGA_BW_QMD_MAX_SHARED_BYTES + 1u);
72 CHECK(build(OMEGA_BW_QMD_MAX_SHARED_BYTES, q) == 0, "the cap itself (%u bytes) was refused", OMEGA_BW_QMD_MAX_SHARED_BYTES);
73
74 /* The production FP8 grouped GEMM: omega_tc2_shared_bytes = 4096 * rt, rt 8 at the shipped shape. */
75 CHECK(4096u * 8u <= OMEGA_BW_QMD_MAX_SHARED_BYTES, "the tc2 production shape (rt 8, 32768 bytes) fits the cap %u", OMEGA_BW_QMD_MAX_SHARED_BYTES);
76 CHECK(FIELD_SHARED7(q_def[36]) * 128u <= OMEGA_BW_QMD_MAX_SHARED_BYTES, "the cap is inside what the 11-bit field can name");
77
78 printf("qmd shared: %d checks, %d failed: %s\n", g_checks, g_failed, g_failed ? "FAIL" : "PASS");
79 return g_failed ? 1 : 0;
80}