char-fork/llama.cpp
git clone https://git.t4t.associates/char-fork/llama.cpp
814d84bc9
char/aliceai-t5-moe
1#include "set_rows.hpp" 2#include "cpy.hpp" 3 4#include "ggml-quants.h" 5 6#include <vector> 7 8namespace utils { 9template < typename T > 10static constexpr bool is_arithmetic_v () { 11return std::is_arithmetic_v < T > || std::is_same_v < T , sycl::half > 12#ifdef GGML_SYCL_HAS_BF16 13|| std ::is_same_v < T , sycl::ext::oneapi::bfloat16 > 14#endif 15 ; 16} 17} 18 19template < typename TIn ,typename TOut > 20static inline std::enable_if_t < utils::is_arithmetic_v < TIn > ()&& utils::is_arithmetic_v < TOut > (),void > 21convert (const char * src ,char * dst ) { 22auto src_val = * reinterpret_cast < const TIn *> (src ); 23auto dst_val = sycl::vec < TIn ,1 > (src_val ).template convert < TOut , sycl::rounding_mode::automatic > ()[0 ]; 24* reinterpret_cast < TOut *> (dst )= dst_val ; 25} 26 27#ifdef GGML_SYCL_HAS_BF16 28// sycl::vec::convert does not provide a half -> bfloat16 path, so route through float. 29template <> 30inline void convert < sycl::half , sycl::ext::oneapi::bfloat16 > (const char * src ,char * dst ) { 31const float tmp = sycl::vec < sycl::half ,1 > (* reinterpret_cast < const sycl::half *> (src )) 32 .template convert < float , sycl::rounding_mode::automatic > ()[0 ]; 33* reinterpret_cast < sycl::ext::oneapi::bfloat16 *> (dst )= sycl::ext::oneapi::bfloat16 (tmp ); 34} 35#endif 36 37template < typename TIn ,typename TIdx ,typename blockType ,int qk ,cpy_kernel_t cpyblck > 38static void set_rows_sycl_q (const char * __restrict__src0_d , 39const TIdx * __restrict__src1_d , 40blockType * __restrict__dst_d , 41// tensor dimensions src0 and src1 42const int64_t ne00 , 43const int64_t ne01 , 44const int64_t ne02 , 45const int64_t ne03 , 46const int64_t ne10 , 47const int64_t ne11 , 48const int64_t ne12 , 49const int64_t ne13 , 50// strides for src0 51const size_t nb00 , 52const size_t nb01 , 53const size_t nb02 , 54const size_t nb03 , 55// strides for src1 56const size_t nb10 , 57const size_t nb11 , 58const size_t nb12 , 59const size_t nb13 , 60// strides for dst 61const size_t nb1 , 62const size_t nb2 , 63const size_t nb3 , 64queue_ptr stream ) { 65const int64_t total_blocks = (ne00 * ne01 * ne02 * ne03 ) /qk ; 66constexpr int block_size = 256 ; 67const int64_t grid_size = ceil_div (total_blocks ,block_size ); 68 69stream -> parallel_for (sycl::nd_range < 1 > (grid_size * block_size ,block_size ), [= ](sycl::nd_item < 1 > item_ct1 ) { 70const int64_t i = item_ct1 .get_global_linear_id (); 71if (i >=total_blocks ) { 72return ; 73 } 74const int64_t i_base = i * qk ; 75const int64_t i03 = i_base / (ne00 * ne01 * ne02 ); 76const int64_t rem1 = i_base - i03 * (ne00 * ne01 * ne02 ); 77const int64_t i02 = rem1 / (ne00 * ne01 ); 78const int64_t rem2 = rem1 - i02 * ne00 * ne01 ; 79const int64_t i01 = rem2 /ne00 ; 80const int64_t i00 = rem2 - i01 * ne00 ; 81const int64_t i12 = i03 %ne12 ; 82const int64_t i11 = i02 %ne11 ; 83const int64_t i10 = i01 ; 84const size_t src_offset = calculate_offset < 3 > ({nb01 ,nb02 ,nb03 }, {i01 ,i02 ,i03 }); 85const char * src_block = src0_d + src_offset + i00 * sizeof (TIn ); 86const size_t src1_offset = calculate_offset < 3 > ({nb10 ,nb11 ,nb12 }, {i10 ,i11 ,i12 }); 87const int64_t dst_row = src1_d [src1_offset /sizeof (TIdx )]; 88const size_t dst_offset = 89calculate_offset < 3 > ({nb1 ,nb2 ,nb3 }, {dst_row ,i02 ,i03 })+ (i00 /qk )* sizeof (blockType ); 90char * dst_block = reinterpret_cast < char *> (reinterpret_cast < char *> (dst_d )+ dst_offset ); 91if constexpr (std::is_same_v < TIn ,float > ) { 92cpyblck (src_block ,dst_block ); 93 }else { 94float src_block_f32 [qk ]; 95const TIn * src_block_t = reinterpret_cast < const TIn *> (src_block ); 96for (int j = 0 ;j < qk ;++ j ) { 97src_block_f32 [j ]= (float )src_block_t [j ]; 98 } 99cpyblck (reinterpret_cast < const char *> (src_block_f32 ),dst_block ); 100 } 101 }); 102GGML_UNUSED (ne10 ); 103GGML_UNUSED (ne13 ); 104GGML_UNUSED (nb00 ); 105GGML_UNUSED (nb13 ); 106} 107 108template < typename blockType > 109using quantize_row_qk_t = void (* )(const float * ,blockType * ,int64_t ); 110 111using quantize_rows_f_t = size_t (* )(const float * ,void * ,int64_t ,int64_t ,const float * ); 112 113template < typename TIn ,typename TIdx ,typename blockType ,int qk ,quantize_row_qk_t < blockType > quantize_row > 114static void set_rows_sycl_qk_host ( 115const ggml_tensor * src0 , 116const ggml_tensor * src1 , 117ggml_tensor * dst , 118const int64_t ne00 , 119const int64_t ne01 , 120const int64_t ne02 , 121const int64_t ne03 , 122const int64_t ne11 , 123const int64_t ne12 , 124const size_t nb01 , 125const size_t nb02 , 126const size_t nb03 , 127const size_t nb10 , 128const size_t nb11 , 129const size_t nb12 , 130const size_t nb1 , 131const size_t nb2 , 132const size_t nb3 , 133queue_ptr stream ) { 134GGML_ASSERT (ne00 %qk == 0 ); 135 136const size_t src0_bytes = ggml_nbytes (src0 ); 137const size_t src1_bytes = ggml_nbytes (src1 ); 138 139 std::vector < char > src0_host (src0_bytes ); 140 std::vector < char > src1_host (src1_bytes ); 141 142stream -> memcpy (src0_host .data (),src0 -> data ,src0_bytes ); 143stream -> memcpy (src1_host .data (),src1 -> data ,src1_bytes ); 144stream -> wait (); 145 146 std::vector < float > src_row_f32 (ne00 ); 147const int64_t nblocks = ne00 /qk ; 148 std::vector < blockType > dst_row_q (nblocks ); 149 150for (int64_t i03 = 0 ;i03 < ne03 ;++ i03 ) { 151for (int64_t i02 = 0 ;i02 < ne02 ;++ i02 ) { 152for (int64_t i01 = 0 ;i01 < ne01 ;++ i01 ) { 153const int64_t i12 = i03 %ne12 ; 154const int64_t i11 = i02 %ne11 ; 155const int64_t i10 = i01 ; 156 157const size_t src1_offset = calculate_offset < 3 > ({nb10 ,nb11 ,nb12 }, {i10 ,i11 ,i12 }); 158const int64_t dst_row = * (const TIdx * ) (src1_host .data ()+ src1_offset ); 159 160const size_t src0_row_offset = calculate_offset < 3 > ({nb01 ,nb02 ,nb03 }, {i01 ,i02 ,i03 }); 161const TIn * src_row = reinterpret_cast < const TIn *> (src0_host .data ()+ src0_row_offset ); 162 163for (int64_t i00 = 0 ;i00 < ne00 ;++ i00 ) { 164src_row_f32 [i00 ]= (float )src_row [i00 ]; 165 } 166 167quantize_row (src_row_f32 .data (),dst_row_q .data (),ne00 ); 168 169const size_t dst_offset = calculate_offset < 3 > ({nb1 ,nb2 ,nb3 }, {dst_row ,i02 ,i03 }); 170stream -> memcpy ((char * )dst -> data + dst_offset ,dst_row_q .data (),nblocks * sizeof (blockType )); 171stream -> wait (); 172 } 173 } 174 } 175} 176 177template < typename TIn ,typename TIdx ,typename blockType ,int qk ,quantize_rows_f_t quantize_rows > 178static void set_rows_sycl_iq_host ( 179const ggml_tensor * src0 , 180const ggml_tensor * src1 , 181ggml_tensor * dst , 182const int64_t ne00 , 183const int64_t ne01 , 184const int64_t ne02 , 185const int64_t ne03 , 186const int64_t ne11 , 187const int64_t ne12 , 188const size_t nb01 , 189const size_t nb02 , 190const size_t nb03 , 191const size_t nb10 , 192const size_t nb11 , 193const size_t nb12 , 194const size_t nb1 , 195const size_t nb2 , 196const size_t nb3 , 197queue_ptr stream ) { 198GGML_ASSERT (ne00 %qk == 0 ); 199 200const size_t src0_bytes = ggml_nbytes (src0 ); 201const size_t src1_bytes = ggml_nbytes (src1 ); 202 203 std::vector < char > src0_host (src0_bytes ); 204 std::vector < char > src1_host (src1_bytes ); 205 206stream -> memcpy (src0_host .data (),src0 -> data ,src0_bytes ); 207stream -> memcpy (src1_host .data (),src1 -> data ,src1_bytes ); 208stream -> wait (); 209 210 std::vector < float > src_row_f32 (ne00 ); 211const int64_t nblocks = ne00 /qk ; 212 std::vector < blockType > dst_row_q (nblocks ); 213 214for (int64_t i03 = 0 ;i03 < ne03 ;++ i03 ) { 215for (int64_t i02 = 0 ;i02 < ne02 ;++ i02 ) { 216for (int64_t i01 = 0 ;i01 < ne01 ;++ i01 ) { 217const int64_t i12 = i03 %ne12 ; 218const int64_t i11 = i02 %ne11 ; 219const int64_t i10 = i01 ; 220 221const size_t src1_offset = calculate_offset < 3 > ({nb10 ,nb11 ,nb12 }, {i10 ,i11 ,i12 }); 222const int64_t dst_row = * (const TIdx * ) (src1_host .data ()+ src1_offset ); 223 224const size_t src0_row_offset = calculate_offset < 3 > ({nb01 ,nb02 ,nb03 }, {i01 ,i02 ,i03 }); 225const TIn * src_row = reinterpret_cast < const TIn *> (src0_host .data ()+ src0_row_offset ); 226 227for (int64_t i00 = 0 ;i00 < ne00 ;++ i00 ) { 228src_row_f32 [i00 ]= (float )src_row [i00 ]; 229 } 230 231quantize_rows (src_row_f32 .data (),dst_row_q .data (),1 ,ne00 ,nullptr ); 232 233const size_t dst_offset = calculate_offset < 3 > ({nb1 ,nb2 ,nb3 }, {dst_row ,i02 ,i03 }); 234stream -> memcpy ((char * )dst -> data + dst_offset ,dst_row_q .data (),nblocks * sizeof (blockType )); 235stream -> wait (); 236 } 237 } 238 } 239} 240 241template < typename TIn ,typename TIdx ,typename TOut > 242static void k_set_rows ( 243const char * __restrict__src0 ,const TIdx * __restrict__src1 ,char * __restrict__dst , 244const int64_t ne00 ,const int64_t ne01 ,const int64_t ne02 , 245const int64_t ne11 ,const int64_t ne12 , 246const size_t nb01 ,const size_t nb02 ,const size_t nb03 , 247const size_t nb10 ,const size_t nb11 ,const size_t nb12 , 248const size_t nb1 ,const size_t nb2 ,const size_t nb3 , 249const size_t src_type_size ,const size_t dst_type_size , 250const int64_t total_elements , 251const sycl::nd_item < 1 > & item_ct1 ) { 252 253const int64_t i = item_ct1 .get_global_linear_id (); 254if (i >=total_elements ) { 255return ; 256 } 257 258const int64_t i03 = i / (ne00 * ne01 * ne02 ); 259const int64_t i02 = (i - i03 * ne00 * ne01 * ne02 ) / (ne00 * ne01 ); 260const int64_t i01 = (i - i03 * ne00 * ne01 * ne02 - i02 * ne00 * ne01 ) /ne00 ; 261const int64_t i00 = i - i03 * ne00 * ne01 * ne02 - i02 * ne00 * ne01 - i01 * ne00 ; 262 263const int64_t i12 = i03 %ne12 ; 264const int64_t i11 = i02 %ne11 ; 265const int64_t i10 = i01 ; 266 267const int64_t dst_row = * (const TIdx * )((const char * )src1 + calculate_offset < 3 > ({nb10 ,nb11 ,nb12 }, {i10 ,i11 ,i12 })); 268 269const char * src0_row = src0 + calculate_offset < 3 > ({nb01 ,nb02 ,nb03 }, {i01 ,i02 ,i03 }); 270const char * src_elem = src0_row + i00 * src_type_size ; 271char * dst_row_ptr = dst + dst_row * nb1 + i02 * nb2 + i03 * nb3 ; 272char * dst_elem = dst_row_ptr + i00 * dst_type_size ; 273 274convert < TIn ,TOut > (src_elem ,dst_elem ); 275} 276 277template < typename TIn ,typename TIdx ,typename TOut > 278static void set_rows_sycl ( 279const char * src0_d ,const TIdx * src1_d ,char * dst_d , 280const int64_t ne00 ,const int64_t ne01 ,const int64_t ne02 ,const int64_t ne03 , 281const int64_t ne11 ,const int64_t ne12 ,const size_t nb01 ,const size_t nb02 ,const size_t nb03 , 282const size_t nb10 ,const size_t nb11 ,const size_t nb12 , 283const size_t nb1 ,const size_t nb2 ,const size_t nb3 , 284const size_t src_type_size ,const size_t dst_type_size , 285queue_ptr stream ) { 286 287const int64_t total_elements = ne00 * ne01 * ne02 * ne03 ; 288 289constexpr int block_size = 64 ; 290const int64_t grid_size = ceil_div (total_elements ,block_size ); 291 292stream -> parallel_for ( 293 sycl::nd_range < 1 > (grid_size * block_size ,block_size ), 294 [= ](sycl::nd_item < 1 > item_ct1 ) [[sycl ::reqd_sub_group_size (WARP_SIZE )]] { 295k_set_rows < TIn ,TIdx ,TOut > ( 296src0_d ,src1_d ,dst_d , 297ne00 ,ne01 ,ne02 , 298ne11 ,ne12 , 299nb01 ,nb02 ,nb03 , 300nb10 ,nb11 ,nb12 , 301nb1 ,nb2 ,nb3 , 302src_type_size ,dst_type_size , 303total_elements , 304item_ct1 305 ); 306 } 307 ); 308} 309 310template < typename TIn ,typename TIdx > 311static void set_rows_sycl (ggml_backend_sycl_context & ctx ,const ggml_tensor * src0 ,const ggml_tensor * src1 ,ggml_tensor * dst ) { 312const char * src0_d = (const char * )src0 -> data ; 313const TIdx * src1_d = (const TIdx * )src1 -> data ; 314 315GGML_TENSOR_BINARY_OP_LOCALS 316 317 dpct::queue_ptr stream = ctx .stream (); 318switch (dst -> type ) { 319case GGML_TYPE_F32 : 320set_rows_sycl < TIn ,TIdx ,float > ( 321src0_d ,src1_d , (char * )dst -> data , 322ne00 ,ne01 ,ne02 ,ne03 , 323ne11 ,ne12 , 324nb01 ,nb02 ,nb03 , 325nb10 ,nb11 ,nb12 , 326nb1 ,nb2 ,nb3 , 327sizeof (TIn ),sizeof (float ), 328stream 329 ); 330break ; 331case GGML_TYPE_F16 : 332 dpct::has_capability_or_fail (stream -> get_device (), { sycl::aspect::fp16 }); 333set_rows_sycl < TIn ,TIdx , sycl::half > ( 334src0_d ,src1_d , (char * )dst -> data , 335ne00 ,ne01 ,ne02 ,ne03 , 336ne11 ,ne12 , 337nb01 ,nb02 ,nb03 , 338nb10 ,nb11 ,nb12 , 339nb1 ,nb2 ,nb3 , 340sizeof (TIn ),sizeof (sycl::half ), 341stream 342 ); 343break ; 344#ifdef GGML_SYCL_HAS_BF16 345case GGML_TYPE_BF16 : 346set_rows_sycl < TIn ,TIdx , sycl::ext::oneapi::bfloat16 > ( 347src0_d ,src1_d , (char * )dst -> data , 348ne00 ,ne01 ,ne02 ,ne03 , 349ne11 ,ne12 , 350nb01 ,nb02 ,nb03 , 351nb10 ,nb11 ,nb12 , 352nb1 ,nb2 ,nb3 , 353sizeof (TIn ),sizeof (sycl::ext::oneapi::bfloat16 ), 354stream 355 ); 356break ; 357#endif 358case GGML_TYPE_Q8_0 : 359set_rows_sycl_q < TIn ,TIdx ,block_q8_0 ,QK8_0 ,cpy_blck_f32_q8_0 > ( 360src0_d ,src1_d , (block_q8_0 * )dst -> data ,ne00 ,ne01 ,ne02 ,ne03 , 361ne10 ,ne11 ,ne12 ,ne13 ,nb00 ,nb01 , 362nb02 ,nb03 ,nb10 ,nb11 ,nb12 ,nb13 ,nb1 ,nb2 ,nb3 ,stream ); 363break ; 364case GGML_TYPE_Q1_0 : 365set_rows_sycl_q < TIn ,TIdx ,block_q1_0 ,QK1_0 ,cpy_blck_f32_q1_0 > ( 366src0_d ,src1_d , (block_q1_0 * )dst -> data ,ne00 ,ne01 ,ne02 ,ne03 , 367ne10 ,ne11 ,ne12 ,ne13 ,nb00 ,nb01 , 368nb02 ,nb03 ,nb10 ,nb11 ,nb12 ,nb13 ,nb1 ,nb2 ,nb3 ,stream ); 369break ; 370case GGML_TYPE_Q2_0 : 371set_rows_sycl_q < TIn ,TIdx ,block_q2_0 ,QK2_0 ,cpy_blck_f32_q2_0 > ( 372src0_d ,src1_d , (block_q2_0 * )dst -> data ,ne00 ,ne01 ,ne02 ,ne03 , 373ne10 ,ne11 ,ne12 ,ne13 ,nb00 ,nb01 , 374nb02 ,nb03 ,nb10 ,nb11 ,nb12 ,nb13 ,nb1 ,nb2 ,nb3 ,stream ); 375break ; 376case GGML_TYPE_Q5_1 : 377set_rows_sycl_q < TIn ,TIdx ,block_q5_1 ,QK5_1 ,cpy_blck_f32_q5_1 > ( 378src0_d ,src1_d , (block_q5_1 * )dst -> data ,ne00 ,ne01 ,ne02 ,ne03 , 379ne10 ,ne11 ,ne12 ,ne13 ,nb00 ,nb01 , 380nb02 ,nb03 ,nb10 ,nb11 ,nb12 ,nb13 ,nb1 ,nb2 ,nb3 ,stream ); 381break ; 382case GGML_TYPE_Q5_0 : 383set_rows_sycl_q < TIn ,TIdx ,block_q5_0 ,QK5_0 ,cpy_blck_f32_q5_0 > ( 384src0_d ,src1_d , (block_q5_0 * )dst -> data ,ne00 ,ne01 ,ne02 ,ne03 , 385ne10 ,ne11 ,ne12 ,ne13 ,nb00 ,nb01 , 386nb02 ,nb03 ,nb10 ,nb11 ,nb12 ,nb13 ,nb1 ,nb2 ,nb3 ,stream ); 387break ; 388case GGML_TYPE_Q4_1 : 389set_rows_sycl_q < TIn ,TIdx ,block_q4_1 ,QK4_1 ,cpy_blck_f32_q4_1 > ( 390src0_d ,src1_d , (block_q4_1 * )dst -> data ,ne00 ,ne01 ,ne02 ,ne03 , 391ne10 ,ne11 ,ne12 ,ne13 ,nb00 ,nb01 , 392nb02 ,nb03 ,nb10 ,nb11 ,nb12 ,nb13 ,nb1 ,nb2 ,nb3 ,stream ); 393break ; 394case GGML_TYPE_Q4_0 : 395set_rows_sycl_q < TIn ,TIdx ,block_q4_0 ,QK4_0 ,cpy_blck_f32_q4_0 > ( 396src0_d ,src1_d , (block_q4_0 * )dst -> data ,ne00 ,ne01 ,ne02 ,ne03 , 397ne10 ,ne11 ,ne12 ,ne13 ,nb00 ,nb01 , 398nb02 ,nb03 ,nb10 ,nb11 ,nb12 ,nb13 ,nb1 ,nb2 ,nb3 ,stream ); 399break ; 400case GGML_TYPE_IQ4_NL : 401set_rows_sycl_q < TIn ,TIdx ,block_iq4_nl ,QK4_NL ,cpy_blck_f32_iq4_nl > ( 402src0_d ,src1_d , (block_iq4_nl * )dst -> data ,ne00 ,ne01 ,ne02 ,ne03 , 403ne10 ,ne11 ,ne12 ,ne13 ,nb00 ,nb01 , 404nb02 ,nb03 ,nb10 ,nb11 ,nb12 ,nb13 ,nb1 ,nb2 ,nb3 ,stream ); 405break ; 406case GGML_TYPE_MXFP4 : 407set_rows_sycl_q < TIn ,TIdx ,block_mxfp4 ,QK_MXFP4 ,cpy_blck_f32_mxfp4 > ( 408src0_d ,src1_d , (block_mxfp4 * )dst -> data ,ne00 ,ne01 ,ne02 ,ne03 , 409ne10 ,ne11 ,ne12 ,ne13 ,nb00 ,nb01 , 410nb02 ,nb03 ,nb10 ,nb11 ,nb12 ,nb13 ,nb1 ,nb2 ,nb3 ,stream ); 411break ; 412case GGML_TYPE_NVFP4 : 413set_rows_sycl_q < TIn ,TIdx ,block_nvfp4 ,QK_NVFP4 ,cpy_blck_f32_nvfp4 > ( 414src0_d ,src1_d , (block_nvfp4 * )dst -> data ,ne00 ,ne01 ,ne02 ,ne03 , 415ne10 ,ne11 ,ne12 ,ne13 ,nb00 ,nb01 , 416nb02 ,nb03 ,nb10 ,nb11 ,nb12 ,nb13 ,nb1 ,nb2 ,nb3 ,stream ); 417break ; 418case GGML_TYPE_Q2_K : 419set_rows_sycl_qk_host < TIn ,TIdx ,block_q2_K ,QK_K ,quantize_row_q2_K_ref > ( 420src0 ,src1 ,dst , 421ne00 ,ne01 ,ne02 ,ne03 , 422ne11 ,ne12 , 423nb01 ,nb02 ,nb03 , 424nb10 ,nb11 ,nb12 , 425nb1 ,nb2 ,nb3 , 426stream ); 427break ; 428case GGML_TYPE_Q3_K : 429set_rows_sycl_qk_host < TIn ,TIdx ,block_q3_K ,QK_K ,quantize_row_q3_K_ref > ( 430src0 ,src1 ,dst , 431ne00 ,ne01 ,ne02 ,ne03 , 432ne11 ,ne12 , 433nb01 ,nb02 ,nb03 , 434nb10 ,nb11 ,nb12 , 435nb1 ,nb2 ,nb3 , 436stream ); 437break ; 438case GGML_TYPE_Q4_K : 439set_rows_sycl_qk_host < TIn ,TIdx ,block_q4_K ,QK_K ,quantize_row_q4_K_ref > ( 440src0 ,src1 ,dst , 441ne00 ,ne01 ,ne02 ,ne03 , 442ne11 ,ne12 , 443nb01 ,nb02 ,nb03 , 444nb10 ,nb11 ,nb12 , 445nb1 ,nb2 ,nb3 , 446stream ); 447break ; 448case GGML_TYPE_Q5_K : 449set_rows_sycl_qk_host < TIn ,TIdx ,block_q5_K ,QK_K ,quantize_row_q5_K_ref > ( 450src0 ,src1 ,dst , 451ne00 ,ne01 ,ne02 ,ne03 , 452ne11 ,ne12 , 453nb01 ,nb02 ,nb03 , 454nb10 ,nb11 ,nb12 , 455nb1 ,nb2 ,nb3 , 456stream ); 457break ; 458case GGML_TYPE_Q6_K : 459set_rows_sycl_qk_host < TIn ,TIdx ,block_q6_K ,QK_K ,quantize_row_q6_K_ref > ( 460src0 ,src1 ,dst , 461ne00 ,ne01 ,ne02 ,ne03 , 462ne11 ,ne12 , 463nb01 ,nb02 ,nb03 , 464nb10 ,nb11 ,nb12 , 465nb1 ,nb2 ,nb3 , 466stream ); 467break ; 468case GGML_TYPE_IQ2_XXS : 469set_rows_sycl_iq_host < TIn ,TIdx ,block_iq2_xxs ,QK_K ,quantize_iq2_xxs > ( 470src0 ,src1 ,dst , 471ne00 ,ne01 ,ne02 ,ne03 , 472ne11 ,ne12 , 473nb01 ,nb02 ,nb03 , 474nb10 ,nb11 ,nb12 , 475nb1 ,nb2 ,nb3 , 476stream ); 477break ; 478case GGML_TYPE_IQ2_XS : 479set_rows_sycl_iq_host < TIn ,TIdx ,block_iq2_xs ,QK_K ,quantize_iq2_xs > ( 480src0 ,src1 ,dst , 481ne00 ,ne01 ,ne02 ,ne03 , 482ne11 ,ne12 , 483nb01 ,nb02 ,nb03 , 484nb10 ,nb11 ,nb12 , 485nb1 ,nb2 ,nb3 , 486stream ); 487break ; 488case GGML_TYPE_IQ2_S : 489set_rows_sycl_iq_host < TIn ,TIdx ,block_iq2_s ,QK_K ,quantize_iq2_s > ( 490src0 ,src1 ,dst , 491ne00 ,ne01 ,ne02 ,ne03 , 492ne11 ,ne12 , 493nb01 ,nb02 ,nb03 , 494nb10 ,nb11 ,nb12 , 495nb1 ,nb2 ,nb3 , 496stream ); 497break ; 498case GGML_TYPE_IQ3_XXS : 499set_rows_sycl_qk_host < TIn ,TIdx ,block_iq3_xxs ,QK_K ,quantize_row_iq3_xxs_ref > ( 500src0 ,src1 ,dst , 501ne00 ,ne01 ,ne02 ,ne03 , 502ne11 ,ne12 , 503nb01 ,nb02 ,nb03 , 504nb10 ,nb11 ,nb12 , 505nb1 ,nb2 ,nb3 , 506stream ); 507break ; 508case GGML_TYPE_IQ3_S : 509set_rows_sycl_qk_host < TIn ,TIdx ,block_iq3_s ,QK_K ,quantize_row_iq3_s_ref > ( 510src0 ,src1 ,dst , 511ne00 ,ne01 ,ne02 ,ne03 , 512ne11 ,ne12 , 513nb01 ,nb02 ,nb03 , 514nb10 ,nb11 ,nb12 , 515nb1 ,nb2 ,nb3 , 516stream ); 517break ; 518case GGML_TYPE_IQ1_S : 519set_rows_sycl_iq_host < TIn ,TIdx ,block_iq1_s ,QK_K ,quantize_iq1_s > ( 520src0 ,src1 ,dst , 521ne00 ,ne01 ,ne02 ,ne03 , 522ne11 ,ne12 , 523nb01 ,nb02 ,nb03 , 524nb10 ,nb11 ,nb12 , 525nb1 ,nb2 ,nb3 , 526stream ); 527break ; 528case GGML_TYPE_IQ1_M : 529set_rows_sycl_iq_host < TIn ,TIdx ,block_iq1_m ,QK_K ,quantize_iq1_m > ( 530src0 ,src1 ,dst , 531ne00 ,ne01 ,ne02 ,ne03 , 532ne11 ,ne12 , 533nb01 ,nb02 ,nb03 , 534nb10 ,nb11 ,nb12 , 535nb1 ,nb2 ,nb3 , 536stream ); 537break ; 538case GGML_TYPE_IQ4_XS : 539set_rows_sycl_qk_host < TIn ,TIdx ,block_iq4_xs ,QK_K ,quantize_row_iq4_xs_ref > ( 540src0 ,src1 ,dst , 541ne00 ,ne01 ,ne02 ,ne03 , 542ne11 ,ne12 , 543nb01 ,nb02 ,nb03 , 544nb10 ,nb11 ,nb12 , 545nb1 ,nb2 ,nb3 , 546stream ); 547break ; 548default : 549GGML_ABORT ("Unsupported tensor type: src0 %s src1 %s dst %s" ,ggml_type_name (dst -> src [0 ]-> type ), 550ggml_type_name (dst -> src [1 ]-> type ),ggml_type_name (dst -> type )); 551break ; 552 } 553} 554 555void ggml_sycl_op_set_rows (ggml_backend_sycl_context & ctx ,ggml_tensor * dst ) { 556scope_op_debug_print scope_dbg_print (__func__ ,dst ,/*num_src=*/ 2 ); 557const ggml_tensor * src0 = dst -> src [0 ]; 558const ggml_tensor * src1 = dst -> src [1 ]; 559 560GGML_ASSERT (dst -> src [0 ]-> type == GGML_TYPE_F32 || dst -> src [0 ]-> type == GGML_TYPE_F16 ); 561GGML_ASSERT (dst -> src [1 ]-> type == GGML_TYPE_I64 || dst -> src [1 ]-> type == GGML_TYPE_I32 ); 562 563// dispatch on the index type (src1) and the source value type (src0) 564if (src0 -> type == GGML_TYPE_F16 ) { 565if (src1 -> type == GGML_TYPE_I64 ) { 566set_rows_sycl < sycl::half ,int64_t > (ctx ,src0 ,src1 ,dst ); 567 }else { 568set_rows_sycl < sycl::half ,int32_t > (ctx ,src0 ,src1 ,dst ); 569 } 570 }else { 571if (src1 -> type == GGML_TYPE_I64 ) { 572set_rows_sycl < float ,int64_t > (ctx ,src0 ,src1 ,dst ); 573 }else { 574set_rows_sycl < float ,int32_t > (ctx ,src0 ,src1 ,dst ); 575 } 576 } 577}