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 / tools-om / own30b_diff.c

103 lines · 4835 bytes Raw Blame History
1/* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */
2/* Differential driver for tools/own30b_decode_profile.c. Built twice from the same source: with
3 * -DCUDAPP_MIGRATION_PENDING_C_TOOLS_OWN30B (the C oracle) and without (om/tools/own30b_prof.om). Both builds read
4 * the same splitmix64 stream, print every classification to stdout, and dump the profile to stderr at exit; the
5 * two outputs must be byte-identical.
6 *
7 * usage: own30b_diff SEED TOKENS MUT_PER_MILLE
8 * TOKENS decode steps are driven; each record is mutated with probability MUT_PER_MILLE / 1000 (wrong or
9 * other stage, failed launch, null launch, random shape, wrapped clock, huge byte count). With
10 * MUT_PER_MILLE >= 100 every 64th classification also uses a fully random launch. TOKENS above 4096
11 * exercises the dropped counter. */
12#define OWN30B_PROFILE_DIFF 1
13#include "../../tools/own30b_decode_profile.c"
14#include <stdlib.h>
15
16static uint64_t rng;
17static uint64_t next(void) {
18 uint64_t z = (rng += 0x9e3779b97f4a7c15ull);
19 z = (z ^ (z >> 30)) * 0xbf58476d1ce4e5b9ull;
20 z = (z ^ (z >> 27)) * 0x94d049bb133111ebull;
21 return z ^ (z >> 31);
22}
23
24static uint32_t args[32];
25static OmegaGpuLaunch L;
26
27/* A launch that the profile should classify as stage s. */
28static void shape(int s) {
29 memset(args, 0, sizeof args);
30 memset(&L, 0, sizeof L);
31 L.args = args;
32 switch (s) {
33 case QKV: L.n_args = OMEGA_FP8_ARGS_WORDS; L.grid_y = 1; args[8] = 5120 * 4 + (uint32_t)(next() & 3); break;
34 case O: L.n_args = OMEGA_FP8_ARGS_WORDS; L.grid_y = 1; args[8] = 2048 * 4 + (uint32_t)(next() & 3); break;
35 case GU: L.n_args = OMEGA_FP8_ARGS_WORDS; L.grid_y = 8; args[8] = 1536 * 4; break;
36 case DOWN: L.n_args = OMEGA_FP8_ARGS_WORDS; L.grid_y = 8; args[8] = 2048 * 4; break;
37 case ATTN: L.n_args = OMEGA_DATTN_ARGS_WORDS; L.num_elements = 4096; args[18] = (next() & 1) ? (uint32_t)next() : (uint32_t)(next() & 4095); break;
38 case ROUTER: L.n_args = OMEGA_ROUTER_ARGS_WORDS; L.num_elements = 2048; break;
39 case HEAD: L.n_args = OMEGA_BF16_ARGS_WORDS; L.num_elements = 151936; break;
40 default: L.n_args = 3; break;
41 }
42}
43
44/* A launch with every classified field drawn from the boundary sets or at random. */
45static void wild(void) {
46 static const uint32_t na[] = { OMEGA_FP8_ARGS_WORDS, OMEGA_DATTN_ARGS_WORDS, OMEGA_ROUTER_ARGS_WORDS, OMEGA_BF16_ARGS_WORDS, 0, 9, 11, 24, 26, 32 };
47 static const uint32_t a8[] = { 5120 * 4, 2048 * 4, 1536 * 4, 2048 * 4 + 3, 5120 * 4 - 1, 1536 * 4 + 4, 0, 0xffffffffu };
48 static const uint32_t gy[] = { 0, 1, 2, 7, 8, 9, 0xffffffffu };
49 static const size_t ne[] = { 4096, 2048, 151936, 0, 4095, 2049, 151937, (size_t)-1 };
50 memset(&L, 0, sizeof L);
51 for (int i = 0; i < 32; i++) args[i] = (uint32_t)next();
52 L.args = (next() & 15) ? args : NULL;
53 L.n_args = (next() & 7) ? na[next() % 10] : (uint32_t)(next() & 31);
54 args[8] = (next() & 3) ? a8[next() % 8] : (uint32_t)next();
55 L.grid_y = (next() & 3) ? gy[next() % 7] : (uint32_t)next();
56 L.num_elements = (next() & 3) ? ne[next() % 8] : (size_t)next();
57}
58
59static uint64_t clk;
60static unsigned nclass;
61
62static void step(int want, unsigned mut) {
63 int s = want, rc = 0, nul = 0;
64 uint64_t bytes, begin, end, elapsed, extra = 0;
65 if (mut >= 100 && ++nclass % 64 == 0) wild(); else shape(want);
66 if (mut && next() % 1000 < mut) {
67 switch (next() % 8) {
68 case 0: shape((int)(next() % 8)); break;
69 case 1: shape(OTHER); break;
70 case 2: rc = (next() & 1) ? -1 : (int)(next() % 200) + 1; break;
71 case 3: nul = 1; break;
72 case 4: wild(); break;
73 case 5: clk -= next() % 100000; break;
74 case 6: extra = next(); break;
75 default: clk = next(); break;
76 }
77 }
78 s = classify(nul ? NULL : &L, &bytes);
79 printf("C %d %" PRIu64 "\n", s, bytes);
80 begin = clk + next() % 5000;
81 end = begin + next() % 200000;
82 if (extra && (extra & 1)) end = begin - (extra >> 40);
83 elapsed = (next() & 255) ? next() % 150000 : next();
84 record(s, bytes + (extra ? extra : 0), begin, end, elapsed, rc);
85 clk = end;
86}
87
88int main(int argc, char **argv) {
89 if (argc != 4) { fprintf(stderr, "usage: own30b_diff SEED TOKENS MUT_PER_MILLE\n"); return 2; }
90 rng = strtoull(argv[1], NULL, 0);
91 unsigned long toks = strtoul(argv[2], NULL, 0);
92 unsigned mut = (unsigned)strtoul(argv[3], NULL, 0);
93 clk = next() >> (next() & 63);
94 step(HEAD, 0);
95 for (unsigned long t = 0; t < toks; t++) {
96 for (unsigned i = 0; i < 288; i++) step((int)(i % 6), mut);
97 step(HEAD, mut);
98 /* Occasionally record without a head first, or a stray launch between steps. */
99 if (mut && next() % 50 == 0) step((int)(next() % 8), mut);
100 }
101 printf("RETAINED %" PRIu64 "\n", prof_used());
102 return 0;
103}