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_iq3_s_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_iq3_s_f32( |
| 8 | global const uchar * src0_qs, |
| 9 | global const uchar * src0_sg, |
| 10 | global const uchar * src0_qh, |
| 11 | global const uchar * src0_sc, |
| 12 | global const half * src0_d, |
| 13 | read_only image1d_buffer_t src1, |
| 14 | global float * dst, |
| 15 | ulong offsetd, |
| 16 | int m, |
| 17 | int n, |
| 18 | int k, |
| 19 | int n_no_padding |
| 20 | ) { |
| 21 | dst = (global float *)((global char *)dst + offsetd); |
| 22 | const int gy = get_global_id(0); |
| 23 | const int row = get_global_id(1) * 4; |
| 24 | const int n_4 = n / 4; |
| 25 | if (row >= m) { |
| 26 | return; |
| 27 | } |
| 28 | |
| 29 | half8 c0 = 0, c1 = 0, c2 = 0, c3 = 0; |
| 30 | for (int i = 0; i < k; i += 16) { |
| 31 | const uchar4 sc = vload4(0, src0_sc + row + (i / 64) * m); |
| 32 | const half4 d = vload4(0, src0_d + row + (i / 256) * m); |
| 33 | const float4 scale_f = convert_float4(d) * (1.0f + 2.0f*convert_float4((sc >> (uchar4)(4*((i / 32) & 1))) & (uchar4)(15))); |
| 34 | const half4 scale = convert_half4(scale_f); |
| 35 | |
| 36 | for (int l = 0; l < 16; l += 4) { |
| 37 | const int ki = i + l; |
| 38 | const uint4 qs = convert_uint4(vload4(0, src0_qs + row + (ki / 4) * m)); |
| 39 | const uint4 qh = convert_uint4(vload4(0, src0_qh + row + (ki / 32) * m)); |
| 40 | const uchar4 sg = vload4(0, src0_sg + row + (ki / 8) * m); |
| 41 | const uint4 gi = qs | (((qh >> (uint4)(((ki / 4) & 7))) & (uint4)(1)) << (uint4)(8)); |
| 42 | const uint4 grid = (uint4)(iq3_s_grid[gi.s0], iq3_s_grid[gi.s1], |
| 43 | iq3_s_grid[gi.s2], iq3_s_grid[gi.s3]); |
| 44 | #pragma unroll |
| 45 | for (int j = 0; j < 4; ++j) { |
| 46 | half8 b; |
| 47 | b.s0123 = read_imageh(src1, gy * 2 + (ki + j) * n_4); |
| 48 | b.s4567 = read_imageh(src1, gy * 2 + 1 + (ki + j) * n_4); |
| 49 | const int4 magnitude = convert_int4((grid >> (uint4)(8*j)) & (uint4)(255)); |
| 50 | const int4 signs = convert_int4((sg >> (uchar4)((ki & 7) + j)) & (uchar4)(1)); |
| 51 | const half4 w = convert_half4(magnitude * ((int4)(1) - 2*signs)) * scale; |
| 52 | c0 += b * w.s0; |
| 53 | c1 += b * w.s1; |
| 54 | c2 += b * w.s2; |
| 55 | c3 += b * w.s3; |
| 56 | } |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | int idx = gy * 8 * m + row; |
| 61 | if (idx + 3 < m * n_no_padding) { |
| 62 | vstore4((float4)(c0.s0, c1.s0, c2.s0, c3.s0), 0, dst + idx); |
| 63 | idx += m; |
| 64 | } |
| 65 | if (idx + 3 < m * n_no_padding) { |
| 66 | vstore4((float4)(c0.s1, c1.s1, c2.s1, c3.s1), 0, dst + idx); |
| 67 | idx += m; |
| 68 | } |
| 69 | if (idx + 3 < m * n_no_padding) { |
| 70 | vstore4((float4)(c0.s2, c1.s2, c2.s2, c3.s2), 0, dst + idx); |
| 71 | idx += m; |
| 72 | } |
| 73 | if (idx + 3 < m * n_no_padding) { |
| 74 | vstore4((float4)(c0.s3, c1.s3, c2.s3, c3.s3), 0, dst + idx); |
| 75 | idx += m; |
| 76 | } |
| 77 | if (idx + 3 < m * n_no_padding) { |
| 78 | vstore4((float4)(c0.s4, c1.s4, c2.s4, c3.s4), 0, dst + idx); |
| 79 | idx += m; |
| 80 | } |
| 81 | if (idx + 3 < m * n_no_padding) { |
| 82 | vstore4((float4)(c0.s5, c1.s5, c2.s5, c3.s5), 0, dst + idx); |
| 83 | idx += m; |
| 84 | } |
| 85 | if (idx + 3 < m * n_no_padding) { |
| 86 | vstore4((float4)(c0.s6, c1.s6, c2.s6, c3.s6), 0, dst + idx); |
| 87 | idx += m; |
| 88 | } |
| 89 | if (idx + 3 < m * n_no_padding) { |
| 90 | vstore4((float4)(c0.s7, c1.s7, c2.s7, c3.s7), 0, dst + idx); |
| 91 | } |
| 92 | } |