interplane.Get Omega
Read in your language

ggml

[Ported from github.com/ggml-org/ggml] docs : sync ggml_type enum in gguf.md (#1685)

Brought by drakestapleton

branch master Branches Tags History

ggml / src / ggml-opencl / kernels / gemm_noshuffle_iq2_xs_f32.cl

91 lines · 3438 bytes Raw Blame History
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
7kernel void kernel_gemm_noshuffle_iq2_xs_f32(
8 global const ushort * src0_qs,
9 global const uchar * src0_sc,
10 global const half * src0_d,
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 uchar4 sc = vload4(0, src0_sc + row + (i / 32) * m);
30 const half4 d = vload4(0, src0_d + row + (i / 256) * m);
31 const float4 scale_f = convert_float4(d) * 0.25f * (0.5f + convert_float4((sc >> (uchar4)(4*((i / 16) & 1))) & (uchar4)(15)));
32 const half4 scale = convert_half4(scale_f);
33
34 for (int l = 0; l < 16; l += 4) {
35 const int ki = i + l;
36 const uint4 qs = convert_uint4(vload4(0, src0_qs + row + (ki / 8) * m));
37 const uint4 code = qs >> (uint4)(9);
38 const uint4 sg = code | ((popcount(code) & (uint4)(1)) << (uint4)(7));
39 const uint4 gi = qs & (uint4)(511);
40 const uint half_grid = (ki & 7) / 4;
41 const uint4 grid = (uint4)(iq2_xs_grid[2*gi.s0 + half_grid], iq2_xs_grid[2*gi.s1 + half_grid],
42 iq2_xs_grid[2*gi.s2 + half_grid], iq2_xs_grid[2*gi.s3 + half_grid]);
43 #pragma unroll
44 for (int j = 0; j < 4; ++j) {
45 half8 b;
46 b.s0123 = read_imageh(src1, gy * 2 + (ki + j) * n_4);
47 b.s4567 = read_imageh(src1, gy * 2 + 1 + (ki + j) * n_4);
48 const int4 magnitude = convert_int4((grid >> (uint4)(8*j)) & (uint4)(255));
49 const int4 signs = convert_int4((sg >> (uint4)((ki & 7) + j)) & (uint4)(1));
50 const half4 w = convert_half4(magnitude * ((int4)(1) - 2*signs)) * scale;
51 c0 += b * w.s0;
52 c1 += b * w.s1;
53 c2 += b * w.s2;
54 c3 += b * w.s3;
55 }
56 }
57 }
58
59 int idx = gy * 8 * m + row;
60 if (idx + 3 < m * n_no_padding) {
61 vstore4((float4)(c0.s0, c1.s0, c2.s0, c3.s0), 0, dst + idx);
62 idx += m;
63 }
64 if (idx + 3 < m * n_no_padding) {
65 vstore4((float4)(c0.s1, c1.s1, c2.s1, c3.s1), 0, dst + idx);
66 idx += m;
67 }
68 if (idx + 3 < m * n_no_padding) {
69 vstore4((float4)(c0.s2, c1.s2, c2.s2, c3.s2), 0, dst + idx);
70 idx += m;
71 }
72 if (idx + 3 < m * n_no_padding) {
73 vstore4((float4)(c0.s3, c1.s3, c2.s3, c3.s3), 0, dst + idx);
74 idx += m;
75 }
76 if (idx + 3 < m * n_no_padding) {
77 vstore4((float4)(c0.s4, c1.s4, c2.s4, c3.s4), 0, dst + idx);
78 idx += m;
79 }
80 if (idx + 3 < m * n_no_padding) {
81 vstore4((float4)(c0.s5, c1.s5, c2.s5, c3.s5), 0, dst + idx);
82 idx += m;
83 }
84 if (idx + 3 < m * n_no_padding) {
85 vstore4((float4)(c0.s6, c1.s6, c2.s6, c3.s6), 0, dst + idx);
86 idx += m;
87 }
88 if (idx + 3 < m * n_no_padding) {
89 vstore4((float4)(c0.s7, c1.s7, c2.s7, c3.s7), 0, dst + idx);
90 }
91}