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 / src / omega_blackwell_qmd.h

72 lines · 3359 bytes Raw Blame History
1/* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */
2#ifndef OMEGA_BLACKWELL_QMD_H
3#define OMEGA_BLACKWELL_QMD_H
4
5#include <stdbool.h>
6#include <stddef.h>
7#include <stdint.h>
8
9#define OMEGA_BW_QMD_WORDS 96
10#define OMEGA_BW_QMD_BYTES (OMEGA_BW_QMD_WORDS * 4) /* 384 bytes */
11#define OMEGA_BW_CBANK_DRIVER_WORDS 224
12#define OMEGA_BW_CBANK_ARGS_WORDS 7
13#define OMEGA_BW_CBANK_MATMUL_ARGS_WORDS 10
14
15/* Epistemic classifications for QMD fields */
16typedef enum {
17 EPISTEMIC_DOCUMENTED = 1, /* NVIDIA open-gpu-kernel-modules / clcdc0qmd.h */
18 EPISTEMIC_OBSERVED = 2, /* Empirically verified on physical GB10 silicon */
19 EPISTEMIC_REVERSE_ENGINEERED = 3 /* Derived from Blackwell instruction trace */
20} OmegaEpistemicTier;
21
22typedef struct {
23 uint64_t code_va;
24 uint64_t cbank_va;
25 uint64_t scratch_va;
26 uint64_t sem_va;
27 uint64_t qmd0_va;
28 uint64_t qmd1_va;
29 uint32_t num_elements;
30 uint32_t threads_per_block;
31 uint32_t grid_width;
32 uint32_t threads_x;
33 uint32_t threads_y;
34 uint32_t grid_x;
35 uint32_t grid_y;
36 uint32_t gpr_count;
37 /* Shared memory per CTA in bytes (clcec0qmd.h SHARED_MEMORY_SIZE_SHIFTED7, 128-byte units).
38 * 0 keeps the long-standing 1024. At most OMEGA_BW_QMD_MAX_SHARED_BYTES: word 36 declares
39 * MIN_ and TARGET_SM_CONFIG_SHARED_MEM_SIZE 9 = 32 KB (mesa nak qmd.rs gv100_smem_size_to_hw:
40 * size_kb / 4 + 1; SM >= 120 configs 0, 8, 16, 32, 64, 100 KB, nouveau_device.c), and a CTA must fit
41 * the MIN config. Raised from 16 KiB for the bf16 GEMV at k 5120 (20 KiB of x, sc #642); above
42 * 32 KiB the MIN / TARGET fields must follow the size (not done yet: every launch keeps one word 36). */
43 uint32_t shared_bytes;
44} OmegaBlackwellQmdConfig;
45#define OMEGA_BW_QMD_MAX_SHARED_BYTES 32768u
46
47/* Build QMD 0: GRID_NULL null-barrier grid with dependence counter 2 */
48int omega_blackwell_build_qmd0(uint32_t *qmd0_words, uint64_t qmd0_va, uint64_t qmd1_va);
49
50/* Build QMD 1: GRID_CTA compute grid for Blackwell sm_121 vector add and matmul */
51int omega_blackwell_build_qmd1(uint32_t *qmd1_words, const OmegaBlackwellQmdConfig *cfg);
52
53/* Build driver constant bank 0 (224 words) with hardware descriptor addresses */
54int omega_blackwell_build_cbank_driver(uint32_t *cbank_words, uint64_t cbank_va);
55
56/* Build driver constant bank 0 (224 words) with 2D tile geometry */
57int omega_blackwell_build_cbank_driver_2d(uint32_t *cbank_words, uint64_t cbank_va,
58 uint32_t threads_x, uint32_t threads_y,
59 uint32_t grid_x, uint32_t grid_y);
60
61/* Build kernel argument constant bank buffer (7 words: pointers A, B, C, length N) */
62int omega_blackwell_build_cbank_args(uint32_t *args_words, uint64_t a_va, uint64_t b_va,
63 uint64_t c_va, uint32_t n);
64
65/* Build matrix multiplication kernel argument constant bank buffer (10 words) */
66int omega_blackwell_build_cbank_args_matmul(uint32_t *args_words, uint64_t a_va, uint64_t b_va,
67 uint64_t c_va, uint32_t m, uint32_t k, uint32_t n);
68
69/* Verify QMD structural invariants (SKEDCHECK05, version, alignment, etc.) */
70int omega_blackwell_verify_qmd_invariants(const uint32_t *qmd1_words);
71
72#endif /* OMEGA_BLACKWELL_QMD_H */