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

70 lines · 3317 bytes Raw Blame History
1/* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */
2#ifdef BW_SPEC_NATIVE_PROBE
3#include "omega_native.h"
4#include <stdio.h>
5int main(void) {
6 for (uint64_t mode = 0; mode < 3; ++mode) {
7 uint64_t result = UINT64_MAX;
8 uint32_t status = omega_sp_native_probe(&result, mode);
9 if (status != 0 || result != mode) {
10 fprintf(stderr, "native spec probe mode %llu: status %u result %llu\n",
11 (unsigned long long)mode, status, (unsigned long long)result);
12 return 1;
13 }
14 }
15 puts("PASS: generated function binding, private state, semantic mutant=1, raw refusal=2");
16 return 0;
17}
18#else
19/*
20 * bw_encode_control_test: every opcode the encoder accepts must carry the control word the emitter scheduled
21 * (BlackwellIRInsn.control: stall, yield, write / read scoreboards, wait mask) into the instruction's top word
22 * (omega-mv#545, 2026-10-18). The encoder's golden-word checks compare words 0..2 only, so an opcode that wrote a
23 * fixed word 3 kept its own wait mask and dropped the emitter's: IADD3 always waited on scoreboard 4 instead of the
24 * Q loads' scoreboards, the next MOVs overwrote the loads' address registers while loads were still queued, and the
25 * prefill attention faulted (Xid 13, Invalid Address Space) on the chip.
26 *
27 * Host only, no device. Exit 0 when every accepted opcode honours the control word.
28 */
29#include "omega_blackwell_codegen.h"
30#include <stdio.h>
31#include <string.h>
32
33#define CTL_FIELD 0x03fffe00u /* stall 9..12, yield 13, wbar 14..16, rbar 17..19, wait 20..25 */
34
35static const uint32_t sentinels[] = {
36 (3u << 9) | (5u << 14) | (4u << 17) | (0x2au << 20), /* stall 3, wbar 5, rbar 4, wait 0x2a */
37 (12u << 9) | 0x2000u | (2u << 14) | (7u << 17) | (0x15u << 20), /* stall 12, yield, wbar 2, rbar none, wait 0x15 */
38};
39
40int main(void) {
41 int checked = 0, refused = 0, bad = 0;
42 for (int op = 0; op <= (int)BW_IR_ATOMG_MIN_U64_STRONG_SYS; op++) {
43 for (int form = 0; form < 4; form++) {
44 const int pred = form & 1, uni = form >> 1;
45 int accepted_any = 0;
46 for (unsigned s = 0; s < sizeof sentinels / sizeof sentinels[0]; s++) {
47 BlackwellIRInsn in;
48 memset(&in, 0, sizeof in);
49 in.op = (BlackwellIROpcode)op;
50 in.dst_vreg = 4; in.src1_vreg = 6; in.src2_vreg = 8; in.src3_vreg = 10; in.ureg = 4;
51 in.imm = 2; in.predicate_p0 = pred != 0; in.is_uniform = uni != 0;
52 in.control = sentinels[s];
53 uint32_t w[4] = { 0, 0, 0, 0 };
54 if (omega_blackwell_encode_one(&in, w) != 0) continue;
55 accepted_any = 1;
56 checked++;
57 if ((w[3] & CTL_FIELD) != (sentinels[s] & CTL_FIELD)) {
58 bad++;
59 printf("FAIL: op %d%s%s: control 0x%08x encoded as 0x%08x\n", op, pred ? " (@P0)" : "", uni ? " (uniform)" : "", sentinels[s], w[3]);
60 }
61 }
62 if (!accepted_any && form == 0) refused++;
63 }
64 }
65 printf("bw_encode_control_test: %d encodings checked, %d opcodes refused (no operands), %d dropped the control word: %s\n",
66 checked, refused, bad, bad ? "FAIL" : "PASS");
67 return bad ? 1 : 0;
68}
69
70#endif