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_q5_1_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_q5_1_f32.cl` 134 lines ยท 5812 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 #ifdef ADRENO_GPU 11 REQD_SUBGROUP_SIZE_128 12 #endif 13 14 kernel void kernel_gemm_noshuffle_q5_1_f32( 15 global const ushort * src0_qs, // quantized A 16 global const uchar * src0_qh, // 5th bits 17 global const half * src0_d, // A scales 18 global const half * src0_m, // A mins 19 __read_only image1d_buffer_t src1, // B (1d image) 20 global float * dst, // C 21 int m, // M 22 int n, // N with padding 23 int k, // K 24 int n_no_padding // N without padding 25 ) { 26 27 int n_4 = n >> 2; 28 29 int gy = get_global_id(0); 30 int gx = get_global_id(1); 31 int gx_2 = gx << 2; 32 33 half8 c0 = 0, c1 = 0, c2 = 0, c3 = 0; 34 half8 B; 35 half4 dequantized_weights; 36 37 global const ushort * weight_ptr = src0_qs + gx_2; 38 global const uchar * qh_ptr = src0_qh + gx_2; 39 global const half * scale_ptr = src0_d + gx_2; 40 global const half * min_ptr = src0_m + gx_2; 41 42 for (int i = 0; i < k; i += 4) { 43 44 B.s0123 = read_imageh(src1, gy*2 + i*n_4); 45 B.s4567 = read_imageh(src1, gy*2 + i*n_4 + 1); 46 47 ushort4 bits4 = vload4(0, weight_ptr + (i >> 2)*m); 48 uchar4 bits1 = vload4(0, qh_ptr + (i >> 3)*m); 49 uchar4 qh = bits1 >> (uchar4)(i & 4); 50 51 half4 scale = vload4(0, scale_ptr + (i >> 5)*m); 52 half4 minv = vload4(0, min_ptr + (i >> 5)*m); 53 54 // j=0 55 dequantized_weights.s0 = convert_half((bits4.s0 & 0x000F) | ((qh.s0 & 0x01) << 4)) * scale.s0 + minv.s0; 56 dequantized_weights.s1 = convert_half((bits4.s1 & 0x000F) | ((qh.s1 & 0x01) << 4)) * scale.s1 + minv.s1; 57 dequantized_weights.s2 = convert_half((bits4.s2 & 0x000F) | ((qh.s2 & 0x01) << 4)) * scale.s2 + minv.s2; 58 dequantized_weights.s3 = convert_half((bits4.s3 & 0x000F) | ((qh.s3 & 0x01) << 4)) * scale.s3 + minv.s3; 59 c0 += B * dequantized_weights.s0; 60 c1 += B * dequantized_weights.s1; 61 c2 += B * dequantized_weights.s2; 62 c3 += B * dequantized_weights.s3; 63 64 // j=1 65 B.s0123 = read_imageh(src1, gy*2 + (i+1)*n_4); 66 B.s4567 = read_imageh(src1, gy*2 + (i+1)*n_4 + 1); 67 dequantized_weights.s0 = convert_half(((bits4.s0 & 0x00F0) >> 4) | ((qh.s0 & 0x02) << 3)) * scale.s0 + minv.s0; 68 dequantized_weights.s1 = convert_half(((bits4.s1 & 0x00F0) >> 4) | ((qh.s1 & 0x02) << 3)) * scale.s1 + minv.s1; 69 dequantized_weights.s2 = convert_half(((bits4.s2 & 0x00F0) >> 4) | ((qh.s2 & 0x02) << 3)) * scale.s2 + minv.s2; 70 dequantized_weights.s3 = convert_half(((bits4.s3 & 0x00F0) >> 4) | ((qh.s3 & 0x02) << 3)) * scale.s3 + minv.s3; 71 c0 += B * dequantized_weights.s0; 72 c1 += B * dequantized_weights.s1; 73 c2 += B * dequantized_weights.s2; 74 c3 += B * dequantized_weights.s3; 75 76 // j=2 77 B.s0123 = read_imageh(src1, gy*2 + (i+2)*n_4); 78 B.s4567 = read_imageh(src1, gy*2 + (i+2)*n_4 + 1); 79 dequantized_weights.s0 = convert_half(((bits4.s0 & 0x0F00) >> 8) | ((qh.s0 & 0x04) << 2)) * scale.s0 + minv.s0; 80 dequantized_weights.s1 = convert_half(((bits4.s1 & 0x0F00) >> 8) | ((qh.s1 & 0x04) << 2)) * scale.s1 + minv.s1; 81 dequantized_weights.s2 = convert_half(((bits4.s2 & 0x0F00) >> 8) | ((qh.s2 & 0x04) << 2)) * scale.s2 + minv.s2; 82 dequantized_weights.s3 = convert_half(((bits4.s3 & 0x0F00) >> 8) | ((qh.s3 & 0x04) << 2)) * scale.s3 + minv.s3; 83 c0 += B * dequantized_weights.s0; 84 c1 += B * dequantized_weights.s1; 85 c2 += B * dequantized_weights.s2; 86 c3 += B * dequantized_weights.s3; 87 88 // j=3 89 B.s0123 = read_imageh(src1, gy*2 + (i+3)*n_4); 90 B.s4567 = read_imageh(src1, gy*2 + (i+3)*n_4 + 1); 91 dequantized_weights.s0 = convert_half(((bits4.s0 & 0xF000) >> 12) | ((qh.s0 & 0x08) << 1)) * scale.s0 + minv.s0; 92 dequantized_weights.s1 = convert_half(((bits4.s1 & 0xF000) >> 12) | ((qh.s1 & 0x08) << 1)) * scale.s1 + minv.s1; 93 dequantized_weights.s2 = convert_half(((bits4.s2 & 0xF000) >> 12) | ((qh.s2 & 0x08) << 1)) * scale.s2 + minv.s2; 94 dequantized_weights.s3 = convert_half(((bits4.s3 & 0xF000) >> 12) | ((qh.s3 & 0x08) << 1)) * scale.s3 + minv.s3; 95 c0 += B * dequantized_weights.s0; 96 c1 += B * dequantized_weights.s1; 97 c2 += B * dequantized_weights.s2; 98 c3 += B * dequantized_weights.s3; 99 } 100 101 int idx = (gy<<3)*m + (gx<<2); 102 103 if(idx+3 < m*n_no_padding){ 104 vstore4((float4)(c0.s0, c1.s0, c2.s0, c3.s0), 0, dst + idx); 105 idx += m; 106 } 107 if(idx+3 < m*n_no_padding){ 108 vstore4((float4)(c0.s1, c1.s1, c2.s1, c3.s1), 0, dst + idx); 109 idx += m; 110 } 111 if(idx+3 < m*n_no_padding){ 112 vstore4((float4)(c0.s2, c1.s2, c2.s2, c3.s2), 0, dst + idx); 113 idx += m; 114 } 115 if(idx+3 < m*n_no_padding){ 116 vstore4((float4)(c0.s3, c1.s3, c2.s3, c3.s3), 0, dst + idx); 117 idx += m; 118 } 119 if(idx+3 < m*n_no_padding){ 120 vstore4((float4)(c0.s4, c1.s4, c2.s4, c3.s4), 0, dst + idx); 121 idx += m; 122 } 123 if(idx+3 < m*n_no_padding){ 124 vstore4((float4)(c0.s5, c1.s5, c2.s5, c3.s5), 0, dst + idx); 125 idx += m; 126 } 127 if(idx+3 < m*n_no_padding){ 128 vstore4((float4)(c0.s6, c1.s6, c2.s6, c3.s6), 0, dst + idx); 129 idx += m; 130 } 131 if(idx+3 < m*n_no_padding){ 132 vstore4((float4)(c0.s7, c1.s7, c2.s7, c3.s7), 0, dst + idx); 133 } 134 }