interplane.Get Omega
Read in your language

benchmarks-mv

Measurement harnesses and evidence bundles for AIEN on the NVIDIA DGX Spark GB10. Speed is reported against the machine's physical limit and my own previous run. Attachment of AienOS.

Brought by drakestapleton

branch main Branches Tags History

benchmarks-mv / prime-drag-race / evidence / 2026-10-05-campaign / c5 / eltwise / FB1-CUT4-c505e7f / omega_gpu_elementwise_api.h

145 lines · 7941 bytes Raw Blame History
1#ifndef OMEGA_GPU_ELEMENTWISE_API_H
2#define OMEGA_GPU_ELEMENTWISE_API_H
3/*
4 * omega_gpu_elementwise_api: native (no CUDA) elementwise and row-reduction
5 * kernels for the AIEN inference stack (FB-1 cut 4, 2026-10-04).
6 *
7 * Three inference ops plus two probe ops, every kernel generated by our own
8 * codegen (src/omega_blackwell_codegen.c IR) and launched through the same
9 * chip-proven sequence as the tensor matmul path: all buffers GPU-uncached
10 * (nvos.h NVOS32_ATTR2_GPU_CACHEABLE: system memory cached by the GPU is not
11 * coherent with CPU mappings), first marker, L2_FLUSH_DIRTY, second marker
12 * (C3 tail), poison-filled output scanned for unwritten words after readback.
13 *
14 * The math follows aien-sovereign-core crates/aien-inference-abi/src/tensor.rs
15 * (ReferenceCpuBackend), read 2026-10-04 at main 5fdab70:
16 * rmsnorm: scale = 1/sqrt(mean(x^2) + eps) (oracle sums in f64; the chip
17 * sums in f32 and uses MUFU.RSQ refined by one Newton step),
18 * out[i] = (x[i] * scale) * weight[i] in that order.
19 * rope: rotate_half pairs (i, i + head_dim/2) per head, cos/sin tables
20 * supplied by the host as f32 (the oracle casts f64 cos/sin to f32
21 * before the f32 math): out0 = q0*cos - q1*sin, out1 = q0*sin + q1*cos,
22 * emitted as FMUL, FMUL, FADD (no fused multiply-add), so the chip
23 * result is bit-identical to the f32 oracle.
24 * swiglu: out = silu(gate) * up, silu(g) = g / (1 + exp(-g)); the chip uses
25 * MUFU.EX2(g * -log2(e)) and MUFU.RCP (approximate units), the
26 * oracle computes in f64. Tolerance is stated per op in the test.
27 *
28 * Cut 4b (2026-10-04): the device, channel and launch scratch are the process-wide
29 * session shared with the matmul and attention APIs (omega_gpu_session.h): one open
30 * per process instead of one per call (~40 ms), kernels resident after first use,
31 * staging buffers reused at their high-water mark. Calls serialise on one lock.
32 *
33 * Launch envelope: at most OMEGA_GPU_EW_MAX_CTAS CTAs per launch (the matmul
34 * sweep of 2026-10-03 lost whole tiles at 128 CTAs, investigation I42); the
35 * API splits larger work on the host and makes several launches.
36 */
37#include <stdbool.h>
38#include <stddef.h>
39#include <stdint.h>
40#include "omega_blackwell_matmul.h" /* OmegaBlackwellKernel */
41
42#ifdef __cplusplus
43extern "C" {
44#endif
45
46enum {
47 OMEGA_GPU_EW_OK = 0,
48 OMEGA_GPU_EW_BAD_ARGS = -1, /* NULL pointer, zero dimension, or a shape rule below broken */
49 OMEGA_GPU_EW_TOO_LARGE = -2, /* dimension outside the codegen limits */
50 OMEGA_GPU_EW_CODEGEN_FAIL = -3, /* our codegen refused or exceeded the register budget */
51 OMEGA_GPU_EW_CHIP_FAIL = -4, /* device open, submit, marker or release failed */
52 OMEGA_GPU_EW_UNWRITTEN = -5 /* output words still equal to their poison after the run */
53};
54
55/* Kernel families. The two probes exist to prove the new instructions on the
56 * chip with the smallest possible kernels (and are kept for regression). */
57typedef enum {
58 OMEGA_GPU_EW_EX2 = 1, /* out[i] = 2^a[i] (probe for MUFU.EX2) */
59 OMEGA_GPU_EW_XCHG, /* out[i] = a[i ^ (T-1)] inside each CTA (probe for STS/BAR.SYNC/LDS) */
60 OMEGA_GPU_EW_RMSNORM,
61 OMEGA_GPU_EW_ROPE,
62 OMEGA_GPU_EW_SWIGLU,
63 OMEGA_GPU_EW_PRIME_SIEVE, /* prime race (2026-10-05): word-parallel odd-only sieve, codegen only
64 * here; launched by bench/prime_race/gb10_native.c (argument words in
65 * gen_prime_sieve's comment) */
66 OMEGA_GPU_EW_PRIME_SIEVE_SHARED /* the same sieve with the table staged in shared memory (C3) */
67} OmegaGpuEwOp;
68
69/* Shape rules (checked, refused with BAD_ARGS / TOO_LARGE):
70 * rmsnorm: dim % OMEGA_GPU_EW_THREADS == 0, dim <= OMEGA_GPU_EW_MAX_DIM, rows >= 1
71 * rope: head_dim even, 2 <= head_dim <= 2048 (head_dim/2 threads per CTA), heads >= 1
72 * swiglu: n >= 1 (the kernel guards the tail with a predicated EXIT)
73 * ex2: n >= 1; xchg: n % OMEGA_GPU_EW_THREADS == 0 */
74#define OMEGA_GPU_EW_THREADS 128u
75#define OMEGA_GPU_EW_MAX_DIM 16384u
76#define OMEGA_GPU_EW_MAX_CTAS 64u
77
78typedef struct {
79 uint32_t chip_calls; /* launches made */
80 uint64_t elapsed_ns; /* sum of launch-to-second-marker over the launches */
81 uint32_t completion_marker; /* observed first marker word of the last launch */
82 uint32_t unwritten_words; /* output words still equal to poison (0 on success) */
83 bool kernel_cache_hit; /* the shape's kernel was already generated in this process */
84 uint32_t gpr_count; /* registers the generated kernel uses */
85 uint32_t insn_count;
86 uint32_t threads_per_cta;
87 uint32_t ctas_last_launch;
88 char target_chip[64];
89 uint32_t sm_architecture;
90 uint64_t call_ns; /* cut 4b: wall time of the whole API call (staging, launches, copy-out) */
91} OmegaGpuEwInfo;
92
93/* out[r*dim + i] = x[r*dim + i] * scale_r * weight[i]; scale_r = 1/sqrt(mean_i(x^2) + eps). */
94int omega_gpu_rmsnorm_f32(uint32_t rows, uint32_t dim, const float *x, const float *weight,
95 float eps, float *out, OmegaGpuEwInfo *info);
96
97/* v holds `heads` heads of head_dim values back to back; cos_half and sin_half
98 * hold head_dim/2 values each (cos(pos*freq_i), sin(pos*freq_i)); out gets the
99 * rotated heads (may alias v: the API copies through its own buffers). */
100int omega_gpu_rope_f32(uint32_t heads, uint32_t head_dim, const float *v,
101 const float *cos_half, const float *sin_half, float *out,
102 OmegaGpuEwInfo *info);
103
104/* out[i] = silu(gate[i]) * up[i] for i < n. */
105int omega_gpu_swiglu_f32(uint32_t n, const float *gate, const float *up, float *out,
106 OmegaGpuEwInfo *info);
107
108/* Probes. ex2: out[i] = 2^x[i]. xchg: out[i] = x[i ^ (OMEGA_GPU_EW_THREADS-1)] within each CTA. */
109int omega_gpu_ex2_f32(uint32_t n, const float *x, float *out, OmegaGpuEwInfo *info);
110int omega_gpu_shared_xchg_u32(uint32_t n, const uint32_t *x, uint32_t *out, OmegaGpuEwInfo *info);
111
112/* Generate (without launching) the kernel for one op. Kernels read their shape
113 * from the argument words, so one kernel per op serves every shape; dims and eps
114 * are accepted for forward compatibility and ignored today (may be NULL / 0).
115 * Lets tests disassemble the bytes offline (nvdisasm) and check the register
116 * budget. Caller frees kernel->code. */
117int omega_gpu_elementwise_codegen(OmegaGpuEwOp op, const uint32_t *dims, float eps,
118 OmegaBlackwellKernel *kernel);
119
120/* Same, with the mutant chosen by the caller (0 = production kernel) and, when prog is
121 * not NULL, a copy of the allocated IR program (a BlackwellIRProgram, post register
122 * allocation) for a host IR simulator. Does not touch the device or the kernel cache.
123 * Caller frees kernel->code. */
124int omega_gpu_elementwise_codegen_ir(OmegaGpuEwOp op, int mutant, void *prog,
125 OmegaBlackwellKernel *kernel);
126
127/* TEST ONLY. Selects a deliberately wrong kernel for one op (0 clears). Each
128 * mutant changes the math by far more than the op's tolerance, so a parity
129 * check that still passes against it proves nothing. Clears the kernel cache.
130 * EX2: computes 2^(x+1). XCHG: reads its own shared word (no exchange).
131 * RMSNORM: the warp tree drops its last SHFL step (half the lanes go missing).
132 * ROPE: out0 = q0*cos + q1*sin. SWIGLU: exp(+g) instead of exp(-g). */
133void omega_gpu_elementwise_test_set_mutant(int op);
134
135const char *omega_gpu_elementwise_rc_name(int rc);
136void omega_gpu_elementwise_cache_clear(void);
137
138/* Stage name of the most recent CHIP_FAIL ("" if none), shared with the other GPU APIs
139 * (omega_gpu_session_last_error); an open failure carries the driver text. */
140const char *omega_gpu_elementwise_last_error(void);
141
142#ifdef __cplusplus
143}
144#endif
145#endif