okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
8c3f91211
main
1// prefill_fused_group_test - P4-SMALL: the fused int8 experts for ONE GATHERED GROUP (fused::group_bounds + experts_native, the layer-major 2// walk's entry) on random native expert blobs and random routing, per format pair the native kernels take on this device, against 3// (B) the layer's fused path (fused::group over the routing, experts_native over expert ranges: the streamed walk's call, already gated): 4// the SAME bits for every routed (token, k) pair - the same kernels on the same rows, only the tables and the tile choice differ; 5// (C) MMQ in the walk, in prefill.cpp's sequence (rows sorted by expert, entries cut at the group cap, groups of at most 16 entries: 6// gather_native, q8_1 of the group's rows from the token list, gate/up, SwiGLU, q8_1 of H, down into the group's rows): not bitwise 7// (other int8 roundings); its distance is printed and has to be the same number as (B)'s distance to MMQ (it follows from the bits). 8// The walk's tables are built on the host as lm_run builds them: rows sorted by expert, token order within an expert, an expert split 9// into entries of at most `cap` rows, a group closed at 16 entries or when the next entry would pass `cap` rows. 10// Cases: 55 / 300 / 1,000 tokens over 512 experts (cap = tokens x k), 2,048 tokens over 128 experts with skewed routing and cap 700 (experts 11// split over groups). --only=NAME. Exit 77 without a CUDA device the fused kernels run on. 12#include "strata/core/emulate.hpp" 13#include "strata/prefill/moe_fused_iq.hpp" 14#include "strata/prefill/moe_mmq.hpp" 15 16#include "ggml.h" 17 18#include <cuda_runtime.h> 19 20#include <algorithm> 21#include <cmath> 22#include <cstdint> 23#include <cstdio> 24#include <cstdlib> 25#include <cstring> 26#include <random> 27#include <stdexcept> 28#include <string> 29#include <vector> 30 31namespace { 32namespace mmq= strata::prefill::mmq; 33namespace fused= strata::prefill::fused; 34 35constexpr int N = fused::kMoeEmbd ,FF = fused::kMoeFF ,FF2 = fused::kMoeGuRows ,K = (int ) strata::core::kCompiledGeometry .n_expert_used ; 36constexpr int GROUP = 16 ;// prefill.cpp MMQ_GROUP 37constexpr int TAIL = 4096 ;// prefill.cpp MMQ_TAIL (at least) 38 39void ck (cudaError_t e ,const char * what ) { 40if (e != cudaSuccess )throw std::runtime_error (std::string (what )+ ": " + cudaGetErrorString (e )); 41} 42 43struct Dev { 44void * p = nullptr ; 45explicit Dev (size_t n ) {ck (cudaMalloc (& p , std::max < size_t > (n ,16 )),"cudaMalloc" ); } 46 ~Dev () {cudaFree (p ); } 47Dev (const Dev & )= delete ; 48Dev & operator= (const Dev & )= delete ; 49template < typename T > T * as ()const {return (T * )p ; } 50}; 51 52struct Pair { 53ggml_type gu ,d ; 54const char * name ; 55}; 56 57size_t row_size (ggml_type t ,int64_t n ) {return (size_t ) (n /ggml_blck_size (t ))* ggml_type_size (t ); } 58 59struct Geo { 60size_t gu_row ,d_row ,up_off ,down_off ,bytes ; 61explicit Geo (const Pair & p ) { 62gu_row = row_size (p .gu ,N ); 63d_row = row_size (p .d ,FF ); 64up_off = gu_row * FF ; 65down_off = 2 * up_off ; 66bytes = down_off + d_row * N ; 67 } 68 fused::NativeGeom native (const Pair & p )const { 69 fused::NativeGeom g ; 70g .gu_type = (int )p .gu ;g .d_type = (int )p .d ;g .gu_row = gu_row ;g .d_row = d_row ;g .up_off = up_off ;g .down_off = down_off ; 71return g ; 72 } 73}; 74 75// random blocks with a sane fp16 scale at each block's start (prefill_fused_iq_test's fill_matrix for the i-quant / Q2_0 / IQ4_NL formats) 76void fill_matrix (uint8_t * m ,ggml_type t ,int64_t rows ,int64_t cols , std::mt19937 & rng ) { 77const size_t bs = ggml_type_size (t ),nb = (size_t )rows * (size_t ) (cols /ggml_blck_size (t )); 78 std::uniform_int_distribution < int > byte (0 ,255 ); 79const float lo = t == GGML_TYPE_IQ3_S ?0.0004f :t == GGML_TYPE_IQ4_XS ?0.00005f :t == GGML_TYPE_IQ4_NL ?0.0002f 80 :t == GGML_TYPE_Q2_0 ?0.004f :0.0008f ; 81 std::uniform_real_distribution < float > sc (lo ,6.0f * lo ); 82for (size_t i = 0 ;i < nb * bs ;++ i )m [i ]= (uint8_t )byte (rng ); 83for (size_t b = 0 ;b < nb ;++ b ) { 84const ggml_fp16_t h = ggml_fp32_to_fp16 (sc (rng )); 85 std::memcpy (m + b * bs ,& h ,2 ); 86 } 87} 88 89std::vector < float > make_x (int T , std::mt19937 & rng ) { 90 std::vector < float > x ((size_t )T * N ); 91 std::normal_distribution < float > nd (0.0f ,1.0f ); 92 std::uniform_int_distribution < int > pick (0 ,199 ); 93for (float & v :x )v = nd (rng )* (pick (rng )== 0 ?12.0f :1.0f ); 94if (T > 3 ) std::fill (x .begin ()+ 3 * N ,x .begin ()+ 4 * N ,0.0f );// an all-zero token 95return x ; 96} 97 98// K distinct experts per token; `hot` > 0 skews the first choices towards the lowest ids 99std::vector < int32_t > make_ids (int T ,int E , std::mt19937 & rng ,int hot ) { 100 std::vector < int32_t > ids ((size_t )T * K ); 101 std::uniform_int_distribution < int > any (0 ,E - 1 ); 102for (int t = 0 ;t < T ;++ t ) 103for (int k = 0 ;k < K ;++ k ) { 104int e ; 105bool dup ; 106do { 107e = (hot > 0 && k < 3 && (int ) (rng () %4 )!= 0 ) ? (int ) (rng () % (unsigned )hot ) :any (rng ); 108dup = false; 109for (int j = 0 ;j < k ;++ j )dup |=ids [(size_t )t * K + j ]== e ; 110 }while (dup ); 111ids [(size_t )t * K + k ]= e ; 112 } 113return ids ; 114} 115 116// lm_run's tables for one layer 117struct Walk { 118 std::vector < int32_t > row_tok ,row_of ;// sorted row -> token; pair -> sorted row 119struct Ent {int32_t e ,r0 ,nr ; }; 120struct Grp {size_t j0 ,j1 ;int32_t r0 ,nr ,maxr ;size_t b_at ; }; 121 std::vector < Ent > ents ; 122 std::vector < Grp > grps ; 123 std::vector < int32_t > bounds ;// per group: its entries' group-relative first rows, then nr 124}; 125Walk walk_tables (const std::vector < int32_t >& ids ,int E ,int32_t cap ) { 126Walk w ; 127const size_t rows = ids .size (); 128 std::vector < int32_t > cnt ((size_t )E ,0 ),off ((size_t )E + 1 ,0 ); 129for (int32_t e :ids )++ cnt [(size_t )e ]; 130for (int e = 0 ;e < E ;++ e )off [(size_t )e + 1 ]= off [(size_t )e ]+ cnt [(size_t )e ]; 131 std::vector < int32_t > fill (off .begin (),off .end ()- 1 ); 132w .row_tok .resize (rows ); 133w .row_of .resize (rows ); 134for (size_t i = 0 ;i < rows ;++ i ) { 135const int32_t p = fill [(size_t )ids [i ]]++ ; 136w .row_tok [(size_t )p ]= (int32_t ) (i /K ); 137w .row_of [i ]= p ; 138 } 139for (int32_t e = 0 ;e < E ;++ e ) 140for (int32_t r = off [(size_t )e ];r < off [(size_t )e + 1 ];r += cap ) 141w .ents .push_back ({e ,r , std::min < int32_t > (cap ,off [(size_t )e + 1 ]- r )}); 142for (size_t j = 0 ;j < w .ents .size ();) { 143Walk ::Grp g {}; 144g .j0 = j ; 145g .r0 = w .ents [j ].r0 ; 146while (j < w .ents .size ()&& j - g .j0 < (size_t )GROUP && g .nr + w .ents [j ].nr <=cap ) { 147g .nr += w .ents [j ].nr ; 148g .maxr = std::max (g .maxr ,w .ents [j ].nr ); 149++ j ; 150 } 151g .j1 = j ; 152g .b_at = w .bounds .size (); 153for (size_t i = g .j0 ;i < g .j1 ;++ i )w .bounds .push_back (w .ents [i ].r0 - g .r0 ); 154w .bounds .push_back (g .nr ); 155w .grps .push_back (g ); 156 } 157return w ; 158} 159 160struct Case { 161int T ,E ,hot ; 162int32_t cap ;// 0: tokens x k (one group cap = the chunk's rows, as G = T * K) 163}; 164 165// one case: throws when a row differs from the layer path or is not finite; prints the distances to MMQ 166void run_case (const Pair & p ,const Case & c , mmq::Context & ctx ,cudaStream_t s ,uint32_t seed ) { 167const Geo geo (p ); 168const fused::NativeGeom ng = geo .native (p ); 169 std::mt19937 rng (seed ); 170const int T = c .T ,E = c .E ; 171const int64_t rows = (int64_t )T * K ; 172const int32_t cap = c .cap > 0 ?c .cap : (int32_t )rows ; 173// the blobs: one allocation, a 256-byte stride 174const size_t stride = (geo .bytes + 255 ) /256 * 256 ; 175Dev blobs ((size_t )E * stride ); 176 { 177 std::vector < uint8_t > h ((size_t )E * stride ,0 ); 178for (int e = 0 ;e < E ;++ e ) { 179fill_matrix (h .data ()+ (size_t )e * stride ,p .gu ,2 * FF ,N ,rng ); 180fill_matrix (h .data ()+ (size_t )e * stride + geo .down_off ,p .d ,N ,FF ,rng ); 181 } 182ck (cudaMemcpy (blobs .p ,h .data (),h .size (),cudaMemcpyHostToDevice ),"blobs" ); 183 } 184auto blob = [& ](int e ) {return blobs .as < uint8_t > ()+ (size_t )e * stride ; }; 185const std::vector < float > x = make_x (T ,rng ); 186const std::vector < int32_t > ids = make_ids (T ,E ,rng ,c .hot ); 187const Walk w = walk_tables (ids ,E ,cap ); 188Dev x_dev (x .size ()* 4 ),ids_dev ((size_t )rows * 4 ),row_tok_dev ((size_t )rows * 4 ),bounds_dev (w .bounds .size ()* 4 ); 189ck (cudaMemcpy (x_dev .p ,x .data (),x .size ()* 4 ,cudaMemcpyHostToDevice ),"x" ); 190ck (cudaMemcpy (ids_dev .p ,ids .data (), (size_t )rows * 4 ,cudaMemcpyHostToDevice ),"ids" ); 191ck (cudaMemcpy (row_tok_dev .p ,w .row_tok .data (), (size_t )rows * 4 ,cudaMemcpyHostToDevice ),"row_tok" ); 192ck (cudaMemcpy (bounds_dev .p ,w .bounds .data (),w .bounds .size ()* 4 ,cudaMemcpyHostToDevice ),"bounds" ); 193 194// (A) the group entry, as lm_run calls it: xa per token once, then per group the tables and one experts_native 195Dev xa (fused::act_bytes (T ,N )),ha (fused::act_bytes (cap ,FF )),dmA ((size_t )rows * N * 4 ),scratch (fused::group_bytes (cap ,GROUP )); 196ck (cudaMemsetAsync (dmA .p ,0xff , (size_t )rows * N * 4 ,s ),"dmA nan" );// an unwritten row shows as NaN 197 fused::want_dm_f16 (false); 198 fused::quantize_act_native (x_dev .as < float > (),T ,N ,xa .p ,s ); 199for (const Walk ::Grp & g :w .grps ) { 200const int ngx = (int ) (g .j1 - g .j0 ); 201 fused::group_bounds (bounds_dev .as < int32_t > ()+ g .b_at ,ngx ,scratch .p ,s ); 202 fused::Batch b ; 203b .e0 = 0 ; 204b .e1 = ngx ; 205for (int i = 0 ;i < ngx ;++ i )b .blob [i ]= blob (w .ents [g .j0 + (size_t )i ].e ); 206 fused::experts_native (b ,ng ,ngx ,g .nr ,scratch .p ,xa .p ,row_tok_dev .as < int32_t > ()+ g .r0 ,ha .p ,dmA .as < float > ()+ (size_t )g .r0 * N ,s ); 207 } 208// (B) the layer's fused path (the streamed walk's call) 209Dev haB (fused::act_bytes (rows ,FF )),dmB ((size_t )rows * N * 4 ),scrB (fused::group_bytes (rows ,E )),slot ((size_t )rows * 4 ), 210src ((size_t )rows * 4 ); 211 fused::group (ids_dev .as < int32_t > (),rows ,K ,E ,scrB .p ,slot .as < int32_t > (),src .as < int32_t > (),s ); 212for (int e0 = 0 ;e0 < E ;e0 += fused::kMaxBatch ) { 213 fused::Batch b ; 214b .e0 = e0 ; 215b .e1 = std::min (E ,e0 + fused::kMaxBatch ); 216for (int e = b .e0 ;e < b .e1 ;++ e )b .blob [e - b .e0 ]= blob (e ); 217 fused::experts_native (b ,ng ,E ,rows ,scrB .p ,xa .p ,src .as < int32_t > (),haB .p ,dmB .as < float > (),s ); 218 } 219// (D) the staged walk's call: the layer's tables ONCE from the routed experts' absolute row bounds (group_bounds over every routed expert), 220// then experts_native on batches of experts (local indices of those tables, the whole layer's rows as `n`), batch sizes of every kind: 221// a full kMaxBatch, 16 (the staging ring's share), odd sizes and 1 222 std::vector < int32_t > order ,abs_b ; 223 { 224 std::vector < int32_t > cnt ((size_t )E ,0 ); 225for (int32_t e :ids )++ cnt [(size_t )e ]; 226int32_t acc = 0 ; 227for (int e = 0 ;e < E ;++ e ) 228if (cnt [(size_t )e ]> 0 ) {order .push_back (e );abs_b .push_back (acc );acc += cnt [(size_t )e ]; } 229abs_b .push_back (acc ); 230 } 231const int nord = (int )order .size (); 232Dev absD (abs_b .size ()* 4 ),scrD (fused::group_bytes (rows ,nord )),haD (fused::act_bytes (rows ,FF )),dmD ((size_t )rows * N * 4 ); 233ck (cudaMemcpy (absD .p ,abs_b .data (),abs_b .size ()* 4 ,cudaMemcpyHostToDevice ),"abs bounds" ); 234ck (cudaMemsetAsync (dmD .p ,0xff , (size_t )rows * N * 4 ,s ),"dmD nan" ); 235 fused::group_bounds (absD .as < int32_t > (),nord ,scrD .p ,s ); 236 { 237const int sizes []= {fused::kMaxBatch ,16 ,37 ,1 ,5 , fused::kMaxBatch ,16 ,16 }; 238int j0 = 0 ,si = 0 ; 239while (j0 < nord ) { 240const int j1 = std::min (nord ,j0 + sizes [si ++ %8 ]); 241 fused::Batch b ; 242b .e0 = j0 ; 243b .e1 = j1 ; 244for (int j = j0 ;j < j1 ;++ j )b .blob [j - j0 ]= blob (order [(size_t )j ]); 245 fused::experts_native (b ,ng ,nord ,rows ,scrD .p ,xa .p ,row_tok_dev .as < int32_t > (),haD .p ,dmD .as < float > (),s ); 246j0 = j1 ; 247 } 248 } 249// (C) MMQ in the walk 250const size_t gub = mmq::matrix_bytes ((int )p .gu ,FF2 ,N ),db = mmq::matrix_bytes ((int )p .d ,N ,FF ); 251Dev xq (mmq::q8_bytes (cap ,N )),gu ((size_t )cap * FF2 * 4 ),h ((size_t )cap * FF * 4 ),hq (mmq::q8_bytes (cap ,FF )), 252dmC ((size_t )rows * N * 4 ),ident ((size_t )cap * 4 + 4096 ),grp_gu (GROUP * gub + TAIL ),grp_d (GROUP * db + TAIL ); 253 mmq::iota (ident .as < int32_t > (),cap + 1024 ,s );// (MMQ's ids over-read: slack past the rows, as prefill.cpp's mmq_ids_rows) 254for (const Walk ::Grp & g :w .grps ) { 255const int ngx = (int ) (g .j1 - g .j0 ); 256for (int q = 0 ;q < ngx ;++ q ) { 257const uint8_t * bl = blob (w .ents [g .j0 + (size_t )q ].e ); 258 mmq::gather_native (bl ,bl + geo .up_off ,gub /2 ,bl + geo .down_off ,db ,grp_gu .as < uint8_t > ()+ q * gub ,grp_d .as < uint8_t > ()+ q * db ,s ); 259 } 260ck (cudaMemsetAsync (grp_gu .as < uint8_t > ()+ (size_t )ngx * gub ,0 ,TAIL ,s ),"tail" ); 261ck (cudaMemsetAsync (grp_d .as < uint8_t > ()+ (size_t )ngx * db ,0 ,TAIL ,s ),"tail" ); 262 mmq::quantize (x_dev .as < float > (),row_tok_dev .as < int32_t > ()+ g .r0 ,xq .p , (int )p .gu ,N ,N ,g .nr ,s ); 263 mmq::Product pg ; 264pg .w = grp_gu .p ;pg .type = (int )p .gu ;pg .w_rows = FF2 ;pg .w_cols = N ;pg .expert_bytes = gub ; 265pg .n = ngx ;pg .xq = xq .p ;pg .bounds = bounds_dev .as < int32_t > ()+ g .b_at ;pg .ids = ident .as < int32_t > (); 266pg .total_rows = g .nr ;pg .max_rows = g .maxr ;pg .dst = gu .as < float > ();pg .ld_dst = FF2 ; 267ctx .run (pg ,s ); 268 mmq::swiglu (gu .as < float > (),h .as < float > (),g .nr ,FF , false,s ); 269 mmq::quantize (h .as < float > (),nullptr ,hq .p , (int )p .d ,FF ,FF ,g .nr ,s ); 270 mmq::Product pd ; 271pd .w = grp_d .p ;pd .type = (int )p .d ;pd .w_rows = N ;pd .w_cols = FF ;pd .expert_bytes = db ; 272pd .n = ngx ;pd .xq = hq .p ;pd .bounds = bounds_dev .as < int32_t > ()+ g .b_at ;pd .ids = ident .as < int32_t > (); 273pd .total_rows = g .nr ;pd .max_rows = g .maxr ;pd .dst = dmC .as < float > ()+ (size_t )g .r0 * N ;pd .ld_dst = N ; 274ctx .run (pd ,s ); 275 } 276ck (cudaStreamSynchronize (s ),"sync" ); 277 std::vector < float > a ((size_t )rows * N ),b ((size_t )rows * N ),m ((size_t )rows * N ),dd ((size_t )rows * N ); 278 std::vector < int32_t > sl ((size_t )rows ); 279ck (cudaMemcpy (dd .data (),dmD .p ,dd .size ()* 4 ,cudaMemcpyDeviceToHost ),"d" ); 280ck (cudaMemcpy (a .data (),dmA .p ,a .size ()* 4 ,cudaMemcpyDeviceToHost ),"a" ); 281ck (cudaMemcpy (b .data (),dmB .p ,b .size ()* 4 ,cudaMemcpyDeviceToHost ),"b" ); 282ck (cudaMemcpy (m .data (),dmC .p ,m .size ()* 4 ,cudaMemcpyDeviceToHost ),"m" ); 283ck (cudaMemcpy (sl .data (),slot .p ,sl .size ()* 4 ,cudaMemcpyDeviceToHost ),"slot" ); 284int64_t differ = 0 ,nonfinite = 0 ,differ_d = 0 ; 285double e2a = 0 ,e2b = 0 ,r2 = 0 ,worst_a = 0 ,worst_b = 0 ; 286for (int64_t i = 0 ;i < rows ;++ i ) { 287const float * ya = a .data ()+ (size_t )w .row_of [(size_t )i ]* N ; 288const float * yb = b .data ()+ (size_t )sl [(size_t )i ]* N ; 289const float * ym = m .data ()+ (size_t )w .row_of [(size_t )i ]* N ; 290if (std::memcmp (ya ,yb , (size_t )N * 4 )!= 0 )++ differ ; 291if (std::memcmp (dd .data ()+ (size_t )w .row_of [(size_t )i ]* N ,yb , (size_t )N * 4 )!= 0 )++ differ_d ; 292double mea = 0 ,meb = 0 ,mr = 0 ; 293for (int o = 0 ;o < N ;++ o ) { 294if (!std::isfinite (ya [o ])) {++ nonfinite ;break ; } 295const double da = (double )ya [o ]- ym [o ],dbb = (double )yb [o ]- ym [o ]; 296e2a += da * da ; 297e2b += dbb * dbb ; 298r2 += (double )ym [o ]* ym [o ]; 299mea = std::max (mea , std::fabs (da )); 300meb = std::max (meb , std::fabs (dbb )); 301mr = std::max (mr , (double ) std::fabs (ym [o ])); 302 } 303if (mr > 0 ) {worst_a = std::max (worst_a ,mea /mr );worst_b = std::max (worst_b ,meb /mr ); } 304 } 305const double rms_a = r2 > 0 ? std::sqrt (e2a /r2 ) :0 ,rms_b = r2 > 0 ? std::sqrt (e2b /r2 ) :0 ; 306 std::printf ("%-18s T %5d E %3d cap %6d: %zu groups, %zu entries; group entry vs layer fused path: %lld of %lld rows differ, %lld non-finite; " 307"vs MMQ in the walk: rel RMS %.3e (layer path %.3e), worst row %.3e (%.3e)\n" , 308p .name ,T ,E ,cap ,w .grps .size (),w .ents .size (), (long long )differ , (long long )rows , (long long )nonfinite ,rms_a ,rms_b , 309worst_a ,worst_b ); 310 std::printf ("%-18s staged walk's batched call (%d experts, group_bounds once, batches of 128 / 16 / 37 / 1 / 5): %lld of %lld rows differ from the layer fused path\n" , 311p .name ,nord , (long long )differ_d , (long long )rows ); 312if (differ_d )throw std::runtime_error (std::string (p .name )+ ": the staged walk's batched call differs from the layer's fused path" ); 313if (nonfinite )throw std::runtime_error (std::string (p .name )+ ": a row of the group entry is not finite (unwritten or overflowed)" ); 314if (differ )throw std::runtime_error (std::string (p .name )+ ": the group entry's rows differ from the layer's fused path" ); 315if (!(rms_a < 0.1 )|| !(worst_a < 0.5 ))throw std::runtime_error (std::string (p .name )+ ": far from MMQ in the walk" ); 316} 317 318}// namespace 319 320int main (int argc ,char ** argv ) { 321try { 322#ifdef _WIN32 323_putenv_s ("STRATA_PF_FUSED" ,"1" ); 324#else 325setenv ("STRATA_PF_FUSED" ,"1" ,1 ); 326#endif 327int n = 0 ; 328if (cudaGetDeviceCount (& n )!= cudaSuccess || n == 0 ) { std::printf ("no CUDA device: skipped\n" );return 77 ; } 329if (!fused::native_supported (GGML_TYPE_IQ3_S ,GGML_TYPE_IQ4_NL )) { std::printf ("the fused kernels do not run on this device: skipped\n" );return 77 ; } 330if (!mmq::built ()) { std::printf ("no MMQ in this build\n" );return 1 ; } 331const char * only = nullptr ; 332for (int i = 1 ;i < argc ;++ i ) 333if (std::strncmp (argv [i ],"--only=" ,7 )== 0 )only = argv [i ]+ 7 ; 334const std::vector < Pair > pairs = { 335 {GGML_TYPE_IQ3_S ,GGML_TYPE_IQ4_NL ,"IQ3_S / IQ4_NL" }, {GGML_TYPE_IQ3_XXS ,GGML_TYPE_IQ4_NL ,"IQ3_XXS / IQ4_NL" }, 336 {GGML_TYPE_IQ2_XS ,GGML_TYPE_IQ4_NL ,"IQ2_XS / IQ4_NL" }, {GGML_TYPE_IQ2_S ,GGML_TYPE_Q2_0 ,"IQ2_S / Q2_0" }, 337 {GGML_TYPE_IQ2_XXS ,GGML_TYPE_Q2_0 ,"IQ2_XXS / Q2_0" }, {GGML_TYPE_IQ4_XS ,GGML_TYPE_Q2_0 ,"IQ4_XS / Q2_0" }, 338 {GGML_TYPE_IQ4_XS ,GGML_TYPE_IQ4_NL ,"IQ4_XS / IQ4_NL" }, {GGML_TYPE_IQ3_S ,GGML_TYPE_Q2_0 ,"IQ3_S / Q2_0" }}; 339const std::vector < Case > cases = {{55 ,512 ,0 ,0 }, {300 ,512 ,0 ,0 }, {1000 ,512 ,0 ,0 }, {2048 ,128 ,40 ,700 }}; 340cudaStream_t s = nullptr ; 341ck (cudaStreamCreateWithFlags (& s ,cudaStreamNonBlocking ),"stream" ); 342 mmq::Context ctx ; 343int ran = 0 ; 344uint32_t seed = 20261111 ; 345for (const Pair & p :pairs ) { 346if (only && std::string (p .name ).find (only )== std::string::npos )continue ; 347if (!fused::native_supported ((int )p .gu , (int )p .d )|| !mmq::supported ((int )p .gu )|| !mmq::supported ((int )p .d )) { 348 std::printf ("%s: not set up on this device (skipped)\n" ,p .name ); 349continue ; 350 } 351for (const Case & c :cases )run_case (p ,c ,ctx ,s ,seed ++ ); 352++ ran ; 353 } 354ck (cudaStreamDestroy (s ),"destroy" ); 355if (ran == 0 ) { std::printf ("no pair ran: skipped\n" );return 77 ; } 356 std::printf ("prefill fused group entry parity passed (%d pairs)\n" ,ran ); 357return 0 ; 358 }catch (const std::exception & e ) { 359 std::fprintf (stderr ,"prefill fused group entry parity failed: %s\n" ,e .what ()); 360return 1 ; 361 } 362}