okami.mom/strata

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

Niko1221Merge f-0216-dfship into f-0216-all78c5a834e

main
1.6 KiB25 linesraw
1// metal/kernels/mm_i8.metal - matmul2d throughput probes for other operand types (tests/mm_i8_bench.cpp):
2// C[M][N] = A[M][K] . B[N][K]^T with a typed destination: int8 x int8 -> int32, fp16 x fp16 -> fp16 (and the fp32 reference).
3#include <MetalPerformancePrimitives/MetalPerformancePrimitives.h>
4using namespace mpp::tensor_ops;
5
6struct MmArgs { int M, N, K; };
7
8template <typename T, typename D, int TM, int TN, int SG>
9kernel void mpp_mm_t(device T* A [[buffer(0)]], device T* B [[buffer(1)]], device D* C [[buffer(2)]],
10                     constant MmArgs& a [[buffer(3)]], uint3 tg [[threadgroup_position_in_grid]]) {
11    tensor<device T, dextents<int32_t, 2>, tensor_inline> tA(A, dextents<int32_t, 2>(a.K, a.M));
12    tensor<device T, dextents<int32_t, 2>, tensor_inline> tB(B, dextents<int32_t, 2>(a.K, a.N));
13    tensor<device D, dextents<int32_t, 2>, tensor_inline> tC(C, dextents<int32_t, 2>(a.N, a.M));
14    constexpr auto desc = matmul2d_descriptor(TM, TN, dynamic_length_v<int>, false, true, false);
15    matmul2d<desc, execution_simdgroups<SG>> op;
16    auto mA = tA.slice(0, int(tg.y) * TM);
17    auto mB = tB.slice(0, int(tg.x) * TN);
18    auto mC = tC.slice(int(tg.x) * TN, int(tg.y) * TM);
19    op.run(mA, mB, mC);
20}
21
22#define MPPT(T, D, M, N, S) template [[host_name("mpp_" #T "_" #D "_" #M "_" #N "_" #S)]] kernel decltype(mpp_mm_t<T, D, M, N, S>) mpp_mm_t<T, D, M, N, S>;
23MPPT(char, int, 64, 64, 4) MPPT(char, int, 128, 64, 4) MPPT(char, int, 64, 128, 4)
24MPPT(half, half, 64, 64, 4) MPPT(half, half, 128, 64, 4)
25MPPT(half, float, 64, 64, 4) MPPT(half, float, 128, 64, 4)