okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
6a74320ca
main
1// metal/tests/coop_probe.h - which element layout this GPU gives matmul2d's single-simdgroup right-input cooperative 2// tensor: true = runs of 4 consecutive k at one n per lane (the M5), false = anything else (the M4: runs of 2 n at one 3// k). The kernels that fill right inputs per lane (mm_gu3, mm_down3, qsa_attn_mm, qsa_flash) take it as function 4// constant 7. COOP_K4=0/1 in the environment overrides. 5#pragma once 6#include "mtl_rt.h" 7 8#include <cstdlib> 9 10inline bool coop_k4 (mtl ::Context & cx ) { 11if (const char * e = std ::getenv ("COOP_K4" ))return std ::atoi (e )!= 0 ; 12const int lib = cx .compile ({"mm_bench.metal" },"#define NO_GGML_COMMON 1\n" ); 13for (const char * tile : {"coop_layout_16_64_32" ,"coop_layout_16_32_32" }) { 14mtl ::Pipeline p = cx .pipeline (lib ,tile ); 15mtl ::Buffer out = cx .alloc (4 * 3 * 32 * 128 * 4 ); 16mtl ::Dispatch d ; 17d .p = & p ; 18d .args = {mtl ::Arg ::B (out )}; 19d .tg [0 ]= 32 ; 20cx .run ({d }); 21// every lane: elements 4j .. 4j + 3 are (k, n), (k + 1, n), (k + 2, n), (k + 3, n), and element i + cap / 2 is 22// (k + 16, n) with k % 32 < 16 (mm_gu3's paired-run decode relies on it) 23const int * o = out .as < int > (); 24for ( int l = 0 ; l < 32 ; ++ l) { 25const int * q = o + l * 128 * 4 ; 26const int cap = q[ 2 ]; 27for ( int i = 0 ; i + 3 < cap; i += 4 ) 28for ( int j = 1 ; j < 4 ; ++ j) 29if (q[(i + j) * 4 ] != q[i * 4 ] + j || q[(i + j) * 4 + 1 ] != q[i * 4 + 1 ]) return false; 30for ( int i = 0 ; i < cap / 2 ; i += 4 ) 31if (q[(i + cap / 2 ) * 4 ] != q[i * 4 ] + 16 || q[(i + cap / 2 ) * 4 + 1 ] != q[i * 4 + 1 ] || (q[i * 4 ] & 31 ) >= 16 ) 32return false; 33} 34} 35return true; 36}