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

60 lines · 2559 bytes Raw Blame History
1/* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */
2#include "omega_gpu_om_ir.h"
3#include <stdio.h>
4#include <stdlib.h>
5#include <string.h>
6
7static uint32_t records(uint64_t *result, uint64_t kind, uint64_t limit, uint64_t b, uint64_t c,
8 void *words, uint64_t nw, void *metadata, uint64_t nm) {
9 uint64_t *w = words, *m = metadata;
10 (void)b; (void)c;
11 if (nw != OMEGA_OM_IR_WORDS || nm != OMEGA_OM_IR_META) return 1;
12 *result = 0;
13 m[6] = limit;
14 if (!kind) {
15 m[0] = 1;
16 w[0] = BW_IR_EXIT;
17 for (int i = 1; i <= 5; i++) w[i] = UINT64_MAX;
18 return 0;
19 }
20 m[1] = BW_PHYS_GPR_MAX;
21 m[0] = 2 * m[1];
22 for (uint64_t v = 0; v < m[1]; v++) {
23 m[64 + v] = 1;
24 uint64_t *d = w + v * 8, *u = w + (m[1] + v) * 8;
25 d[0] = BW_IR_MOV_IMM;
26 d[1] = v;
27 for (int i = 2; i <= 5; i++) d[i] = UINT64_MAX;
28 d[6] = v;
29 u[0] = BW_IR_MOV_RZ;
30 for (int i = 1; i <= 5; i++) u[i] = UINT64_MAX;
31 u[1] = v;
32 u[2] = v;
33 }
34 return 0;
35}
36
37int main(void) {
38 BlackwellIRProgram *p = malloc(sizeof(*p)), *old = malloc(sizeof(*old)), *zero = malloc(sizeof(*zero));
39 if (!p || !old || !zero) return 2;
40 const uint64_t bad[] = {1, BW_PHYS_GPR_MAX, BW_PHYS_GPR_HW_LIMIT + 1, UINT64_MAX,
41 (UINT64_C(1) << 32) | BW_PHYS_GPR_HW_LIMIT};
42 for (size_t i = 0; i < sizeof(bad) / sizeof(bad[0]); i++) {
43 memset(p, 0xa5, sizeof(*p));
44 memcpy(old, p, sizeof(*p));
45 if (omega_gpu_om_ir_replay(records, 0, bad[i], 0, 0, p, NULL) != OMEGA_OM_IR_REPLAY ||
46 memcmp(p, old, sizeof(*p))) return 3;
47 }
48 if (omega_gpu_om_ir_replay(records, 0, 0, 0, 0, p, NULL) || p->regalloc.gpr_limit) return 4;
49 memcpy(zero, p, sizeof(*p));
50 if (omega_gpu_om_ir_replay(records, 0, 0, 0, 0, p, NULL) || memcmp(p, zero, sizeof(*p))) return 5;
51 const uint64_t good[] = {BW_PHYS_GPR_MAX + 1, BW_PHYS_GPR_HW_LIMIT};
52 for (size_t i = 0; i < sizeof(good) / sizeof(good[0]); i++)
53 if (omega_gpu_om_ir_replay(records, 0, good[i], 0, 0, p, NULL) || p->regalloc.gpr_limit != good[i]) return 6;
54 if (omega_gpu_om_ir_replay(records, 1, 0, 0, 0, p, NULL) != OMEGA_OM_IR_REGALLOC) return 7;
55 if (omega_gpu_om_ir_replay(records, 1, BW_PHYS_GPR_HW_LIMIT, 0, 0, p, NULL) ||
56 p->regalloc.gpr_limit != BW_PHYS_GPR_HW_LIMIT) return 8;
57 free(p); free(old); free(zero);
58 puts("PASS replay-limit zero/default, boundaries, pre-mutation refusals, pressure");
59 return 0;
60}