char-fork/llama.cpp
git clone https://git.t4t.associates/char-fork/llama.cpp
2e1f0a889
char/aliceai-t5-moe
1#define GGML_COMMON_IMPL_C 2#include "ggml-common.h" 3#include "ggml-quants.h" 4#include "ggml-impl.h" 5#include "ggml-cpu.h" 6#include "simd-mappings.h" 7 8#include "../../quants.h" 9#include "../../ggml-cpu-impl.h" 10 11#include <math.h> 12#include <string.h> 13#include <assert.h> 14#include <float.h> 15#include <stdlib.h> // for qsort 16#include <stdio.h> // for GGML_ASSERT 17 18#define GROUP_MAX_EPS 1e-15f 19#define GROUP_MAX_EPS_IQ3_XXS 1e-8f 20#define GROUP_MAX_EPS_IQ2_S 1e-8f 21#define GROUP_MAX_EPS_IQ1_M 1e-7f 22#define GROUP_MAX_EPS_IQ1_S 1e-12f 23 24#define UNUSED GGML_UNUSED 25 26#if defined(__POWER9_VECTOR__ ) 27#define B1 (c ,s ,n ) 0x ## n ## c , 0x ## n ## s 28#define B2 (c ,s ,n ) B1(c,s,n ## c), B1(c,s,n ## s) 29#define B3 (c ,s ,n ) B2(c,s,n ## c), B2(c,s,n ## s) 30#define B4 (c ,s ,n ) B3(c,s,n ## c), B3(c,s,n ## s) 31#define B5 (c ,s ,n ) B4(c,s,n ## c), B4(c,s,n ## s) 32#define B6 (c ,s ,n ) B5(c,s,n ## c), B5(c,s,n ## s) 33#define B7 (c ,s ,n ) B6(c,s,n ## c), B6(c,s,n ## s) 34#define B8 (c ,s ) B7(c,s, c), B7(c,s, s) 35 36// precomputed tables for expanding 8bits to 8 bytes: 37static const uint64_t table_b2b_0 [1 <<8 ]= {B8 (00 ,10 ) };// ( b) << 4 38static const uint64_t table_b2b_1 [1 <<8 ]= {B8 (10 ,00 ) };// (!b) << 4 39#endif 40 41void quantize_row_q8_0 (const float * GGML_RESTRICT x ,void * GGML_RESTRICT vy ,int64_t k ) { 42assert (QK8_0 == 32 ); 43assert (k %QK8_0 == 0 ); 44const int nb = k /QK8_0 ; 45 46block_q8_0 * GGML_RESTRICT y = vy ; 47 48#if defined(__POWER9_VECTOR__ ) 49for (int i = 0 ;i < nb ;i ++ ) { 50vector float srcv [8 ]; 51vector float asrcv [8 ]; 52vector float amaxv [8 ]; 53vector signed int vi [8 ]; 54 55for (int j = 0 ;j < 8 ;j ++ )srcv [j ]= vec_xl (0 ,x + i * 32 + 4 * j ); 56for (int j = 0 ;j < 8 ;j ++ )asrcv [j ]= vec_abs (srcv [j ]); 57 58for (int j = 0 ;j < 4 ;j ++ )amaxv [2 * j ]= vec_max (asrcv [2 * j ],asrcv [2 * j + 1 ]); 59for (int j = 0 ;j < 2 ;j ++ )amaxv [4 * j ]= vec_max (amaxv [4 * j ],amaxv [4 * j + 2 ]); 60for (int j = 0 ;j < 1 ;j ++ )amaxv [8 * j ]= vec_max (amaxv [8 * j ],amaxv [8 * j + 4 ]); 61 62const float amax = MAX (MAX (vec_extract (amaxv [0 ],0 ), 63vec_extract (amaxv [0 ],1 )), 64MAX (vec_extract (amaxv [0 ],2 ), 65vec_extract (amaxv [0 ],3 ))); 66 67const float d = amax / ((1 <<7 )- 1 ); 68const float id = d ?1.0f /d :0.0f ; 69const vector float vid = vec_splats (id ); 70 71y [i ].d = GGML_CPU_FP32_TO_FP16 (d ); 72 73for (int j = 0 ;j < 8 ;j ++ ) { 74const vector float v = vec_round (vec_mul (srcv [j ],vid )); 75vi [j ]= vec_cts (v ,0 ); 76 } 77vec_xst (vec_pack (vec_pack (vi [0 ],vi [1 ]),vec_pack (vi [2 ],vi [3 ])),0 ,& y [i ].qs [0 ]); 78vec_xst (vec_pack (vec_pack (vi [4 ],vi [5 ]),vec_pack (vi [6 ],vi [7 ])),16 ,& y [i ].qs [0 ]); 79 } 80#else 81GGML_UNUSED (nb ); 82// scalar 83quantize_row_q8_0_ref (x ,y ,k ); 84#endif 85} 86 87void quantize_row_q8_1 (const float * GGML_RESTRICT x ,void * GGML_RESTRICT vy ,int64_t k ) { 88assert (k %QK8_1 == 0 ); 89const int nb = k /QK8_1 ; 90 91block_q8_1 * GGML_RESTRICT y = vy ; 92 93#if defined(__POWER9_VECTOR__ ) 94for (int i = 0 ;i < nb ;i ++ ) { 95vector float srcv [8 ]; 96vector float asrcv [8 ]; 97vector float amaxv [8 ]; 98vector signed int vi [8 ]; 99 100for (int j = 0 ;j < 8 ;j ++ )srcv [j ]= vec_xl (0 ,x + i * 32 + 4 * j ); 101for (int j = 0 ;j < 8 ;j ++ )asrcv [j ]= vec_abs (srcv [j ]); 102 103for (int j = 0 ;j < 4 ;j ++ )amaxv [2 * j ]= vec_max (asrcv [2 * j ],asrcv [2 * j + 1 ]); 104for (int j = 0 ;j < 2 ;j ++ )amaxv [4 * j ]= vec_max (amaxv [4 * j ],amaxv [4 * j + 2 ]); 105for (int j = 0 ;j < 1 ;j ++ )amaxv [8 * j ]= vec_max (amaxv [8 * j ],amaxv [8 * j + 4 ]); 106 107const float amax = MAX (MAX (vec_extract (amaxv [0 ],0 ), 108vec_extract (amaxv [0 ],1 )), 109MAX (vec_extract (amaxv [0 ],2 ), 110vec_extract (amaxv [0 ],3 ))); 111 112const float d = amax / ((1 <<7 )- 1 ); 113const float id = d ?1.0f /d :0.0f ; 114const vector float vid = vec_splats (id ); 115 116y [i ].d = GGML_CPU_FP32_TO_FP16 (d ); 117 118vector int accv = vec_splats (0 ); 119 120for (int j = 0 ;j < 8 ;j ++ ) { 121const vector float v = vec_round (vec_mul (srcv [j ],vid )); 122vi [j ]= vec_cts (v ,0 ); 123 124accv = vec_add (accv ,vi [j ]); 125 } 126vec_xst (vec_pack (vec_pack (vi [0 ],vi [1 ]),vec_pack (vi [2 ],vi [3 ])),0 ,& y [i ].qs [0 ]); 127vec_xst (vec_pack (vec_pack (vi [4 ],vi [5 ]),vec_pack (vi [6 ],vi [7 ])),16 ,& y [i ].qs [0 ]); 128 129accv = vec_add (accv ,vec_sld (accv ,accv ,4 )); 130accv = vec_add (accv ,vec_sld (accv ,accv ,8 )); 131y [i ].s = GGML_CPU_FP32_TO_FP16 (d * vec_extract (accv ,0 )); 132 } 133 134#else 135GGML_UNUSED (nb ); 136// scalar 137quantize_row_q8_1_ref (x ,y ,k ); 138#endif 139} 140 141 142//===================================== Dot products ================================= 143 144void ggml_vec_dot_q4_0_q8_0 (int n ,float * GGML_RESTRICT s ,size_t bs ,const void * GGML_RESTRICT vx ,size_t bx ,const void * GGML_RESTRICT vy ,size_t by ,int nrc ) { 145const int qk = QK8_0 ; 146const int nb = n /qk ; 147 148assert (n %qk == 0 ); 149assert (nrc == 1 ); 150UNUSED (nrc ); 151UNUSED (bx ); 152UNUSED (by ); 153UNUSED (bs ); 154 155const block_q4_0 * GGML_RESTRICT x = vx ; 156const block_q8_0 * GGML_RESTRICT y = vy ; 157 158int ib = 0 ; 159float sumf = 0 ; 160 161#if defined(__POWER9_VECTOR__ ) 162const vector signed char lowMask = vec_splats ((signed char )0xF ); 163const vector signed int v0 = vec_splats ((int32_t )0 ); 164const vector unsigned char v4 = vec_splats ((unsigned char )0x4 ); 165const vector signed char v8 = vec_splats ((signed char )0x8 ); 166 167vector float vsumf0 = vec_splats (0.0f ); 168 169#pragma GCC unroll 8 170for (;ib < nb ;++ ib ) { 171__builtin_prefetch (x [ib ].qs ,0 ,1 ); 172__builtin_prefetch (y [ib ].qs ,0 ,1 ); 173 174vector float vxd = vec_splats (GGML_CPU_FP16_TO_FP32 (x [ib ].d )); 175vector float vyd = vec_splats (GGML_CPU_FP16_TO_FP32 (y [ib ].d )); 176vector float vd = vec_mul (vxd ,vyd ); 177 178vector signed char qxs = (vector signed char )vec_xl (0 ,x [ib ].qs ); 179vector signed char q8y0 = vec_xl (0 ,y [ib ].qs ); 180vector signed char q8y1 = vec_xl (16 ,y [ib ].qs ); 181 182vector signed char q4x0 = vec_and (qxs ,lowMask ); 183vector signed char q4x1 = vec_sr (qxs ,v4 ); 184 185q4x0 = vec_sub (q4x0 ,v8 ); 186q4x1 = vec_sub (q4x1 ,v8 ); 187 188vector signed short qv0 = vec_add (vec_mule (q4x0 ,q8y0 ),vec_mulo (q4x0 ,q8y0 )); 189vector signed short qv1 = vec_add (vec_mule (q4x1 ,q8y1 ),vec_mulo (q4x1 ,q8y1 )); 190 191vector signed int vsumi0 = v0 ; 192 193vsumi0 = vec_sum4s (qv0 ,vsumi0 ); 194vsumi0 = vec_sum4s (qv1 ,vsumi0 ); 195 196vsumf0 = vec_madd (vec_ctf (vsumi0 ,0 ),vd ,vsumf0 ); 197 } 198 199vsumf0 = vec_add (vsumf0 ,vec_sld (vsumf0 ,vsumf0 ,4 )); 200vsumf0 = vec_add (vsumf0 ,vec_sld (vsumf0 ,vsumf0 ,8 )); 201 202sumf = vec_extract (vsumf0 ,0 ); 203 204* s = sumf ; 205#else 206UNUSED (x ); 207UNUSED (y ); 208UNUSED (ib ); 209UNUSED (sumf ); 210ggml_vec_dot_q4_0_q8_0_generic (n ,s ,bs ,vx ,bx ,vy ,by ,nrc ); 211#endif 212} 213 214void ggml_vec_dot_q4_1_q8_1 (int n ,float * GGML_RESTRICT s ,size_t bs ,const void * GGML_RESTRICT vx ,size_t bx ,const void * GGML_RESTRICT vy ,size_t by ,int nrc ) { 215const int qk = QK8_1 ; 216const int nb = n /qk ; 217 218assert (n %qk == 0 ); 219assert (nrc == 1 ); 220UNUSED (nrc ); 221UNUSED (bx ); 222UNUSED (by ); 223UNUSED (bs ); 224 225const block_q4_1 * GGML_RESTRICT x = vx ; 226const block_q8_1 * GGML_RESTRICT y = vy ; 227 228int ib = 0 ; 229float sumf = 0 ; 230 231#if defined(__POWER9_VECTOR__ ) 232const vector signed char lowMask = vec_splats ((signed char )0xF ); 233const vector signed int v0 = vec_splats ((int32_t )0 ); 234const vector unsigned char v4 = vec_splats ((unsigned char )0x4 ); 235 236vector float vsumf0 = vec_splats (0.0f ); 237 238#pragma GCC unroll 4 239for (;ib < nb ;++ ib ) { 240__builtin_prefetch (x [ib ].qs ,0 ,1 ); 241__builtin_prefetch (y [ib ].qs ,0 ,1 ); 242 243vector float vxd = vec_splats (GGML_CPU_FP16_TO_FP32 (x [ib ].d )); 244vector float vyd = vec_splats (GGML_CPU_FP16_TO_FP32 (y [ib ].d )); 245vector float vd = vec_mul (vxd ,vyd ); 246 247vector float vxmin = vec_splats (GGML_CPU_FP16_TO_FP32 (x [ib ].m )); 248vector float vys = {GGML_CPU_FP16_TO_FP32 (y [ib ].s ),0.0f ,0.0f ,0.0f }; 249vsumf0 = vec_madd (vxmin ,vys ,vsumf0 ); 250 251vector signed char qxs = (vector signed char )vec_xl (0 ,x [ib ].qs ); 252vector signed char q8y0 = vec_xl (0 ,y [ib ].qs ); 253vector signed char q8y1 = vec_xl (16 ,y [ib ].qs ); 254 255vector unsigned char q4x0 = (vector unsigned char )vec_and (qxs ,lowMask ); 256vector unsigned char q4x1 = (vector unsigned char )vec_sr (qxs ,v4 ); 257 258vector signed int vsumi0 = v0 ; 259 260vsumi0 = vec_msum (q8y0 ,q4x0 ,vsumi0 ); 261vsumi0 = vec_msum (q8y1 ,q4x1 ,vsumi0 ); 262 263vsumf0 = vec_madd (vec_ctf (vsumi0 ,0 ),vd ,vsumf0 ); 264 } 265 266vsumf0 = vec_add (vsumf0 ,vec_sld (vsumf0 ,vsumf0 ,4 )); 267vsumf0 = vec_add (vsumf0 ,vec_sld (vsumf0 ,vsumf0 ,8 )); 268 269sumf = vec_extract (vsumf0 ,0 ); 270 271* s = sumf ; 272#else 273UNUSED (x ); 274UNUSED (y ); 275UNUSED (ib ); 276UNUSED (sumf ); 277ggml_vec_dot_q4_1_q8_1_generic (n ,s ,bs ,vx ,bx ,vy ,by ,nrc ); 278#endif 279} 280 281void ggml_vec_dot_mxfp4_q8_0 (int n ,float * GGML_RESTRICT s ,size_t bs ,const void * GGML_RESTRICT vx ,size_t bx ,const void * GGML_RESTRICT vy ,size_t by ,int nrc ) { 282assert (nrc == 1 ); 283UNUSED (nrc ); 284UNUSED (bx ); 285UNUSED (by ); 286UNUSED (bs ); 287assert (n %QK_MXFP4 == 0 ); 288static_assert (QK_MXFP4 == QK8_0 ,"QK_MXFP4 and QK8_0 must be the same" ); 289 290const block_mxfp4 * GGML_RESTRICT x = vx ; 291const block_q8_0 * GGML_RESTRICT y = vy ; 292 293const int nb = n /QK_MXFP4 ; 294 295int ib = 0 ; 296float sumf = 0 ; 297 298#if defined(__POWER9_VECTOR__ ) 299const vector signed char lowMask = vec_splats ((signed char )0xF ); 300const vector unsigned char vshift4 = vec_splats ((unsigned char )4 ); 301vector float vsumf0 = vec_splats (0.0f ); 302 303vector signed char kv = vec_xl (0 , (const signed char * )kvalues_mxfp4 ); 304 305#pragma GCC unroll 8 306for (;ib < nb ;++ ib ) { 307__builtin_prefetch (x [ib ].qs ,0 ,1 ); 308__builtin_prefetch (y [ib ].qs ,0 ,1 ); 309 310vector float vyd = vec_splats (GGML_CPU_FP16_TO_FP32 (y [ib ].d )* 311GGML_E8M0_TO_FP32_HALF (x [ib ].e )); 312 313vector signed char q8y0 = vec_xl (0 ,y [ib ].qs ); 314vector signed char q8y1 = vec_xl (16 ,y [ib ].qs ); 315 316vector signed char qxs = (vector signed char )vec_xl (0 ,x [ib ].qs ); 317 318vector unsigned char lo_nibbles = (vector unsigned char )vec_and (qxs ,lowMask ); 319vector unsigned char hi_nibbles = (vector unsigned char )vec_sr (qxs ,vshift4 ); 320 321vector signed char q4x0 = vec_perm (kv ,kv ,lo_nibbles ); 322vector signed char q4x1 = vec_perm (kv ,kv ,hi_nibbles ); 323 324vector signed short qv0 = vec_add (vec_mule (q4x0 ,q8y0 ),vec_mulo (q4x0 ,q8y0 )); 325vector signed short qv1 = vec_add (vec_mule (q4x1 ,q8y1 ),vec_mulo (q4x1 ,q8y1 )); 326 327vector signed int vsumi0 = vec_splats ((int32_t )0 ); 328vsumi0 = vec_sum4s (qv0 ,vsumi0 ); 329vsumi0 = vec_sum4s (qv1 ,vsumi0 ); 330 331vsumf0 = vec_madd (vec_ctf (vsumi0 ,0 ),vyd ,vsumf0 ); 332 } 333 334vsumf0 = vec_add (vsumf0 ,vec_sld (vsumf0 ,vsumf0 ,4 )); 335vsumf0 = vec_add (vsumf0 ,vec_sld (vsumf0 ,vsumf0 ,8 )); 336sumf = vec_extract (vsumf0 ,0 ); 337* s = sumf ; 338#else 339UNUSED (x ); 340UNUSED (y ); 341UNUSED (ib ); 342UNUSED (sumf ); 343ggml_vec_dot_mxfp4_q8_0_generic (n ,s ,bs ,vx ,bx ,vy ,by ,nrc ); 344#endif 345} 346 347void ggml_vec_dot_q5_0_q8_0 (int n ,float * GGML_RESTRICT s ,size_t bs ,const void * GGML_RESTRICT vx ,size_t bx ,const void * GGML_RESTRICT vy ,size_t by ,int nrc ) { 348const int qk = QK8_0 ; 349const int nb = n /qk ; 350 351int ib = 0 ; 352float sumf = 0 ; 353 354assert (n %qk == 0 ); 355assert (qk == QK5_0 ); 356assert (nrc == 1 ); 357UNUSED (nrc ); 358UNUSED (bx ); 359UNUSED (by ); 360UNUSED (bs ); 361 362const block_q5_0 * GGML_RESTRICT x = vx ; 363const block_q8_0 * GGML_RESTRICT y = vy ; 364 365#if defined(__POWER9_VECTOR__ ) 366const vector signed char lowMask = vec_splats ((signed char )0xF ); 367const vector unsigned char v4 = vec_splats ((unsigned char )4 ); 368 369vector float vsumf0 = vec_splats (0.0f ); 370 371#pragma GCC unroll 4 372for (;ib < nb ;++ ib ) { 373__builtin_prefetch (x [ib ].qs ,0 ,1 ); 374__builtin_prefetch (y [ib ].qs ,0 ,1 ); 375 376vector float vxd = vec_splats (GGML_CPU_FP16_TO_FP32 (x [ib ].d )); 377vector float vyd = vec_splats (GGML_CPU_FP16_TO_FP32 (y [ib ].d )); 378vector float vd = vec_mul (vxd ,vyd ); 379 380vector signed long long aux64x2_0 = {(uint64_t )(table_b2b_1 [x [ib ].qh [0 ]]), (uint64_t )(table_b2b_1 [x [ib ].qh [1 ]])}; 381vector signed long long aux64x2_1 = {(uint64_t )(table_b2b_1 [x [ib ].qh [2 ]]), (uint64_t )(table_b2b_1 [x [ib ].qh [3 ]])}; 382 383vector signed char qh0 = (vector signed char )aux64x2_0 ; 384vector signed char qh1 = (vector signed char )aux64x2_1 ; 385 386vector signed char qxs = (vector signed char )vec_xl (0 ,x [ib ].qs ); 387 388vector signed char q5x0 = vec_sub (vec_and (qxs ,lowMask ),qh0 ); 389vector signed char q5x1 = vec_sub (vec_sr (qxs ,v4 ),qh1 ); 390 391vector signed char q8y0 = vec_xl (0 ,y [ib ].qs ); 392vector signed char q8y1 = vec_xl (16 ,y [ib ].qs ); 393 394vector signed short qv0 = vec_add (vec_mule (q5x0 ,q8y0 ),vec_mulo (q5x0 ,q8y0 )); 395vector signed short qv1 = vec_add (vec_mule (q5x1 ,q8y1 ),vec_mulo (q5x1 ,q8y1 )); 396 397qv0 = vec_add (qv0 ,qv1 ); 398 399vector signed int vsumi0 = vec_add (vec_unpackh (qv0 ),vec_unpackl (qv0 )); 400 401vsumf0 = vec_madd (vec_ctf (vsumi0 ,0 ),vd ,vsumf0 ); 402 } 403 404vsumf0 = vec_add (vsumf0 ,vec_sld (vsumf0 ,vsumf0 ,4 )); 405vsumf0 = vec_add (vsumf0 ,vec_sld (vsumf0 ,vsumf0 ,8 )); 406 407sumf = vec_extract (vsumf0 ,0 ); 408 409* s = sumf ; 410#else 411UNUSED (ib ); 412UNUSED (sumf ); 413UNUSED (x ); 414UNUSED (y ); 415ggml_vec_dot_q5_0_q8_0_generic (n ,s ,bs ,vx ,bx ,vy ,by ,nrc ); 416#endif 417} 418 419void ggml_vec_dot_q5_1_q8_1 (int n ,float * GGML_RESTRICT s ,size_t bs ,const void * GGML_RESTRICT vx ,size_t bx ,const void * GGML_RESTRICT vy ,size_t by ,int nrc ) { 420const int qk = QK8_1 ; 421const int nb = n /qk ; 422 423int ib = 0 ; 424float sumf = 0 ; 425 426assert (n %qk == 0 ); 427assert (qk == QK5_1 ); 428assert (nrc == 1 ); 429UNUSED (nrc ); 430UNUSED (bx ); 431UNUSED (by ); 432UNUSED (bs ); 433 434const block_q5_1 * GGML_RESTRICT x = vx ; 435const block_q8_1 * GGML_RESTRICT y = vy ; 436 437#if defined(__POWER9_VECTOR__ ) 438const vector signed char lowMask = vec_splats ((signed char )0xF ); 439const vector signed int v0 = vec_splats ((int32_t )0 ); 440const vector unsigned char v4 = vec_splats ((unsigned char )0x4 ); 441 442vector float vsumf0 = vec_splats (0.0f ); 443 444#pragma GCC unroll 4 445for (;ib < nb ;++ ib ) { 446__builtin_prefetch (x [ib ].qs ,0 ,1 ); 447__builtin_prefetch (y [ib ].qs ,0 ,1 ); 448 449vector float vxd = vec_splats (GGML_CPU_FP16_TO_FP32 (x [ib ].d )); 450vector float vyd = vec_splats (GGML_CPU_FP16_TO_FP32 (y [ib ].d )); 451vector float vd = vec_mul (vxd ,vyd ); 452 453vector float vxmin = vec_splats (GGML_CPU_FP16_TO_FP32 (x [ib ].m )); 454vector float vys = {GGML_CPU_FP16_TO_FP32 (y [ib ].s ),0.f ,0.f ,0.f }; 455vsumf0 = vec_madd (vxmin ,vys ,vsumf0 ); 456 457vector unsigned long long aux64x2_0 = {(uint64_t )(table_b2b_0 [x [ib ].qh [0 ]]), (uint64_t )(table_b2b_0 [x [ib ].qh [1 ]])}; 458vector unsigned long long aux64x2_1 = {(uint64_t )(table_b2b_0 [x [ib ].qh [2 ]]), (uint64_t )(table_b2b_0 [x [ib ].qh [3 ]])}; 459 460vector signed char qh0 = (vector signed char )aux64x2_0 ; 461vector signed char qh1 = (vector signed char )aux64x2_1 ; 462 463vector signed char qxs = (vector signed char )vec_xl (0 ,x [ib ].qs ); 464 465vector unsigned char q5x0 = (vector unsigned char )vec_or (vec_and (qxs ,lowMask ),qh0 ); 466vector unsigned char q5x1 = (vector unsigned char )vec_or (vec_sr (qxs ,v4 ),qh1 ); 467 468vector signed char q8y0 = vec_xl (0 ,y [ib ].qs ); 469vector signed char q8y1 = vec_xl (16 ,y [ib ].qs ); 470 471vector signed int vsumi0 = v0 ; 472 473vsumi0 = vec_msum (q8y0 ,q5x0 ,vsumi0 ); 474vsumi0 = vec_msum (q8y1 ,q5x1 ,vsumi0 ); 475 476vsumf0 = vec_madd (vec_ctf (vsumi0 ,0 ),vd ,vsumf0 ); 477 } 478 479vsumf0 = vec_add (vsumf0 ,vec_sld (vsumf0 ,vsumf0 ,4 )); 480vsumf0 = vec_add (vsumf0 ,vec_sld (vsumf0 ,vsumf0 ,8 )); 481 482sumf = vec_extract (vsumf0 ,0 ); 483 484* s = sumf ; 485#else 486UNUSED (nb ); 487UNUSED (ib ); 488UNUSED (sumf ); 489UNUSED (x ); 490UNUSED (y ); 491ggml_vec_dot_q5_1_q8_1_generic (n ,s ,bs ,vx ,bx ,vy ,by ,nrc ); 492#endif 493} 494 495void ggml_vec_dot_q8_0_q8_0 (int n ,float * GGML_RESTRICT s ,size_t bs ,const void * GGML_RESTRICT vx ,size_t bx ,const void * GGML_RESTRICT vy ,size_t by ,int nrc ) { 496const int qk = QK8_0 ; 497const int nb = n /qk ; 498 499assert (n %qk == 0 ); 500assert (nrc == 1 ); 501UNUSED (nrc ); 502UNUSED (bx ); 503UNUSED (by ); 504UNUSED (bs ); 505 506const block_q8_0 * GGML_RESTRICT x = vx ; 507const block_q8_0 * GGML_RESTRICT y = vy ; 508 509int ib = 0 ; 510float sumf = 0 ; 511 512#if defined(__POWER9_VECTOR__ ) 513const vector signed int v0 = vec_splats ((int32_t )0 ); 514vector float vsumf0 = vec_splats (0.0f ); 515 516#pragma GCC unroll 8 517for (;ib < nb ;++ ib ) { 518__builtin_prefetch (x [ib ].qs ,0 ,1 ); 519__builtin_prefetch (y [ib ].qs ,0 ,1 ); 520 521vector float vxd = vec_splats (GGML_CPU_FP16_TO_FP32 (x [ib ].d )); 522vector float vyd = vec_splats (GGML_CPU_FP16_TO_FP32 (y [ib ].d )); 523vector float vd = vec_mul (vxd ,vyd ); 524 525vector signed char q8x0 = vec_xl (0 ,x [ib ].qs ); 526vector signed char q8x1 = vec_xl (16 ,x [ib ].qs ); 527vector signed char q8y0 = vec_xl (0 ,y [ib ].qs ); 528vector signed char q8y1 = vec_xl (16 ,y [ib ].qs ); 529 530vector signed short qv0 = vec_mule (q8x0 ,q8y0 ); 531vector signed short qv1 = vec_mulo (q8x0 ,q8y0 ); 532vector signed short qv2 = vec_mule (q8x1 ,q8y1 ); 533vector signed short qv3 = vec_mulo (q8x1 ,q8y1 ); 534 535vector signed int vsumi0 = v0 ; 536vector signed int vsumi1 = v0 ; 537 538vsumi0 = vec_sum4s (qv0 ,vsumi0 ); 539vsumi1 = vec_sum4s (qv1 ,vsumi1 ); 540vsumi0 = vec_sum4s (qv2 ,vsumi0 ); 541vsumi1 = vec_sum4s (qv3 ,vsumi1 ); 542 543vsumi0 = vec_add (vsumi0 ,vsumi1 ); 544 545vsumf0 = vec_madd (vec_ctf (vsumi0 ,0 ),vd ,vsumf0 ); 546 } 547 548vsumf0 = vec_add (vsumf0 ,vec_sld (vsumf0 ,vsumf0 ,4 )); 549vsumf0 = vec_add (vsumf0 ,vec_sld (vsumf0 ,vsumf0 ,8 )); 550 551sumf = vec_extract (vsumf0 ,0 ); 552 553* s = sumf ; 554#else 555UNUSED (nb ); 556UNUSED (x ); 557UNUSED (y ); 558UNUSED (ib ); 559UNUSED (sumf ); 560ggml_vec_dot_q8_0_q8_0_generic (n ,s ,bs ,vx ,bx ,vy ,by ,nrc ); 561#endif 562} 563 564void ggml_vec_dot_q2_K_q8_K (int n ,float * GGML_RESTRICT s ,size_t bs ,const void * GGML_RESTRICT vx ,size_t bx ,const void * GGML_RESTRICT vy ,size_t by ,int nrc ) { 565assert (nrc == 1 ); 566UNUSED (nrc ); 567UNUSED (bx ); 568UNUSED (by ); 569UNUSED (bs ); 570 571const block_q2_K * GGML_RESTRICT x = vx ; 572const block_q8_K * GGML_RESTRICT y = vy ; 573 574const int nb = n /QK_K ; 575 576#if defined(__POWER9_VECTOR__ ) 577const vector signed char lowMask = vec_splats ((signed char )0x3 ); 578const vector signed char lowScaleMask = vec_splats ((signed char )0xF ); 579const vector int v0 = vec_splats ((int32_t )0 ); 580const vector unsigned char v2 = vec_splats ((unsigned char )0x2 ); 581const vector unsigned char v6 = vec_splats ((unsigned char )0x6 ); 582const vector unsigned char v4 = vec_splats ((unsigned char )0x4 ); 583 584vector float vsumf0 = vec_splats (0.0f ); 585vector float vsumf1 = vec_splats (0.0f ); 586vector float vsumf2 = vec_splats (0.0f ); 587vector float vsumf3 = vec_splats (0.0f ); 588 589for (int i = 0 ;i < nb ;++ i ) { 590vector float vxd = vec_splats (GGML_CPU_FP16_TO_FP32 (x [i ].d )); 591vector float vyd = vec_splats (y [i ].d ); 592vector float vd = vec_mul (vxd ,vyd ); 593 594vector float vxmin = vec_splats (GGML_CPU_FP16_TO_FP32 (x [i ].dmin )); 595vector float vdmin = vec_mul (vxmin ,vyd ); 596 597vector signed short q8ysums0 = vec_xl (0 ,y [i ].bsums ); 598vector signed short q8ysums1 = vec_xl (16 ,y [i ].bsums ); 599 600vector signed char q2xmins = (vector signed char )vec_xl (0 ,x [i ].scales ); 601vector signed char vscales = vec_and (q2xmins ,lowScaleMask ); 602 603q2xmins = vec_sr (q2xmins ,v4 ); 604vector signed short q2xmins0 = vec_unpackh (q2xmins ); 605vector signed short q2xmins1 = vec_unpackl (q2xmins ); 606 607vector signed int prod0 = vec_mule (q2xmins0 ,q8ysums0 ); 608vector signed int prod1 = vec_mulo (q2xmins0 ,q8ysums0 ); 609vector signed int prod2 = vec_mule (q2xmins1 ,q8ysums1 ); 610vector signed int prod3 = vec_mulo (q2xmins1 ,q8ysums1 ); 611 612vsumf0 = vec_nmsub (vec_ctf (prod0 ,0 ),vdmin ,vsumf0 ); 613vsumf1 = vec_nmsub (vec_ctf (prod1 ,0 ),vdmin ,vsumf1 ); 614vsumf2 = vec_nmsub (vec_ctf (prod2 ,0 ),vdmin ,vsumf2 ); 615vsumf3 = vec_nmsub (vec_ctf (prod3 ,0 ),vdmin ,vsumf3 ); 616 617vector signed int vsumi0 = v0 ; 618vector signed int vsumi1 = v0 ; 619vector signed int vsumi2 = v0 ; 620vector signed int vsumi3 = v0 ; 621vector signed int vsumi4 = v0 ; 622vector signed int vsumi5 = v0 ; 623vector signed int vsumi6 = v0 ; 624vector signed int vsumi7 = v0 ; 625 626const uint8_t * GGML_RESTRICT q2 = x [i ].qs ; 627const int8_t * GGML_RESTRICT q8 = y [i ].qs ; 628 629for (int j = 0 ;j < QK_K /128 ;++ j ) { 630__builtin_prefetch (q2 ,0 ,1 ); 631__builtin_prefetch (q8 ,0 ,1 ); 632 633vector signed char qxs0 = (vector signed char )vec_xl (0 ,q2 ); 634vector signed char qxs1 = (vector signed char )vec_xl (16 ,q2 ); 635q2 += 32 ; 636 637vector unsigned char q2x00 = (vector unsigned char )vec_and (qxs0 ,lowMask ); 638vector unsigned char q2x01 = (vector unsigned char )vec_and (vec_sr (qxs0 ,v2 ),lowMask ); 639vector unsigned char q2x02 = (vector unsigned char )vec_and (vec_sr (qxs0 ,v4 ),lowMask ); 640vector unsigned char q2x03 = (vector unsigned char )vec_and (vec_sr (qxs0 ,v6 ),lowMask ); 641vector unsigned char q2x10 = (vector unsigned char )vec_and (qxs1 ,lowMask ); 642vector unsigned char q2x11 = (vector unsigned char )vec_and (vec_sr (qxs1 ,v2 ),lowMask ); 643vector unsigned char q2x12 = (vector unsigned char )vec_and (vec_sr (qxs1 ,v4 ),lowMask ); 644vector unsigned char q2x13 = (vector unsigned char )vec_and (vec_sr (qxs1 ,v6 ),lowMask ); 645 646vector signed char q8y00 = vec_xl (0 ,q8 ); 647vector signed char q8y10 = vec_xl (16 ,q8 ); 648vector signed char q8y01 = vec_xl (32 ,q8 ); 649vector signed char q8y11 = vec_xl (48 ,q8 ); 650vector signed char q8y02 = vec_xl (64 ,q8 ); 651vector signed char q8y12 = vec_xl (80 ,q8 ); 652vector signed char q8y03 = vec_xl (96 ,q8 ); 653vector signed char q8y13 = vec_xl (112 ,q8 ); 654q8 += 128 ; 655 656vector signed int qv0 = vec_msum (q8y00 ,q2x00 ,v0 ); 657vector signed int qv1 = vec_msum (q8y01 ,q2x01 ,v0 ); 658vector signed int qv2 = vec_msum (q8y02 ,q2x02 ,v0 ); 659vector signed int qv3 = vec_msum (q8y03 ,q2x03 ,v0 ); 660vector signed int qv4 = vec_msum (q8y10 ,q2x10 ,v0 ); 661vector signed int qv5 = vec_msum (q8y11 ,q2x11 ,v0 ); 662vector signed int qv6 = vec_msum (q8y12 ,q2x12 ,v0 ); 663vector signed int qv7 = vec_msum (q8y13 ,q2x13 ,v0 ); 664 665vector signed short vscales_07 = vec_unpackh (vscales ); 666vector signed int vscales_03 = vec_unpackh (vscales_07 ); 667vector signed int vscales_47 = vec_unpackl (vscales_07 ); 668vector signed int vs0 = vec_splat (vscales_03 ,0 ); 669vector signed int vs1 = vec_splat (vscales_03 ,1 ); 670vector signed int vs2 = vec_splat (vscales_03 ,2 ); 671vector signed int vs3 = vec_splat (vscales_03 ,3 ); 672vector signed int vs4 = vec_splat (vscales_47 ,0 ); 673vector signed int vs5 = vec_splat (vscales_47 ,1 ); 674vector signed int vs6 = vec_splat (vscales_47 ,2 ); 675vector signed int vs7 = vec_splat (vscales_47 ,3 ); 676vscales = vec_sld (vscales ,vscales ,8 ); 677 678vsumi0 = vec_add (vec_mul (qv0 ,vs0 ),vsumi0 ); 679vsumi1 = vec_add (vec_mul (qv1 ,vs2 ),vsumi1 ); 680vsumi2 = vec_add (vec_mul (qv2 ,vs4 ),vsumi2 ); 681vsumi3 = vec_add (vec_mul (qv3 ,vs6 ),vsumi3 ); 682vsumi4 = vec_add (vec_mul (qv4 ,vs1 ),vsumi4 ); 683vsumi5 = vec_add (vec_mul (qv5 ,vs3 ),vsumi5 ); 684vsumi6 = vec_add (vec_mul (qv6 ,vs5 ),vsumi6 ); 685vsumi7 = vec_add (vec_mul (qv7 ,vs7 ),vsumi7 ); 686 } 687 688vsumi0 = vec_add (vsumi0 ,vsumi4 ); 689vsumi1 = vec_add (vsumi1 ,vsumi5 ); 690vsumi2 = vec_add (vsumi2 ,vsumi6 ); 691vsumi3 = vec_add (vsumi3 ,vsumi7 ); 692 693vsumf0 = vec_madd (vec_ctf (vsumi0 ,0 ),vd ,vsumf0 ); 694vsumf1 = vec_madd (vec_ctf (vsumi1 ,0 ),vd ,vsumf1 ); 695vsumf2 = vec_madd (vec_ctf (vsumi2 ,0 ),vd ,vsumf2 ); 696vsumf3 = vec_madd (vec_ctf (vsumi3 ,0 ),vd ,vsumf3 ); 697 } 698 699vsumf0 = vec_add (vsumf0 ,vsumf2 ); 700vsumf1 = vec_add (vsumf1 ,vsumf3 ); 701 702vsumf0 = vec_add (vsumf0 ,vsumf1 ); 703 704vsumf0 = vec_add (vsumf0 ,vec_sld (vsumf0 ,vsumf0 ,4 )); 705vsumf0 = vec_add (vsumf0 ,vec_sld (vsumf0 ,vsumf0 ,8 )); 706 707* s = vec_extract (vsumf0 ,0 ); 708 709#else 710UNUSED (x ); 711UNUSED (y ); 712UNUSED (nb ); 713ggml_vec_dot_q2_K_q8_K_generic (n ,s ,bs ,vx ,bx ,vy ,by ,nrc ); 714#endif 715} 716 717void ggml_vec_dot_q3_K_q8_K (int n ,float * GGML_RESTRICT s ,size_t bs ,const void * GGML_RESTRICT vx ,size_t bx ,const void * GGML_RESTRICT vy ,size_t by ,int nrc ) { 718assert (n %QK_K == 0 ); 719assert (nrc == 1 ); 720UNUSED (nrc ); 721UNUSED (bx ); 722UNUSED (by ); 723UNUSED (bs ); 724 725const uint32_t kmask1 = 0x03030303 ; 726const uint32_t kmask2 = 0x0f0f0f0f ; 727 728const block_q3_K * GGML_RESTRICT x = vx ; 729const block_q8_K * GGML_RESTRICT y = vy ; 730 731const int nb = n /QK_K ; 732 733#if defined(__POWER9_VECTOR__ ) 734const vector signed char lowMask = vec_splats ((signed char )0x3 ); 735const vector signed char lowMask1 = vec_splats ((int8_t )0xf ); 736const vector signed char lowMask2 = vec_splats ((int8_t )0x30 ); 737const vector int v0 = vec_splats ((int32_t )0 ); 738const vector signed char v1 = vec_splats ((signed char )0x1 ); 739const vector unsigned char v2 = vec_splats ((unsigned char )0x2 ); 740const vector unsigned char v3 = vec_splats ((unsigned char )0x3 ); 741const vector unsigned char v4 = vec_splats ((unsigned char )0x4 ); 742const vector unsigned char v6 = vec_splats ((unsigned char )0x6 ); 743const vector signed char off = vec_splats ((signed char )0x20 ); 744 745vector float vsumf0 = vec_splats (0.0f ); 746vector float vsumf1 = vec_splats (0.0f ); 747vector float vsumf2 = vec_splats (0.0f ); 748vector float vsumf3 = vec_splats (0.0f ); 749 750for (int i = 0 ;i < nb ;++ i ) { 751vector float vxd = vec_splats (GGML_CPU_FP16_TO_FP32 (x [i ].d )); 752vector float vyd = vec_splats (y [i ].d ); 753vector float vd = vec_mul (vxd ,vyd ); 754 755UNUSED (kmask1 ); 756UNUSED (kmask2 ); 757 758vector signed char u0 = (vector signed char )vec_xl_len (x [i ].scales ,8 ); 759vector signed char u1 = vec_and (u0 ,lowMask1 ); 760vector signed char u2 = (vector signed char )vec_xl_len (x [i ].scales + 8 ,4 ); 761vector signed char u3 = (vector signed char )vec_mergeh ((vector signed int )u2 , (vector signed int )vec_sr (u2 ,v2 )); 762vector signed char u30 = vec_sl (vec_and (u3 ,lowMask ),v4 ); 763vector signed char u31 = vec_and (u3 ,lowMask2 ); 764 765u1 = vec_or (u1 ,u30 ); 766u2 = vec_or (vec_sr (u0 ,v4 ),u31 ); 767 768vector signed char vscales = (vector signed char )vec_mergeh ((vector signed long long )u1 , (vector signed long long )u2 ); 769vector signed char qxhs0 = (vector signed char )vec_xl (0 ,x [i ].hmask ); 770vector signed char qxhs1 = (vector signed char )vec_xl (16 ,x [i ].hmask ); 771 772vscales = vec_sub (vscales ,off ); 773 774vector signed int vsumi0 = v0 ; 775vector signed int vsumi1 = v0 ; 776vector signed int vsumi2 = v0 ; 777vector signed int vsumi3 = v0 ; 778vector signed int vsumi4 = v0 ; 779vector signed int vsumi5 = v0 ; 780vector signed int vsumi6 = v0 ; 781vector signed int vsumi7 = v0 ; 782 783const uint8_t * GGML_RESTRICT q3 = x [i ].qs ; 784const int8_t * GGML_RESTRICT q8 = y [i ].qs ; 785 786for (int j = 0 ;j < QK_K /128 ;++ j ) { 787__builtin_prefetch (q3 ,0 ,1 ); 788__builtin_prefetch (q8 ,0 ,1 ); 789 790vector signed char qxs0 = (vector signed char )vec_xl (0 ,q3 ); 791vector signed char qxs1 = (vector signed char )vec_xl (16 ,q3 ); 792q3 += 32 ; 793 794//the low 2 bits 795vector signed char qxs00 = vec_and (qxs0 ,lowMask ); 796vector signed char qxs01 = vec_and (vec_sr (qxs0 ,v2 ),lowMask ); 797vector signed char qxs02 = vec_and (vec_sr (qxs0 ,v4 ),lowMask ); 798vector signed char qxs03 = vec_and (vec_sr (qxs0 ,v6 ),lowMask ); 799vector signed char qxs10 = vec_and (qxs1 ,lowMask ); 800vector signed char qxs11 = vec_and (vec_sr (qxs1 ,v2 ),lowMask ); 801vector signed char qxs12 = vec_and (vec_sr (qxs1 ,v4 ),lowMask ); 802vector signed char qxs13 = vec_and (vec_sr (qxs1 ,v6 ),lowMask ); 803 804//the 3rd bit 805vector signed char qxh00 = vec_sl (vec_andc (v1 ,qxhs0 ),v2 ); 806vector signed char qxh01 = vec_sl (vec_andc (v1 ,vec_sr (qxhs0 , (vector unsigned char )v1 )),v2 ); 807vector signed char qxh02 = vec_sl (vec_andc (v1 ,vec_sr (qxhs0 ,v2 )),v2 ); 808vector signed char qxh03 = vec_sl (vec_andc (v1 ,vec_sr (qxhs0 ,v3 )),v2 ); 809vector signed char qxh10 = vec_sl (vec_andc (v1 ,qxhs1 ),v2 ); 810vector signed char qxh11 = vec_sl (vec_andc (v1 ,vec_sr (qxhs1 , (vector unsigned char )v1 )),v2 ); 811vector signed char qxh12 = vec_sl (vec_andc (v1 ,vec_sr (qxhs1 ,v2 )),v2 ); 812vector signed char qxh13 = vec_sl (vec_andc (v1 ,vec_sr (qxhs1 ,v3 )),v2 ); 813qxhs0 = vec_sr (qxhs0 ,v4 ); 814qxhs1 = vec_sr (qxhs1 ,v4 ); 815 816vector signed char q3x00 = vec_sub (qxs00 ,qxh00 ); 817vector signed char q3x01 = vec_sub (qxs01 ,qxh01 ); 818vector signed char q3x02 = vec_sub (qxs02 ,qxh02 ); 819vector signed char q3x03 = vec_sub (qxs03 ,qxh03 ); 820vector signed char q3x10 = vec_sub (qxs10 ,qxh10 ); 821vector signed char q3x11 = vec_sub (qxs11 ,qxh11 ); 822vector signed char q3x12 = vec_sub (qxs12 ,qxh12 ); 823vector signed char q3x13 = vec_sub (qxs13 ,qxh13 ); 824 825vector signed char q8y00 = vec_xl (0 ,q8 ); 826vector signed char q8y10 = vec_xl (16 ,q8 ); 827vector signed char q8y01 = vec_xl (32 ,q8 ); 828vector signed char q8y11 = vec_xl (48 ,q8 ); 829vector signed char q8y02 = vec_xl (64 ,q8 ); 830vector signed char q8y12 = vec_xl (80 ,q8 ); 831vector signed char q8y03 = vec_xl (96 ,q8 ); 832vector signed char q8y13 = vec_xl (112 ,q8 ); 833q8 += 128 ; 834 835vector signed short vscales_h = vec_unpackh (vscales ); 836vector signed short vs0 = vec_splat (vscales_h ,0 ); 837vector signed short vs1 = vec_splat (vscales_h ,1 ); 838vector signed short vs2 = vec_splat (vscales_h ,2 ); 839vector signed short vs3 = vec_splat (vscales_h ,3 ); 840vector signed short vs4 = vec_splat (vscales_h ,4 ); 841vector signed short vs5 = vec_splat (vscales_h ,5 ); 842vector signed short vs6 = vec_splat (vscales_h ,6 ); 843vector signed short vs7 = vec_splat (vscales_h ,7 ); 844vscales = vec_sld (vscales ,vscales ,8 ); 845 846vector signed short qv00 = vec_add (vec_mule (q3x00 ,q8y00 ),vec_mulo (q3x00 ,q8y00 )); 847vector signed short qv01 = vec_add (vec_mule (q3x01 ,q8y01 ),vec_mulo (q3x01 ,q8y01 )); 848vector signed short qv02 = vec_add (vec_mule (q3x02 ,q8y02 ),vec_mulo (q3x02 ,q8y02 )); 849vector signed short qv03 = vec_add (vec_mule (q3x03 ,q8y03 ),vec_mulo (q3x03 ,q8y03 )); 850vector signed short qv10 = vec_add (vec_mule (q3x10 ,q8y10 ),vec_mulo (q3x10 ,q8y10 )); 851vector signed short qv11 = vec_add (vec_mule (q3x11 ,q8y11 ),vec_mulo (q3x11 ,q8y11 )); 852vector signed short qv12 = vec_add (vec_mule (q3x12 ,q8y12 ),vec_mulo (q3x12 ,q8y12 )); 853vector signed short qv13 = vec_add (vec_mule (q3x13 ,q8y13 ),vec_mulo (q3x13 ,q8y13 )); 854 855vsumi0 = vec_msum (qv00 ,vs0 ,vsumi0 ); 856vsumi1 = vec_msum (qv01 ,vs2 ,vsumi1 ); 857vsumi2 = vec_msum (qv02 ,vs4 ,vsumi2 ); 858vsumi3 = vec_msum (qv03 ,vs6 ,vsumi3 ); 859vsumi4 = vec_msum (qv10 ,vs1 ,vsumi4 ); 860vsumi5 = vec_msum (qv11 ,vs3 ,vsumi5 ); 861vsumi6 = vec_msum (qv12 ,vs5 ,vsumi6 ); 862vsumi7 = vec_msum (qv13 ,vs7 ,vsumi7 ); 863 } 864 865vsumi0 = vec_add (vsumi0 ,vsumi4 ); 866vsumi1 = vec_add (vsumi1 ,vsumi5 ); 867vsumi2 = vec_add (vsumi2 ,vsumi6 ); 868vsumi3 = vec_add (vsumi3 ,vsumi7 ); 869 870vsumf0 = vec_madd (vec_ctf (vsumi0 ,0 ),vd ,vsumf0 ); 871vsumf1 = vec_madd (vec_ctf (vsumi1 ,0 ),vd ,vsumf1 ); 872vsumf2 = vec_madd (vec_ctf (vsumi2 ,0 ),vd ,vsumf2 ); 873vsumf3 = vec_madd (vec_ctf (vsumi3 ,0 ),vd ,vsumf3 ); 874 } 875 876vsumf0 = vec_add (vsumf0 ,vsumf2 ); 877vsumf1 = vec_add (vsumf1 ,vsumf3 ); 878 879vsumf0 = vec_add (vsumf0 ,vsumf1 ); 880 881vsumf0 = vec_add (vsumf0 ,vec_sld (vsumf0 ,vsumf0 ,4 )); 882vsumf0 = vec_add (vsumf0 ,vec_sld (vsumf0 ,vsumf0 ,8 )); 883 884* s = vec_extract (vsumf0 ,0 ); 885 886#else 887UNUSED (kmask1 ); 888UNUSED (kmask2 ); 889UNUSED (x ); 890UNUSED (y ); 891UNUSED (nb ); 892ggml_vec_dot_q3_K_q8_K_generic (n ,s ,bs ,vx ,bx ,vy ,by ,nrc ); 893#endif 894} 895 896void ggml_vec_dot_q4_K_q8_K (int n ,float * GGML_RESTRICT s ,size_t bs ,const void * GGML_RESTRICT vx ,size_t bx ,const void * GGML_RESTRICT vy ,size_t by ,int nrc ) { 897assert (n %QK_K == 0 ); 898assert (nrc == 1 ); 899UNUSED (nrc ); 900UNUSED (bx ); 901UNUSED (by ); 902UNUSED (bs ); 903 904const block_q4_K * GGML_RESTRICT x = vx ; 905const block_q8_K * GGML_RESTRICT y = vy ; 906 907const int nb = n /QK_K ; 908 909static const uint32_t kmask1 = 0x3f3f3f3f ; 910static const uint32_t kmask2 = 0x0f0f0f0f ; 911static const uint32_t kmask3 = 0x03030303 ; 912 913uint32_t utmp [4 ]; 914 915#if defined(__POWER9_VECTOR__ ) 916const vector signed char lowMask = vec_splats ((signed char )0xF ); 917const vector signed char lowMask1 = vec_splats ((int8_t )0x3f ); 918const vector signed char lowMask2 = vec_splats ((int8_t )0x30 ); 919const vector int v0 = vec_splats ((int32_t )0 ); 920const vector unsigned char v2 = vec_splats ((uint8_t )2 ); 921const vector unsigned char v4 = vec_splats ((unsigned char )0x4 ); 922 923vector float vsumf0 = vec_splats (0.0f ); 924vector float vsumf1 = vec_splats (0.0f ); 925vector float vsumf2 = vec_splats (0.0f ); 926vector float vsumf3 = vec_splats (0.0f ); 927 928for (int i = 0 ;i < nb ;++ i ) { 929vector float vxd = vec_splats (GGML_CPU_FP16_TO_FP32 (x [i ].d )); 930vector float vyd = vec_splats (y [i ].d ); 931vector float vd = vec_mul (vxd ,vyd ); 932 933vector float vxmin = vec_splats (GGML_CPU_FP16_TO_FP32 (x [i ].dmin )); 934vector float vdmin = vec_mul (vxmin ,vyd ); 935 936vector signed short q8ysums0 = vec_xl (0 ,y [i ].bsums ); 937vector signed short q8ysums1 = vec_xl (16 ,y [i ].bsums ); 938 939UNUSED (kmask1 ); 940UNUSED (kmask2 ); 941UNUSED (kmask3 ); 942UNUSED (utmp ); 943 944vector signed char u0 = (vector signed char )vec_xl_len (x [i ].scales ,8 ); 945vector signed char u1 = vec_and (vec_sr (u0 ,v2 ),lowMask2 ); 946vector signed char u2 = (vector signed char )vec_xl_len (x [i ].scales + 8 ,4 ); 947vector signed char u3 = vec_sr (u2 ,v4 ); 948 949vector signed char u30 = u1 ; 950vector signed char u31 = (vector signed char )vec_mergeh ((vector signed int )vec_and (u2 ,lowMask ), (vector signed int )u3 ); 951 952u1 = vec_and (u0 ,lowMask1 ); 953u2 = vec_or (u30 ,u31 ); 954 955vector signed char utmps = (vector signed char )vec_mergeh ((vector signed int )u1 , (vector signed int )u2 ); 956 957vector signed short vscales = vec_unpackh (utmps ); 958vector signed short q4xmins = vec_unpackl (utmps ); 959vector signed short q4xmins0 = vec_mergeh (q4xmins ,q4xmins ); 960vector signed short q4xmins1 = vec_mergel (q4xmins ,q4xmins ); 961 962vector signed int prod0 = vec_mule (q4xmins0 ,q8ysums0 ); 963vector signed int prod1 = vec_mule (q4xmins1 ,q8ysums1 ); 964vector signed int prod2 = vec_mulo (q4xmins0 ,q8ysums0 ); 965vector signed int prod3 = vec_mulo (q4xmins1 ,q8ysums1 ); 966 967vsumf0 = vec_nmsub (vec_ctf (prod0 ,0 ),vdmin ,vsumf0 ); 968vsumf1 = vec_nmsub (vec_ctf (prod1 ,0 ),vdmin ,vsumf1 ); 969vsumf2 = vec_nmsub (vec_ctf (prod2 ,0 ),vdmin ,vsumf2 ); 970vsumf3 = vec_nmsub (vec_ctf (prod3 ,0 ),vdmin ,vsumf3 ); 971 972vector signed int vsumi0 = v0 ; 973vector signed int vsumi1 = v0 ; 974vector signed int vsumi2 = v0 ; 975vector signed int vsumi3 = v0 ; 976 977const uint8_t * GGML_RESTRICT q4 = x [i ].qs ; 978const int8_t * GGML_RESTRICT q8 = y [i ].qs ; 979 980for (int j = 0 ;j < QK_K /64 ;j += 2 ) { 981__builtin_prefetch (q4 ,0 ,1 ); 982__builtin_prefetch (q8 ,0 ,1 ); 983 984vector signed char qxs0 = (vector signed char )vec_xl (0 ,q4 ); 985vector signed char qxs1 = (vector signed char )vec_xl (16 ,q4 ); 986vector signed char qxs2 = (vector signed char )vec_xl (32 ,q4 ); 987vector signed char qxs3 = (vector signed char )vec_xl (48 ,q4 ); 988q4 += 64 ; 989 990vector unsigned char q4x00 = (vector unsigned char )vec_and (qxs0 ,lowMask ); 991vector unsigned char q4x01 = (vector unsigned char )vec_sr (qxs0 ,v4 ); 992vector unsigned char q4x10 = (vector unsigned char )vec_and (qxs1 ,lowMask ); 993vector unsigned char q4x11 = (vector unsigned char )vec_sr (qxs1 ,v4 ); 994vector unsigned char q4x20 = (vector unsigned char )vec_and (qxs2 ,lowMask ); 995vector unsigned char q4x21 = (vector unsigned char )vec_sr (qxs2 ,v4 ); 996vector unsigned char q4x30 = (vector unsigned char )vec_and (qxs3 ,lowMask ); 997vector unsigned char q4x31 = (vector unsigned char )vec_sr (qxs3 ,v4 ); 998 999vector signed char q8y00 = vec_xl (0 ,q8 ); 1000vector signed char q8y10 = vec_xl (16 ,q8 ); 1001vector signed char q8y01 = vec_xl (32 ,q8 ); 1002vector signed char q8y11 = vec_xl (48 ,q8 ); 1003vector signed char q8y20 = vec_xl (64 ,q8 ); 1004vector signed char q8y30 = vec_xl (80 ,q8 ); 1005vector signed char q8y21 = vec_xl (96 ,q8 ); 1006vector signed char q8y31 = vec_xl (112 ,q8 ); 1007q8 += 128 ; 1008 1009vector signed int qv00 = vec_msum (q8y00 ,q4x00 ,v0 ); 1010vector signed int qv01 = vec_msum (q8y01 ,q4x01 ,v0 ); 1011vector signed int qv10 = vec_msum (q8y10 ,q4x10 ,v0 ); 1012vector signed int qv11 = vec_msum (q8y11 ,q4x11 ,v0 ); 1013vector signed int qv20 = vec_msum (q8y20 ,q4x20 ,v0 ); 1014vector signed int qv21 = vec_msum (q8y21 ,q4x21 ,v0 ); 1015vector signed int qv30 = vec_msum (q8y30 ,q4x30 ,v0 ); 1016vector signed int qv31 = vec_msum (q8y31 ,q4x31 ,v0 ); 1017 1018vector signed int vscales_h = vec_unpackh (vscales ); 1019vector signed int vs0 = vec_splat (vscales_h ,0 ); 1020vector signed int vs1 = vec_splat (vscales_h ,1 ); 1021vector signed int vs2 = vec_splat (vscales_h ,2 ); 1022vector signed int vs3 = vec_splat (vscales_h ,3 ); 1023vscales = vec_sld (vscales ,vscales ,8 ); 1024 1025vsumi0 = vec_add (vec_mul (qv00 ,vs0 ),vsumi0 ); 1026vsumi1 = vec_add (vec_mul (qv01 ,vs1 ),vsumi1 ); 1027vsumi2 = vec_add (vec_mul (qv20 ,vs2 ),vsumi2 ); 1028vsumi3 = vec_add (vec_mul (qv21 ,vs3 ),vsumi3 ); 1029 1030vsumi0 = vec_add (vec_mul (qv10 ,vs0 ),vsumi0 ); 1031vsumi1 = vec_add (vec_mul (qv11 ,vs1 ),vsumi1 ); 1032vsumi2 = vec_add (vec_mul (qv30 ,vs2 ),vsumi2 ); 1033vsumi3 = vec_add (vec_mul (qv31 ,vs3 ),vsumi3 ); 1034 } 1035 1036vsumf0 = vec_madd (vec_ctf (vsumi0 ,0 ),vd ,vsumf0 ); 1037vsumf1 = vec_madd (vec_ctf (vsumi1 ,0 ),vd ,vsumf1 ); 1038vsumf2 = vec_madd (vec_ctf (vsumi2 ,0 ),vd ,vsumf2 ); 1039vsumf3 = vec_madd (vec_ctf (vsumi3 ,0 ),vd ,vsumf3 ); 1040 } 1041 1042vsumf0 = vec_add (vsumf0 ,vsumf2 ); 1043vsumf1 = vec_add (vsumf1 ,vsumf3 ); 1044 1045vsumf0 = vec_add (vsumf0 ,vsumf1 ); 1046 1047vsumf0 = vec_add (vsumf0 ,vec_sld (vsumf0 ,vsumf0 ,4 )); 1048vsumf0 = vec_add (vsumf0 ,vec_sld (vsumf0 ,vsumf0 ,8 )); 1049 1050* s = vec_extract (vsumf0 ,0 ); 1051 1052#else 1053UNUSED (x ); 1054UNUSED (y ); 1055UNUSED (nb ); 1056UNUSED (kmask1 ); 1057UNUSED (kmask2 ); 1058UNUSED (kmask3 ); 1059UNUSED (utmp ); 1060ggml_vec_dot_q4_K_q8_K_generic (n ,s ,bs ,vx ,bx ,vy ,by ,nrc ); 1061#endif 1062} 1063 1064void ggml_vec_dot_q5_K_q8_K (int n ,float * GGML_RESTRICT s ,size_t bs ,const void * GGML_RESTRICT vx ,size_t bx ,const void * GGML_RESTRICT vy ,size_t by ,int nrc ) { 1065assert (n %QK_K == 0 ); 1066assert (nrc == 1 ); 1067UNUSED (nrc ); 1068UNUSED (bx ); 1069UNUSED (by ); 1070UNUSED (bs ); 1071 1072const block_q5_K * GGML_RESTRICT x = vx ; 1073const block_q8_K * GGML_RESTRICT y = vy ; 1074 1075const int nb = n /QK_K ; 1076 1077static const uint32_t kmask1 = 0x3f3f3f3f ; 1078static const uint32_t kmask2 = 0x0f0f0f0f ; 1079static const uint32_t kmask3 = 0x03030303 ; 1080 1081uint32_t utmp [4 ]; 1082 1083#if defined(__POWER9_VECTOR__ ) 1084const vector signed char lowMask = vec_splats ((signed char )0xF ); 1085const vector signed char lowMask1 = vec_splats ((int8_t )0x3f ); 1086const vector signed char lowMask2 = vec_splats ((int8_t )0x30 ); 1087const vector int v0 = vec_splats ((int32_t )0 ); 1088const vector unsigned char v1 = vec_splats ((unsigned char )0x1 ); 1089const vector unsigned char v2 = vec_splats ((unsigned char )0x2 ); 1090const vector unsigned char v3 = vec_splats ((unsigned char )0x3 ); 1091const vector unsigned char v4 = vec_splats ((unsigned char )0x4 ); 1092 1093vector float vsumf0 = vec_splats (0.0f ); 1094vector float vsumf1 = vec_splats (0.0f ); 1095vector float vsumf2 = vec_splats (0.0f ); 1096vector float vsumf3 = vec_splats (0.0f ); 1097 1098for (int i = 0 ;i < nb ;++ i ) { 1099vector float vxd = vec_splats (GGML_CPU_FP16_TO_FP32 (x [i ].d )); 1100vector float vyd = vec_splats (y [i ].d ); 1101vector float vd = vec_mul (vxd ,vyd ); 1102 1103vector float vxmin = vec_splats (GGML_CPU_FP16_TO_FP32 (x [i ].dmin )); 1104vector float vdmin = vec_mul (vxmin ,vyd ); 1105 1106UNUSED (kmask1 ); 1107UNUSED (kmask2 ); 1108UNUSED (kmask3 ); 1109UNUSED (utmp ); 1110 1111vector signed char u0 = (vector signed char )vec_xl_len (x [i ].scales ,8 ); 1112vector signed char u1 = vec_and (vec_sr (u0 ,v2 ),lowMask2 ); 1113vector signed char u2 = (vector signed char )vec_xl_len (x [i ].scales + 8 ,4 ); 1114vector signed char u3 = vec_sr (u2 ,v4 ); 1115 1116vector signed char u30 = u1 ; 1117vector signed char u31 = (vector signed char )vec_mergeh ((vector signed int )vec_and (u2 ,lowMask ), (vector signed int )u3 ); 1118 1119u1 = vec_and (u0 ,lowMask1 ); 1120u2 = vec_or (u30 ,u31 ); 1121 1122vector signed char utmps = (vector signed char )vec_mergeh ((vector signed int )u1 , (vector signed int )u2 ); 1123 1124vector signed short q8ysums0 = vec_xl (0 ,y [i ].bsums ); 1125vector signed short q8ysums1 = vec_xl (16 ,y [i ].bsums ); 1126 1127vector signed short vscales = vec_unpackh (utmps ); 1128 1129vector signed short q5xmins = vec_unpackl (utmps ); 1130vector signed short q5xmins0 = vec_mergeh (q5xmins ,q5xmins ); 1131vector signed short q5xmins1 = vec_mergel (q5xmins ,q5xmins ); 1132 1133vector signed int prod0 = vec_mule (q5xmins0 ,q8ysums0 ); 1134vector signed int prod1 = vec_mule (q5xmins1 ,q8ysums1 ); 1135vector signed int prod2 = vec_mulo (q5xmins0 ,q8ysums0 ); 1136vector signed int prod3 = vec_mulo (q5xmins1 ,q8ysums1 ); 1137 1138vsumf0 = vec_nmsub (vec_ctf (prod0 ,0 ),vdmin ,vsumf0 ); 1139vsumf1 = vec_nmsub (vec_ctf (prod1 ,0 ),vdmin ,vsumf1 ); 1140vsumf2 = vec_nmsub (vec_ctf (prod2 ,0 ),vdmin ,vsumf2 ); 1141vsumf3 = vec_nmsub (vec_ctf (prod3 ,0 ),vdmin ,vsumf3 ); 1142 1143vector signed char qxhs0 = (vector signed char )vec_xl (0 ,x [i ].qh ); 1144vector signed char qxhs1 = (vector signed char )vec_xl (16 ,x [i ].qh ); 1145 1146vector signed int vsumi0 = v0 ; 1147vector signed int vsumi1 = v0 ; 1148vector signed int vsumi2 = v0 ; 1149vector signed int vsumi3 = v0 ; 1150 1151const uint8_t * GGML_RESTRICT q5 = x [i ].qs ; 1152const int8_t * GGML_RESTRICT q8 = y [i ].qs ; 1153 1154for (int j = 0 ;j < QK_K /64 ;++ j ) { 1155__builtin_prefetch (q5 ,0 ,1 ); 1156__builtin_prefetch (q8 ,0 ,1 ); 1157 1158vector signed char qxs0 = (vector signed char )vec_xl (0 ,q5 ); 1159vector signed char qxs1 = (vector signed char )vec_xl (16 ,q5 ); 1160q5 += 32 ; 1161 1162vector signed char qxs00 = vec_and (qxs0 ,lowMask ); 1163vector signed char qxs01 = vec_sr (qxs0 ,v4 ); 1164vector signed char qxs10 = vec_and (qxs1 ,lowMask ); 1165vector signed char qxs11 = vec_sr (qxs1 ,v4 ); 1166 1167vector signed char q5h00 = vec_sl (vec_and ((vector signed char )v1 ,qxhs0 ),v4 ); 1168vector signed char q5h01 = vec_sl (vec_and ((vector signed char )v2 ,qxhs0 ),v3 ); 1169vector signed char q5h10 = vec_sl (vec_and ((vector signed char )v1 ,qxhs1 ),v4 ); 1170vector signed char q5h11 = vec_sl (vec_and ((vector signed char )v2 ,qxhs1 ),v3 ); 1171qxhs0 = vec_sr (qxhs0 ,v2 ); 1172qxhs1 = vec_sr (qxhs1 ,v2 ); 1173 1174vector unsigned char q5x00 = (vector unsigned char )vec_or (q5h00 ,qxs00 ); 1175vector unsigned char q5x01 = (vector unsigned char )vec_or (q5h01 ,qxs01 ); 1176vector unsigned char q5x10 = (vector unsigned char )vec_or (q5h10 ,qxs10 ); 1177vector unsigned char q5x11 = (vector unsigned char )vec_or (q5h11 ,qxs11 ); 1178 1179vector signed char q8y00 = vec_xl (0 ,q8 ); 1180vector signed char q8y10 = vec_xl (16 ,q8 ); 1181vector signed char q8y01 = vec_xl (32 ,q8 ); 1182vector signed char q8y11 = vec_xl (48 ,q8 ); 1183q8 += 64 ; 1184 1185vector signed int qv00 = vec_msum (q8y00 ,q5x00 ,v0 ); 1186vector signed int qv01 = vec_msum (q8y01 ,q5x01 ,v0 ); 1187vector signed int qv10 = vec_msum (q8y10 ,q5x10 ,v0 ); 1188vector signed int qv11 = vec_msum (q8y11 ,q5x11 ,v0 ); 1189 1190vector signed int vscales_h = vec_unpackh (vscales ); 1191vector signed int vs0 = vec_splat (vscales_h ,0 ); 1192vector signed int vs1 = vec_splat (vscales_h ,1 ); 1193vscales = vec_sld (vscales ,vscales ,12 ); 1194 1195vsumi0 = vec_add (vec_mul (qv00 ,vs0 ),vsumi0 ); 1196vsumi1 = vec_add (vec_mul (qv10 ,vs0 ),vsumi1 ); 1197vsumi2 = vec_add (vec_mul (qv01 ,vs1 ),vsumi2 ); 1198vsumi3 = vec_add (vec_mul (qv11 ,vs1 ),vsumi3 ); 1199 } 1200 1201vsumf0 = vec_madd (vec_ctf (vsumi0 ,0 ),vd ,vsumf0 ); 1202vsumf1 = vec_madd (vec_ctf (vsumi1 ,0 ),vd ,vsumf1 ); 1203vsumf2 = vec_madd (vec_ctf (vsumi2 ,0 ),vd ,vsumf2 ); 1204vsumf3 = vec_madd (vec_ctf (vsumi3 ,0 ),vd ,vsumf3 ); 1205 } 1206 1207vsumf0 = vec_add (vsumf0 ,vsumf2 ); 1208vsumf1 = vec_add (vsumf1 ,vsumf3 ); 1209 1210vsumf0 = vec_add (vsumf0 ,vsumf1 ); 1211 1212vsumf0 = vec_add (vsumf0 ,vec_sld (vsumf0 ,vsumf0 ,4 )); 1213vsumf0 = vec_add (vsumf0 ,vec_sld (vsumf0 ,vsumf0 ,8 )); 1214 1215* s = vec_extract (vsumf0 ,0 ); 1216 1217#else 1218UNUSED (x ); 1219UNUSED (y ); 1220UNUSED (nb ); 1221UNUSED (kmask1 ); 1222UNUSED (kmask2 ); 1223UNUSED (kmask3 ); 1224UNUSED (utmp ); 1225ggml_vec_dot_q5_K_q8_K_generic (n ,s ,bs ,vx ,bx ,vy ,by ,nrc ); 1226#endif 1227} 1228 1229void ggml_vec_dot_q6_K_q8_K (int n ,float * GGML_RESTRICT s ,size_t bs ,const void * GGML_RESTRICT vx ,size_t bx ,const void * GGML_RESTRICT vy ,size_t by ,int nrc ) { 1230assert (n %QK_K == 0 ); 1231assert (nrc == 1 ); 1232UNUSED (nrc ); 1233UNUSED (bx ); 1234UNUSED (by ); 1235UNUSED (bs ); 1236 1237const block_q6_K * GGML_RESTRICT x = vx ; 1238const block_q8_K * GGML_RESTRICT y = vy ; 1239 1240const int nb = n /QK_K ; 1241 1242#if defined(__POWER9_VECTOR__ ) 1243const vector signed char lowMask = vec_splats ((signed char )0xF ); 1244const vector int v0 = vec_splats ((int32_t )0 ); 1245const vector unsigned char v2 = vec_splats ((unsigned char )0x2 ); 1246const vector unsigned char v3 = vec_splats ((unsigned char )0x3 ); 1247const vector unsigned char v4 = vec_splats ((unsigned char )0x4 ); 1248const vector unsigned char v6 = vec_splats ((unsigned char )0x6 ); 1249const vector signed char off = vec_splats ((signed char )0x20 ); 1250 1251vector float vsumf0 = vec_splats (0.0f ); 1252vector float vsumf1 = vec_splats (0.0f ); 1253vector float vsumf2 = vec_splats (0.0f ); 1254vector float vsumf3 = vec_splats (0.0f ); 1255 1256for (int i = 0 ;i < nb ;++ i ) { 1257vector float vxd = vec_splats (GGML_CPU_FP16_TO_FP32 (x [i ].d )); 1258vector float vyd = vec_splats (y [i ].d ); 1259vector float vd = vec_mul (vxd ,vyd ); 1260 1261vector signed int vsumi0 = v0 ; 1262vector signed int vsumi1 = v0 ; 1263vector signed int vsumi2 = v0 ; 1264vector signed int vsumi3 = v0 ; 1265vector signed int vsumi4 = v0 ; 1266vector signed int vsumi5 = v0 ; 1267vector signed int vsumi6 = v0 ; 1268vector signed int vsumi7 = v0 ; 1269 1270const uint8_t * GGML_RESTRICT q6 = x [i ].ql ; 1271const uint8_t * GGML_RESTRICT qh = x [i ].qh ; 1272const int8_t * GGML_RESTRICT qs = x [i ].scales ; 1273const int8_t * GGML_RESTRICT q8 = y [i ].qs ; 1274 1275for (int j = 0 ;j < QK_K /128 ;++ j ) { 1276__builtin_prefetch (q6 ,0 ,0 ); 1277__builtin_prefetch (qh ,0 ,0 ); 1278__builtin_prefetch (q8 ,0 ,0 ); 1279 1280vector signed char qxs0 = (vector signed char )vec_xl (0 ,q6 ); 1281vector signed char qxs1 = (vector signed char )vec_xl (16 ,q6 ); 1282vector signed char qxs2 = (vector signed char )vec_xl (32 ,q6 ); 1283vector signed char qxs3 = (vector signed char )vec_xl (48 ,q6 ); 1284q6 += 64 ; 1285 1286vector signed char qxs00 = vec_and (qxs0 ,lowMask ); 1287vector signed char qxs01 = vec_sr (qxs0 ,v4 ); 1288vector signed char qxs10 = vec_and (qxs1 ,lowMask ); 1289vector signed char qxs11 = vec_sr (qxs1 ,v4 ); 1290vector signed char qxs20 = vec_and (qxs2 ,lowMask ); 1291vector signed char qxs21 = vec_sr (qxs2 ,v4 ); 1292vector signed char qxs30 = vec_and (qxs3 ,lowMask ); 1293vector signed char qxs31 = vec_sr (qxs3 ,v4 ); 1294 1295vector signed char qxhs0 = (vector signed char )vec_xl (0 ,qh ); 1296vector signed char qxhs1 = (vector signed char )vec_xl (16 ,qh ); 1297qh += 32 ; 1298 1299vector signed char qxh00 = vec_sl (vec_and ((vector signed char )v3 ,qxhs0 ),v4 ); 1300vector signed char qxh01 = vec_sl (vec_and ((vector signed char )v3 ,vec_sr (qxhs0 ,v4 )),v4 ); 1301vector signed char qxh10 = vec_sl (vec_and ((vector signed char )v3 ,qxhs1 ),v4 ); 1302vector signed char qxh11 = vec_sl (vec_and ((vector signed char )v3 ,vec_sr (qxhs1 ,v4 )),v4 ); 1303vector signed char qxh20 = vec_sl (vec_and ((vector signed char )v3 ,vec_sr (qxhs0 ,v2 )),v4 ); 1304vector signed char qxh21 = vec_sl (vec_and ((vector signed char )v3 ,vec_sr (qxhs0 ,v6 )),v4 ); 1305vector signed char qxh30 = vec_sl (vec_and ((vector signed char )v3 ,vec_sr (qxhs1 ,v2 )),v4 ); 1306vector signed char qxh31 = vec_sl (vec_and ((vector signed char )v3 ,vec_sr (qxhs1 ,v6 )),v4 ); 1307 1308vector signed char q6x00 = vec_sub (vec_or (qxh00 ,qxs00 ),off ); 1309vector signed char q6x01 = vec_sub (vec_or (qxh01 ,qxs01 ),off ); 1310vector signed char q6x10 = vec_sub (vec_or (qxh10 ,qxs10 ),off ); 1311vector signed char q6x11 = vec_sub (vec_or (qxh11 ,qxs11 ),off ); 1312vector signed char q6x20 = vec_sub (vec_or (qxh20 ,qxs20 ),off ); 1313vector signed char q6x21 = vec_sub (vec_or (qxh21 ,qxs21 ),off ); 1314vector signed char q6x30 = vec_sub (vec_or (qxh30 ,qxs30 ),off ); 1315vector signed char q6x31 = vec_sub (vec_or (qxh31 ,qxs31 ),off ); 1316 1317vector signed char q8y00 = vec_xl (0 ,q8 ); 1318vector signed char q8y10 = vec_xl (16 ,q8 ); 1319vector signed char q8y20 = vec_xl (32 ,q8 ); 1320vector signed char q8y30 = vec_xl (48 ,q8 ); 1321vector signed char q8y01 = vec_xl (64 ,q8 ); 1322vector signed char q8y11 = vec_xl (80 ,q8 ); 1323vector signed char q8y21 = vec_xl (96 ,q8 ); 1324vector signed char q8y31 = vec_xl (112 ,q8 ); 1325q8 += 128 ; 1326 1327vector signed short qv00 = vec_add (vec_mule (q6x00 ,q8y00 ),vec_mulo (q6x00 ,q8y00 )); 1328vector signed short qv10 = vec_add (vec_mule (q6x10 ,q8y10 ),vec_mulo (q6x10 ,q8y10 )); 1329vector signed short qv20 = vec_add (vec_mule (q6x20 ,q8y20 ),vec_mulo (q6x20 ,q8y20 )); 1330vector signed short qv30 = vec_add (vec_mule (q6x30 ,q8y30 ),vec_mulo (q6x30 ,q8y30 )); 1331vector signed short qv01 = vec_add (vec_mule (q6x01 ,q8y01 ),vec_mulo (q6x01 ,q8y01 )); 1332vector signed short qv11 = vec_add (vec_mule (q6x11 ,q8y11 ),vec_mulo (q6x11 ,q8y11 )); 1333vector signed short qv21 = vec_add (vec_mule (q6x21 ,q8y21 ),vec_mulo (q6x21 ,q8y21 )); 1334vector signed short qv31 = vec_add (vec_mule (q6x31 ,q8y31 ),vec_mulo (q6x31 ,q8y31 )); 1335 1336vector signed short vscales = vec_unpackh (vec_xl_len (qs ,8 )); 1337qs += 8 ; 1338 1339vector signed short vs0 = vec_splat (vscales ,0 ); 1340vector signed short vs1 = vec_splat (vscales ,1 ); 1341vector signed short vs2 = vec_splat (vscales ,2 ); 1342vector signed short vs3 = vec_splat (vscales ,3 ); 1343vector signed short vs4 = vec_splat (vscales ,4 ); 1344vector signed short vs5 = vec_splat (vscales ,5 ); 1345vector signed short vs6 = vec_splat (vscales ,6 ); 1346vector signed short vs7 = vec_splat (vscales ,7 ); 1347 1348vsumi0 = vec_msum (qv00 ,vs0 ,vsumi0 ); 1349vsumi1 = vec_msum (qv01 ,vs4 ,vsumi1 ); 1350vsumi2 = vec_msum (qv10 ,vs1 ,vsumi2 ); 1351vsumi3 = vec_msum (qv11 ,vs5 ,vsumi3 ); 1352vsumi4 = vec_msum (qv20 ,vs2 ,vsumi4 ); 1353vsumi5 = vec_msum (qv21 ,vs6 ,vsumi5 ); 1354vsumi6 = vec_msum (qv30 ,vs3 ,vsumi6 ); 1355vsumi7 = vec_msum (qv31 ,vs7 ,vsumi7 ); 1356 } 1357 1358vsumi0 = vec_add (vsumi0 ,vsumi4 ); 1359vsumi1 = vec_add (vsumi1 ,vsumi5 ); 1360vsumi2 = vec_add (vsumi2 ,vsumi6 ); 1361vsumi3 = vec_add (vsumi3 ,vsumi7 ); 1362 1363vsumf0 = vec_madd (vec_ctf (vsumi0 ,0 ),vd ,vsumf0 ); 1364vsumf1 = vec_madd (vec_ctf (vsumi1 ,0 ),vd ,vsumf1 ); 1365vsumf2 = vec_madd (vec_ctf (vsumi2 ,0 ),vd ,vsumf2 ); 1366vsumf3 = vec_madd (vec_ctf (vsumi3 ,0 ),vd ,vsumf3 ); 1367 } 1368 1369vsumf0 = vec_add (vsumf0 ,vsumf2 ); 1370vsumf1 = vec_add (vsumf1 ,vsumf3 ); 1371 1372vsumf0 = vec_add (vsumf0 ,vsumf1 ); 1373 1374vsumf0 = vec_add (vsumf0 ,vec_sld (vsumf0 ,vsumf0 ,4 )); 1375vsumf0 = vec_add (vsumf0 ,vec_sld (vsumf0 ,vsumf0 ,8 )); 1376 1377* s = vec_extract (vsumf0 ,0 ); 1378 1379#else 1380UNUSED (x ); 1381UNUSED (y ); 1382UNUSED (nb ); 1383ggml_vec_dot_q6_K_q8_K_generic (n ,s ,bs ,vx ,bx ,vy ,by ,nrc ); 1384#endif 1385} 1386 1387#if defined (__POWER9_VECTOR__ ) 1388static const int8_t keven_signs_q2xs [1024 ]= { 13891 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,-1 ,1 ,1 ,1 ,1 ,1 ,1 ,-1 ,1 ,-1 ,1 ,1 ,1 ,1 ,1 ,-1 ,-1 ,-1 ,1 ,1 ,1 ,1 ,1 ,1 , 13901 ,1 ,-1 ,1 ,1 ,1 ,1 ,-1 ,-1 ,1 ,-1 ,1 ,1 ,1 ,1 ,1 ,1 ,-1 ,-1 ,1 ,1 ,1 ,1 ,1 ,-1 ,-1 ,-1 ,1 ,1 ,1 ,1 ,-1 , 13911 ,1 ,1 ,-1 ,1 ,1 ,1 ,-1 ,-1 ,1 ,1 ,-1 ,1 ,1 ,1 ,1 ,1 ,-1 ,1 ,-1 ,1 ,1 ,1 ,1 ,-1 ,-1 ,1 ,-1 ,1 ,1 ,1 ,-1 , 13921 ,1 ,-1 ,-1 ,1 ,1 ,1 ,1 ,-1 ,1 ,-1 ,-1 ,1 ,1 ,1 ,-1 ,1 ,-1 ,-1 ,-1 ,1 ,1 ,1 ,-1 ,-1 ,-1 ,-1 ,-1 ,1 ,1 ,1 ,1 , 13931 ,1 ,1 ,1 ,-1 ,1 ,1 ,-1 ,-1 ,1 ,1 ,1 ,-1 ,1 ,1 ,1 ,1 ,-1 ,1 ,1 ,-1 ,1 ,1 ,1 ,-1 ,-1 ,1 ,1 ,-1 ,1 ,1 ,-1 , 13941 ,1 ,-1 ,1 ,-1 ,1 ,1 ,1 ,-1 ,1 ,-1 ,1 ,-1 ,1 ,1 ,-1 ,1 ,-1 ,-1 ,1 ,-1 ,1 ,1 ,-1 ,-1 ,-1 ,-1 ,1 ,-1 ,1 ,1 ,1 , 13951 ,1 ,1 ,-1 ,-1 ,1 ,1 ,1 ,-1 ,1 ,1 ,-1 ,-1 ,1 ,1 ,-1 ,1 ,-1 ,1 ,-1 ,-1 ,1 ,1 ,-1 ,-1 ,-1 ,1 ,-1 ,-1 ,1 ,1 ,1 , 13961 ,1 ,-1 ,-1 ,-1 ,1 ,1 ,-1 ,-1 ,1 ,-1 ,-1 ,-1 ,1 ,1 ,1 ,1 ,-1 ,-1 ,-1 ,-1 ,1 ,1 ,1 ,-1 ,-1 ,-1 ,-1 ,-1 ,1 ,1 ,-1 , 13971 ,1 ,1 ,1 ,1 ,-1 ,1 ,-1 ,-1 ,1 ,1 ,1 ,1 ,-1 ,1 ,1 ,1 ,-1 ,1 ,1 ,1 ,-1 ,1 ,1 ,-1 ,-1 ,1 ,1 ,1 ,-1 ,1 ,-1 , 13981 ,1 ,-1 ,1 ,1 ,-1 ,1 ,1 ,-1 ,1 ,-1 ,1 ,1 ,-1 ,1 ,-1 ,1 ,-1 ,-1 ,1 ,1 ,-1 ,1 ,-1 ,-1 ,-1 ,-1 ,1 ,1 ,-1 ,1 ,1 , 13991 ,1 ,1 ,-1 ,1 ,-1 ,1 ,1 ,-1 ,1 ,1 ,-1 ,1 ,-1 ,1 ,-1 ,1 ,-1 ,1 ,-1 ,1 ,-1 ,1 ,-1 ,-1 ,-1 ,1 ,-1 ,1 ,-1 ,1 ,1 , 14001 ,1 ,-1 ,-1 ,1 ,-1 ,1 ,-1 ,-1 ,1 ,-1 ,-1 ,1 ,-1 ,1 ,1 ,1 ,-1 ,-1 ,-1 ,1 ,-1 ,1 ,1 ,-1 ,-1 ,-1 ,-1 ,1 ,-1 ,1 ,-1 , 14011 ,1 ,1 ,1 ,-1 ,-1 ,1 ,1 ,-1 ,1 ,1 ,1 ,-1 ,-1 ,1 ,-1 ,1 ,-1 ,1 ,1 ,-1 ,-1 ,1 ,-1 ,-1 ,-1 ,1 ,1 ,-1 ,-1 ,1 ,1 , 14021 ,1 ,-1 ,1 ,-1 ,-1 ,1 ,-1 ,-1 ,1 ,-1 ,1 ,-1 ,-1 ,1 ,1 ,1 ,-1 ,-1 ,1 ,-1 ,-1 ,1 ,1 ,-1 ,-1 ,-1 ,1 ,-1 ,-1 ,1 ,-1 , 14031 ,1 ,1 ,-1 ,-1 ,-1 ,1 ,-1 ,-1 ,1 ,1 ,-1 ,-1 ,-1 ,1 ,1 ,1 ,-1 ,1 ,-1 ,-1 ,-1 ,1 ,1 ,-1 ,-1 ,1 ,-1 ,-1 ,-1 ,1 ,-1 , 14041 ,1 ,-1 ,-1 ,-1 ,-1 ,1 ,1 ,-1 ,1 ,-1 ,-1 ,-1 ,-1 ,1 ,-1 ,1 ,-1 ,-1 ,-1 ,-1 ,-1 ,1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,1 ,1 , 14051 ,1 ,1 ,1 ,1 ,1 ,-1 ,-1 ,-1 ,1 ,1 ,1 ,1 ,1 ,-1 ,1 ,1 ,-1 ,1 ,1 ,1 ,1 ,-1 ,1 ,-1 ,-1 ,1 ,1 ,1 ,1 ,-1 ,-1 , 14061 ,1 ,-1 ,1 ,1 ,1 ,-1 ,1 ,-1 ,1 ,-1 ,1 ,1 ,1 ,-1 ,-1 ,1 ,-1 ,-1 ,1 ,1 ,1 ,-1 ,-1 ,-1 ,-1 ,-1 ,1 ,1 ,1 ,-1 ,1 , 14071 ,1 ,1 ,-1 ,1 ,1 ,-1 ,1 ,-1 ,1 ,1 ,-1 ,1 ,1 ,-1 ,-1 ,1 ,-1 ,1 ,-1 ,1 ,1 ,-1 ,-1 ,-1 ,-1 ,1 ,-1 ,1 ,1 ,-1 ,1 , 14081 ,1 ,-1 ,-1 ,1 ,1 ,-1 ,-1 ,-1 ,1 ,-1 ,-1 ,1 ,1 ,-1 ,1 ,1 ,-1 ,-1 ,-1 ,1 ,1 ,-1 ,1 ,-1 ,-1 ,-1 ,-1 ,1 ,1 ,-1 ,-1 , 14091 ,1 ,1 ,1 ,-1 ,1 ,-1 ,1 ,-1 ,1 ,1 ,1 ,-1 ,1 ,-1 ,-1 ,1 ,-1 ,1 ,1 ,-1 ,1 ,-1 ,-1 ,-1 ,-1 ,1 ,1 ,-1 ,1 ,-1 ,1 , 14101 ,1 ,-1 ,1 ,-1 ,1 ,-1 ,-1 ,-1 ,1 ,-1 ,1 ,-1 ,1 ,-1 ,1 ,1 ,-1 ,-1 ,1 ,-1 ,1 ,-1 ,1 ,-1 ,-1 ,-1 ,1 ,-1 ,1 ,-1 ,-1 , 14111 ,1 ,1 ,-1 ,-1 ,1 ,-1 ,-1 ,-1 ,1 ,1 ,-1 ,-1 ,1 ,-1 ,1 ,1 ,-1 ,1 ,-1 ,-1 ,1 ,-1 ,1 ,-1 ,-1 ,1 ,-1 ,-1 ,1 ,-1 ,-1 , 14121 ,1 ,-1 ,-1 ,-1 ,1 ,-1 ,1 ,-1 ,1 ,-1 ,-1 ,-1 ,1 ,-1 ,-1 ,1 ,-1 ,-1 ,-1 ,-1 ,1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,1 ,-1 ,1 , 14131 ,1 ,1 ,1 ,1 ,-1 ,-1 ,1 ,-1 ,1 ,1 ,1 ,1 ,-1 ,-1 ,-1 ,1 ,-1 ,1 ,1 ,1 ,-1 ,-1 ,-1 ,-1 ,-1 ,1 ,1 ,1 ,-1 ,-1 ,1 , 14141 ,1 ,-1 ,1 ,1 ,-1 ,-1 ,-1 ,-1 ,1 ,-1 ,1 ,1 ,-1 ,-1 ,1 ,1 ,-1 ,-1 ,1 ,1 ,-1 ,-1 ,1 ,-1 ,-1 ,-1 ,1 ,1 ,-1 ,-1 ,-1 , 14151 ,1 ,1 ,-1 ,1 ,-1 ,-1 ,-1 ,-1 ,1 ,1 ,-1 ,1 ,-1 ,-1 ,1 ,1 ,-1 ,1 ,-1 ,1 ,-1 ,-1 ,1 ,-1 ,-1 ,1 ,-1 ,1 ,-1 ,-1 ,-1 , 14161 ,1 ,-1 ,-1 ,1 ,-1 ,-1 ,1 ,-1 ,1 ,-1 ,-1 ,1 ,-1 ,-1 ,-1 ,1 ,-1 ,-1 ,-1 ,1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,1 ,-1 ,-1 ,1 , 14171 ,1 ,1 ,1 ,-1 ,-1 ,-1 ,-1 ,-1 ,1 ,1 ,1 ,-1 ,-1 ,-1 ,1 ,1 ,-1 ,1 ,1 ,-1 ,-1 ,-1 ,1 ,-1 ,-1 ,1 ,1 ,-1 ,-1 ,-1 ,-1 , 14181 ,1 ,-1 ,1 ,-1 ,-1 ,-1 ,1 ,-1 ,1 ,-1 ,1 ,-1 ,-1 ,-1 ,-1 ,1 ,-1 ,-1 ,1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,1 ,-1 ,-1 ,-1 ,1 , 14191 ,1 ,1 ,-1 ,-1 ,-1 ,-1 ,1 ,-1 ,1 ,1 ,-1 ,-1 ,-1 ,-1 ,-1 ,1 ,-1 ,1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,1 ,-1 ,-1 ,-1 ,-1 ,1 , 14201 ,1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,1 ,-1 ,-1 ,-1 ,-1 ,-1 ,1 ,1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 , 1421}; 1422#endif 1423 1424void ggml_vec_dot_iq2_xxs_q8_K (int n ,float * GGML_RESTRICT s ,size_t bs ,const void * GGML_RESTRICT vx ,size_t bx ,const void * GGML_RESTRICT vy ,size_t by ,int nrc ) { 1425assert (n %QK_K == 0 ); 1426assert (nrc == 1 ); 1427UNUSED (nrc ); 1428UNUSED (bx ); 1429UNUSED (by ); 1430UNUSED (bs ); 1431 1432const block_iq2_xxs * GGML_RESTRICT x = vx ; 1433const block_q8_K * GGML_RESTRICT y = vy ; 1434 1435const int nb = n /QK_K ; 1436 1437#if defined(__POWER9_VECTOR__ ) 1438const vector int v0 = vec_splats ((int32_t )0 ); 1439vector float vsumf0 = vec_splats (0.0f ); 1440vector float vsumf1 = vec_splats (0.0f ); 1441vector float vsumf2 = vec_splats (0.0f ); 1442vector float vsumf3 = vec_splats (0.0f ); 1443 1444const uint64_t * signs64 = (const uint64_t * )keven_signs_q2xs ; 1445 1446for (int i = 0 ;i < nb ;++ i ) { 1447vector float vxd = vec_splats (GGML_CPU_FP16_TO_FP32 (x [i ].d )); 1448vector float vyd = vec_splats (y [i ].d ); 1449vector float vd = vec_mul (vxd ,vyd ); 1450 1451vector signed int vsumi0 = v0 ; 1452vector signed int vsumi1 = v0 ; 1453vector signed int vsumi2 = v0 ; 1454vector signed int vsumi3 = v0 ; 1455 1456const uint16_t * GGML_RESTRICT q2 = x [i ].qs ; 1457const int8_t * GGML_RESTRICT q8 = y [i ].qs ; 1458 1459for (int j = 0 ;j < QK_K /32 ;j += 2 ) { 1460__builtin_prefetch (q2 ,0 ,1 ); 1461__builtin_prefetch (q8 ,0 ,1 ); 1462 1463uint32_t aux32 [4 ]; 1464const uint8_t * aux8 = (const uint8_t * )aux32 ; 1465 1466memcpy (aux32 ,q2 ,4 * sizeof (uint32_t )); 1467q2 += 8 ; 1468 1469vector signed long long aux64x2_0 = {* (const int64_t * )(iq2xxs_grid + aux8 [0 ]),* (const int64_t * )(iq2xxs_grid + aux8 [1 ])}; 1470vector signed long long aux64x2_1 = {* (const int64_t * )(iq2xxs_grid + aux8 [2 ]),* (const int64_t * )(iq2xxs_grid + aux8 [3 ])}; 1471vector signed long long aux64x2_2 = {* (const int64_t * )(iq2xxs_grid + aux8 [8 ]),* (const int64_t * )(iq2xxs_grid + aux8 [9 ])}; 1472vector signed long long aux64x2_3 = {* (const int64_t * )(iq2xxs_grid + aux8 [10 ]),* (const int64_t * )(iq2xxs_grid + aux8 [11 ])}; 1473 1474vector signed long long vsigns0 = {* (const int64_t * )(signs64 + ((aux32 [1 ] >>0 )& 127 )),* (const int64_t * )(signs64 + ((aux32 [1 ] >>7 )& 127 ))}; 1475vector signed long long vsigns1 = {* (const int64_t * )(signs64 + ((aux32 [1 ] >>14 )& 127 )),* (const int64_t * )(signs64 + ((aux32 [1 ] >>21 )& 127 ))}; 1476vector signed long long vsigns2 = {* (const int64_t * )(signs64 + ((aux32 [3 ] >>0 )& 127 )),* (const int64_t * )(signs64 + ((aux32 [3 ] >>7 )& 127 ))}; 1477vector signed long long vsigns3 = {* (const int64_t * )(signs64 + ((aux32 [3 ] >>14 )& 127 )),* (const int64_t * )(signs64 + ((aux32 [3 ] >>21 )& 127 ))}; 1478 1479vector signed char q2x0 = (vector signed char )vec_mul ((vector signed char )vsigns0 , (vector signed char )aux64x2_0 ); 1480vector signed char q2x1 = (vector signed char )vec_mul ((vector signed char )vsigns1 , (vector signed char )aux64x2_1 ); 1481vector signed char q2x2 = (vector signed char )vec_mul ((vector signed char )vsigns2 , (vector signed char )aux64x2_2 ); 1482vector signed char q2x3 = (vector signed char )vec_mul ((vector signed char )vsigns3 , (vector signed char )aux64x2_3 ); 1483 1484vector signed char q8y0 = vec_xl (0 ,q8 ); 1485vector signed char q8y1 = vec_xl (16 ,q8 ); 1486vector signed char q8y2 = vec_xl (32 ,q8 ); 1487vector signed char q8y3 = vec_xl (48 ,q8 ); 1488q8 += 64 ; 1489 1490vector signed short qv0 = vec_add (vec_mule (q2x0 ,q8y0 ),vec_mulo (q2x0 ,q8y0 )); 1491vector signed short qv1 = vec_add (vec_mule (q2x1 ,q8y1 ),vec_mulo (q2x1 ,q8y1 )); 1492vector signed short qv2 = vec_add (vec_mule (q2x2 ,q8y2 ),vec_mulo (q2x2 ,q8y2 )); 1493vector signed short qv3 = vec_add (vec_mule (q2x3 ,q8y3 ),vec_mulo (q2x3 ,q8y3 )); 1494 1495const uint16_t ls0 = aux32 [1 ] >>28 ; 1496const uint16_t ls1 = aux32 [3 ] >>28 ; 1497 1498vector signed short vscales01 = vec_splats ((int16_t )(2 * ls0 + 1 )); 1499vector signed short vscales23 = vec_splats ((int16_t )(2 * ls1 + 1 )); 1500 1501vsumi0 = vec_msum (qv0 ,vscales01 ,vsumi0 ); 1502vsumi1 = vec_msum (qv1 ,vscales01 ,vsumi1 ); 1503vsumi2 = vec_msum (qv2 ,vscales23 ,vsumi2 ); 1504vsumi3 = vec_msum (qv3 ,vscales23 ,vsumi3 ); 1505 } 1506 1507vsumf0 = vec_madd (vec_ctf (vsumi0 ,0 ),vd ,vsumf0 ); 1508vsumf1 = vec_madd (vec_ctf (vsumi1 ,0 ),vd ,vsumf1 ); 1509vsumf2 = vec_madd (vec_ctf (vsumi2 ,0 ),vd ,vsumf2 ); 1510vsumf3 = vec_madd (vec_ctf (vsumi3 ,0 ),vd ,vsumf3 ); 1511 } 1512 1513vsumf0 = vec_add (vsumf0 ,vsumf2 ); 1514vsumf1 = vec_add (vsumf1 ,vsumf3 ); 1515 1516vsumf0 = vec_add (vsumf0 ,vsumf1 ); 1517 1518vsumf0 = vec_add (vsumf0 ,vec_sld (vsumf0 ,vsumf0 ,4 )); 1519vsumf0 = vec_add (vsumf0 ,vec_sld (vsumf0 ,vsumf0 ,8 )); 1520 1521* s = 0.125f * vec_extract (vsumf0 ,0 ); 1522 1523#else 1524UNUSED (x ); 1525UNUSED (y ); 1526UNUSED (nb ); 1527ggml_vec_dot_iq2_xxs_q8_K_generic (n ,s ,bs ,vx ,bx ,vy ,by ,nrc ); 1528#endif 1529} 1530 1531void ggml_vec_dot_iq2_xs_q8_K (int n ,float * GGML_RESTRICT s ,size_t bs ,const void * GGML_RESTRICT vx ,size_t bx ,const void * GGML_RESTRICT vy ,size_t by ,int nrc ) { 1532assert (n %QK_K == 0 ); 1533assert (nrc == 1 ); 1534UNUSED (nrc ); 1535UNUSED (bx ); 1536UNUSED (by ); 1537UNUSED (bs ); 1538 1539const block_iq2_xs * GGML_RESTRICT x = vx ; 1540const block_q8_K * GGML_RESTRICT y = vy ; 1541 1542const int nb = n /QK_K ; 1543 1544#if defined(__POWER9_VECTOR__ ) 1545const vector int v0 = vec_splats ((int32_t )0 ); 1546vector float vsumf0 = vec_splats (0.0f ); 1547vector float vsumf1 = vec_splats (0.0f ); 1548vector float vsumf2 = vec_splats (0.0f ); 1549vector float vsumf3 = vec_splats (0.0f ); 1550 1551const uint64_t * signs64 = (const uint64_t * )keven_signs_q2xs ; 1552 1553for (int i = 0 ;i < nb ;++ i ) { 1554vector float vxd = vec_splats (GGML_CPU_FP16_TO_FP32 (x [i ].d )); 1555vector float vyd = vec_splats (y [i ].d ); 1556vector float vd = vec_mul (vxd ,vyd ); 1557 1558vector signed int vsumi0 = v0 ; 1559vector signed int vsumi1 = v0 ; 1560vector signed int vsumi2 = v0 ; 1561vector signed int vsumi3 = v0 ; 1562 1563const uint16_t * GGML_RESTRICT q2 = x [i ].qs ; 1564const uint8_t * GGML_RESTRICT sc = x [i ].scales ; 1565const int8_t * GGML_RESTRICT q8 = y [i ].qs ; 1566 1567for (int j = 0 ;j < QK_K /64 ;++ j ) { 1568__builtin_prefetch (q2 ,0 ,1 ); 1569__builtin_prefetch (q8 ,0 ,1 ); 1570 1571vector signed long long aux64x2_0 = {* (const int64_t * )(iq2xs_grid + (q2 [0 ]& 511 )),* (const int64_t * )(iq2xs_grid + (q2 [1 ]& 511 ))}; 1572vector signed long long aux64x2_1 = {* (const int64_t * )(iq2xs_grid + (q2 [2 ]& 511 )),* (const int64_t * )(iq2xs_grid + (q2 [3 ]& 511 ))}; 1573vector signed long long aux64x2_2 = {* (const int64_t * )(iq2xs_grid + (q2 [4 ]& 511 )),* (const int64_t * )(iq2xs_grid + (q2 [5 ]& 511 ))}; 1574vector signed long long aux64x2_3 = {* (const int64_t * )(iq2xs_grid + (q2 [6 ]& 511 )),* (const int64_t * )(iq2xs_grid + (q2 [7 ]& 511 ))}; 1575 1576vector signed long long vsigns0 = {* (const int64_t * )(signs64 + ((q2 [0 ] >>9 ))),* (const int64_t * )(signs64 + ((q2 [1 ] >>9 )))}; 1577vector signed long long vsigns1 = {* (const int64_t * )(signs64 + ((q2 [2 ] >>9 ))),* (const int64_t * )(signs64 + ((q2 [3 ] >>9 )))}; 1578vector signed long long vsigns2 = {* (const int64_t * )(signs64 + ((q2 [4 ] >>9 ))),* (const int64_t * )(signs64 + ((q2 [5 ] >>9 )))}; 1579vector signed long long vsigns3 = {* (const int64_t * )(signs64 + ((q2 [6 ] >>9 ))),* (const int64_t * )(signs64 + ((q2 [7 ] >>9 )))}; 1580q2 += 8 ; 1581 1582vector signed char q2x0 = (vector signed char )vec_mul ((vector signed char )vsigns0 , (vector signed char )aux64x2_0 ); 1583vector signed char q2x1 = (vector signed char )vec_mul ((vector signed char )vsigns1 , (vector signed char )aux64x2_1 ); 1584vector signed char q2x2 = (vector signed char )vec_mul ((vector signed char )vsigns2 , (vector signed char )aux64x2_2 ); 1585vector signed char q2x3 = (vector signed char )vec_mul ((vector signed char )vsigns3 , (vector signed char )aux64x2_3 ); 1586 1587vector signed char q8y0 = vec_xl (0 ,q8 ); 1588vector signed char q8y1 = vec_xl (16 ,q8 ); 1589vector signed char q8y2 = vec_xl (32 ,q8 ); 1590vector signed char q8y3 = vec_xl (48 ,q8 ); 1591q8 += 64 ; 1592 1593vector signed short qv0 = vec_add (vec_mule (q2x0 ,q8y0 ),vec_mulo (q2x0 ,q8y0 )); 1594vector signed short qv1 = vec_add (vec_mule (q2x1 ,q8y1 ),vec_mulo (q2x1 ,q8y1 )); 1595vector signed short qv2 = vec_add (vec_mule (q2x2 ,q8y2 ),vec_mulo (q2x2 ,q8y2 )); 1596vector signed short qv3 = vec_add (vec_mule (q2x3 ,q8y3 ),vec_mulo (q2x3 ,q8y3 )); 1597 1598const uint16_t ls0 = (uint16_t )(sc [0 ]& 0xf ); 1599const uint16_t ls1 = (uint16_t )(sc [0 ] >>4 ); 1600const uint16_t ls2 = (uint16_t )(sc [1 ]& 0xf ); 1601const uint16_t ls3 = (uint16_t )(sc [1 ] >>4 ); 1602sc += 2 ; 1603 1604vector signed short vscales0 = vec_splats ((int16_t )(2 * ls0 + 1 )); 1605vector signed short vscales1 = vec_splats ((int16_t )(2 * ls1 + 1 )); 1606vector signed short vscales2 = vec_splats ((int16_t )(2 * ls2 + 1 )); 1607vector signed short vscales3 = vec_splats ((int16_t )(2 * ls3 + 1 )); 1608 1609vsumi0 = vec_msum (qv0 ,vscales0 ,vsumi0 ); 1610vsumi1 = vec_msum (qv1 ,vscales1 ,vsumi1 ); 1611vsumi2 = vec_msum (qv2 ,vscales2 ,vsumi2 ); 1612vsumi3 = vec_msum (qv3 ,vscales3 ,vsumi3 ); 1613 } 1614 1615vsumf0 = vec_madd (vec_ctf (vsumi0 ,0 ),vd ,vsumf0 ); 1616vsumf1 = vec_madd (vec_ctf (vsumi1 ,0 ),vd ,vsumf1 ); 1617vsumf2 = vec_madd (vec_ctf (vsumi2 ,0 ),vd ,vsumf2 ); 1618vsumf3 = vec_madd (vec_ctf (vsumi3 ,0 ),vd ,vsumf3 ); 1619 } 1620 1621vsumf0 = vec_add (vsumf0 ,vsumf2 ); 1622vsumf1 = vec_add (vsumf1 ,vsumf3 ); 1623 1624vsumf0 = vec_add (vsumf0 ,vsumf1 ); 1625 1626vsumf0 = vec_add (vsumf0 ,vec_sld (vsumf0 ,vsumf0 ,4 )); 1627vsumf0 = vec_add (vsumf0 ,vec_sld (vsumf0 ,vsumf0 ,8 )); 1628 1629* s = 0.125f * vec_extract (vsumf0 ,0 ); 1630 1631#else 1632UNUSED (x ); 1633UNUSED (y ); 1634UNUSED (nb ); 1635ggml_vec_dot_iq2_xs_q8_K_generic (n ,s ,bs ,vx ,bx ,vy ,by ,nrc ); 1636#endif 1637} 1638 1639void ggml_vec_dot_iq2_s_q8_K (int n ,float * GGML_RESTRICT s ,size_t bs ,const void * GGML_RESTRICT vx ,size_t bx ,const void * GGML_RESTRICT vy ,size_t by ,int nrc ) { 1640assert (n %QK_K == 0 ); 1641assert (nrc == 1 ); 1642UNUSED (nrc ); 1643UNUSED (bx ); 1644UNUSED (by ); 1645UNUSED (bs ); 1646 1647const block_iq2_s * GGML_RESTRICT x = vx ; 1648const block_q8_K * GGML_RESTRICT y = vy ; 1649 1650const int nb = n /QK_K ; 1651 1652#if defined(__POWER9_VECTOR__ ) 1653static const uint8_t k_mask1 [32 ]= {0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x01 ,0x01 ,0x01 ,0x01 ,0x01 ,0x01 ,0x01 ,0x01 , 16540x02 ,0x02 ,0x02 ,0x02 ,0x02 ,0x02 ,0x02 ,0x02 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 1655 }; 1656 1657static const uint8_t k_mask2 [16 ]= {0x01 ,0x02 ,0x04 ,0x08 ,0x10 ,0x20 ,0x40 ,0x80 ,0x01 ,0x02 ,0x04 ,0x08 ,0x10 ,0x20 ,0x40 ,0x80 ,}; 1658 1659const vector int v0 = vec_splats ((int32_t )0 ); 1660 1661vector float vsumf0 = vec_splats (0.0f ); 1662vector float vsumf1 = vec_splats (0.0f ); 1663vector float vsumf2 = vec_splats (0.0f ); 1664vector float vsumf3 = vec_splats (0.0f ); 1665 1666const vector unsigned char mask0 = vec_xl (0 ,k_mask1 ); 1667const vector unsigned char mask1 = vec_xl (16 ,k_mask1 ); 1668const vector signed char mask2 = (vector signed char )vec_xl (0 ,k_mask2 ); 1669 1670for (int i = 0 ;i < nb ;++ i ) { 1671vector float vxd = vec_splats (GGML_CPU_FP16_TO_FP32 (x [i ].d )); 1672vector float vyd = vec_splats (y [i ].d ); 1673vector float vd = vec_mul (vxd ,vyd ); 1674 1675vector signed int vsumi0 = v0 ; 1676vector signed int vsumi1 = v0 ; 1677vector signed int vsumi2 = v0 ; 1678vector signed int vsumi3 = v0 ; 1679 1680const uint8_t * GGML_RESTRICT q2 = x [i ].qs ; 1681const uint8_t * GGML_RESTRICT qh = x [i ].qh ; 1682const uint16_t * GGML_RESTRICT signs = (const uint16_t * )(x [i ].qs + QK_K /8 ); 1683const uint8_t * GGML_RESTRICT sc = x [i ].scales ; 1684const int8_t * GGML_RESTRICT q8 = y [i ].qs ; 1685 1686for (int j = 0 ;j < QK_K /32 ;j += 2 ) { 1687__builtin_prefetch (q2 ,0 ,1 ); 1688__builtin_prefetch (q8 ,0 ,1 ); 1689 1690vector signed long long aux64x2_0 = {* (const int64_t * )(iq2s_grid + (q2 [0 ] | ((qh [0 ] <<8 )& 0x300 ))),* (const int64_t * )(iq2s_grid + (q2 [1 ] | ((qh [0 ] <<6 )& 0x300 )))}; 1691vector signed long long aux64x2_1 = {* (const int64_t * )(iq2s_grid + (q2 [2 ] | ((qh [0 ] <<4 )& 0x300 ))),* (const int64_t * )(iq2s_grid + (q2 [3 ] | ((qh [0 ] <<2 )& 0x300 )))}; 1692vector signed long long aux64x2_2 = {* (const int64_t * )(iq2s_grid + (q2 [4 ] | ((qh [1 ] <<8 )& 0x300 ))),* (const int64_t * )(iq2s_grid + (q2 [5 ] | ((qh [1 ] <<6 )& 0x300 )))}; 1693vector signed long long aux64x2_3 = {* (const int64_t * )(iq2s_grid + (q2 [6 ] | ((qh [1 ] <<4 )& 0x300 ))),* (const int64_t * )(iq2s_grid + (q2 [7 ] | ((qh [1 ] <<2 )& 0x300 )))}; 1694q2 += 8 ; 1695qh += 2 ; 1696 1697vector signed char vsigns01 = (vector signed char )vec_splats (* (const uint32_t * )& signs [0 ]); 1698vector signed char vsigns23 = (vector signed char )vec_splats (* (const uint32_t * )& signs [2 ]); 1699signs += 4 ; 1700 1701vector signed char vsigns0 = vec_perm (vsigns01 ,vsigns01 ,mask0 ); 1702vector signed char vsigns1 = vec_perm (vsigns01 ,vsigns01 ,mask1 ); 1703vector signed char vsigns2 = vec_perm (vsigns23 ,vsigns23 ,mask0 ); 1704vector signed char vsigns3 = vec_perm (vsigns23 ,vsigns23 ,mask1 ); 1705 1706vsigns0 = (vector signed char )vec_cmpeq (vec_and (vsigns0 ,mask2 ),mask2 ); 1707vsigns1 = (vector signed char )vec_cmpeq (vec_and (vsigns1 ,mask2 ),mask2 ); 1708vsigns2 = (vector signed char )vec_cmpeq (vec_and (vsigns2 ,mask2 ),mask2 ); 1709vsigns3 = (vector signed char )vec_cmpeq (vec_and (vsigns3 ,mask2 ),mask2 ); 1710 1711vector signed char q2x0 = vec_sub (vec_xor (vsigns0 , (vector signed char )aux64x2_0 ),vsigns0 ); 1712vector signed char q2x1 = vec_sub (vec_xor (vsigns1 , (vector signed char )aux64x2_1 ),vsigns1 ); 1713vector signed char q2x2 = vec_sub (vec_xor (vsigns2 , (vector signed char )aux64x2_2 ),vsigns2 ); 1714vector signed char q2x3 = vec_sub (vec_xor (vsigns3 , (vector signed char )aux64x2_3 ),vsigns3 ); 1715 1716vector signed char q8y0 = vec_xl (0 ,q8 ); 1717vector signed char q8y1 = vec_xl (16 ,q8 ); 1718vector signed char q8y2 = vec_xl (32 ,q8 ); 1719vector signed char q8y3 = vec_xl (48 ,q8 ); 1720q8 += 64 ; 1721 1722vector signed short qv0 = vec_add (vec_mule (q2x0 ,q8y0 ),vec_mulo (q2x0 ,q8y0 )); 1723vector signed short qv1 = vec_add (vec_mule (q2x1 ,q8y1 ),vec_mulo (q2x1 ,q8y1 )); 1724vector signed short qv2 = vec_add (vec_mule (q2x2 ,q8y2 ),vec_mulo (q2x2 ,q8y2 )); 1725vector signed short qv3 = vec_add (vec_mule (q2x3 ,q8y3 ),vec_mulo (q2x3 ,q8y3 )); 1726 1727const uint16_t ls0 = (uint16_t )(sc [0 ]& 0xf ); 1728const uint16_t ls1 = (uint16_t )(sc [0 ] >>4 ); 1729const uint16_t ls2 = (uint16_t )(sc [1 ]& 0xf ); 1730const uint16_t ls3 = (uint16_t )(sc [1 ] >>4 ); 1731sc += 2 ; 1732 1733vector signed short vscales0 = vec_splats ((int16_t )(2 * ls0 + 1 )); 1734vector signed short vscales1 = vec_splats ((int16_t )(2 * ls1 + 1 )); 1735vector signed short vscales2 = vec_splats ((int16_t )(2 * ls2 + 1 )); 1736vector signed short vscales3 = vec_splats ((int16_t )(2 * ls3 + 1 )); 1737 1738vsumi0 = vec_msum (qv0 ,vscales0 ,vsumi0 ); 1739vsumi1 = vec_msum (qv1 ,vscales1 ,vsumi1 ); 1740vsumi2 = vec_msum (qv2 ,vscales2 ,vsumi2 ); 1741vsumi3 = vec_msum (qv3 ,vscales3 ,vsumi3 ); 1742 } 1743 1744vsumf0 = vec_madd (vec_ctf (vsumi0 ,0 ),vd ,vsumf0 ); 1745vsumf1 = vec_madd (vec_ctf (vsumi1 ,0 ),vd ,vsumf1 ); 1746vsumf2 = vec_madd (vec_ctf (vsumi2 ,0 ),vd ,vsumf2 ); 1747vsumf3 = vec_madd (vec_ctf (vsumi3 ,0 ),vd ,vsumf3 ); 1748 } 1749 1750vsumf0 = vec_add (vsumf0 ,vsumf2 ); 1751vsumf1 = vec_add (vsumf1 ,vsumf3 ); 1752 1753vsumf0 = vec_add (vsumf0 ,vsumf1 ); 1754 1755vsumf0 = vec_add (vsumf0 ,vec_sld (vsumf0 ,vsumf0 ,4 )); 1756vsumf0 = vec_add (vsumf0 ,vec_sld (vsumf0 ,vsumf0 ,8 )); 1757 1758* s = 0.125f * vec_extract (vsumf0 ,0 ); 1759 1760#else 1761UNUSED (x ); 1762UNUSED (y ); 1763UNUSED (nb ); 1764ggml_vec_dot_iq2_s_q8_K_generic (n ,s ,bs ,vx ,bx ,vy ,by ,nrc ); 1765#endif 1766} 1767 1768void ggml_vec_dot_iq3_xxs_q8_K (int n ,float * GGML_RESTRICT s ,size_t bs ,const void * GGML_RESTRICT vx ,size_t bx ,const void * GGML_RESTRICT vy ,size_t by ,int nrc ) { 1769assert (n %QK_K == 0 ); 1770assert (nrc == 1 ); 1771UNUSED (nrc ); 1772UNUSED (bx ); 1773UNUSED (by ); 1774UNUSED (bs ); 1775 1776const block_iq3_xxs * GGML_RESTRICT x = vx ; 1777const block_q8_K * GGML_RESTRICT y = vy ; 1778 1779const int nb = n /QK_K ; 1780 1781#if defined(__POWER9_VECTOR__ ) 1782const uint64_t * signs64 = (const uint64_t * )keven_signs_q2xs ; 1783 1784const vector int v0 = vec_splats ((int32_t )0 ); 1785 1786vector float vsumf0 = vec_splats (0.0f ); 1787vector float vsumf1 = vec_splats (0.0f ); 1788vector float vsumf2 = vec_splats (0.0f ); 1789vector float vsumf3 = vec_splats (0.0f ); 1790 1791for (int i = 0 ;i < nb ;++ i ) { 1792vector float vxd = vec_splats (GGML_CPU_FP16_TO_FP32 (x [i ].d )); 1793vector float vyd = vec_splats (y [i ].d ); 1794vector float vd = vec_mul (vxd ,vyd ); 1795 1796vector signed int vsumi0 = v0 ; 1797vector signed int vsumi1 = v0 ; 1798vector signed int vsumi2 = v0 ; 1799vector signed int vsumi3 = v0 ; 1800 1801const uint8_t * GGML_RESTRICT q3 = x [i ].qs ; 1802const uint32_t * GGML_RESTRICT signs = (const uint32_t * )(x [i ].qs + QK_K /4 ); 1803const int8_t * GGML_RESTRICT q8 = y [i ].qs ; 1804 1805#pragma GCC unroll 1 1806for (int j = 0 ;j < QK_K /32 ;j += 2 ) { 1807__builtin_prefetch (q3 ,0 ,1 ); 1808__builtin_prefetch (q8 ,0 ,1 ); 1809 1810vector unsigned int aux32x4_0 = {iq3xxs_grid [q3 [0 ]],iq3xxs_grid [q3 [1 ]],iq3xxs_grid [q3 [2 ]],iq3xxs_grid [q3 [3 ]]}; 1811vector unsigned int aux32x4_1 = {iq3xxs_grid [q3 [4 ]],iq3xxs_grid [q3 [5 ]],iq3xxs_grid [q3 [6 ]],iq3xxs_grid [q3 [7 ]]}; 1812vector unsigned int aux32x4_2 = {iq3xxs_grid [q3 [8 ]],iq3xxs_grid [q3 [9 ]],iq3xxs_grid [q3 [10 ]],iq3xxs_grid [q3 [11 ]]}; 1813vector unsigned int aux32x4_3 = {iq3xxs_grid [q3 [12 ]],iq3xxs_grid [q3 [13 ]],iq3xxs_grid [q3 [14 ]],iq3xxs_grid [q3 [15 ]]}; 1814q3 += 16 ; 1815 1816vector unsigned long long aux64x2_0 = {(uint64_t )(signs64 [(signs [0 ] >>0 )& 127 ]), (uint64_t )(signs64 [(signs [0 ] >>7 )& 127 ])}; 1817vector unsigned long long aux64x2_1 = {(uint64_t )(signs64 [(signs [0 ] >>14 )& 127 ]), (uint64_t )(signs64 [(signs [0 ] >>21 )& 127 ])}; 1818vector unsigned long long aux64x2_2 = {(uint64_t )(signs64 [(signs [1 ] >>0 )& 127 ]), (uint64_t )(signs64 [(signs [1 ] >>7 )& 127 ])}; 1819vector unsigned long long aux64x2_3 = {(uint64_t )(signs64 [(signs [1 ] >>14 )& 127 ]), (uint64_t )(signs64 [(signs [1 ] >>21 )& 127 ])}; 1820 1821vector signed char q3x0 = vec_mul ((vector signed char )aux64x2_0 , (vector signed char )aux32x4_0 ); 1822vector signed char q3x1 = vec_mul ((vector signed char )aux64x2_1 , (vector signed char )aux32x4_1 ); 1823vector signed char q3x2 = vec_mul ((vector signed char )aux64x2_2 , (vector signed char )aux32x4_2 ); 1824vector signed char q3x3 = vec_mul ((vector signed char )aux64x2_3 , (vector signed char )aux32x4_3 ); 1825 1826vector signed char q8y0 = vec_xl (0 ,q8 ); 1827vector signed char q8y1 = vec_xl (16 ,q8 ); 1828vector signed char q8y2 = vec_xl (32 ,q8 ); 1829vector signed char q8y3 = vec_xl (48 ,q8 ); 1830q8 += 64 ; 1831 1832vector signed short qv0 = vec_add (vec_mule (q3x0 ,q8y0 ),vec_mulo (q3x0 ,q8y0 )); 1833vector signed short qv1 = vec_add (vec_mule (q3x1 ,q8y1 ),vec_mulo (q3x1 ,q8y1 )); 1834vector signed short qv2 = vec_add (vec_mule (q3x2 ,q8y2 ),vec_mulo (q3x2 ,q8y2 )); 1835vector signed short qv3 = vec_add (vec_mule (q3x3 ,q8y3 ),vec_mulo (q3x3 ,q8y3 )); 1836 1837const uint16_t ls0 = (uint16_t )(signs [0 ] >>28 ); 1838const uint16_t ls1 = (uint16_t )(signs [1 ] >>28 ); 1839signs += 2 ; 1840 1841vector signed short vscales01 = (vector signed short )vec_splats ((uint16_t )(2 * ls0 + 1 )); 1842vector signed short vscales23 = (vector signed short )vec_splats ((uint16_t )(2 * ls1 + 1 )); 1843 1844vsumi0 = vec_msum (qv0 ,vscales01 ,vsumi0 ); 1845vsumi1 = vec_msum (qv1 ,vscales01 ,vsumi1 ); 1846vsumi2 = vec_msum (qv2 ,vscales23 ,vsumi2 ); 1847vsumi3 = vec_msum (qv3 ,vscales23 ,vsumi3 ); 1848 } 1849 1850vsumf0 = vec_madd (vec_ctf (vsumi0 ,0 ),vd ,vsumf0 ); 1851vsumf1 = vec_madd (vec_ctf (vsumi1 ,0 ),vd ,vsumf1 ); 1852vsumf2 = vec_madd (vec_ctf (vsumi2 ,0 ),vd ,vsumf2 ); 1853vsumf3 = vec_madd (vec_ctf (vsumi3 ,0 ),vd ,vsumf3 ); 1854 } 1855 1856vsumf0 = vec_add (vsumf0 ,vsumf2 ); 1857vsumf1 = vec_add (vsumf1 ,vsumf3 ); 1858 1859vsumf0 = vec_add (vsumf0 ,vsumf1 ); 1860 1861vsumf0 = vec_add (vsumf0 ,vec_sld (vsumf0 ,vsumf0 ,4 )); 1862vsumf0 = vec_add (vsumf0 ,vec_sld (vsumf0 ,vsumf0 ,8 )); 1863 1864* s = 0.25f * vec_extract (vsumf0 ,0 ); 1865 1866#else 1867UNUSED (x ); 1868UNUSED (y ); 1869UNUSED (nb ); 1870ggml_vec_dot_iq3_xxs_q8_K_generic (n ,s ,bs ,vx ,bx ,vy ,by ,nrc ); 1871#endif 1872} 1873 1874void ggml_vec_dot_iq3_s_q8_K (int n ,float * GGML_RESTRICT s ,size_t bs ,const void * GGML_RESTRICT vx ,size_t bx ,const void * GGML_RESTRICT vy ,size_t by ,int nrc ) { 1875assert (n %QK_K == 0 ); 1876assert (nrc == 1 ); 1877UNUSED (nrc ); 1878UNUSED (bx ); 1879UNUSED (by ); 1880UNUSED (bs ); 1881 1882const block_iq3_s * GGML_RESTRICT x = vx ; 1883const block_q8_K * GGML_RESTRICT y = vy ; 1884 1885const int nb = n /QK_K ; 1886 1887#if defined(__POWER9_VECTOR__ ) 1888static const uint8_t k_mask1 [32 ]= {0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x01 ,0x01 ,0x01 ,0x01 ,0x01 ,0x01 ,0x01 ,0x01 , 18890x02 ,0x02 ,0x02 ,0x02 ,0x02 ,0x02 ,0x02 ,0x02 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 1890 }; 1891 1892static const uint8_t k_mask2 [16 ]= {0x01 ,0x02 ,0x04 ,0x08 ,0x10 ,0x20 ,0x40 ,0x80 ,0x01 ,0x02 ,0x04 ,0x08 ,0x10 ,0x20 ,0x40 ,0x80 ,}; 1893 1894const vector int v0 = vec_splats ((int32_t )0 ); 1895 1896vector float vsumf0 = vec_splats (0.0f ); 1897vector float vsumf1 = vec_splats (0.0f ); 1898vector float vsumf2 = vec_splats (0.0f ); 1899vector float vsumf3 = vec_splats (0.0f ); 1900 1901const vector unsigned char mask0 = vec_xl (0 ,k_mask1 ); 1902const vector unsigned char mask1 = vec_xl (16 ,k_mask1 ); 1903const vector signed char mask2 = (vector signed char )vec_xl (0 ,k_mask2 ); 1904 1905for (int i = 0 ;i < nb ;++ i ) { 1906vector float vxd = vec_splats (GGML_CPU_FP16_TO_FP32 (x [i ].d )); 1907vector float vyd = vec_splats (y [i ].d ); 1908vector float vd = vec_mul (vxd ,vyd ); 1909 1910const uint8_t * GGML_RESTRICT q3 = x [i ].qs ; 1911const uint8_t * GGML_RESTRICT qh = x [i ].qh ; 1912const uint16_t * GGML_RESTRICT signs = (const uint16_t * )(x [i ].signs ); 1913const uint8_t * GGML_RESTRICT sc = x [i ].scales ; 1914const int8_t * GGML_RESTRICT q8 = y [i ].qs ; 1915 1916vector signed int vsumi0 = v0 ; 1917vector signed int vsumi1 = v0 ; 1918vector signed int vsumi2 = v0 ; 1919vector signed int vsumi3 = v0 ; 1920 1921for (int j = 0 ;j < QK_K /32 ;j += 2 ) { 1922__builtin_prefetch (q3 ,0 ,1 ); 1923__builtin_prefetch (q8 ,0 ,1 ); 1924 1925vector unsigned int aux32x4_0 = {iq3s_grid [q3 [0 ] | ((qh [0 ] <<8 )& 256 )],iq3s_grid [q3 [1 ] | ((qh [0 ] <<7 )& 256 )], 1926iq3s_grid [q3 [2 ] | ((qh [0 ] <<6 )& 256 )],iq3s_grid [q3 [3 ] | ((qh [0 ] <<5 )& 256 )]}; 1927vector unsigned int aux32x4_1 = {iq3s_grid [q3 [4 ] | ((qh [0 ] <<4 )& 256 )],iq3s_grid [q3 [5 ] | ((qh [0 ] <<3 )& 256 )], 1928iq3s_grid [q3 [6 ] | ((qh [0 ] <<2 )& 256 )],iq3s_grid [q3 [7 ] | ((qh [0 ] <<1 )& 256 )]}; 1929vector unsigned int aux32x4_2 = {iq3s_grid [q3 [8 ] | ((qh [1 ] <<8 )& 256 )],iq3s_grid [q3 [9 ] | ((qh [1 ] <<7 )& 256 )], 1930iq3s_grid [q3 [10 ] | ((qh [1 ] <<6 )& 256 )],iq3s_grid [q3 [11 ] | ((qh [1 ] <<5 )& 256 )]}; 1931vector unsigned int aux32x4_3 = {iq3s_grid [q3 [12 ] | ((qh [1 ] <<4 )& 256 )],iq3s_grid [q3 [13 ] | ((qh [1 ] <<3 )& 256 )], 1932iq3s_grid [q3 [14 ] | ((qh [1 ] <<2 )& 256 )],iq3s_grid [q3 [15 ] | ((qh [1 ] <<1 )& 256 )]}; 1933q3 += 16 ; 1934qh += 2 ; 1935 1936vector signed char vsigns01 = (vector signed char )vec_splats (* (const uint32_t * )& signs [0 ]); 1937vector signed char vsigns02 = (vector signed char )vec_splats (* (const uint32_t * )& signs [2 ]); 1938signs += 4 ; 1939 1940vector signed char vsigns0 = vec_perm (vsigns01 ,vsigns01 ,mask0 ); 1941vector signed char vsigns1 = vec_perm (vsigns01 ,vsigns01 ,mask1 ); 1942vector signed char vsigns2 = vec_perm (vsigns02 ,vsigns02 ,mask0 ); 1943vector signed char vsigns3 = vec_perm (vsigns02 ,vsigns02 ,mask1 ); 1944 1945vsigns0 = (vector signed char )vec_cmpeq (vec_and (vsigns0 ,mask2 ),mask2 ); 1946vsigns1 = (vector signed char )vec_cmpeq (vec_and (vsigns1 ,mask2 ),mask2 ); 1947vsigns2 = (vector signed char )vec_cmpeq (vec_and (vsigns2 ,mask2 ),mask2 ); 1948vsigns3 = (vector signed char )vec_cmpeq (vec_and (vsigns3 ,mask2 ),mask2 ); 1949 1950vector signed char q3x0 = vec_sub (vec_xor (vsigns0 , (vector signed char )aux32x4_0 ),vsigns0 ); 1951vector signed char q3x1 = vec_sub (vec_xor (vsigns1 , (vector signed char )aux32x4_1 ),vsigns1 ); 1952vector signed char q3x2 = vec_sub (vec_xor (vsigns2 , (vector signed char )aux32x4_2 ),vsigns2 ); 1953vector signed char q3x3 = vec_sub (vec_xor (vsigns3 , (vector signed char )aux32x4_3 ),vsigns3 ); 1954 1955vector signed char q8y0 = vec_xl (0 ,q8 ); 1956vector signed char q8y1 = vec_xl (16 ,q8 ); 1957vector signed char q8y2 = vec_xl (32 ,q8 ); 1958vector signed char q8y3 = vec_xl (48 ,q8 ); 1959q8 += 64 ; 1960 1961vector signed short qv0 = vec_add (vec_mule (q3x0 ,q8y0 ),vec_mulo (q3x0 ,q8y0 )); 1962vector signed short qv1 = vec_add (vec_mule (q3x1 ,q8y1 ),vec_mulo (q3x1 ,q8y1 )); 1963vector signed short qv2 = vec_add (vec_mule (q3x2 ,q8y2 ),vec_mulo (q3x2 ,q8y2 )); 1964vector signed short qv3 = vec_add (vec_mule (q3x3 ,q8y3 ),vec_mulo (q3x3 ,q8y3 )); 1965 1966const uint16_t ls0 = (uint16_t )(sc [0 ]& 0xf ); 1967const uint16_t ls1 = (uint16_t )(sc [0 ] >>4 ); 1968sc ++ ; 1969 1970vector signed short vscales01 = (vector signed short )vec_splats ((uint16_t )(2 * ls0 + 1 )); 1971vector signed short vscales23 = (vector signed short )vec_splats ((uint16_t )(2 * ls1 + 1 )); 1972 1973vsumi0 = vec_msum (qv0 ,vscales01 ,vsumi0 ); 1974vsumi1 = vec_msum (qv1 ,vscales01 ,vsumi1 ); 1975vsumi2 = vec_msum (qv2 ,vscales23 ,vsumi2 ); 1976vsumi3 = vec_msum (qv3 ,vscales23 ,vsumi3 ); 1977 } 1978 1979vsumf0 = vec_madd (vec_ctf (vsumi0 ,0 ),vd ,vsumf0 ); 1980vsumf1 = vec_madd (vec_ctf (vsumi1 ,0 ),vd ,vsumf1 ); 1981vsumf2 = vec_madd (vec_ctf (vsumi2 ,0 ),vd ,vsumf2 ); 1982vsumf3 = vec_madd (vec_ctf (vsumi3 ,0 ),vd ,vsumf3 ); 1983 } 1984 1985vsumf0 = vec_add (vsumf0 ,vsumf2 ); 1986vsumf1 = vec_add (vsumf1 ,vsumf3 ); 1987 1988vsumf0 = vec_add (vsumf0 ,vsumf1 ); 1989 1990vsumf0 = vec_add (vsumf0 ,vec_sld (vsumf0 ,vsumf0 ,4 )); 1991vsumf0 = vec_add (vsumf0 ,vec_sld (vsumf0 ,vsumf0 ,8 )); 1992 1993* s = vec_extract (vsumf0 ,0 ); 1994 1995#else 1996UNUSED (x ); 1997UNUSED (y ); 1998UNUSED (nb ); 1999ggml_vec_dot_iq3_s_q8_K_generic (n ,s ,bs ,vx ,bx ,vy ,by ,nrc ); 2000#endif 2001} 2002 2003void ggml_vec_dot_iq1_s_q8_K (int n ,float * GGML_RESTRICT s ,size_t bs ,const void * GGML_RESTRICT vx ,size_t bx ,const void * GGML_RESTRICT vy ,size_t by ,int nrc ) { 2004assert (n %QK_K == 0 ); 2005assert (nrc == 1 ); 2006UNUSED (nrc ); 2007UNUSED (bx ); 2008UNUSED (by ); 2009UNUSED (bs ); 2010 2011const block_iq1_s * GGML_RESTRICT x = vx ; 2012const block_q8_K * GGML_RESTRICT y = vy ; 2013 2014const int nb = n /QK_K ; 2015 2016#if defined(__POWER9_VECTOR__ ) 2017const vector unsigned char v0 = vec_splats ((unsigned char )0x0 ); 2018const vector unsigned short vsign = vec_splats ((unsigned short )0x8000 ); 2019 2020vector float vsumf0 = vec_splats (0.0f ); 2021vector float vsumf1 = vec_splats (0.0f ); 2022vector float vsumf2 = vec_splats (0.0f ); 2023vector float vsumf3 = vec_splats (0.0f ); 2024 2025for (int i = 0 ;i < nb ;++ i ) { 2026vector float vxd = vec_splats (GGML_CPU_FP16_TO_FP32 (x [i ].d )); 2027vector float vyd = vec_splats (y [i ].d ); 2028vector float vd = vec_mul (vxd ,vyd ); 2029 2030vector signed int vsumi0 = vec_splats ((int32_t )0 ); 2031vector signed int vsumi1 = vec_splats ((int32_t )0 ); 2032vector signed int vsumi2 = vec_splats ((int32_t )0 ); 2033vector signed int vsumi3 = vec_splats ((int32_t )0 ); 2034vector signed int vsumi8 = vec_splats ((int32_t )0 ); 2035 2036const uint8_t * GGML_RESTRICT q1 = x [i ].qs ; 2037const uint16_t * GGML_RESTRICT qh = x [i ].qh ; 2038const int8_t * GGML_RESTRICT q8 = y [i ].qs ; 2039const int16_t * GGML_RESTRICT qs = y [i ].bsums ; 2040 2041for (int j = 0 ;j < QK_K /32 ;j += 2 ) { 2042__builtin_prefetch (q1 ,0 ,1 ); 2043__builtin_prefetch (qh ,0 ,1 ); 2044__builtin_prefetch (q8 ,0 ,1 ); 2045 2046vector signed long long aux64x2_0 = {* (const int64_t * )(iq1s_grid + (q1 [0 ] | ((qh [0 ] <<8 )& 0x700 ))),* (const int64_t * )(iq1s_grid + (q1 [1 ] | ((qh [0 ] <<5 )& 0x700 )))}; 2047vector signed long long aux64x2_1 = {* (const int64_t * )(iq1s_grid + (q1 [2 ] | ((qh [0 ] <<2 )& 0x700 ))),* (const int64_t * )(iq1s_grid + (q1 [3 ] | ((qh [0 ] >>1 )& 0x700 )))}; 2048vector signed long long aux64x2_2 = {* (const int64_t * )(iq1s_grid + (q1 [4 ] | ((qh [1 ] <<8 )& 0x700 ))),* (const int64_t * )(iq1s_grid + (q1 [5 ] | ((qh [1 ] <<5 )& 0x700 )))}; 2049vector signed long long aux64x2_3 = {* (const int64_t * )(iq1s_grid + (q1 [6 ] | ((qh [1 ] <<2 )& 0x700 ))),* (const int64_t * )(iq1s_grid + (q1 [7 ] | ((qh [1 ] >>1 )& 0x700 )))}; 2050q1 += 8 ; 2051 2052vector signed char q1x0 = (vector signed char )aux64x2_0 ; 2053vector signed char q1x1 = (vector signed char )aux64x2_1 ; 2054vector signed char q1x2 = (vector signed char )aux64x2_2 ; 2055vector signed char q1x3 = (vector signed char )aux64x2_3 ; 2056 2057vector signed char q8y0 = vec_xl (0 ,q8 ); 2058vector signed char q8y1 = vec_xl (16 ,q8 ); 2059vector signed char q8y2 = vec_xl (32 ,q8 ); 2060vector signed char q8y3 = vec_xl (48 ,q8 ); 2061q8 += 64 ; 2062 2063vector signed short qv0 = vec_add (vec_mule (q1x0 ,q8y0 ),vec_mulo (q1x0 ,q8y0 )); 2064vector signed short qv1 = vec_add (vec_mule (q1x1 ,q8y1 ),vec_mulo (q1x1 ,q8y1 )); 2065vector signed short qv2 = vec_add (vec_mule (q1x2 ,q8y2 ),vec_mulo (q1x2 ,q8y2 )); 2066vector signed short qv3 = vec_add (vec_mule (q1x3 ,q8y3 ),vec_mulo (q1x3 ,q8y3 )); 2067 2068const uint16_t ls0 = (uint16_t )((qh [0 ] >>12 )& 7 ); 2069const uint16_t ls1 = (uint16_t )((qh [1 ] >>12 )& 7 ); 2070 2071vector signed short vscales01 = (vector signed short )vec_splats ((uint16_t )(2 * ls0 + 1 )); 2072vector signed short vscales23 = (vector signed short )vec_splats ((uint16_t )(2 * ls1 + 1 )); 2073vector signed short vscales = vec_sld (vscales23 ,vscales01 ,8 ); 2074 2075vsumi0 = vec_msum (qv0 ,vscales01 ,vsumi0 ); 2076vsumi1 = vec_msum (qv1 ,vscales01 ,vsumi1 ); 2077vsumi2 = vec_msum (qv2 ,vscales23 ,vsumi2 ); 2078vsumi3 = vec_msum (qv3 ,vscales23 ,vsumi3 ); 2079 2080vector signed short q8ysums = vec_xl_len (qs ,8 ); 2081qs += 4 ; 2082q8ysums = vec_mergeh (q8ysums , (vector signed short )v0 ); 2083 2084vector signed short qxh = (vector signed short )vec_sld (vec_splats (qh [1 ]),vec_splats (qh [0 ]),8 ); 2085qh += 2 ; 2086vector __bool short vsel = vec_cmpge (qxh , (vector signed short )v0 ); 2087 2088vector signed short q8ysum = vec_sel ((vector signed short )vec_xor ((vector unsigned short )q8ysums ,vsign ),q8ysums ,vsel ); 2089 2090vsumi8 = vec_add (vec_mule (q8ysum ,vscales ),vsumi8 ); 2091 } 2092 2093vsumf0 = vec_madd (vec_ctf (vsumi0 ,0 ),vd ,vsumf0 ); 2094vsumf1 = vec_madd (vec_ctf (vsumi1 ,0 ),vd ,vsumf1 ); 2095vsumf2 = vec_madd (vec_ctf (vsumi2 ,0 ),vd ,vsumf2 ); 2096vsumf3 = vec_madd (vec_ctf (vsumi3 ,0 ),vd ,vsumf3 ); 2097 2098vsumf0 = vec_madd (vec_ctf (vsumi8 ,0 ),vec_mul (vd ,vec_splats (IQ1S_DELTA )),vsumf0 ); 2099 } 2100 2101vsumf0 = vec_add (vsumf0 ,vsumf2 ); 2102vsumf1 = vec_add (vsumf1 ,vsumf3 ); 2103 2104vsumf0 = vec_add (vsumf0 ,vsumf1 ); 2105 2106vsumf0 = vec_add (vsumf0 ,vec_sld (vsumf0 ,vsumf0 ,4 )); 2107vsumf0 = vec_add (vsumf0 ,vec_sld (vsumf0 ,vsumf0 ,8 )); 2108 2109* s = vec_extract (vsumf0 ,0 ); 2110 2111#else 2112UNUSED (x ); 2113UNUSED (y ); 2114UNUSED (nb ); 2115ggml_vec_dot_iq1_s_q8_K_generic (n ,s ,bs ,vx ,bx ,vy ,by ,nrc ); 2116#endif 2117} 2118 2119void ggml_vec_dot_iq4_nl_q8_0 (int n ,float * GGML_RESTRICT s ,size_t bs ,const void * GGML_RESTRICT vx ,size_t bx ,const void * GGML_RESTRICT vy ,size_t by ,int nrc ) { 2120assert (nrc == 1 ); 2121UNUSED (nrc ); 2122UNUSED (bx ); 2123UNUSED (by ); 2124UNUSED (bs ); 2125assert (n %QK4_NL == 0 ); 2126static_assert (QK4_NL == QK8_0 ,"QK4_NL and QK8_0 must be the same" ); 2127 2128const block_iq4_nl * GGML_RESTRICT x = vx ; 2129const block_q8_0 * GGML_RESTRICT y = vy ; 2130 2131const int nb = n /QK4_NL ; 2132 2133int ib = 0 ; 2134float sumf = 0 ; 2135 2136#if defined(__POWER9_VECTOR__ ) 2137const vector signed char lowMask = vec_splats ((signed char )0xF ); 2138const vector signed int v0 = vec_splats ((int32_t )0 ); 2139const vector unsigned char v4 = vec_splats ((unsigned char )0x4 ); 2140 2141vector float vsumf0 = vec_splats (0.0f ); 2142vector float vsumf1 = vec_splats (0.0f ); 2143 2144const vector signed char values = vec_xl (0 ,kvalues_iq4nl ); 2145 2146#pragma GCC unroll 4 2147for (;ib < nb ;++ ib ) { 2148__builtin_prefetch (x [ib ].qs ,0 ,1 ); 2149__builtin_prefetch (y [ib ].qs ,0 ,1 ); 2150 2151 2152vector float vxd = vec_splats (GGML_CPU_FP16_TO_FP32 (x [ib ].d )); 2153vector float vyd = vec_splats (GGML_CPU_FP16_TO_FP32 (y [ib ].d )); 2154vector float vd = vec_mul (vxd ,vyd ); 2155 2156vector signed char qxs = (vector signed char )vec_xl (0 ,x [ib ].qs ); 2157vector signed char q4x0 = vec_and (qxs ,lowMask ); 2158vector signed char q4x1 = vec_sr (qxs ,v4 ); 2159 2160q4x0 = vec_perm (values ,values , (vector unsigned char )q4x0 ); 2161q4x1 = vec_perm (values ,values , (vector unsigned char )q4x1 ); 2162 2163vector signed char q8y0 = vec_xl (0 ,y [ib ].qs ); 2164vector signed char q8y1 = vec_xl (16 ,y [ib ].qs ); 2165 2166vector signed short qv0 = vec_add (vec_mule (q4x0 ,q8y0 ),vec_mulo (q4x0 ,q8y0 )); 2167vector signed short qv1 = vec_add (vec_mule (q4x1 ,q8y1 ),vec_mulo (q4x1 ,q8y1 )); 2168 2169vector signed int vsumi0 = v0 ; 2170vector signed int vsumi1 = v0 ; 2171 2172vsumi0 = vec_sum4s (qv0 ,vsumi0 ); 2173vsumi1 = vec_sum4s (qv1 ,vsumi1 ); 2174 2175vsumf0 = vec_madd (vec_ctf (vsumi0 ,0 ),vd ,vsumf0 ); 2176vsumf1 = vec_madd (vec_ctf (vsumi1 ,0 ),vd ,vsumf1 ); 2177 } 2178 2179vsumf0 = vec_add (vsumf0 ,vsumf1 ); 2180 2181vsumf0 = vec_add (vsumf0 ,vec_sld (vsumf0 ,vsumf0 ,4 )); 2182vsumf0 = vec_add (vsumf0 ,vec_sld (vsumf0 ,vsumf0 ,8 )); 2183 2184sumf = vec_extract (vsumf0 ,0 ); 2185 2186* s = sumf ; 2187#else 2188UNUSED (x ); 2189UNUSED (y ); 2190UNUSED (nb ); 2191UNUSED (ib ); 2192UNUSED (sumf ); 2193ggml_vec_dot_iq4_nl_q8_0_generic (n ,s ,bs ,vx ,bx ,vy ,by ,nrc ); 2194#endif 2195} 2196 2197void ggml_vec_dot_iq4_xs_q8_K (int n ,float * GGML_RESTRICT s ,size_t bs ,const void * GGML_RESTRICT vx ,size_t bx ,const void * GGML_RESTRICT vy ,size_t by ,int nrc ) { 2198assert (nrc == 1 ); 2199UNUSED (nrc ); 2200UNUSED (bx ); 2201UNUSED (by ); 2202UNUSED (bs ); 2203assert (n %QK_K == 0 ); 2204 2205const block_iq4_xs * GGML_RESTRICT x = vx ; 2206const block_q8_K * GGML_RESTRICT y = vy ; 2207 2208const int nb = n /QK_K ; 2209 2210#if defined(__POWER9_VECTOR__ ) 2211const vector signed char lowMask = vec_splats ((signed char )0xF ); 2212const vector int v0 = vec_splats ((int32_t )0 ); 2213const vector unsigned char v4 = vec_splats ((unsigned char )0x4 ); 2214 2215vector float vsumf0 = vec_splats (0.0f ); 2216vector float vsumf1 = vec_splats (0.0f ); 2217vector float vsumf2 = vec_splats (0.0f ); 2218vector float vsumf3 = vec_splats (0.0f ); 2219 2220const vector signed char values = vec_xl (0 ,kvalues_iq4nl ); 2221 2222for (int ibl = 0 ;ibl < nb ;++ ibl ) { 2223 2224vector float vxd = vec_splats (GGML_CPU_FP16_TO_FP32 (x [ibl ].d )); 2225vector float vyd = vec_splats (y [ibl ].d ); 2226vector float vd = vec_mul (vxd ,vyd ); 2227 2228vector signed int vsumi0 = v0 ; 2229vector signed int vsumi1 = v0 ; 2230vector signed int vsumi2 = v0 ; 2231vector signed int vsumi3 = v0 ; 2232 2233uint16_t h = x [ibl ].scales_h ; 2234 2235const uint8_t * GGML_RESTRICT q4 = x [ibl ].qs ; 2236const uint8_t * GGML_RESTRICT sc = x [ibl ].scales_l ; 2237const int8_t * GGML_RESTRICT q8 = y [ibl ].qs ; 2238 2239for (int ib = 0 ;ib < QK_K /64 ;ib ++ ) { 2240__builtin_prefetch (q4 ,0 ,1 ); 2241__builtin_prefetch (q8 ,0 ,1 ); 2242 2243vector signed char qxs0 = (vector signed char )vec_xl (0 ,q4 ); 2244vector signed char qxs1 = (vector signed char )vec_xl (16 ,q4 ); 2245q4 += 32 ; 2246 2247vector signed char q4x00 = (vector signed char )vec_and (qxs0 ,lowMask ); 2248vector signed char q4x01 = (vector signed char )vec_sr (qxs0 ,v4 ); 2249vector signed char q4x10 = (vector signed char )vec_and (qxs1 ,lowMask ); 2250vector signed char q4x11 = (vector signed char )vec_sr (qxs1 ,v4 ); 2251 2252q4x00 = vec_perm (values ,values , (vector unsigned char )q4x00 ); 2253q4x01 = vec_perm (values ,values , (vector unsigned char )q4x01 ); 2254q4x10 = vec_perm (values ,values , (vector unsigned char )q4x10 ); 2255q4x11 = vec_perm (values ,values , (vector unsigned char )q4x11 ); 2256 2257vector signed char q8y0 = vec_xl (0 ,q8 ); 2258vector signed char q8y1 = vec_xl (16 ,q8 ); 2259vector signed char q8y2 = vec_xl (32 ,q8 ); 2260vector signed char q8y3 = vec_xl (48 ,q8 ); 2261q8 += 64 ; 2262 2263vector signed short qv0 = vec_add (vec_mule (q4x00 ,q8y0 ),vec_mulo (q4x00 ,q8y0 )); 2264vector signed short qv1 = vec_add (vec_mule (q4x01 ,q8y1 ),vec_mulo (q4x01 ,q8y1 )); 2265vector signed short qv2 = vec_add (vec_mule (q4x10 ,q8y2 ),vec_mulo (q4x10 ,q8y2 )); 2266vector signed short qv3 = vec_add (vec_mule (q4x11 ,q8y3 ),vec_mulo (q4x11 ,q8y3 )); 2267 2268const uint16_t ls0 = (uint16_t )(((sc [0 ]& 0xf ) | ((h <<4 )& 0x30 ))- 32 ); 2269const uint16_t ls1 = (uint16_t )(((sc [0 ] >>4 ) | ((h <<2 )& 0x30 ))- 32 ); 2270h >>=4 ; 2271sc ++ ; 2272 2273vector signed short vscales01 = vec_splats ((int16_t )ls0 ); 2274vector signed short vscales23 = vec_splats ((int16_t )ls1 ); 2275 2276vsumi0 = vec_msum (qv0 ,vscales01 ,vsumi0 ); 2277vsumi1 = vec_msum (qv1 ,vscales01 ,vsumi1 ); 2278vsumi2 = vec_msum (qv2 ,vscales23 ,vsumi2 ); 2279vsumi3 = vec_msum (qv3 ,vscales23 ,vsumi3 ); 2280 } 2281 2282vsumf0 = vec_madd (vec_ctf (vsumi0 ,0 ),vd ,vsumf0 ); 2283vsumf1 = vec_madd (vec_ctf (vsumi1 ,0 ),vd ,vsumf1 ); 2284vsumf2 = vec_madd (vec_ctf (vsumi2 ,0 ),vd ,vsumf2 ); 2285vsumf3 = vec_madd (vec_ctf (vsumi3 ,0 ),vd ,vsumf3 ); 2286 } 2287 2288vsumf0 = vec_add (vsumf0 ,vsumf2 ); 2289vsumf1 = vec_add (vsumf1 ,vsumf3 ); 2290 2291vsumf0 = vec_add (vsumf0 ,vsumf1 ); 2292 2293vsumf0 = vec_add (vsumf0 ,vec_sld (vsumf0 ,vsumf0 ,4 )); 2294vsumf0 = vec_add (vsumf0 ,vec_sld (vsumf0 ,vsumf0 ,8 )); 2295 2296* s = vec_extract (vsumf0 ,0 ); 2297 2298#else 2299UNUSED (x ); 2300UNUSED (y ); 2301UNUSED (nb ); 2302ggml_vec_dot_iq4_xs_q8_K_generic (n ,s ,bs ,vx ,bx ,vy ,by ,nrc ); 2303#endif 2304}