okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
01f8c3255
main
1// src/prefill/wmma_gemm.h - RDNA3 WMMA FP16 & BF16 GEMM for Strata prefill. 2#pragma once 3 4#include <cstdint> 5 6/// Compute Y[t, n] = beta * Y[t, n] + sum_k W[n, k] * X[t, k] using RDNA3 WMMA instructions. 7/// X: T x K row-major (leading dim K), fp16 (uint16_t) 8/// W: N x K row-major (leading dim K), fp16 (uint16_t) 9/// Y: T x N row-major with leading dimension ldy >= N, fp32 (float) 10/// Returns true if executed on WMMA, false if unsupported shape/parameters (fall back to hipblas). 11bool strata_wmma_gemm_f16 (const uint16_t * X ,const uint16_t * W ,float * Y , 12int64_t T ,int64_t N ,int64_t K ,int64_t ldy ,float beta , 13void * stream = nullptr ); 14 15/// Compute Y[t, n] = beta * Y[t, n] + sum_k W[n, k] * X[t, k] using RDNA3 WMMA instructions. 16/// X: T x K row-major (leading dim K), bf16 (uint16_t) 17/// W: N x K row-major (leading dim K), bf16 (uint16_t) 18/// Y: T x N row-major with leading dimension ldy >= N, fp32 (float) 19/// Returns true if executed on WMMA, false if unsupported shape/parameters (fall back to hipblas). 20/// S23 (opt-in STRATA_PF_GEMM=1): Y = beta * Y + X . W^T, FP16 in, FP32 out, beta 0 or 1, K a multiple of 32, 21/// T >= 64, N >= 512; the 128 x 256 / 128 x 128 grouped-order WMMA kernel. False (nothing launched) otherwise / off gfx11. 22bool strata_pf_gemm_f16 (const uint16_t * X ,const uint16_t * W ,float * Y ,int64_t T ,int64_t N ,int64_t K ,int64_t ldy , 23float beta ,void * stream = nullptr ); 24/// The same with row strides ldx >= K and ldw >= K (multiples of 8): a 4 KB-multiple row stride (K 2048 / 4096 / 25/// 6144) camps on the memory channels, K + 64 does not (S23 gemm_probe7/8: K 6144 19 -> 35 TFLOPS). 26/// S23 (STRATA_PF_HCDOWN=1): lo[t, n] = sum_k X[t, k] Wd[n, k] (n < nd) and inj[t, n] = sum_k X[t, k] Wi[n, k] 27/// (n < ni) in one BF16 WMMA GEMM over X (T x K, token stride ldx >= K, a multiple of 8; Wd / Wi row-major, stride 28/// K); lo T x nd and inj T x ni, FP32. K a multiple of 64, T >= 64. False (nothing launched) otherwise / off gfx11. 29#if defined(STRATA_USE_HIP ) 30bool strata_pf_hcdown_bf16 (const uint16_t * X ,int64_t ldx ,const uint16_t * Wd ,const uint16_t * Wi ,int64_t nd , 31int64_t ni ,float * lo ,float * inj ,int64_t T ,int64_t K ,void * stream = nullptr ); 32#else 33// wmma_gemm.cu is part of the AMD builds only: another build has no such kernel (prefill.cpp then stops with its error) 34inline bool strata_pf_hcdown_bf16 (const uint16_t * ,int64_t ,const uint16_t * ,const uint16_t * ,int64_t ,int64_t ,float * ,float * , 35int64_t ,int64_t ,void * = nullptr ) {return false ; } 36#endif 37/// S (STRATA_HCD_EXACT=1): Y[t, n] = sum_k X[t, k] W[n, k] for N 320, K 10240 (BF16, FP32 out, X token stride ldx >= K, a 38/// multiple of 8), bitwise equal to hipBLASLt solution 1176 / 1177 for that shape (its k order, StaggerU included). 39/// False (nothing launched) for any other shape / off gfx11. 40bool strata_pf_hcdown_exact_bf16 (const uint16_t * X ,int64_t ldx ,const uint16_t * W ,float * Y ,int64_t T ,int64_t N , 41int64_t K ,void * stream = nullptr ); 42bool strata_pf_gemm_f16_ld (const uint16_t * X ,int64_t ldx ,const uint16_t * W ,int64_t ldw ,float * Y ,int64_t T , 43int64_t N ,int64_t K ,int64_t ldy ,float beta ,void * stream = nullptr ); 44/// True when the products above can run on the current device (the gfx11 matrix cores). Host code that pads an 45/// activation's row stride for them (STRATA_PF_PAD, prefill.cpp) must ask this first: on another card no kernel takes 46/// a padded X, and Gemm::native would have to copy the rows unpadded. 47#if defined(STRATA_USE_HIP ) 48bool strata_pf_padded_gemm_available (); 49#else 50inline bool strata_pf_padded_gemm_available () {return false; } 51#endif 52 53bool strata_wmma_gemm_bf16 (const uint16_t * X ,const uint16_t * W ,float * Y , 54int64_t T ,int64_t N ,int64_t K ,int64_t ldy ,float beta , 55void * stream = nullptr );