okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
b0fc432ed
main
1// sycl/src/kernels/mmvq_sg_bench.cpp - SYCL port: the decode mmvq kernels on the Coder's dense shapes and types. 2// mmvq_sg_bench (prints us per call and a checksum of the outputs; the SIMD16 variants it once compared, STRATA_MMVQ_SG, were removed in 0.2.13) 3#include "strata/kernels/native_mmvq.hpp" 4#include <sycl/sycl.hpp> 5#include <dpct/dpct.hpp> 6#include <chrono> 7#include <cmath> 8#include <cstdio> 9#include <cstring> 10#include <vector> 11int main () { 12 sycl::queue * s = & dpct::get_in_order_queue (); 13struct T {const char * name ;int type ,bytes ,elems ; };// ggml type, bytes per block of `elems` weights 14const T types []= {{"q6_k" ,14 ,210 ,256 }, {"q5_k" ,13 ,176 ,256 }, {"q4_k" ,12 ,144 ,256 }, {"iq4_xs" ,23 ,136 ,256 }, 15 {"q8_0" ,8 ,34 ,32 }, {"iq4_nl" ,20 ,18 ,32 }}; 16const int shapes [][2 ]= {{2560 ,10240 }, {2560 ,12288 }, {6144 ,2560 }, {2560 ,640 }, {640 ,2560 }, {2560 ,2560 }}; 17const int cols []= {2 ,4 ,6 }; 18for (const T & t :types ) 19for (auto & sh :shapes ) { 20const int n_in = sh [0 ],n_out = sh [1 ]; 21if (n_in %t .elems != 0 )continue ;// 640 wide: the 32-element formats only 22const size_t wbytes = (size_t )n_out * (n_in /t .elems )* t .bytes ; 23 std::vector < uint8_t > hw (wbytes ); 24for (size_t i = 0 ;i < wbytes ;++ i )hw [i ]= (uint8_t ) (i * 2654435761u >>13 )& 0x3b ;// keeps fp16 fields finite 25void * w = sycl::malloc_device (wbytes ,* s ); 26s -> memcpy (w ,hw .data (),wbytes ).wait (); 27for (int nc :cols ) { 28 std::vector < float > hx ((size_t )nc * n_in ); 29for (size_t i = 0 ;i < hx .size ();++ i )hx [i ]= (float ) ((i * 7919 ) %1000 ) /500.f - 1.f ; 30float * x = sycl::malloc_device < float > (hx .size (),* s ); 31void * xq = sycl::malloc_device ((size_t )nc * (n_in /32 )* 36 ,* s ); 32float * y = sycl::malloc_device < float > ((size_t )nc * n_out ,* s ); 33s -> memcpy (x ,hx .data (),hx .size ()* 4 ).wait (); 34 strata::kernels::native_quantize_q8_1 (x ,xq ,n_in ,nc ,s ); 35auto run = [& ] { strata::kernels::native_mmvq (t .type ,w ,xq ,y ,n_in ,n_out ,nc ,s ); }; 36const auto w0 = std::chrono::steady_clock::now (); 37while (std::chrono::duration < double , std::milli > (std::chrono::steady_clock::now ()- w0 ).count ()< 150 ) { 38for (int i = 0 ;i < 20 ;++ i )run (); 39s -> wait (); 40 } 41const int it = 300 ; 42const auto t0 = std::chrono::steady_clock::now (); 43for (int i = 0 ;i < it ;++ i )run (); 44s -> wait (); 45const double us = std::chrono::duration < double , std::micro > (std::chrono::steady_clock::now ()- t0 ).count () /it ; 46 std::vector < float > hy ((size_t )nc * n_out ); 47s -> memcpy (hy .data (),y ,hy .size ()* 4 ).wait (); 48double cs = 0 ;for (float v :hy )cs += std::isfinite (v ) ? std::fabs ((double )v ) :1e30 ; 49 std::printf ("%-7s %5d x %5d cols %d %7.1f us %6.1f GB/s sum %.6e\n" ,t .name ,n_in ,n_out ,nc ,us , 50wbytes /us /1e3 ,cs ); 51 sycl::free (x ,* s ); sycl::free (xq ,* s ); sycl::free (y ,* s ); 52 } 53 sycl::free (w ,* s ); 54 } 55return 0 ; 56}