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/gemm_noshuffle_iq1_m_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 / gemm_noshuffle_iq1_m_f32.cl` 93 lines ยท 3801 bytes Raw Blame History 1 #pragma OPENCL EXTENSION cl_khr_fp16 : enable 2 3 #ifdef cl_qcom_reqd_sub_group_size 4 #pragma OPENCL EXTENSION cl_qcom_reqd_sub_group_size : enable 5 __attribute__((qcom_reqd_sub_group_size("full"))) 6 #endif 7 kernel void kernel_gemm_noshuffle_iq1_m_f32( 8 global const uchar * src0_qs, 9 global const uchar * src0_qh, 10 global const ushort * src0_sc, 11 read_only image1d_buffer_t src1, 12 global float * dst, 13 ulong offsetd, 14 int m, 15 int n, 16 int k, 17 int n_no_padding 18 ) { 19 dst = (global float *)((global char *)dst + offsetd); 20 const int gy = get_global_id(0); 21 const int row = get_global_id(1) * 4; 22 const int n_4 = n / 4; 23 if (row >= m) { 24 return; 25 } 26 27 half8 c0 = 0, c1 = 0, c2 = 0, c3 = 0; 28 for (int i = 0; i < k; i += 16) { 29 const uint4 w0 = convert_uint4(vload4(0, src0_sc + row + (4*(i / 256) + 0) * m)); 30 const uint4 w1 = convert_uint4(vload4(0, src0_sc + row + (4*(i / 256) + 1) * m)); 31 const uint4 w2 = convert_uint4(vload4(0, src0_sc + row + (4*(i / 256) + 2) * m)); 32 const uint4 w3 = convert_uint4(vload4(0, src0_sc + row + (4*(i / 256) + 3) * m)); 33 const ushort4 bits = convert_ushort4((w0 >> (uint4)(12)) | ((w1 >> (uint4)(8)) & (uint4)(0x00f0)) 34 | ((w2 >> (uint4)(4)) & (uint4)(0x0f00)) | (w3 & (uint4)(0xf000))); 35 const half4 d = as_half4(bits); 36 const uint4 sc = convert_uint4(vload4(0, src0_sc + row + (i / 64) * m)); 37 const half4 scale = d * convert_half4(2*((sc >> (uint4)(3*((i / 16) & 3))) & (uint4)(7)) + 1); 38 const uint4 qh = convert_uint4(vload4(0, src0_qh + row + (i / 16) * m)); 39 40 for (int l = 0; l < 16; l += 4) { 41 const int ki = i + l; 42 const uint4 gi = convert_uint4(vload4(0, src0_qs + row + (ki / 8) * m)) 43 | (((qh >> (uint4)(4*((ki / 8) & 1))) & (uint4)(7)) << (uint4)(8)); 44 const uint4 grid = (uint4)(iq1_s_grid[gi.s0], iq1_s_grid[gi.s1], iq1_s_grid[gi.s2], iq1_s_grid[gi.s3]); 45 const float4 delta = select((float4)(-0.875f), (float4)(-1.125f), (qh & (uint4)(0x08 << (4*((ki / 8) & 1)))) != 0); 46 #pragma unroll 47 for (int j = 0; j < 4; ++j) { 48 half8 b; 49 b.s0123 = read_imageh(src1, gy * 2 + (ki + j) * n_4); 50 b.s4567 = read_imageh(src1, gy * 2 + 1 + (ki + j) * n_4); 51 const float4 magnitude = convert_float4((grid >> (uint4)(8*j + (ki & 4))) & (uint4)(15)); 52 const half4 w = convert_half4(magnitude + delta) * scale; 53 c0 += b * w.s0; 54 c1 += b * w.s1; 55 c2 += b * w.s2; 56 c3 += b * w.s3; 57 } 58 } 59 } 60 61 int idx = gy * 8 * m + row; 62 if (idx + 3 < m * n_no_padding) { 63 vstore4((float4)(c0.s0, c1.s0, c2.s0, c3.s0), 0, dst + idx); 64 idx += m; 65 } 66 if (idx + 3 < m * n_no_padding) { 67 vstore4((float4)(c0.s1, c1.s1, c2.s1, c3.s1), 0, dst + idx); 68 idx += m; 69 } 70 if (idx + 3 < m * n_no_padding) { 71 vstore4((float4)(c0.s2, c1.s2, c2.s2, c3.s2), 0, dst + idx); 72 idx += m; 73 } 74 if (idx + 3 < m * n_no_padding) { 75 vstore4((float4)(c0.s3, c1.s3, c2.s3, c3.s3), 0, dst + idx); 76 idx += m; 77 } 78 if (idx + 3 < m * n_no_padding) { 79 vstore4((float4)(c0.s4, c1.s4, c2.s4, c3.s4), 0, dst + idx); 80 idx += m; 81 } 82 if (idx + 3 < m * n_no_padding) { 83 vstore4((float4)(c0.s5, c1.s5, c2.s5, c3.s5), 0, dst + idx); 84 idx += m; 85 } 86 if (idx + 3 < m * n_no_padding) { 87 vstore4((float4)(c0.s6, c1.s6, c2.s6, c3.s6), 0, dst + idx); 88 idx += m; 89 } 90 if (idx + 3 < m * n_no_padding) { 91 vstore4((float4)(c0.s7, c1.s7, c2.s7, c3.s7), 0, dst + idx); 92 } 93 }