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_iq1_s_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_iq1_s_f32.cl` 117 lines ยท 3835 bytes Raw Blame History 1 #pragma OPENCL EXTENSION cl_khr_fp16 : enable 2 3 #define QK_K 256 4 5 #ifndef IQ1_S_MV_NSG 6 #define IQ1_S_MV_NSG 4 7 #endif 8 9 inline float4 iq1_s_vals(uint g) { 10 return (float4)((float)( g & 0xFu), (float)((g >> 8) & 0xFu), 11 (float)((g >> 16) & 0xFu), (float)((g >> 24) & 0xFu)); 12 } 13 14 kernel void kernel_gemv_noshuffle_iq1_s_f32( 15 __read_only image1d_buffer_t grid_img, 16 global const uchar * src0_qs, 17 global const ushort * src0_qh, 18 global const half * src0_d, 19 global const float * src1, 20 ulong offset1, 21 global float * dst, 22 ulong offsetd, 23 int ne00, 24 int ne01, 25 int ne10, 26 int ne0 27 ) { 28 src1 = (global const float *)((global const char *)src1 + offset1); 29 dst = (global float *)((global char *)dst + offsetd); 30 31 const uint m = (uint)ne01; 32 const uint K = (uint)ne00; 33 const uint nsb = K / QK_K; 34 35 const uint lid = get_local_id(0); 36 const uint sgi = get_local_id(1); 37 const uint col = get_group_id(1); 38 39 global const float * y = src1 + (ulong)col * (uint)ne10; 40 41 #define IQ1_S_GRID(i) (read_imageui(grid_img, (int)(i)).x) 42 43 const uint mh = m >> 1; 44 const uint j = get_group_id(0) * 64u + lid; 45 const uint row = j << 1; 46 47 float sumf = 0.f, sumf1 = 0.f; 48 49 if (j < mh) { 50 global const ushort * qsu = (global const ushort *)src0_qs; 51 52 for (uint ib = sgi; ib < nsb; ib += IQ1_S_MV_NSG) { 53 const half2 dh = vload2(j + ib * mh, src0_d); 54 55 float acc0 = 0.f, acc1 = 0.f; 56 for (uint sb = 0; sb < 8u; ++sb) { 57 const uint sub = ib * 8u + sb; 58 const ushort2 qhv = vload2(j + sub * mh, src0_qh); 59 const uint h0 = (uint)qhv.s0, h1 = (uint)qhv.s1; 60 61 const float s0 = (float)(2u * ((h0 >> 12) & 7u) + 1u); 62 const float s1 = (float)(2u * ((h1 >> 12) & 7u) + 1u); 63 const float t0 = ((h0 & 0x8000u) ? -0.125f : 0.125f) - 1.0f; 64 const float t1 = ((h1 & 0x8000u) ? -0.125f : 0.125f) - 1.0f; 65 66 const uint gb = j + (sub * 4u) * mh; 67 const uint grp = sub * 8u; 68 69 float a0 = 0.f, a1 = 0.f; 70 float4 as = (float4)(0.f); 71 for (uint l = 0; l < 4u; ++l) { 72 const uint qsv = (uint)qsu[gb + l * mh]; 73 const uint g0 = IQ1_S_GRID(( qsv & 0xFFu) | ((((h0 >> (3u*l)) & 7u) << 8))); 74 const uint g1 = IQ1_S_GRID(((qsv >> 8) & 0xFFu) | ((((h1 >> (3u*l)) & 7u) << 8))); 75 76 const float4 y0 = vload4(grp + 2u*l + 0u, y); 77 const float4 y1 = vload4(grp + 2u*l + 1u, y); 78 as += y0 + y1; 79 a0 += dot(y0, iq1_s_vals(g0)) + dot(y1, iq1_s_vals(g0 >> 4)); 80 a1 += dot(y0, iq1_s_vals(g1)) + dot(y1, iq1_s_vals(g1 >> 4)); 81 } 82 83 const float asum = as.s0 + as.s1 + as.s2 + as.s3; 84 acc0 += s0 * (a0 + t0 * asum); 85 acc1 += s1 * (a1 + t1 * asum); 86 } 87 sumf += (float)dh.s0 * acc0; 88 sumf1 += (float)dh.s1 * acc1; 89 } 90 } 91 92 #if IQ1_S_MV_NSG > 1 93 __local float2 part[IQ1_S_MV_NSG][64]; 94 part[sgi][lid] = (float2)(sumf, sumf1); 95 barrier(CLK_LOCAL_MEM_FENCE); 96 if (sgi != 0) { 97 return; 98 } 99 for (uint s = 1; s < IQ1_S_MV_NSG; ++s) { 100 const float2 p = part[s][lid]; 101 sumf += p.s0; 102 sumf1 += p.s1; 103 } 104 #endif 105 106 if (j < mh) { 107 vstore2((float2)(sumf, sumf1), 0, dst + (ulong)col * (uint)ne0 + row); 108 } 109 #undef IQ1_S_GRID 110 } 111 112 kernel void kernel_iq1_s_grid_export(global uint * out) { 113 const uint i = get_global_id(0); 114 if (i < 2048u) { 115 out[i] = iq1_s_grid[i]; 116 } 117 }