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_q1_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 / gemm_noshuffle_q1_0_f32.cl` 94 lines ยท 3023 bytes Raw Blame History 1 #pragma OPENCL EXTENSION cl_khr_fp16 : enable 2 #pragma OPENCL EXTENSION cl_qcom_reqd_sub_group_size : enable 3 4 #ifdef cl_qcom_reqd_sub_group_size 5 #pragma OPENCL EXTENSION cl_qcom_reqd_sub_group_size : enable 6 #define ADRENO_GPU 1 7 #define REQD_SUBGROUP_SIZE_128 __attribute__((qcom_reqd_sub_group_size("full"))) 8 #endif 9 10 // each work-item computes a 4 (rows of A / m) x 8 (cols of B / n) output tile. 11 #ifdef ADRENO_GPU 12 REQD_SUBGROUP_SIZE_128 13 #endif 14 kernel void kernel_gemm_noshuffle_q1_0_f32( 15 global const uint * src0_q, 16 global const half * src0_d, 17 read_only image1d_buffer_t src1, 18 global float * dst, 19 int k, 20 int m, 21 int n, 22 int n_no_padding, 23 ulong offsetd 24 ) { 25 int n_4 = n >> 2; 26 27 int gy = get_global_id(0); 28 int gx = get_global_id(1); 29 int gx_2 = gx << 2; 30 dst = (global float *)((global char*)dst + offsetd); 31 32 half8 c0 = 0, c1 = 0, c2 = 0, c3 = 0; 33 half8 B; 34 35 global const uint* wptr = src0_q + gx_2; 36 global const half* sptr = src0_d + gx_2; 37 38 // 32 weights per uint32, 128 weights (one block / one scale) per 4 uint32. 39 for (int i = 0; i < k; i += 32) { 40 uint4 pack4 = vload4(0, wptr + (i / 32) * m); // 4 rows, 32 K-values each 41 half4 scale = vload4(0, sptr + (i / 128) * m); // 4 rows, one scale per 128 42 43 for (int j = 0; j < 32; ++j) { 44 B.s0123 = read_imageh(src1, gy * 2 + (i + j) * n_4); 45 B.s4567 = read_imageh(src1, gy * 2 + (i + j) * n_4 + 1); 46 47 // sign bit -> +-1 (half arithmetic avoids unsigned underflow) 48 half4 wj = (half4)( 49 2.0h * (half)((pack4.s0 >> j) & 1u) - 1.0h, 50 2.0h * (half)((pack4.s1 >> j) & 1u) - 1.0h, 51 2.0h * (half)((pack4.s2 >> j) & 1u) - 1.0h, 52 2.0h * (half)((pack4.s3 >> j) & 1u) - 1.0h) * scale; 53 54 c0 += B * wj.s0; 55 c1 += B * wj.s1; 56 c2 += B * wj.s2; 57 c3 += B * wj.s3; 58 } 59 } 60 61 int idx = (gy << 3) * m + (gx << 2); 62 63 if(idx+3 < m*n_no_padding){ 64 vstore4((float4)(c0.s0, c1.s0, c2.s0, c3.s0), 0, dst + idx); 65 idx += m; 66 } 67 if(idx+3 < m*n_no_padding){ 68 vstore4((float4)(c0.s1, c1.s1, c2.s1, c3.s1), 0, dst + idx); 69 idx += m; 70 } 71 if(idx+3 < m*n_no_padding){ 72 vstore4((float4)(c0.s2, c1.s2, c2.s2, c3.s2), 0, dst + idx); 73 idx += m; 74 } 75 if(idx+3 < m*n_no_padding){ 76 vstore4((float4)(c0.s3, c1.s3, c2.s3, c3.s3), 0, dst + idx); 77 idx += m; 78 } 79 if(idx+3 < m*n_no_padding){ 80 vstore4((float4)(c0.s4, c1.s4, c2.s4, c3.s4), 0, dst + idx); 81 idx += m; 82 } 83 if(idx+3 < m*n_no_padding){ 84 vstore4((float4)(c0.s5, c1.s5, c2.s5, c3.s5), 0, dst + idx); 85 idx += m; 86 } 87 if(idx+3 < m*n_no_padding){ 88 vstore4((float4)(c0.s6, c1.s6, c2.s6, c3.s6), 0, dst + idx); 89 idx += m; 90 } 91 if(idx+3 < m*n_no_padding){ 92 vstore4((float4)(c0.s7, c1.s7, c2.s7, c3.s7), 0, dst + idx); 93 } 94 }