Distribute and run LLMs with a single file.
C++ cross-platformggufllama-cpplocal-ailocal-inferencelocal-llmopen-source-aisingle-file-executablespeech-to-text
Clean up some code
Justine Tunney4ab9d7285c08
diff --git a/llamafile/explain_a_warp_kernel.cpp b/llamafile/explain_a_warp_kernel.cppnew file mode 100644index 00000000..96dd2f88--- /dev/null+++ b/llamafile/explain_a_warp_kernel.cpp@@ -0,0 +1,158 @@+// -*- mode:c++;indent-tabs-mode:nil;c-basic-offset:4;coding:utf-8 -*-+// vi: set et ft=c++ ts=4 sts=4 sw=4 fenc=utf-8 :vi+//+// Copyright 2024 Mozilla Foundation+//+// Licensed under the Apache License, Version 2.0 (the "License");+// you may not use this file except in compliance with the License.+// You may obtain a copy of the License at+//+// http://www.apache.org/licenses/LICENSE-2.0+//+// Unless required by applicable law or agreed to in writing, software+// distributed under the License is distributed on an "AS IS" BASIS,+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+// See the License for the specific language governing permissions and+// limitations under the License.++#include <stdio.h>++// constexpr int TT = 1024;+// constexpr int BN = 256;+// constexpr int BM = 128;+// constexpr int VE = 4;+// constexpr int BK = 32;+// constexpr int WN = 8;+// constexpr int WM = 128;+// constexpr int WNI = 1;+// constexpr int TN = 4;+// constexpr int TM = 8;++constexpr int TT = 256;+constexpr int BM = 128;+constexpr int BN = 64;+constexpr int BK = 64;+constexpr int VE = 16;+constexpr int WM = 32;+constexpr int WN = 32;+constexpr int WNI = 1;+constexpr int TM = 8;+constexpr int TN = 4;++#define SRC 4 // half++// run o//llamafile/cudaprops to get these values for your gpu+#define regsPerBlock 65536+#define sharedMemPerBlock 65536 // 49152+#define warpSize 32+#define cudaSharedOverhead 1024+#define maxThreadsPerBlock 1024+#define regsPerMultiprocessor 65536+#define sharedMemPerMultiprocessor 65536+#define maxThreadsPerMultiProcessor 2048++#define MIN(X, Y) ((Y) > (X) ? (X) : (Y))+#define ROUNDUP(X, K) (((X) + (K) - 1) & -(K))++int main(int argc, char *argv[]) {++ if (TT > maxThreadsPerBlock) {+ printf("TT[%d] > maxThreadsPerBlock[%d]\n", TT, maxThreadsPerBlock);+ return 1;+ }++ if (BM % WM) {+ printf("BM[%d] %% WM[%d] was %d (should be 0)\n", BM, WM, BM % WM);+ return 2;+ }++ if (BN % WN) {+ printf("BN[%d] %% WN[%d] was %d (should be 0)\n", BN, WN, BN % WN);+ return 3;+ }++ int WARPS = TT / warpSize;+ if ((BN / WN) * (BM / WM) != WARPS) {+ printf("TT[%d] / warpSize[%d] = WARPS[%d]\n", TT, warpSize, WARPS);+ printf("(BN[%d] / WN[%d]) * (BM[%d] / WM[%d]) = WARPS[%d]\n", BN, WN, BM, WM,+ (BN / WN) * (BM / WM));+ printf("try using TT = %d\n", (BN / WN) * (BM / WM) * warpSize);+ return 4;+ }++ if ((WM * WN) % (warpSize * TM * TN * WNI))+ return 6;++ int WMI = (WM * WN) / (warpSize * TM * TN * WNI);+ if ((WM % WMI) || (WN % WNI))+ return 7;++ if (BK % VE)+ return 8;++ if (BN % VE)+ return 9;++ if ((BM * BK) % (VE * TT)) {+ printf("(BM[%d] * BK[%d])[%d] %% (VE[%d] * TT[%d])[%d] was non-zero\n", BM, BK, BM * BK, VE,+ TT, VE * TT);+ return 10;+ }++ if ((BN * BK) % (VE * TT)) {+ printf("(BN[%d] * BK[%d])[%d] %% (VE[%d] * TT[%d])[%d] was non-zero\n", BN, BK, BN * BK, VE,+ TT, VE * TT);+ return 11;+ }++ int SMEM = (BK * BM) + (BK * BN); // in words+ if (SMEM * 4 + cudaSharedOverhead > sharedMemPerBlock) {+ printf("SMEM[%d] * 4 + cudaSharedOverhead[%d] > sharedMemPerBlock[%d]\n", SMEM,+ cudaSharedOverhead, sharedMemPerBlock);+ return 12;+ }+ SMEM *= SRC; // now in bytes++ int REGS = ROUNDUP(((WMI * TM) + (WNI * TN) + (WMI * TM * WNI * TN)) * warpSize, 256) *+ (TT / warpSize);+ if (REGS > regsPerBlock)+ return 10;++ int occupants = MIN(regsPerMultiprocessor / REGS,+ MIN(maxThreadsPerMultiProcessor / TT,+ sharedMemPerMultiprocessor / (SMEM + cudaSharedOverhead)));++ int occupancy =+ ((TT * occupants / (double)maxThreadsPerMultiProcessor) + //+ (REGS * occupants / (double)regsPerMultiprocessor) ++ ((SMEM + cudaSharedOverhead) * occupants / (double)sharedMemPerMultiprocessor)) /+ 3 * 100 ++ .5;++ printf("\n");+ printf("constexpr int TT = %d;\n", TT);+ printf("constexpr int BN = %d;\n", BN);+ printf("constexpr int BM = %d;\n", BM);+ printf("constexpr int VE = %d;\n", VE);+ printf("constexpr int BK = %d;\n", BK);+ printf("constexpr int WN = %d;\n", WN);+ printf("constexpr int WM = %d;\n", WM);+ printf("constexpr int WNI = %d;\n", WNI);+ printf("constexpr int TN = %d;\n", TN);+ printf("constexpr int TM = %d;\n", TM);+ printf("constexpr int SMEM = %d * sizeof(SRC) + %d;\n", (SMEM / SRC), cudaSharedOverhead);+ printf("constexpr int REGS = %d;\n", REGS);+ printf("\n");++ printf("occupants = %d\n", occupants);+ printf("occupancy = %d\n", occupancy);+ printf("register occupancy = %d\n",+ (int)(REGS * occupants / (double)regsPerMultiprocessor * 100 + .5));+ printf("shared occupancy = %d\n", (int)((SMEM + cudaSharedOverhead) * occupants /+ (double)sharedMemPerMultiprocessor * 100 ++ .5));+ printf("thread occupancy = %d\n",+ (int)(TT * occupants / (double)maxThreadsPerMultiProcessor * 100 + .5));++ //+}diff --git a/llamafile/pick_a_warp_kernel.c b/llamafile/pick_a_warp_kernel.cindex d965d3f1..12af58b9 100644--- a/llamafile/pick_a_warp_kernel.c+++ b/llamafile/pick_a_warp_kernel.c@@ -30,7 +30,6 @@// warp kernel implementation which is the opposite of the tinyBLAS API#define SRC 2-#define BANK 8// run o//llamafile/cudaprops to get these values for your gpu#define regsPerBlock 65536@@ -79,10 +78,12 @@ int main(int argc, char *argv[]) {for (int iBK = 0; iBK < ARRAYLEN(kNumbers); ++iBK)for (int iWM = 0; iWM < ARRAYLEN(kNumbers); ++iWM)for (int iWN = 0; iWN < ARRAYLEN(kNumbers); ++iWN)+ for (int BK = 4; BK <= 128; BK<<=1)+ for (int VE = 4; VE <= 32; VE<<=1)for (int TM = 1; TM <= 8; TM<<=1)for (int TN = 1; TN <= 8; TN<<=1)for (int WNI = 1; WNI <= 8; ++WNI)- for (int TT = warpSize; TT <= 128/* maxThreadsPerBlock */; TT += warpSize) {+ for (int TT = warpSize; TT <= maxThreadsPerBlock; TT += warpSize) {int BM = kNumbers[iBM];int BN = kNumbers[iBN];int BK = kNumbers[iBK];@@ -109,22 +110,25 @@ int main(int argc, char *argv[]) {if (TM * TN < 24) continue;// banking possible- if (BK % BANK) continue;- if (BN % BANK) continue;- if ((BM * BK) % (BANK * TT)) continue;- if ((BN * BK) % (BANK * TT)) continue;+ if (BK % VE) continue;+ if (BN % VE) continue;+ if ((BM * BK) % (VE * TT)) continue;+ if ((BN * BK) % (VE * TT)) continue;// plan out warp tiles for each threadint WARPS = TT / warpSize;if ((BN / WN) * (BM / WM) != WARPS) continue;+ if ((WM * WN) % (warpSize * TM * TN * WNI)) continue;int WMI = (WM * WN) / (warpSize * TM * TN * WNI);- if (!((WM * WN) / (warpSize * TM * TN * WNI))) continue;if ((WM % WMI) || (WN % WNI)) continue;- if ((WM * WN) % (warpSize * TM * TN * WNI)) continue;+ if (WM % WMI) continue;+ if (WN % WNI) continue;+ int WSUBN = WN / WNI;+ if (WSUBN % TN) continue;// compute number of bytes of shared memory required per blockint SMEM = (BK * BM) + (BK * BN); // in words- if (SMEM * 4 > sharedMemPerBlock) continue;+ if (SMEM * SRC > sharedMemPerBlock) continue;SMEM *= SRC; // now in bytes// compute number of words used for thread local storage@@ -134,17 +138,31 @@ int main(int argc, char *argv[]) {int occupants = MIN(regsPerMultiprocessor / REGS,MIN(maxThreadsPerMultiProcessor / TT,sharedMemPerMultiprocessor / (SMEM + cudaSharedOverhead)));- if (occupants < 2) continue; // so there's room for sgemm float- int occupancy = ((REGS * occupants / (double)regsPerMultiprocessor) +- (SMEM * occupants / (double)sharedMemPerMultiprocessor)) / 2 * 100 + .5;- int score = occupancy;+ int register_occupancy = REGS * occupants / (double)regsPerMultiprocessor * 100 + .5;+ int shared_occupancy = (SMEM + cudaSharedOverhead) * occupants / (double)sharedMemPerMultiprocessor * 100 + .5;+ int thread_occupancy = TT * occupants / (double)maxThreadsPerMultiProcessor * 100 + .5;++ /* int score = register_occupancy + shared_occupancy + thread_occupancy; */++ int score =+ (TT > 256) ++ (BM == 128) ++ (BN == 64) ++ (BK == 64) ++ (VE == 16) ++ (WM == 32) ++ (WN == 32) ++ (WNI == 1) ++ (TM == 8) ++ (TN == 4);int n = 256;char *s = malloc(256);- snprintf(s, n, "%07d constexpr int TT = %3d, BM = %3d, BN = %3d, BK = %3d, WM = %3d, "- "WN = %3d, WNI = %d, TM = %2d, TN = %3d; // %5d REGS, %5d SMEM, %2d occupants (%d%%)",- score, TT, BM, BN, BK, WM, WN, WNI, TM, TN, REGS, SMEM, occupants, occupancy);+ snprintf(s, n, "%07d constexpr int TT = %3d, BM = %3d, BN = %3d, BK = %3d, VE = %3d, WM = %3d, "+ "WN = %3d, WNI = %d, TM = %2d, TN = %3d; // %5d REGS, %5d SMEM, %2d occupants (%2d%% / %2d%% / %2d%%)",+ score, TT, BM, BN, BK, VE, WM, WN, WNI, TM, TN, REGS, SMEM, occupants,+ register_occupancy, shared_occupancy, thread_occupancy);while (atomic_exchange_explicit(&lock, 1, memory_order_acquire));if (results == STRINGS) exit(7);diff --git a/llamafile/tester.h b/llamafile/tester.hindex a6661ea0..88bcea22 100644--- a/llamafile/tester.h+++ b/llamafile/tester.h@@ -252,7 +252,7 @@ void check(double tol, //assert(lda >= std::max(1, m));assert(ldb >= std::max(1, m));ErrorReport errors = diff(m, n, A, lda, B, ldb);- if (!errors.nans && errors.worst <= tol * sqrt(k) && errors.flips < m * n * .01) {+ if (!errors.nans && errors.sad <= tol && errors.flips < m * n * .01) {if (!is_self_testing)printf(" %lld ulp - %g (%llx) vs. %g (%llx)\n"" sad=%g nans=%d infs=%d flips=%d zeroes=%d denormals=%d\n",@@ -325,9 +325,9 @@ void check(double tol, //CUDA_OR_DIE(cudaEventRecord(stop_, stream)); \CUDA_OR_DIE(cudaEventSynchronize(stop_)); \CUDA_OR_DIE(cudaEventElapsedTime(&msecTotal_, start_, stop_)); \- printf("%8d us %s(%d, %d, %d)\n", \+ printf("%8d us %s(%d, %d, %d) %g gigaflops\n", \static_cast<int>(std::ceil(msecTotal_ / ITERATIONS * 1000)), __FUNCTION__, m, \- n, k); \+ n, k, 1000. / (msecTotal_ / ITERATIONS) * m * n * k * 1e-9); \CUDA_OR_DIE(cudaEventDestroy(start_)); \CUDA_OR_DIE(cudaEventDestroy(stop_)); \} \diff --git a/llamafile/tinyblas.cu b/llamafile/tinyblas.cuindex 7894cedf..9e6bc8ef 100644--- a/llamafile/tinyblas.cu+++ b/llamafile/tinyblas.cu@@ -33,12 +33,7 @@// our software open source if it spends most of its time inside NVIDIA// proprietary blobs like cuBLAS? tinyBLAS provides a free, open, libre// alternative to cuBLAS that's orders of a magnitude tinier (cuBLAS is-// a 500mb DSO) and goes fast enough that you won't sacrifice much. AMD-// users might even prefer tinyBLAS, since outperforming hipBLAS is not-// very difficult for large matrices. tinyBLAS also has better accuracy-// too, since hipBLAS uses tricks that cause sign flips, and denormals.-//-// TODO(jart): make tinyBLAS go fast for skinny matrices+// a 500mb DSO) and goes fast enough that you won't sacrifice much.//// [1] S. Boehm, ‘How to Optimize a CUDA Matmul Kernel for cuBLAS-like// Performance’, 2022. [Online]. Available:@@ -138,13 +133,9 @@ static __device__ void matmul_block2d(tinyblasOperation_t transa, tinyblasOperatAt[j] = As[BM * l + ti + j];for (int h = 0; h < TN; ++h)Bt[h] = Bs[BN * l + tj + h];- for (int j = 0; j < TM; ++j) {- WORD a = At[j];- for (int h = 0; h < TN; ++h) {- WORD b = Bt[h];- Ct[TN * j + h] += a * b;- }- }+ for (int j = 0; j < TM; ++j)+ for (int h = 0; h < TN; ++h)+ Ct[TN * j + h] += At[j] * Bt[h];}__syncthreads();@@ -172,8 +163,8 @@ static __device__ void matmul_block2d(tinyblasOperation_t transa, tinyblasOperat////////////////////////////////////////////////////////////////////////////////////////////////////// tinyBLAS warp block tiling outer product GEMM kernel-template <int CONFIG, int BM, int BN, int BK, int WM, int WN, int WNI, int TM, int TN, int TT,- typename WORD, typename SRC, typename DST>+template <int CONFIG, int BM, int BN, int BK, int VE, int WM, int WN, int WNI, int TM, int TN,+ int TT, typename WORD, typename SRC, typename DST>static __device__ void matmul_warp2d(tinyblasOperation_t aT, //tinyblasOperation_t bT, //int m, int n, int k, WORD alpha, //@@ -190,7 +181,6 @@ static __device__ void matmul_warp2d(tinyblasOperation_t aT, //constexpr int WMI = (WM * WN) / (WARPSIZE * TM * TN * WNI);constexpr int WSUBM = WM / WMI;constexpr int WSUBN = WN / WNI;- constexpr int BANK = 16;constexpr bool msafe = !!(CONFIG & ASSUME_M_SAFE);constexpr bool nsafe = !!(CONFIG & ASSUME_N_SAFE);@@ -206,10 +196,10 @@ static __device__ void matmul_warp2d(tinyblasOperation_t aT, //static_assert(!(WM % WMI) && !(WN % WNI), "");static_assert((BN / WN) * (BM / WM) == WARPS, "");static_assert((WM * WN) % (WARPSIZE * TM * TN * WNI) == 0, "");- static_assert((BM * BK) % (BANK * TT) == 0, "");- static_assert((BN * BK) % (BANK * TT) == 0, "");- static_assert(BK % BANK == 0, "");- static_assert(BN % BANK == 0, "");+ static_assert((BM * BK) % (VE * TT) == 0, "");+ static_assert((BN * BK) % (VE * TT) == 0, "");+ static_assert(BK % VE == 0, "");+ static_assert(BN % VE == 0, "");__shared__ SRC As[BK * BM];__shared__ SRC Bs[BK * BN];@@ -229,22 +219,22 @@ static __device__ void matmul_warp2d(tinyblasOperation_t aT, //for (int ll = 0; ll < k; ll += BK) {- for (int h = 0; h < BM; h += (TT * BANK) / BK)- for (int v = 0; v < BANK; ++v) {- int l = ll + threadIdx.x % (BK / BANK) * BANK + v;- int i = blockIdx.y * BM + threadIdx.x / (BK / BANK) + h;- As[BM * (threadIdx.x % (BK / BANK) * BANK + v) + (threadIdx.x / (BK / BANK) + h)] =+ for (int h = 0; h < BM; h += (TT * VE) / BK)+ for (int v = 0; v < VE; ++v) {+ int l = ll + threadIdx.x % (BK / VE) * VE + v;+ int i = blockIdx.y * BM + threadIdx.x / (BK / VE) + h;+ As[BM * (threadIdx.x % (BK / VE) * VE + v) + (threadIdx.x / (BK / VE) + h)] =(((i < m || msafe) && //(l < k || ksafe))- ? A[!aT ? lda * i + l : lda * l + i]+ ? A[aT ? lda * l + i : lda * i + l]: zero);}- for (int h = 0; h < BK; h += TT / (BN / BANK))- for (int v = 0; v < BANK; ++v) {- int l = ll + threadIdx.x / (BN / BANK) + h;- int j = blockIdx.x * BN + threadIdx.x % (BN / BANK) * BANK + v;- Bs[BN * (threadIdx.x / (BN / BANK) + h) + (threadIdx.x % (BN / BANK) * BANK + v)] =+ for (int h = 0; h < BK; h += TT / (BN / VE))+ for (int v = 0; v < VE; ++v) {+ int l = ll + threadIdx.x / (BN / VE) + h;+ int j = blockIdx.x * BN + threadIdx.x % (BN / VE) * VE + v;+ Bs[BN * (threadIdx.x / (BN / VE) + h) + (threadIdx.x % (BN / VE) * VE + v)] =(((j < n || nsafe) && //(l < k || ksafe))? B[bT ? ldb * j + l : ldb * l + j]@@ -419,24 +409,24 @@ tinyblasStatus_t tinyblasSgemm(tinyblasHandle_t handle, tinyblasOperation_t tranTINYBLAS_GEMM_DEFAULT);}-template <int CONFIG, int BM, int BN, int BK, int WM, int WN, int WNI, int TM, int TN, int TT,- typename WORD, typename SRC, typename DST>+template <int CONFIG, int BM, int BN, int BK, int VE, int WM, int WN, int WNI, int TM, int TN,+ int TT, typename WORD, typename SRC, typename DST>static __global__ void __launch_bounds__(TT) tinyblasGE_entry(tinyblasOperation_t aT, //tinyblasOperation_t bT, //int m, int n, int k, WORD alpha, //const SRC *A, int lda, //const SRC *B, int ldb, //WORD beta, DST *C, int ldc) {- matmul_warp2d<CONFIG, BM, BN, BK, WM, WN, WNI, TM, TN, TT>(aT, bT, m, n, k, alpha, A, lda, B,- ldb, beta, C, ldc);+ matmul_warp2d<CONFIG, BM, BN, BK, VE, WM, WN, WNI, TM, TN, TT>(aT, bT, m, n, k, alpha, A, lda,+ B, ldb, beta, C, ldc);}-template <typename WORD, typename SRC, typename DST>+template <int BM, int BN, int BK, int VE, int WM, int WN, int WNI, int TM, int TN, int TT,+ typename WORD, typename SRC, typename DST>static tinyblasStatus_t tinyblasGE_launcher(tinyblasHandle_t handle, tinyblasOperation_t aT,tinyblasOperation_t bT, int m, int n, int k, WORD alpha,const SRC *A, int lda, const SRC *B, int ldb, WORD beta,DST *C, int ldc) {- constexpr int TT = 256, BM = 128, BN = 64, BK = 64, WM = 128, WN = 8, WNI = 1, TM = 8, TN = 4;dim3 blocks(CEIL_DIV(n, BN), CEIL_DIV(m, BM));if ((beta == 0 && //alpha == 1 && //@@ -446,12 +436,13 @@ static tinyblasStatus_t tinyblasGE_launcher(tinyblasHandle_t handle, tinyblasOpebT == TINYBLAS_OP_T)) {constexpr int CONFIG = IGNORE_BETA | IGNORE_ALPHA | ASSUME_A_OP_N | ASSUME_B_OP_T |ASSUME_N_SAFE | ASSUME_K_SAFE;- tinyblasGE_entry<CONFIG, BM, BN, BK, WM, WN, WNI, TM, TN, TT>+ tinyblasGE_entry<CONFIG, BM, BN, BK, VE, WM, WN, WNI, TM, TN, TT><<<blocks, TT, 0, handle->stream>>>(aT, bT, m, n, k, alpha, A, lda, B, ldb, beta, C,ldc);} else {- tinyblasGE_entry<0, BM, BN, BK, WM, WN, WNI, TM, TN, TT><<<blocks, TT, 0, handle->stream>>>(- aT, bT, m, n, k, alpha, A, lda, B, ldb, beta, C, ldc);+ tinyblasGE_entry<0, BM, BN, BK, VE, WM, WN, WNI, TM, TN, TT>+ <<<blocks, TT, 0, handle->stream>>>(aT, bT, m, n, k, alpha, A, lda, B, ldb, beta, C,+ ldc);}if (cudaGetLastError() != cudaSuccess)return TINYBLAS_STATUS_EXECUTION_FAILED;@@ -459,11 +450,22 @@ static tinyblasStatus_t tinyblasGE_launcher(tinyblasHandle_t handle, tinyblasOpe}template <typename WORD, typename SRC, typename DST>-static tinyblasStatus_t tinyblasGE_launch(tinyblasHandle_t handle, tinyblasOperation_t aT,- tinyblasOperation_t bT, int m, int n, int k, WORD alpha,- const SRC *A, int lda, const SRC *B, int ldb, WORD beta,- DST *C, int ldc) {- return tinyblasGE_launcher(handle, bT, aT, n, m, k, alpha, B, ldb, A, lda, beta, C, ldc);+tinyblasStatus_t tinyblasGE_launch(tinyblasHandle_t handle, tinyblasOperation_t aT,+ tinyblasOperation_t bT, int m, int n, int k, WORD alpha,+ const SRC *A, int lda, const SRC *B, int ldb, WORD beta, DST *C,+ int ldc) {+ constexpr int TT = 256;+ constexpr int BM = 128;+ constexpr int BN = 64;+ constexpr int BK = 64;+ constexpr int VE = 16;+ constexpr int WM = 32;+ constexpr int WN = 32;+ constexpr int WNI = 1;+ constexpr int TM = 8;+ constexpr int TN = 4;+ return tinyblasGE_launcher<BM, BN, BK, VE, WM, WN, WNI, TM, TN, TT>(+ handle, bT, aT, n, m, k, alpha, B, ldb, A, lda, beta, C, ldc);}/**@@ -592,10 +594,10 @@ static tinyblasStatus_t tinyblasGBE_launch(tinyblasHandle_t handle, tinyblasOperWORD alpha, const SRC *const *Aarray, int lda,const SRC *const *Barray, int ldb, WORD beta,DST *const *Carray, int ldc, int batchCount) {- constexpr int BM = 32;- constexpr int BN = 32;- constexpr int TM = 2;- constexpr int TN = 8;+ constexpr int BM = 16;+ constexpr int BN = 16;+ constexpr int TM = 4;+ constexpr int TN = 4;dim3 blocks(CEIL_DIV(m, BM), CEIL_DIV(n, BN), batchCount);tinyblasGBE_entry<BM, BN, TM, TN><<<blocks, THREAD_COUNT, 0, handle->stream>>>(transa, transb, m, n, k, alpha, Aarray, lda, Barray, ldb, beta, Carray, ldc, batchCount);@@ -728,16 +730,12 @@ static __global__ void KERNEL tinyblasGSBE_entry(tinyblasOperation_t transa,C + strideC * blockIdx.z, ldc);}-template <typename WORD, typename SRC, typename DST>-static tinyblasStatus_t tinyblasGSBE_launch(tinyblasHandle_t handle, tinyblasOperation_t transa,- tinyblasOperation_t transb, int m, int n, int k,- WORD alpha, const SRC *A, int lda, long long strideA,- const SRC *B, int ldb, long long strideB, WORD beta,- DST *C, int ldc, long long strideC, int batchCount) {- constexpr int BM = 32;- constexpr int BN = 32;- constexpr int TM = 2;- constexpr int TN = 8;+template <int BM, int BN, int TM, int TN, typename WORD, typename SRC, typename DST>+static tinyblasStatus_t tinyblasGSBE_launcher(tinyblasHandle_t handle, tinyblasOperation_t transa,+ tinyblasOperation_t transb, int m, int n, int k,+ WORD alpha, const SRC *A, int lda, long long strideA,+ const SRC *B, int ldb, long long strideB, WORD beta,+ DST *C, int ldc, long long strideC, int batchCount) {constexpr int BK = THREAD_COUNT;dim3 blocks(CEIL_DIV(m, BM), CEIL_DIV(n, BN), batchCount);if ((beta == 0 && //@@ -761,6 +759,21 @@ static tinyblasStatus_t tinyblasGSBE_launch(tinyblasHandle_t handle, tinyblasOpereturn TINYBLAS_STATUS_SUCCESS;}+template <typename WORD, typename SRC, typename DST>+static tinyblasStatus_t tinyblasGSBE_launch(tinyblasHandle_t handle, tinyblasOperation_t transa,+ tinyblasOperation_t transb, int m, int n, int k,+ WORD alpha, const SRC *A, int lda, long long strideA,+ const SRC *B, int ldb, long long strideB, WORD beta,+ DST *C, int ldc, long long strideC, int batchCount) {+ constexpr int BM = 16;+ constexpr int BN = 16;+ constexpr int TM = 4;+ constexpr int TN = 4;+ return tinyblasGSBE_launcher<BM, BN, TM, TN>(handle, transa, transb, m, n, k, alpha, A, lda,+ strideA, B, ldb, strideB, beta, C, ldc, strideC,+ batchCount);+}+/*** Multiplies matrices.*diff --git a/llamafile/tinyblas_test.cu b/llamafile/tinyblas_test.cuindex 6bf23a74..bf2e0062 100644--- a/llamafile/tinyblas_test.cu+++ b/llamafile/tinyblas_test.cu@@ -15,10 +15,9 @@// See the License for the specific language governing permissions and// limitations under the License.-#include "gemm.h"#include "tester.h"-double TOLERANCE = 1;+double TOLERANCE = 1e-5;void checkTinyblasWorksHHHS() {float alpha = 1;