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_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 / gemv_noshuffle_q1_0_f32.cl` 135 lines ยท 6678 bytes Raw Blame History 1 #pragma OPENCL EXTENSION cl_khr_fp16 : enable 2 #pragma OPENCL EXTENSION cl_khr_subgroups : 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_64 __attribute__((qcom_reqd_sub_group_size("half"))) 8 #endif 9 10 #define QK1_0 128 11 #ifndef N_SIMDGROUP 12 #define N_SIMDGROUP 4 13 #endif 14 15 #define dequantizeBlockAccum_q1(total, bits, scale, regB, lb) \ 16 total += (2.0f*(float)((bits >> 0) & 1u) - 1.0f) * scale * sub_group_broadcast(regB.s0, lb+0); \ 17 total += (2.0f*(float)((bits >> 1) & 1u) - 1.0f) * scale * sub_group_broadcast(regB.s1, lb+0); \ 18 total += (2.0f*(float)((bits >> 2) & 1u) - 1.0f) * scale * sub_group_broadcast(regB.s2, lb+0); \ 19 total += (2.0f*(float)((bits >> 3) & 1u) - 1.0f) * scale * sub_group_broadcast(regB.s3, lb+0); \ 20 total += (2.0f*(float)((bits >> 4) & 1u) - 1.0f) * scale * sub_group_broadcast(regB.s4, lb+0); \ 21 total += (2.0f*(float)((bits >> 5) & 1u) - 1.0f) * scale * sub_group_broadcast(regB.s5, lb+0); \ 22 total += (2.0f*(float)((bits >> 6) & 1u) - 1.0f) * scale * sub_group_broadcast(regB.s6, lb+0); \ 23 total += (2.0f*(float)((bits >> 7) & 1u) - 1.0f) * scale * sub_group_broadcast(regB.s7, lb+0); \ 24 total += (2.0f*(float)((bits >> 8) & 1u) - 1.0f) * scale * sub_group_broadcast(regB.s0, lb+1); \ 25 total += (2.0f*(float)((bits >> 9) & 1u) - 1.0f) * scale * sub_group_broadcast(regB.s1, lb+1); \ 26 total += (2.0f*(float)((bits >> 10) & 1u) - 1.0f) * scale * sub_group_broadcast(regB.s2, lb+1); \ 27 total += (2.0f*(float)((bits >> 11) & 1u) - 1.0f) * scale * sub_group_broadcast(regB.s3, lb+1); \ 28 total += (2.0f*(float)((bits >> 12) & 1u) - 1.0f) * scale * sub_group_broadcast(regB.s4, lb+1); \ 29 total += (2.0f*(float)((bits >> 13) & 1u) - 1.0f) * scale * sub_group_broadcast(regB.s5, lb+1); \ 30 total += (2.0f*(float)((bits >> 14) & 1u) - 1.0f) * scale * sub_group_broadcast(regB.s6, lb+1); \ 31 total += (2.0f*(float)((bits >> 15) & 1u) - 1.0f) * scale * sub_group_broadcast(regB.s7, lb+1); \ 32 total += (2.0f*(float)((bits >> 16) & 1u) - 1.0f) * scale * sub_group_broadcast(regB.s0, lb+2); \ 33 total += (2.0f*(float)((bits >> 17) & 1u) - 1.0f) * scale * sub_group_broadcast(regB.s1, lb+2); \ 34 total += (2.0f*(float)((bits >> 18) & 1u) - 1.0f) * scale * sub_group_broadcast(regB.s2, lb+2); \ 35 total += (2.0f*(float)((bits >> 19) & 1u) - 1.0f) * scale * sub_group_broadcast(regB.s3, lb+2); \ 36 total += (2.0f*(float)((bits >> 20) & 1u) - 1.0f) * scale * sub_group_broadcast(regB.s4, lb+2); \ 37 total += (2.0f*(float)((bits >> 21) & 1u) - 1.0f) * scale * sub_group_broadcast(regB.s5, lb+2); \ 38 total += (2.0f*(float)((bits >> 22) & 1u) - 1.0f) * scale * sub_group_broadcast(regB.s6, lb+2); \ 39 total += (2.0f*(float)((bits >> 23) & 1u) - 1.0f) * scale * sub_group_broadcast(regB.s7, lb+2); \ 40 total += (2.0f*(float)((bits >> 24) & 1u) - 1.0f) * scale * sub_group_broadcast(regB.s0, lb+3); \ 41 total += (2.0f*(float)((bits >> 25) & 1u) - 1.0f) * scale * sub_group_broadcast(regB.s1, lb+3); \ 42 total += (2.0f*(float)((bits >> 26) & 1u) - 1.0f) * scale * sub_group_broadcast(regB.s2, lb+3); \ 43 total += (2.0f*(float)((bits >> 27) & 1u) - 1.0f) * scale * sub_group_broadcast(regB.s3, lb+3); \ 44 total += (2.0f*(float)((bits >> 28) & 1u) - 1.0f) * scale * sub_group_broadcast(regB.s4, lb+3); \ 45 total += (2.0f*(float)((bits >> 29) & 1u) - 1.0f) * scale * sub_group_broadcast(regB.s5, lb+3); \ 46 total += (2.0f*(float)((bits >> 30) & 1u) - 1.0f) * scale * sub_group_broadcast(regB.s6, lb+3); \ 47 total += (2.0f*(float)((bits >> 31) & 1u) - 1.0f) * scale * sub_group_broadcast(regB.s7, lb+3); 48 49 50 #ifdef ADRENO_GPU 51 REQD_SUBGROUP_SIZE_64 52 #endif 53 __kernel void kernel_gemv_noshuffle_q1_0_f32( 54 read_only image1d_buffer_t src0_q, 55 global half * src0_d, 56 read_only image1d_buffer_t src1, 57 ulong offset1, 58 global float * dst, 59 ulong offsetd, 60 int ne00, 61 int ne01, 62 int ne02, 63 int ne10, 64 int ne12, 65 int ne0, 66 int ne1, 67 int r2, 68 int r3) 69 { 70 uint groupId = get_local_id(1); 71 uint gid = get_global_id(0); 72 ushort slid = get_sub_group_local_id(); 73 74 uint K = ne00; 75 uint M = ne01; 76 77 uint LINE_STRIDE_A = M; 78 // Keep tail lanes active for subgroup ops, but read a valid weight row. 79 uint gid_s = min(gid, LINE_STRIDE_A - 1); 80 uint BLOCK_STRIDE_A = 4 * M; 81 82 uint4 regA; 83 half regS; 84 float8 regB; 85 86 float totalSum = 0.0f; 87 88 #pragma unroll 1 89 for (uint kb = groupId; kb < (K / QK1_0); kb += N_SIMDGROUP) { 90 regS = src0_d[gid_s + kb * LINE_STRIDE_A]; // each fiber loads its row's scale 91 92 // first 16 fibers load 8 B values each -> 128 activations for this block 93 if (slid < 16) { 94 regB.s0123 = read_imagef(src1, (slid * 2 + kb * 32)); 95 regB.s4567 = read_imagef(src1, (1 + slid * 2 + kb * 32)); 96 } 97 98 // load this row's 4 uint32 (128 sign bits) 99 regA.s0 = read_imageui(src0_q, (gid_s + kb * BLOCK_STRIDE_A + LINE_STRIDE_A * 0)).x; 100 regA.s1 = read_imageui(src0_q, (gid_s + kb * BLOCK_STRIDE_A + LINE_STRIDE_A * 1)).x; 101 regA.s2 = read_imageui(src0_q, (gid_s + kb * BLOCK_STRIDE_A + LINE_STRIDE_A * 2)).x; 102 regA.s3 = read_imageui(src0_q, (gid_s + kb * BLOCK_STRIDE_A + LINE_STRIDE_A * 3)).x; 103 104 float scale = (float)regS; 105 dequantizeBlockAccum_q1(totalSum, regA.s0, scale, regB, 0); 106 dequantizeBlockAccum_q1(totalSum, regA.s1, scale, regB, 4); 107 dequantizeBlockAccum_q1(totalSum, regA.s2, scale, regB, 8); 108 dequantizeBlockAccum_q1(totalSum, regA.s3, scale, regB, 12); 109 } 110 111 #if N_SIMDGROUP > 1 112 // Sum the K slices from the other subgroups. 113 local float reduceLM[SIMDGROUP_WIDTH * (N_SIMDGROUP - 1)]; 114 if (groupId > 0) { 115 reduceLM[SIMDGROUP_WIDTH * (groupId - 1) + slid] = totalSum; 116 } 117 barrier(CLK_LOCAL_MEM_FENCE); 118 if (groupId == 0) { 119 for (uint w = 0; w < N_SIMDGROUP - 1; ++w) { 120 totalSum += reduceLM[SIMDGROUP_WIDTH * w + slid]; 121 } 122 } 123 #endif 124 125 if (groupId == 0) { 126 dst = (global float*)((global char*)dst + offsetd); 127 // Guard the output row. The x-grid is padded to CEIL_DIV(M,wavesize)*wavesize, 128 // so when ne01 is not a multiple of the wave size the tail work-items run past 129 // row ne01 and would overrun dst into the adjacent tensor. No-op / byte-identical 130 // when ne01 is wave-aligned (no padding). 131 if (gid < M) { 132 dst[gid] = totalSum; 133 } 134 } 135 }