omega-mv
Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.
Brought by drakestapleton
omega-mv / src / omega_gpu_tcgemm_api.h
| 1 | /* SPDX-License-Identifier: Apache-2.0 |
| 2 | * Copyright 2026 Drake Stapleton (AIEN / aien-dev) |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef OMEGA_GPU_TCGEMM_API_H |
| 18 | #define OMEGA_GPU_TCGEMM_API_H |
| 19 | /* |
| 20 | * omega_gpu_tcgemm_api (OWN-30B T3 cut 1): FP8 e4m3 block-128-scaled GROUPED GEMM on the tensor cores |
| 21 | * (HMMA.16816.F32.BF16; e4m3 -> bf16 dequantised in registers, exact). New file on the shared session. |
| 22 | * |
| 23 | * int omega_gpu_tcgemm_f32(const OmegaGpuFp8Tensor *t, uint32_t M, const uint32_t *expert_ids, |
| 24 | * const uint32_t *token_rows, const float *x, uint32_t x_rows, float *y, OmegaGpuTcGemmInfo *info); |
| 25 | * Row i computes expert expert_ids[i] (non-decreasing) on x[token_rows[i]]; y is M x n f32 in row-table order. |
| 26 | * Arithmetic (bit-exact contract, tests/gpu_tcgemm_test.c emulate()): x rounded RNE to bf16 after * 2^64; per 128-wide |
| 27 | * k block, eight HMMA steps of 16 terms each (GB10 fused-sum model, tests/bw_hmma_model.h) from zero, then |
| 28 | * acc = fmaf(block, scale', acc). This differs from the FFMA path's order (not bit-identical to omega_gpu_fp8gemm). |
| 29 | * No row cap beyond device memory; every output word is poisoned and checked. |
| 30 | * int omega_gpu_tcgemm_prepare(uint32_t k); |
| 31 | * Return codes: the OMEGA_GPU_TCGEMM_* values below; an uncertain completion latches the session (CHIP_FAIL). |
| 32 | */ |
| 33 | #include <stdbool.h> |
| 34 | #include <stdint.h> |
| 35 | #include "omega_gpu_fp8_api.h" |
| 36 | #include "omega_blackwell_codegen_tc.h" |
| 37 | |
| 38 | #ifdef __cplusplus |
| 39 | extern "C" { |
| 40 | #endif |
| 41 | enum { OMEGA_GPU_TCGEMM_OK = 0, OMEGA_GPU_TCGEMM_BAD_ARGS = -1, OMEGA_GPU_TCGEMM_TOO_LARGE = -2, OMEGA_GPU_TCGEMM_CODEGEN_FAIL = -3, OMEGA_GPU_TCGEMM_CHIP_FAIL = -4 }; |
| 42 | |
| 43 | typedef struct { |
| 44 | uint32_t rows, segments, tiles, n, k, rt, ct, warps, grid_x, grid_y, gpr_declared; |
| 45 | uint64_t weight_bytes; /* e4m3 bytes of the distinct experts */ |
| 46 | uint64_t streamed_bytes; /* weight bytes the launch reads (tiles * n * k) */ |
| 47 | uint64_t act_bytes; /* activation bytes gathered (tiles * grid_x * 16 rt * k * 2) */ |
| 48 | uint64_t elapsed_ns; /* chip submit-to-second-marker */ |
| 49 | uint64_t call_ns; |
| 50 | uint32_t completion_marker; |
| 51 | bool kernel_cache_hit; |
| 52 | } OmegaGpuTcGemmInfo; |
| 53 | |
| 54 | int omega_gpu_tcgemm_f32(const OmegaGpuFp8Tensor *t, uint32_t M, const uint32_t *expert_ids, const uint32_t *token_rows, |
| 55 | const float *x, uint32_t x_rows, float *y, OmegaGpuTcGemmInfo *info); |
| 56 | int omega_gpu_tcgemm_prepare(uint32_t k); |
| 57 | const char *omega_gpu_tcgemm_rc_name(int rc); |
| 58 | const char *omega_gpu_tcgemm_last_error(void); |
| 59 | void omega_gpu_tcgemm_cache_clear(void); |
| 60 | /* the shape the API uses for width k and output width n */ |
| 61 | void omega_gpu_tcgemm_spec_for(uint32_t k, uint32_t n, OmegaTcGemmSpec *spec); |
| 62 | /* measurement knob: force rt, ct, warps (0 restores); TEST ONLY mutants 1-4 (omega_blackwell_codegen_tc.h) */ |
| 63 | void omega_gpu_tcgemm_set_shape(uint32_t rt, uint32_t ct, uint32_t warps); |
| 64 | void omega_gpu_tcgemm_test_set_mutant(int mutant); |
| 65 | #ifdef __cplusplus |
| 66 | } |
| 67 | #endif |
| 68 | #endif |