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

156 lines · 7274 bytes Raw Blame History
1/* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */
2/* Stand-ins for the 30 generators and the two encoders tools/ampere_families.c calls, linked into both
3 * builds (the seeded Omega shell and the CUDAPP_MIGRATION_PENDING_C_TOOLS_AMPFAM oracle) by
4 * tests/tools-om/ampfam.sh. Each call is appended to descriptor 3 when AMPFAM_TRACE_FD=3: the generator name and its
5 * specification byte for byte (or its scalar arguments), the SM121 buffer size, and the SM86 target, size
6 * and incoming length. $AMPFAM_CASE "K:KIND" changes the outcome at generator call K:
7 * g, g7 the generator returns 1, or -7
8 * r the SM121 encoder returns 1
9 * a0keep the SM121 encoder writes length 0 and the SM86 encoder leaves its length untouched
10 * rc1, rc0, rcm1, rcm2 the SM86 encoder returns 1, 0, -1, -2 (length as for a pass)
11 * bplus the SM86 length is one more than a pass (a + 1 for an encode step, 1 for a refusal)
12 * bkeep the SM86 encoder leaves its length untouched
13 * Without a case every step passes: an encode step gets rc 0 and the SM121 length, a refusal rc -2 and
14 * length 0. EXPECT is the source-derived plan of the 133 steps (E encode, R refuse); a wrong letter makes
15 * the oracle fail its baseline, so the table is checked by every run. */
16#include "omega_ampere_codegen.h"
17#include "omega_blackwell_codegen_attn256.h"
18#include "omega_blackwell_codegen_pattn256.h"
19#include "omega_blackwell_codegen_gdn.h"
20#include "omega_blackwell_codegen_tern.h"
21#include "omega_blackwell_codegen_attn.h"
22#include "omega_blackwell_codegen_bf16.h"
23#include "omega_blackwell_codegen_dec.h"
24#include "omega_blackwell_codegen_gemm.h"
25#include "omega_blackwell_codegen_moe2.h"
26#include "omega_blackwell_codegen_pattn.h"
27#include "omega_blackwell_codegen_pf.h"
28#include "omega_blackwell_codegen_pfhost.h"
29#include "omega_blackwell_codegen_qg.h"
30#include "omega_blackwell_codegen_qmma.h"
31#include "omega_blackwell_codegen_router.h"
32#include "omega_blackwell_codegen_tc.h"
33#include "omega_blackwell_codegen_tc2.h"
34#include <fcntl.h>
35#include <stdio.h>
36#include <stdlib.h>
37#include <string.h>
38#include <unistd.h>
39
40static const char EXPECT[] =
41 "EEEE" "RER" "EEEEEEEEEEEEEEEEE" "EERR" "EEEEEEEE" "RR" "RRRR"
42 "EEEEEEEEEEEEEEEER" "EEEEEEEEEEEEEEEER"
43 "EEERR" "REERR" "EEERR" "REERR" "EE"
44 "EEEEEEEEEE" "EEEEEEEEEE" "EEEEEEEEEE" "EEEEE";
45static unsigned call_no;
46static size_t last_a;
47
48static void trace(const char *fmt, ...) __attribute__((format(printf, 1, 2)));
49#include <stdarg.h>
50static void trace(const char *fmt, ...)
51{
52 const char *fd = getenv("AMPFAM_TRACE_FD");
53 if (!fd) return;
54 if (strcmp(fd, "3") != 0) abort();
55 va_list ap; va_start(ap, fmt); if (vdprintf(3, fmt, ap) < 0) abort(); va_end(ap);
56}
57
58static int case_is(const char *kind)
59{
60 const char *c = getenv("AMPFAM_CASE");
61 char want[32];
62 snprintf(want, sizeof(want), "%u:%s", call_no, kind);
63 return c && strcmp(c, want) == 0;
64}
65
66static char expect(void)
67{
68 if (call_no == 0 || call_no > sizeof(EXPECT) - 1) { fprintf(stderr, "stub: call %u past the plan\n", call_no); abort(); }
69 return EXPECT[call_no - 1];
70}
71
72static int generated(const char *name, const void *spec, size_t n)
73{
74 ++call_no;
75 trace("gen %u %s", call_no, name);
76 for (size_t i = 0; i < n; ++i) trace(" %02x", ((const unsigned char *)spec)[i]);
77 trace("\n");
78 if (case_is("g")) return 1;
79 if (case_is("g7")) return -7;
80 return 0;
81}
82
83#define SPEC(fn, type) int fn(const type *spec, BlackwellIRProgram *prog) { (void)prog; return generated(#fn, spec, sizeof(*spec)); }
84SPEC(omega_blackwell_codegen_bf16_gemv_prog, OmegaBf16GemvSpec)
85SPEC(omega_blackwell_codegen_decode_attn256_prog, OmegaDecodeAttn256Spec)
86SPEC(omega_blackwell_codegen_decode_attn_prog, OmegaDecodeAttnSpec)
87SPEC(omega_blackwell_codegen_dec_prog, OmegaDecSpec)
88SPEC(omega_blackwell_codegen_fp8gemm_prog, OmegaFp8GemmSpec)
89SPEC(omega_blackwell_codegen_fp8_gemv2_prog, OmegaFp8GemvSpec)
90SPEC(omega_blackwell_codegen_fp8_gemv_prog, OmegaFp8GemvSpec)
91SPEC(omega_blackwell_codegen_gdn_copy_prog, OmegaGdnSpec)
92SPEC(omega_blackwell_codegen_gdn_multi_prog, OmegaGdnSpec)
93SPEC(omega_blackwell_codegen_gdn_post_prog, OmegaGdnSpec)
94SPEC(omega_blackwell_codegen_gdn_prep_prog, OmegaGdnSpec)
95SPEC(omega_blackwell_codegen_gdn_prog, OmegaGdnSpec)
96SPEC(omega_blackwell_codegen_gdn_scan_prog, OmegaGdnSpec)
97SPEC(omega_blackwell_codegen_mc_prog, OmegaMcSpec)
98SPEC(omega_blackwell_codegen_pq_prog, OmegaPqSpec)
99SPEC(omega_blackwell_codegen_prefill_attn256_prog, OmegaPrefillAttn256Spec)
100SPEC(omega_blackwell_codegen_prefill_attn_prog, OmegaPrefillAttnSpec)
101SPEC(omega_blackwell_codegen_qgemm_prog, OmegaQgSpec)
102SPEC(omega_blackwell_codegen_rl_prog, OmegaRlSpec)
103SPEC(omega_blackwell_codegen_router_prog, OmegaRouterSpec)
104SPEC(omega_blackwell_codegen_tc2_prog, OmegaTc2Spec)
105SPEC(omega_blackwell_codegen_tcgemm_prog, OmegaTcGemmSpec)
106SPEC(omega_blackwell_codegen_tern_gemv_prog, OmegaTernGemvSpec)
107
108int omega_blackwell_codegen_pf_copy_prog(BlackwellIRProgram *prog) { (void)prog; return generated("pf_copy", "", 0); }
109int omega_blackwell_codegen_f2e4_probe_prog(BlackwellIRProgram *prog) { (void)prog; return generated("f2e4_probe", "", 0); }
110int omega_blackwell_codegen_tc_probe_prog(int mutant, BlackwellIRProgram *prog)
111{
112 (void)prog; return generated("tc_probe", &mutant, sizeof(mutant));
113}
114int omega_blackwell_codegen_qmma_probe_prog(int mutant, uint32_t wait_nops, BlackwellIRProgram *prog)
115{
116 (void)prog; int64_t v[2] = { mutant, wait_nops }; return generated("qmma_probe", v, sizeof(v));
117}
118int omega_blackwell_codegen_tc_bw_prog(uint32_t iters, uint32_t groups, uint32_t threads, BlackwellIRProgram *prog)
119{
120 (void)prog; uint32_t v[3] = { iters, groups, threads }; return generated("tc_bw", v, sizeof(v));
121}
122int omega_blackwell_codegen_tc_peak_prog(uint32_t iters, uint32_t chains, uint32_t stall, uint32_t threads, BlackwellIRProgram *prog)
123{
124 (void)prog; uint32_t v[4] = { iters, chains, stall, threads }; return generated("tc_peak", v, sizeof(v));
125}
126int omega_blackwell_codegen_qmma_peak_prog(uint32_t iters, uint32_t chains, uint32_t stall, uint32_t threads, BlackwellIRProgram *prog)
127{
128 (void)prog; uint32_t v[4] = { iters, chains, stall, threads }; return generated("qmma_peak", v, sizeof(v));
129}
130
131int omega_bw_encode_program(const BlackwellIRProgram *prog, uint8_t *code_buf, size_t max_len, size_t *out_len)
132{
133 (void)prog; (void)code_buf;
134 trace("ref %u max %zu in %zu\n", call_no, max_len, *out_len);
135 if (case_is("r")) return 1;
136 last_a = case_is("a0keep") ? 0 : 100 + call_no;
137 *out_len = last_a;
138 return 0;
139}
140
141int omega_gpu_encode_program_target(const BlackwellIRProgram *prog, uint32_t target_sm, uint8_t *code_buf,
142 size_t max_len, size_t *out_len)
143{
144 (void)prog; (void)code_buf;
145 trace("tgt %u sm %u max %zu in %zu\n", call_no, target_sm, max_len, *out_len);
146 int enc = expect() == 'E';
147 int rc = enc ? 0 : -2;
148 size_t b = enc ? last_a : 0;
149 if (case_is("rc1")) rc = 1;
150 if (case_is("rc0")) rc = 0;
151 if (case_is("rcm1")) rc = -1;
152 if (case_is("rcm2")) rc = -2;
153 if (case_is("bplus")) b = enc ? last_a + 1 : 1;
154 if (!case_is("bkeep") && !case_is("a0keep")) *out_len = b;
155 return rc;
156}