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

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