ggml
[Ported from github.com/ggml-org/ggml] docs : sync ggml_type enum in gguf.md (#1685)
Brought by drakestapleton
ggml / src / ggml-opencl / kernels / gemm_noshuffle_q2_k_f32.cl
| 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_q2_k_f32( |
| 8 | global const uchar * src0_qs, |
| 9 | global const uchar * src0_sc, |
| 10 | global const half * src0_dm, |
| 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 half8 dm = vload8(0, src0_dm + 2 * (row + (i / 256) * m)); |
| 30 | const uchar4 sc = vload4(0, src0_sc + row + (i / 16) * m); |
| 31 | const half4 scale = convert_half4(convert_float4(dm.s0246) * convert_float4(sc & (uchar4)(15))); |
| 32 | const half4 mval = convert_half4(convert_float4(dm.s1357) * convert_float4(sc >> (uchar4)(4))); |
| 33 | |
| 34 | for (int l = 0; l < 16; l += 4) { |
| 35 | const int ki = i + l; |
| 36 | const uchar4 bits = vload4(0, src0_qs + row + (ki / 4) * m); |
| 37 | #pragma unroll |
| 38 | for (int j = 0; j < 4; ++j) { |
| 39 | half8 b; |
| 40 | b.s0123 = read_imageh(src1, gy * 2 + (ki + j) * n_4); |
| 41 | b.s4567 = read_imageh(src1, gy * 2 + 1 + (ki + j) * n_4); |
| 42 | const half4 w = convert_half4((bits >> (uchar4)(2 * j)) & (uchar4)(3)) * scale - mval; |
| 43 | c0 += b * w.s0; |
| 44 | c1 += b * w.s1; |
| 45 | c2 += b * w.s2; |
| 46 | c3 += b * w.s3; |
| 47 | } |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | int idx = gy * 8 * m + row; |
| 52 | if (idx + 3 < m * n_no_padding) { |
| 53 | vstore4((float4)(c0.s0, c1.s0, c2.s0, c3.s0), 0, dst + idx); |
| 54 | idx += m; |
| 55 | } |
| 56 | if (idx + 3 < m * n_no_padding) { |
| 57 | vstore4((float4)(c0.s1, c1.s1, c2.s1, c3.s1), 0, dst + idx); |
| 58 | idx += m; |
| 59 | } |
| 60 | if (idx + 3 < m * n_no_padding) { |
| 61 | vstore4((float4)(c0.s2, c1.s2, c2.s2, c3.s2), 0, dst + idx); |
| 62 | idx += m; |
| 63 | } |
| 64 | if (idx + 3 < m * n_no_padding) { |
| 65 | vstore4((float4)(c0.s3, c1.s3, c2.s3, c3.s3), 0, dst + idx); |
| 66 | idx += m; |
| 67 | } |
| 68 | if (idx + 3 < m * n_no_padding) { |
| 69 | vstore4((float4)(c0.s4, c1.s4, c2.s4, c3.s4), 0, dst + idx); |
| 70 | idx += m; |
| 71 | } |
| 72 | if (idx + 3 < m * n_no_padding) { |
| 73 | vstore4((float4)(c0.s5, c1.s5, c2.s5, c3.s5), 0, dst + idx); |
| 74 | idx += m; |
| 75 | } |
| 76 | if (idx + 3 < m * n_no_padding) { |
| 77 | vstore4((float4)(c0.s6, c1.s6, c2.s6, c3.s6), 0, dst + idx); |
| 78 | idx += m; |
| 79 | } |
| 80 | if (idx + 3 < m * n_no_padding) { |
| 81 | vstore4((float4)(c0.s7, c1.s7, c2.s7, c3.s7), 0, dst + idx); |
| 82 | } |
| 83 | } |