Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/ggml/blob/master/src/ggml-opencl/kernels/gemv_noshuffle_q2_0_f32.cl # ggml [Ported from github.com/ggml-org/ggml] docs : sync ggml_type enum in gguf.md (#1685) Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `ggml / src / ggml-opencl / kernels / gemv_noshuffle_q2_0_f32.cl` 77 lines ยท 2614 bytes Raw Blame History 1 #pragma OPENCL EXTENSION cl_khr_fp16 : enable 2 3 #if Q2_0_MV_WIDE 4 #define Q2_0_MV_ROWS 8 5 #define Q2_0_MV_LOAD_D vload8 6 #define Q2_0_MV_STORE vstore8 7 #define Q2_0_MV_FLOAT convert_float8 8 typedef float8 q2_0_mv_acc_t; 9 typedef uchar8 q2_0_mv_quant_t; 10 #else 11 #define Q2_0_MV_ROWS 4 12 #define Q2_0_MV_LOAD_D vload4 13 #define Q2_0_MV_STORE vstore4 14 #define Q2_0_MV_FLOAT convert_float4 15 typedef float4 q2_0_mv_acc_t; 16 typedef uchar4 q2_0_mv_quant_t; 17 #endif 18 19 kernel void kernel_gemv_noshuffle_q2_0_f32( 20 global const uchar * src0_qs, 21 global const half * src0_d, 22 global const float * src1, 23 ulong offset1, 24 global float * dst, 25 ulong offsetd, 26 int ne00, 27 int ne01, 28 int ne10, 29 int ne0 30 ) { 31 src1 = (global const float *)((global const char *)src1 + offset1); 32 dst = (global float *)((global char *)dst + offsetd); 33 34 const uint mr = (uint)ne01/Q2_0_MV_ROWS; 35 const uint lid = get_local_id(0); 36 const uint sgi = get_local_id(1); 37 const uint lanes = get_local_size(0); 38 const uint nsg = get_local_size(1); 39 const uint col = get_group_id(1); 40 const uint j = get_group_id(0)*lanes + lid; 41 global const float * y = src1 + (ulong)col * (uint)ne10; 42 43 q2_0_mv_acc_t sum = 0.0f; 44 if (j < mr) { 45 for (uint ib = sgi; ib < (uint)ne00/64; ib += nsg) { 46 const q2_0_mv_acc_t d = Q2_0_MV_FLOAT(Q2_0_MV_LOAD_D(j + ib*mr, src0_d)); 47 q2_0_mv_acc_t acc = 0.0f; 48 for (uint u = 0; u < 16; ++u) { 49 const uint group = ib*16 + u; 50 #if Q2_0_MV_WIDE 51 const uchar8 q = as_uchar8(((global const uint2 *)src0_qs)[j + group*mr]); 52 #else 53 const uchar4 q = as_uchar4(((global const uint *)src0_qs)[j + group*mr]); 54 #endif 55 const float4 yv = vload4(group, y); 56 acc += (Q2_0_MV_FLOAT( q & (q2_0_mv_quant_t)(3)) - 1.0f)*yv.s0; 57 acc += (Q2_0_MV_FLOAT((q >> (q2_0_mv_quant_t)(2)) & (q2_0_mv_quant_t)(3)) - 1.0f)*yv.s1; 58 acc += (Q2_0_MV_FLOAT((q >> (q2_0_mv_quant_t)(4)) & (q2_0_mv_quant_t)(3)) - 1.0f)*yv.s2; 59 acc += (Q2_0_MV_FLOAT( q >> (q2_0_mv_quant_t)(6)) - 1.0f)*yv.s3; 60 } 61 sum += d*acc; 62 } 63 } 64 65 local q2_0_mv_acc_t part[512]; 66 part[sgi*lanes + lid] = sum; 67 barrier(CLK_LOCAL_MEM_FENCE); 68 if (sgi != 0) { 69 return; 70 } 71 for (uint s = 1; s < nsg; ++s) { 72 sum += part[s*lanes + lid]; 73 } 74 if (j < mr) { 75 Q2_0_MV_STORE(sum, 0, dst + (ulong)col*(uint)ne0 + j*Q2_0_MV_ROWS); 76 } 77 }