okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
6a74320ca
main
1// metal/src/engine/mmvq_host.cpp - the host-side helpers of src/kernels/cuda/native_mmvq.cu the shared host code reads 2// (which GGUF types the dense projections take, their byte sizes). Copied from native_mmvq.cu; keep in step. The 3// kernels are not ported: on Metal the decode window runs mac-kern's GEMVs (metal/src/engine/window.cpp). 4#include "strata/kernels/iq_kernels.hpp" 5#include "strata/kernels/native_mmvq.hpp" 6 7#include <cstddef> 8#include <cstdlib> 9#include <limits> 10#include <stdexcept> 11 12namespace strata::kernels { 13namespace { 14constexpr int Q8K = 32 ; 15constexpr std::size_t kQ81Block = 4 + 32 ;// half2 ds + int8 qs[32] 16void validate_shape (int n_in ,int ncols ,int block_elems = Q8K ) { 17if (n_in <=0 || n_in %block_elems != 0 ) 18throw std::invalid_argument ("native MMVQ requires n_in > 0 and divisible by its block element count" ); 19if (ncols < 1 || ncols > 8 )throw std::invalid_argument ("native MMVQ requires 1 <= ncols <= 8" ); 20} 21}// namespace 22 23bool native_mmvq_supported (int ggml_type )noexcept { 24return ggml_type == 2 || ggml_type == 6 || ggml_type == 7 || ggml_type == 8 || ggml_type == 11 || 25ggml_type == 12 || ggml_type == 13 || ggml_type == 14 || ggml_type == 20 || 26ggml_type == 23 || ggml_type == 42 || ggml_type == 16 || ggml_type == 17 || ggml_type == 18 || 27ggml_type == 21 || ggml_type == 22 || ggml_type == 29 ; 28} 29 30std::size_t native_mmvq_weight_bytes (int ggml_type ,int n_in ,int n_out ) { 31int block_elems ,block_bytes ; 32switch (ggml_type ) { 33case 2 :block_elems = 32 ;block_bytes = 18 ;break ; 34case 6 :block_elems = 32 ;block_bytes = 22 ;break ; 35case 7 :block_elems = 32 ;block_bytes = 24 ;break ; 36case 8 :block_elems = 32 ;block_bytes = 34 ;break ; 37case 20 :block_elems = 32 ;block_bytes = 18 ;break ; 38case 11 :block_elems = 256 ;block_bytes = 110 ;break ; 39case 12 :block_elems = 256 ;block_bytes = 144 ;break ; 40case 13 :block_elems = 256 ;block_bytes = 176 ;break ; 41case 14 :block_elems = 256 ;block_bytes = 210 ;break ; 42case 23 :block_elems = 256 ;block_bytes = 136 ;break ; 43case 42 :block_elems = 64 ;block_bytes = 18 ;break ; 44case 16 :case 17 :case 18 :case 21 :case 22 :case 29 : 45block_elems = 256 ;block_bytes = (int )iq_row_bytes (ggml_type ,256 );break ; 46default :throw std::invalid_argument ("unsupported native MMVQ GGML type" ); 47 } 48validate_shape (n_in ,1 ,block_elems ); 49if (n_out <=0 )throw std::invalid_argument ("native MMVQ requires n_out > 0" ); 50const std::size_t row_bytes = std::size_t (n_in /block_elems )* block_bytes ; 51if (row_bytes > std::numeric_limits < std::size_t > ::max () / std::size_t (n_out )) 52throw std::length_error ("native MMVQ weight byte count overflows size_t" ); 53return row_bytes * std::size_t (n_out ); 54} 55 56std::size_t native_q8_1_bytes (int n_in ,int ncols ) { 57validate_shape (n_in ,ncols ); 58return std::size_t (ncols )* std::size_t (n_in /Q8K )* kQ81Block ; 59} 60std::size_t native_q8_1_il_bytes (int n_in ,int ncols ) {return native_q8_1_bytes (n_in ,ncols )* 2 ; } 61bool native_mmvq_il_supported (int ,int ,int ) {return false; } 62bool native_q8_0_packed_eligible (int ,int ) {return false; } 63bool native_q8_0_packed_enabled () {return false; } 64bool native_q6_k_packed_enabled () {return false; } 65 66}// namespace strata::kernels