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
CUDApp / src / omega_gpu_tcgemm_api.h
| 1 | /* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ |
| 2 | #ifndef OMEGA_GPU_TCGEMM_API_H |
| 3 | #define OMEGA_GPU_TCGEMM_API_H |
| 4 | /* |
| 5 | * omega_gpu_tcgemm_api (OWN-30B T3 cut 1): FP8 e4m3 block-128-scaled GROUPED GEMM on the tensor cores |
| 6 | * (HMMA.16816.F32.BF16; e4m3 -> bf16 dequantised in registers, exact). New file on the shared session. |
| 7 | * |
| 8 | * int omega_gpu_tcgemm_f32(const OmegaGpuFp8Tensor *t, uint32_t M, const uint32_t *expert_ids, |
| 9 | * const uint32_t *token_rows, const float *x, uint32_t x_rows, float *y, OmegaGpuTcGemmInfo *info); |
| 10 | * Row i computes expert expert_ids[i] (non-decreasing) on x[token_rows[i]]; y is M x n f32 in row-table order. |
| 11 | * Arithmetic (bit-exact contract, tests/gpu_tcgemm_test.c emulate()): x rounded RNE to bf16 after * 2^64; per 128-wide |
| 12 | * k block, eight HMMA steps of 16 terms each (GB10 fused-sum model, tests/bw_hmma_model.h) from zero, then |
| 13 | * acc = fmaf(block, scale', acc). This differs from the FFMA path's order (not bit-identical to omega_gpu_fp8gemm). |
| 14 | * No row cap beyond device memory; every output word is poisoned and checked. |
| 15 | * int omega_gpu_tcgemm_prepare(uint32_t k); |
| 16 | * Return codes: the OMEGA_GPU_TCGEMM_* values below; an uncertain completion latches the session (CHIP_FAIL). |
| 17 | */ |
| 18 | #include <stdbool.h> |
| 19 | #include <stdint.h> |
| 20 | #include "omega_gpu_fp8_api.h" |
| 21 | #include "omega_blackwell_codegen_tc.h" |
| 22 | |
| 23 | #ifdef __cplusplus |
| 24 | extern "C" { |
| 25 | #endif |
| 26 | 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 }; |
| 27 | |
| 28 | typedef struct { |
| 29 | uint32_t rows, segments, tiles, n, k, rt, ct, warps, grid_x, grid_y, gpr_declared; |
| 30 | uint64_t weight_bytes; /* e4m3 bytes of the distinct experts */ |
| 31 | uint64_t streamed_bytes; /* weight bytes the launch reads (tiles * n * k) */ |
| 32 | uint64_t act_bytes; /* activation bytes gathered (tiles * grid_x * 16 rt * k * 2) */ |
| 33 | uint64_t elapsed_ns; /* chip submit-to-second-marker */ |
| 34 | uint64_t call_ns; |
| 35 | uint32_t completion_marker; |
| 36 | bool kernel_cache_hit; |
| 37 | } OmegaGpuTcGemmInfo; |
| 38 | |
| 39 | int omega_gpu_tcgemm_f32(const OmegaGpuFp8Tensor *t, uint32_t M, const uint32_t *expert_ids, const uint32_t *token_rows, |
| 40 | const float *x, uint32_t x_rows, float *y, OmegaGpuTcGemmInfo *info); |
| 41 | int omega_gpu_tcgemm_prepare(uint32_t k); |
| 42 | const char *omega_gpu_tcgemm_rc_name(int rc); |
| 43 | const char *omega_gpu_tcgemm_last_error(void); |
| 44 | void omega_gpu_tcgemm_cache_clear(void); |
| 45 | /* the shape the API uses for width k and output width n */ |
| 46 | void omega_gpu_tcgemm_spec_for(uint32_t k, uint32_t n, OmegaTcGemmSpec *spec); |
| 47 | /* measurement knob: force rt, ct, warps (0 restores); TEST ONLY mutants 1-4 (omega_blackwell_codegen_tc.h) */ |
| 48 | void omega_gpu_tcgemm_set_shape(uint32_t rt, uint32_t ct, uint32_t warps); |
| 49 | void omega_gpu_tcgemm_test_set_mutant(int mutant); |
| 50 | #ifdef __cplusplus |
| 51 | } |
| 52 | #endif |
| 53 | #endif |