okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Merge f-mac-rel (Mac Metal support) into f-144-rel6a74320ca

main
1.7 KiB36 linesraw
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) {
11    if (const char* e = std::getenv("COOP_K4")) return std::atoi(e) != 0;
12    const int lib = cx.compile({"mm_bench.metal"}, "#define NO_GGML_COMMON 1\n");
13    for (const char* tile : {"coop_layout_16_64_32", "coop_layout_16_32_32"}) {
14    mtl::Pipeline p = cx.pipeline(lib, tile);
15    mtl::Buffer out = cx.alloc(4 * 3 * 32 * 128 * 4);
16    mtl::Dispatch d;
17    d.p = &p;
18    d.args = {mtl::Arg::B(out)};
19    d.tg[0] = 32;
20    cx.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)
23    const int* o = out.as<int>();
24    for (int l = 0; l < 32; ++l) {
25        const int* q = o + l * 128 * 4;
26        const int cap = q[2];
27        for (int i = 0; i + 3 < cap; i += 4)
28            for (int j = 1; j < 4; ++j)
29                if (q[(i + j) * 4] != q[i * 4] + j || q[(i + j) * 4 + 1] != q[i * 4 + 1]) return false;
30        for (int i = 0; i < cap / 2; i += 4)
31            if (q[(i + cap / 2) * 4] != q[i * 4] + 16 || q[(i + cap / 2) * 4 + 1] != q[i * 4 + 1] || (q[i * 4] & 31) >= 16)
32                return false;
33    }
34    }
35    return true;
36}