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_iq4_xs_f32.cl

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