whispercpp 1.3.0 → 1.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +5 -0
- data/LICENSE +1 -1
- data/README.md +165 -434
- data/Rakefile +60 -11
- data/ext/.gitignore +13 -0
- data/ext/cpu.mk +9 -0
- data/ext/{dr_wav.h → examples/dr_wav.h} +3560 -1179
- data/ext/extconf.rb +185 -16
- data/ext/ggml/include/ggml-alloc.h +76 -0
- data/ext/ggml/include/ggml-backend.h +352 -0
- data/ext/ggml/include/ggml-blas.h +25 -0
- data/ext/ggml/include/ggml-cann.h +123 -0
- data/ext/ggml/include/ggml-cpp.h +38 -0
- data/ext/ggml/include/ggml-cpu.h +135 -0
- data/ext/ggml/include/ggml-cuda.h +47 -0
- data/ext/ggml/include/ggml-kompute.h +50 -0
- data/ext/ggml/include/ggml-metal.h +66 -0
- data/ext/ggml/include/ggml-opencl.h +26 -0
- data/ext/ggml/include/ggml-opt.h +216 -0
- data/ext/ggml/include/ggml-rpc.h +28 -0
- data/ext/ggml/include/ggml-sycl.h +49 -0
- data/ext/ggml/include/ggml-vulkan.h +31 -0
- data/ext/{ggml.h → ggml/include/ggml.h} +479 -596
- data/ext/ggml/src/ggml-alloc.c +1037 -0
- data/ext/ggml/src/ggml-amx/common.h +94 -0
- data/ext/ggml/src/ggml-amx/ggml-amx.cpp +446 -0
- data/ext/ggml/src/ggml-amx/mmq.cpp +2510 -0
- data/ext/ggml/src/ggml-amx/mmq.h +17 -0
- data/ext/ggml/src/ggml-backend-impl.h +256 -0
- data/ext/ggml/src/ggml-backend-reg.cpp +552 -0
- data/ext/ggml/src/ggml-backend.cpp +1999 -0
- data/ext/ggml/src/ggml-blas/ggml-blas.cpp +517 -0
- data/ext/ggml/src/ggml-cann/acl_tensor.cpp +175 -0
- data/ext/ggml/src/ggml-cann/acl_tensor.h +258 -0
- data/ext/ggml/src/ggml-cann/aclnn_ops.cpp +3427 -0
- data/ext/ggml/src/ggml-cann/aclnn_ops.h +592 -0
- data/ext/ggml/src/ggml-cann/common.h +286 -0
- data/ext/ggml/src/ggml-cann/ggml-cann.cpp +2188 -0
- data/ext/ggml/src/ggml-cann/kernels/ascendc_kernels.h +19 -0
- data/ext/ggml/src/ggml-cann/kernels/dup.cpp +236 -0
- data/ext/ggml/src/ggml-cann/kernels/get_row_f16.cpp +197 -0
- data/ext/ggml/src/ggml-cann/kernels/get_row_f32.cpp +190 -0
- data/ext/ggml/src/ggml-cann/kernels/get_row_q4_0.cpp +204 -0
- data/ext/ggml/src/ggml-cann/kernels/get_row_q8_0.cpp +191 -0
- data/ext/ggml/src/ggml-cann/kernels/quantize_f16_q8_0.cpp +218 -0
- data/ext/ggml/src/ggml-cann/kernels/quantize_f32_q8_0.cpp +216 -0
- data/ext/ggml/src/ggml-cann/kernels/quantize_float_to_q4_0.cpp +295 -0
- data/ext/ggml/src/ggml-common.h +1853 -0
- data/ext/ggml/src/ggml-cpu/amx/amx.cpp +220 -0
- data/ext/ggml/src/ggml-cpu/amx/amx.h +8 -0
- data/ext/ggml/src/ggml-cpu/amx/common.h +91 -0
- data/ext/ggml/src/ggml-cpu/amx/mmq.cpp +2511 -0
- data/ext/ggml/src/ggml-cpu/amx/mmq.h +10 -0
- data/ext/ggml/src/ggml-cpu/cpu-feats-x86.cpp +323 -0
- data/ext/ggml/src/ggml-cpu/ggml-cpu-aarch64.cpp +4262 -0
- data/ext/ggml/src/ggml-cpu/ggml-cpu-aarch64.h +8 -0
- data/ext/ggml/src/ggml-cpu/ggml-cpu-hbm.cpp +55 -0
- data/ext/ggml/src/ggml-cpu/ggml-cpu-hbm.h +8 -0
- data/ext/ggml/src/ggml-cpu/ggml-cpu-impl.h +386 -0
- data/ext/ggml/src/ggml-cpu/ggml-cpu-quants.c +10835 -0
- data/ext/ggml/src/ggml-cpu/ggml-cpu-quants.h +63 -0
- data/ext/ggml/src/ggml-cpu/ggml-cpu-traits.cpp +36 -0
- data/ext/ggml/src/ggml-cpu/ggml-cpu-traits.h +38 -0
- data/ext/ggml/src/ggml-cpu/ggml-cpu.c +14123 -0
- data/ext/ggml/src/ggml-cpu/ggml-cpu.cpp +622 -0
- data/ext/ggml/src/ggml-cpu/llamafile/sgemm.cpp +1884 -0
- data/ext/ggml/src/ggml-cpu/llamafile/sgemm.h +14 -0
- data/ext/ggml/src/ggml-cuda/vendors/cuda.h +14 -0
- data/ext/ggml/src/ggml-cuda/vendors/hip.h +186 -0
- data/ext/ggml/src/ggml-cuda/vendors/musa.h +134 -0
- data/ext/ggml/src/ggml-impl.h +556 -0
- data/ext/ggml/src/ggml-kompute/ggml-kompute.cpp +2251 -0
- data/ext/ggml/src/ggml-metal/ggml-metal-impl.h +288 -0
- data/ext/ggml/src/ggml-metal/ggml-metal.m +4884 -0
- data/ext/ggml/src/ggml-metal/ggml-metal.metal +6732 -0
- data/ext/ggml/src/ggml-opt.cpp +854 -0
- data/ext/ggml/src/ggml-quants.c +5238 -0
- data/ext/ggml/src/ggml-quants.h +100 -0
- data/ext/ggml/src/ggml-rpc/ggml-rpc.cpp +1406 -0
- data/ext/ggml/src/ggml-sycl/common.cpp +95 -0
- data/ext/ggml/src/ggml-sycl/concat.cpp +196 -0
- data/ext/ggml/src/ggml-sycl/conv.cpp +99 -0
- data/ext/ggml/src/ggml-sycl/convert.cpp +547 -0
- data/ext/ggml/src/ggml-sycl/dmmv.cpp +1023 -0
- data/ext/ggml/src/ggml-sycl/element_wise.cpp +1030 -0
- data/ext/ggml/src/ggml-sycl/ggml-sycl.cpp +4729 -0
- data/ext/ggml/src/ggml-sycl/im2col.cpp +126 -0
- data/ext/ggml/src/ggml-sycl/mmq.cpp +3031 -0
- data/ext/ggml/src/ggml-sycl/mmvq.cpp +1015 -0
- data/ext/ggml/src/ggml-sycl/norm.cpp +378 -0
- data/ext/ggml/src/ggml-sycl/outprod.cpp +56 -0
- data/ext/ggml/src/ggml-sycl/rope.cpp +276 -0
- data/ext/ggml/src/ggml-sycl/softmax.cpp +251 -0
- data/ext/ggml/src/ggml-sycl/tsembd.cpp +72 -0
- data/ext/ggml/src/ggml-sycl/wkv6.cpp +141 -0
- data/ext/ggml/src/ggml-threading.cpp +12 -0
- data/ext/ggml/src/ggml-threading.h +14 -0
- data/ext/ggml/src/ggml-vulkan/ggml-vulkan.cpp +8657 -0
- data/ext/ggml/src/ggml-vulkan/vulkan-shaders/vulkan-shaders-gen.cpp +593 -0
- data/ext/ggml/src/ggml.c +7694 -0
- data/ext/{whisper.h → include/whisper.h} +23 -22
- data/ext/metal-embed.mk +17 -0
- data/ext/metal.mk +6 -0
- data/ext/ruby_whisper.cpp +1492 -9
- data/ext/ruby_whisper.h +10 -0
- data/ext/scripts/get-flags.mk +38 -0
- data/ext/src/coreml/whisper-decoder-impl.h +146 -0
- data/ext/src/coreml/whisper-decoder-impl.m +201 -0
- data/ext/src/coreml/whisper-encoder-impl.h +142 -0
- data/ext/src/coreml/whisper-encoder-impl.m +197 -0
- data/ext/src/coreml/whisper-encoder.h +26 -0
- data/ext/src/openvino/whisper-openvino-encoder.cpp +108 -0
- data/ext/src/openvino/whisper-openvino-encoder.h +31 -0
- data/ext/{whisper.cpp → src/whisper.cpp} +661 -492
- data/extsources.rb +6 -0
- data/lib/whisper/model/uri.rb +157 -0
- data/lib/whisper.rb +2 -0
- data/tests/helper.rb +7 -0
- data/tests/jfk_reader/.gitignore +5 -0
- data/tests/jfk_reader/extconf.rb +3 -0
- data/tests/jfk_reader/jfk_reader.c +68 -0
- data/tests/test_callback.rb +160 -0
- data/tests/test_error.rb +20 -0
- data/tests/test_model.rb +71 -0
- data/tests/test_package.rb +31 -0
- data/tests/test_params.rb +160 -0
- data/tests/test_segment.rb +83 -0
- data/tests/test_whisper.rb +211 -123
- data/whispercpp.gemspec +36 -0
- metadata +137 -11
- data/ext/ggml.c +0 -21755
@@ -0,0 +1,4262 @@
|
|
1
|
+
#define GGML_COMMON_IMPL_CPP
|
2
|
+
#define GGML_COMMON_DECL_CPP
|
3
|
+
#include "ggml-common.h"
|
4
|
+
#include "ggml-backend-impl.h"
|
5
|
+
|
6
|
+
#include "ggml-quants.h"
|
7
|
+
#include "ggml-impl.h"
|
8
|
+
#include "ggml-cpu.h"
|
9
|
+
#include "ggml-cpu-impl.h"
|
10
|
+
#include "ggml-cpu-traits.h"
|
11
|
+
|
12
|
+
#include <cmath>
|
13
|
+
#include <cstring>
|
14
|
+
#include <cassert>
|
15
|
+
#include <cfloat>
|
16
|
+
#include <cstdlib> // for qsort
|
17
|
+
#include <cstdio> // for GGML_ASSERT
|
18
|
+
|
19
|
+
#include "ggml-cpu-aarch64.h"
|
20
|
+
|
21
|
+
// TODO: move to include file?
|
22
|
+
template <int K> constexpr int QK_0() {
|
23
|
+
if constexpr (K == 4) {
|
24
|
+
return QK4_0;
|
25
|
+
}
|
26
|
+
if constexpr (K == 8) {
|
27
|
+
return QK8_0;
|
28
|
+
}
|
29
|
+
return -1;
|
30
|
+
}
|
31
|
+
|
32
|
+
template <int K, int N> struct block {
|
33
|
+
ggml_half d[N]; // deltas for N qK_0 blocks
|
34
|
+
int8_t qs[(QK_0<K>() * N * K) / 8]; // quants for N qK_0 blocks
|
35
|
+
};
|
36
|
+
|
37
|
+
// control size
|
38
|
+
static_assert(sizeof(block<4, 4>) == 4 * sizeof(ggml_half) + QK8_0 * 2, "wrong block<4,4> size/padding");
|
39
|
+
static_assert(sizeof(block<4, 8>) == 8 * sizeof(ggml_half) + QK8_0 * 4, "wrong block<4,8> size/padding");
|
40
|
+
static_assert(sizeof(block<8, 4>) == 4 * sizeof(ggml_half) + QK8_0 * 4, "wrong block<8,4> size/padding");
|
41
|
+
static_assert(sizeof(block<8, 8>) == 8 * sizeof(ggml_half) + QK8_0 * 8, "wrong block<8,8> size/padding");
|
42
|
+
|
43
|
+
using block_q4_0x4 = block<4, 4>;
|
44
|
+
using block_q4_0x8 = block<4, 8>;
|
45
|
+
using block_q8_0x4 = block<8, 4>;
|
46
|
+
using block_q8_0x8 = block<8, 8>;
|
47
|
+
|
48
|
+
struct block_iq4_nlx4 {
|
49
|
+
ggml_half d[4]; // deltas for 4 iq4_nl blocks
|
50
|
+
uint8_t qs[QK4_NL * 2]; // nibbles / quants for 4 iq4_nl blocks
|
51
|
+
};
|
52
|
+
|
53
|
+
static_assert(sizeof(block_iq4_nlx4) == 4 * sizeof(ggml_half) + QK4_NL * 2, "wrong iq4_nlx4 block size/padding");
|
54
|
+
|
55
|
+
#if defined(__GNUC__)
|
56
|
+
#pragma GCC diagnostic ignored "-Woverlength-strings"
|
57
|
+
#elif defined(_MSC_VER)
|
58
|
+
#pragma warning(disable: 4244 4267) // possible loss of data
|
59
|
+
#endif
|
60
|
+
|
61
|
+
#define UNUSED GGML_UNUSED
|
62
|
+
|
63
|
+
// Functions to create the interleaved data layout formats
|
64
|
+
|
65
|
+
// interleave 4 block_q4_0s in blocks of blck_size_interleave
|
66
|
+
// returns an interleaved block_q4_0x4
|
67
|
+
// in the interleaved block_q4_0x4, place deltas for 4 block_q4_0 blocks
|
68
|
+
// first, then interleave quants from 4 block_q4_0s in blocks of blck_size_interleave
|
69
|
+
//
|
70
|
+
// - in : an array of block_q4_0 pointers
|
71
|
+
// - blck_size_interleave : the block_q4_0 quants bytes are interleaved in blocks of
|
72
|
+
// blck_size_interleave bytes
|
73
|
+
// - xor_mask : the mask to convert the nibbles in block_q4_0 quants bytes
|
74
|
+
// from bias offset form to pure sign form (this saves subtract
|
75
|
+
// operations durin unpacking)
|
76
|
+
//
|
77
|
+
#if defined(__AVX__)
|
78
|
+
#if defined(__F16C__)
|
79
|
+
#if defined(__AVX512F__)
|
80
|
+
#define GGML_F32Cx8x2_LOAD(x, y) _mm512_cvtph_ps(_mm256_set_m128i(_mm_loadu_si128((const __m128i *)(y)), _mm_loadu_si128((const __m128i *)(x))))
|
81
|
+
#define GGML_F32Cx16_REPEAT_LOAD(x) _mm512_cvtph_ps(_mm256_set_m128i(x, x))
|
82
|
+
#endif
|
83
|
+
// the _mm256_cvt intrinsics require F16C
|
84
|
+
#define GGML_F32Cx8_LOAD(x) _mm256_cvtph_ps(_mm_loadu_si128((const __m128i *)(x)))
|
85
|
+
#define GGML_F32Cx8_REPEAT_LOAD(x, loadMask) _mm256_cvtph_ps(_mm_shuffle_epi32(_mm_maskload_epi32((int const*)(x), loadMask), 68))
|
86
|
+
#define GGML_F32Cx8_REARRANGE_LOAD(x, arrangeMask) _mm256_cvtph_ps(_mm_shuffle_epi8(_mm_loadu_si128((const __m128i *) x), arrangeMask))
|
87
|
+
#else
|
88
|
+
#if defined(__AVX512F__)
|
89
|
+
static inline __m512 __avx512_f32cx8x2_load(ggml_fp16_t *x, ggml_fp16_t *y) {
|
90
|
+
float tmp[16];
|
91
|
+
|
92
|
+
for (int i = 0; i < 8; i++) {
|
93
|
+
tmp[i] = GGML_FP16_TO_FP32(x[i]);
|
94
|
+
}
|
95
|
+
|
96
|
+
for (int i = 0; i < 8; i++) {
|
97
|
+
tmp[i + 8] = GGML_FP16_TO_FP32(y[i]);
|
98
|
+
}
|
99
|
+
|
100
|
+
return _mm512_loadu_ps(tmp);
|
101
|
+
}
|
102
|
+
static inline __m512 __avx512_repeat_f32cx16_load(__m128i x) {
|
103
|
+
float tmp[16];
|
104
|
+
uint16_t tmphalf[8];
|
105
|
+
_mm_storeu_si128((__m128i*)tmphalf, x);
|
106
|
+
|
107
|
+
for (int i = 0; i < 4; i++) {
|
108
|
+
tmp[i] = GGML_FP16_TO_FP32(tmphalf[i]);
|
109
|
+
tmp[i + 4] = GGML_FP16_TO_FP32(tmphalf[i]);
|
110
|
+
tmp[i + 8] = GGML_FP16_TO_FP32(tmphalf[i]);
|
111
|
+
tmp[i + 12] = GGML_FP16_TO_FP32(tmphalf[i]);
|
112
|
+
}
|
113
|
+
|
114
|
+
return _mm512_loadu_ps(tmp);
|
115
|
+
}
|
116
|
+
#endif
|
117
|
+
static inline __m256 __avx_f32cx8_load(ggml_fp16_t *x) {
|
118
|
+
float tmp[8];
|
119
|
+
|
120
|
+
for (int i = 0; i < 8; i++) {
|
121
|
+
tmp[i] = GGML_FP16_TO_FP32(x[i]);
|
122
|
+
}
|
123
|
+
|
124
|
+
return _mm256_loadu_ps(tmp);
|
125
|
+
}
|
126
|
+
static inline __m256 __avx_repeat_f32cx8_load(ggml_fp16_t *x) {
|
127
|
+
float tmp[8];
|
128
|
+
|
129
|
+
for (int i = 0; i < 4; i++) {
|
130
|
+
tmp[i] = GGML_FP16_TO_FP32(x[i]);
|
131
|
+
tmp[i + 4] = GGML_FP16_TO_FP32(x[i]);
|
132
|
+
}
|
133
|
+
|
134
|
+
return _mm256_loadu_ps(tmp);
|
135
|
+
}
|
136
|
+
static inline __m256 __avx_rearranged_f32cx8_load(ggml_fp16_t *x, __m128i arrangeMask) {
|
137
|
+
uint16_t tmphalf[8];
|
138
|
+
float tmp[8];
|
139
|
+
|
140
|
+
_mm_storeu_si128((__m128i*)tmphalf, _mm_shuffle_epi8(_mm_loadu_si128((const __m128i *) x), arrangeMask));
|
141
|
+
for (int i = 0; i < 8; i++) {
|
142
|
+
tmp[i] = GGML_FP16_TO_FP32(tmphalf[i]);
|
143
|
+
}
|
144
|
+
|
145
|
+
return _mm256_loadu_ps(tmp);
|
146
|
+
}
|
147
|
+
|
148
|
+
#define GGML_F32Cx8_LOAD(x) __avx_f32cx8_load(x)
|
149
|
+
#define GGML_F32Cx8_REPEAT_LOAD(x, loadMask) __avx_repeat_f32cx8_load(x)
|
150
|
+
#define GGML_F32Cx8_REARRANGE_LOAD(x, arrangeMask) __avx_rearranged_f32cx8_load(x, arrangeMask)
|
151
|
+
#if defined(__AVX512F__)
|
152
|
+
#define GGML_F32Cx8x2_LOAD(x, y) __avx512_f32cx8x2_load(x, y)
|
153
|
+
#define GGML_F32Cx16_REPEAT_LOAD(x) __avx512_repeat_f32cx16_load(x)
|
154
|
+
#endif
|
155
|
+
#endif
|
156
|
+
#endif
|
157
|
+
|
158
|
+
|
159
|
+
#if defined(__AVX2__) || defined(__AVX512F__)
|
160
|
+
#if defined(__AVX512F__)
|
161
|
+
// add int16_t pairwise and return as 512 bit int vector
|
162
|
+
static inline __m512i sum_i16_pairs_int_32x16(const __m512i x) {
|
163
|
+
const __m512i ones = _mm512_set1_epi16(1);
|
164
|
+
return _mm512_madd_epi16(ones, x);
|
165
|
+
}
|
166
|
+
|
167
|
+
static inline __m512i mul_sum_us8_pairs_int32x16(const __m512i ax, const __m512i sy) {
|
168
|
+
#if defined(__AVX512VNNI__)
|
169
|
+
const __m512i zero = _mm512_setzero_si512();
|
170
|
+
return _mm512_dpbusd_epi32(zero, ax, sy);
|
171
|
+
#else
|
172
|
+
// Perform multiplication and create 16-bit values
|
173
|
+
const __m512i dot = _mm512_maddubs_epi16(ax, sy);
|
174
|
+
return sum_i16_pairs_int_32x16(dot);
|
175
|
+
#endif
|
176
|
+
}
|
177
|
+
|
178
|
+
// multiply int8_t, add results pairwise twice and return as 512 bit int vector
|
179
|
+
static inline __m512i mul_sum_i8_pairs_int32x16(const __m512i x, const __m512i y) {
|
180
|
+
const __m512i zero = _mm512_setzero_si512();
|
181
|
+
// Get absolute values of x vectors
|
182
|
+
const __m512i ax = _mm512_abs_epi8(x);
|
183
|
+
// Sign the values of the y vectors
|
184
|
+
__mmask64 blt0 = _mm512_movepi8_mask(x);
|
185
|
+
const __m512i sy = _mm512_mask_sub_epi8(y, blt0, zero, y);
|
186
|
+
return mul_sum_us8_pairs_int32x16(ax, sy);
|
187
|
+
}
|
188
|
+
#endif
|
189
|
+
|
190
|
+
// add int16_t pairwise and return as 256 bit int vector
|
191
|
+
static inline __m256i sum_i16_pairs_int32x8(const __m256i x) {
|
192
|
+
const __m256i ones = _mm256_set1_epi16(1);
|
193
|
+
return _mm256_madd_epi16(ones, x);
|
194
|
+
}
|
195
|
+
|
196
|
+
static inline __m256i mul_sum_us8_pairs_int32x8(const __m256i ax, const __m256i sy) {
|
197
|
+
#if defined(__AVXVNNI__) || (defined(__AVX512VNNI__) && defined(__AVX512VL__))
|
198
|
+
const __m256i zero = _mm256_setzero_si256();
|
199
|
+
return _mm256_dpbusd_epi32(zero, ax, sy);
|
200
|
+
#else
|
201
|
+
// Perform multiplication and create 16-bit values
|
202
|
+
const __m256i dot = _mm256_maddubs_epi16(ax, sy);
|
203
|
+
return sum_i16_pairs_int32x8(dot);
|
204
|
+
#endif
|
205
|
+
}
|
206
|
+
|
207
|
+
// Integer variant of the function defined in ggml-quants.c
|
208
|
+
// multiply int8_t, add results pairwise twice and return as 256 bit int vector
|
209
|
+
static inline __m256i mul_sum_i8_pairs_int32x8(const __m256i x, const __m256i y) {
|
210
|
+
#if __AVXVNNIINT8__
|
211
|
+
const __m256i zero = _mm256_setzero_si256();
|
212
|
+
return _mm256_dpbssd_epi32(zero, x, y);
|
213
|
+
#else
|
214
|
+
// Get absolute values of x vectors
|
215
|
+
const __m256i ax = _mm256_sign_epi8(x, x);
|
216
|
+
// Sign the values of the y vectors
|
217
|
+
const __m256i sy = _mm256_sign_epi8(y, x);
|
218
|
+
return mul_sum_us8_pairs_int32x8(ax, sy);
|
219
|
+
#endif
|
220
|
+
}
|
221
|
+
#endif
|
222
|
+
|
223
|
+
static const int8_t kvalues_iq4nl[16] = {-127, -104, -83, -65, -49, -35, -22, -10, 1, 13, 25, 38, 53, 69, 89, 113};
|
224
|
+
|
225
|
+
static void quantize_q8_0_4x4(const float * GGML_RESTRICT x, void * GGML_RESTRICT vy, int64_t k) {
|
226
|
+
assert(QK8_0 == 32);
|
227
|
+
assert(k % QK8_0 == 0);
|
228
|
+
const int nb = k / QK8_0;
|
229
|
+
|
230
|
+
block_q8_0x4 * GGML_RESTRICT y = (block_q8_0x4 *) vy;
|
231
|
+
|
232
|
+
#if defined(__ARM_NEON)
|
233
|
+
float32x4_t srcv[4][8];
|
234
|
+
float id[4];
|
235
|
+
|
236
|
+
for (int i = 0; i < nb; i++) {
|
237
|
+
float32x4_t asrcv[8];
|
238
|
+
float32x4_t amaxv[8];
|
239
|
+
|
240
|
+
for (int row_iter = 0; row_iter < 4; row_iter++) {
|
241
|
+
for (int j = 0; j < 8; j++) srcv[row_iter][j] = vld1q_f32(x + row_iter * k + i * 32 + 4 * j);
|
242
|
+
for (int j = 0; j < 8; j++) asrcv[j] = vabsq_f32(srcv[row_iter][j]);
|
243
|
+
|
244
|
+
for (int j = 0; j < 4; j++) amaxv[2 * j] = vmaxq_f32(asrcv[2 * j], asrcv[2 * j + 1]);
|
245
|
+
for (int j = 0; j < 2; j++) amaxv[4 * j] = vmaxq_f32(amaxv[4 * j], amaxv[4 * j + 2]);
|
246
|
+
for (int j = 0; j < 1; j++) amaxv[8 * j] = vmaxq_f32(amaxv[8 * j], amaxv[8 * j + 4]);
|
247
|
+
|
248
|
+
const float amax = vmaxvq_f32(amaxv[0]);
|
249
|
+
|
250
|
+
const float d = amax / ((1 << 7) - 1);
|
251
|
+
id[row_iter] = d ? 1.0f / d : 0.0f;
|
252
|
+
|
253
|
+
y[i].d[row_iter] = GGML_FP32_TO_FP16(d);
|
254
|
+
}
|
255
|
+
|
256
|
+
for (int j = 0; j < 8; j++) {
|
257
|
+
float32x4_t v = vmulq_n_f32(srcv[0][j], id[0]);
|
258
|
+
int32x4_t vi = vcvtnq_s32_f32(v);
|
259
|
+
y[i].qs[16 * j + 0] = vgetq_lane_s32(vi, 0);
|
260
|
+
y[i].qs[16 * j + 1] = vgetq_lane_s32(vi, 1);
|
261
|
+
y[i].qs[16 * j + 2] = vgetq_lane_s32(vi, 2);
|
262
|
+
y[i].qs[16 * j + 3] = vgetq_lane_s32(vi, 3);
|
263
|
+
|
264
|
+
v = vmulq_n_f32(srcv[1][j], id[1]);
|
265
|
+
vi = vcvtnq_s32_f32(v);
|
266
|
+
y[i].qs[16 * j + 4] = vgetq_lane_s32(vi, 0);
|
267
|
+
y[i].qs[16 * j + 5] = vgetq_lane_s32(vi, 1);
|
268
|
+
y[i].qs[16 * j + 6] = vgetq_lane_s32(vi, 2);
|
269
|
+
y[i].qs[16 * j + 7] = vgetq_lane_s32(vi, 3);
|
270
|
+
|
271
|
+
v = vmulq_n_f32(srcv[2][j], id[2]);
|
272
|
+
vi = vcvtnq_s32_f32(v);
|
273
|
+
y[i].qs[16 * j + 8] = vgetq_lane_s32(vi, 0);
|
274
|
+
y[i].qs[16 * j + 9] = vgetq_lane_s32(vi, 1);
|
275
|
+
y[i].qs[16 * j + 10] = vgetq_lane_s32(vi, 2);
|
276
|
+
y[i].qs[16 * j + 11] = vgetq_lane_s32(vi, 3);
|
277
|
+
|
278
|
+
v = vmulq_n_f32(srcv[3][j], id[3]);
|
279
|
+
vi = vcvtnq_s32_f32(v);
|
280
|
+
y[i].qs[16 * j + 12] = vgetq_lane_s32(vi, 0);
|
281
|
+
y[i].qs[16 * j + 13] = vgetq_lane_s32(vi, 1);
|
282
|
+
y[i].qs[16 * j + 14] = vgetq_lane_s32(vi, 2);
|
283
|
+
y[i].qs[16 * j + 15] = vgetq_lane_s32(vi, 3);
|
284
|
+
}
|
285
|
+
}
|
286
|
+
#else
|
287
|
+
// scalar
|
288
|
+
const int blck_size_interleave = 4;
|
289
|
+
float srcv[4][QK8_0];
|
290
|
+
float id[4];
|
291
|
+
|
292
|
+
for (int i = 0; i < nb; i++) {
|
293
|
+
for (int row_iter = 0; row_iter < 4; row_iter++) {
|
294
|
+
float amax = 0.0f; // absolute max
|
295
|
+
|
296
|
+
for (int j = 0; j < QK8_0; j++) {
|
297
|
+
srcv[row_iter][j] = x[row_iter * k + i * QK8_0 + j];
|
298
|
+
amax = MAX(amax, fabsf(srcv[row_iter][j]));
|
299
|
+
}
|
300
|
+
|
301
|
+
const float d = amax / ((1 << 7) - 1);
|
302
|
+
id[row_iter] = d ? 1.0f / d : 0.0f;
|
303
|
+
|
304
|
+
y[i].d[row_iter] = GGML_FP32_TO_FP16(d);
|
305
|
+
}
|
306
|
+
|
307
|
+
for (int j = 0; j < QK8_0 * 4; j++) {
|
308
|
+
int src_offset = (j / (4 * blck_size_interleave)) * blck_size_interleave;
|
309
|
+
int src_id = (j % (4 * blck_size_interleave)) / blck_size_interleave;
|
310
|
+
src_offset += (j % blck_size_interleave);
|
311
|
+
|
312
|
+
float x0 = srcv[src_id][src_offset] * id[src_id];
|
313
|
+
y[i].qs[j] = roundf(x0);
|
314
|
+
}
|
315
|
+
}
|
316
|
+
#endif
|
317
|
+
}
|
318
|
+
|
319
|
+
static void quantize_q8_0_4x8(const float * GGML_RESTRICT x, void * GGML_RESTRICT vy, int64_t k) {
|
320
|
+
assert(QK8_0 == 32);
|
321
|
+
assert(k % QK8_0 == 0);
|
322
|
+
const int nb = k / QK8_0;
|
323
|
+
|
324
|
+
block_q8_0x4 * GGML_RESTRICT y = (block_q8_0x4 *) vy;
|
325
|
+
|
326
|
+
#if defined(__ARM_NEON)
|
327
|
+
float32x4_t srcv[4][8];
|
328
|
+
float id[4];
|
329
|
+
|
330
|
+
for (int i = 0; i < nb; i++) {
|
331
|
+
float32x4_t asrcv[8];
|
332
|
+
float32x4_t amaxv[8];
|
333
|
+
|
334
|
+
for (int row_iter = 0; row_iter < 4; row_iter++) {
|
335
|
+
for (int j = 0; j < 8; j++) srcv[row_iter][j] = vld1q_f32(x + row_iter * k + i * 32 + 4 * j);
|
336
|
+
for (int j = 0; j < 8; j++) asrcv[j] = vabsq_f32(srcv[row_iter][j]);
|
337
|
+
|
338
|
+
for (int j = 0; j < 4; j++) amaxv[2 * j] = vmaxq_f32(asrcv[2 * j], asrcv[2 * j + 1]);
|
339
|
+
for (int j = 0; j < 2; j++) amaxv[4 * j] = vmaxq_f32(amaxv[4 * j], amaxv[4 * j + 2]);
|
340
|
+
for (int j = 0; j < 1; j++) amaxv[8 * j] = vmaxq_f32(amaxv[8 * j], amaxv[8 * j + 4]);
|
341
|
+
|
342
|
+
const float amax = vmaxvq_f32(amaxv[0]);
|
343
|
+
|
344
|
+
const float d = amax / ((1 << 7) - 1);
|
345
|
+
id[row_iter] = d ? 1.0f / d : 0.0f;
|
346
|
+
|
347
|
+
y[i].d[row_iter] = GGML_FP32_TO_FP16(d);
|
348
|
+
}
|
349
|
+
|
350
|
+
for (int j = 0; j < 4; j++) {
|
351
|
+
float32x4_t v = vmulq_n_f32(srcv[0][2 * j], id[0]);
|
352
|
+
int32x4_t vi = vcvtnq_s32_f32(v);
|
353
|
+
y[i].qs[32 * j + 0] = vgetq_lane_s32(vi, 0);
|
354
|
+
y[i].qs[32 * j + 1] = vgetq_lane_s32(vi, 1);
|
355
|
+
y[i].qs[32 * j + 2] = vgetq_lane_s32(vi, 2);
|
356
|
+
y[i].qs[32 * j + 3] = vgetq_lane_s32(vi, 3);
|
357
|
+
v = vmulq_n_f32(srcv[0][2 * j + 1], id[0]);
|
358
|
+
vi = vcvtnq_s32_f32(v);
|
359
|
+
y[i].qs[32 * j + 4] = vgetq_lane_s32(vi, 0);
|
360
|
+
y[i].qs[32 * j + 5] = vgetq_lane_s32(vi, 1);
|
361
|
+
y[i].qs[32 * j + 6] = vgetq_lane_s32(vi, 2);
|
362
|
+
y[i].qs[32 * j + 7] = vgetq_lane_s32(vi, 3);
|
363
|
+
|
364
|
+
v = vmulq_n_f32(srcv[1][2 * j], id[1]);
|
365
|
+
vi = vcvtnq_s32_f32(v);
|
366
|
+
y[i].qs[32 * j + 8] = vgetq_lane_s32(vi, 0);
|
367
|
+
y[i].qs[32 * j + 9] = vgetq_lane_s32(vi, 1);
|
368
|
+
y[i].qs[32 * j + 10] = vgetq_lane_s32(vi, 2);
|
369
|
+
y[i].qs[32 * j + 11] = vgetq_lane_s32(vi, 3);
|
370
|
+
v = vmulq_n_f32(srcv[1][2 * j + 1], id[1]);
|
371
|
+
vi = vcvtnq_s32_f32(v);
|
372
|
+
y[i].qs[32 * j + 12] = vgetq_lane_s32(vi, 0);
|
373
|
+
y[i].qs[32 * j + 13] = vgetq_lane_s32(vi, 1);
|
374
|
+
y[i].qs[32 * j + 14] = vgetq_lane_s32(vi, 2);
|
375
|
+
y[i].qs[32 * j + 15] = vgetq_lane_s32(vi, 3);
|
376
|
+
|
377
|
+
v = vmulq_n_f32(srcv[2][2 * j], id[2]);
|
378
|
+
vi = vcvtnq_s32_f32(v);
|
379
|
+
y[i].qs[32 * j + 16] = vgetq_lane_s32(vi, 0);
|
380
|
+
y[i].qs[32 * j + 17] = vgetq_lane_s32(vi, 1);
|
381
|
+
y[i].qs[32 * j + 18] = vgetq_lane_s32(vi, 2);
|
382
|
+
y[i].qs[32 * j + 19] = vgetq_lane_s32(vi, 3);
|
383
|
+
v = vmulq_n_f32(srcv[2][2 * j + 1], id[2]);
|
384
|
+
vi = vcvtnq_s32_f32(v);
|
385
|
+
y[i].qs[32 * j + 20] = vgetq_lane_s32(vi, 0);
|
386
|
+
y[i].qs[32 * j + 21] = vgetq_lane_s32(vi, 1);
|
387
|
+
y[i].qs[32 * j + 22] = vgetq_lane_s32(vi, 2);
|
388
|
+
y[i].qs[32 * j + 23] = vgetq_lane_s32(vi, 3);
|
389
|
+
|
390
|
+
v = vmulq_n_f32(srcv[3][2 * j], id[3]);
|
391
|
+
vi = vcvtnq_s32_f32(v);
|
392
|
+
y[i].qs[32 * j + 24] = vgetq_lane_s32(vi, 0);
|
393
|
+
y[i].qs[32 * j + 25] = vgetq_lane_s32(vi, 1);
|
394
|
+
y[i].qs[32 * j + 26] = vgetq_lane_s32(vi, 2);
|
395
|
+
y[i].qs[32 * j + 27] = vgetq_lane_s32(vi, 3);
|
396
|
+
v = vmulq_n_f32(srcv[3][2 * j + 1], id[3]);
|
397
|
+
vi = vcvtnq_s32_f32(v);
|
398
|
+
y[i].qs[32 * j + 28] = vgetq_lane_s32(vi, 0);
|
399
|
+
y[i].qs[32 * j + 29] = vgetq_lane_s32(vi, 1);
|
400
|
+
y[i].qs[32 * j + 30] = vgetq_lane_s32(vi, 2);
|
401
|
+
y[i].qs[32 * j + 31] = vgetq_lane_s32(vi, 3);
|
402
|
+
}
|
403
|
+
}
|
404
|
+
#elif defined(__AVX2__) || defined(__AVX__)
|
405
|
+
float id[4];
|
406
|
+
__m256 srcv[4][4];
|
407
|
+
__m256 idvec[4];
|
408
|
+
|
409
|
+
for (int i = 0; i < nb; i++) {
|
410
|
+
for (int row_iter = 0; row_iter < 4; row_iter++) {
|
411
|
+
// Load elements into 4 AVX vectors
|
412
|
+
__m256 v0 = _mm256_loadu_ps( x + row_iter * k + i * 32 );
|
413
|
+
__m256 v1 = _mm256_loadu_ps( x + row_iter * k + i * 32 + 8 );
|
414
|
+
__m256 v2 = _mm256_loadu_ps( x + row_iter * k + i * 32 + 16 );
|
415
|
+
__m256 v3 = _mm256_loadu_ps( x + row_iter * k + i * 32 + 24 );
|
416
|
+
|
417
|
+
// Compute max(abs(e)) for the block
|
418
|
+
const __m256 signBit = _mm256_set1_ps( -0.0f );
|
419
|
+
__m256 maxAbs = _mm256_andnot_ps( signBit, v0 );
|
420
|
+
maxAbs = _mm256_max_ps( maxAbs, _mm256_andnot_ps( signBit, v1 ) );
|
421
|
+
maxAbs = _mm256_max_ps( maxAbs, _mm256_andnot_ps( signBit, v2 ) );
|
422
|
+
maxAbs = _mm256_max_ps( maxAbs, _mm256_andnot_ps( signBit, v3 ) );
|
423
|
+
|
424
|
+
__m128 max4 = _mm_max_ps( _mm256_extractf128_ps( maxAbs, 1 ), _mm256_castps256_ps128( maxAbs ) );
|
425
|
+
max4 = _mm_max_ps( max4, _mm_movehl_ps( max4, max4 ) );
|
426
|
+
max4 = _mm_max_ss( max4, _mm_movehdup_ps( max4 ) );
|
427
|
+
const float maxScalar = _mm_cvtss_f32( max4 );
|
428
|
+
|
429
|
+
// Divided by 127.f to mirror results in quantize_row_q8_0
|
430
|
+
const float d = maxScalar / 127.f;
|
431
|
+
id[row_iter] = ( maxScalar != 0.0f ) ? 127.f / maxScalar : 0.0f; //d ? 1.0f / d : 0.0f;
|
432
|
+
|
433
|
+
// Store the scale for the individual block
|
434
|
+
y[i].d[row_iter] = GGML_FP32_TO_FP16(d);
|
435
|
+
|
436
|
+
// Store the values in blocks of eight values - Aim is to use these later for block interleaving
|
437
|
+
srcv[row_iter][0] = v0;
|
438
|
+
srcv[row_iter][1] = v1;
|
439
|
+
srcv[row_iter][2] = v2;
|
440
|
+
srcv[row_iter][3] = v3;
|
441
|
+
idvec[row_iter] = _mm256_set1_ps(id[row_iter]);
|
442
|
+
}
|
443
|
+
|
444
|
+
// The loop iterates four times - The aim is to get 4 corresponding chunks of eight bytes from the original weight blocks that are interleaved
|
445
|
+
for (int j = 0; j < 4; j++) {
|
446
|
+
// Apply the multiplier
|
447
|
+
__m256 v0 = _mm256_mul_ps(srcv[0][j], idvec[0]);
|
448
|
+
__m256 v1 = _mm256_mul_ps(srcv[1][j], idvec[1]);
|
449
|
+
__m256 v2 = _mm256_mul_ps(srcv[2][j], idvec[2]);
|
450
|
+
__m256 v3 = _mm256_mul_ps(srcv[3][j], idvec[3]);
|
451
|
+
|
452
|
+
// Round to nearest integer
|
453
|
+
v0 = _mm256_round_ps( v0, _MM_ROUND_NEAREST );
|
454
|
+
v1 = _mm256_round_ps( v1, _MM_ROUND_NEAREST );
|
455
|
+
v2 = _mm256_round_ps( v2, _MM_ROUND_NEAREST );
|
456
|
+
v3 = _mm256_round_ps( v3, _MM_ROUND_NEAREST );
|
457
|
+
|
458
|
+
// Convert floats to integers
|
459
|
+
__m256i i0 = _mm256_cvtps_epi32( v0 );
|
460
|
+
__m256i i1 = _mm256_cvtps_epi32( v1 );
|
461
|
+
__m256i i2 = _mm256_cvtps_epi32( v2 );
|
462
|
+
__m256i i3 = _mm256_cvtps_epi32( v3 );
|
463
|
+
|
464
|
+
#if defined(__AVX2__)
|
465
|
+
// Convert int32 to int16
|
466
|
+
i0 = _mm256_packs_epi32( i0, i1 );
|
467
|
+
i2 = _mm256_packs_epi32( i2, i3 );
|
468
|
+
// Convert int16 to int8
|
469
|
+
i0 = _mm256_packs_epi16( i0, i2 );
|
470
|
+
|
471
|
+
// Permute and store the quantized weights in the required order after the pack instruction
|
472
|
+
const __m256i perm = _mm256_setr_epi32( 0, 4, 1, 5, 2, 6, 3, 7 );
|
473
|
+
i0 = _mm256_permutevar8x32_epi32( i0, perm );
|
474
|
+
|
475
|
+
_mm256_storeu_si256((__m256i *)(y[i].qs + 32 * j), i0);
|
476
|
+
#else
|
477
|
+
// Since we don't have in AVX some necessary functions,
|
478
|
+
// we split the registers in half and call AVX2 analogs from SSE
|
479
|
+
__m128i ni0 = _mm256_castsi256_si128( i0 );
|
480
|
+
__m128i ni1 = _mm256_extractf128_si256( i0, 1);
|
481
|
+
__m128i ni2 = _mm256_castsi256_si128( i1 );
|
482
|
+
__m128i ni3 = _mm256_extractf128_si256( i1, 1);
|
483
|
+
__m128i ni4 = _mm256_castsi256_si128( i2 );
|
484
|
+
__m128i ni5 = _mm256_extractf128_si256( i2, 1);
|
485
|
+
__m128i ni6 = _mm256_castsi256_si128( i3 );
|
486
|
+
__m128i ni7 = _mm256_extractf128_si256( i3, 1);
|
487
|
+
|
488
|
+
// Convert int32 to int16
|
489
|
+
ni0 = _mm_packs_epi32( ni0, ni1 );
|
490
|
+
ni2 = _mm_packs_epi32( ni2, ni3 );
|
491
|
+
ni4 = _mm_packs_epi32( ni4, ni5 );
|
492
|
+
ni6 = _mm_packs_epi32( ni6, ni7 );
|
493
|
+
// Convert int16 to int8
|
494
|
+
ni0 = _mm_packs_epi16( ni0, ni2 );
|
495
|
+
ni4 = _mm_packs_epi16( ni4, ni6 );
|
496
|
+
_mm_storeu_si128((__m128i *)(y[i].qs + 32 * j), ni0);
|
497
|
+
_mm_storeu_si128((__m128i *)(y[i].qs + 32 * j + 16), ni4);
|
498
|
+
#endif
|
499
|
+
}
|
500
|
+
}
|
501
|
+
#else
|
502
|
+
// scalar
|
503
|
+
const int blck_size_interleave = 8;
|
504
|
+
float srcv[4][QK8_0];
|
505
|
+
float id[4];
|
506
|
+
|
507
|
+
for (int i = 0; i < nb; i++) {
|
508
|
+
for (int row_iter = 0; row_iter < 4; row_iter++) {
|
509
|
+
float amax = 0.0f; // absolute max
|
510
|
+
|
511
|
+
for (int j = 0; j < QK8_0; j++) {
|
512
|
+
srcv[row_iter][j] = x[row_iter * k + i * QK8_0 + j];
|
513
|
+
amax = MAX(amax, fabsf(srcv[row_iter][j]));
|
514
|
+
}
|
515
|
+
|
516
|
+
const float d = amax / ((1 << 7) - 1);
|
517
|
+
id[row_iter] = d ? 1.0f / d : 0.0f;
|
518
|
+
|
519
|
+
y[i].d[row_iter] = GGML_FP32_TO_FP16(d);
|
520
|
+
}
|
521
|
+
|
522
|
+
for (int j = 0; j < QK8_0 * 4; j++) {
|
523
|
+
int src_offset = (j / (4 * blck_size_interleave)) * blck_size_interleave;
|
524
|
+
int src_id = (j % (4 * blck_size_interleave)) / blck_size_interleave;
|
525
|
+
src_offset += (j % blck_size_interleave);
|
526
|
+
|
527
|
+
float x0 = srcv[src_id][src_offset] * id[src_id];
|
528
|
+
y[i].qs[j] = roundf(x0);
|
529
|
+
}
|
530
|
+
}
|
531
|
+
#endif
|
532
|
+
}
|
533
|
+
|
534
|
+
static void quantize_mat_q8_0(const float * GGML_RESTRICT x, void * GGML_RESTRICT vy, int64_t nrow, int64_t n_per_row, int64_t blck_size_interleave) {
|
535
|
+
assert(nrow == 4);
|
536
|
+
UNUSED(nrow);
|
537
|
+
if (blck_size_interleave == 4) {
|
538
|
+
quantize_q8_0_4x4(x, vy, n_per_row);
|
539
|
+
} else if (blck_size_interleave == 8) {
|
540
|
+
quantize_q8_0_4x8(x, vy, n_per_row);
|
541
|
+
} else {
|
542
|
+
assert(false);
|
543
|
+
}
|
544
|
+
}
|
545
|
+
|
546
|
+
static void ggml_gemv_q4_0_4x4_q8_0(int n, float * GGML_RESTRICT s, size_t bs, const void * GGML_RESTRICT vx, const void * GGML_RESTRICT vy, int nr, int nc) {
|
547
|
+
const int qk = QK8_0;
|
548
|
+
const int nb = n / qk;
|
549
|
+
const int ncols_interleaved = 4;
|
550
|
+
const int blocklen = 4;
|
551
|
+
|
552
|
+
assert (n % qk == 0);
|
553
|
+
assert (nc % ncols_interleaved == 0);
|
554
|
+
|
555
|
+
UNUSED(s);
|
556
|
+
UNUSED(bs);
|
557
|
+
UNUSED(vx);
|
558
|
+
UNUSED(vy);
|
559
|
+
UNUSED(nr);
|
560
|
+
UNUSED(nc);
|
561
|
+
UNUSED(nb);
|
562
|
+
UNUSED(ncols_interleaved);
|
563
|
+
UNUSED(blocklen);
|
564
|
+
|
565
|
+
#if ! ((defined(_MSC_VER)) && ! defined(__clang__)) && defined(__aarch64__) && defined(__ARM_NEON) && defined(__ARM_FEATURE_DOTPROD)
|
566
|
+
if (ggml_cpu_has_neon() && ggml_cpu_has_dotprod()) {
|
567
|
+
const block_q4_0x4 * b_ptr = (const block_q4_0x4 *)vx;
|
568
|
+
|
569
|
+
for (int c = 0; c < nc; c += ncols_interleaved) {
|
570
|
+
const block_q8_0 * a_ptr = (const block_q8_0 *)vy;
|
571
|
+
float32x4_t acc = vdupq_n_f32(0);
|
572
|
+
for (int b = 0; b < nb; b++) {
|
573
|
+
int8x16_t b0 = vld1q_s8((const int8_t *)b_ptr->qs);
|
574
|
+
int8x16_t b1 = vld1q_s8((const int8_t *)b_ptr->qs + 16);
|
575
|
+
int8x16_t b2 = vld1q_s8((const int8_t *)b_ptr->qs + 32);
|
576
|
+
int8x16_t b3 = vld1q_s8((const int8_t *)b_ptr->qs + 48);
|
577
|
+
float16x4_t bd = vld1_f16((const __fp16 *)b_ptr->d);
|
578
|
+
|
579
|
+
int8x16_t a0 = vld1q_s8(a_ptr->qs);
|
580
|
+
int8x16_t a1 = vld1q_s8(a_ptr->qs + qk/2);
|
581
|
+
float16x4_t ad = vld1_dup_f16((const __fp16 *)&a_ptr->d);
|
582
|
+
|
583
|
+
int32x4_t ret = vdupq_n_s32(0);
|
584
|
+
|
585
|
+
ret = vdotq_laneq_s32(ret, b0 << 4, a0, 0);
|
586
|
+
ret = vdotq_laneq_s32(ret, b1 << 4, a0, 1);
|
587
|
+
ret = vdotq_laneq_s32(ret, b2 << 4, a0, 2);
|
588
|
+
ret = vdotq_laneq_s32(ret, b3 << 4, a0, 3);
|
589
|
+
|
590
|
+
ret = vdotq_laneq_s32(ret, b0 & 0xf0U, a1, 0);
|
591
|
+
ret = vdotq_laneq_s32(ret, b1 & 0xf0U, a1, 1);
|
592
|
+
ret = vdotq_laneq_s32(ret, b2 & 0xf0U, a1, 2);
|
593
|
+
ret = vdotq_laneq_s32(ret, b3 & 0xf0U, a1, 3);
|
594
|
+
|
595
|
+
acc = vfmaq_f32(acc, vcvtq_n_f32_s32(ret, 4),
|
596
|
+
vmulq_f32(vcvt_f32_f16(ad), vcvt_f32_f16(bd)));
|
597
|
+
a_ptr++;
|
598
|
+
b_ptr++;
|
599
|
+
}
|
600
|
+
vst1q_f32(s, acc);
|
601
|
+
s += ncols_interleaved;
|
602
|
+
}
|
603
|
+
return;
|
604
|
+
}
|
605
|
+
#endif // #if ! ((defined(_MSC_VER)) && ! defined(__clang__)) && defined(__aarch64__) && defined(__ARM_NEON) && defined(__ARM_FEATURE_DOTPROD)
|
606
|
+
float sumf[4];
|
607
|
+
int sumi;
|
608
|
+
|
609
|
+
const block_q8_0 * a_ptr = (const block_q8_0 *) vy;
|
610
|
+
for (int x = 0; x < nc / ncols_interleaved; x++) {
|
611
|
+
const block_q4_0x4 * b_ptr = (const block_q4_0x4 *) vx + (x * nb);
|
612
|
+
|
613
|
+
for (int j = 0; j < ncols_interleaved; j++) sumf[j] = 0.0;
|
614
|
+
for (int l = 0; l < nb; l++) {
|
615
|
+
for (int k = 0; k < (qk / (2 * blocklen)); k++) {
|
616
|
+
for (int j = 0; j < ncols_interleaved; j++) {
|
617
|
+
sumi = 0;
|
618
|
+
for (int i = 0; i < blocklen; ++i) {
|
619
|
+
const int v0 = (int8_t) (b_ptr[l].qs[k * ncols_interleaved * blocklen + j * blocklen + i] << 4);
|
620
|
+
const int v1 = (int8_t) (b_ptr[l].qs[k * ncols_interleaved * blocklen + j * blocklen + i] & 0xF0);
|
621
|
+
sumi += ((v0 * a_ptr[l].qs[k * blocklen + i]) + (v1 * a_ptr[l].qs[k * blocklen + i + qk / 2])) >> 4;
|
622
|
+
}
|
623
|
+
sumf[j] += sumi * GGML_FP16_TO_FP32(b_ptr[l].d[j]) * GGML_FP16_TO_FP32(a_ptr[l].d);
|
624
|
+
}
|
625
|
+
}
|
626
|
+
}
|
627
|
+
for (int j = 0; j < ncols_interleaved; j++) s[x * ncols_interleaved + j] = sumf[j];
|
628
|
+
}
|
629
|
+
}
|
630
|
+
|
631
|
+
static void ggml_gemv_q4_0_4x8_q8_0(int n, float * GGML_RESTRICT s, size_t bs, const void * GGML_RESTRICT vx, const void * GGML_RESTRICT vy, int nr, int nc) {
|
632
|
+
const int qk = QK8_0;
|
633
|
+
const int nb = n / qk;
|
634
|
+
const int ncols_interleaved = 4;
|
635
|
+
const int blocklen = 8;
|
636
|
+
|
637
|
+
assert (n % qk == 0);
|
638
|
+
assert (nc % ncols_interleaved == 0);
|
639
|
+
|
640
|
+
UNUSED(s);
|
641
|
+
UNUSED(bs);
|
642
|
+
UNUSED(vx);
|
643
|
+
UNUSED(vy);
|
644
|
+
UNUSED(nr);
|
645
|
+
UNUSED(nc);
|
646
|
+
UNUSED(nb);
|
647
|
+
UNUSED(ncols_interleaved);
|
648
|
+
UNUSED(blocklen);
|
649
|
+
|
650
|
+
#if ! ((defined(_MSC_VER)) && ! defined(__clang__)) && defined(__aarch64__) && defined(__ARM_NEON) && defined(__ARM_FEATURE_MATMUL_INT8)
|
651
|
+
if (ggml_cpu_has_neon() && ggml_cpu_has_matmul_int8()) {
|
652
|
+
const void * b_ptr = vx;
|
653
|
+
const void * a_ptr = vy;
|
654
|
+
float * res_ptr = s;
|
655
|
+
|
656
|
+
__asm__ __volatile__(
|
657
|
+
"movi v2.16b, #0x4\n"
|
658
|
+
"movi v1.16b, #0xf0\n"
|
659
|
+
"add %x[b_ptr], %x[b_ptr], #0x8\n"
|
660
|
+
"1:" // Column loop
|
661
|
+
"add x23, %x[a_ptr], #0x2\n"
|
662
|
+
"movi v0.16b, #0x0\n"
|
663
|
+
"mov x22, %x[nb]\n"
|
664
|
+
"2:" // Block loop
|
665
|
+
"ldr q31, [%x[b_ptr], #0x0]\n"
|
666
|
+
"ldr q30, [%x[b_ptr], #0x10]\n"
|
667
|
+
"mov x21, x23\n"
|
668
|
+
"movi v29.4s, #0x0\n"
|
669
|
+
"ldr q28, [%x[b_ptr], #0x20]\n"
|
670
|
+
"ldr q27, [%x[b_ptr], #0x30]\n"
|
671
|
+
"movi v26.4s, #0x0\n"
|
672
|
+
"sub x20, x23, #0x2\n"
|
673
|
+
"ld1r { v25.8h }, [x20]\n"
|
674
|
+
"ldr q24, [%x[b_ptr], #-0x8]\n"
|
675
|
+
"sub x22, x22, #0x1\n"
|
676
|
+
"add x23, x23, #0x22\n"
|
677
|
+
"ld1r { v23.2d }, [x21], #0x8\n"
|
678
|
+
"sshl v22.16b, v31.16b, v2.16b\n"
|
679
|
+
"sshl v16.16b, v30.16b, v2.16b\n"
|
680
|
+
"add %x[b_ptr], %x[b_ptr], #0x48\n"
|
681
|
+
"ld1r { v21.2d }, [x21], #0x8\n"
|
682
|
+
"sshl v20.16b, v28.16b, v2.16b\n"
|
683
|
+
"sshl v19.16b, v27.16b, v2.16b\n"
|
684
|
+
"ld1r { v18.2d }, [x21], #0x8\n"
|
685
|
+
"ld1r { v17.2d }, [x21], #0x8\n"
|
686
|
+
"and v31.16b, v31.16b, v1.16b\n"
|
687
|
+
"and v30.16b, v30.16b, v1.16b\n"
|
688
|
+
".inst 0x4e9796dd // sdot v29.4s, v22.16b, v23.16b\n"
|
689
|
+
".inst 0x4e97961a // sdot v26.4s, v16.16b, v23.16b\n"
|
690
|
+
"and v28.16b, v28.16b, v1.16b\n"
|
691
|
+
"and v27.16b, v27.16b, v1.16b\n"
|
692
|
+
"fcvtl v25.4s, v25.4h\n"
|
693
|
+
"fcvtl v16.4s, v24.4h\n"
|
694
|
+
".inst 0x4e95969d // sdot v29.4s, v20.16b, v21.16b\n"
|
695
|
+
".inst 0x4e95967a // sdot v26.4s, v19.16b, v21.16b\n"
|
696
|
+
"fmul v16.4s, v16.4s, v25.4s\n"
|
697
|
+
".inst 0x4e9297fd // sdot v29.4s, v31.16b, v18.16b\n"
|
698
|
+
".inst 0x4e9297da // sdot v26.4s, v30.16b, v18.16b\n"
|
699
|
+
".inst 0x4e91979d // sdot v29.4s, v28.16b, v17.16b\n"
|
700
|
+
".inst 0x4e91977a // sdot v26.4s, v27.16b, v17.16b\n"
|
701
|
+
"addp v29.4s, v29.4s, v26.4s\n"
|
702
|
+
"scvtf v29.4s, v29.4s, #0x4\n"
|
703
|
+
"fmla v0.4s, v29.4s, v16.4s\n"
|
704
|
+
"cbnz x22, 2b\n"
|
705
|
+
"sub %x[nc], %x[nc], #0x4\n"
|
706
|
+
"str q0, [%x[res_ptr], #0x0]\n"
|
707
|
+
"add %x[res_ptr], %x[res_ptr], #0x10\n"
|
708
|
+
"cbnz %x[nc], 1b\n"
|
709
|
+
: [b_ptr] "+&r" (b_ptr), [res_ptr] "+&r" (res_ptr), [nc] "+&r" (nc)
|
710
|
+
: [a_ptr] "r" (a_ptr), [nb] "r" (nb)
|
711
|
+
: "memory", "v0", "v1", "v2", "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23", "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31", "x20", "x21", "x22", "x23"
|
712
|
+
);
|
713
|
+
return;
|
714
|
+
}
|
715
|
+
#endif // #if ! ((defined(_MSC_VER)) && ! defined(__clang__)) && defined(__aarch64__) && defined(__ARM_NEON) && defined(__ARM_FEATURE_MATMUL_INT8)
|
716
|
+
float sumf[4];
|
717
|
+
int sumi;
|
718
|
+
|
719
|
+
const block_q8_0 * a_ptr = (const block_q8_0 *) vy;
|
720
|
+
for (int x = 0; x < nc / ncols_interleaved; x++) {
|
721
|
+
const block_q4_0x4 * b_ptr = (const block_q4_0x4 *) vx + (x * nb);
|
722
|
+
|
723
|
+
for (int j = 0; j < ncols_interleaved; j++) sumf[j] = 0.0;
|
724
|
+
for (int l = 0; l < nb; l++) {
|
725
|
+
for (int k = 0; k < (qk / (2 * blocklen)); k++) {
|
726
|
+
for (int j = 0; j < ncols_interleaved; j++) {
|
727
|
+
sumi = 0;
|
728
|
+
for (int i = 0; i < blocklen; ++i) {
|
729
|
+
const int v0 = (int8_t) (b_ptr[l].qs[k * ncols_interleaved * blocklen + j * blocklen + i] << 4);
|
730
|
+
const int v1 = (int8_t) (b_ptr[l].qs[k * ncols_interleaved * blocklen + j * blocklen + i] & 0xF0);
|
731
|
+
sumi += ((v0 * a_ptr[l].qs[k * blocklen + i]) + (v1 * a_ptr[l].qs[k * blocklen + i + qk / 2])) >> 4;
|
732
|
+
}
|
733
|
+
sumf[j] += sumi * GGML_FP16_TO_FP32(b_ptr[l].d[j]) * GGML_FP16_TO_FP32(a_ptr[l].d);
|
734
|
+
}
|
735
|
+
}
|
736
|
+
}
|
737
|
+
for (int j = 0; j < ncols_interleaved; j++) s[x * ncols_interleaved + j] = sumf[j];
|
738
|
+
}
|
739
|
+
}
|
740
|
+
|
741
|
+
static void ggml_gemv_q4_0_8x8_q8_0(int n, float * GGML_RESTRICT s, size_t bs, const void * GGML_RESTRICT vx, const void * GGML_RESTRICT vy, int nr, int nc) {
|
742
|
+
const int qk = QK8_0;
|
743
|
+
const int nb = n / qk;
|
744
|
+
const int ncols_interleaved = 8;
|
745
|
+
const int blocklen = 8;
|
746
|
+
|
747
|
+
assert (n % qk == 0);
|
748
|
+
assert (nc % ncols_interleaved == 0);
|
749
|
+
|
750
|
+
UNUSED(s);
|
751
|
+
UNUSED(bs);
|
752
|
+
UNUSED(vx);
|
753
|
+
UNUSED(vy);
|
754
|
+
UNUSED(nr);
|
755
|
+
UNUSED(nc);
|
756
|
+
UNUSED(nb);
|
757
|
+
UNUSED(ncols_interleaved);
|
758
|
+
UNUSED(blocklen);
|
759
|
+
|
760
|
+
#if ! ((defined(_MSC_VER)) && ! defined(__clang__)) && defined(__aarch64__)
|
761
|
+
#if defined(__ARM_FEATURE_SVE)
|
762
|
+
if (ggml_cpu_has_sve() && ggml_cpu_get_sve_cnt() == QK8_0) {
|
763
|
+
const void * b_ptr = vx;
|
764
|
+
const void * a_ptr = vy;
|
765
|
+
float * res_ptr = s;
|
766
|
+
|
767
|
+
__asm__ __volatile__(
|
768
|
+
"ptrue p0.b\n"
|
769
|
+
"add %x[b_ptr], %x[b_ptr], #0x10\n"
|
770
|
+
"1:" // Column loop
|
771
|
+
"add x22, %x[a_ptr], #0x2\n"
|
772
|
+
"mov z31.b, #0x0\n"
|
773
|
+
"mov x21, %x[nb]\n"
|
774
|
+
"2:" // Block loop
|
775
|
+
"ld1b { z30.b }, p0/Z, [%x[b_ptr]]\n"
|
776
|
+
"ld1b { z29.b }, p0/Z, [%x[b_ptr], #1, MUL VL]\n"
|
777
|
+
"mov z28.s, #0x0\n"
|
778
|
+
"mov z27.s, #0x0\n"
|
779
|
+
"ld1rd { z26.d }, p0/Z, [x22]\n"
|
780
|
+
"ld1b { z25.b }, p0/Z, [%x[b_ptr], #2, MUL VL]\n"
|
781
|
+
"sub x20, x22, #0x2\n"
|
782
|
+
"sub x21, x21, #0x1\n"
|
783
|
+
"ld1b { z24.b }, p0/Z, [%x[b_ptr], #3, MUL VL]\n"
|
784
|
+
"ld1rd { z23.d }, p0/Z, [x22, #8]\n"
|
785
|
+
"lsl z22.b, z30.b, #0x4\n"
|
786
|
+
"lsl z16.b, z29.b, #0x4\n"
|
787
|
+
"and z30.b, z30.b, #0xf0\n"
|
788
|
+
"and z29.b, z29.b, #0xf0\n"
|
789
|
+
"ld1rd { z21.d }, p0/Z, [x22, #16]\n"
|
790
|
+
"ld1rd { z20.d }, p0/Z, [x22, #24]\n"
|
791
|
+
"lsl z19.b, z25.b, #0x4\n"
|
792
|
+
"and z25.b, z25.b, #0xf0\n"
|
793
|
+
"ld1rh { z17.h }, p0/Z, [x20]\n"
|
794
|
+
"ld1h { z18.s }, p0/Z, [%x[b_ptr], #-1, MUL VL]\n"
|
795
|
+
"sdot z28.s, z22.b, z26.b\n"
|
796
|
+
"sdot z27.s, z16.b, z26.b\n"
|
797
|
+
"lsl z16.b, z24.b, #0x4\n"
|
798
|
+
"add x22, x22, #0x22\n"
|
799
|
+
"and z24.b, z24.b, #0xf0\n"
|
800
|
+
"add %x[b_ptr], %x[b_ptr], #0x90\n"
|
801
|
+
"fcvt z17.s, p0/m, z17.h\n"
|
802
|
+
"fcvt z18.s, p0/m, z18.h\n"
|
803
|
+
"sdot z28.s, z19.b, z23.b\n"
|
804
|
+
"sdot z27.s, z16.b, z23.b\n"
|
805
|
+
"fmul z18.s, z18.s, z17.s\n"
|
806
|
+
"sdot z28.s, z30.b, z21.b\n"
|
807
|
+
"sdot z27.s, z29.b, z21.b\n"
|
808
|
+
"sdot z28.s, z25.b, z20.b\n"
|
809
|
+
"sdot z27.s, z24.b, z20.b\n"
|
810
|
+
"uzp1 z17.s, z28.s, z27.s\n"
|
811
|
+
"uzp2 z16.s, z28.s, z27.s\n"
|
812
|
+
"add z17.s, z17.s, z16.s\n"
|
813
|
+
"asr z17.s, z17.s, #0x4\n"
|
814
|
+
"scvtf z17.s, p0/m, z17.s\n"
|
815
|
+
"fmla z31.s, p0/M, z17.s, z18.s\n"
|
816
|
+
"cbnz x21, 2b\n"
|
817
|
+
"sub %x[nc], %x[nc], #0x8\n"
|
818
|
+
"st1w { z31.s }, p0, [%x[res_ptr]]\n"
|
819
|
+
"add %x[res_ptr], %x[res_ptr], #0x20\n"
|
820
|
+
"cbnz %x[nc], 1b\n"
|
821
|
+
: [b_ptr] "+&r" (b_ptr), [res_ptr] "+&r" (res_ptr), [nc] "+&r" (nc)
|
822
|
+
: [a_ptr] "r" (a_ptr), [nb] "r" (nb)
|
823
|
+
: "memory", "p0", "x20", "x21", "x22", "z16", "z17", "z18", "z19", "z20", "z21", "z22", "z23", "z24", "z25", "z26", "z27", "z28", "z29", "z30", "z31"
|
824
|
+
);
|
825
|
+
return;
|
826
|
+
}
|
827
|
+
#endif // #if defined(__ARM_FEATURE_SVE)
|
828
|
+
#elif defined(__AVX2__)
|
829
|
+
// Lookup table to convert signed nibbles to signed bytes
|
830
|
+
__m256i signextendlut = _mm256_castsi128_si256(_mm_set_epi8(-1, -2, -3, -4, -5, -6, -7, -8, 7, 6, 5, 4, 3, 2, 1, 0));
|
831
|
+
signextendlut = _mm256_permute2f128_si256(signextendlut, signextendlut, 0);
|
832
|
+
__m128i changemask = _mm_set_epi8(15, 14, 7, 6, 13, 12, 5, 4, 11, 10, 3, 2, 9, 8, 1, 0);
|
833
|
+
__m256i finalpermutemask = _mm256_set_epi32(7, 5, 3, 1, 6, 4, 2, 0);
|
834
|
+
|
835
|
+
// Permute mask used for easier vector processing at later stages
|
836
|
+
const __m256i m4b = _mm256_set1_epi8(0x0F);
|
837
|
+
|
838
|
+
int64_t b_nb = n / QK4_0;
|
839
|
+
|
840
|
+
const block_q4_0x8 * b_ptr_start = (const block_q4_0x8 *)vx;
|
841
|
+
const block_q8_0 * a_ptr_start = (const block_q8_0 *)vy;
|
842
|
+
|
843
|
+
// Process Q8_0 blocks one by one
|
844
|
+
for (int64_t y = 0; y < nr; y++) {
|
845
|
+
|
846
|
+
// Pointers to LHS blocks of block_q8_0 format
|
847
|
+
const block_q8_0 * a_ptr = a_ptr_start + (y * nb);
|
848
|
+
|
849
|
+
// Take group of eight block_q4_0x8 structures at each pass of the loop and perform dot product operation
|
850
|
+
for (int64_t x = 0; x < nc / 8; x++) {
|
851
|
+
|
852
|
+
// Pointers to RHS blocks
|
853
|
+
const block_q4_0x8 * b_ptr = b_ptr_start + (x * b_nb);
|
854
|
+
|
855
|
+
// Master FP accumulator
|
856
|
+
__m256 acc_row = _mm256_setzero_ps();
|
857
|
+
|
858
|
+
for (int64_t b = 0; b < nb; b++) {
|
859
|
+
// Load 8 blocks of Q4_0 interleaved as 8 bytes (B0 - B7)
|
860
|
+
const __m256i rhs_raw_vec_0123_0 = _mm256_loadu_si256((const __m256i *)(b_ptr[b].qs));
|
861
|
+
const __m256i rhs_raw_vec_4567_0 = _mm256_loadu_si256((const __m256i *)(b_ptr[b].qs) + 1);
|
862
|
+
const __m256i rhs_raw_vec_0123_1 = _mm256_loadu_si256((const __m256i *)(b_ptr[b].qs) + 2);
|
863
|
+
const __m256i rhs_raw_vec_4567_1 = _mm256_loadu_si256((const __m256i *)(b_ptr[b].qs) + 3);
|
864
|
+
|
865
|
+
// 4-bit -> 8-bit - Sign is maintained
|
866
|
+
const __m256i rhs_vec_0123_0 = _mm256_shuffle_epi8(signextendlut, _mm256_and_si256(rhs_raw_vec_0123_0, m4b)); // B0(0-7) B1(0-7) B2(0-7) B3(0-7)
|
867
|
+
const __m256i rhs_vec_4567_0 = _mm256_shuffle_epi8(signextendlut, _mm256_and_si256(rhs_raw_vec_4567_0, m4b)); // B4(0-7) B5(0-7) B6(0-7) B7(0-7)
|
868
|
+
const __m256i rhs_vec_0123_1 = _mm256_shuffle_epi8(signextendlut, _mm256_and_si256(rhs_raw_vec_0123_1, m4b)); // B0(8-15) B1(8-15) B2(8-15) B3(8-15)
|
869
|
+
const __m256i rhs_vec_4567_1 = _mm256_shuffle_epi8(signextendlut, _mm256_and_si256(rhs_raw_vec_4567_1, m4b)); // B0(8-15) B1(8-15) B2(8-15) B3(8-15)
|
870
|
+
|
871
|
+
const __m256i rhs_vec_0123_2 = _mm256_shuffle_epi8(signextendlut, _mm256_and_si256(_mm256_srli_epi16(rhs_raw_vec_0123_0, 4), m4b)); // B0(16-23) B1(16-23) B2(16-23) B3(16-23)
|
872
|
+
const __m256i rhs_vec_4567_2 = _mm256_shuffle_epi8(signextendlut, _mm256_and_si256(_mm256_srli_epi16(rhs_raw_vec_4567_0, 4), m4b)); // B4(16-23) B5(16-23) B6(16-23) B7(16-23)
|
873
|
+
const __m256i rhs_vec_0123_3 = _mm256_shuffle_epi8(signextendlut, _mm256_and_si256(_mm256_srli_epi16(rhs_raw_vec_0123_1, 4), m4b)); // B0(24-31) B1(24-31) B2(24-31) B3(24-31)
|
874
|
+
const __m256i rhs_vec_4567_3 = _mm256_shuffle_epi8(signextendlut, _mm256_and_si256(_mm256_srli_epi16(rhs_raw_vec_4567_1, 4), m4b)); // B4(24-31) B5(24-31) B6(24-31) B7(24-31)
|
875
|
+
|
876
|
+
// Load the scale values for the 8 blocks interleaved in block_q4_0x8
|
877
|
+
const __m256 col_scale_f32 = GGML_F32Cx8_REARRANGE_LOAD(b_ptr[b].d, changemask);
|
878
|
+
|
879
|
+
// Load and convert to FP32 scale from block_q8_0
|
880
|
+
const __m256 row_scale_f32 = _mm256_set1_ps(GGML_FP16_TO_FP32(a_ptr[b].d));
|
881
|
+
|
882
|
+
// Load the block values in block_q8_0 in batches of 16 bytes and replicate the same across 256 bit vector
|
883
|
+
__m256i lhs_vec_0 = _mm256_castsi128_si256(_mm_loadu_si128((const __m128i *)a_ptr[b].qs));
|
884
|
+
__m256i lhs_vec_1 = _mm256_castsi128_si256(_mm_loadu_si128((const __m128i *)(a_ptr[b].qs + 16)));
|
885
|
+
|
886
|
+
lhs_vec_0 = _mm256_permute2f128_si256(lhs_vec_0, lhs_vec_0, 0); // A0 (0-15) A0(0-15)
|
887
|
+
lhs_vec_1 = _mm256_permute2f128_si256(lhs_vec_1, lhs_vec_1, 0); // A0 (16-31) A0(16-31))
|
888
|
+
|
889
|
+
__m256i iacc = _mm256_setzero_si256();
|
890
|
+
|
891
|
+
// Dot product done within 32 bit lanes and accumulated in the same vector
|
892
|
+
// B0(0-3) B4(0-3) B1(0-3) B5(0-3) B2(0-3) B6(0-3) B3(0-3) B7(0-3) with A0(0-3)
|
893
|
+
// B0(4-7) B4(4-7) B1(4-7) B5(4-7) B2(4-7) B6(4-7) B3(4-7) B7(4-7) with A0(4-7)
|
894
|
+
// ...........................................................................
|
895
|
+
// B0(28-31) B4(28-31) B1(28-31) B5(28-31) B2(28-31) B6(28-31) B3(28-31) B7(28-31) with A0(28-31)
|
896
|
+
|
897
|
+
iacc = _mm256_add_epi32(iacc, mul_sum_i8_pairs_int32x8(_mm256_blend_epi32(rhs_vec_0123_0 ,_mm256_shuffle_epi32(rhs_vec_4567_0, 177), 170), _mm256_shuffle_epi32(lhs_vec_0, 0)));
|
898
|
+
iacc = _mm256_add_epi32(iacc, mul_sum_i8_pairs_int32x8(_mm256_blend_epi32(_mm256_shuffle_epi32(rhs_vec_0123_0, 177) ,rhs_vec_4567_0, 170), _mm256_shuffle_epi32(lhs_vec_0, 85)));
|
899
|
+
|
900
|
+
iacc = _mm256_add_epi32(iacc, mul_sum_i8_pairs_int32x8(_mm256_blend_epi32(rhs_vec_0123_1 ,_mm256_shuffle_epi32(rhs_vec_4567_1, 177), 170), _mm256_shuffle_epi32(lhs_vec_0, 170)));
|
901
|
+
iacc = _mm256_add_epi32(iacc, mul_sum_i8_pairs_int32x8(_mm256_blend_epi32(_mm256_shuffle_epi32(rhs_vec_0123_1, 177) ,rhs_vec_4567_1, 170), _mm256_shuffle_epi32(lhs_vec_0, 255)));
|
902
|
+
|
903
|
+
iacc = _mm256_add_epi32(iacc, mul_sum_i8_pairs_int32x8(_mm256_blend_epi32(rhs_vec_0123_2 ,_mm256_shuffle_epi32(rhs_vec_4567_2, 177), 170), _mm256_shuffle_epi32(lhs_vec_1, 0)));
|
904
|
+
iacc = _mm256_add_epi32(iacc, mul_sum_i8_pairs_int32x8(_mm256_blend_epi32(_mm256_shuffle_epi32(rhs_vec_0123_2, 177) ,rhs_vec_4567_2, 170), _mm256_shuffle_epi32(lhs_vec_1, 85)));
|
905
|
+
|
906
|
+
iacc = _mm256_add_epi32(iacc, mul_sum_i8_pairs_int32x8(_mm256_blend_epi32(rhs_vec_0123_3 ,_mm256_shuffle_epi32(rhs_vec_4567_3, 177), 170), _mm256_shuffle_epi32(lhs_vec_1, 170)));
|
907
|
+
iacc = _mm256_add_epi32(iacc, mul_sum_i8_pairs_int32x8(_mm256_blend_epi32(_mm256_shuffle_epi32(rhs_vec_0123_3, 177) ,rhs_vec_4567_3, 170), _mm256_shuffle_epi32(lhs_vec_1, 255)));
|
908
|
+
|
909
|
+
// Accumulated values multipled with appropriate scales
|
910
|
+
acc_row = _mm256_fmadd_ps(_mm256_cvtepi32_ps(iacc), _mm256_mul_ps(col_scale_f32, row_scale_f32), acc_row);
|
911
|
+
}
|
912
|
+
|
913
|
+
// Accumulated output values permuted so as to be stored in appropriate order post accumulation
|
914
|
+
acc_row = _mm256_permutevar8x32_ps(acc_row, finalpermutemask);
|
915
|
+
_mm256_storeu_ps(s + (y * nr + x * 8), acc_row);
|
916
|
+
}
|
917
|
+
}
|
918
|
+
return;
|
919
|
+
#elif defined(__riscv_v_intrinsic)
|
920
|
+
if (__riscv_vlenb() >= QK4_0) {
|
921
|
+
const size_t vl = QK4_0;
|
922
|
+
|
923
|
+
const block_q8_0 * a_ptr = (const block_q8_0 *) vy;
|
924
|
+
for (int x = 0; x < nc / ncols_interleaved; x++) {
|
925
|
+
const block_q4_0x8 * b_ptr = (const block_q4_0x8 *) vx + (x * nb);
|
926
|
+
|
927
|
+
vfloat32m1_t sumf = __riscv_vfmv_v_f_f32m1(0.0, vl / 4);
|
928
|
+
for (int l = 0; l < nb; l++) {
|
929
|
+
const int64_t a0 = *(const int64_t *)&a_ptr[l].qs[0];
|
930
|
+
const int64_t a1 = *(const int64_t *)&a_ptr[l].qs[8];
|
931
|
+
const int64_t a2 = *(const int64_t *)&a_ptr[l].qs[16];
|
932
|
+
const int64_t a3 = *(const int64_t *)&a_ptr[l].qs[24];
|
933
|
+
__asm__ __volatile__("" ::: "memory"); // prevent gcc from emitting fused vlse64, violating alignment
|
934
|
+
const vint8m2_t lhs_0_8 =__riscv_vreinterpret_v_i64m2_i8m2(__riscv_vmv_v_x_i64m2(a0, vl / 4));
|
935
|
+
const vint8m2_t lhs_1_8 =__riscv_vreinterpret_v_i64m2_i8m2(__riscv_vmv_v_x_i64m2(a1, vl / 4));
|
936
|
+
const vint8m2_t lhs_2_8 =__riscv_vreinterpret_v_i64m2_i8m2(__riscv_vmv_v_x_i64m2(a2, vl / 4));
|
937
|
+
const vint8m2_t lhs_3_8 =__riscv_vreinterpret_v_i64m2_i8m2(__riscv_vmv_v_x_i64m2(a3, vl / 4));
|
938
|
+
|
939
|
+
const vint8m4_t rhs_raw_vec = __riscv_vle8_v_i8m4((const int8_t *)b_ptr[l].qs, vl * 4);
|
940
|
+
const vint8m4_t rhs_vec_lo = __riscv_vsra_vx_i8m4(__riscv_vsll_vx_i8m4(rhs_raw_vec, 4, vl * 4), 4, vl * 4);
|
941
|
+
const vint8m4_t rhs_vec_hi = __riscv_vsra_vx_i8m4(rhs_raw_vec, 4, vl * 4);
|
942
|
+
const vint8m2_t rhs_vec_lo_0 = __riscv_vget_v_i8m4_i8m2(rhs_vec_lo, 0);
|
943
|
+
const vint8m2_t rhs_vec_lo_1 = __riscv_vget_v_i8m4_i8m2(rhs_vec_lo, 1);
|
944
|
+
const vint8m2_t rhs_vec_hi_0 = __riscv_vget_v_i8m4_i8m2(rhs_vec_hi, 0);
|
945
|
+
const vint8m2_t rhs_vec_hi_1 = __riscv_vget_v_i8m4_i8m2(rhs_vec_hi, 1);
|
946
|
+
|
947
|
+
const vint16m4_t sumi_lo_0 = __riscv_vwmul_vv_i16m4(rhs_vec_lo_0, lhs_0_8, vl * 2);
|
948
|
+
const vint16m4_t sumi_lo_1 = __riscv_vwmacc_vv_i16m4(sumi_lo_0, rhs_vec_lo_1, lhs_1_8, vl * 2);
|
949
|
+
const vint16m4_t sumi_hi_0 = __riscv_vwmacc_vv_i16m4(sumi_lo_1, rhs_vec_hi_0, lhs_2_8, vl * 2);
|
950
|
+
const vint16m4_t sumi_hi_m = __riscv_vwmacc_vv_i16m4(sumi_hi_0, rhs_vec_hi_1, lhs_3_8, vl * 2);
|
951
|
+
|
952
|
+
const vuint32m4_t sumi_i32 = __riscv_vreinterpret_v_i32m4_u32m4(__riscv_vreinterpret_v_i16m4_i32m4(sumi_hi_m));
|
953
|
+
const vuint16m2_t sumi_h2_0 = __riscv_vnsrl_wx_u16m2(sumi_i32, 0, vl);
|
954
|
+
const vuint16m2_t sumi_h2_1 = __riscv_vnsrl_wx_u16m2(sumi_i32, 16, vl);
|
955
|
+
const vuint16m2_t sumi_h2 = __riscv_vadd_vv_u16m2(sumi_h2_0, sumi_h2_1, vl);
|
956
|
+
const vuint32m2_t sumi_h2_i32 = __riscv_vreinterpret_v_u16m2_u32m2(sumi_h2);
|
957
|
+
const vuint16m1_t sumi_h4_0 = __riscv_vnsrl_wx_u16m1(sumi_h2_i32, 0, vl / 2);
|
958
|
+
const vuint16m1_t sumi_h4_1 = __riscv_vnsrl_wx_u16m1(sumi_h2_i32, 16, vl / 2);
|
959
|
+
const vuint16m1_t sumi_h4 = __riscv_vadd_vv_u16m1(sumi_h4_0, sumi_h4_1, vl / 2);
|
960
|
+
const vuint32m1_t sumi_h4_i32 = __riscv_vreinterpret_v_u16m1_u32m1(sumi_h4);
|
961
|
+
const vint16mf2_t sumi_h8_0 = __riscv_vreinterpret_v_u16mf2_i16mf2(__riscv_vnsrl_wx_u16mf2(sumi_h4_i32, 0, vl / 4));
|
962
|
+
const vint16mf2_t sumi_h8_1 = __riscv_vreinterpret_v_u16mf2_i16mf2(__riscv_vnsrl_wx_u16mf2(sumi_h4_i32, 16, vl / 4));
|
963
|
+
const vint32m1_t sumi_h8 = __riscv_vwadd_vv_i32m1(sumi_h8_0, sumi_h8_1, vl / 4);
|
964
|
+
const vfloat32m1_t facc = __riscv_vfcvt_f_x_v_f32m1(sumi_h8, vl / 4);
|
965
|
+
|
966
|
+
// vector version needs Zvfhmin extension
|
967
|
+
const float a_scale = GGML_FP16_TO_FP32(a_ptr[l].d);
|
968
|
+
const float b_scales[8] = {
|
969
|
+
GGML_FP16_TO_FP32(b_ptr[l].d[0]),
|
970
|
+
GGML_FP16_TO_FP32(b_ptr[l].d[1]),
|
971
|
+
GGML_FP16_TO_FP32(b_ptr[l].d[2]),
|
972
|
+
GGML_FP16_TO_FP32(b_ptr[l].d[3]),
|
973
|
+
GGML_FP16_TO_FP32(b_ptr[l].d[4]),
|
974
|
+
GGML_FP16_TO_FP32(b_ptr[l].d[5]),
|
975
|
+
GGML_FP16_TO_FP32(b_ptr[l].d[6]),
|
976
|
+
GGML_FP16_TO_FP32(b_ptr[l].d[7])
|
977
|
+
};
|
978
|
+
const vfloat32m1_t b_scales_vec = __riscv_vle32_v_f32m1(b_scales, vl / 4);
|
979
|
+
const vfloat32m1_t tmp1 = __riscv_vfmul_vf_f32m1(facc, a_scale, vl / 4);
|
980
|
+
sumf = __riscv_vfmacc_vv_f32m1(sumf, tmp1, b_scales_vec, vl / 4);
|
981
|
+
}
|
982
|
+
__riscv_vse32_v_f32m1(s + x * ncols_interleaved, sumf, vl / 4);
|
983
|
+
}
|
984
|
+
return;
|
985
|
+
}
|
986
|
+
#endif // #if ! ((defined(_MSC_VER)) && ! defined(__clang__)) && defined(__aarch64__)
|
987
|
+
{
|
988
|
+
float sumf[8];
|
989
|
+
int sumi;
|
990
|
+
|
991
|
+
const block_q8_0 * a_ptr = (const block_q8_0 *) vy;
|
992
|
+
for (int x = 0; x < nc / ncols_interleaved; x++) {
|
993
|
+
const block_q4_0x8 * b_ptr = (const block_q4_0x8 *) vx + (x * nb);
|
994
|
+
|
995
|
+
for (int j = 0; j < ncols_interleaved; j++) sumf[j] = 0.0;
|
996
|
+
for (int l = 0; l < nb; l++) {
|
997
|
+
for (int k = 0; k < (qk / (2 * blocklen)); k++) {
|
998
|
+
for (int j = 0; j < ncols_interleaved; j++) {
|
999
|
+
sumi = 0;
|
1000
|
+
for (int i = 0; i < blocklen; ++i) {
|
1001
|
+
const int v0 = (int8_t) (b_ptr[l].qs[k * ncols_interleaved * blocklen + j * blocklen + i] << 4);
|
1002
|
+
const int v1 = (int8_t) (b_ptr[l].qs[k * ncols_interleaved * blocklen + j * blocklen + i] & 0xF0);
|
1003
|
+
sumi += ((v0 * a_ptr[l].qs[k * blocklen + i]) + (v1 * a_ptr[l].qs[k * blocklen + i + qk / 2])) >> 4;
|
1004
|
+
}
|
1005
|
+
sumf[j] += sumi * GGML_FP16_TO_FP32(b_ptr[l].d[j]) * GGML_FP16_TO_FP32(a_ptr[l].d);
|
1006
|
+
}
|
1007
|
+
}
|
1008
|
+
}
|
1009
|
+
for (int j = 0; j < ncols_interleaved; j++) s[x * ncols_interleaved + j] = sumf[j];
|
1010
|
+
}
|
1011
|
+
}
|
1012
|
+
}
|
1013
|
+
|
1014
|
+
static void ggml_gemv_iq4_nl_4x4_q8_0(int n, float * GGML_RESTRICT s, size_t bs, const void * GGML_RESTRICT vx, const void * GGML_RESTRICT vy, int nr, int nc) {
|
1015
|
+
const int qk = QK8_0;
|
1016
|
+
const int nb = n / qk;
|
1017
|
+
const int ncols_interleaved = 4;
|
1018
|
+
const int blocklen = 4;
|
1019
|
+
|
1020
|
+
assert (n % qk == 0);
|
1021
|
+
assert (nc % ncols_interleaved == 0);
|
1022
|
+
|
1023
|
+
UNUSED(s);
|
1024
|
+
UNUSED(bs);
|
1025
|
+
UNUSED(vx);
|
1026
|
+
UNUSED(vy);
|
1027
|
+
UNUSED(nr);
|
1028
|
+
UNUSED(nc);
|
1029
|
+
UNUSED(nb);
|
1030
|
+
UNUSED(ncols_interleaved);
|
1031
|
+
UNUSED(blocklen);
|
1032
|
+
|
1033
|
+
#if ! ((defined(_MSC_VER)) && ! defined(__clang__)) && defined(__aarch64__) && defined(__ARM_NEON) && defined(__ARM_FEATURE_DOTPROD)
|
1034
|
+
if (ggml_cpu_has_neon() && ggml_cpu_has_dotprod()) {
|
1035
|
+
const int8x16_t kvalues = vld1q_s8(kvalues_iq4nl);
|
1036
|
+
const block_q8_0 * a_ptr = (const block_q8_0 *) vy;
|
1037
|
+
float * res_ptr = s;
|
1038
|
+
|
1039
|
+
for (int x = 0; x < nc / ncols_interleaved; x++) {
|
1040
|
+
const block_iq4_nlx4 * b_ptr = (const block_iq4_nlx4 *) vx + (x * nb);
|
1041
|
+
|
1042
|
+
float32x4_t sumf = vdupq_n_f32(0);
|
1043
|
+
for (int l = 0; l < nb; l++) {
|
1044
|
+
uint8x16_t b_0 = vld1q_u8(b_ptr[l].qs + 0);
|
1045
|
+
uint8x16_t b_1 = vld1q_u8(b_ptr[l].qs + 16);
|
1046
|
+
uint8x16_t b_2 = vld1q_u8(b_ptr[l].qs + 32);
|
1047
|
+
uint8x16_t b_3 = vld1q_u8(b_ptr[l].qs + 48);
|
1048
|
+
|
1049
|
+
int8x16_t b_0_hi = vqtbl1q_s8(kvalues, b_0 >> 4);
|
1050
|
+
int8x16_t b_0_lo = vqtbl1q_s8(kvalues, b_0 & 0x0F);
|
1051
|
+
int8x16_t b_1_hi = vqtbl1q_s8(kvalues, b_1 >> 4);
|
1052
|
+
int8x16_t b_1_lo = vqtbl1q_s8(kvalues, b_1 & 0x0F);
|
1053
|
+
int8x16_t b_2_hi = vqtbl1q_s8(kvalues, b_2 >> 4);
|
1054
|
+
int8x16_t b_2_lo = vqtbl1q_s8(kvalues, b_2 & 0x0F);
|
1055
|
+
int8x16_t b_3_hi = vqtbl1q_s8(kvalues, b_3 >> 4);
|
1056
|
+
int8x16_t b_3_lo = vqtbl1q_s8(kvalues, b_3 & 0x0F);
|
1057
|
+
|
1058
|
+
int8x16_t a_0 = vld1q_s8(a_ptr[l].qs + 0);
|
1059
|
+
int8x16_t a_1 = vld1q_s8(a_ptr[l].qs + 16);
|
1060
|
+
|
1061
|
+
int32x4_t sumi = vdupq_n_s32(0);
|
1062
|
+
sumi = vdotq_laneq_s32(sumi, b_0_lo, a_0, 0);
|
1063
|
+
sumi = vdotq_laneq_s32(sumi, b_0_hi, a_1, 0);
|
1064
|
+
sumi = vdotq_laneq_s32(sumi, b_1_lo, a_0, 1);
|
1065
|
+
sumi = vdotq_laneq_s32(sumi, b_1_hi, a_1, 1);
|
1066
|
+
sumi = vdotq_laneq_s32(sumi, b_2_lo, a_0, 2);
|
1067
|
+
sumi = vdotq_laneq_s32(sumi, b_2_hi, a_1, 2);
|
1068
|
+
sumi = vdotq_laneq_s32(sumi, b_3_lo, a_0, 3);
|
1069
|
+
sumi = vdotq_laneq_s32(sumi, b_3_hi, a_1, 3);
|
1070
|
+
|
1071
|
+
float32x4_t a_d = vcvt_f32_f16(vld1_dup_f16((const float16_t *)&a_ptr[l].d));
|
1072
|
+
float32x4_t b_d = vcvt_f32_f16(vld1_f16((const float16_t *)b_ptr[l].d));
|
1073
|
+
float32x4_t d = a_d * b_d;
|
1074
|
+
|
1075
|
+
sumf = vmlaq_f32(sumf, d, vcvtq_f32_s32(sumi));
|
1076
|
+
}
|
1077
|
+
|
1078
|
+
vst1q_f32(res_ptr + x * 4, sumf);
|
1079
|
+
}
|
1080
|
+
return;
|
1081
|
+
}
|
1082
|
+
#endif // #if ! ((defined(_MSC_VER)) && ! defined(__clang__)) && defined(__aarch64__) && defined(__ARM_NEON)
|
1083
|
+
{
|
1084
|
+
float sumf[4];
|
1085
|
+
int sumi;
|
1086
|
+
|
1087
|
+
const block_q8_0 * a_ptr = (const block_q8_0 *) vy;
|
1088
|
+
for (int x = 0; x < nc / ncols_interleaved; x++) {
|
1089
|
+
const block_iq4_nlx4 * b_ptr = (const block_iq4_nlx4 *) vx + (x * nb);
|
1090
|
+
|
1091
|
+
for (int j = 0; j < ncols_interleaved; j++) sumf[j] = 0.0;
|
1092
|
+
for (int l = 0; l < nb; l++) {
|
1093
|
+
for (int k = 0; k < (qk / (2 * blocklen)); k++) {
|
1094
|
+
for (int j = 0; j < ncols_interleaved; j++) {
|
1095
|
+
sumi = 0;
|
1096
|
+
for (int i = 0; i < blocklen; ++i) {
|
1097
|
+
const int v0 = kvalues_iq4nl[b_ptr[l].qs[k * ncols_interleaved * blocklen + j * blocklen + i] & 0x0F];
|
1098
|
+
const int v1 = kvalues_iq4nl[b_ptr[l].qs[k * ncols_interleaved * blocklen + j * blocklen + i] >> 4];
|
1099
|
+
sumi += ((v0 * a_ptr[l].qs[k * blocklen + i]) + (v1 * a_ptr[l].qs[k * blocklen + i + qk / 2]));
|
1100
|
+
}
|
1101
|
+
sumf[j] += sumi * GGML_FP16_TO_FP32(b_ptr[l].d[j]) * GGML_FP16_TO_FP32(a_ptr[l].d);
|
1102
|
+
}
|
1103
|
+
}
|
1104
|
+
}
|
1105
|
+
for (int j = 0; j < ncols_interleaved; j++) s[x * ncols_interleaved + j] = sumf[j];
|
1106
|
+
}
|
1107
|
+
}
|
1108
|
+
}
|
1109
|
+
|
1110
|
+
static void ggml_gemm_q4_0_4x4_q8_0(int n, float * GGML_RESTRICT s, size_t bs, const void * GGML_RESTRICT vx, const void * GGML_RESTRICT vy, int nr, int nc) {
|
1111
|
+
const int qk = QK8_0;
|
1112
|
+
const int nb = n / qk;
|
1113
|
+
const int ncols_interleaved = 4;
|
1114
|
+
const int blocklen = 4;
|
1115
|
+
|
1116
|
+
assert (n % qk == 0);
|
1117
|
+
assert (nr % 4 == 0);
|
1118
|
+
assert (nc % ncols_interleaved == 0);
|
1119
|
+
|
1120
|
+
UNUSED(s);
|
1121
|
+
UNUSED(bs);
|
1122
|
+
UNUSED(vx);
|
1123
|
+
UNUSED(vy);
|
1124
|
+
UNUSED(nr);
|
1125
|
+
UNUSED(nc);
|
1126
|
+
UNUSED(nb);
|
1127
|
+
UNUSED(ncols_interleaved);
|
1128
|
+
UNUSED(blocklen);
|
1129
|
+
|
1130
|
+
#if ! ((defined(_MSC_VER)) && ! defined(__clang__)) && defined(__aarch64__) && defined(__ARM_NEON)
|
1131
|
+
if (ggml_cpu_has_neon() && ggml_cpu_has_dotprod()) {
|
1132
|
+
const void * b_ptr = vx;
|
1133
|
+
const void * a_ptr = vy;
|
1134
|
+
float * res_ptr = s;
|
1135
|
+
size_t res_stride = bs * sizeof(float);
|
1136
|
+
|
1137
|
+
__asm__ __volatile__(
|
1138
|
+
"mov x10, %x[nr]\n"
|
1139
|
+
"mov x9, #0x88\n"
|
1140
|
+
"cmp x10, #0x10\n"
|
1141
|
+
"mul x9, %x[nb], x9\n"
|
1142
|
+
"blt 4f\n"
|
1143
|
+
"1:" // Row loop
|
1144
|
+
"add x28, %x[b_ptr], #0x8\n"
|
1145
|
+
"mov x27, %x[nc]\n"
|
1146
|
+
"add x26, %x[res_ptr], %x[res_stride], LSL #4\n"
|
1147
|
+
"2:" // Column loop
|
1148
|
+
"add x25, %x[a_ptr], #0x8\n"
|
1149
|
+
"movi v15.16b, #0x0\n"
|
1150
|
+
"movi v19.16b, #0x0\n"
|
1151
|
+
"mov x24, %x[nb]\n"
|
1152
|
+
"add x23, x25, x9\n"
|
1153
|
+
"movi v18.16b, #0x0\n"
|
1154
|
+
"movi v14.16b, #0x0\n"
|
1155
|
+
"add x22, x23, x9\n"
|
1156
|
+
"movi v11.16b, #0x0\n"
|
1157
|
+
"movi v13.16b, #0x0\n"
|
1158
|
+
"add x21, x22, x9\n"
|
1159
|
+
"movi v23.16b, #0x0\n"
|
1160
|
+
"movi v16.16b, #0x0\n"
|
1161
|
+
"movi v25.16b, #0x0\n"
|
1162
|
+
"movi v7.16b, #0x0\n"
|
1163
|
+
"movi v0.16b, #0x0\n"
|
1164
|
+
"movi v4.16b, #0x0\n"
|
1165
|
+
"movi v5.16b, #0x0\n"
|
1166
|
+
"movi v21.16b, #0x0\n"
|
1167
|
+
"movi v8.16b, #0x0\n"
|
1168
|
+
"movi v1.16b, #0x0\n"
|
1169
|
+
"3:" // Block loop
|
1170
|
+
"ldr q3, [x28, #0x0]\n"
|
1171
|
+
"ldr q31, [x25, #0x0]\n"
|
1172
|
+
"movi v28.16b, #0x4\n"
|
1173
|
+
"movi v10.4s, #0x0\n"
|
1174
|
+
"ldr q22, [x28, #0x10]\n"
|
1175
|
+
"ldr q6, [x25, #0x10]\n"
|
1176
|
+
"movi v29.4s, #0x0\n"
|
1177
|
+
"movi v9.4s, #0x0\n"
|
1178
|
+
"ldr q27, [x28, #0x20]\n"
|
1179
|
+
"ldr q30, [x28, #0x30]\n"
|
1180
|
+
"movi v20.4s, #0x0\n"
|
1181
|
+
"movi v24.16b, #0xf0\n"
|
1182
|
+
"ldr d2, [x25, #-0x8]\n"
|
1183
|
+
"ldr d26, [x23, #-0x8]\n"
|
1184
|
+
"sshl v12.16b, v3.16b, v28.16b\n"
|
1185
|
+
"sub x20, x28, #0x8\n"
|
1186
|
+
"ldr d17, [x20, #0x0]\n"
|
1187
|
+
"and v3.16b, v3.16b, v24.16b\n"
|
1188
|
+
"subs x24, x24, #0x1\n"
|
1189
|
+
"add x28, x28, #0x48\n"
|
1190
|
+
".inst 0x4f9fe18a // sdot v10.4s, v12.16b, v31.4b[0]\n"
|
1191
|
+
".inst 0x4fbfe19d // sdot v29.4s, v12.16b, v31.4b[1]\n"
|
1192
|
+
".inst 0x4f9fe989 // sdot v9.4s, v12.16b, v31.4b[2]\n"
|
1193
|
+
".inst 0x4fbfe994 // sdot v20.4s, v12.16b, v31.4b[3]\n"
|
1194
|
+
"sshl v31.16b, v22.16b, v28.16b\n"
|
1195
|
+
"and v22.16b, v22.16b, v24.16b\n"
|
1196
|
+
"fcvtl v17.4s, v17.4h\n"
|
1197
|
+
"fcvtl v2.4s, v2.4h\n"
|
1198
|
+
"fcvtl v26.4s, v26.4h\n"
|
1199
|
+
".inst 0x4f86e3ea // sdot v10.4s, v31.16b, v6.4b[0]\n"
|
1200
|
+
".inst 0x4fa6e3fd // sdot v29.4s, v31.16b, v6.4b[1]\n"
|
1201
|
+
".inst 0x4f86ebe9 // sdot v9.4s, v31.16b, v6.4b[2]\n"
|
1202
|
+
".inst 0x4fa6ebf4 // sdot v20.4s, v31.16b, v6.4b[3]\n"
|
1203
|
+
"sshl v6.16b, v27.16b, v28.16b\n"
|
1204
|
+
"sshl v28.16b, v30.16b, v28.16b\n"
|
1205
|
+
"and v27.16b, v27.16b, v24.16b\n"
|
1206
|
+
"and v30.16b, v30.16b, v24.16b\n"
|
1207
|
+
"ldr q24, [x25, #0x20]\n"
|
1208
|
+
".inst 0x4f98e0ca // sdot v10.4s, v6.16b, v24.4b[0]\n"
|
1209
|
+
".inst 0x4fb8e0dd // sdot v29.4s, v6.16b, v24.4b[1]\n"
|
1210
|
+
".inst 0x4f98e8c9 // sdot v9.4s, v6.16b, v24.4b[2]\n"
|
1211
|
+
".inst 0x4fb8e8d4 // sdot v20.4s, v6.16b, v24.4b[3]\n"
|
1212
|
+
"ldr q24, [x25, #0x30]\n"
|
1213
|
+
".inst 0x4f98e38a // sdot v10.4s, v28.16b, v24.4b[0]\n"
|
1214
|
+
".inst 0x4fb8e39d // sdot v29.4s, v28.16b, v24.4b[1]\n"
|
1215
|
+
".inst 0x4f98eb89 // sdot v9.4s, v28.16b, v24.4b[2]\n"
|
1216
|
+
".inst 0x4fb8eb94 // sdot v20.4s, v28.16b, v24.4b[3]\n"
|
1217
|
+
"ldr q24, [x25, #0x40]\n"
|
1218
|
+
".inst 0x4f98e06a // sdot v10.4s, v3.16b, v24.4b[0]\n"
|
1219
|
+
".inst 0x4fb8e07d // sdot v29.4s, v3.16b, v24.4b[1]\n"
|
1220
|
+
".inst 0x4f98e869 // sdot v9.4s, v3.16b, v24.4b[2]\n"
|
1221
|
+
".inst 0x4fb8e874 // sdot v20.4s, v3.16b, v24.4b[3]\n"
|
1222
|
+
"ldr q24, [x25, #0x50]\n"
|
1223
|
+
".inst 0x4f98e2ca // sdot v10.4s, v22.16b, v24.4b[0]\n"
|
1224
|
+
".inst 0x4fb8e2dd // sdot v29.4s, v22.16b, v24.4b[1]\n"
|
1225
|
+
".inst 0x4f98eac9 // sdot v9.4s, v22.16b, v24.4b[2]\n"
|
1226
|
+
".inst 0x4fb8ead4 // sdot v20.4s, v22.16b, v24.4b[3]\n"
|
1227
|
+
"ldr q24, [x25, #0x60]\n"
|
1228
|
+
".inst 0x4f98e36a // sdot v10.4s, v27.16b, v24.4b[0]\n"
|
1229
|
+
".inst 0x4fb8e37d // sdot v29.4s, v27.16b, v24.4b[1]\n"
|
1230
|
+
".inst 0x4f98eb69 // sdot v9.4s, v27.16b, v24.4b[2]\n"
|
1231
|
+
".inst 0x4fb8eb74 // sdot v20.4s, v27.16b, v24.4b[3]\n"
|
1232
|
+
"ldr q24, [x25, #0x70]\n"
|
1233
|
+
"add x25, x25, #0x88\n"
|
1234
|
+
".inst 0x4f98e3ca // sdot v10.4s, v30.16b, v24.4b[0]\n"
|
1235
|
+
".inst 0x4fb8e3dd // sdot v29.4s, v30.16b, v24.4b[1]\n"
|
1236
|
+
".inst 0x4f98ebc9 // sdot v9.4s, v30.16b, v24.4b[2]\n"
|
1237
|
+
".inst 0x4fb8ebd4 // sdot v20.4s, v30.16b, v24.4b[3]\n"
|
1238
|
+
"fmul v24.4s, v17.4s, v2.s[0]\n"
|
1239
|
+
"scvtf v10.4s, v10.4s, #0x4\n"
|
1240
|
+
"scvtf v29.4s, v29.4s, #0x4\n"
|
1241
|
+
"scvtf v9.4s, v9.4s, #0x4\n"
|
1242
|
+
"scvtf v20.4s, v20.4s, #0x4\n"
|
1243
|
+
"fmla v15.4s, v10.4s, v24.4s\n"
|
1244
|
+
"ldr q24, [x23, #0x0]\n"
|
1245
|
+
"fmul v10.4s, v17.4s, v2.s[1]\n"
|
1246
|
+
"fmla v19.4s, v29.4s, v10.4s\n"
|
1247
|
+
"ldr q10, [x23, #0x10]\n"
|
1248
|
+
"fmul v29.4s, v17.4s, v2.s[2]\n"
|
1249
|
+
"fmul v2.4s, v17.4s, v2.s[3]\n"
|
1250
|
+
"fmla v18.4s, v9.4s, v29.4s\n"
|
1251
|
+
"movi v9.4s, #0x0\n"
|
1252
|
+
"movi v29.4s, #0x0\n"
|
1253
|
+
".inst 0x4f98e189 // sdot v9.4s, v12.16b, v24.4b[0]\n"
|
1254
|
+
".inst 0x4fb8e19d // sdot v29.4s, v12.16b, v24.4b[1]\n"
|
1255
|
+
"fmla v14.4s, v20.4s, v2.4s\n"
|
1256
|
+
"movi v20.4s, #0x0\n"
|
1257
|
+
"movi v2.4s, #0x0\n"
|
1258
|
+
".inst 0x4f98e994 // sdot v20.4s, v12.16b, v24.4b[2]\n"
|
1259
|
+
".inst 0x4fb8e982 // sdot v2.4s, v12.16b, v24.4b[3]\n"
|
1260
|
+
"ldr q24, [x23, #0x20]\n"
|
1261
|
+
".inst 0x4f8ae3e9 // sdot v9.4s, v31.16b, v10.4b[0]\n"
|
1262
|
+
".inst 0x4faae3fd // sdot v29.4s, v31.16b, v10.4b[1]\n"
|
1263
|
+
".inst 0x4f8aebf4 // sdot v20.4s, v31.16b, v10.4b[2]\n"
|
1264
|
+
".inst 0x4faaebe2 // sdot v2.4s, v31.16b, v10.4b[3]\n"
|
1265
|
+
"ldr q10, [x23, #0x30]\n"
|
1266
|
+
".inst 0x4f98e0c9 // sdot v9.4s, v6.16b, v24.4b[0]\n"
|
1267
|
+
".inst 0x4fb8e0dd // sdot v29.4s, v6.16b, v24.4b[1]\n"
|
1268
|
+
".inst 0x4f98e8d4 // sdot v20.4s, v6.16b, v24.4b[2]\n"
|
1269
|
+
".inst 0x4fb8e8c2 // sdot v2.4s, v6.16b, v24.4b[3]\n"
|
1270
|
+
"ldr q24, [x23, #0x40]\n"
|
1271
|
+
".inst 0x4f8ae389 // sdot v9.4s, v28.16b, v10.4b[0]\n"
|
1272
|
+
".inst 0x4faae39d // sdot v29.4s, v28.16b, v10.4b[1]\n"
|
1273
|
+
".inst 0x4f8aeb94 // sdot v20.4s, v28.16b, v10.4b[2]\n"
|
1274
|
+
".inst 0x4faaeb82 // sdot v2.4s, v28.16b, v10.4b[3]\n"
|
1275
|
+
"ldr q10, [x23, #0x50]\n"
|
1276
|
+
".inst 0x4f98e069 // sdot v9.4s, v3.16b, v24.4b[0]\n"
|
1277
|
+
".inst 0x4fb8e07d // sdot v29.4s, v3.16b, v24.4b[1]\n"
|
1278
|
+
".inst 0x4f98e874 // sdot v20.4s, v3.16b, v24.4b[2]\n"
|
1279
|
+
".inst 0x4fb8e862 // sdot v2.4s, v3.16b, v24.4b[3]\n"
|
1280
|
+
"ldr q24, [x23, #0x60]\n"
|
1281
|
+
".inst 0x4f8ae2c9 // sdot v9.4s, v22.16b, v10.4b[0]\n"
|
1282
|
+
".inst 0x4faae2dd // sdot v29.4s, v22.16b, v10.4b[1]\n"
|
1283
|
+
".inst 0x4f8aead4 // sdot v20.4s, v22.16b, v10.4b[2]\n"
|
1284
|
+
".inst 0x4faaeac2 // sdot v2.4s, v22.16b, v10.4b[3]\n"
|
1285
|
+
"ldr q10, [x23, #0x70]\n"
|
1286
|
+
"add x23, x23, #0x88\n"
|
1287
|
+
".inst 0x4f98e369 // sdot v9.4s, v27.16b, v24.4b[0]\n"
|
1288
|
+
".inst 0x4fb8e37d // sdot v29.4s, v27.16b, v24.4b[1]\n"
|
1289
|
+
".inst 0x4f98eb74 // sdot v20.4s, v27.16b, v24.4b[2]\n"
|
1290
|
+
".inst 0x4fb8eb62 // sdot v2.4s, v27.16b, v24.4b[3]\n"
|
1291
|
+
"ldr q24, [x22, #0x0]\n"
|
1292
|
+
".inst 0x4f8ae3c9 // sdot v9.4s, v30.16b, v10.4b[0]\n"
|
1293
|
+
".inst 0x4faae3dd // sdot v29.4s, v30.16b, v10.4b[1]\n"
|
1294
|
+
".inst 0x4f8aebd4 // sdot v20.4s, v30.16b, v10.4b[2]\n"
|
1295
|
+
".inst 0x4faaebc2 // sdot v2.4s, v30.16b, v10.4b[3]\n"
|
1296
|
+
"fmul v10.4s, v17.4s, v26.s[0]\n"
|
1297
|
+
"scvtf v9.4s, v9.4s, #0x4\n"
|
1298
|
+
"scvtf v29.4s, v29.4s, #0x4\n"
|
1299
|
+
"scvtf v20.4s, v20.4s, #0x4\n"
|
1300
|
+
"scvtf v2.4s, v2.4s, #0x4\n"
|
1301
|
+
"fmla v11.4s, v9.4s, v10.4s\n"
|
1302
|
+
"ldr q9, [x22, #0x10]\n"
|
1303
|
+
"fmul v10.4s, v17.4s, v26.s[1]\n"
|
1304
|
+
"fmla v13.4s, v29.4s, v10.4s\n"
|
1305
|
+
"ldr d29, [x22, #-0x8]\n"
|
1306
|
+
"fmul v10.4s, v17.4s, v26.s[2]\n"
|
1307
|
+
"fmul v26.4s, v17.4s, v26.s[3]\n"
|
1308
|
+
"fcvtl v29.4s, v29.4h\n"
|
1309
|
+
"fmla v23.4s, v20.4s, v10.4s\n"
|
1310
|
+
"movi v20.4s, #0x0\n"
|
1311
|
+
"movi v10.4s, #0x0\n"
|
1312
|
+
"fmla v16.4s, v2.4s, v26.4s\n"
|
1313
|
+
"movi v26.4s, #0x0\n"
|
1314
|
+
"movi v2.4s, #0x0\n"
|
1315
|
+
".inst 0x4f98e194 // sdot v20.4s, v12.16b, v24.4b[0]\n"
|
1316
|
+
".inst 0x4fb8e18a // sdot v10.4s, v12.16b, v24.4b[1]\n"
|
1317
|
+
".inst 0x4f98e99a // sdot v26.4s, v12.16b, v24.4b[2]\n"
|
1318
|
+
".inst 0x4fb8e982 // sdot v2.4s, v12.16b, v24.4b[3]\n"
|
1319
|
+
"ldr q24, [x22, #0x20]\n"
|
1320
|
+
".inst 0x4f89e3f4 // sdot v20.4s, v31.16b, v9.4b[0]\n"
|
1321
|
+
".inst 0x4fa9e3ea // sdot v10.4s, v31.16b, v9.4b[1]\n"
|
1322
|
+
".inst 0x4f89ebfa // sdot v26.4s, v31.16b, v9.4b[2]\n"
|
1323
|
+
".inst 0x4fa9ebe2 // sdot v2.4s, v31.16b, v9.4b[3]\n"
|
1324
|
+
"ldr q9, [x22, #0x30]\n"
|
1325
|
+
".inst 0x4f98e0d4 // sdot v20.4s, v6.16b, v24.4b[0]\n"
|
1326
|
+
".inst 0x4fb8e0ca // sdot v10.4s, v6.16b, v24.4b[1]\n"
|
1327
|
+
".inst 0x4f98e8da // sdot v26.4s, v6.16b, v24.4b[2]\n"
|
1328
|
+
".inst 0x4fb8e8c2 // sdot v2.4s, v6.16b, v24.4b[3]\n"
|
1329
|
+
"ldr q24, [x22, #0x40]\n"
|
1330
|
+
".inst 0x4f89e394 // sdot v20.4s, v28.16b, v9.4b[0]\n"
|
1331
|
+
".inst 0x4fa9e38a // sdot v10.4s, v28.16b, v9.4b[1]\n"
|
1332
|
+
".inst 0x4f89eb9a // sdot v26.4s, v28.16b, v9.4b[2]\n"
|
1333
|
+
".inst 0x4fa9eb82 // sdot v2.4s, v28.16b, v9.4b[3]\n"
|
1334
|
+
"ldr q9, [x22, #0x50]\n"
|
1335
|
+
".inst 0x4f98e074 // sdot v20.4s, v3.16b, v24.4b[0]\n"
|
1336
|
+
".inst 0x4fb8e06a // sdot v10.4s, v3.16b, v24.4b[1]\n"
|
1337
|
+
".inst 0x4f98e87a // sdot v26.4s, v3.16b, v24.4b[2]\n"
|
1338
|
+
".inst 0x4fb8e862 // sdot v2.4s, v3.16b, v24.4b[3]\n"
|
1339
|
+
"ldr q24, [x22, #0x60]\n"
|
1340
|
+
".inst 0x4f89e2d4 // sdot v20.4s, v22.16b, v9.4b[0]\n"
|
1341
|
+
".inst 0x4fa9e2ca // sdot v10.4s, v22.16b, v9.4b[1]\n"
|
1342
|
+
".inst 0x4f89eada // sdot v26.4s, v22.16b, v9.4b[2]\n"
|
1343
|
+
".inst 0x4fa9eac2 // sdot v2.4s, v22.16b, v9.4b[3]\n"
|
1344
|
+
"ldr q9, [x22, #0x70]\n"
|
1345
|
+
"add x22, x22, #0x88\n"
|
1346
|
+
".inst 0x4f98e374 // sdot v20.4s, v27.16b, v24.4b[0]\n"
|
1347
|
+
".inst 0x4fb8e36a // sdot v10.4s, v27.16b, v24.4b[1]\n"
|
1348
|
+
".inst 0x4f98eb7a // sdot v26.4s, v27.16b, v24.4b[2]\n"
|
1349
|
+
".inst 0x4fb8eb62 // sdot v2.4s, v27.16b, v24.4b[3]\n"
|
1350
|
+
"ldr q24, [x21, #0x0]\n"
|
1351
|
+
".inst 0x4f89e3d4 // sdot v20.4s, v30.16b, v9.4b[0]\n"
|
1352
|
+
".inst 0x4fa9e3ca // sdot v10.4s, v30.16b, v9.4b[1]\n"
|
1353
|
+
".inst 0x4f89ebda // sdot v26.4s, v30.16b, v9.4b[2]\n"
|
1354
|
+
".inst 0x4fa9ebc2 // sdot v2.4s, v30.16b, v9.4b[3]\n"
|
1355
|
+
"fmul v9.4s, v17.4s, v29.s[0]\n"
|
1356
|
+
"scvtf v20.4s, v20.4s, #0x4\n"
|
1357
|
+
"scvtf v10.4s, v10.4s, #0x4\n"
|
1358
|
+
"scvtf v26.4s, v26.4s, #0x4\n"
|
1359
|
+
"scvtf v2.4s, v2.4s, #0x4\n"
|
1360
|
+
"fmla v25.4s, v20.4s, v9.4s\n"
|
1361
|
+
"ldr q9, [x21, #0x10]\n"
|
1362
|
+
"fmul v20.4s, v17.4s, v29.s[1]\n"
|
1363
|
+
"fmla v7.4s, v10.4s, v20.4s\n"
|
1364
|
+
"ldr d20, [x21, #-0x8]\n"
|
1365
|
+
"fmul v10.4s, v17.4s, v29.s[2]\n"
|
1366
|
+
"fmul v29.4s, v17.4s, v29.s[3]\n"
|
1367
|
+
"fcvtl v20.4s, v20.4h\n"
|
1368
|
+
"fmla v0.4s, v26.4s, v10.4s\n"
|
1369
|
+
"movi v26.4s, #0x0\n"
|
1370
|
+
"movi v10.4s, #0x0\n"
|
1371
|
+
"fmla v4.4s, v2.4s, v29.4s\n"
|
1372
|
+
"movi v2.4s, #0x0\n"
|
1373
|
+
"movi v29.4s, #0x0\n"
|
1374
|
+
".inst 0x4f98e19a // sdot v26.4s, v12.16b, v24.4b[0]\n"
|
1375
|
+
".inst 0x4fb8e18a // sdot v10.4s, v12.16b, v24.4b[1]\n"
|
1376
|
+
".inst 0x4f98e982 // sdot v2.4s, v12.16b, v24.4b[2]\n"
|
1377
|
+
".inst 0x4fb8e99d // sdot v29.4s, v12.16b, v24.4b[3]\n"
|
1378
|
+
"ldr q12, [x21, #0x20]\n"
|
1379
|
+
"fmul v24.4s, v17.4s, v20.s[0]\n"
|
1380
|
+
".inst 0x4f89e3fa // sdot v26.4s, v31.16b, v9.4b[0]\n"
|
1381
|
+
".inst 0x4fa9e3ea // sdot v10.4s, v31.16b, v9.4b[1]\n"
|
1382
|
+
".inst 0x4f89ebe2 // sdot v2.4s, v31.16b, v9.4b[2]\n"
|
1383
|
+
".inst 0x4fa9ebfd // sdot v29.4s, v31.16b, v9.4b[3]\n"
|
1384
|
+
"ldr q9, [x21, #0x30]\n"
|
1385
|
+
"fmul v31.4s, v17.4s, v20.s[1]\n"
|
1386
|
+
".inst 0x4f8ce0da // sdot v26.4s, v6.16b, v12.4b[0]\n"
|
1387
|
+
".inst 0x4face0ca // sdot v10.4s, v6.16b, v12.4b[1]\n"
|
1388
|
+
".inst 0x4f8ce8c2 // sdot v2.4s, v6.16b, v12.4b[2]\n"
|
1389
|
+
".inst 0x4face8dd // sdot v29.4s, v6.16b, v12.4b[3]\n"
|
1390
|
+
"ldr q12, [x21, #0x40]\n"
|
1391
|
+
"fmul v6.4s, v17.4s, v20.s[2]\n"
|
1392
|
+
"fmul v20.4s, v17.4s, v20.s[3]\n"
|
1393
|
+
".inst 0x4f89e39a // sdot v26.4s, v28.16b, v9.4b[0]\n"
|
1394
|
+
".inst 0x4fa9e38a // sdot v10.4s, v28.16b, v9.4b[1]\n"
|
1395
|
+
".inst 0x4f89eb82 // sdot v2.4s, v28.16b, v9.4b[2]\n"
|
1396
|
+
".inst 0x4fa9eb9d // sdot v29.4s, v28.16b, v9.4b[3]\n"
|
1397
|
+
"ldr q9, [x21, #0x50]\n"
|
1398
|
+
".inst 0x4f8ce07a // sdot v26.4s, v3.16b, v12.4b[0]\n"
|
1399
|
+
".inst 0x4face06a // sdot v10.4s, v3.16b, v12.4b[1]\n"
|
1400
|
+
".inst 0x4f8ce862 // sdot v2.4s, v3.16b, v12.4b[2]\n"
|
1401
|
+
".inst 0x4face87d // sdot v29.4s, v3.16b, v12.4b[3]\n"
|
1402
|
+
"ldr q12, [x21, #0x60]\n"
|
1403
|
+
".inst 0x4f89e2da // sdot v26.4s, v22.16b, v9.4b[0]\n"
|
1404
|
+
".inst 0x4fa9e2ca // sdot v10.4s, v22.16b, v9.4b[1]\n"
|
1405
|
+
".inst 0x4f89eac2 // sdot v2.4s, v22.16b, v9.4b[2]\n"
|
1406
|
+
".inst 0x4fa9eadd // sdot v29.4s, v22.16b, v9.4b[3]\n"
|
1407
|
+
"ldr q17, [x21, #0x70]\n"
|
1408
|
+
"add x21, x21, #0x88\n"
|
1409
|
+
".inst 0x4f8ce37a // sdot v26.4s, v27.16b, v12.4b[0]\n"
|
1410
|
+
".inst 0x4face36a // sdot v10.4s, v27.16b, v12.4b[1]\n"
|
1411
|
+
".inst 0x4f8ceb62 // sdot v2.4s, v27.16b, v12.4b[2]\n"
|
1412
|
+
".inst 0x4faceb7d // sdot v29.4s, v27.16b, v12.4b[3]\n"
|
1413
|
+
".inst 0x4f91e3da // sdot v26.4s, v30.16b, v17.4b[0]\n"
|
1414
|
+
".inst 0x4fb1e3ca // sdot v10.4s, v30.16b, v17.4b[1]\n"
|
1415
|
+
".inst 0x4f91ebc2 // sdot v2.4s, v30.16b, v17.4b[2]\n"
|
1416
|
+
".inst 0x4fb1ebdd // sdot v29.4s, v30.16b, v17.4b[3]\n"
|
1417
|
+
"scvtf v26.4s, v26.4s, #0x4\n"
|
1418
|
+
"scvtf v10.4s, v10.4s, #0x4\n"
|
1419
|
+
"fmla v5.4s, v26.4s, v24.4s\n"
|
1420
|
+
"scvtf v2.4s, v2.4s, #0x4\n"
|
1421
|
+
"scvtf v29.4s, v29.4s, #0x4\n"
|
1422
|
+
"fmla v21.4s, v10.4s, v31.4s\n"
|
1423
|
+
"fmla v8.4s, v2.4s, v6.4s\n"
|
1424
|
+
"fmla v1.4s, v29.4s, v20.4s\n"
|
1425
|
+
"bgt 3b\n"
|
1426
|
+
"mov x20, %x[res_ptr]\n"
|
1427
|
+
"subs x27, x27, #0x4\n"
|
1428
|
+
"add %x[res_ptr], %x[res_ptr], #0x10\n"
|
1429
|
+
"str q15, [x20, #0x0]\n"
|
1430
|
+
"add x20, x20, %x[res_stride]\n"
|
1431
|
+
"str q19, [x20, #0x0]\n"
|
1432
|
+
"add x20, x20, %x[res_stride]\n"
|
1433
|
+
"str q18, [x20, #0x0]\n"
|
1434
|
+
"add x20, x20, %x[res_stride]\n"
|
1435
|
+
"str q14, [x20, #0x0]\n"
|
1436
|
+
"add x20, x20, %x[res_stride]\n"
|
1437
|
+
"str q11, [x20, #0x0]\n"
|
1438
|
+
"add x20, x20, %x[res_stride]\n"
|
1439
|
+
"str q13, [x20, #0x0]\n"
|
1440
|
+
"add x20, x20, %x[res_stride]\n"
|
1441
|
+
"str q23, [x20, #0x0]\n"
|
1442
|
+
"add x20, x20, %x[res_stride]\n"
|
1443
|
+
"str q16, [x20, #0x0]\n"
|
1444
|
+
"add x20, x20, %x[res_stride]\n"
|
1445
|
+
"str q25, [x20, #0x0]\n"
|
1446
|
+
"add x20, x20, %x[res_stride]\n"
|
1447
|
+
"str q7, [x20, #0x0]\n"
|
1448
|
+
"add x20, x20, %x[res_stride]\n"
|
1449
|
+
"str q0, [x20, #0x0]\n"
|
1450
|
+
"add x20, x20, %x[res_stride]\n"
|
1451
|
+
"str q4, [x20, #0x0]\n"
|
1452
|
+
"add x20, x20, %x[res_stride]\n"
|
1453
|
+
"str q5, [x20, #0x0]\n"
|
1454
|
+
"add x20, x20, %x[res_stride]\n"
|
1455
|
+
"str q21, [x20, #0x0]\n"
|
1456
|
+
"add x20, x20, %x[res_stride]\n"
|
1457
|
+
"str q8, [x20, #0x0]\n"
|
1458
|
+
"add x20, x20, %x[res_stride]\n"
|
1459
|
+
"str q1, [x20, #0x0]\n"
|
1460
|
+
"bne 2b\n"
|
1461
|
+
"mov x20, #0x4\n"
|
1462
|
+
"sub x10, x10, #0x10\n"
|
1463
|
+
"cmp x10, #0x10\n"
|
1464
|
+
"mov %x[res_ptr], x26\n"
|
1465
|
+
"madd %x[a_ptr], x20, x9, %x[a_ptr]\n"
|
1466
|
+
"bge 1b\n"
|
1467
|
+
"4:" // Row loop skip
|
1468
|
+
"cbz x10, 9f\n"
|
1469
|
+
"5:" // Row tail: Row loop
|
1470
|
+
"add x24, %x[b_ptr], #0x8\n"
|
1471
|
+
"mov x23, %x[nc]\n"
|
1472
|
+
"add x22, %x[res_ptr], %x[res_stride], LSL #2\n"
|
1473
|
+
"6:" // Row tail: Column loop
|
1474
|
+
"movi v15.16b, #0x0\n"
|
1475
|
+
"movi v19.16b, #0x0\n"
|
1476
|
+
"add x25, %x[a_ptr], #0x8\n"
|
1477
|
+
"mov x21, %x[nb]\n"
|
1478
|
+
"movi v18.16b, #0x0\n"
|
1479
|
+
"movi v14.16b, #0x0\n"
|
1480
|
+
"7:" // Row tail: Block loop
|
1481
|
+
"ldr q7, [x24, #0x0]\n"
|
1482
|
+
"ldr q5, [x25, #0x0]\n"
|
1483
|
+
"movi v9.16b, #0x4\n"
|
1484
|
+
"movi v4.4s, #0x0\n"
|
1485
|
+
"ldr q3, [x24, #0x10]\n"
|
1486
|
+
"ldr q2, [x25, #0x10]\n"
|
1487
|
+
"movi v1.4s, #0x0\n"
|
1488
|
+
"movi v0.4s, #0x0\n"
|
1489
|
+
"ldr q13, [x24, #0x20]\n"
|
1490
|
+
"ldr q31, [x25, #0x20]\n"
|
1491
|
+
"movi v30.4s, #0x0\n"
|
1492
|
+
"movi v29.16b, #0xf0\n"
|
1493
|
+
"ldr q28, [x24, #0x30]\n"
|
1494
|
+
"ldr q27, [x25, #0x30]\n"
|
1495
|
+
"sshl v20.16b, v7.16b, v9.16b\n"
|
1496
|
+
"sub x20, x24, #0x8\n"
|
1497
|
+
"ldr q26, [x25, #0x40]\n"
|
1498
|
+
"ldr q25, [x25, #0x50]\n"
|
1499
|
+
"sshl v17.16b, v3.16b, v9.16b\n"
|
1500
|
+
"and v7.16b, v7.16b, v29.16b\n"
|
1501
|
+
"ldr q24, [x25, #0x60]\n"
|
1502
|
+
"ldr q16, [x25, #0x70]\n"
|
1503
|
+
"sshl v22.16b, v13.16b, v9.16b\n"
|
1504
|
+
"and v3.16b, v3.16b, v29.16b\n"
|
1505
|
+
"ldr d21, [x20, #0x0]\n"
|
1506
|
+
"ldr d12, [x25, #-0x8]\n"
|
1507
|
+
".inst 0x4f85e284 // sdot v4.4s, v20.16b, v5.4b[0]\n"
|
1508
|
+
".inst 0x4fa5e281 // sdot v1.4s, v20.16b, v5.4b[1]\n"
|
1509
|
+
".inst 0x4f85ea80 // sdot v0.4s, v20.16b, v5.4b[2]\n"
|
1510
|
+
".inst 0x4fa5ea9e // sdot v30.4s, v20.16b, v5.4b[3]\n"
|
1511
|
+
"sshl v9.16b, v28.16b, v9.16b\n"
|
1512
|
+
"subs x21, x21, #0x1\n"
|
1513
|
+
"and v13.16b, v13.16b, v29.16b\n"
|
1514
|
+
"and v28.16b, v28.16b, v29.16b\n"
|
1515
|
+
"add x25, x25, #0x88\n"
|
1516
|
+
"add x24, x24, #0x48\n"
|
1517
|
+
"fcvtl v21.4s, v21.4h\n"
|
1518
|
+
"fcvtl v12.4s, v12.4h\n"
|
1519
|
+
".inst 0x4f82e224 // sdot v4.4s, v17.16b, v2.4b[0]\n"
|
1520
|
+
".inst 0x4fa2e221 // sdot v1.4s, v17.16b, v2.4b[1]\n"
|
1521
|
+
".inst 0x4f82ea20 // sdot v0.4s, v17.16b, v2.4b[2]\n"
|
1522
|
+
".inst 0x4fa2ea3e // sdot v30.4s, v17.16b, v2.4b[3]\n"
|
1523
|
+
"fmul v11.4s, v21.4s, v12.s[0]\n"
|
1524
|
+
"fmul v23.4s, v21.4s, v12.s[1]\n"
|
1525
|
+
"fmul v17.4s, v21.4s, v12.s[2]\n"
|
1526
|
+
".inst 0x4f9fe2c4 // sdot v4.4s, v22.16b, v31.4b[0]\n"
|
1527
|
+
"fmul v6.4s, v21.4s, v12.s[3]\n"
|
1528
|
+
".inst 0x4fbfe2c1 // sdot v1.4s, v22.16b, v31.4b[1]\n"
|
1529
|
+
".inst 0x4f9feac0 // sdot v0.4s, v22.16b, v31.4b[2]\n"
|
1530
|
+
".inst 0x4fbfeade // sdot v30.4s, v22.16b, v31.4b[3]\n"
|
1531
|
+
".inst 0x4f9be124 // sdot v4.4s, v9.16b, v27.4b[0]\n"
|
1532
|
+
".inst 0x4fbbe121 // sdot v1.4s, v9.16b, v27.4b[1]\n"
|
1533
|
+
".inst 0x4f9be920 // sdot v0.4s, v9.16b, v27.4b[2]\n"
|
1534
|
+
".inst 0x4fbbe93e // sdot v30.4s, v9.16b, v27.4b[3]\n"
|
1535
|
+
".inst 0x4f9ae0e4 // sdot v4.4s, v7.16b, v26.4b[0]\n"
|
1536
|
+
".inst 0x4fbae0e1 // sdot v1.4s, v7.16b, v26.4b[1]\n"
|
1537
|
+
".inst 0x4f9ae8e0 // sdot v0.4s, v7.16b, v26.4b[2]\n"
|
1538
|
+
".inst 0x4fbae8fe // sdot v30.4s, v7.16b, v26.4b[3]\n"
|
1539
|
+
".inst 0x4f99e064 // sdot v4.4s, v3.16b, v25.4b[0]\n"
|
1540
|
+
".inst 0x4fb9e061 // sdot v1.4s, v3.16b, v25.4b[1]\n"
|
1541
|
+
".inst 0x4f99e860 // sdot v0.4s, v3.16b, v25.4b[2]\n"
|
1542
|
+
".inst 0x4fb9e87e // sdot v30.4s, v3.16b, v25.4b[3]\n"
|
1543
|
+
".inst 0x4f98e1a4 // sdot v4.4s, v13.16b, v24.4b[0]\n"
|
1544
|
+
".inst 0x4fb8e1a1 // sdot v1.4s, v13.16b, v24.4b[1]\n"
|
1545
|
+
".inst 0x4f98e9a0 // sdot v0.4s, v13.16b, v24.4b[2]\n"
|
1546
|
+
".inst 0x4fb8e9be // sdot v30.4s, v13.16b, v24.4b[3]\n"
|
1547
|
+
".inst 0x4f90e384 // sdot v4.4s, v28.16b, v16.4b[0]\n"
|
1548
|
+
".inst 0x4fb0e381 // sdot v1.4s, v28.16b, v16.4b[1]\n"
|
1549
|
+
".inst 0x4f90eb80 // sdot v0.4s, v28.16b, v16.4b[2]\n"
|
1550
|
+
".inst 0x4fb0eb9e // sdot v30.4s, v28.16b, v16.4b[3]\n"
|
1551
|
+
"scvtf v4.4s, v4.4s, #0x4\n"
|
1552
|
+
"scvtf v1.4s, v1.4s, #0x4\n"
|
1553
|
+
"scvtf v0.4s, v0.4s, #0x4\n"
|
1554
|
+
"fmla v15.4s, v4.4s, v11.4s\n"
|
1555
|
+
"scvtf v30.4s, v30.4s, #0x4\n"
|
1556
|
+
"fmla v19.4s, v1.4s, v23.4s\n"
|
1557
|
+
"fmla v18.4s, v0.4s, v17.4s\n"
|
1558
|
+
"fmla v14.4s, v30.4s, v6.4s\n"
|
1559
|
+
"bgt 7b\n"
|
1560
|
+
"mov x20, %x[res_ptr]\n"
|
1561
|
+
"cmp x10, #0x1\n"
|
1562
|
+
"str q15, [x20, #0x0]\n"
|
1563
|
+
"add x20, x20, %x[res_stride]\n"
|
1564
|
+
"ble 8f\n"
|
1565
|
+
"cmp x10, #0x2\n"
|
1566
|
+
"str q19, [x20, #0x0]\n"
|
1567
|
+
"add x20, x20, %x[res_stride]\n"
|
1568
|
+
"ble 8f\n"
|
1569
|
+
"cmp x10, #0x3\n"
|
1570
|
+
"str q18, [x20, #0x0]\n"
|
1571
|
+
"add x20, x20, %x[res_stride]\n"
|
1572
|
+
"ble 8f\n"
|
1573
|
+
"str q14, [x20, #0x0]\n"
|
1574
|
+
"8:" // Row tail: Accumulator store skip
|
1575
|
+
"subs x23, x23, #0x4\n"
|
1576
|
+
"add %x[res_ptr], %x[res_ptr], #0x10\n"
|
1577
|
+
"bne 6b\n"
|
1578
|
+
"subs x10, x10, #0x4\n"
|
1579
|
+
"add %x[a_ptr], %x[a_ptr], x9\n"
|
1580
|
+
"mov %x[res_ptr], x22\n"
|
1581
|
+
"bgt 5b\n"
|
1582
|
+
"9:" // Row tail: Row loop skip
|
1583
|
+
: [a_ptr] "+&r" (a_ptr), [res_ptr] "+&r" (res_ptr)
|
1584
|
+
: [b_ptr] "r" (b_ptr), [nr] "r" (nr), [nb] "r" (nb), [res_stride] "r" (res_stride), [nc] "r" (nc)
|
1585
|
+
: "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15", "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23", "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31", "x9", "x10", "x20", "x21", "x22", "x23", "x24", "x25", "x26", "x27", "x28"
|
1586
|
+
);
|
1587
|
+
return;
|
1588
|
+
}
|
1589
|
+
#endif // #if ! ((defined(_MSC_VER)) && ! defined(__clang__)) && defined(__aarch64__) && defined(__ARM_NEON)
|
1590
|
+
{
|
1591
|
+
float sumf[4][4];
|
1592
|
+
int sumi;
|
1593
|
+
|
1594
|
+
for (int y = 0; y < nr / 4; y++) {
|
1595
|
+
const block_q8_0x4 * a_ptr = (const block_q8_0x4 *) vy + (y * nb);
|
1596
|
+
for (int x = 0; x < nc / ncols_interleaved; x++) {
|
1597
|
+
const block_q4_0x4 * b_ptr = (const block_q4_0x4 *) vx + (x * nb);
|
1598
|
+
for (int m = 0; m < 4; m++) {
|
1599
|
+
for (int j = 0; j < ncols_interleaved; j++) sumf[m][j] = 0.0;
|
1600
|
+
}
|
1601
|
+
for (int l = 0; l < nb; l++) {
|
1602
|
+
for (int k = 0; k < (qk / (2 * blocklen)); k++) {
|
1603
|
+
for (int m = 0; m < 4; m++) {
|
1604
|
+
for (int j = 0; j < ncols_interleaved; j++) {
|
1605
|
+
sumi = 0;
|
1606
|
+
for (int i = 0; i < blocklen; ++i) {
|
1607
|
+
const int v0 = (int8_t) (b_ptr[l].qs[k * ncols_interleaved * blocklen + j * blocklen + i] << 4);
|
1608
|
+
const int v1 = (int8_t) (b_ptr[l].qs[k * ncols_interleaved * blocklen + j * blocklen + i] & 0xF0);
|
1609
|
+
sumi += ((v0 * a_ptr[l].qs[k * 4 * blocklen + m * blocklen + i]) +
|
1610
|
+
(v1 * a_ptr[l].qs[k * 4 * blocklen + m * blocklen + i + qk / 2 * 4])) >> 4;
|
1611
|
+
}
|
1612
|
+
sumf[m][j] += sumi * GGML_FP16_TO_FP32(b_ptr[l].d[j]) * GGML_FP16_TO_FP32(a_ptr[l].d[m]);
|
1613
|
+
}
|
1614
|
+
}
|
1615
|
+
}
|
1616
|
+
}
|
1617
|
+
for (int m = 0; m < 4; m++) {
|
1618
|
+
for (int j = 0; j < ncols_interleaved; j++)
|
1619
|
+
s[(y * 4 + m) * bs + x * ncols_interleaved + j] = sumf[m][j];
|
1620
|
+
}
|
1621
|
+
}
|
1622
|
+
}
|
1623
|
+
}
|
1624
|
+
}
|
1625
|
+
|
1626
|
+
static void ggml_gemm_q4_0_4x8_q8_0(int n, float * GGML_RESTRICT s, size_t bs, const void * GGML_RESTRICT vx, const void * GGML_RESTRICT vy, int nr, int nc) {
|
1627
|
+
const int qk = QK8_0;
|
1628
|
+
const int nb = n / qk;
|
1629
|
+
const int ncols_interleaved = 4;
|
1630
|
+
const int blocklen = 8;
|
1631
|
+
|
1632
|
+
assert (n % qk == 0);
|
1633
|
+
assert (nr % 4 == 0);
|
1634
|
+
assert (nc % ncols_interleaved == 0);
|
1635
|
+
|
1636
|
+
UNUSED(s);
|
1637
|
+
UNUSED(bs);
|
1638
|
+
UNUSED(vx);
|
1639
|
+
UNUSED(vy);
|
1640
|
+
UNUSED(nr);
|
1641
|
+
UNUSED(nc);
|
1642
|
+
UNUSED(nb);
|
1643
|
+
UNUSED(ncols_interleaved);
|
1644
|
+
UNUSED(blocklen);
|
1645
|
+
|
1646
|
+
#if ! ((defined(_MSC_VER)) && ! defined(__clang__)) && defined(__aarch64__) && defined(__ARM_NEON) && defined(__ARM_FEATURE_MATMUL_INT8)
|
1647
|
+
if (ggml_cpu_has_neon() && ggml_cpu_has_matmul_int8()) {
|
1648
|
+
const void * b_ptr = vx;
|
1649
|
+
const void * a_ptr = vy;
|
1650
|
+
float * res_ptr = s;
|
1651
|
+
size_t res_stride = bs * sizeof(float);
|
1652
|
+
|
1653
|
+
__asm__ __volatile__(
|
1654
|
+
"mov x10, %x[nr]\n"
|
1655
|
+
"mov x9, #0x88\n"
|
1656
|
+
"cmp x10, #0x10\n"
|
1657
|
+
"mul x9, %x[nb], x9\n"
|
1658
|
+
"blt 4f\n"
|
1659
|
+
"1:" // Row loop
|
1660
|
+
"add x28, %x[b_ptr], #0x8\n"
|
1661
|
+
"mov x27, %x[nc]\n"
|
1662
|
+
"add x26, %x[res_ptr], %x[res_stride], LSL #4\n"
|
1663
|
+
"2:" // Column loop
|
1664
|
+
"add x25, %x[a_ptr], #0x8\n"
|
1665
|
+
"movi v2.16b, #0x0\n"
|
1666
|
+
"movi v10.16b, #0x0\n"
|
1667
|
+
"mov x24, %x[nb]\n"
|
1668
|
+
"add x23, x25, x9\n"
|
1669
|
+
"movi v12.16b, #0x0\n"
|
1670
|
+
"movi v28.16b, #0x0\n"
|
1671
|
+
"add x22, x23, x9\n"
|
1672
|
+
"movi v11.16b, #0x0\n"
|
1673
|
+
"movi v13.16b, #0x0\n"
|
1674
|
+
"add x21, x22, x9\n"
|
1675
|
+
"movi v22.16b, #0x0\n"
|
1676
|
+
"movi v23.16b, #0x0\n"
|
1677
|
+
"movi v25.16b, #0x0\n"
|
1678
|
+
"movi v5.16b, #0x0\n"
|
1679
|
+
"movi v7.16b, #0x0\n"
|
1680
|
+
"movi v4.16b, #0x0\n"
|
1681
|
+
"movi v6.16b, #0x0\n"
|
1682
|
+
"movi v30.16b, #0x0\n"
|
1683
|
+
"movi v24.16b, #0x0\n"
|
1684
|
+
"movi v14.16b, #0x0\n"
|
1685
|
+
"3:" // Block loop
|
1686
|
+
"ldr q21, [x28, #0x0]\n"
|
1687
|
+
"ldr q16, [x28, #0x10]\n"
|
1688
|
+
"movi v1.16b, #0x4\n"
|
1689
|
+
"movi v19.4s, #0x0\n"
|
1690
|
+
"ldr q27, [x25, #0x0]\n"
|
1691
|
+
"ldr q15, [x25, #0x10]\n"
|
1692
|
+
"movi v26.4s, #0x0\n"
|
1693
|
+
"movi v18.4s, #0x0\n"
|
1694
|
+
"ldr q29, [x28, #0x20]\n"
|
1695
|
+
"ldr q3, [x28, #0x30]\n"
|
1696
|
+
"movi v17.4s, #0x0\n"
|
1697
|
+
"movi v0.16b, #0xf0\n"
|
1698
|
+
"ldr d20, [x25, #-0x8]\n"
|
1699
|
+
"ldr d9, [x23, #-0x8]\n"
|
1700
|
+
"sshl v8.16b, v21.16b, v1.16b\n"
|
1701
|
+
"sshl v31.16b, v16.16b, v1.16b\n"
|
1702
|
+
"and v21.16b, v21.16b, v0.16b\n"
|
1703
|
+
"and v16.16b, v16.16b, v0.16b\n"
|
1704
|
+
"sub x20, x28, #0x8\n"
|
1705
|
+
"subs x24, x24, #0x1\n"
|
1706
|
+
"add x28, x28, #0x48\n"
|
1707
|
+
".inst 0x4e88a773 // smmla v19.4s, v27.16b, v8.16b\n"
|
1708
|
+
".inst 0x4e9fa77a // smmla v26.4s, v27.16b, v31.16b\n"
|
1709
|
+
"ldr q27, [x25, #0x20]\n"
|
1710
|
+
".inst 0x4e88a5f2 // smmla v18.4s, v15.16b, v8.16b\n"
|
1711
|
+
".inst 0x4e9fa5f1 // smmla v17.4s, v15.16b, v31.16b\n"
|
1712
|
+
"sshl v15.16b, v29.16b, v1.16b\n"
|
1713
|
+
"sshl v1.16b, v3.16b, v1.16b\n"
|
1714
|
+
"and v29.16b, v29.16b, v0.16b\n"
|
1715
|
+
"and v3.16b, v3.16b, v0.16b\n"
|
1716
|
+
"ldr q0, [x25, #0x30]\n"
|
1717
|
+
"fcvtl v20.4s, v20.4h\n"
|
1718
|
+
".inst 0x4e8fa773 // smmla v19.4s, v27.16b, v15.16b\n"
|
1719
|
+
"fcvtl v9.4s, v9.4h\n"
|
1720
|
+
".inst 0x4e81a77a // smmla v26.4s, v27.16b, v1.16b\n"
|
1721
|
+
"ldr q27, [x25, #0x40]\n"
|
1722
|
+
".inst 0x4e8fa412 // smmla v18.4s, v0.16b, v15.16b\n"
|
1723
|
+
".inst 0x4e81a411 // smmla v17.4s, v0.16b, v1.16b\n"
|
1724
|
+
"ldr q0, [x25, #0x50]\n"
|
1725
|
+
".inst 0x4e95a773 // smmla v19.4s, v27.16b, v21.16b\n"
|
1726
|
+
".inst 0x4e90a77a // smmla v26.4s, v27.16b, v16.16b\n"
|
1727
|
+
"ldr q27, [x25, #0x60]\n"
|
1728
|
+
".inst 0x4e95a412 // smmla v18.4s, v0.16b, v21.16b\n"
|
1729
|
+
".inst 0x4e90a411 // smmla v17.4s, v0.16b, v16.16b\n"
|
1730
|
+
"ldr q0, [x25, #0x70]\n"
|
1731
|
+
"add x25, x25, #0x88\n"
|
1732
|
+
".inst 0x4e9da773 // smmla v19.4s, v27.16b, v29.16b\n"
|
1733
|
+
".inst 0x4e83a77a // smmla v26.4s, v27.16b, v3.16b\n"
|
1734
|
+
"ldr d27, [x20, #0x0]\n"
|
1735
|
+
".inst 0x4e9da412 // smmla v18.4s, v0.16b, v29.16b\n"
|
1736
|
+
".inst 0x4e83a411 // smmla v17.4s, v0.16b, v3.16b\n"
|
1737
|
+
"fcvtl v27.4s, v27.4h\n"
|
1738
|
+
"uzp1 v0.2d, v19.2d, v26.2d\n"
|
1739
|
+
"uzp2 v26.2d, v19.2d, v26.2d\n"
|
1740
|
+
"fmul v19.4s, v27.4s, v20.s[0]\n"
|
1741
|
+
"scvtf v0.4s, v0.4s, #0x4\n"
|
1742
|
+
"scvtf v26.4s, v26.4s, #0x4\n"
|
1743
|
+
"fmla v2.4s, v0.4s, v19.4s\n"
|
1744
|
+
"ldr q19, [x23, #0x0]\n"
|
1745
|
+
"uzp1 v0.2d, v18.2d, v17.2d\n"
|
1746
|
+
"uzp2 v18.2d, v18.2d, v17.2d\n"
|
1747
|
+
"fmul v17.4s, v27.4s, v20.s[1]\n"
|
1748
|
+
"scvtf v0.4s, v0.4s, #0x4\n"
|
1749
|
+
"scvtf v18.4s, v18.4s, #0x4\n"
|
1750
|
+
"fmla v10.4s, v26.4s, v17.4s\n"
|
1751
|
+
"ldr q17, [x23, #0x10]\n"
|
1752
|
+
"fmul v26.4s, v27.4s, v20.s[2]\n"
|
1753
|
+
"fmul v20.4s, v27.4s, v20.s[3]\n"
|
1754
|
+
"fmla v12.4s, v0.4s, v26.4s\n"
|
1755
|
+
"ldr d0, [x22, #-0x8]\n"
|
1756
|
+
"ldr d26, [x21, #-0x8]\n"
|
1757
|
+
"fcvtl v0.4s, v0.4h\n"
|
1758
|
+
"fmla v28.4s, v18.4s, v20.4s\n"
|
1759
|
+
"movi v20.4s, #0x0\n"
|
1760
|
+
"movi v18.4s, #0x0\n"
|
1761
|
+
".inst 0x4e88a674 // smmla v20.4s, v19.16b, v8.16b\n"
|
1762
|
+
".inst 0x4e9fa672 // smmla v18.4s, v19.16b, v31.16b\n"
|
1763
|
+
"ldr q19, [x23, #0x20]\n"
|
1764
|
+
"fcvtl v26.4s, v26.4h\n"
|
1765
|
+
".inst 0x4e8fa674 // smmla v20.4s, v19.16b, v15.16b\n"
|
1766
|
+
".inst 0x4e81a672 // smmla v18.4s, v19.16b, v1.16b\n"
|
1767
|
+
"ldr q19, [x23, #0x40]\n"
|
1768
|
+
".inst 0x4e95a674 // smmla v20.4s, v19.16b, v21.16b\n"
|
1769
|
+
".inst 0x4e90a672 // smmla v18.4s, v19.16b, v16.16b\n"
|
1770
|
+
"ldr q19, [x23, #0x60]\n"
|
1771
|
+
".inst 0x4e9da674 // smmla v20.4s, v19.16b, v29.16b\n"
|
1772
|
+
".inst 0x4e83a672 // smmla v18.4s, v19.16b, v3.16b\n"
|
1773
|
+
"uzp1 v19.2d, v20.2d, v18.2d\n"
|
1774
|
+
"scvtf v19.4s, v19.4s, #0x4\n"
|
1775
|
+
"uzp2 v20.2d, v20.2d, v18.2d\n"
|
1776
|
+
"fmul v18.4s, v27.4s, v9.s[0]\n"
|
1777
|
+
"scvtf v20.4s, v20.4s, #0x4\n"
|
1778
|
+
"fmla v11.4s, v19.4s, v18.4s\n"
|
1779
|
+
"ldr q18, [x22, #0x0]\n"
|
1780
|
+
"fmul v19.4s, v27.4s, v9.s[1]\n"
|
1781
|
+
"fmla v13.4s, v20.4s, v19.4s\n"
|
1782
|
+
"movi v19.4s, #0x0\n"
|
1783
|
+
"movi v20.4s, #0x0\n"
|
1784
|
+
".inst 0x4e88a633 // smmla v19.4s, v17.16b, v8.16b\n"
|
1785
|
+
".inst 0x4e9fa634 // smmla v20.4s, v17.16b, v31.16b\n"
|
1786
|
+
"ldr q17, [x23, #0x30]\n"
|
1787
|
+
".inst 0x4e8fa633 // smmla v19.4s, v17.16b, v15.16b\n"
|
1788
|
+
".inst 0x4e81a634 // smmla v20.4s, v17.16b, v1.16b\n"
|
1789
|
+
"ldr q17, [x23, #0x50]\n"
|
1790
|
+
".inst 0x4e95a633 // smmla v19.4s, v17.16b, v21.16b\n"
|
1791
|
+
".inst 0x4e90a634 // smmla v20.4s, v17.16b, v16.16b\n"
|
1792
|
+
"ldr q17, [x23, #0x70]\n"
|
1793
|
+
"add x23, x23, #0x88\n"
|
1794
|
+
".inst 0x4e9da633 // smmla v19.4s, v17.16b, v29.16b\n"
|
1795
|
+
".inst 0x4e83a634 // smmla v20.4s, v17.16b, v3.16b\n"
|
1796
|
+
"uzp1 v17.2d, v19.2d, v20.2d\n"
|
1797
|
+
"scvtf v17.4s, v17.4s, #0x4\n"
|
1798
|
+
"uzp2 v20.2d, v19.2d, v20.2d\n"
|
1799
|
+
"fmul v19.4s, v27.4s, v9.s[2]\n"
|
1800
|
+
"fmul v9.4s, v27.4s, v9.s[3]\n"
|
1801
|
+
"scvtf v20.4s, v20.4s, #0x4\n"
|
1802
|
+
"fmla v22.4s, v17.4s, v19.4s\n"
|
1803
|
+
"ldr q17, [x22, #0x10]\n"
|
1804
|
+
"movi v19.4s, #0x0\n"
|
1805
|
+
".inst 0x4e88a653 // smmla v19.4s, v18.16b, v8.16b\n"
|
1806
|
+
"fmla v23.4s, v20.4s, v9.4s\n"
|
1807
|
+
"movi v20.4s, #0x0\n"
|
1808
|
+
"movi v9.4s, #0x0\n"
|
1809
|
+
".inst 0x4e9fa654 // smmla v20.4s, v18.16b, v31.16b\n"
|
1810
|
+
"ldr q18, [x22, #0x20]\n"
|
1811
|
+
".inst 0x4e88a629 // smmla v9.4s, v17.16b, v8.16b\n"
|
1812
|
+
".inst 0x4e8fa653 // smmla v19.4s, v18.16b, v15.16b\n"
|
1813
|
+
".inst 0x4e81a654 // smmla v20.4s, v18.16b, v1.16b\n"
|
1814
|
+
"ldr q18, [x22, #0x40]\n"
|
1815
|
+
".inst 0x4e95a653 // smmla v19.4s, v18.16b, v21.16b\n"
|
1816
|
+
".inst 0x4e90a654 // smmla v20.4s, v18.16b, v16.16b\n"
|
1817
|
+
"ldr q18, [x22, #0x60]\n"
|
1818
|
+
".inst 0x4e9da653 // smmla v19.4s, v18.16b, v29.16b\n"
|
1819
|
+
".inst 0x4e83a654 // smmla v20.4s, v18.16b, v3.16b\n"
|
1820
|
+
"movi v18.4s, #0x0\n"
|
1821
|
+
".inst 0x4e9fa632 // smmla v18.4s, v17.16b, v31.16b\n"
|
1822
|
+
"ldr q17, [x22, #0x30]\n"
|
1823
|
+
".inst 0x4e8fa629 // smmla v9.4s, v17.16b, v15.16b\n"
|
1824
|
+
".inst 0x4e81a632 // smmla v18.4s, v17.16b, v1.16b\n"
|
1825
|
+
"ldr q17, [x22, #0x50]\n"
|
1826
|
+
".inst 0x4e95a629 // smmla v9.4s, v17.16b, v21.16b\n"
|
1827
|
+
".inst 0x4e90a632 // smmla v18.4s, v17.16b, v16.16b\n"
|
1828
|
+
"ldr q17, [x22, #0x70]\n"
|
1829
|
+
"add x22, x22, #0x88\n"
|
1830
|
+
".inst 0x4e9da629 // smmla v9.4s, v17.16b, v29.16b\n"
|
1831
|
+
".inst 0x4e83a632 // smmla v18.4s, v17.16b, v3.16b\n"
|
1832
|
+
"uzp1 v17.2d, v19.2d, v20.2d\n"
|
1833
|
+
"uzp2 v20.2d, v19.2d, v20.2d\n"
|
1834
|
+
"fmul v19.4s, v27.4s, v0.s[0]\n"
|
1835
|
+
"scvtf v17.4s, v17.4s, #0x4\n"
|
1836
|
+
"scvtf v20.4s, v20.4s, #0x4\n"
|
1837
|
+
"fmla v25.4s, v17.4s, v19.4s\n"
|
1838
|
+
"ldr q19, [x21, #0x0]\n"
|
1839
|
+
"fmul v17.4s, v27.4s, v0.s[1]\n"
|
1840
|
+
"fmla v5.4s, v20.4s, v17.4s\n"
|
1841
|
+
"ldr q17, [x21, #0x10]\n"
|
1842
|
+
"uzp1 v20.2d, v9.2d, v18.2d\n"
|
1843
|
+
"uzp2 v9.2d, v9.2d, v18.2d\n"
|
1844
|
+
"fmul v18.4s, v27.4s, v0.s[2]\n"
|
1845
|
+
"fmul v0.4s, v27.4s, v0.s[3]\n"
|
1846
|
+
"scvtf v20.4s, v20.4s, #0x4\n"
|
1847
|
+
"scvtf v9.4s, v9.4s, #0x4\n"
|
1848
|
+
"fmla v7.4s, v20.4s, v18.4s\n"
|
1849
|
+
"movi v20.4s, #0x0\n"
|
1850
|
+
"movi v18.4s, #0x0\n"
|
1851
|
+
".inst 0x4e88a674 // smmla v20.4s, v19.16b, v8.16b\n"
|
1852
|
+
".inst 0x4e9fa672 // smmla v18.4s, v19.16b, v31.16b\n"
|
1853
|
+
"ldr q19, [x21, #0x20]\n"
|
1854
|
+
"fmla v4.4s, v9.4s, v0.4s\n"
|
1855
|
+
"movi v9.4s, #0x0\n"
|
1856
|
+
"movi v0.4s, #0x0\n"
|
1857
|
+
".inst 0x4e88a629 // smmla v9.4s, v17.16b, v8.16b\n"
|
1858
|
+
"fmul v8.4s, v27.4s, v26.s[0]\n"
|
1859
|
+
".inst 0x4e9fa620 // smmla v0.4s, v17.16b, v31.16b\n"
|
1860
|
+
"ldr q17, [x21, #0x30]\n"
|
1861
|
+
".inst 0x4e8fa674 // smmla v20.4s, v19.16b, v15.16b\n"
|
1862
|
+
"fmul v31.4s, v27.4s, v26.s[1]\n"
|
1863
|
+
".inst 0x4e81a672 // smmla v18.4s, v19.16b, v1.16b\n"
|
1864
|
+
"ldr q19, [x21, #0x40]\n"
|
1865
|
+
".inst 0x4e8fa629 // smmla v9.4s, v17.16b, v15.16b\n"
|
1866
|
+
"fmul v15.4s, v27.4s, v26.s[2]\n"
|
1867
|
+
"fmul v27.4s, v27.4s, v26.s[3]\n"
|
1868
|
+
".inst 0x4e81a620 // smmla v0.4s, v17.16b, v1.16b\n"
|
1869
|
+
"ldr q1, [x21, #0x50]\n"
|
1870
|
+
".inst 0x4e95a674 // smmla v20.4s, v19.16b, v21.16b\n"
|
1871
|
+
".inst 0x4e90a672 // smmla v18.4s, v19.16b, v16.16b\n"
|
1872
|
+
"ldr q26, [x21, #0x60]\n"
|
1873
|
+
".inst 0x4e95a429 // smmla v9.4s, v1.16b, v21.16b\n"
|
1874
|
+
".inst 0x4e90a420 // smmla v0.4s, v1.16b, v16.16b\n"
|
1875
|
+
"ldr q21, [x21, #0x70]\n"
|
1876
|
+
"add x21, x21, #0x88\n"
|
1877
|
+
".inst 0x4e9da754 // smmla v20.4s, v26.16b, v29.16b\n"
|
1878
|
+
".inst 0x4e83a752 // smmla v18.4s, v26.16b, v3.16b\n"
|
1879
|
+
".inst 0x4e9da6a9 // smmla v9.4s, v21.16b, v29.16b\n"
|
1880
|
+
".inst 0x4e83a6a0 // smmla v0.4s, v21.16b, v3.16b\n"
|
1881
|
+
"uzp1 v29.2d, v20.2d, v18.2d\n"
|
1882
|
+
"uzp2 v21.2d, v20.2d, v18.2d\n"
|
1883
|
+
"scvtf v29.4s, v29.4s, #0x4\n"
|
1884
|
+
"uzp1 v18.2d, v9.2d, v0.2d\n"
|
1885
|
+
"uzp2 v16.2d, v9.2d, v0.2d\n"
|
1886
|
+
"scvtf v21.4s, v21.4s, #0x4\n"
|
1887
|
+
"fmla v6.4s, v29.4s, v8.4s\n"
|
1888
|
+
"scvtf v18.4s, v18.4s, #0x4\n"
|
1889
|
+
"scvtf v16.4s, v16.4s, #0x4\n"
|
1890
|
+
"fmla v30.4s, v21.4s, v31.4s\n"
|
1891
|
+
"fmla v24.4s, v18.4s, v15.4s\n"
|
1892
|
+
"fmla v14.4s, v16.4s, v27.4s\n"
|
1893
|
+
"bgt 3b\n"
|
1894
|
+
"mov x20, %x[res_ptr]\n"
|
1895
|
+
"subs x27, x27, #0x4\n"
|
1896
|
+
"add %x[res_ptr], %x[res_ptr], #0x10\n"
|
1897
|
+
"str q2, [x20, #0x0]\n"
|
1898
|
+
"add x20, x20, %x[res_stride]\n"
|
1899
|
+
"str q10, [x20, #0x0]\n"
|
1900
|
+
"add x20, x20, %x[res_stride]\n"
|
1901
|
+
"str q12, [x20, #0x0]\n"
|
1902
|
+
"add x20, x20, %x[res_stride]\n"
|
1903
|
+
"str q28, [x20, #0x0]\n"
|
1904
|
+
"add x20, x20, %x[res_stride]\n"
|
1905
|
+
"str q11, [x20, #0x0]\n"
|
1906
|
+
"add x20, x20, %x[res_stride]\n"
|
1907
|
+
"str q13, [x20, #0x0]\n"
|
1908
|
+
"add x20, x20, %x[res_stride]\n"
|
1909
|
+
"str q22, [x20, #0x0]\n"
|
1910
|
+
"add x20, x20, %x[res_stride]\n"
|
1911
|
+
"str q23, [x20, #0x0]\n"
|
1912
|
+
"add x20, x20, %x[res_stride]\n"
|
1913
|
+
"str q25, [x20, #0x0]\n"
|
1914
|
+
"add x20, x20, %x[res_stride]\n"
|
1915
|
+
"str q5, [x20, #0x0]\n"
|
1916
|
+
"add x20, x20, %x[res_stride]\n"
|
1917
|
+
"str q7, [x20, #0x0]\n"
|
1918
|
+
"add x20, x20, %x[res_stride]\n"
|
1919
|
+
"str q4, [x20, #0x0]\n"
|
1920
|
+
"add x20, x20, %x[res_stride]\n"
|
1921
|
+
"str q6, [x20, #0x0]\n"
|
1922
|
+
"add x20, x20, %x[res_stride]\n"
|
1923
|
+
"str q30, [x20, #0x0]\n"
|
1924
|
+
"add x20, x20, %x[res_stride]\n"
|
1925
|
+
"str q24, [x20, #0x0]\n"
|
1926
|
+
"add x20, x20, %x[res_stride]\n"
|
1927
|
+
"str q14, [x20, #0x0]\n"
|
1928
|
+
"bne 2b\n"
|
1929
|
+
"mov x20, #0x4\n"
|
1930
|
+
"sub x10, x10, #0x10\n"
|
1931
|
+
"cmp x10, #0x10\n"
|
1932
|
+
"mov %x[res_ptr], x26\n"
|
1933
|
+
"madd %x[a_ptr], x20, x9, %x[a_ptr]\n"
|
1934
|
+
"bge 1b\n"
|
1935
|
+
"4:" // Row loop skip
|
1936
|
+
"cbz x10, 9f\n"
|
1937
|
+
"5:" // Row tail: Row loop
|
1938
|
+
"add x24, %x[b_ptr], #0x8\n"
|
1939
|
+
"mov x23, %x[nc]\n"
|
1940
|
+
"add x22, %x[res_ptr], %x[res_stride], LSL #2\n"
|
1941
|
+
"6:" // Row tail: Column loop
|
1942
|
+
"movi v2.16b, #0x0\n"
|
1943
|
+
"movi v10.16b, #0x0\n"
|
1944
|
+
"add x25, %x[a_ptr], #0x8\n"
|
1945
|
+
"mov x21, %x[nb]\n"
|
1946
|
+
"movi v12.16b, #0x0\n"
|
1947
|
+
"movi v28.16b, #0x0\n"
|
1948
|
+
"7:" // Row tail: Block loop
|
1949
|
+
"ldr q6, [x24, #0x0]\n"
|
1950
|
+
"ldr q5, [x24, #0x10]\n"
|
1951
|
+
"movi v17.16b, #0x4\n"
|
1952
|
+
"movi v8.4s, #0x0\n"
|
1953
|
+
"ldr q4, [x25, #0x0]\n"
|
1954
|
+
"ldr q13, [x25, #0x10]\n"
|
1955
|
+
"movi v27.4s, #0x0\n"
|
1956
|
+
"movi v0.4s, #0x0\n"
|
1957
|
+
"ldr q31, [x24, #0x20]\n"
|
1958
|
+
"ldr q14, [x24, #0x30]\n"
|
1959
|
+
"movi v29.4s, #0x0\n"
|
1960
|
+
"movi v22.16b, #0xf0\n"
|
1961
|
+
"ldr q11, [x25, #0x20]\n"
|
1962
|
+
"ldr q23, [x25, #0x30]\n"
|
1963
|
+
"sshl v21.16b, v6.16b, v17.16b\n"
|
1964
|
+
"sshl v16.16b, v5.16b, v17.16b\n"
|
1965
|
+
"ldr q20, [x25, #0x40]\n"
|
1966
|
+
"ldr q26, [x25, #0x50]\n"
|
1967
|
+
"and v6.16b, v6.16b, v22.16b\n"
|
1968
|
+
"and v5.16b, v5.16b, v22.16b\n"
|
1969
|
+
"ldr q25, [x25, #0x60]\n"
|
1970
|
+
"ldr q3, [x25, #0x70]\n"
|
1971
|
+
"sshl v19.16b, v31.16b, v17.16b\n"
|
1972
|
+
"sshl v18.16b, v14.16b, v17.16b\n"
|
1973
|
+
"ldr d17, [x25, #-0x8]\n"
|
1974
|
+
".inst 0x4e95a488 // smmla v8.4s, v4.16b, v21.16b\n"
|
1975
|
+
".inst 0x4e90a49b // smmla v27.4s, v4.16b, v16.16b\n"
|
1976
|
+
"and v31.16b, v31.16b, v22.16b\n"
|
1977
|
+
".inst 0x4e95a5a0 // smmla v0.4s, v13.16b, v21.16b\n"
|
1978
|
+
".inst 0x4e90a5bd // smmla v29.4s, v13.16b, v16.16b\n"
|
1979
|
+
"and v14.16b, v14.16b, v22.16b\n"
|
1980
|
+
"sub x20, x24, #0x8\n"
|
1981
|
+
"ldr d16, [x20, #0x0]\n"
|
1982
|
+
"subs x21, x21, #0x1\n"
|
1983
|
+
"add x25, x25, #0x88\n"
|
1984
|
+
"fcvtl v17.4s, v17.4h\n"
|
1985
|
+
"add x24, x24, #0x48\n"
|
1986
|
+
".inst 0x4e93a568 // smmla v8.4s, v11.16b, v19.16b\n"
|
1987
|
+
".inst 0x4e92a57b // smmla v27.4s, v11.16b, v18.16b\n"
|
1988
|
+
".inst 0x4e93a6e0 // smmla v0.4s, v23.16b, v19.16b\n"
|
1989
|
+
".inst 0x4e92a6fd // smmla v29.4s, v23.16b, v18.16b\n"
|
1990
|
+
"fcvtl v16.4s, v16.4h\n"
|
1991
|
+
".inst 0x4e86a688 // smmla v8.4s, v20.16b, v6.16b\n"
|
1992
|
+
".inst 0x4e85a69b // smmla v27.4s, v20.16b, v5.16b\n"
|
1993
|
+
"fmul v23.4s, v16.4s, v17.s[0]\n"
|
1994
|
+
"fmul v21.4s, v16.4s, v17.s[1]\n"
|
1995
|
+
"fmul v1.4s, v16.4s, v17.s[2]\n"
|
1996
|
+
"fmul v20.4s, v16.4s, v17.s[3]\n"
|
1997
|
+
".inst 0x4e86a740 // smmla v0.4s, v26.16b, v6.16b\n"
|
1998
|
+
".inst 0x4e85a75d // smmla v29.4s, v26.16b, v5.16b\n"
|
1999
|
+
".inst 0x4e9fa728 // smmla v8.4s, v25.16b, v31.16b\n"
|
2000
|
+
".inst 0x4e8ea73b // smmla v27.4s, v25.16b, v14.16b\n"
|
2001
|
+
".inst 0x4e9fa460 // smmla v0.4s, v3.16b, v31.16b\n"
|
2002
|
+
".inst 0x4e8ea47d // smmla v29.4s, v3.16b, v14.16b\n"
|
2003
|
+
"uzp1 v19.2d, v8.2d, v27.2d\n"
|
2004
|
+
"uzp2 v18.2d, v8.2d, v27.2d\n"
|
2005
|
+
"scvtf v19.4s, v19.4s, #0x4\n"
|
2006
|
+
"uzp1 v17.2d, v0.2d, v29.2d\n"
|
2007
|
+
"uzp2 v16.2d, v0.2d, v29.2d\n"
|
2008
|
+
"scvtf v18.4s, v18.4s, #0x4\n"
|
2009
|
+
"fmla v2.4s, v19.4s, v23.4s\n"
|
2010
|
+
"scvtf v17.4s, v17.4s, #0x4\n"
|
2011
|
+
"scvtf v16.4s, v16.4s, #0x4\n"
|
2012
|
+
"fmla v10.4s, v18.4s, v21.4s\n"
|
2013
|
+
"fmla v12.4s, v17.4s, v1.4s\n"
|
2014
|
+
"fmla v28.4s, v16.4s, v20.4s\n"
|
2015
|
+
"bgt 7b\n"
|
2016
|
+
"mov x20, %x[res_ptr]\n"
|
2017
|
+
"cmp x10, #0x1\n"
|
2018
|
+
"str q2, [x20, #0x0]\n"
|
2019
|
+
"add x20, x20, %x[res_stride]\n"
|
2020
|
+
"ble 8f\n"
|
2021
|
+
"cmp x10, #0x2\n"
|
2022
|
+
"str q10, [x20, #0x0]\n"
|
2023
|
+
"add x20, x20, %x[res_stride]\n"
|
2024
|
+
"ble 8f\n"
|
2025
|
+
"cmp x10, #0x3\n"
|
2026
|
+
"str q12, [x20, #0x0]\n"
|
2027
|
+
"add x20, x20, %x[res_stride]\n"
|
2028
|
+
"ble 8f\n"
|
2029
|
+
"str q28, [x20, #0x0]\n"
|
2030
|
+
"8:" // Row tail: Accumulator store skip
|
2031
|
+
"subs x23, x23, #0x4\n"
|
2032
|
+
"add %x[res_ptr], %x[res_ptr], #0x10\n"
|
2033
|
+
"bne 6b\n"
|
2034
|
+
"subs x10, x10, #0x4\n"
|
2035
|
+
"add %x[a_ptr], %x[a_ptr], x9\n"
|
2036
|
+
"mov %x[res_ptr], x22\n"
|
2037
|
+
"bgt 5b\n"
|
2038
|
+
"9:" // Row tail: Row loop skip
|
2039
|
+
: [a_ptr] "+&r" (a_ptr), [res_ptr] "+&r" (res_ptr)
|
2040
|
+
: [b_ptr] "r" (b_ptr), [nr] "r" (nr), [nb] "r" (nb), [res_stride] "r" (res_stride), [nc] "r" (nc)
|
2041
|
+
: "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15", "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23", "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31", "x9", "x10", "x20", "x21", "x22", "x23", "x24", "x25", "x26", "x27", "x28"
|
2042
|
+
);
|
2043
|
+
return;
|
2044
|
+
}
|
2045
|
+
#endif // #if ! ((defined(_MSC_VER)) && ! defined(__clang__)) && defined(__aarch64__) && defined(__ARM_NEON) && defined(__ARM_FEATURE_MATMUL_INT8)
|
2046
|
+
float sumf[4][4];
|
2047
|
+
int sumi;
|
2048
|
+
|
2049
|
+
for (int y = 0; y < nr / 4; y++) {
|
2050
|
+
const block_q8_0x4 * a_ptr = (const block_q8_0x4 *) vy + (y * nb);
|
2051
|
+
for (int x = 0; x < nc / ncols_interleaved; x++) {
|
2052
|
+
const block_q4_0x4 * b_ptr = (const block_q4_0x4 *) vx + (x * nb);
|
2053
|
+
for (int m = 0; m < 4; m++) {
|
2054
|
+
for (int j = 0; j < ncols_interleaved; j++) sumf[m][j] = 0.0;
|
2055
|
+
}
|
2056
|
+
for (int l = 0; l < nb; l++) {
|
2057
|
+
for (int k = 0; k < (qk / (2 * blocklen)); k++) {
|
2058
|
+
for (int m = 0; m < 4; m++) {
|
2059
|
+
for (int j = 0; j < ncols_interleaved; j++) {
|
2060
|
+
sumi = 0;
|
2061
|
+
for (int i = 0; i < blocklen; ++i) {
|
2062
|
+
const int v0 = (int8_t) (b_ptr[l].qs[k * ncols_interleaved * blocklen + j * blocklen + i] << 4);
|
2063
|
+
const int v1 = (int8_t) (b_ptr[l].qs[k * ncols_interleaved * blocklen + j * blocklen + i] & 0xF0);
|
2064
|
+
sumi += ((v0 * a_ptr[l].qs[k * 4 * blocklen + m * blocklen + i]) +
|
2065
|
+
(v1 * a_ptr[l].qs[k * 4 * blocklen + m * blocklen + i + qk / 2 * 4])) >> 4;
|
2066
|
+
}
|
2067
|
+
sumf[m][j] += sumi * GGML_FP16_TO_FP32(b_ptr[l].d[j]) * GGML_FP16_TO_FP32(a_ptr[l].d[m]);
|
2068
|
+
}
|
2069
|
+
}
|
2070
|
+
}
|
2071
|
+
}
|
2072
|
+
for (int m = 0; m < 4; m++) {
|
2073
|
+
for (int j = 0; j < ncols_interleaved; j++)
|
2074
|
+
s[(y * 4 + m) * bs + x * ncols_interleaved + j] = sumf[m][j];
|
2075
|
+
}
|
2076
|
+
}
|
2077
|
+
}
|
2078
|
+
}
|
2079
|
+
|
2080
|
+
static void ggml_gemm_q4_0_8x8_q8_0(int n, float * GGML_RESTRICT s, size_t bs, const void * GGML_RESTRICT vx, const void * GGML_RESTRICT vy, int nr, int nc) {
|
2081
|
+
const int qk = QK8_0;
|
2082
|
+
const int nb = n / qk;
|
2083
|
+
const int ncols_interleaved = 8;
|
2084
|
+
const int blocklen = 8;
|
2085
|
+
|
2086
|
+
assert (n % qk == 0);
|
2087
|
+
assert (nr % 4 == 0);
|
2088
|
+
assert (nc % ncols_interleaved == 0);
|
2089
|
+
|
2090
|
+
UNUSED(s);
|
2091
|
+
UNUSED(bs);
|
2092
|
+
UNUSED(vx);
|
2093
|
+
UNUSED(vy);
|
2094
|
+
UNUSED(nr);
|
2095
|
+
UNUSED(nc);
|
2096
|
+
UNUSED(nb);
|
2097
|
+
UNUSED(ncols_interleaved);
|
2098
|
+
UNUSED(blocklen);
|
2099
|
+
|
2100
|
+
#if ! ((defined(_MSC_VER)) && ! defined(__clang__)) && defined(__aarch64__)
|
2101
|
+
#if defined(__ARM_FEATURE_SVE) && defined(__ARM_FEATURE_MATMUL_INT8)
|
2102
|
+
if (ggml_cpu_has_sve() && ggml_cpu_has_matmul_int8() && ggml_cpu_get_sve_cnt() == QK8_0) {
|
2103
|
+
const void * b_ptr = vx;
|
2104
|
+
const void * a_ptr = vy;
|
2105
|
+
float * res_ptr = s;
|
2106
|
+
size_t res_stride = bs * sizeof(float);
|
2107
|
+
|
2108
|
+
__asm__ __volatile__(
|
2109
|
+
"mov x20, #0x4\n"
|
2110
|
+
"mov x13, %x[nr]\n"
|
2111
|
+
"mov z28.s, #-0x4\n"
|
2112
|
+
"mov x12, #0x88\n"
|
2113
|
+
"ptrue p1.b\n"
|
2114
|
+
"whilelt p0.s, XZR, x20\n"
|
2115
|
+
"cmp x13, #0x10\n"
|
2116
|
+
"mul x12, %x[nb], x12\n"
|
2117
|
+
"blt 4f\n"
|
2118
|
+
"1:" // Row loop
|
2119
|
+
"add x11, %x[b_ptr], #0x10\n"
|
2120
|
+
"mov x10, %x[nc]\n"
|
2121
|
+
"add x9, %x[res_ptr], %x[res_stride], LSL #4\n"
|
2122
|
+
"2:" // Column loop
|
2123
|
+
"add x28, %x[a_ptr], #0x8\n"
|
2124
|
+
"mov z24.b, #0x0\n"
|
2125
|
+
"mov z15.b, #0x0\n"
|
2126
|
+
"mov x27, %x[nb]\n"
|
2127
|
+
"add x26, x28, x12\n"
|
2128
|
+
"mov z12.b, #0x0\n"
|
2129
|
+
"mov z0.b, #0x0\n"
|
2130
|
+
"add x25, x26, x12\n"
|
2131
|
+
"mov z13.b, #0x0\n"
|
2132
|
+
"mov z1.b, #0x0\n"
|
2133
|
+
"add x24, x25, x12\n"
|
2134
|
+
"mov z20.b, #0x0\n"
|
2135
|
+
"mov z25.b, #0x0\n"
|
2136
|
+
"mov z11.b, #0x0\n"
|
2137
|
+
"mov z16.b, #0x0\n"
|
2138
|
+
"mov z19.b, #0x0\n"
|
2139
|
+
"mov z26.b, #0x0\n"
|
2140
|
+
"mov z8.b, #0x0\n"
|
2141
|
+
"mov z29.b, #0x0\n"
|
2142
|
+
"mov z27.b, #0x0\n"
|
2143
|
+
"mov z10.b, #0x0\n"
|
2144
|
+
"3:" // Block loop
|
2145
|
+
"ld1b { z30.b }, p1/Z, [x11]\n"
|
2146
|
+
"ld1b { z21.b }, p1/Z, [x11, #1, MUL VL]\n"
|
2147
|
+
"mov z18.s, #0x0\n"
|
2148
|
+
"mov z7.s, #0x0\n"
|
2149
|
+
"ld1rqb { z3.b }, p1/Z, [x28]\n"
|
2150
|
+
"ld1rqb { z5.b }, p1/Z, [x28, #16]\n"
|
2151
|
+
"mov z9.s, #0x0\n"
|
2152
|
+
"mov z22.s, #0x0\n"
|
2153
|
+
"ld1b { z4.b }, p1/Z, [x11, #2, MUL VL]\n"
|
2154
|
+
"ld1b { z17.b }, p1/Z, [x11, #3, MUL VL]\n"
|
2155
|
+
"sub x20, x11, #0x10\n"
|
2156
|
+
"sub x23, x28, #0x8\n"
|
2157
|
+
"lsl z31.b, z30.b, #0x4\n"
|
2158
|
+
"lsl z6.b, z21.b, #0x4\n"
|
2159
|
+
"ld1h { z23.s }, p1/Z, [x20]\n"
|
2160
|
+
"sub x22, x26, #0x8\n"
|
2161
|
+
"and z30.b, z30.b, #0xf0\n"
|
2162
|
+
"and z21.b, z21.b, #0xf0\n"
|
2163
|
+
"sub x21, x25, #0x8\n"
|
2164
|
+
"sub x20, x24, #0x8\n"
|
2165
|
+
"lsl z14.b, z4.b, #0x4\n"
|
2166
|
+
"lsl z2.b, z17.b, #0x4\n"
|
2167
|
+
"subs x27, x27, #0x1\n"
|
2168
|
+
"add x11, x11, #0x90\n"
|
2169
|
+
".inst 0x451f9872 // smmla z18.s, z3.b, z31.b\n"
|
2170
|
+
".inst 0x45069867 // smmla z7.s, z3.b, z6.b\n"
|
2171
|
+
"ld1rqb { z3.b }, p1/Z, [x28, #32]\n"
|
2172
|
+
"and z4.b, z4.b, #0xf0\n"
|
2173
|
+
".inst 0x451f98a9 // smmla z9.s, z5.b, z31.b\n"
|
2174
|
+
".inst 0x450698b6 // smmla z22.s, z5.b, z6.b\n"
|
2175
|
+
"ld1rqb { z5.b }, p1/Z, [x28, #48]\n"
|
2176
|
+
"and z17.b, z17.b, #0xf0\n"
|
2177
|
+
"fcvt z23.s, p1/m, z23.h\n"
|
2178
|
+
".inst 0x450e9872 // smmla z18.s, z3.b, z14.b\n"
|
2179
|
+
".inst 0x45029867 // smmla z7.s, z3.b, z2.b\n"
|
2180
|
+
"ld1rqb { z3.b }, p1/Z, [x28, #64]\n"
|
2181
|
+
".inst 0x450e98a9 // smmla z9.s, z5.b, z14.b\n"
|
2182
|
+
".inst 0x450298b6 // smmla z22.s, z5.b, z2.b\n"
|
2183
|
+
"ld1rqb { z5.b }, p1/Z, [x28, #80]\n"
|
2184
|
+
"fscale z23.s, p1/m, z23.s, z28.s\n"
|
2185
|
+
".inst 0x451e9872 // smmla z18.s, z3.b, z30.b\n"
|
2186
|
+
".inst 0x45159867 // smmla z7.s, z3.b, z21.b\n"
|
2187
|
+
"ld1rqb { z3.b }, p1/Z, [x28, #96]\n"
|
2188
|
+
".inst 0x451e98a9 // smmla z9.s, z5.b, z30.b\n"
|
2189
|
+
".inst 0x451598b6 // smmla z22.s, z5.b, z21.b\n"
|
2190
|
+
"ld1rqb { z5.b }, p1/Z, [x28, #112]\n"
|
2191
|
+
"add x28, x28, #0x88\n"
|
2192
|
+
".inst 0x45049872 // smmla z18.s, z3.b, z4.b\n"
|
2193
|
+
".inst 0x45119867 // smmla z7.s, z3.b, z17.b\n"
|
2194
|
+
"ld1h { z3.s }, p0/Z, [x23]\n"
|
2195
|
+
".inst 0x450498a9 // smmla z9.s, z5.b, z4.b\n"
|
2196
|
+
".inst 0x451198b6 // smmla z22.s, z5.b, z17.b\n"
|
2197
|
+
"fcvt z3.s, p1/m, z3.h\n"
|
2198
|
+
"uzp1 z5.d, z18.d, z7.d\n"
|
2199
|
+
"uzp2 z18.d, z18.d, z7.d\n"
|
2200
|
+
"mov z3.q, z3.q[0]\n"
|
2201
|
+
"uzp1 z7.d, z9.d, z22.d\n"
|
2202
|
+
"uzp2 z22.d, z9.d, z22.d\n"
|
2203
|
+
"fmul z9.s, z23.s, z3.s[0]\n"
|
2204
|
+
"scvtf z5.s, p1/m, z5.s\n"
|
2205
|
+
"scvtf z18.s, p1/m, z18.s\n"
|
2206
|
+
"scvtf z7.s, p1/m, z7.s\n"
|
2207
|
+
"scvtf z22.s, p1/m, z22.s\n"
|
2208
|
+
"fmla z24.s, p1/M, z5.s, z9.s\n"
|
2209
|
+
"ld1rqb { z5.b }, p1/Z, [x26]\n"
|
2210
|
+
"fmul z9.s, z23.s, z3.s[1]\n"
|
2211
|
+
"fmla z15.s, p1/M, z18.s, z9.s\n"
|
2212
|
+
"ld1rqb { z18.b }, p1/Z, [x26, #16]\n"
|
2213
|
+
"fmul z9.s, z23.s, z3.s[2]\n"
|
2214
|
+
"fmul z3.s, z23.s, z3.s[3]\n"
|
2215
|
+
"fmla z12.s, p1/M, z7.s, z9.s\n"
|
2216
|
+
"mov z9.s, #0x0\n"
|
2217
|
+
"ld1h { z7.s }, p0/Z, [x22]\n"
|
2218
|
+
".inst 0x451f98a9 // smmla z9.s, z5.b, z31.b\n"
|
2219
|
+
"fmla z0.s, p1/M, z22.s, z3.s\n"
|
2220
|
+
"mov z22.s, #0x0\n"
|
2221
|
+
"ld1h { z3.s }, p0/Z, [x21]\n"
|
2222
|
+
".inst 0x450698b6 // smmla z22.s, z5.b, z6.b\n"
|
2223
|
+
"ld1rqb { z5.b }, p1/Z, [x26, #32]\n"
|
2224
|
+
"fcvt z7.s, p1/m, z7.h\n"
|
2225
|
+
"fcvt z3.s, p1/m, z3.h\n"
|
2226
|
+
".inst 0x450e98a9 // smmla z9.s, z5.b, z14.b\n"
|
2227
|
+
".inst 0x450298b6 // smmla z22.s, z5.b, z2.b\n"
|
2228
|
+
"ld1rqb { z5.b }, p1/Z, [x26, #64]\n"
|
2229
|
+
"mov z7.q, z7.q[0]\n"
|
2230
|
+
"mov z3.q, z3.q[0]\n"
|
2231
|
+
".inst 0x451e98a9 // smmla z9.s, z5.b, z30.b\n"
|
2232
|
+
".inst 0x451598b6 // smmla z22.s, z5.b, z21.b\n"
|
2233
|
+
"ld1rqb { z5.b }, p1/Z, [x26, #96]\n"
|
2234
|
+
".inst 0x450498a9 // smmla z9.s, z5.b, z4.b\n"
|
2235
|
+
".inst 0x451198b6 // smmla z22.s, z5.b, z17.b\n"
|
2236
|
+
"uzp1 z5.d, z9.d, z22.d\n"
|
2237
|
+
"scvtf z5.s, p1/m, z5.s\n"
|
2238
|
+
"uzp2 z22.d, z9.d, z22.d\n"
|
2239
|
+
"fmul z9.s, z23.s, z7.s[0]\n"
|
2240
|
+
"scvtf z22.s, p1/m, z22.s\n"
|
2241
|
+
"fmla z13.s, p1/M, z5.s, z9.s\n"
|
2242
|
+
"ld1rqb { z9.b }, p1/Z, [x25]\n"
|
2243
|
+
"fmul z5.s, z23.s, z7.s[1]\n"
|
2244
|
+
"fmla z1.s, p1/M, z22.s, z5.s\n"
|
2245
|
+
"mov z5.s, #0x0\n"
|
2246
|
+
"mov z22.s, #0x0\n"
|
2247
|
+
".inst 0x451f9a45 // smmla z5.s, z18.b, z31.b\n"
|
2248
|
+
".inst 0x45069a56 // smmla z22.s, z18.b, z6.b\n"
|
2249
|
+
"ld1rqb { z18.b }, p1/Z, [x26, #48]\n"
|
2250
|
+
".inst 0x450e9a45 // smmla z5.s, z18.b, z14.b\n"
|
2251
|
+
".inst 0x45029a56 // smmla z22.s, z18.b, z2.b\n"
|
2252
|
+
"ld1rqb { z18.b }, p1/Z, [x26, #80]\n"
|
2253
|
+
".inst 0x451e9a45 // smmla z5.s, z18.b, z30.b\n"
|
2254
|
+
".inst 0x45159a56 // smmla z22.s, z18.b, z21.b\n"
|
2255
|
+
"ld1rqb { z18.b }, p1/Z, [x26, #112]\n"
|
2256
|
+
"add x26, x26, #0x88\n"
|
2257
|
+
".inst 0x45049a45 // smmla z5.s, z18.b, z4.b\n"
|
2258
|
+
".inst 0x45119a56 // smmla z22.s, z18.b, z17.b\n"
|
2259
|
+
"uzp1 z18.d, z5.d, z22.d\n"
|
2260
|
+
"scvtf z18.s, p1/m, z18.s\n"
|
2261
|
+
"uzp2 z22.d, z5.d, z22.d\n"
|
2262
|
+
"fmul z5.s, z23.s, z7.s[2]\n"
|
2263
|
+
"fmul z7.s, z23.s, z7.s[3]\n"
|
2264
|
+
"scvtf z22.s, p1/m, z22.s\n"
|
2265
|
+
"fmla z20.s, p1/M, z18.s, z5.s\n"
|
2266
|
+
"ld1rqb { z18.b }, p1/Z, [x25, #16]\n"
|
2267
|
+
"ld1h { z5.s }, p0/Z, [x20]\n"
|
2268
|
+
"fcvt z5.s, p1/m, z5.h\n"
|
2269
|
+
"fmla z25.s, p1/M, z22.s, z7.s\n"
|
2270
|
+
"mov z22.s, #0x0\n"
|
2271
|
+
"mov z7.s, #0x0\n"
|
2272
|
+
".inst 0x451f9936 // smmla z22.s, z9.b, z31.b\n"
|
2273
|
+
".inst 0x45069927 // smmla z7.s, z9.b, z6.b\n"
|
2274
|
+
"ld1rqb { z9.b }, p1/Z, [x25, #32]\n"
|
2275
|
+
"mov z5.q, z5.q[0]\n"
|
2276
|
+
".inst 0x450e9936 // smmla z22.s, z9.b, z14.b\n"
|
2277
|
+
".inst 0x45029927 // smmla z7.s, z9.b, z2.b\n"
|
2278
|
+
"ld1rqb { z9.b }, p1/Z, [x25, #64]\n"
|
2279
|
+
".inst 0x451e9936 // smmla z22.s, z9.b, z30.b\n"
|
2280
|
+
".inst 0x45159927 // smmla z7.s, z9.b, z21.b\n"
|
2281
|
+
"ld1rqb { z9.b }, p1/Z, [x25, #96]\n"
|
2282
|
+
".inst 0x45049936 // smmla z22.s, z9.b, z4.b\n"
|
2283
|
+
".inst 0x45119927 // smmla z7.s, z9.b, z17.b\n"
|
2284
|
+
"uzp1 z9.d, z22.d, z7.d\n"
|
2285
|
+
"scvtf z9.s, p1/m, z9.s\n"
|
2286
|
+
"uzp2 z22.d, z22.d, z7.d\n"
|
2287
|
+
"fmul z7.s, z23.s, z3.s[0]\n"
|
2288
|
+
"scvtf z22.s, p1/m, z22.s\n"
|
2289
|
+
"fmla z11.s, p1/M, z9.s, z7.s\n"
|
2290
|
+
"ld1rqb { z9.b }, p1/Z, [x24]\n"
|
2291
|
+
"fmul z7.s, z23.s, z3.s[1]\n"
|
2292
|
+
"fmla z16.s, p1/M, z22.s, z7.s\n"
|
2293
|
+
"mov z22.s, #0x0\n"
|
2294
|
+
"mov z7.s, #0x0\n"
|
2295
|
+
".inst 0x451f9a56 // smmla z22.s, z18.b, z31.b\n"
|
2296
|
+
".inst 0x45069a47 // smmla z7.s, z18.b, z6.b\n"
|
2297
|
+
"ld1rqb { z18.b }, p1/Z, [x25, #48]\n"
|
2298
|
+
".inst 0x450e9a56 // smmla z22.s, z18.b, z14.b\n"
|
2299
|
+
".inst 0x45029a47 // smmla z7.s, z18.b, z2.b\n"
|
2300
|
+
"ld1rqb { z18.b }, p1/Z, [x25, #80]\n"
|
2301
|
+
".inst 0x451e9a56 // smmla z22.s, z18.b, z30.b\n"
|
2302
|
+
".inst 0x45159a47 // smmla z7.s, z18.b, z21.b\n"
|
2303
|
+
"ld1rqb { z18.b }, p1/Z, [x25, #112]\n"
|
2304
|
+
"add x25, x25, #0x88\n"
|
2305
|
+
".inst 0x45049a56 // smmla z22.s, z18.b, z4.b\n"
|
2306
|
+
".inst 0x45119a47 // smmla z7.s, z18.b, z17.b\n"
|
2307
|
+
"uzp1 z18.d, z22.d, z7.d\n"
|
2308
|
+
"scvtf z18.s, p1/m, z18.s\n"
|
2309
|
+
"uzp2 z7.d, z22.d, z7.d\n"
|
2310
|
+
"fmul z22.s, z23.s, z3.s[2]\n"
|
2311
|
+
"fmul z3.s, z23.s, z3.s[3]\n"
|
2312
|
+
"scvtf z7.s, p1/m, z7.s\n"
|
2313
|
+
"fmla z19.s, p1/M, z18.s, z22.s\n"
|
2314
|
+
"ld1rqb { z18.b }, p1/Z, [x24, #16]\n"
|
2315
|
+
"fmul z22.s, z23.s, z5.s[0]\n"
|
2316
|
+
"fmla z26.s, p1/M, z7.s, z3.s\n"
|
2317
|
+
"mov z3.s, #0x0\n"
|
2318
|
+
"mov z7.s, #0x0\n"
|
2319
|
+
".inst 0x451f9923 // smmla z3.s, z9.b, z31.b\n"
|
2320
|
+
".inst 0x45069927 // smmla z7.s, z9.b, z6.b\n"
|
2321
|
+
"ld1rqb { z9.b }, p1/Z, [x24, #32]\n"
|
2322
|
+
".inst 0x450e9923 // smmla z3.s, z9.b, z14.b\n"
|
2323
|
+
".inst 0x45029927 // smmla z7.s, z9.b, z2.b\n"
|
2324
|
+
"mov z9.s, #0x0\n"
|
2325
|
+
".inst 0x451f9a49 // smmla z9.s, z18.b, z31.b\n"
|
2326
|
+
"mov z31.s, #0x0\n"
|
2327
|
+
".inst 0x45069a5f // smmla z31.s, z18.b, z6.b\n"
|
2328
|
+
"ld1rqb { z6.b }, p1/Z, [x24, #48]\n"
|
2329
|
+
"ld1rqb { z18.b }, p1/Z, [x24, #64]\n"
|
2330
|
+
".inst 0x450e98c9 // smmla z9.s, z6.b, z14.b\n"
|
2331
|
+
"fmul z14.s, z23.s, z5.s[1]\n"
|
2332
|
+
".inst 0x450298df // smmla z31.s, z6.b, z2.b\n"
|
2333
|
+
"ld1rqb { z6.b }, p1/Z, [x24, #80]\n"
|
2334
|
+
"fmul z2.s, z23.s, z5.s[2]\n"
|
2335
|
+
"fmul z23.s, z23.s, z5.s[3]\n"
|
2336
|
+
".inst 0x451e9a43 // smmla z3.s, z18.b, z30.b\n"
|
2337
|
+
".inst 0x45159a47 // smmla z7.s, z18.b, z21.b\n"
|
2338
|
+
"ld1rqb { z5.b }, p1/Z, [x24, #96]\n"
|
2339
|
+
".inst 0x451e98c9 // smmla z9.s, z6.b, z30.b\n"
|
2340
|
+
".inst 0x451598df // smmla z31.s, z6.b, z21.b\n"
|
2341
|
+
"ld1rqb { z18.b }, p1/Z, [x24, #112]\n"
|
2342
|
+
"add x24, x24, #0x88\n"
|
2343
|
+
".inst 0x450498a3 // smmla z3.s, z5.b, z4.b\n"
|
2344
|
+
".inst 0x451198a7 // smmla z7.s, z5.b, z17.b\n"
|
2345
|
+
".inst 0x45049a49 // smmla z9.s, z18.b, z4.b\n"
|
2346
|
+
".inst 0x45119a5f // smmla z31.s, z18.b, z17.b\n"
|
2347
|
+
"uzp1 z18.d, z3.d, z7.d\n"
|
2348
|
+
"uzp2 z5.d, z3.d, z7.d\n"
|
2349
|
+
"scvtf z18.s, p1/m, z18.s\n"
|
2350
|
+
"uzp1 z6.d, z9.d, z31.d\n"
|
2351
|
+
"uzp2 z9.d, z9.d, z31.d\n"
|
2352
|
+
"scvtf z5.s, p1/m, z5.s\n"
|
2353
|
+
"fmla z8.s, p1/M, z18.s, z22.s\n"
|
2354
|
+
"scvtf z6.s, p1/m, z6.s\n"
|
2355
|
+
"scvtf z9.s, p1/m, z9.s\n"
|
2356
|
+
"fmla z29.s, p1/M, z5.s, z14.s\n"
|
2357
|
+
"fmla z27.s, p1/M, z6.s, z2.s\n"
|
2358
|
+
"fmla z10.s, p1/M, z9.s, z23.s\n"
|
2359
|
+
"bgt 3b\n"
|
2360
|
+
"mov x20, %x[res_ptr]\n"
|
2361
|
+
"subs x10, x10, #0x8\n"
|
2362
|
+
"add %x[res_ptr], %x[res_ptr], #0x20\n"
|
2363
|
+
"st1w { z24.s }, p1, [x20]\n"
|
2364
|
+
"add x20, x20, %x[res_stride]\n"
|
2365
|
+
"st1w { z15.s }, p1, [x20]\n"
|
2366
|
+
"add x20, x20, %x[res_stride]\n"
|
2367
|
+
"st1w { z12.s }, p1, [x20]\n"
|
2368
|
+
"add x20, x20, %x[res_stride]\n"
|
2369
|
+
"st1w { z0.s }, p1, [x20]\n"
|
2370
|
+
"add x20, x20, %x[res_stride]\n"
|
2371
|
+
"st1w { z13.s }, p1, [x20]\n"
|
2372
|
+
"add x20, x20, %x[res_stride]\n"
|
2373
|
+
"st1w { z1.s }, p1, [x20]\n"
|
2374
|
+
"add x20, x20, %x[res_stride]\n"
|
2375
|
+
"st1w { z20.s }, p1, [x20]\n"
|
2376
|
+
"add x20, x20, %x[res_stride]\n"
|
2377
|
+
"st1w { z25.s }, p1, [x20]\n"
|
2378
|
+
"add x20, x20, %x[res_stride]\n"
|
2379
|
+
"st1w { z11.s }, p1, [x20]\n"
|
2380
|
+
"add x20, x20, %x[res_stride]\n"
|
2381
|
+
"st1w { z16.s }, p1, [x20]\n"
|
2382
|
+
"add x20, x20, %x[res_stride]\n"
|
2383
|
+
"st1w { z19.s }, p1, [x20]\n"
|
2384
|
+
"add x20, x20, %x[res_stride]\n"
|
2385
|
+
"st1w { z26.s }, p1, [x20]\n"
|
2386
|
+
"add x20, x20, %x[res_stride]\n"
|
2387
|
+
"st1w { z8.s }, p1, [x20]\n"
|
2388
|
+
"add x20, x20, %x[res_stride]\n"
|
2389
|
+
"st1w { z29.s }, p1, [x20]\n"
|
2390
|
+
"add x20, x20, %x[res_stride]\n"
|
2391
|
+
"st1w { z27.s }, p1, [x20]\n"
|
2392
|
+
"add x20, x20, %x[res_stride]\n"
|
2393
|
+
"st1w { z10.s }, p1, [x20]\n"
|
2394
|
+
"bne 2b\n"
|
2395
|
+
"mov x20, #0x4\n"
|
2396
|
+
"sub x13, x13, #0x10\n"
|
2397
|
+
"cmp x13, #0x10\n"
|
2398
|
+
"mov %x[res_ptr], x9\n"
|
2399
|
+
"madd %x[a_ptr], x20, x12, %x[a_ptr]\n"
|
2400
|
+
"bge 1b\n"
|
2401
|
+
"4:" // Row loop skip
|
2402
|
+
"cbz x13, 9f\n"
|
2403
|
+
"5:" // Row tail: Row loop
|
2404
|
+
"add x25, %x[b_ptr], #0x10\n"
|
2405
|
+
"mov x24, %x[nc]\n"
|
2406
|
+
"add x23, %x[res_ptr], %x[res_stride], LSL #2\n"
|
2407
|
+
"6:" // Row tail: Column loop
|
2408
|
+
"mov z24.b, #0x0\n"
|
2409
|
+
"mov z15.b, #0x0\n"
|
2410
|
+
"add x28, %x[a_ptr], #0x8\n"
|
2411
|
+
"mov x22, %x[nb]\n"
|
2412
|
+
"mov z12.b, #0x0\n"
|
2413
|
+
"mov z0.b, #0x0\n"
|
2414
|
+
"7:" // Row tail: Block loop
|
2415
|
+
"ld1b { z3.b }, p1/Z, [x25]\n"
|
2416
|
+
"ld1b { z6.b }, p1/Z, [x25, #1, MUL VL]\n"
|
2417
|
+
"mov z2.s, #0x0\n"
|
2418
|
+
"mov z25.s, #0x0\n"
|
2419
|
+
"ld1rqb { z26.b }, p1/Z, [x28]\n"
|
2420
|
+
"ld1rqb { z21.b }, p1/Z, [x28, #16]\n"
|
2421
|
+
"mov z27.s, #0x0\n"
|
2422
|
+
"mov z19.s, #0x0\n"
|
2423
|
+
"ld1b { z29.b }, p1/Z, [x25, #2, MUL VL]\n"
|
2424
|
+
"ld1b { z16.b }, p1/Z, [x25, #3, MUL VL]\n"
|
2425
|
+
"sub x21, x25, #0x10\n"
|
2426
|
+
"sub x20, x28, #0x8\n"
|
2427
|
+
"lsl z20.b, z3.b, #0x4\n"
|
2428
|
+
"lsl z4.b, z6.b, #0x4\n"
|
2429
|
+
"ld1rqb { z10.b }, p1/Z, [x28, #32]\n"
|
2430
|
+
"ld1rqb { z23.b }, p1/Z, [x28, #48]\n"
|
2431
|
+
"and z3.b, z3.b, #0xf0\n"
|
2432
|
+
"and z6.b, z6.b, #0xf0\n"
|
2433
|
+
"ld1rqb { z11.b }, p1/Z, [x28, #64]\n"
|
2434
|
+
"ld1rqb { z7.b }, p1/Z, [x28, #80]\n"
|
2435
|
+
"lsl z8.b, z29.b, #0x4\n"
|
2436
|
+
"lsl z14.b, z16.b, #0x4\n"
|
2437
|
+
"ld1rqb { z18.b }, p1/Z, [x28, #96]\n"
|
2438
|
+
"ld1rqb { z30.b }, p1/Z, [x28, #112]\n"
|
2439
|
+
".inst 0x45149b42 // smmla z2.s, z26.b, z20.b\n"
|
2440
|
+
".inst 0x45049b59 // smmla z25.s, z26.b, z4.b\n"
|
2441
|
+
"and z29.b, z29.b, #0xf0\n"
|
2442
|
+
"ld1h { z17.s }, p1/Z, [x21]\n"
|
2443
|
+
".inst 0x45149abb // smmla z27.s, z21.b, z20.b\n"
|
2444
|
+
".inst 0x45049ab3 // smmla z19.s, z21.b, z4.b\n"
|
2445
|
+
"and z16.b, z16.b, #0xf0\n"
|
2446
|
+
"ld1h { z4.s }, p0/Z, [x20]\n"
|
2447
|
+
"subs x22, x22, #0x1\n"
|
2448
|
+
"add x28, x28, #0x88\n"
|
2449
|
+
"fcvt z17.s, p1/m, z17.h\n"
|
2450
|
+
"add x25, x25, #0x90\n"
|
2451
|
+
".inst 0x45089942 // smmla z2.s, z10.b, z8.b\n"
|
2452
|
+
".inst 0x450e9959 // smmla z25.s, z10.b, z14.b\n"
|
2453
|
+
"fcvt z4.s, p1/m, z4.h\n"
|
2454
|
+
".inst 0x45089afb // smmla z27.s, z23.b, z8.b\n"
|
2455
|
+
".inst 0x450e9af3 // smmla z19.s, z23.b, z14.b\n"
|
2456
|
+
"fscale z17.s, p1/m, z17.s, z28.s\n"
|
2457
|
+
"mov z4.q, z4.q[0]\n"
|
2458
|
+
".inst 0x45039962 // smmla z2.s, z11.b, z3.b\n"
|
2459
|
+
".inst 0x45069979 // smmla z25.s, z11.b, z6.b\n"
|
2460
|
+
"fmul z23.s, z17.s, z4.s[0]\n"
|
2461
|
+
"fmul z9.s, z17.s, z4.s[1]\n"
|
2462
|
+
"fmul z21.s, z17.s, z4.s[2]\n"
|
2463
|
+
"fmul z4.s, z17.s, z4.s[3]\n"
|
2464
|
+
".inst 0x450398fb // smmla z27.s, z7.b, z3.b\n"
|
2465
|
+
".inst 0x450698f3 // smmla z19.s, z7.b, z6.b\n"
|
2466
|
+
".inst 0x451d9a42 // smmla z2.s, z18.b, z29.b\n"
|
2467
|
+
".inst 0x45109a59 // smmla z25.s, z18.b, z16.b\n"
|
2468
|
+
".inst 0x451d9bdb // smmla z27.s, z30.b, z29.b\n"
|
2469
|
+
".inst 0x45109bd3 // smmla z19.s, z30.b, z16.b\n"
|
2470
|
+
"uzp1 z31.d, z2.d, z25.d\n"
|
2471
|
+
"uzp2 z13.d, z2.d, z25.d\n"
|
2472
|
+
"scvtf z31.s, p1/m, z31.s\n"
|
2473
|
+
"uzp1 z17.d, z27.d, z19.d\n"
|
2474
|
+
"uzp2 z18.d, z27.d, z19.d\n"
|
2475
|
+
"scvtf z13.s, p1/m, z13.s\n"
|
2476
|
+
"fmla z24.s, p1/M, z31.s, z23.s\n"
|
2477
|
+
"scvtf z17.s, p1/m, z17.s\n"
|
2478
|
+
"scvtf z18.s, p1/m, z18.s\n"
|
2479
|
+
"fmla z15.s, p1/M, z13.s, z9.s\n"
|
2480
|
+
"fmla z12.s, p1/M, z17.s, z21.s\n"
|
2481
|
+
"fmla z0.s, p1/M, z18.s, z4.s\n"
|
2482
|
+
"bgt 7b\n"
|
2483
|
+
"mov x20, %x[res_ptr]\n"
|
2484
|
+
"cmp x13, #0x1\n"
|
2485
|
+
"st1w { z24.s }, p1, [x20]\n"
|
2486
|
+
"add x20, x20, %x[res_stride]\n"
|
2487
|
+
"ble 8f\n"
|
2488
|
+
"cmp x13, #0x2\n"
|
2489
|
+
"st1w { z15.s }, p1, [x20]\n"
|
2490
|
+
"add x20, x20, %x[res_stride]\n"
|
2491
|
+
"ble 8f\n"
|
2492
|
+
"cmp x13, #0x3\n"
|
2493
|
+
"st1w { z12.s }, p1, [x20]\n"
|
2494
|
+
"add x20, x20, %x[res_stride]\n"
|
2495
|
+
"ble 8f\n"
|
2496
|
+
"st1w { z0.s }, p1, [x20]\n"
|
2497
|
+
"8:" // Row tail: Accumulator store skip
|
2498
|
+
"subs x24, x24, #0x8\n"
|
2499
|
+
"add %x[res_ptr], %x[res_ptr], #0x20\n"
|
2500
|
+
"bne 6b\n"
|
2501
|
+
"subs x13, x13, #0x4\n"
|
2502
|
+
"add %x[a_ptr], %x[a_ptr], x12\n"
|
2503
|
+
"mov %x[res_ptr], x23\n"
|
2504
|
+
"bgt 5b\n"
|
2505
|
+
"9:" // Row tail: Row loop skip
|
2506
|
+
: [a_ptr] "+&r" (a_ptr), [res_ptr] "+&r" (res_ptr)
|
2507
|
+
: [b_ptr] "r" (b_ptr), [nr] "r" (nr), [nb] "r" (nb), [res_stride] "r" (res_stride), [nc] "r" (nc)
|
2508
|
+
: "cc", "memory", "p0", "p1", "x9", "x10", "x11", "x12", "x13", "x20", "x21", "x22", "x23", "x24", "x25", "x26", "x27", "x28", "z0", "z1", "z2", "z3", "z4", "z5", "z6", "z7", "z8", "z9", "z10", "z11", "z12", "z13", "z14", "z15", "z16", "z17", "z18", "z19", "z20", "z21", "z22", "z23", "z24", "z25", "z26", "z27", "z28", "z29", "z30", "z31"
|
2509
|
+
);
|
2510
|
+
return;
|
2511
|
+
}
|
2512
|
+
#endif // #if defined(__ARM_FEATURE_SVE) && defined(__ARM_FEATURE_MATMUL_INT8)
|
2513
|
+
#elif defined(__AVX2__) || defined(__AVX512F__)
|
2514
|
+
{
|
2515
|
+
const block_q4_0x8 * b_ptr_start = (const block_q4_0x8 *)vx;
|
2516
|
+
const block_q8_0x4 * a_ptr_start = (const block_q8_0x4 *)vy;
|
2517
|
+
int64_t b_nb = n / QK4_0;
|
2518
|
+
int64_t y = 0;
|
2519
|
+
// Mask to mask out nibbles from packed bytes
|
2520
|
+
const __m256i m4b = _mm256_set1_epi8(0x0F);
|
2521
|
+
const __m128i loadMask = _mm_blend_epi32(_mm_setzero_si128(), _mm_set1_epi32(0xFFFFFFFF), 3);
|
2522
|
+
// Lookup table to convert signed nibbles to signed bytes
|
2523
|
+
__m256i signextendlut = _mm256_castsi128_si256(_mm_set_epi8(-1, -2, -3, -4, -5, -6, -7, -8, 7, 6, 5, 4, 3, 2, 1, 0));
|
2524
|
+
signextendlut = _mm256_permute2f128_si256(signextendlut, signextendlut, 0);
|
2525
|
+
// Permute mask used for easier vector processing at later stages
|
2526
|
+
__m256i requiredOrder = _mm256_set_epi32(3, 2, 1, 0, 7, 6, 5, 4);
|
2527
|
+
int64_t xstart = 0;
|
2528
|
+
int anr = nr - nr%16; // Used to align nr with boundary of 16
|
2529
|
+
#ifdef __AVX512F__
|
2530
|
+
int anc = nc - nc%16; // Used to align nc with boundary of 16
|
2531
|
+
// Mask to mask out nibbles from packed bytes expanded to 512 bit length
|
2532
|
+
const __m512i m4bexpanded = _mm512_set1_epi8(0x0F);
|
2533
|
+
// Lookup table to convert signed nibbles to signed bytes expanded to 512 bit length
|
2534
|
+
__m512i signextendlutexpanded = _mm512_inserti32x8(_mm512_castsi256_si512(signextendlut), signextendlut, 1);
|
2535
|
+
|
2536
|
+
// Take group of four block_q8_0x4 structures at each pass of the loop and perform dot product operation
|
2537
|
+
for (; y < anr / 4; y += 4) {
|
2538
|
+
|
2539
|
+
const block_q8_0x4 * a_ptrs[4];
|
2540
|
+
|
2541
|
+
a_ptrs[0] = a_ptr_start + (y * nb);
|
2542
|
+
for (int i = 0; i < 3; ++i) {
|
2543
|
+
a_ptrs[i + 1] = a_ptrs[i] + nb;
|
2544
|
+
}
|
2545
|
+
|
2546
|
+
// Take group of two block_q4_0x8 structures at each pass of the loop and perform dot product operation
|
2547
|
+
for (int64_t x = 0; x < anc / 8; x += 2) {
|
2548
|
+
|
2549
|
+
const block_q4_0x8 * b_ptr_0 = b_ptr_start + ((x) * b_nb);
|
2550
|
+
const block_q4_0x8 * b_ptr_1 = b_ptr_start + ((x + 1) * b_nb);
|
2551
|
+
|
2552
|
+
// Master FP accumulators
|
2553
|
+
__m512 acc_rows[16];
|
2554
|
+
for (int i = 0; i < 16; i++) {
|
2555
|
+
acc_rows[i] = _mm512_setzero_ps();
|
2556
|
+
}
|
2557
|
+
|
2558
|
+
for (int64_t b = 0; b < nb; b++) {
|
2559
|
+
// Load the sixteen block_q4_0 quantized values interleaved with each other in chunks of eight - B0,B1 ....BE,BF
|
2560
|
+
const __m256i rhs_raw_mat_0123_0 = _mm256_loadu_si256((const __m256i *)(b_ptr_0[b].qs));
|
2561
|
+
const __m256i rhs_raw_mat_4567_0 = _mm256_loadu_si256((const __m256i *)(b_ptr_0[b].qs + 32));
|
2562
|
+
const __m256i rhs_raw_mat_0123_1 = _mm256_loadu_si256((const __m256i *)(b_ptr_0[b].qs + 64));
|
2563
|
+
const __m256i rhs_raw_mat_4567_1 = _mm256_loadu_si256((const __m256i *)(b_ptr_0[b].qs + 96));
|
2564
|
+
|
2565
|
+
const __m256i rhs_raw_mat_89AB_0 = _mm256_loadu_si256((const __m256i *)(b_ptr_1[b].qs));
|
2566
|
+
const __m256i rhs_raw_mat_CDEF_0 = _mm256_loadu_si256((const __m256i *)(b_ptr_1[b].qs + 32));
|
2567
|
+
const __m256i rhs_raw_mat_89AB_1 = _mm256_loadu_si256((const __m256i *)(b_ptr_1[b].qs + 64));
|
2568
|
+
const __m256i rhs_raw_mat_CDEF_1 = _mm256_loadu_si256((const __m256i *)(b_ptr_1[b].qs + 96));
|
2569
|
+
|
2570
|
+
// Save the values in the following vectors in the formats B0B1B4B5B8B9BCBD, B2B3B6B7BABBBEBF for further processing and storing of values
|
2571
|
+
const __m256i rhs_raw_mat_0145_0 = _mm256_blend_epi32(rhs_raw_mat_0123_0, _mm256_permutevar8x32_epi32(rhs_raw_mat_4567_0, requiredOrder), 240);
|
2572
|
+
const __m256i rhs_raw_mat_2367_0 = _mm256_blend_epi32(_mm256_permutevar8x32_epi32(rhs_raw_mat_0123_0, requiredOrder), rhs_raw_mat_4567_0, 240);
|
2573
|
+
const __m256i rhs_raw_mat_0145_1 = _mm256_blend_epi32(rhs_raw_mat_0123_1, _mm256_permutevar8x32_epi32(rhs_raw_mat_4567_1, requiredOrder), 240);
|
2574
|
+
const __m256i rhs_raw_mat_2367_1 = _mm256_blend_epi32(_mm256_permutevar8x32_epi32(rhs_raw_mat_0123_1, requiredOrder), rhs_raw_mat_4567_1, 240);
|
2575
|
+
|
2576
|
+
const __m256i rhs_raw_mat_89CD_0 = _mm256_blend_epi32(rhs_raw_mat_89AB_0, _mm256_permutevar8x32_epi32(rhs_raw_mat_CDEF_0, requiredOrder), 240);
|
2577
|
+
const __m256i rhs_raw_mat_ABEF_0 = _mm256_blend_epi32(_mm256_permutevar8x32_epi32(rhs_raw_mat_89AB_0, requiredOrder), rhs_raw_mat_CDEF_0, 240);
|
2578
|
+
const __m256i rhs_raw_mat_89CD_1 = _mm256_blend_epi32(rhs_raw_mat_89AB_1, _mm256_permutevar8x32_epi32(rhs_raw_mat_CDEF_1, requiredOrder), 240);
|
2579
|
+
const __m256i rhs_raw_mat_ABEF_1 = _mm256_blend_epi32(_mm256_permutevar8x32_epi32(rhs_raw_mat_89AB_1, requiredOrder), rhs_raw_mat_CDEF_1, 240);
|
2580
|
+
|
2581
|
+
const __m512i rhs_raw_mat_014589CD_0 = _mm512_inserti32x8(_mm512_castsi256_si512(rhs_raw_mat_0145_0), rhs_raw_mat_89CD_0, 1);
|
2582
|
+
const __m512i rhs_raw_mat_2367ABEF_0 = _mm512_inserti32x8(_mm512_castsi256_si512(rhs_raw_mat_2367_0), rhs_raw_mat_ABEF_0, 1);
|
2583
|
+
const __m512i rhs_raw_mat_014589CD_1 = _mm512_inserti32x8(_mm512_castsi256_si512(rhs_raw_mat_0145_1), rhs_raw_mat_89CD_1, 1);
|
2584
|
+
const __m512i rhs_raw_mat_2367ABEF_1 = _mm512_inserti32x8(_mm512_castsi256_si512(rhs_raw_mat_2367_1), rhs_raw_mat_ABEF_1, 1);
|
2585
|
+
|
2586
|
+
// 4-bit -> 8-bit - Sign is maintained
|
2587
|
+
const __m512i rhs_mat_014589CD_0 = _mm512_shuffle_epi8(signextendlutexpanded, _mm512_and_si512(rhs_raw_mat_014589CD_0, m4bexpanded)); //B0(0-7) B1(0-7) B4(0-7) B5(0-7) B8(0-7) B9(0-7) BC(0-7) BD(0-7)
|
2588
|
+
const __m512i rhs_mat_2367ABEF_0 = _mm512_shuffle_epi8(signextendlutexpanded, _mm512_and_si512(rhs_raw_mat_2367ABEF_0, m4bexpanded)); //B2(0-7) B3(0-7) B6(0-7) B7(0-7) BA(0-7) BB(0-7) BE(0-7) BF(0-7)
|
2589
|
+
|
2590
|
+
const __m512i rhs_mat_014589CD_1 = _mm512_shuffle_epi8(signextendlutexpanded, _mm512_and_si512(rhs_raw_mat_014589CD_1, m4bexpanded)); //B0(8-15) B1(8-15) B4(8-15) B5(8-15) B8(8-15) B9(8-15) BC(8-15) BD(8-15)
|
2591
|
+
const __m512i rhs_mat_2367ABEF_1 = _mm512_shuffle_epi8(signextendlutexpanded, _mm512_and_si512(rhs_raw_mat_2367ABEF_1, m4bexpanded)); //B2(8-15) B3(8-15) B6(8-15) B7(8-15) BA(8-15) BB(8-15) BE(8-15) BF(8-15)
|
2592
|
+
|
2593
|
+
const __m512i rhs_mat_014589CD_2 = _mm512_shuffle_epi8(signextendlutexpanded, _mm512_and_si512(_mm512_srli_epi16(rhs_raw_mat_014589CD_0, 4), m4bexpanded)); //B0(16-23) B1(16-23) B4(16-23) B5(16-23) B8(16-23) B9(16-23) BC(16-23) BD(16-23)
|
2594
|
+
const __m512i rhs_mat_2367ABEF_2 = _mm512_shuffle_epi8(signextendlutexpanded, _mm512_and_si512(_mm512_srli_epi16(rhs_raw_mat_2367ABEF_0, 4), m4bexpanded)); //B2(16-23) B3(16-23) B6(16-23) B7(16-23) BA(16-23) BB(16-23) BE(16-23) BF(16-23)
|
2595
|
+
|
2596
|
+
const __m512i rhs_mat_014589CD_3 = _mm512_shuffle_epi8(signextendlutexpanded, _mm512_and_si512(_mm512_srli_epi16(rhs_raw_mat_014589CD_1, 4), m4bexpanded)); //B0(24-31) B1(24-31) B4(24-31) B5(24-31) B8(24-31) B9(24-31) BC(24-31) BD(24-31)
|
2597
|
+
const __m512i rhs_mat_2367ABEF_3 = _mm512_shuffle_epi8(signextendlutexpanded, _mm512_and_si512(_mm512_srli_epi16(rhs_raw_mat_2367ABEF_1, 4), m4bexpanded)); //B2(24-31) B3(24-31) B6(24-31) B7(24-31) BA(24-31) BB(24-31) BE(24-31) BF(24-31)
|
2598
|
+
|
2599
|
+
// Shuffle pattern one - right side input
|
2600
|
+
const __m512i rhs_mat_014589CD_0_sp1 = _mm512_shuffle_epi32(rhs_mat_014589CD_0, (_MM_PERM_ENUM)136); //B0(0-3) B1(0-3) B0(0-3) B1(0-3) B4(0-3) B5(0-3) B4(0-3) B5(0-3) B8(0-3) B9(0-3) B8(0-3) B9(0-3) BC(0-3) BD(0-3) BC(0-3) BD(0-3)
|
2601
|
+
const __m512i rhs_mat_2367ABEF_0_sp1 = _mm512_shuffle_epi32(rhs_mat_2367ABEF_0, (_MM_PERM_ENUM)136); //B2(0-3) B3(0-3) B2(0-3) B3(0-3) B6(0-3) B7(0-3) B6(0-3) B7(0-3) BA(0-3) BB(0-3) BA(0-3) BB(0-3) BE(0-3) BF(0-3) BE(0-3) BF(0-3)
|
2602
|
+
|
2603
|
+
const __m512i rhs_mat_014589CD_1_sp1 = _mm512_shuffle_epi32(rhs_mat_014589CD_1, (_MM_PERM_ENUM)136); //B0(8-11) B1(8-11) B0(8-11) B1(8-11) B4(8-11) B5(8-11) B4(8-11) B5(8-11) B8(8-11) B9(8-11) B8(8-11) B9(8-11) BC(8-11) BD(8-11) BC(8-11) BD(8-11)
|
2604
|
+
const __m512i rhs_mat_2367ABEF_1_sp1 = _mm512_shuffle_epi32(rhs_mat_2367ABEF_1, (_MM_PERM_ENUM)136); //B2(8-11) B3(8-11) B2(8-11) B3(8-11) B6(8-11) B7(8-11) B6(8-11) B7(8-11) BA(8-11) BB(8-11) BA(8-11) BB(8-11) BE(8-11) BF(8-11) BE(8-11) BF(8-11)
|
2605
|
+
|
2606
|
+
const __m512i rhs_mat_014589CD_2_sp1 = _mm512_shuffle_epi32(rhs_mat_014589CD_2, (_MM_PERM_ENUM)136); //B0(16-19) B1(16-19) B0(16-19) B1(16-19) B4(16-19) B5(16-19) B4(16-19) B5(16-19) B8(16-19) B9(16-19) B8(16-19) B9(16-19) BC(16-19) BD(16-19) BC(16-19) BD(16-19)
|
2607
|
+
const __m512i rhs_mat_2367ABEF_2_sp1 = _mm512_shuffle_epi32(rhs_mat_2367ABEF_2, (_MM_PERM_ENUM)136); //B2(16-19) B3(16-19) B2(16-19) B3(16-19) B6(16-19) B7(16-19) B6(16-19) B7(16-19) BA(16-19) BB(16-19) BA(16-19) BB(16-19) BE(16-19) BF(16-19) BE(16-19) BF(16-19)
|
2608
|
+
|
2609
|
+
const __m512i rhs_mat_014589CD_3_sp1 = _mm512_shuffle_epi32(rhs_mat_014589CD_3, (_MM_PERM_ENUM)136); //B0(24-27) B1(24-27) B0(24-27) B1(24-27) B4(24-27) B5(24-27) B4(24-27) B5(24-27) B8(24-27) B9(24-27) B8(24-27) B9(24-27) BC(24-27) BD(24-27) BC(24-27) BD(24-27)
|
2610
|
+
const __m512i rhs_mat_2367ABEF_3_sp1 = _mm512_shuffle_epi32(rhs_mat_2367ABEF_3, (_MM_PERM_ENUM)136); //B2(24-27) B3(24-27) B2(24-27) B3(24-27) B6(24-27) B7(24-27) B6(24-27) B7(24-27) BA(24-27) BB(24-27) BA(24-27) BB(24-27) BE(24-27) BF(24-27) BE(24-27) BF(24-27)
|
2611
|
+
|
2612
|
+
// Shuffle pattern two - right side input
|
2613
|
+
|
2614
|
+
const __m512i rhs_mat_014589CD_0_sp2 = _mm512_shuffle_epi32(rhs_mat_014589CD_0, (_MM_PERM_ENUM)221); //B0(4-7) B1(4-7) B0(4-7) B1(4-7) B4(4-7) B5(4-7) B4(4-7) B5(4-7) B8(4-7) B9(4-7) B8(4-7) B9(4-7) BC(4-7) BD(4-7) BC(4-7) BD(4-7)
|
2615
|
+
const __m512i rhs_mat_2367ABEF_0_sp2 = _mm512_shuffle_epi32(rhs_mat_2367ABEF_0, (_MM_PERM_ENUM)221); //B2(4-7) B3(4-7) B2(4-7) B3(4-7) B6(4-7) B7(4-7) B6(4-7) B7(4-7) BA(4-7) BB(4-7) BA(4-7) BB(4-7) BE(4-7) BF(4-7) BE(4-7) BF(4-7)
|
2616
|
+
|
2617
|
+
const __m512i rhs_mat_014589CD_1_sp2 = _mm512_shuffle_epi32(rhs_mat_014589CD_1, (_MM_PERM_ENUM)221); //B0(12-15) B1(12-15) B0(12-15) B1(12-15) B4(12-15) B5(12-15) B4(12-15) B5(12-15) B8(12-15) B9(12-15) B8(12-15) B9(12-15) BC(12-15) BD(12-15) BC(12-15) BD(12-15)
|
2618
|
+
const __m512i rhs_mat_2367ABEF_1_sp2 = _mm512_shuffle_epi32(rhs_mat_2367ABEF_1, (_MM_PERM_ENUM)221); //B2(12-15) B3(12-15) B2(12-15) B3(12-15) B6(12-15) B7(12-15) B6(12-15) B7(12-15) BA(12-15) BB(12-15) BA(12-15) BB(12-15) BE(12-15) BF(12-15) BE(12-15) BF(12-15)
|
2619
|
+
|
2620
|
+
const __m512i rhs_mat_014589CD_2_sp2 = _mm512_shuffle_epi32(rhs_mat_014589CD_2, (_MM_PERM_ENUM)221); //B0(20-23) B1(20-23) B0(20-23) B1(20-23) B4(20-23) B5(20-23) B4(20-23) B5(20-23) B8(20-23) B9(20-23) B8(20-23) B9(20-23) BC(20-23) BD(20-23) BC(20-23) BD(20-23)
|
2621
|
+
const __m512i rhs_mat_2367ABEF_2_sp2 = _mm512_shuffle_epi32(rhs_mat_2367ABEF_2, (_MM_PERM_ENUM)221); //B2(20-23) B3(20-23) B2(20-23) B3(20-23) B6(20-23) B7(20-23) B6(20-23) B7(20-23) BA(20-23) BB(20-23) BA(20-23) BB(20-23) BE(20-23) BF(20-23) BE(20-23) BF(20-23)
|
2622
|
+
|
2623
|
+
const __m512i rhs_mat_014589CD_3_sp2 = _mm512_shuffle_epi32(rhs_mat_014589CD_3, (_MM_PERM_ENUM)221); //B0(28-31) B1(28-31) B0(28-31) B1(28-31) B4(28-31) B5(28-31) B4(28-31) B5(28-31) B8(28-31) B9(28-31) B8(28-31) B9(28-31) BC(28-31) BD(28-31) BC(28-31) BD(28-31)
|
2624
|
+
const __m512i rhs_mat_2367ABEF_3_sp2 = _mm512_shuffle_epi32(rhs_mat_2367ABEF_3, (_MM_PERM_ENUM)221); //B2(28-31) B3(28-31) B2(28-31) B3(28-31) B6(28-31) B7(28-31) B6(28-31) B7(28-31) BA(28-31) BB(28-31) BA(28-31) BB(28-31) BE(28-31) BF(28-31) BE(28-31) BF(28-31)
|
2625
|
+
|
2626
|
+
// Scale values - Load the weight scale values of two block_q4_0x8
|
2627
|
+
const __m512 col_scale_f32 = GGML_F32Cx8x2_LOAD(b_ptr_0[b].d, b_ptr_1[b].d);
|
2628
|
+
|
2629
|
+
// Process LHS in pairs of rows
|
2630
|
+
for (int rp = 0; rp < 4; rp++) {
|
2631
|
+
|
2632
|
+
// Load the four block_q4_0 quantized values interleaved with each other in chunks of eight - A0,A1,A2,A3
|
2633
|
+
// Loaded as set of 128 bit vectors and repeated and stored into a 256 bit vector before again repeating into 512 bit vector
|
2634
|
+
__m256i lhs_mat_ymm_0123_0 = _mm256_loadu_si256((const __m256i *)((a_ptrs[rp][b].qs)));
|
2635
|
+
__m256i lhs_mat_ymm_01_0 = _mm256_permute2f128_si256(lhs_mat_ymm_0123_0, lhs_mat_ymm_0123_0, 0);
|
2636
|
+
__m256i lhs_mat_ymm_23_0 = _mm256_permute2f128_si256(lhs_mat_ymm_0123_0, lhs_mat_ymm_0123_0, 17);
|
2637
|
+
__m256i lhs_mat_ymm_0123_1 = _mm256_loadu_si256((const __m256i *)((a_ptrs[rp][b].qs + 32)));
|
2638
|
+
__m256i lhs_mat_ymm_01_1 = _mm256_permute2f128_si256(lhs_mat_ymm_0123_1, lhs_mat_ymm_0123_1, 0);
|
2639
|
+
__m256i lhs_mat_ymm_23_1 = _mm256_permute2f128_si256(lhs_mat_ymm_0123_1, lhs_mat_ymm_0123_1, 17);
|
2640
|
+
__m256i lhs_mat_ymm_0123_2 = _mm256_loadu_si256((const __m256i *)((a_ptrs[rp][b].qs + 64)));
|
2641
|
+
__m256i lhs_mat_ymm_01_2 = _mm256_permute2f128_si256(lhs_mat_ymm_0123_2, lhs_mat_ymm_0123_2, 0);
|
2642
|
+
__m256i lhs_mat_ymm_23_2 = _mm256_permute2f128_si256(lhs_mat_ymm_0123_2, lhs_mat_ymm_0123_2, 17);
|
2643
|
+
__m256i lhs_mat_ymm_0123_3 = _mm256_loadu_si256((const __m256i *)((a_ptrs[rp][b].qs + 96)));
|
2644
|
+
__m256i lhs_mat_ymm_01_3 = _mm256_permute2f128_si256(lhs_mat_ymm_0123_3, lhs_mat_ymm_0123_3, 0);
|
2645
|
+
__m256i lhs_mat_ymm_23_3 = _mm256_permute2f128_si256(lhs_mat_ymm_0123_3, lhs_mat_ymm_0123_3, 17);
|
2646
|
+
|
2647
|
+
__m512i lhs_mat_01_0 = _mm512_inserti32x8(_mm512_castsi256_si512(lhs_mat_ymm_01_0), lhs_mat_ymm_01_0, 1);
|
2648
|
+
__m512i lhs_mat_23_0 = _mm512_inserti32x8(_mm512_castsi256_si512(lhs_mat_ymm_23_0), lhs_mat_ymm_23_0, 1);
|
2649
|
+
__m512i lhs_mat_01_1 = _mm512_inserti32x8(_mm512_castsi256_si512(lhs_mat_ymm_01_1), lhs_mat_ymm_01_1, 1);
|
2650
|
+
__m512i lhs_mat_23_1 = _mm512_inserti32x8(_mm512_castsi256_si512(lhs_mat_ymm_23_1), lhs_mat_ymm_23_1, 1);
|
2651
|
+
__m512i lhs_mat_01_2 = _mm512_inserti32x8(_mm512_castsi256_si512(lhs_mat_ymm_01_2), lhs_mat_ymm_01_2, 1);
|
2652
|
+
__m512i lhs_mat_23_2 = _mm512_inserti32x8(_mm512_castsi256_si512(lhs_mat_ymm_23_2), lhs_mat_ymm_23_2, 1);
|
2653
|
+
__m512i lhs_mat_01_3 = _mm512_inserti32x8(_mm512_castsi256_si512(lhs_mat_ymm_01_3), lhs_mat_ymm_01_3, 1);
|
2654
|
+
__m512i lhs_mat_23_3 = _mm512_inserti32x8(_mm512_castsi256_si512(lhs_mat_ymm_23_3), lhs_mat_ymm_23_3, 1);
|
2655
|
+
|
2656
|
+
// Shuffle pattern one - left side input
|
2657
|
+
|
2658
|
+
const __m512i lhs_mat_01_0_sp1 = _mm512_shuffle_epi32(lhs_mat_01_0, (_MM_PERM_ENUM)160); //A0(0-3) A0(0-3) A1(0-3) A1(0-3) A0(0-3) A0(0-3) A1(0-3) A1(0-3) A0(0-3) A0(0-3) A1(0-3) A1(0-3) A0(0-3) A0(0-3) A1(0-3) A1(0-3)
|
2659
|
+
const __m512i lhs_mat_23_0_sp1 = _mm512_shuffle_epi32(lhs_mat_23_0, (_MM_PERM_ENUM)160); //A2(0-3) A2(0-3) A3(0-3) A3(0-3) A2(0-3) A2(0-3) A3(0-3) A3(0-3) A2(0-3) A2(0-3) A3(0-3) A3(0-3) A2(0-3) A2(0-3) A3(0-3) A3(0-3)
|
2660
|
+
|
2661
|
+
const __m512i lhs_mat_01_1_sp1 = _mm512_shuffle_epi32(lhs_mat_01_1, (_MM_PERM_ENUM)160); //A0(8-11) A0(8-11) A1(8-11) A1(8-11) A0(8-11) A0(8-11) A1(8-11) A1(8-11) A0(8-11) A0(8-11) A1(8-11) A1(8-11) A0(8-11) A0(8-11) A1(8-11) A1(8-11)
|
2662
|
+
const __m512i lhs_mat_23_1_sp1 = _mm512_shuffle_epi32(lhs_mat_23_1, (_MM_PERM_ENUM)160); //A2(8-11) A2(8-11) A3(8-11) A3(8-11) A2(8-11) A2(8-11) A3(8-11) A3(8-11) A2(8-11) A2(8-11) A3(8-11) A3(8-11) A2(8-11) A2(8-11) A3(8-11) A3(8-11)
|
2663
|
+
|
2664
|
+
const __m512i lhs_mat_01_2_sp1 = _mm512_shuffle_epi32(lhs_mat_01_2, (_MM_PERM_ENUM)160); //A0(16-19) A0(16-19) A1(16-19) A1(16-19) A0(16-19) A0(16-19) A1(16-19) A1(16-19) A0(16-19) A0(16-19) A1(16-19) A1(16-19) A0(16-19) A0(16-19) A1(16-19) A1(16-19)
|
2665
|
+
const __m512i lhs_mat_23_2_sp1 = _mm512_shuffle_epi32(lhs_mat_23_2, (_MM_PERM_ENUM)160); //A2(16-19) A2(16-19) A3(16-19) A3(16-19) A2(16-19) A2(16-19) A3(16-19) A3(16-19) A2(16-19) A2(16-19) A3(16-19) A3(16-19) A2(16-19) A2(16-19) A3(16-19) A3(16-19)
|
2666
|
+
|
2667
|
+
const __m512i lhs_mat_01_3_sp1 = _mm512_shuffle_epi32(lhs_mat_01_3, (_MM_PERM_ENUM)160); //A0(24-27) A0(24-27) A1(24-27) A1(24-27) A0(24-27) A0(24-27) A1(24-27) A1(24-27) A0(24-27) A0(24-27) A1(24-27) A1(24-27) A0(24-27) A0(24-27) A1(24-27) A1(24-27)
|
2668
|
+
const __m512i lhs_mat_23_3_sp1 = _mm512_shuffle_epi32(lhs_mat_23_3, (_MM_PERM_ENUM)160); //A2(24-27) A2(24-27) A3(24-27) A3(24-27) A2(24-27) A2(24-27) A3(24-27) A3(24-27) A2(24-27) A2(24-27) A3(24-27) A3(24-27) A2(24-27) A2(24-27) A3(24-27) A3(24-27)
|
2669
|
+
|
2670
|
+
// Shuffle pattern two - left side input
|
2671
|
+
|
2672
|
+
const __m512i lhs_mat_01_0_sp2 = _mm512_shuffle_epi32(lhs_mat_01_0, (_MM_PERM_ENUM)245); //A0(4-7) A0(4-7) A1(4-7) A1(4-7) A0(4-7) A0(4-7) A1(4-7) A1(4-7) A0(4-7) A0(4-7) A1(4-7) A1(4-7) A0(4-7) A0(4-7) A1(4-7) A1(4-7)
|
2673
|
+
const __m512i lhs_mat_23_0_sp2 = _mm512_shuffle_epi32(lhs_mat_23_0, (_MM_PERM_ENUM)245); //A2(4-7) A2(4-7) A3(4-7) A3(4-7) A2(4-7) A2(4-7) A3(4-7) A3(4-7) A2(4-7) A2(4-7) A3(4-7) A3(4-7) A2(4-7) A2(4-7) A3(4-7) A3(4-7)
|
2674
|
+
|
2675
|
+
const __m512i lhs_mat_01_1_sp2 = _mm512_shuffle_epi32(lhs_mat_01_1, (_MM_PERM_ENUM)245); //A0(12-15) A0(12-15) A1(12-15) A1(12-15) A0(12-15) A0(12-15) A1(12-15) A1(12-15) A0(12-15) A0(12-15) A1(12-15) A1(12-15) A0(12-15) A0(12-15) A1(12-15) A1(12-15)
|
2676
|
+
const __m512i lhs_mat_23_1_sp2 = _mm512_shuffle_epi32(lhs_mat_23_1, (_MM_PERM_ENUM)245); //A2(12-15) A2(12-15) A3(12-15) A3(12-15) A2(12-15) A2(12-15) A3(12-15) A3(12-15) A2(12-15) A2(12-15) A3(12-15) A3(12-15) A2(12-15) A2(12-15) A3(12-15) A3(12-15)
|
2677
|
+
|
2678
|
+
const __m512i lhs_mat_01_2_sp2 = _mm512_shuffle_epi32(lhs_mat_01_2, (_MM_PERM_ENUM)245); //A0(20-23) A0(20-23) A1(20-23) A1(20-23) A0(20-23) A0(20-23) A1(20-23) A1(20-23) A0(20-23) A0(20-23) A1(20-23) A1(20-23) A0(20-23) A0(20-23) A1(20-23) A1(20-23)
|
2679
|
+
const __m512i lhs_mat_23_2_sp2 = _mm512_shuffle_epi32(lhs_mat_23_2, (_MM_PERM_ENUM)245); //A2(20-23) A2(20-23) A3(20-23) A3(20-23) A2(20-23) A2(20-23) A3(20-23) A3(20-23) A2(20-23) A2(20-23) A3(20-23) A3(20-23) A2(20-23) A2(20-23) A3(20-23) A3(20-23)
|
2680
|
+
|
2681
|
+
const __m512i lhs_mat_01_3_sp2 = _mm512_shuffle_epi32(lhs_mat_01_3, (_MM_PERM_ENUM)245); //A0(28-31) A0(28-31) A1(28-31) A1(28-31) A0(28-31) A0(28-31) A1(28-31) A1(28-31) A0(28-31) A0(28-31) A1(28-31) A1(28-31) A0(28-31) A0(28-31) A1(28-31) A1(28-31)
|
2682
|
+
const __m512i lhs_mat_23_3_sp2 = _mm512_shuffle_epi32(lhs_mat_23_3, (_MM_PERM_ENUM)245); //A2(28-31) A2(28-31) A3(28-31) A3(28-31) A2(28-31) A2(28-31) A3(28-31) A3(28-31) A2(28-31) A2(28-31) A3(28-31) A3(28-31) A2(28-31) A2(28-31) A3(28-31) A3(28-31)
|
2683
|
+
|
2684
|
+
// The values arranged in shuffle patterns are operated with dot product operation within 32 bit lane i.e corresponding bytes and multiplied and added into 32 bit integers within 32 bit lane
|
2685
|
+
// Resembles MMLAs into 2x2 matrices in ARM Version
|
2686
|
+
__m512i iacc_mat_00_sp1 =
|
2687
|
+
_mm512_add_epi32(_mm512_add_epi32(_mm512_add_epi32(mul_sum_i8_pairs_int32x16(lhs_mat_01_3_sp1, rhs_mat_014589CD_3_sp1), mul_sum_i8_pairs_int32x16(lhs_mat_01_2_sp1, rhs_mat_014589CD_2_sp1)), mul_sum_i8_pairs_int32x16(lhs_mat_01_1_sp1, rhs_mat_014589CD_1_sp1)), mul_sum_i8_pairs_int32x16(lhs_mat_01_0_sp1, rhs_mat_014589CD_0_sp1));
|
2688
|
+
__m512i iacc_mat_01_sp1 =
|
2689
|
+
_mm512_add_epi32(_mm512_add_epi32(_mm512_add_epi32(mul_sum_i8_pairs_int32x16(lhs_mat_01_3_sp1, rhs_mat_2367ABEF_3_sp1), mul_sum_i8_pairs_int32x16(lhs_mat_01_2_sp1, rhs_mat_2367ABEF_2_sp1)), mul_sum_i8_pairs_int32x16(lhs_mat_01_1_sp1, rhs_mat_2367ABEF_1_sp1)), mul_sum_i8_pairs_int32x16(lhs_mat_01_0_sp1, rhs_mat_2367ABEF_0_sp1));
|
2690
|
+
__m512i iacc_mat_10_sp1 =
|
2691
|
+
_mm512_add_epi32(_mm512_add_epi32(_mm512_add_epi32(mul_sum_i8_pairs_int32x16(lhs_mat_23_3_sp1, rhs_mat_014589CD_3_sp1), mul_sum_i8_pairs_int32x16(lhs_mat_23_2_sp1, rhs_mat_014589CD_2_sp1)), mul_sum_i8_pairs_int32x16(lhs_mat_23_1_sp1, rhs_mat_014589CD_1_sp1)), mul_sum_i8_pairs_int32x16(lhs_mat_23_0_sp1, rhs_mat_014589CD_0_sp1));
|
2692
|
+
__m512i iacc_mat_11_sp1 =
|
2693
|
+
_mm512_add_epi32(_mm512_add_epi32(_mm512_add_epi32(mul_sum_i8_pairs_int32x16(lhs_mat_23_3_sp1, rhs_mat_2367ABEF_3_sp1), mul_sum_i8_pairs_int32x16(lhs_mat_23_2_sp1, rhs_mat_2367ABEF_2_sp1)), mul_sum_i8_pairs_int32x16(lhs_mat_23_1_sp1, rhs_mat_2367ABEF_1_sp1)), mul_sum_i8_pairs_int32x16(lhs_mat_23_0_sp1, rhs_mat_2367ABEF_0_sp1));
|
2694
|
+
__m512i iacc_mat_00_sp2 =
|
2695
|
+
_mm512_add_epi32(_mm512_add_epi32(_mm512_add_epi32(mul_sum_i8_pairs_int32x16(lhs_mat_01_3_sp2, rhs_mat_014589CD_3_sp2), mul_sum_i8_pairs_int32x16(lhs_mat_01_2_sp2, rhs_mat_014589CD_2_sp2)), mul_sum_i8_pairs_int32x16(lhs_mat_01_1_sp2, rhs_mat_014589CD_1_sp2)), mul_sum_i8_pairs_int32x16(lhs_mat_01_0_sp2, rhs_mat_014589CD_0_sp2));
|
2696
|
+
__m512i iacc_mat_01_sp2 =
|
2697
|
+
_mm512_add_epi32(_mm512_add_epi32(_mm512_add_epi32(mul_sum_i8_pairs_int32x16(lhs_mat_01_3_sp2, rhs_mat_2367ABEF_3_sp2), mul_sum_i8_pairs_int32x16(lhs_mat_01_2_sp2, rhs_mat_2367ABEF_2_sp2)), mul_sum_i8_pairs_int32x16(lhs_mat_01_1_sp2, rhs_mat_2367ABEF_1_sp2)), mul_sum_i8_pairs_int32x16(lhs_mat_01_0_sp2, rhs_mat_2367ABEF_0_sp2));
|
2698
|
+
__m512i iacc_mat_10_sp2 =
|
2699
|
+
_mm512_add_epi32(_mm512_add_epi32(_mm512_add_epi32(mul_sum_i8_pairs_int32x16(lhs_mat_23_3_sp2, rhs_mat_014589CD_3_sp2), mul_sum_i8_pairs_int32x16(lhs_mat_23_2_sp2, rhs_mat_014589CD_2_sp2)), mul_sum_i8_pairs_int32x16(lhs_mat_23_1_sp2, rhs_mat_014589CD_1_sp2)), mul_sum_i8_pairs_int32x16(lhs_mat_23_0_sp2, rhs_mat_014589CD_0_sp2));
|
2700
|
+
__m512i iacc_mat_11_sp2 =
|
2701
|
+
_mm512_add_epi32(_mm512_add_epi32(_mm512_add_epi32(mul_sum_i8_pairs_int32x16(lhs_mat_23_3_sp2, rhs_mat_2367ABEF_3_sp2), mul_sum_i8_pairs_int32x16(lhs_mat_23_2_sp2, rhs_mat_2367ABEF_2_sp2)), mul_sum_i8_pairs_int32x16(lhs_mat_23_1_sp2, rhs_mat_2367ABEF_1_sp2)), mul_sum_i8_pairs_int32x16(lhs_mat_23_0_sp2, rhs_mat_2367ABEF_0_sp2));
|
2702
|
+
|
2703
|
+
// Output of both shuffle patterns are added in order to sum dot product outputs of all 32 values in block
|
2704
|
+
__m512i iacc_mat_00 = _mm512_add_epi32(iacc_mat_00_sp1, iacc_mat_00_sp2);
|
2705
|
+
__m512i iacc_mat_01 = _mm512_add_epi32(iacc_mat_01_sp1, iacc_mat_01_sp2);
|
2706
|
+
__m512i iacc_mat_10 = _mm512_add_epi32(iacc_mat_10_sp1, iacc_mat_10_sp2);
|
2707
|
+
__m512i iacc_mat_11 = _mm512_add_epi32(iacc_mat_11_sp1, iacc_mat_11_sp2);
|
2708
|
+
|
2709
|
+
|
2710
|
+
// Straighten out to make 4 row vectors
|
2711
|
+
__m512i iacc_row_0 = _mm512_mask_blend_epi32(0xCCCC, iacc_mat_00, _mm512_shuffle_epi32(iacc_mat_01, (_MM_PERM_ENUM)78));
|
2712
|
+
__m512i iacc_row_1 = _mm512_mask_blend_epi32(0xCCCC, _mm512_shuffle_epi32(iacc_mat_00, (_MM_PERM_ENUM)78), iacc_mat_01);
|
2713
|
+
__m512i iacc_row_2 = _mm512_mask_blend_epi32(0xCCCC, iacc_mat_10, _mm512_shuffle_epi32(iacc_mat_11, (_MM_PERM_ENUM)78));
|
2714
|
+
__m512i iacc_row_3 = _mm512_mask_blend_epi32(0xCCCC, _mm512_shuffle_epi32(iacc_mat_10, (_MM_PERM_ENUM)78), iacc_mat_11);
|
2715
|
+
|
2716
|
+
// Load the scale(d) values for all the 4 Q8_0 blocks and repeat it across lanes
|
2717
|
+
const __m128i row_scale_f16 = _mm_shuffle_epi32(_mm_maskload_epi32((int const*)(a_ptrs[rp][b].d), loadMask), 68);
|
2718
|
+
const __m512 row_scale_f32 = GGML_F32Cx16_REPEAT_LOAD(row_scale_f16);
|
2719
|
+
|
2720
|
+
// Multiply with appropiate scales and accumulate
|
2721
|
+
acc_rows[rp * 4] = _mm512_fmadd_ps(_mm512_cvtepi32_ps(iacc_row_0), _mm512_mul_ps(col_scale_f32, _mm512_shuffle_ps(row_scale_f32, row_scale_f32, 0)), acc_rows[rp * 4]);
|
2722
|
+
acc_rows[rp * 4 + 1] = _mm512_fmadd_ps(_mm512_cvtepi32_ps(iacc_row_1), _mm512_mul_ps(col_scale_f32, _mm512_shuffle_ps(row_scale_f32, row_scale_f32, 85)), acc_rows[rp * 4 + 1]);
|
2723
|
+
acc_rows[rp * 4 + 2] = _mm512_fmadd_ps(_mm512_cvtepi32_ps(iacc_row_2), _mm512_mul_ps(col_scale_f32, _mm512_shuffle_ps(row_scale_f32, row_scale_f32, 170)), acc_rows[rp * 4 + 2]);
|
2724
|
+
acc_rows[rp * 4 + 3] = _mm512_fmadd_ps(_mm512_cvtepi32_ps(iacc_row_3), _mm512_mul_ps(col_scale_f32, _mm512_shuffle_ps(row_scale_f32, row_scale_f32, 255)), acc_rows[rp * 4 + 3]);
|
2725
|
+
}
|
2726
|
+
}
|
2727
|
+
|
2728
|
+
// Store the accumulated values
|
2729
|
+
for (int i = 0; i < 16; i++) {
|
2730
|
+
_mm512_storeu_ps((float *)(s + ((y * 4 + i) * bs + x * 8)), acc_rows[i]);
|
2731
|
+
}
|
2732
|
+
}
|
2733
|
+
}
|
2734
|
+
// Take a block_q8_0x4 structures at each pass of the loop and perform dot product operation
|
2735
|
+
for (; y < nr / 4; y ++) {
|
2736
|
+
|
2737
|
+
const block_q8_0x4 * a_ptr = a_ptr_start + (y * nb);
|
2738
|
+
|
2739
|
+
// Take group of two block_q4_0x8 structures at each pass of the loop and perform dot product operation
|
2740
|
+
for (int64_t x = 0; x < anc / 8; x += 2) {
|
2741
|
+
|
2742
|
+
const block_q4_0x8 * b_ptr_0 = b_ptr_start + ((x) * b_nb);
|
2743
|
+
const block_q4_0x8 * b_ptr_1 = b_ptr_start + ((x + 1) * b_nb);
|
2744
|
+
|
2745
|
+
// Master FP accumulators
|
2746
|
+
__m512 acc_rows[4];
|
2747
|
+
for (int i = 0; i < 4; i++) {
|
2748
|
+
acc_rows[i] = _mm512_setzero_ps();
|
2749
|
+
}
|
2750
|
+
|
2751
|
+
for (int64_t b = 0; b < nb; b++) {
|
2752
|
+
// Load the sixteen block_q4_0 quantized values interleaved with each other in chunks of eight - B0,B1 ....BE,BF
|
2753
|
+
const __m256i rhs_raw_mat_0123_0 = _mm256_loadu_si256((const __m256i *)(b_ptr_0[b].qs));
|
2754
|
+
const __m256i rhs_raw_mat_4567_0 = _mm256_loadu_si256((const __m256i *)(b_ptr_0[b].qs + 32));
|
2755
|
+
const __m256i rhs_raw_mat_0123_1 = _mm256_loadu_si256((const __m256i *)(b_ptr_0[b].qs + 64));
|
2756
|
+
const __m256i rhs_raw_mat_4567_1 = _mm256_loadu_si256((const __m256i *)(b_ptr_0[b].qs + 96));
|
2757
|
+
|
2758
|
+
const __m256i rhs_raw_mat_89AB_0 = _mm256_loadu_si256((const __m256i *)(b_ptr_1[b].qs));
|
2759
|
+
const __m256i rhs_raw_mat_CDEF_0 = _mm256_loadu_si256((const __m256i *)(b_ptr_1[b].qs + 32));
|
2760
|
+
const __m256i rhs_raw_mat_89AB_1 = _mm256_loadu_si256((const __m256i *)(b_ptr_1[b].qs + 64));
|
2761
|
+
const __m256i rhs_raw_mat_CDEF_1 = _mm256_loadu_si256((const __m256i *)(b_ptr_1[b].qs + 96));
|
2762
|
+
|
2763
|
+
// Save the values in the following vectors in the formats B0B1B4B5, B2B3B6B7 for further processing and storing of valuess
|
2764
|
+
const __m256i rhs_raw_mat_0145_0 = _mm256_blend_epi32(rhs_raw_mat_0123_0, _mm256_permutevar8x32_epi32(rhs_raw_mat_4567_0, requiredOrder), 240);
|
2765
|
+
const __m256i rhs_raw_mat_2367_0 = _mm256_blend_epi32(_mm256_permutevar8x32_epi32(rhs_raw_mat_0123_0, requiredOrder), rhs_raw_mat_4567_0, 240);
|
2766
|
+
const __m256i rhs_raw_mat_0145_1 = _mm256_blend_epi32(rhs_raw_mat_0123_1, _mm256_permutevar8x32_epi32(rhs_raw_mat_4567_1, requiredOrder), 240);
|
2767
|
+
const __m256i rhs_raw_mat_2367_1 = _mm256_blend_epi32(_mm256_permutevar8x32_epi32(rhs_raw_mat_0123_1, requiredOrder), rhs_raw_mat_4567_1, 240);
|
2768
|
+
|
2769
|
+
const __m256i rhs_raw_mat_89CD_0 = _mm256_blend_epi32(rhs_raw_mat_89AB_0, _mm256_permutevar8x32_epi32(rhs_raw_mat_CDEF_0, requiredOrder), 240);
|
2770
|
+
const __m256i rhs_raw_mat_ABEF_0 = _mm256_blend_epi32(_mm256_permutevar8x32_epi32(rhs_raw_mat_89AB_0, requiredOrder), rhs_raw_mat_CDEF_0, 240);
|
2771
|
+
const __m256i rhs_raw_mat_89CD_1 = _mm256_blend_epi32(rhs_raw_mat_89AB_1, _mm256_permutevar8x32_epi32(rhs_raw_mat_CDEF_1, requiredOrder), 240);
|
2772
|
+
const __m256i rhs_raw_mat_ABEF_1 = _mm256_blend_epi32(_mm256_permutevar8x32_epi32(rhs_raw_mat_89AB_1, requiredOrder), rhs_raw_mat_CDEF_1, 240);
|
2773
|
+
|
2774
|
+
const __m512i rhs_raw_mat_014589CD_0 = _mm512_inserti32x8(_mm512_castsi256_si512(rhs_raw_mat_0145_0), rhs_raw_mat_89CD_0, 1);
|
2775
|
+
const __m512i rhs_raw_mat_2367ABEF_0 = _mm512_inserti32x8(_mm512_castsi256_si512(rhs_raw_mat_2367_0), rhs_raw_mat_ABEF_0, 1);
|
2776
|
+
const __m512i rhs_raw_mat_014589CD_1 = _mm512_inserti32x8(_mm512_castsi256_si512(rhs_raw_mat_0145_1), rhs_raw_mat_89CD_1, 1);
|
2777
|
+
const __m512i rhs_raw_mat_2367ABEF_1 = _mm512_inserti32x8(_mm512_castsi256_si512(rhs_raw_mat_2367_1), rhs_raw_mat_ABEF_1, 1);
|
2778
|
+
|
2779
|
+
// 4-bit -> 8-bit - Sign is maintained
|
2780
|
+
const __m512i rhs_mat_014589CD_0 = _mm512_shuffle_epi8(signextendlutexpanded, _mm512_and_si512(rhs_raw_mat_014589CD_0, m4bexpanded)); //B0(0-7) B1(0-7) B4(0-7) B5(0-7) B8(0-7) B9(0-7) BC(0-7) BD(0-7)
|
2781
|
+
const __m512i rhs_mat_2367ABEF_0 = _mm512_shuffle_epi8(signextendlutexpanded, _mm512_and_si512(rhs_raw_mat_2367ABEF_0, m4bexpanded)); //B2(0-7) B3(0-7) B6(0-7) B7(0-7) BA(0-7) BB(0-7) BE(0-7) BF(0-7)
|
2782
|
+
|
2783
|
+
const __m512i rhs_mat_014589CD_1 = _mm512_shuffle_epi8(signextendlutexpanded, _mm512_and_si512(rhs_raw_mat_014589CD_1, m4bexpanded)); //B0(8-15) B1(8-15) B4(8-15) B5(8-15) B8(8-15) B9(8-15) BC(8-15) BD(8-15)
|
2784
|
+
const __m512i rhs_mat_2367ABEF_1 = _mm512_shuffle_epi8(signextendlutexpanded, _mm512_and_si512(rhs_raw_mat_2367ABEF_1, m4bexpanded)); //B2(8-15) B3(8-15) B6(8-15) B7(8-15) BA(8-15) BB(8-15) BE(8-15) BF(8-15)
|
2785
|
+
|
2786
|
+
const __m512i rhs_mat_014589CD_2 = _mm512_shuffle_epi8(signextendlutexpanded, _mm512_and_si512(_mm512_srli_epi16(rhs_raw_mat_014589CD_0, 4), m4bexpanded)); //B0(16-23) B1(16-23) B4(16-23) B5(16-23) B8(16-23) B9(16-23) BC(16-23) BD(16-23)
|
2787
|
+
const __m512i rhs_mat_2367ABEF_2 = _mm512_shuffle_epi8(signextendlutexpanded, _mm512_and_si512(_mm512_srli_epi16(rhs_raw_mat_2367ABEF_0, 4), m4bexpanded)); //B2(16-23) B3(16-23) B6(16-23) B7(16-23) BA(16-23) BB(16-23) BE(16-23) BF(16-23)
|
2788
|
+
|
2789
|
+
const __m512i rhs_mat_014589CD_3 = _mm512_shuffle_epi8(signextendlutexpanded, _mm512_and_si512(_mm512_srli_epi16(rhs_raw_mat_014589CD_1, 4), m4bexpanded)); //B0(24-31) B1(24-31) B4(24-31) B5(24-31) B8(24-31) B9(24-31) BC(24-31) BD(24-31)
|
2790
|
+
const __m512i rhs_mat_2367ABEF_3 = _mm512_shuffle_epi8(signextendlutexpanded, _mm512_and_si512(_mm512_srli_epi16(rhs_raw_mat_2367ABEF_1, 4), m4bexpanded)); //B2(24-31) B3(24-31) B6(24-31) B7(24-31) BA(24-31) BB(24-31) BE(24-31) BF(24-31)
|
2791
|
+
|
2792
|
+
// Shuffle pattern one - right side input
|
2793
|
+
const __m512i rhs_mat_014589CD_0_sp1 = _mm512_shuffle_epi32(rhs_mat_014589CD_0, (_MM_PERM_ENUM)136); //B0(0-3) B1(0-3) B0(0-3) B1(0-3) B4(0-3) B5(0-3) B4(0-3) B5(0-3) B8(0-3) B9(0-3) B8(0-3) B9(0-3) BC(0-3) BD(0-3) BC(0-3) BD(0-3)
|
2794
|
+
const __m512i rhs_mat_2367ABEF_0_sp1 = _mm512_shuffle_epi32(rhs_mat_2367ABEF_0, (_MM_PERM_ENUM)136); //B2(0-3) B3(0-3) B2(0-3) B3(0-3) B6(0-3) B7(0-3) B6(0-3) B7(0-3) BA(0-3) BB(0-3) BA(0-3) BB(0-3) BE(0-3) BF(0-3) BE(0-3) BF(0-3)
|
2795
|
+
|
2796
|
+
const __m512i rhs_mat_014589CD_1_sp1 = _mm512_shuffle_epi32(rhs_mat_014589CD_1, (_MM_PERM_ENUM)136); //B0(8-11) B1(8-11) B0(8-11) B1(8-11) B4(8-11) B5(8-11) B4(8-11) B5(8-11) B8(8-11) B9(8-11) B8(8-11) B9(8-11) BC(8-11) BD(8-11) BC(8-11) BD(8-11)
|
2797
|
+
const __m512i rhs_mat_2367ABEF_1_sp1 = _mm512_shuffle_epi32(rhs_mat_2367ABEF_1, (_MM_PERM_ENUM)136); //B2(8-11) B3(8-11) B2(8-11) B3(8-11) B6(8-11) B7(8-11) B6(8-11) B7(8-11) BA(8-11) BB(8-11) BA(8-11) BB(8-11) BE(8-11) BF(8-11) BE(8-11) BF(8-11)
|
2798
|
+
|
2799
|
+
const __m512i rhs_mat_014589CD_2_sp1 = _mm512_shuffle_epi32(rhs_mat_014589CD_2, (_MM_PERM_ENUM)136); //B0(16-19) B1(16-19) B0(16-19) B1(16-19) B4(16-19) B5(16-19) B4(16-19) B5(16-19) B8(16-19) B9(16-19) B8(16-19) B9(16-19) BC(16-19) BD(16-19) BC(16-19) BD(16-19)
|
2800
|
+
const __m512i rhs_mat_2367ABEF_2_sp1 = _mm512_shuffle_epi32(rhs_mat_2367ABEF_2, (_MM_PERM_ENUM)136); //B2(16-19) B3(16-19) B2(16-19) B3(16-19) B6(16-19) B7(16-19) B6(16-19) B7(16-19) BA(16-19) BB(16-19) BA(16-19) BB(16-19) BE(16-19) BF(16-19) BE(16-19) BF(16-19)
|
2801
|
+
|
2802
|
+
const __m512i rhs_mat_014589CD_3_sp1 = _mm512_shuffle_epi32(rhs_mat_014589CD_3, (_MM_PERM_ENUM)136); //B0(24-27) B1(24-27) B0(24-27) B1(24-27) B4(24-27) B5(24-27) B4(24-27) B5(24-27) B8(24-27) B9(24-27) B8(24-27) B9(24-27) BC(24-27) BD(24-27) BC(24-27) BD(24-27)
|
2803
|
+
const __m512i rhs_mat_2367ABEF_3_sp1 = _mm512_shuffle_epi32(rhs_mat_2367ABEF_3, (_MM_PERM_ENUM)136); //B2(24-27) B3(24-27) B2(24-27) B3(24-27) B6(24-27) B7(24-27) B6(24-27) B7(24-27) BA(24-27) BB(24-27) BA(24-27) BB(24-27) BE(24-27) BF(24-27) BE(24-27) BF(24-27)
|
2804
|
+
|
2805
|
+
// Shuffle pattern two - right side input
|
2806
|
+
|
2807
|
+
const __m512i rhs_mat_014589CD_0_sp2 = _mm512_shuffle_epi32(rhs_mat_014589CD_0, (_MM_PERM_ENUM)221); //B0(4-7) B1(4-7) B0(4-7) B1(4-7) B4(4-7) B5(4-7) B4(4-7) B5(4-7) B8(4-7) B9(4-7) B8(4-7) B9(4-7) BC(4-7) BD(4-7) BC(4-7) BD(4-7)
|
2808
|
+
const __m512i rhs_mat_2367ABEF_0_sp2 = _mm512_shuffle_epi32(rhs_mat_2367ABEF_0, (_MM_PERM_ENUM)221); //B2(4-7) B3(4-7) B2(4-7) B3(4-7) B6(4-7) B7(4-7) B6(4-7) B7(4-7) BA(4-7) BB(4-7) BA(4-7) BB(4-7) BE(4-7) BF(4-7) BE(4-7) BF(4-7)
|
2809
|
+
|
2810
|
+
const __m512i rhs_mat_014589CD_1_sp2 = _mm512_shuffle_epi32(rhs_mat_014589CD_1, (_MM_PERM_ENUM)221); //B0(12-15) B1(12-15) B0(12-15) B1(12-15) B4(12-15) B5(12-15) B4(12-15) B5(12-15) B8(12-15) B9(12-15) B8(12-15) B9(12-15) BC(12-15) BD(12-15) BC(12-15) BD(12-15)
|
2811
|
+
const __m512i rhs_mat_2367ABEF_1_sp2 = _mm512_shuffle_epi32(rhs_mat_2367ABEF_1, (_MM_PERM_ENUM)221); //B2(12-15) B3(12-15) B2(12-15) B3(12-15) B6(12-15) B7(12-15) B6(12-15) B7(12-15) BA(12-15) BB(12-15) BA(12-15) BB(12-15) BE(12-15) BF(12-15) BE(12-15) BF(12-15)
|
2812
|
+
|
2813
|
+
const __m512i rhs_mat_014589CD_2_sp2 = _mm512_shuffle_epi32(rhs_mat_014589CD_2, (_MM_PERM_ENUM)221); //B0(20-23) B1(20-23) B0(20-23) B1(20-23) B4(20-23) B5(20-23) B4(20-23) B5(20-23) B8(20-23) B9(20-23) B8(20-23) B9(20-23) BC(20-23) BD(20-23) BC(20-23) BD(20-23)
|
2814
|
+
const __m512i rhs_mat_2367ABEF_2_sp2 = _mm512_shuffle_epi32(rhs_mat_2367ABEF_2, (_MM_PERM_ENUM)221); //B2(20-23) B3(20-23) B2(20-23) B3(20-23) B6(20-23) B7(20-23) B6(20-23) B7(20-23) BA(20-23) BB(20-23) BA(20-23) BB(20-23) BE(20-23) BF(20-23) BE(20-23) BF(20-23)
|
2815
|
+
|
2816
|
+
const __m512i rhs_mat_014589CD_3_sp2 = _mm512_shuffle_epi32(rhs_mat_014589CD_3, (_MM_PERM_ENUM)221); //B0(28-31) B1(28-31) B0(28-31) B1(28-31) B4(28-31) B5(28-31) B4(28-31) B5(28-31) B8(28-31) B9(28-31) B8(28-31) B9(28-31) BC(28-31) BD(28-31) BC(28-31) BD(28-31)
|
2817
|
+
const __m512i rhs_mat_2367ABEF_3_sp2 = _mm512_shuffle_epi32(rhs_mat_2367ABEF_3, (_MM_PERM_ENUM)221); //B2(28-31) B3(28-31) B2(28-31) B3(28-31) B6(28-31) B7(28-31) B6(28-31) B7(28-31) BA(28-31) BB(28-31) BA(28-31) BB(28-31) BE(28-31) BF(28-31) BE(28-31) BF(28-31)
|
2818
|
+
|
2819
|
+
|
2820
|
+
// Scale values - Load the weight scale values of two block_q4_0x8
|
2821
|
+
const __m512 col_scale_f32 = GGML_F32Cx8x2_LOAD(b_ptr_0[b].d, b_ptr_1[b].d);
|
2822
|
+
|
2823
|
+
// Load the four block_q4_0 quantized values interleaved with each other in chunks of eight - A0,A1,A2,A3
|
2824
|
+
// Loaded as set of 128 bit vectors and repeated and stored into a 256 bit vector before again repeating into 512 bit vector
|
2825
|
+
__m256i lhs_mat_ymm_0123_0 = _mm256_loadu_si256((const __m256i *)((a_ptr[b].qs)));
|
2826
|
+
__m256i lhs_mat_ymm_01_0 = _mm256_permute2f128_si256(lhs_mat_ymm_0123_0, lhs_mat_ymm_0123_0, 0);
|
2827
|
+
__m256i lhs_mat_ymm_23_0 = _mm256_permute2f128_si256(lhs_mat_ymm_0123_0, lhs_mat_ymm_0123_0, 17);
|
2828
|
+
__m256i lhs_mat_ymm_0123_1 = _mm256_loadu_si256((const __m256i *)((a_ptr[b].qs + 32)));
|
2829
|
+
__m256i lhs_mat_ymm_01_1 = _mm256_permute2f128_si256(lhs_mat_ymm_0123_1, lhs_mat_ymm_0123_1, 0);
|
2830
|
+
__m256i lhs_mat_ymm_23_1 = _mm256_permute2f128_si256(lhs_mat_ymm_0123_1, lhs_mat_ymm_0123_1, 17);
|
2831
|
+
__m256i lhs_mat_ymm_0123_2 = _mm256_loadu_si256((const __m256i *)((a_ptr[b].qs + 64)));
|
2832
|
+
__m256i lhs_mat_ymm_01_2 = _mm256_permute2f128_si256(lhs_mat_ymm_0123_2, lhs_mat_ymm_0123_2, 0);
|
2833
|
+
__m256i lhs_mat_ymm_23_2 = _mm256_permute2f128_si256(lhs_mat_ymm_0123_2, lhs_mat_ymm_0123_2, 17);
|
2834
|
+
__m256i lhs_mat_ymm_0123_3 = _mm256_loadu_si256((const __m256i *)((a_ptr[b].qs + 96)));
|
2835
|
+
__m256i lhs_mat_ymm_01_3 = _mm256_permute2f128_si256(lhs_mat_ymm_0123_3, lhs_mat_ymm_0123_3, 0);
|
2836
|
+
__m256i lhs_mat_ymm_23_3 = _mm256_permute2f128_si256(lhs_mat_ymm_0123_3, lhs_mat_ymm_0123_3, 17);
|
2837
|
+
|
2838
|
+
__m512i lhs_mat_01_0 = _mm512_inserti32x8(_mm512_castsi256_si512(lhs_mat_ymm_01_0), lhs_mat_ymm_01_0, 1);
|
2839
|
+
__m512i lhs_mat_23_0 = _mm512_inserti32x8(_mm512_castsi256_si512(lhs_mat_ymm_23_0), lhs_mat_ymm_23_0, 1);
|
2840
|
+
__m512i lhs_mat_01_1 = _mm512_inserti32x8(_mm512_castsi256_si512(lhs_mat_ymm_01_1), lhs_mat_ymm_01_1, 1);
|
2841
|
+
__m512i lhs_mat_23_1 = _mm512_inserti32x8(_mm512_castsi256_si512(lhs_mat_ymm_23_1), lhs_mat_ymm_23_1, 1);
|
2842
|
+
__m512i lhs_mat_01_2 = _mm512_inserti32x8(_mm512_castsi256_si512(lhs_mat_ymm_01_2), lhs_mat_ymm_01_2, 1);
|
2843
|
+
__m512i lhs_mat_23_2 = _mm512_inserti32x8(_mm512_castsi256_si512(lhs_mat_ymm_23_2), lhs_mat_ymm_23_2, 1);
|
2844
|
+
__m512i lhs_mat_01_3 = _mm512_inserti32x8(_mm512_castsi256_si512(lhs_mat_ymm_01_3), lhs_mat_ymm_01_3, 1);
|
2845
|
+
__m512i lhs_mat_23_3 = _mm512_inserti32x8(_mm512_castsi256_si512(lhs_mat_ymm_23_3), lhs_mat_ymm_23_3, 1);
|
2846
|
+
|
2847
|
+
// Shuffle pattern one - left side input
|
2848
|
+
|
2849
|
+
const __m512i lhs_mat_01_0_sp1 = _mm512_shuffle_epi32(lhs_mat_01_0, (_MM_PERM_ENUM)160); //A0(0-3) A0(0-3) A1(0-3) A1(0-3) A0(0-3) A0(0-3) A1(0-3) A1(0-3) A0(0-3) A0(0-3) A1(0-3) A1(0-3) A0(0-3) A0(0-3) A1(0-3) A1(0-3)
|
2850
|
+
const __m512i lhs_mat_23_0_sp1 = _mm512_shuffle_epi32(lhs_mat_23_0, (_MM_PERM_ENUM)160); //A2(0-3) A2(0-3) A3(0-3) A3(0-3) A2(0-3) A2(0-3) A3(0-3) A3(0-3) A2(0-3) A2(0-3) A3(0-3) A3(0-3) A2(0-3) A2(0-3) A3(0-3) A3(0-3)
|
2851
|
+
|
2852
|
+
const __m512i lhs_mat_01_1_sp1 = _mm512_shuffle_epi32(lhs_mat_01_1, (_MM_PERM_ENUM)160); //A0(8-11) A0(8-11) A1(8-11) A1(8-11) A0(8-11) A0(8-11) A1(8-11) A1(8-11) A0(8-11) A0(8-11) A1(8-11) A1(8-11) A0(8-11) A0(8-11) A1(8-11) A1(8-11)
|
2853
|
+
const __m512i lhs_mat_23_1_sp1 = _mm512_shuffle_epi32(lhs_mat_23_1, (_MM_PERM_ENUM)160); //A2(8-11) A2(8-11) A3(8-11) A3(8-11) A2(8-11) A2(8-11) A3(8-11) A3(8-11) A2(8-11) A2(8-11) A3(8-11) A3(8-11) A2(8-11) A2(8-11) A3(8-11) A3(8-11)
|
2854
|
+
|
2855
|
+
const __m512i lhs_mat_01_2_sp1 = _mm512_shuffle_epi32(lhs_mat_01_2, (_MM_PERM_ENUM)160); //A0(16-19) A0(16-19) A1(16-19) A1(16-19) A0(16-19) A0(16-19) A1(16-19) A1(16-19) A0(16-19) A0(16-19) A1(16-19) A1(16-19) A0(16-19) A0(16-19) A1(16-19) A1(16-19)
|
2856
|
+
const __m512i lhs_mat_23_2_sp1 = _mm512_shuffle_epi32(lhs_mat_23_2, (_MM_PERM_ENUM)160); //A2(16-19) A2(16-19) A3(16-19) A3(16-19) A2(16-19) A2(16-19) A3(16-19) A3(16-19) A2(16-19) A2(16-19) A3(16-19) A3(16-19) A2(16-19) A2(16-19) A3(16-19) A3(16-19)
|
2857
|
+
|
2858
|
+
const __m512i lhs_mat_01_3_sp1 = _mm512_shuffle_epi32(lhs_mat_01_3, (_MM_PERM_ENUM)160); //A0(24-27) A0(24-27) A1(24-27) A1(24-27) A0(24-27) A0(24-27) A1(24-27) A1(24-27) A0(24-27) A0(24-27) A1(24-27) A1(24-27) A0(24-27) A0(24-27) A1(24-27) A1(24-27)
|
2859
|
+
const __m512i lhs_mat_23_3_sp1 = _mm512_shuffle_epi32(lhs_mat_23_3, (_MM_PERM_ENUM)160); //A2(24-27) A2(24-27) A3(24-27) A3(24-27) A2(24-27) A2(24-27) A3(24-27) A3(24-27) A2(24-27) A2(24-27) A3(24-27) A3(24-27) A2(24-27) A2(24-27) A3(24-27) A3(24-27)
|
2860
|
+
|
2861
|
+
// Shuffle pattern two - left side input
|
2862
|
+
|
2863
|
+
const __m512i lhs_mat_01_0_sp2 = _mm512_shuffle_epi32(lhs_mat_01_0, (_MM_PERM_ENUM)245); //A0(4-7) A0(4-7) A1(4-7) A1(4-7) A0(4-7) A0(4-7) A1(4-7) A1(4-7) A0(4-7) A0(4-7) A1(4-7) A1(4-7) A0(4-7) A0(4-7) A1(4-7) A1(4-7)
|
2864
|
+
const __m512i lhs_mat_23_0_sp2 = _mm512_shuffle_epi32(lhs_mat_23_0, (_MM_PERM_ENUM)245); //A2(4-7) A2(4-7) A3(4-7) A3(4-7) A2(4-7) A2(4-7) A3(4-7) A3(4-7) A2(4-7) A2(4-7) A3(4-7) A3(4-7) A2(4-7) A2(4-7) A3(4-7) A3(4-7)
|
2865
|
+
|
2866
|
+
const __m512i lhs_mat_01_1_sp2 = _mm512_shuffle_epi32(lhs_mat_01_1, (_MM_PERM_ENUM)245); //A0(12-15) A0(12-15) A1(12-15) A1(12-15) A0(12-15) A0(12-15) A1(12-15) A1(12-15) A0(12-15) A0(12-15) A1(12-15) A1(12-15) A0(12-15) A0(12-15) A1(12-15) A1(12-15)
|
2867
|
+
const __m512i lhs_mat_23_1_sp2 = _mm512_shuffle_epi32(lhs_mat_23_1, (_MM_PERM_ENUM)245); //A2(12-15) A2(12-15) A3(12-15) A3(12-15) A2(12-15) A2(12-15) A3(12-15) A3(12-15) A2(12-15) A2(12-15) A3(12-15) A3(12-15) A2(12-15) A2(12-15) A3(12-15) A3(12-15)
|
2868
|
+
|
2869
|
+
const __m512i lhs_mat_01_2_sp2 = _mm512_shuffle_epi32(lhs_mat_01_2, (_MM_PERM_ENUM)245); //A0(20-23) A0(20-23) A1(20-23) A1(20-23) A0(20-23) A0(20-23) A1(20-23) A1(20-23) A0(20-23) A0(20-23) A1(20-23) A1(20-23) A0(20-23) A0(20-23) A1(20-23) A1(20-23)
|
2870
|
+
const __m512i lhs_mat_23_2_sp2 = _mm512_shuffle_epi32(lhs_mat_23_2, (_MM_PERM_ENUM)245); //A2(20-23) A2(20-23) A3(20-23) A3(20-23) A2(20-23) A2(20-23) A3(20-23) A3(20-23) A2(20-23) A2(20-23) A3(20-23) A3(20-23) A2(20-23) A2(20-23) A3(20-23) A3(20-23)
|
2871
|
+
|
2872
|
+
const __m512i lhs_mat_01_3_sp2 = _mm512_shuffle_epi32(lhs_mat_01_3, (_MM_PERM_ENUM)245); //A0(28-31) A0(28-31) A1(28-31) A1(28-31) A0(28-31) A0(28-31) A1(28-31) A1(28-31) A0(28-31) A0(28-31) A1(28-31) A1(28-31) A0(28-31) A0(28-31) A1(28-31) A1(28-31)
|
2873
|
+
const __m512i lhs_mat_23_3_sp2 = _mm512_shuffle_epi32(lhs_mat_23_3, (_MM_PERM_ENUM)245); //A2(28-31) A2(28-31) A3(28-31) A3(28-31) A2(28-31) A2(28-31) A3(28-31) A3(28-31) A2(28-31) A2(28-31) A3(28-31) A3(28-31) A2(28-31) A2(28-31) A3(28-31) A3(28-31)
|
2874
|
+
|
2875
|
+
// The values arranged in shuffle patterns are operated with dot product operation within 32 bit lane i.e corresponding bytes and multiplied and added into 32 bit integers within 32 bit lane
|
2876
|
+
// Resembles MMLAs into 2x2 matrices in ARM Version
|
2877
|
+
__m512i iacc_mat_00_sp1 =
|
2878
|
+
_mm512_add_epi32(_mm512_add_epi32(_mm512_add_epi32(mul_sum_i8_pairs_int32x16(lhs_mat_01_3_sp1, rhs_mat_014589CD_3_sp1), mul_sum_i8_pairs_int32x16(lhs_mat_01_2_sp1, rhs_mat_014589CD_2_sp1)), mul_sum_i8_pairs_int32x16(lhs_mat_01_1_sp1, rhs_mat_014589CD_1_sp1)), mul_sum_i8_pairs_int32x16(lhs_mat_01_0_sp1, rhs_mat_014589CD_0_sp1));
|
2879
|
+
__m512i iacc_mat_01_sp1 =
|
2880
|
+
_mm512_add_epi32(_mm512_add_epi32(_mm512_add_epi32(mul_sum_i8_pairs_int32x16(lhs_mat_01_3_sp1, rhs_mat_2367ABEF_3_sp1), mul_sum_i8_pairs_int32x16(lhs_mat_01_2_sp1, rhs_mat_2367ABEF_2_sp1)), mul_sum_i8_pairs_int32x16(lhs_mat_01_1_sp1, rhs_mat_2367ABEF_1_sp1)), mul_sum_i8_pairs_int32x16(lhs_mat_01_0_sp1, rhs_mat_2367ABEF_0_sp1));
|
2881
|
+
__m512i iacc_mat_10_sp1 =
|
2882
|
+
_mm512_add_epi32(_mm512_add_epi32(_mm512_add_epi32(mul_sum_i8_pairs_int32x16(lhs_mat_23_3_sp1, rhs_mat_014589CD_3_sp1), mul_sum_i8_pairs_int32x16(lhs_mat_23_2_sp1, rhs_mat_014589CD_2_sp1)), mul_sum_i8_pairs_int32x16(lhs_mat_23_1_sp1, rhs_mat_014589CD_1_sp1)), mul_sum_i8_pairs_int32x16(lhs_mat_23_0_sp1, rhs_mat_014589CD_0_sp1));
|
2883
|
+
__m512i iacc_mat_11_sp1 =
|
2884
|
+
_mm512_add_epi32(_mm512_add_epi32(_mm512_add_epi32(mul_sum_i8_pairs_int32x16(lhs_mat_23_3_sp1, rhs_mat_2367ABEF_3_sp1), mul_sum_i8_pairs_int32x16(lhs_mat_23_2_sp1, rhs_mat_2367ABEF_2_sp1)), mul_sum_i8_pairs_int32x16(lhs_mat_23_1_sp1, rhs_mat_2367ABEF_1_sp1)), mul_sum_i8_pairs_int32x16(lhs_mat_23_0_sp1, rhs_mat_2367ABEF_0_sp1));
|
2885
|
+
__m512i iacc_mat_00_sp2 =
|
2886
|
+
_mm512_add_epi32(_mm512_add_epi32(_mm512_add_epi32(mul_sum_i8_pairs_int32x16(lhs_mat_01_3_sp2, rhs_mat_014589CD_3_sp2), mul_sum_i8_pairs_int32x16(lhs_mat_01_2_sp2, rhs_mat_014589CD_2_sp2)), mul_sum_i8_pairs_int32x16(lhs_mat_01_1_sp2, rhs_mat_014589CD_1_sp2)), mul_sum_i8_pairs_int32x16(lhs_mat_01_0_sp2, rhs_mat_014589CD_0_sp2));
|
2887
|
+
__m512i iacc_mat_01_sp2 =
|
2888
|
+
_mm512_add_epi32(_mm512_add_epi32(_mm512_add_epi32(mul_sum_i8_pairs_int32x16(lhs_mat_01_3_sp2, rhs_mat_2367ABEF_3_sp2), mul_sum_i8_pairs_int32x16(lhs_mat_01_2_sp2, rhs_mat_2367ABEF_2_sp2)), mul_sum_i8_pairs_int32x16(lhs_mat_01_1_sp2, rhs_mat_2367ABEF_1_sp2)), mul_sum_i8_pairs_int32x16(lhs_mat_01_0_sp2, rhs_mat_2367ABEF_0_sp2));
|
2889
|
+
__m512i iacc_mat_10_sp2 =
|
2890
|
+
_mm512_add_epi32(_mm512_add_epi32(_mm512_add_epi32(mul_sum_i8_pairs_int32x16(lhs_mat_23_3_sp2, rhs_mat_014589CD_3_sp2), mul_sum_i8_pairs_int32x16(lhs_mat_23_2_sp2, rhs_mat_014589CD_2_sp2)), mul_sum_i8_pairs_int32x16(lhs_mat_23_1_sp2, rhs_mat_014589CD_1_sp2)), mul_sum_i8_pairs_int32x16(lhs_mat_23_0_sp2, rhs_mat_014589CD_0_sp2));
|
2891
|
+
__m512i iacc_mat_11_sp2 =
|
2892
|
+
_mm512_add_epi32(_mm512_add_epi32(_mm512_add_epi32(mul_sum_i8_pairs_int32x16(lhs_mat_23_3_sp2, rhs_mat_2367ABEF_3_sp2), mul_sum_i8_pairs_int32x16(lhs_mat_23_2_sp2, rhs_mat_2367ABEF_2_sp2)), mul_sum_i8_pairs_int32x16(lhs_mat_23_1_sp2, rhs_mat_2367ABEF_1_sp2)), mul_sum_i8_pairs_int32x16(lhs_mat_23_0_sp2, rhs_mat_2367ABEF_0_sp2));
|
2893
|
+
|
2894
|
+
// Output of both shuffle patterns are added in order to sum dot product outputs of all 32 values in block
|
2895
|
+
__m512i iacc_mat_00 = _mm512_add_epi32(iacc_mat_00_sp1, iacc_mat_00_sp2);
|
2896
|
+
__m512i iacc_mat_01 = _mm512_add_epi32(iacc_mat_01_sp1, iacc_mat_01_sp2);
|
2897
|
+
__m512i iacc_mat_10 = _mm512_add_epi32(iacc_mat_10_sp1, iacc_mat_10_sp2);
|
2898
|
+
__m512i iacc_mat_11 = _mm512_add_epi32(iacc_mat_11_sp1, iacc_mat_11_sp2);
|
2899
|
+
|
2900
|
+
|
2901
|
+
// Straighten out to make 4 row vectors
|
2902
|
+
__m512i iacc_row_0 = _mm512_mask_blend_epi32(0xCCCC, iacc_mat_00, _mm512_shuffle_epi32(iacc_mat_01, (_MM_PERM_ENUM)78));
|
2903
|
+
__m512i iacc_row_1 = _mm512_mask_blend_epi32(0xCCCC, _mm512_shuffle_epi32(iacc_mat_00, (_MM_PERM_ENUM)78), iacc_mat_01);
|
2904
|
+
__m512i iacc_row_2 = _mm512_mask_blend_epi32(0xCCCC, iacc_mat_10, _mm512_shuffle_epi32(iacc_mat_11, (_MM_PERM_ENUM)78));
|
2905
|
+
__m512i iacc_row_3 = _mm512_mask_blend_epi32(0xCCCC, _mm512_shuffle_epi32(iacc_mat_10, (_MM_PERM_ENUM)78), iacc_mat_11);
|
2906
|
+
|
2907
|
+
// Load the scale(d) values for all the 4 Q8_0 blocks and repeat it across lanes
|
2908
|
+
const __m128i row_scale_f16 = _mm_shuffle_epi32(_mm_maskload_epi32((int const*)(a_ptr[b].d), loadMask), 68);
|
2909
|
+
const __m512 row_scale_f32 = GGML_F32Cx16_REPEAT_LOAD(row_scale_f16);
|
2910
|
+
|
2911
|
+
// Multiply with appropiate scales and accumulate
|
2912
|
+
acc_rows[0] = _mm512_fmadd_ps(_mm512_cvtepi32_ps(iacc_row_0), _mm512_mul_ps(col_scale_f32, _mm512_shuffle_ps(row_scale_f32, row_scale_f32, 0)), acc_rows[0]);
|
2913
|
+
acc_rows[1] = _mm512_fmadd_ps(_mm512_cvtepi32_ps(iacc_row_1), _mm512_mul_ps(col_scale_f32, _mm512_shuffle_ps(row_scale_f32, row_scale_f32, 85)), acc_rows[1]);
|
2914
|
+
acc_rows[2] = _mm512_fmadd_ps(_mm512_cvtepi32_ps(iacc_row_2), _mm512_mul_ps(col_scale_f32, _mm512_shuffle_ps(row_scale_f32, row_scale_f32, 170)), acc_rows[2]);
|
2915
|
+
acc_rows[3] = _mm512_fmadd_ps(_mm512_cvtepi32_ps(iacc_row_3), _mm512_mul_ps(col_scale_f32, _mm512_shuffle_ps(row_scale_f32, row_scale_f32, 255)), acc_rows[3]);
|
2916
|
+
}
|
2917
|
+
|
2918
|
+
// Store the accumulated values
|
2919
|
+
for (int i = 0; i < 4; i++) {
|
2920
|
+
_mm512_storeu_ps((float *)(s + ((y * 4 + i) * bs + x * 8)), acc_rows[i]);
|
2921
|
+
}
|
2922
|
+
}
|
2923
|
+
}
|
2924
|
+
if (anc != nc) {
|
2925
|
+
xstart = anc/8;
|
2926
|
+
y = 0;
|
2927
|
+
}
|
2928
|
+
#endif // __AVX512F__
|
2929
|
+
|
2930
|
+
// Take group of four block_q8_0x4 structures at each pass of the loop and perform dot product operation
|
2931
|
+
|
2932
|
+
for (; y < anr / 4; y += 4) {
|
2933
|
+
const block_q8_0x4 * a_ptrs[4];
|
2934
|
+
|
2935
|
+
a_ptrs[0] = a_ptr_start + (y * nb);
|
2936
|
+
for (int i = 0; i < 3; ++i) {
|
2937
|
+
a_ptrs[i + 1] = a_ptrs[i] + nb;
|
2938
|
+
}
|
2939
|
+
|
2940
|
+
// Take group of eight block_q4_0x8 structures at each pass of the loop and perform dot product operation
|
2941
|
+
for (int64_t x = xstart; x < nc / 8; x++) {
|
2942
|
+
|
2943
|
+
const block_q4_0x8 * b_ptr = b_ptr_start + (x * b_nb);
|
2944
|
+
|
2945
|
+
// Master FP accumulators
|
2946
|
+
__m256 acc_rows[16];
|
2947
|
+
for (int i = 0; i < 16; i++) {
|
2948
|
+
acc_rows[i] = _mm256_setzero_ps();
|
2949
|
+
}
|
2950
|
+
|
2951
|
+
for (int64_t b = 0; b < nb; b++) {
|
2952
|
+
// Load the eight block_q4_0 quantized values interleaved with each other in chunks of eight - B0,B1 ....B6,B7
|
2953
|
+
const __m256i rhs_raw_mat_0123_0 = _mm256_loadu_si256((const __m256i *)(b_ptr[b].qs));
|
2954
|
+
const __m256i rhs_raw_mat_4567_0 = _mm256_loadu_si256((const __m256i *)(b_ptr[b].qs + 32));
|
2955
|
+
const __m256i rhs_raw_mat_0123_1 = _mm256_loadu_si256((const __m256i *)(b_ptr[b].qs + 64));
|
2956
|
+
const __m256i rhs_raw_mat_4567_1 = _mm256_loadu_si256((const __m256i *)(b_ptr[b].qs + 96));
|
2957
|
+
|
2958
|
+
// Save the values in the following vectors in the formats B0B1B4B5, B2B3B6B7 for further processing and storing of values
|
2959
|
+
const __m256i rhs_raw_mat_0145_0 = _mm256_blend_epi32(rhs_raw_mat_0123_0, _mm256_permutevar8x32_epi32(rhs_raw_mat_4567_0, requiredOrder), 240);
|
2960
|
+
const __m256i rhs_raw_mat_2367_0 = _mm256_blend_epi32(_mm256_permutevar8x32_epi32(rhs_raw_mat_0123_0, requiredOrder), rhs_raw_mat_4567_0, 240);
|
2961
|
+
const __m256i rhs_raw_mat_0145_1 = _mm256_blend_epi32(rhs_raw_mat_0123_1, _mm256_permutevar8x32_epi32(rhs_raw_mat_4567_1, requiredOrder), 240);
|
2962
|
+
const __m256i rhs_raw_mat_2367_1 = _mm256_blend_epi32(_mm256_permutevar8x32_epi32(rhs_raw_mat_0123_1, requiredOrder), rhs_raw_mat_4567_1, 240);
|
2963
|
+
|
2964
|
+
// 4-bit -> 8-bit - Sign is maintained
|
2965
|
+
const __m256i rhs_mat_0145_0 = _mm256_shuffle_epi8(signextendlut, _mm256_and_si256(rhs_raw_mat_0145_0, m4b)); //B0(0-7) B1(0-7) B4(0-7) B5(0-7)
|
2966
|
+
const __m256i rhs_mat_2367_0 = _mm256_shuffle_epi8(signextendlut, _mm256_and_si256(rhs_raw_mat_2367_0, m4b)); //B2(0-7) B3(0-7) B6(0-7) B7(0-7)
|
2967
|
+
|
2968
|
+
const __m256i rhs_mat_0145_1 = _mm256_shuffle_epi8(signextendlut, _mm256_and_si256(rhs_raw_mat_0145_1, m4b)); //B0(8-15) B1(8-15) B4(8-15) B5(8-15)
|
2969
|
+
const __m256i rhs_mat_2367_1 = _mm256_shuffle_epi8(signextendlut, _mm256_and_si256(rhs_raw_mat_2367_1, m4b)); //B2(8-15) B3(8-15) B6(8-15) B7(8-15)
|
2970
|
+
|
2971
|
+
const __m256i rhs_mat_0145_2 = _mm256_shuffle_epi8(signextendlut, _mm256_and_si256(_mm256_srli_epi16(rhs_raw_mat_0145_0, 4), m4b)); //B0(16-23) B1(16-23) B4(16-23) B5(16-23)
|
2972
|
+
const __m256i rhs_mat_2367_2 = _mm256_shuffle_epi8(signextendlut, _mm256_and_si256(_mm256_srli_epi16(rhs_raw_mat_2367_0, 4), m4b)); //B2(16-23) B3(16-23) B6(16-23) B7(16-23)
|
2973
|
+
|
2974
|
+
const __m256i rhs_mat_0145_3 = _mm256_shuffle_epi8(signextendlut, _mm256_and_si256(_mm256_srli_epi16(rhs_raw_mat_0145_1, 4), m4b)); //B0(24-31) B1(24-31) B4(24-31) B5(24-31)
|
2975
|
+
const __m256i rhs_mat_2367_3 = _mm256_shuffle_epi8(signextendlut, _mm256_and_si256(_mm256_srli_epi16(rhs_raw_mat_2367_1, 4), m4b)); //B2(24-31) B3(24-31) B6(24-31) B7(24-31)
|
2976
|
+
|
2977
|
+
// Shuffle pattern one - right side input
|
2978
|
+
const __m256i rhs_mat_0145_0_sp1 = _mm256_shuffle_epi32(rhs_mat_0145_0, 136); //B0(0-3) B1(0-3) B0(0-3) B1(0-3) B4(0-3) B5(0-3) B4(0-3) B5(0-3)
|
2979
|
+
const __m256i rhs_mat_2367_0_sp1 = _mm256_shuffle_epi32(rhs_mat_2367_0, 136); //B2(0-3) B3(0-3) B2(0-3) B3(0-3) B6(0-3) B7(0-3) B6(0-3) B7(0-3)
|
2980
|
+
|
2981
|
+
const __m256i rhs_mat_0145_1_sp1 = _mm256_shuffle_epi32(rhs_mat_0145_1, 136); //B0(8-11) B1(8-11) B0(8-11) B1(8-11) B4(8-11) B5(8-11) B4(8-11) B5(8-11)
|
2982
|
+
const __m256i rhs_mat_2367_1_sp1 = _mm256_shuffle_epi32(rhs_mat_2367_1, 136); //B2(8-11) B3(8-11) B2(8-11) B3(8-11) B6(8-11) B7(8-11) B6(8-11) B7(8-11)
|
2983
|
+
|
2984
|
+
const __m256i rhs_mat_0145_2_sp1 = _mm256_shuffle_epi32(rhs_mat_0145_2, 136); //B0(16-19) B1(16-19) B0(16-19) B1(16-19) B4(16-19) B5(16-19) B4(16-19) B5(16-19)
|
2985
|
+
const __m256i rhs_mat_2367_2_sp1 = _mm256_shuffle_epi32(rhs_mat_2367_2, 136); //B2(16-19) B3(16-19) B2(16-19) B3(16-19) B6(16-19) B7(16-19) B6(16-19) B7(16-19)
|
2986
|
+
|
2987
|
+
const __m256i rhs_mat_0145_3_sp1 = _mm256_shuffle_epi32(rhs_mat_0145_3, 136); //B0(24-27) B1(24-27) B0(24-27) B1(24-27) B4(24-27) B5(24-27) B4(24-27) B5(24-27)
|
2988
|
+
const __m256i rhs_mat_2367_3_sp1 = _mm256_shuffle_epi32(rhs_mat_2367_3, 136); //B2(24-27) B3(24-27) B2(24-27) B3(24-27) B6(24-27) B7(24-27) B6(24-27) B7(24-27)
|
2989
|
+
|
2990
|
+
// Shuffle pattern two - right side input
|
2991
|
+
|
2992
|
+
const __m256i rhs_mat_0145_0_sp2 = _mm256_shuffle_epi32(rhs_mat_0145_0, 221); //B0(4-7) B1(4-7) B0(4-7) B1(4-7) B4(4-7) B5(4-7) B4(4-7) B5(4-7)
|
2993
|
+
const __m256i rhs_mat_2367_0_sp2 = _mm256_shuffle_epi32(rhs_mat_2367_0, 221); //B2(4-7) B3(4-7) B2(4-7) B3(4-7) B6(4-7) B7(4-7) B6(4-7) B7(4-7)
|
2994
|
+
|
2995
|
+
const __m256i rhs_mat_0145_1_sp2 = _mm256_shuffle_epi32(rhs_mat_0145_1, 221); //B0(12-15) B1(12-15) B0(12-15) B1(12-15) B4(12-15) B5(12-15) B4(12-15) B5(12-15)
|
2996
|
+
const __m256i rhs_mat_2367_1_sp2 = _mm256_shuffle_epi32(rhs_mat_2367_1, 221); //B2(12-15) B3(12-15) B2(12-15) B3(12-15) B6(12-15) B7(12-15) B6(12-15) B7(12-15)
|
2997
|
+
|
2998
|
+
const __m256i rhs_mat_0145_2_sp2 = _mm256_shuffle_epi32(rhs_mat_0145_2, 221); //B0(20-23) B1(20-23) B0(20-23) B1(20-23) B4(20-23) B5(20-23) B4(20-23) B5(20-23)
|
2999
|
+
const __m256i rhs_mat_2367_2_sp2 = _mm256_shuffle_epi32(rhs_mat_2367_2, 221); //B2(20-23) B3(20-23) B2(20-23) B3(20-23) B6(20-23) B7(20-23) B6(20-23) B7(20-23)
|
3000
|
+
|
3001
|
+
const __m256i rhs_mat_0145_3_sp2 = _mm256_shuffle_epi32(rhs_mat_0145_3, 221); //B0(28-31) B1(28-31) B0(28-31) B1(28-31) B4(28-31) B5(28-31) B4(28-31) B5(28-31)
|
3002
|
+
const __m256i rhs_mat_2367_3_sp2 = _mm256_shuffle_epi32(rhs_mat_2367_3, 221); //B2(28-31) B3(28-31) B2(28-31) B3(28-31) B6(28-31) B7(28-31) B6(28-31) B7(28-31)
|
3003
|
+
|
3004
|
+
// Scale values - Load the wight scale values of block_q4_0x8
|
3005
|
+
const __m256 col_scale_f32 = GGML_F32Cx8_LOAD(b_ptr[b].d);
|
3006
|
+
|
3007
|
+
// Process LHS in groups of four
|
3008
|
+
for (int rp = 0; rp < 4; rp++) {
|
3009
|
+
// Load the four block_q4_0 quantized values interleaved with each other in chunks of eight - A0,A1,A2,A3
|
3010
|
+
// Loaded as set of 128 bit vectors and repeated into a 256 bit vector
|
3011
|
+
__m256i lhs_mat_0123_0 = _mm256_loadu_si256((const __m256i *)((a_ptrs[rp][b].qs)));
|
3012
|
+
__m256i lhs_mat_01_0 = _mm256_permute2f128_si256(lhs_mat_0123_0, lhs_mat_0123_0, 0);
|
3013
|
+
__m256i lhs_mat_23_0 = _mm256_permute2f128_si256(lhs_mat_0123_0, lhs_mat_0123_0, 17);
|
3014
|
+
__m256i lhs_mat_0123_1 = _mm256_loadu_si256((const __m256i *)((a_ptrs[rp][b].qs + 32)));
|
3015
|
+
__m256i lhs_mat_01_1 = _mm256_permute2f128_si256(lhs_mat_0123_1, lhs_mat_0123_1, 0);
|
3016
|
+
__m256i lhs_mat_23_1 = _mm256_permute2f128_si256(lhs_mat_0123_1, lhs_mat_0123_1, 17);
|
3017
|
+
__m256i lhs_mat_0123_2 = _mm256_loadu_si256((const __m256i *)((a_ptrs[rp][b].qs + 64)));
|
3018
|
+
__m256i lhs_mat_01_2 = _mm256_permute2f128_si256(lhs_mat_0123_2, lhs_mat_0123_2, 0);
|
3019
|
+
__m256i lhs_mat_23_2 = _mm256_permute2f128_si256(lhs_mat_0123_2, lhs_mat_0123_2, 17);
|
3020
|
+
__m256i lhs_mat_0123_3 = _mm256_loadu_si256((const __m256i *)((a_ptrs[rp][b].qs + 96)));
|
3021
|
+
__m256i lhs_mat_01_3 = _mm256_permute2f128_si256(lhs_mat_0123_3, lhs_mat_0123_3, 0);
|
3022
|
+
__m256i lhs_mat_23_3 = _mm256_permute2f128_si256(lhs_mat_0123_3, lhs_mat_0123_3, 17);
|
3023
|
+
|
3024
|
+
// Shuffle pattern one - left side input
|
3025
|
+
const __m256i lhs_mat_01_0_sp1 = _mm256_shuffle_epi32(lhs_mat_01_0, 160); //A0(0-3) A0(0-3) A1(0-3) A1(0-3) A0(0-3) A0(0-3) A1(0-3) A1(0-3)
|
3026
|
+
const __m256i lhs_mat_23_0_sp1 = _mm256_shuffle_epi32(lhs_mat_23_0, 160); //A2(0-3) A2(0-3) A3(0-3) A3(0-3) A2(0-3) A2(0-3) A3(0-3) A3(0-3)
|
3027
|
+
|
3028
|
+
const __m256i lhs_mat_01_1_sp1 = _mm256_shuffle_epi32(lhs_mat_01_1, 160); //A0(8-11) A0(8-11) A1(8-11) A1(8-11) A0(8-11) A0(8-11) A1(8-11) A1(8-11)
|
3029
|
+
const __m256i lhs_mat_23_1_sp1 = _mm256_shuffle_epi32(lhs_mat_23_1, 160); //A2(8-11) A2(8-11) A3(8-11) A3(8-11) A2(8-11) A2(8-11) A3(8-11) A3(8-11)
|
3030
|
+
|
3031
|
+
const __m256i lhs_mat_01_2_sp1 = _mm256_shuffle_epi32(lhs_mat_01_2, 160); //A0(16-19) A0(16-19) A1(16-19) A1(16-19) A0(16-19) A0(16-19) A1(16-19) A1(16-19)
|
3032
|
+
const __m256i lhs_mat_23_2_sp1 = _mm256_shuffle_epi32(lhs_mat_23_2, 160); //A2(16-19) A2(16-19) A3(16-19) A3(16-19) A2(16-19) A2(16-19) A3(16-19) A3(16-19)
|
3033
|
+
|
3034
|
+
const __m256i lhs_mat_01_3_sp1 = _mm256_shuffle_epi32(lhs_mat_01_3, 160); //A0(24-27) A0(24-27) A1(24-27) A1(24-27) A0(24-27) A0(24-27) A1(24-27) A1(24-27)
|
3035
|
+
const __m256i lhs_mat_23_3_sp1 = _mm256_shuffle_epi32(lhs_mat_23_3, 160); //A2(24-27) A2(24-27) A3(24-27) A3(24-27) A2(24-27) A2(24-27) A3(24-27) A3(24-27)
|
3036
|
+
|
3037
|
+
// Shuffle pattern two - left side input
|
3038
|
+
const __m256i lhs_mat_01_0_sp2 = _mm256_shuffle_epi32(lhs_mat_01_0, 245); //A0(4-7) A0(4-7) A1(4-7) A1(4-7) A0(4-7) A0(4-7) A1(4-7) A1(4-7)
|
3039
|
+
const __m256i lhs_mat_23_0_sp2 = _mm256_shuffle_epi32(lhs_mat_23_0, 245); //A2(4-7) A2(4-7) A3(4-7) A3(4-7) A2(4-7) A2(4-7) A3(4-7) A3(4-7)
|
3040
|
+
|
3041
|
+
const __m256i lhs_mat_01_1_sp2 = _mm256_shuffle_epi32(lhs_mat_01_1, 245); //A0(12-15) A0(12-15) A1(12-15) A1(12-15) A0(12-15) A0(12-15) A1(12-15) A1(12-15)
|
3042
|
+
const __m256i lhs_mat_23_1_sp2 = _mm256_shuffle_epi32(lhs_mat_23_1, 245); //A2(12-15) A2(12-15) A3(12-15) A3(12-15) A2(12-15) A2(12-15) A3(12-15) A3(12-15)
|
3043
|
+
|
3044
|
+
const __m256i lhs_mat_01_2_sp2 = _mm256_shuffle_epi32(lhs_mat_01_2, 245); //A0(20-23) A0(20-23) A1(20-23) A1(20-23) A0(20-23) A0(20-23) A1(20-23) A1(20-23)
|
3045
|
+
const __m256i lhs_mat_23_2_sp2 = _mm256_shuffle_epi32(lhs_mat_23_2, 245); //A2(20-23) A2(20-23) A3(20-23) A3(20-23) A2(20-23) A2(20-23) A3(20-23) A3(20-23)
|
3046
|
+
|
3047
|
+
const __m256i lhs_mat_01_3_sp2 = _mm256_shuffle_epi32(lhs_mat_01_3, 245); //A0(28-31) A0(28-31) A1(28-31) A1(28-31) A0(28-31) A0(28-31) A1(28-31) A1(28-31)
|
3048
|
+
const __m256i lhs_mat_23_3_sp2 = _mm256_shuffle_epi32(lhs_mat_23_3, 245); //A2(28-31) A2(28-31) A3(28-31) A3(28-31) A2(28-31) A2(28-31) A3(28-31) A3(28-31)
|
3049
|
+
|
3050
|
+
// The values arranged in shuffle patterns are operated with dot product operation within 32 bit lane i.e corresponding bytes and multiplied and added into 32 bit integers within 32 bit lane
|
3051
|
+
// Resembles MMLAs into 2x2 matrices in ARM Version
|
3052
|
+
__m256i iacc_mat_00_sp1 =
|
3053
|
+
_mm256_add_epi32(_mm256_add_epi32(_mm256_add_epi32(mul_sum_i8_pairs_int32x8(lhs_mat_01_3_sp1, rhs_mat_0145_3_sp1), mul_sum_i8_pairs_int32x8(lhs_mat_01_2_sp1, rhs_mat_0145_2_sp1)), mul_sum_i8_pairs_int32x8(lhs_mat_01_1_sp1, rhs_mat_0145_1_sp1)), mul_sum_i8_pairs_int32x8(lhs_mat_01_0_sp1, rhs_mat_0145_0_sp1));
|
3054
|
+
__m256i iacc_mat_01_sp1 =
|
3055
|
+
_mm256_add_epi32(_mm256_add_epi32(_mm256_add_epi32(mul_sum_i8_pairs_int32x8(lhs_mat_01_3_sp1, rhs_mat_2367_3_sp1), mul_sum_i8_pairs_int32x8(lhs_mat_01_2_sp1, rhs_mat_2367_2_sp1)), mul_sum_i8_pairs_int32x8(lhs_mat_01_1_sp1, rhs_mat_2367_1_sp1)), mul_sum_i8_pairs_int32x8(lhs_mat_01_0_sp1, rhs_mat_2367_0_sp1));
|
3056
|
+
__m256i iacc_mat_10_sp1 =
|
3057
|
+
_mm256_add_epi32(_mm256_add_epi32(_mm256_add_epi32(mul_sum_i8_pairs_int32x8(lhs_mat_23_3_sp1, rhs_mat_0145_3_sp1), mul_sum_i8_pairs_int32x8(lhs_mat_23_2_sp1, rhs_mat_0145_2_sp1)), mul_sum_i8_pairs_int32x8(lhs_mat_23_1_sp1, rhs_mat_0145_1_sp1)), mul_sum_i8_pairs_int32x8(lhs_mat_23_0_sp1, rhs_mat_0145_0_sp1));
|
3058
|
+
__m256i iacc_mat_11_sp1 =
|
3059
|
+
_mm256_add_epi32(_mm256_add_epi32(_mm256_add_epi32(mul_sum_i8_pairs_int32x8(lhs_mat_23_3_sp1, rhs_mat_2367_3_sp1), mul_sum_i8_pairs_int32x8(lhs_mat_23_2_sp1, rhs_mat_2367_2_sp1)), mul_sum_i8_pairs_int32x8(lhs_mat_23_1_sp1, rhs_mat_2367_1_sp1)), mul_sum_i8_pairs_int32x8(lhs_mat_23_0_sp1, rhs_mat_2367_0_sp1));
|
3060
|
+
__m256i iacc_mat_00_sp2 =
|
3061
|
+
_mm256_add_epi32(_mm256_add_epi32(_mm256_add_epi32(mul_sum_i8_pairs_int32x8(lhs_mat_01_3_sp2, rhs_mat_0145_3_sp2), mul_sum_i8_pairs_int32x8(lhs_mat_01_2_sp2, rhs_mat_0145_2_sp2)), mul_sum_i8_pairs_int32x8(lhs_mat_01_1_sp2, rhs_mat_0145_1_sp2)), mul_sum_i8_pairs_int32x8(lhs_mat_01_0_sp2, rhs_mat_0145_0_sp2));
|
3062
|
+
__m256i iacc_mat_01_sp2 =
|
3063
|
+
_mm256_add_epi32(_mm256_add_epi32(_mm256_add_epi32(mul_sum_i8_pairs_int32x8(lhs_mat_01_3_sp2, rhs_mat_2367_3_sp2), mul_sum_i8_pairs_int32x8(lhs_mat_01_2_sp2, rhs_mat_2367_2_sp2)), mul_sum_i8_pairs_int32x8(lhs_mat_01_1_sp2, rhs_mat_2367_1_sp2)), mul_sum_i8_pairs_int32x8(lhs_mat_01_0_sp2, rhs_mat_2367_0_sp2));
|
3064
|
+
__m256i iacc_mat_10_sp2 =
|
3065
|
+
_mm256_add_epi32(_mm256_add_epi32(_mm256_add_epi32(mul_sum_i8_pairs_int32x8(lhs_mat_23_3_sp2, rhs_mat_0145_3_sp2), mul_sum_i8_pairs_int32x8(lhs_mat_23_2_sp2, rhs_mat_0145_2_sp2)), mul_sum_i8_pairs_int32x8(lhs_mat_23_1_sp2, rhs_mat_0145_1_sp2)), mul_sum_i8_pairs_int32x8(lhs_mat_23_0_sp2, rhs_mat_0145_0_sp2));
|
3066
|
+
__m256i iacc_mat_11_sp2 =
|
3067
|
+
_mm256_add_epi32(_mm256_add_epi32(_mm256_add_epi32(mul_sum_i8_pairs_int32x8(lhs_mat_23_3_sp2, rhs_mat_2367_3_sp2), mul_sum_i8_pairs_int32x8(lhs_mat_23_2_sp2, rhs_mat_2367_2_sp2)), mul_sum_i8_pairs_int32x8(lhs_mat_23_1_sp2, rhs_mat_2367_1_sp2)), mul_sum_i8_pairs_int32x8(lhs_mat_23_0_sp2, rhs_mat_2367_0_sp2));
|
3068
|
+
|
3069
|
+
// Output of both shuffle patterns are added in order to sum dot product outputs of all 32 values in block
|
3070
|
+
__m256i iacc_mat_00 = _mm256_add_epi32(iacc_mat_00_sp1, iacc_mat_00_sp2);
|
3071
|
+
__m256i iacc_mat_01 = _mm256_add_epi32(iacc_mat_01_sp1, iacc_mat_01_sp2);
|
3072
|
+
__m256i iacc_mat_10 = _mm256_add_epi32(iacc_mat_10_sp1, iacc_mat_10_sp2);
|
3073
|
+
__m256i iacc_mat_11 = _mm256_add_epi32(iacc_mat_11_sp1, iacc_mat_11_sp2);
|
3074
|
+
|
3075
|
+
// Straighten out to make 4 row vectors
|
3076
|
+
__m256i iacc_row_0 = _mm256_blend_epi32(iacc_mat_00, _mm256_shuffle_epi32(iacc_mat_01, 78), 204);
|
3077
|
+
__m256i iacc_row_1 = _mm256_blend_epi32(_mm256_shuffle_epi32(iacc_mat_00, 78), iacc_mat_01, 204);
|
3078
|
+
__m256i iacc_row_2 = _mm256_blend_epi32(iacc_mat_10, _mm256_shuffle_epi32(iacc_mat_11, 78), 204);
|
3079
|
+
__m256i iacc_row_3 = _mm256_blend_epi32(_mm256_shuffle_epi32(iacc_mat_10, 78), iacc_mat_11, 204);
|
3080
|
+
|
3081
|
+
// Load the scale(d) values for all the 4 Q8_0 blocks and repeat it across lanes
|
3082
|
+
const __m256 row_scale_f32 = GGML_F32Cx8_REPEAT_LOAD(a_ptrs[rp][b].d, loadMask);
|
3083
|
+
|
3084
|
+
// Multiply with appropiate scales and accumulate
|
3085
|
+
acc_rows[rp * 4] = _mm256_fmadd_ps(_mm256_cvtepi32_ps(iacc_row_0), _mm256_mul_ps(col_scale_f32, _mm256_shuffle_ps(row_scale_f32, row_scale_f32, 0)), acc_rows[rp * 4]);
|
3086
|
+
acc_rows[rp * 4 + 1] = _mm256_fmadd_ps(_mm256_cvtepi32_ps(iacc_row_1), _mm256_mul_ps(col_scale_f32, _mm256_shuffle_ps(row_scale_f32, row_scale_f32, 85)), acc_rows[rp * 4 + 1]);
|
3087
|
+
acc_rows[rp * 4 + 2] = _mm256_fmadd_ps(_mm256_cvtepi32_ps(iacc_row_2), _mm256_mul_ps(col_scale_f32, _mm256_shuffle_ps(row_scale_f32, row_scale_f32, 170)), acc_rows[rp * 4 + 2]);
|
3088
|
+
acc_rows[rp * 4 + 3] = _mm256_fmadd_ps(_mm256_cvtepi32_ps(iacc_row_3), _mm256_mul_ps(col_scale_f32, _mm256_shuffle_ps(row_scale_f32, row_scale_f32, 255)), acc_rows[rp * 4 + 3]);
|
3089
|
+
}
|
3090
|
+
}
|
3091
|
+
|
3092
|
+
// Store the accumulated values
|
3093
|
+
for (int i = 0; i < 16; i++) {
|
3094
|
+
_mm256_storeu_ps((float *)(s + ((y * 4 + i) * bs + x * 8)), acc_rows[i]);
|
3095
|
+
}
|
3096
|
+
}
|
3097
|
+
}
|
3098
|
+
|
3099
|
+
// Take a block_q8_0x4 structures at each pass of the loop and perform dot product operation
|
3100
|
+
for (; y < nr / 4; y ++) {
|
3101
|
+
|
3102
|
+
const block_q8_0x4 * a_ptr = a_ptr_start + (y * nb);
|
3103
|
+
|
3104
|
+
// Load the eight block_q4_0 quantized values interleaved with each other in chunks of eight - B0,B1 ....B6,B7
|
3105
|
+
for (int64_t x = xstart; x < nc / 8; x++) {
|
3106
|
+
|
3107
|
+
const block_q4_0x8 * b_ptr = b_ptr_start + (x * b_nb);
|
3108
|
+
|
3109
|
+
// Master FP accumulators
|
3110
|
+
__m256 acc_rows[4];
|
3111
|
+
for (int i = 0; i < 4; i++) {
|
3112
|
+
acc_rows[i] = _mm256_setzero_ps();
|
3113
|
+
}
|
3114
|
+
|
3115
|
+
for (int64_t b = 0; b < nb; b++) {
|
3116
|
+
// Load the eight block_q8_0 quantized values interleaved with each other in chunks of eight - B0,B1 ....B6,B7
|
3117
|
+
const __m256i rhs_raw_mat_0123_0 = _mm256_loadu_si256((const __m256i *)(b_ptr[b].qs));
|
3118
|
+
const __m256i rhs_raw_mat_4567_0 = _mm256_loadu_si256((const __m256i *)(b_ptr[b].qs + 32));
|
3119
|
+
const __m256i rhs_raw_mat_0123_1 = _mm256_loadu_si256((const __m256i *)(b_ptr[b].qs + 64));
|
3120
|
+
const __m256i rhs_raw_mat_4567_1 = _mm256_loadu_si256((const __m256i *)(b_ptr[b].qs + 96));
|
3121
|
+
|
3122
|
+
// Save the values in the following vectors in the formats B0B1B4B5, B2B3B6B7 for further processing and storing of valuess
|
3123
|
+
const __m256i rhs_raw_mat_0145_0 = _mm256_blend_epi32(rhs_raw_mat_0123_0, _mm256_permutevar8x32_epi32(rhs_raw_mat_4567_0, requiredOrder), 240);
|
3124
|
+
const __m256i rhs_raw_mat_2367_0 = _mm256_blend_epi32(_mm256_permutevar8x32_epi32(rhs_raw_mat_0123_0, requiredOrder), rhs_raw_mat_4567_0, 240);
|
3125
|
+
const __m256i rhs_raw_mat_0145_1 = _mm256_blend_epi32(rhs_raw_mat_0123_1, _mm256_permutevar8x32_epi32(rhs_raw_mat_4567_1, requiredOrder), 240);
|
3126
|
+
const __m256i rhs_raw_mat_2367_1 = _mm256_blend_epi32(_mm256_permutevar8x32_epi32(rhs_raw_mat_0123_1, requiredOrder), rhs_raw_mat_4567_1, 240);
|
3127
|
+
|
3128
|
+
// 4-bit -> 8-bit - Sign is maintained
|
3129
|
+
const __m256i rhs_mat_0145_0 = _mm256_shuffle_epi8(signextendlut, _mm256_and_si256(rhs_raw_mat_0145_0, m4b)); //B0(0-7) B1(0-7) B4(0-7) B5(0-7)
|
3130
|
+
const __m256i rhs_mat_2367_0 = _mm256_shuffle_epi8(signextendlut, _mm256_and_si256(rhs_raw_mat_2367_0, m4b)); //B2(0-7) B3(0-7) B6(0-7) B7(0-7)
|
3131
|
+
|
3132
|
+
const __m256i rhs_mat_0145_1 = _mm256_shuffle_epi8(signextendlut, _mm256_and_si256(rhs_raw_mat_0145_1, m4b)); //B0(8-15) B1(8-15) B4(8-15) B5(8-15)
|
3133
|
+
const __m256i rhs_mat_2367_1 = _mm256_shuffle_epi8(signextendlut, _mm256_and_si256(rhs_raw_mat_2367_1, m4b)); //B2(8-15) B3(8-15) B6(8-15) B7(8-15)
|
3134
|
+
|
3135
|
+
const __m256i rhs_mat_0145_2 = _mm256_shuffle_epi8(signextendlut, _mm256_and_si256(_mm256_srli_epi16(rhs_raw_mat_0145_0, 4), m4b)); //B0(16-23) B1(16-23) B4(16-23) B5(16-23)
|
3136
|
+
const __m256i rhs_mat_2367_2 = _mm256_shuffle_epi8(signextendlut, _mm256_and_si256(_mm256_srli_epi16(rhs_raw_mat_2367_0, 4), m4b)); //B2(16-23) B3(16-23) B6(16-23) B7(16-23)
|
3137
|
+
|
3138
|
+
const __m256i rhs_mat_0145_3 = _mm256_shuffle_epi8(signextendlut, _mm256_and_si256(_mm256_srli_epi16(rhs_raw_mat_0145_1, 4), m4b)); //B0(24-31) B1(24-31) B4(24-31) B5(24-31)
|
3139
|
+
const __m256i rhs_mat_2367_3 = _mm256_shuffle_epi8(signextendlut, _mm256_and_si256(_mm256_srli_epi16(rhs_raw_mat_2367_1, 4), m4b)); //B2(24-31) B3(24-31) B6(24-31) B7(24-31)
|
3140
|
+
|
3141
|
+
// Shuffle pattern one - right side input
|
3142
|
+
const __m256i rhs_mat_0145_0_sp1 = _mm256_shuffle_epi32(rhs_mat_0145_0, 136); //B0(0-3) B1(0-3) B0(0-3) B1(0-3) B4(0-3) B5(0-3) B4(0-3) B5(0-3)
|
3143
|
+
const __m256i rhs_mat_2367_0_sp1 = _mm256_shuffle_epi32(rhs_mat_2367_0, 136); //B2(0-3) B3(0-3) B2(0-3) B3(0-3) B6(0-3) B7(0-3) B6(0-3) B7(0-3)
|
3144
|
+
|
3145
|
+
const __m256i rhs_mat_0145_1_sp1 = _mm256_shuffle_epi32(rhs_mat_0145_1, 136); //B0(8-11) B1(8-11) B0(8-11) B1(8-11) B4(8-11) B5(8-11) B4(8-11) B5(8-11)
|
3146
|
+
const __m256i rhs_mat_2367_1_sp1 = _mm256_shuffle_epi32(rhs_mat_2367_1, 136); //B2(8-11) B3(8-11) B2(8-11) B3(8-11) B6(8-11) B7(8-11) B6(8-11) B7(8-11)
|
3147
|
+
|
3148
|
+
const __m256i rhs_mat_0145_2_sp1 = _mm256_shuffle_epi32(rhs_mat_0145_2, 136); //B0(16-19) B1(16-19) B0(16-19) B1(16-19) B4(16-19) B5(16-19) B4(16-19) B5(16-19)
|
3149
|
+
const __m256i rhs_mat_2367_2_sp1 = _mm256_shuffle_epi32(rhs_mat_2367_2, 136); //B2(16-19) B3(16-19) B2(16-19) B3(16-19) B6(16-19) B7(16-19) B6(16-19) B7(16-19)
|
3150
|
+
|
3151
|
+
const __m256i rhs_mat_0145_3_sp1 = _mm256_shuffle_epi32(rhs_mat_0145_3, 136); //B0(24-27) B1(24-27) B0(24-27) B1(24-27) B4(24-27) B5(24-27) B4(24-27) B5(24-27)
|
3152
|
+
const __m256i rhs_mat_2367_3_sp1 = _mm256_shuffle_epi32(rhs_mat_2367_3, 136); //B2(24-27) B3(24-27) B2(24-27) B3(24-27) B6(24-27) B7(24-27) B6(24-27) B7(24-27)
|
3153
|
+
|
3154
|
+
// Shuffle pattern two - right side input
|
3155
|
+
|
3156
|
+
const __m256i rhs_mat_0145_0_sp2 = _mm256_shuffle_epi32(rhs_mat_0145_0, 221); //B0(4-7) B1(4-7) B0(4-7) B1(4-7) B4(4-7) B5(4-7) B4(4-7) B5(4-7)
|
3157
|
+
const __m256i rhs_mat_2367_0_sp2 = _mm256_shuffle_epi32(rhs_mat_2367_0, 221); //B2(4-7) B3(4-7) B2(4-7) B3(4-7) B6(4-7) B7(4-7) B6(4-7) B7(4-7)
|
3158
|
+
|
3159
|
+
const __m256i rhs_mat_0145_1_sp2 = _mm256_shuffle_epi32(rhs_mat_0145_1, 221); //B0(12-15) B1(12-15) B0(12-15) B1(12-15) B4(12-15) B5(12-15) B4(12-15) B5(12-15)
|
3160
|
+
const __m256i rhs_mat_2367_1_sp2 = _mm256_shuffle_epi32(rhs_mat_2367_1, 221); //B2(12-15) B3(12-15) B2(12-15) B3(12-15) B6(12-15) B7(12-15) B6(12-15) B7(12-15)
|
3161
|
+
|
3162
|
+
const __m256i rhs_mat_0145_2_sp2 = _mm256_shuffle_epi32(rhs_mat_0145_2, 221); //B0(20-23) B1(20-23) B0(20-23) B1(20-23) B4(20-23) B5(20-23) B4(20-23) B5(20-23)
|
3163
|
+
const __m256i rhs_mat_2367_2_sp2 = _mm256_shuffle_epi32(rhs_mat_2367_2, 221); //B2(20-23) B3(20-23) B2(20-23) B3(20-23) B6(20-23) B7(20-23) B6(20-23) B7(20-23)
|
3164
|
+
|
3165
|
+
const __m256i rhs_mat_0145_3_sp2 = _mm256_shuffle_epi32(rhs_mat_0145_3, 221); //B0(28-31) B1(28-31) B0(28-31) B1(28-31) B4(28-31) B5(28-31) B4(28-31) B5(28-31)
|
3166
|
+
const __m256i rhs_mat_2367_3_sp2 = _mm256_shuffle_epi32(rhs_mat_2367_3, 221); //B2(28-31) B3(28-31) B2(28-31) B3(28-31) B6(28-31) B7(28-31) B6(28-31) B7(28-31)
|
3167
|
+
|
3168
|
+
// Scale values - Load the wight scale values of block_q4_0x8
|
3169
|
+
const __m256 col_scale_f32 = GGML_F32Cx8_LOAD(b_ptr[b].d);
|
3170
|
+
|
3171
|
+
// Load the four block_q4_0 quantized values interleaved with each other in chunks of eight - A0,A1,A2,A3
|
3172
|
+
// Loaded as set of 128 bit vectors and repeated into a 256 bit vector
|
3173
|
+
__m256i lhs_mat_0123_0 = _mm256_loadu_si256((const __m256i *)((a_ptr[b].qs)));
|
3174
|
+
__m256i lhs_mat_01_0 = _mm256_permute2f128_si256(lhs_mat_0123_0, lhs_mat_0123_0, 0);
|
3175
|
+
__m256i lhs_mat_23_0 = _mm256_permute2f128_si256(lhs_mat_0123_0, lhs_mat_0123_0, 17);
|
3176
|
+
__m256i lhs_mat_0123_1 = _mm256_loadu_si256((const __m256i *)((a_ptr[b].qs + 32)));
|
3177
|
+
__m256i lhs_mat_01_1 = _mm256_permute2f128_si256(lhs_mat_0123_1, lhs_mat_0123_1, 0);
|
3178
|
+
__m256i lhs_mat_23_1 = _mm256_permute2f128_si256(lhs_mat_0123_1, lhs_mat_0123_1, 17);
|
3179
|
+
__m256i lhs_mat_0123_2 = _mm256_loadu_si256((const __m256i *)((a_ptr[b].qs + 64)));
|
3180
|
+
__m256i lhs_mat_01_2 = _mm256_permute2f128_si256(lhs_mat_0123_2, lhs_mat_0123_2, 0);
|
3181
|
+
__m256i lhs_mat_23_2 = _mm256_permute2f128_si256(lhs_mat_0123_2, lhs_mat_0123_2, 17);
|
3182
|
+
__m256i lhs_mat_0123_3 = _mm256_loadu_si256((const __m256i *)((a_ptr[b].qs + 96)));
|
3183
|
+
__m256i lhs_mat_01_3 = _mm256_permute2f128_si256(lhs_mat_0123_3, lhs_mat_0123_3, 0);
|
3184
|
+
__m256i lhs_mat_23_3 = _mm256_permute2f128_si256(lhs_mat_0123_3, lhs_mat_0123_3, 17);
|
3185
|
+
|
3186
|
+
// Shuffle pattern one - left side input
|
3187
|
+
|
3188
|
+
const __m256i lhs_mat_01_0_sp1 = _mm256_shuffle_epi32(lhs_mat_01_0, 160); //A0(0-3) A0(0-3) A1(0-3) A1(0-3) A0(0-3) A0(0-3) A1(0-3) A1(0-3)
|
3189
|
+
const __m256i lhs_mat_23_0_sp1 = _mm256_shuffle_epi32(lhs_mat_23_0, 160); //A2(0-3) A2(0-3) A3(0-3) A3(0-3) A2(0-3) A2(0-3) A3(0-3) A3(0-3)
|
3190
|
+
|
3191
|
+
const __m256i lhs_mat_01_1_sp1 = _mm256_shuffle_epi32(lhs_mat_01_1, 160); //A0(8-11) A0(8-11) A1(8-11) A1(8-11) A0(8-11) A0(8-11) A1(8-11) A1(8-11)
|
3192
|
+
const __m256i lhs_mat_23_1_sp1 = _mm256_shuffle_epi32(lhs_mat_23_1, 160); //A2(8-11) A2(8-11) A3(8-11) A3(8-11) A2(8-11) A2(8-11) A3(8-11) A3(8-11)
|
3193
|
+
|
3194
|
+
const __m256i lhs_mat_01_2_sp1 = _mm256_shuffle_epi32(lhs_mat_01_2, 160); //A0(16-19) A0(16-19) A1(16-19) A1(16-19) A0(16-19) A0(16-19) A1(16-19) A1(16-19)
|
3195
|
+
const __m256i lhs_mat_23_2_sp1 = _mm256_shuffle_epi32(lhs_mat_23_2, 160); //A2(16-19) A2(16-19) A3(16-19) A3(16-19) A2(16-19) A2(16-19) A3(16-19) A3(16-19)
|
3196
|
+
|
3197
|
+
const __m256i lhs_mat_01_3_sp1 = _mm256_shuffle_epi32(lhs_mat_01_3, 160); //A0(24-27) A0(24-27) A1(24-27) A1(24-27) A0(24-27) A0(24-27) A1(24-27) A1(24-27)
|
3198
|
+
const __m256i lhs_mat_23_3_sp1 = _mm256_shuffle_epi32(lhs_mat_23_3, 160); //A2(24-27) A2(24-27) A3(24-27) A3(24-27) A2(24-27) A2(24-27) A3(24-27) A3(24-27)
|
3199
|
+
|
3200
|
+
// Shuffle pattern two - left side input
|
3201
|
+
|
3202
|
+
const __m256i lhs_mat_01_0_sp2 = _mm256_shuffle_epi32(lhs_mat_01_0, 245); //A0(4-7) A0(4-7) A1(4-7) A1(4-7) A0(4-7) A0(4-7) A1(4-7) A1(4-7)
|
3203
|
+
const __m256i lhs_mat_23_0_sp2 = _mm256_shuffle_epi32(lhs_mat_23_0, 245); //A2(4-7) A2(4-7) A3(4-7) A3(4-7) A2(4-7) A2(4-7) A3(4-7) A3(4-7)
|
3204
|
+
|
3205
|
+
const __m256i lhs_mat_01_1_sp2 = _mm256_shuffle_epi32(lhs_mat_01_1, 245); //A0(12-15) A0(12-15) A1(12-15) A1(12-15) A0(12-15) A0(12-15) A1(12-15) A1(12-15)
|
3206
|
+
const __m256i lhs_mat_23_1_sp2 = _mm256_shuffle_epi32(lhs_mat_23_1, 245); //A2(12-15) A2(12-15) A3(12-15) A3(12-15) A2(12-15) A2(12-15) A3(12-15) A3(12-15)
|
3207
|
+
|
3208
|
+
const __m256i lhs_mat_01_2_sp2 = _mm256_shuffle_epi32(lhs_mat_01_2, 245); //A0(20-23) A0(20-23) A1(20-23) A1(20-23) A0(20-23) A0(20-23) A1(20-23) A1(20-23)
|
3209
|
+
const __m256i lhs_mat_23_2_sp2 = _mm256_shuffle_epi32(lhs_mat_23_2, 245); //A2(20-23) A2(20-23) A3(20-23) A3(20-23) A2(20-23) A2(20-23) A3(20-23) A3(20-23)
|
3210
|
+
|
3211
|
+
const __m256i lhs_mat_01_3_sp2 = _mm256_shuffle_epi32(lhs_mat_01_3, 245); //A0(28-31) A0(28-31) A1(28-31) A1(28-31) A0(28-31) A0(28-31) A1(28-31) A1(28-31)
|
3212
|
+
const __m256i lhs_mat_23_3_sp2 = _mm256_shuffle_epi32(lhs_mat_23_3, 245); //A2(28-31) A2(28-31) A3(28-31) A3(28-31) A2(28-31) A2(28-31) A3(28-31) A3(28-31)
|
3213
|
+
|
3214
|
+
// The values arranged in shuffle patterns are operated with dot product operation within 32 bit lane i.e corresponding bytes and multiplied and added into 32 bit integers within 32 bit lane
|
3215
|
+
// Resembles MMLAs into 2x2 matrices in ARM Version
|
3216
|
+
__m256i iacc_mat_00_sp1 =
|
3217
|
+
_mm256_add_epi32(_mm256_add_epi32(_mm256_add_epi32(mul_sum_i8_pairs_int32x8(lhs_mat_01_3_sp1, rhs_mat_0145_3_sp1), mul_sum_i8_pairs_int32x8(lhs_mat_01_2_sp1, rhs_mat_0145_2_sp1)), mul_sum_i8_pairs_int32x8(lhs_mat_01_1_sp1, rhs_mat_0145_1_sp1)), mul_sum_i8_pairs_int32x8(lhs_mat_01_0_sp1, rhs_mat_0145_0_sp1));
|
3218
|
+
__m256i iacc_mat_01_sp1 =
|
3219
|
+
_mm256_add_epi32(_mm256_add_epi32(_mm256_add_epi32(mul_sum_i8_pairs_int32x8(lhs_mat_01_3_sp1, rhs_mat_2367_3_sp1), mul_sum_i8_pairs_int32x8(lhs_mat_01_2_sp1, rhs_mat_2367_2_sp1)), mul_sum_i8_pairs_int32x8(lhs_mat_01_1_sp1, rhs_mat_2367_1_sp1)), mul_sum_i8_pairs_int32x8(lhs_mat_01_0_sp1, rhs_mat_2367_0_sp1));
|
3220
|
+
__m256i iacc_mat_10_sp1 =
|
3221
|
+
_mm256_add_epi32(_mm256_add_epi32(_mm256_add_epi32(mul_sum_i8_pairs_int32x8(lhs_mat_23_3_sp1, rhs_mat_0145_3_sp1), mul_sum_i8_pairs_int32x8(lhs_mat_23_2_sp1, rhs_mat_0145_2_sp1)), mul_sum_i8_pairs_int32x8(lhs_mat_23_1_sp1, rhs_mat_0145_1_sp1)), mul_sum_i8_pairs_int32x8(lhs_mat_23_0_sp1, rhs_mat_0145_0_sp1));
|
3222
|
+
__m256i iacc_mat_11_sp1 =
|
3223
|
+
_mm256_add_epi32(_mm256_add_epi32(_mm256_add_epi32(mul_sum_i8_pairs_int32x8(lhs_mat_23_3_sp1, rhs_mat_2367_3_sp1), mul_sum_i8_pairs_int32x8(lhs_mat_23_2_sp1, rhs_mat_2367_2_sp1)), mul_sum_i8_pairs_int32x8(lhs_mat_23_1_sp1, rhs_mat_2367_1_sp1)), mul_sum_i8_pairs_int32x8(lhs_mat_23_0_sp1, rhs_mat_2367_0_sp1));
|
3224
|
+
__m256i iacc_mat_00_sp2 =
|
3225
|
+
_mm256_add_epi32(_mm256_add_epi32(_mm256_add_epi32(mul_sum_i8_pairs_int32x8(lhs_mat_01_3_sp2, rhs_mat_0145_3_sp2), mul_sum_i8_pairs_int32x8(lhs_mat_01_2_sp2, rhs_mat_0145_2_sp2)), mul_sum_i8_pairs_int32x8(lhs_mat_01_1_sp2, rhs_mat_0145_1_sp2)), mul_sum_i8_pairs_int32x8(lhs_mat_01_0_sp2, rhs_mat_0145_0_sp2));
|
3226
|
+
__m256i iacc_mat_01_sp2 =
|
3227
|
+
_mm256_add_epi32(_mm256_add_epi32(_mm256_add_epi32(mul_sum_i8_pairs_int32x8(lhs_mat_01_3_sp2, rhs_mat_2367_3_sp2), mul_sum_i8_pairs_int32x8(lhs_mat_01_2_sp2, rhs_mat_2367_2_sp2)), mul_sum_i8_pairs_int32x8(lhs_mat_01_1_sp2, rhs_mat_2367_1_sp2)), mul_sum_i8_pairs_int32x8(lhs_mat_01_0_sp2, rhs_mat_2367_0_sp2));
|
3228
|
+
__m256i iacc_mat_10_sp2 =
|
3229
|
+
_mm256_add_epi32(_mm256_add_epi32(_mm256_add_epi32(mul_sum_i8_pairs_int32x8(lhs_mat_23_3_sp2, rhs_mat_0145_3_sp2), mul_sum_i8_pairs_int32x8(lhs_mat_23_2_sp2, rhs_mat_0145_2_sp2)), mul_sum_i8_pairs_int32x8(lhs_mat_23_1_sp2, rhs_mat_0145_1_sp2)), mul_sum_i8_pairs_int32x8(lhs_mat_23_0_sp2, rhs_mat_0145_0_sp2));
|
3230
|
+
__m256i iacc_mat_11_sp2 =
|
3231
|
+
_mm256_add_epi32(_mm256_add_epi32(_mm256_add_epi32(mul_sum_i8_pairs_int32x8(lhs_mat_23_3_sp2, rhs_mat_2367_3_sp2), mul_sum_i8_pairs_int32x8(lhs_mat_23_2_sp2, rhs_mat_2367_2_sp2)), mul_sum_i8_pairs_int32x8(lhs_mat_23_1_sp2, rhs_mat_2367_1_sp2)), mul_sum_i8_pairs_int32x8(lhs_mat_23_0_sp2, rhs_mat_2367_0_sp2));
|
3232
|
+
|
3233
|
+
// Output of both shuffle patterns are added in order to sum dot product outputs of all 32 values in block
|
3234
|
+
__m256i iacc_mat_00 = _mm256_add_epi32(iacc_mat_00_sp1, iacc_mat_00_sp2);
|
3235
|
+
__m256i iacc_mat_01 = _mm256_add_epi32(iacc_mat_01_sp1, iacc_mat_01_sp2);
|
3236
|
+
__m256i iacc_mat_10 = _mm256_add_epi32(iacc_mat_10_sp1, iacc_mat_10_sp2);
|
3237
|
+
__m256i iacc_mat_11 = _mm256_add_epi32(iacc_mat_11_sp1, iacc_mat_11_sp2);
|
3238
|
+
|
3239
|
+
|
3240
|
+
// Straighten out to make 4 row vectors
|
3241
|
+
__m256i iacc_row_0 = _mm256_blend_epi32(iacc_mat_00, _mm256_shuffle_epi32(iacc_mat_01, 78), 204);
|
3242
|
+
__m256i iacc_row_1 = _mm256_blend_epi32(_mm256_shuffle_epi32(iacc_mat_00, 78), iacc_mat_01, 204);
|
3243
|
+
__m256i iacc_row_2 = _mm256_blend_epi32(iacc_mat_10, _mm256_shuffle_epi32(iacc_mat_11, 78), 204);
|
3244
|
+
__m256i iacc_row_3 = _mm256_blend_epi32(_mm256_shuffle_epi32(iacc_mat_10, 78), iacc_mat_11, 204);
|
3245
|
+
|
3246
|
+
// Load the scale(d) values for all the 4 Q8_0 blocks and repeat it across lanes
|
3247
|
+
const __m256 row_scale_f32 = GGML_F32Cx8_REPEAT_LOAD(a_ptr[b].d, loadMask);
|
3248
|
+
|
3249
|
+
// Multiply with appropiate scales and accumulate
|
3250
|
+
acc_rows[0] = _mm256_fmadd_ps(_mm256_cvtepi32_ps(iacc_row_0), _mm256_mul_ps(col_scale_f32, _mm256_shuffle_ps(row_scale_f32, row_scale_f32, 0)), acc_rows[0]);
|
3251
|
+
acc_rows[1] = _mm256_fmadd_ps(_mm256_cvtepi32_ps(iacc_row_1), _mm256_mul_ps(col_scale_f32, _mm256_shuffle_ps(row_scale_f32, row_scale_f32, 85)), acc_rows[1]);
|
3252
|
+
acc_rows[2] = _mm256_fmadd_ps(_mm256_cvtepi32_ps(iacc_row_2), _mm256_mul_ps(col_scale_f32, _mm256_shuffle_ps(row_scale_f32, row_scale_f32, 170)), acc_rows[2]);
|
3253
|
+
acc_rows[3] = _mm256_fmadd_ps(_mm256_cvtepi32_ps(iacc_row_3), _mm256_mul_ps(col_scale_f32, _mm256_shuffle_ps(row_scale_f32, row_scale_f32, 255)), acc_rows[3]);
|
3254
|
+
}
|
3255
|
+
|
3256
|
+
// Store the accumulated values
|
3257
|
+
for (int i = 0; i < 4; i++) {
|
3258
|
+
_mm256_storeu_ps((float *)(s + ((y * 4 + i) * bs + x * 8)), acc_rows[i]);
|
3259
|
+
}
|
3260
|
+
}
|
3261
|
+
}
|
3262
|
+
return;
|
3263
|
+
}
|
3264
|
+
#elif defined(__riscv_v_intrinsic)
|
3265
|
+
if (__riscv_vlenb() >= QK4_0) {
|
3266
|
+
const size_t vl = QK4_0;
|
3267
|
+
|
3268
|
+
for (int y = 0; y < nr / 4; y++) {
|
3269
|
+
const block_q8_0x4 * a_ptr = (const block_q8_0x4 *) vy + (y * nb);
|
3270
|
+
for (int x = 0; x < nc / ncols_interleaved; x++) {
|
3271
|
+
const block_q4_0x8 * b_ptr = (const block_q4_0x8 *) vx + (x * nb);
|
3272
|
+
vfloat32m1_t sumf0 = __riscv_vfmv_v_f_f32m1(0.0, vl / 4);
|
3273
|
+
vfloat32m1_t sumf1 = __riscv_vfmv_v_f_f32m1(0.0, vl / 4);
|
3274
|
+
vfloat32m1_t sumf2 = __riscv_vfmv_v_f_f32m1(0.0, vl / 4);
|
3275
|
+
vfloat32m1_t sumf3 = __riscv_vfmv_v_f_f32m1(0.0, vl / 4);
|
3276
|
+
for (int l = 0; l < nb; l++) {
|
3277
|
+
const vint8m4_t rhs_raw_vec = __riscv_vle8_v_i8m4((const int8_t *)b_ptr[l].qs, vl * 4);
|
3278
|
+
const vint8m4_t rhs_vec_lo = __riscv_vsra_vx_i8m4(__riscv_vsll_vx_i8m4(rhs_raw_vec, 4, vl * 4), 4, vl * 4);
|
3279
|
+
const vint8m4_t rhs_vec_hi = __riscv_vsra_vx_i8m4(rhs_raw_vec, 4, vl * 4);
|
3280
|
+
const vint8m2_t rhs_vec_lo_0 = __riscv_vget_v_i8m4_i8m2(rhs_vec_lo, 0);
|
3281
|
+
const vint8m2_t rhs_vec_lo_1 = __riscv_vget_v_i8m4_i8m2(rhs_vec_lo, 1);
|
3282
|
+
const vint8m2_t rhs_vec_hi_0 = __riscv_vget_v_i8m4_i8m2(rhs_vec_hi, 0);
|
3283
|
+
const vint8m2_t rhs_vec_hi_1 = __riscv_vget_v_i8m4_i8m2(rhs_vec_hi, 1);
|
3284
|
+
|
3285
|
+
// vector version needs Zvfhmin extension
|
3286
|
+
const float a_scales[4] = {
|
3287
|
+
GGML_FP16_TO_FP32(a_ptr[l].d[0]),
|
3288
|
+
GGML_FP16_TO_FP32(a_ptr[l].d[1]),
|
3289
|
+
GGML_FP16_TO_FP32(a_ptr[l].d[2]),
|
3290
|
+
GGML_FP16_TO_FP32(a_ptr[l].d[3])
|
3291
|
+
};
|
3292
|
+
const float b_scales[8] = {
|
3293
|
+
GGML_FP16_TO_FP32(b_ptr[l].d[0]),
|
3294
|
+
GGML_FP16_TO_FP32(b_ptr[l].d[1]),
|
3295
|
+
GGML_FP16_TO_FP32(b_ptr[l].d[2]),
|
3296
|
+
GGML_FP16_TO_FP32(b_ptr[l].d[3]),
|
3297
|
+
GGML_FP16_TO_FP32(b_ptr[l].d[4]),
|
3298
|
+
GGML_FP16_TO_FP32(b_ptr[l].d[5]),
|
3299
|
+
GGML_FP16_TO_FP32(b_ptr[l].d[6]),
|
3300
|
+
GGML_FP16_TO_FP32(b_ptr[l].d[7])
|
3301
|
+
};
|
3302
|
+
const vfloat32m1_t b_scales_vec = __riscv_vle32_v_f32m1(b_scales, vl / 4);
|
3303
|
+
|
3304
|
+
const int64_t A0 = *(const int64_t *)&a_ptr[l].qs[0];
|
3305
|
+
const int64_t A4 = *(const int64_t *)&a_ptr[l].qs[32];
|
3306
|
+
const int64_t A8 = *(const int64_t *)&a_ptr[l].qs[64];
|
3307
|
+
const int64_t Ac = *(const int64_t *)&a_ptr[l].qs[96];
|
3308
|
+
__asm__ __volatile__("" ::: "memory"); // prevent gcc from emitting fused vlse64, violating alignment
|
3309
|
+
vint16m4_t sumi_l0;
|
3310
|
+
{
|
3311
|
+
const vint8m2_t lhs_0_8 =__riscv_vreinterpret_v_i64m2_i8m2(__riscv_vmv_v_x_i64m2(A0, vl / 4));
|
3312
|
+
const vint8m2_t lhs_1_8 =__riscv_vreinterpret_v_i64m2_i8m2(__riscv_vmv_v_x_i64m2(A4, vl / 4));
|
3313
|
+
const vint8m2_t lhs_2_8 =__riscv_vreinterpret_v_i64m2_i8m2(__riscv_vmv_v_x_i64m2(A8, vl / 4));
|
3314
|
+
const vint8m2_t lhs_3_8 =__riscv_vreinterpret_v_i64m2_i8m2(__riscv_vmv_v_x_i64m2(Ac, vl / 4));
|
3315
|
+
const vint16m4_t sumi_lo_0 = __riscv_vwmul_vv_i16m4(rhs_vec_lo_0, lhs_0_8, vl * 2);
|
3316
|
+
const vint16m4_t sumi_lo_1 = __riscv_vwmacc_vv_i16m4(sumi_lo_0, rhs_vec_lo_1, lhs_1_8, vl * 2);
|
3317
|
+
const vint16m4_t sumi_hi_0 = __riscv_vwmacc_vv_i16m4(sumi_lo_1, rhs_vec_hi_0, lhs_2_8, vl * 2);
|
3318
|
+
const vint16m4_t sumi_hi_m = __riscv_vwmacc_vv_i16m4(sumi_hi_0, rhs_vec_hi_1, lhs_3_8, vl * 2);
|
3319
|
+
|
3320
|
+
sumi_l0 = sumi_hi_m;
|
3321
|
+
}
|
3322
|
+
|
3323
|
+
{
|
3324
|
+
const vuint32m4_t sumi_i32 = __riscv_vreinterpret_v_i32m4_u32m4(__riscv_vreinterpret_v_i16m4_i32m4(sumi_l0));
|
3325
|
+
const vuint16m2_t sumi_h2_0 = __riscv_vnsrl_wx_u16m2(sumi_i32, 0, vl);
|
3326
|
+
const vuint16m2_t sumi_h2_1 = __riscv_vnsrl_wx_u16m2(sumi_i32, 16, vl);
|
3327
|
+
const vuint16m2_t sumi_h2 = __riscv_vadd_vv_u16m2(sumi_h2_0, sumi_h2_1, vl);
|
3328
|
+
const vuint32m2_t sumi_h2_i32 = __riscv_vreinterpret_v_u16m2_u32m2(sumi_h2);
|
3329
|
+
const vuint16m1_t sumi_h4_0 = __riscv_vnsrl_wx_u16m1(sumi_h2_i32, 0, vl / 2);
|
3330
|
+
const vuint16m1_t sumi_h4_1 = __riscv_vnsrl_wx_u16m1(sumi_h2_i32, 16, vl / 2);
|
3331
|
+
const vuint16m1_t sumi_h4 = __riscv_vadd_vv_u16m1(sumi_h4_0, sumi_h4_1, vl / 2);
|
3332
|
+
const vuint32m1_t sumi_h4_i32 = __riscv_vreinterpret_v_u16m1_u32m1(sumi_h4);
|
3333
|
+
const vint16mf2_t sumi_h8_0 = __riscv_vreinterpret_v_u16mf2_i16mf2(__riscv_vnsrl_wx_u16mf2(sumi_h4_i32, 0, vl / 4));
|
3334
|
+
const vint16mf2_t sumi_h8_1 = __riscv_vreinterpret_v_u16mf2_i16mf2(__riscv_vnsrl_wx_u16mf2(sumi_h4_i32, 16, vl / 4));
|
3335
|
+
const vint32m1_t sumi_h8 = __riscv_vwadd_vv_i32m1(sumi_h8_0, sumi_h8_1, vl / 4);
|
3336
|
+
const vfloat32m1_t facc = __riscv_vfcvt_f_x_v_f32m1(sumi_h8, vl / 4);
|
3337
|
+
|
3338
|
+
const vfloat32m1_t tmp1 = __riscv_vfmul_vf_f32m1(facc, a_scales[0], vl / 4);
|
3339
|
+
sumf0 = __riscv_vfmacc_vv_f32m1(sumf0, tmp1, b_scales_vec, vl / 4);
|
3340
|
+
}
|
3341
|
+
|
3342
|
+
const int64_t A1 = *(const int64_t *)&a_ptr[l].qs[8];
|
3343
|
+
const int64_t A5 = *(const int64_t *)&a_ptr[l].qs[40];
|
3344
|
+
const int64_t A9 = *(const int64_t *)&a_ptr[l].qs[72];
|
3345
|
+
const int64_t Ad = *(const int64_t *)&a_ptr[l].qs[104];
|
3346
|
+
__asm__ __volatile__("" ::: "memory"); // prevent gcc from emitting fused vlse64, violating alignment
|
3347
|
+
vint16m4_t sumi_l1;
|
3348
|
+
{
|
3349
|
+
const vint8m2_t lhs_0_8 =__riscv_vreinterpret_v_i64m2_i8m2(__riscv_vmv_v_x_i64m2(A1, vl / 4));
|
3350
|
+
const vint8m2_t lhs_1_8 =__riscv_vreinterpret_v_i64m2_i8m2(__riscv_vmv_v_x_i64m2(A5, vl / 4));
|
3351
|
+
const vint8m2_t lhs_2_8 =__riscv_vreinterpret_v_i64m2_i8m2(__riscv_vmv_v_x_i64m2(A9, vl / 4));
|
3352
|
+
const vint8m2_t lhs_3_8 =__riscv_vreinterpret_v_i64m2_i8m2(__riscv_vmv_v_x_i64m2(Ad, vl / 4));
|
3353
|
+
const vint16m4_t sumi_lo_0 = __riscv_vwmul_vv_i16m4(rhs_vec_lo_0, lhs_0_8, vl * 2);
|
3354
|
+
const vint16m4_t sumi_lo_1 = __riscv_vwmacc_vv_i16m4(sumi_lo_0, rhs_vec_lo_1, lhs_1_8, vl * 2);
|
3355
|
+
const vint16m4_t sumi_hi_0 = __riscv_vwmacc_vv_i16m4(sumi_lo_1, rhs_vec_hi_0, lhs_2_8, vl * 2);
|
3356
|
+
const vint16m4_t sumi_hi_m = __riscv_vwmacc_vv_i16m4(sumi_hi_0, rhs_vec_hi_1, lhs_3_8, vl * 2);
|
3357
|
+
|
3358
|
+
sumi_l1 = sumi_hi_m;
|
3359
|
+
}
|
3360
|
+
|
3361
|
+
{
|
3362
|
+
const vuint32m4_t sumi_i32 = __riscv_vreinterpret_v_i32m4_u32m4(__riscv_vreinterpret_v_i16m4_i32m4(sumi_l1));
|
3363
|
+
const vuint16m2_t sumi_h2_0 = __riscv_vnsrl_wx_u16m2(sumi_i32, 0, vl);
|
3364
|
+
const vuint16m2_t sumi_h2_1 = __riscv_vnsrl_wx_u16m2(sumi_i32, 16, vl);
|
3365
|
+
const vuint16m2_t sumi_h2 = __riscv_vadd_vv_u16m2(sumi_h2_0, sumi_h2_1, vl);
|
3366
|
+
const vuint32m2_t sumi_h2_i32 = __riscv_vreinterpret_v_u16m2_u32m2(sumi_h2);
|
3367
|
+
const vuint16m1_t sumi_h4_0 = __riscv_vnsrl_wx_u16m1(sumi_h2_i32, 0, vl / 2);
|
3368
|
+
const vuint16m1_t sumi_h4_1 = __riscv_vnsrl_wx_u16m1(sumi_h2_i32, 16, vl / 2);
|
3369
|
+
const vuint16m1_t sumi_h4 = __riscv_vadd_vv_u16m1(sumi_h4_0, sumi_h4_1, vl / 2);
|
3370
|
+
const vuint32m1_t sumi_h4_i32 = __riscv_vreinterpret_v_u16m1_u32m1(sumi_h4);
|
3371
|
+
const vint16mf2_t sumi_h8_0 = __riscv_vreinterpret_v_u16mf2_i16mf2(__riscv_vnsrl_wx_u16mf2(sumi_h4_i32, 0, vl / 4));
|
3372
|
+
const vint16mf2_t sumi_h8_1 = __riscv_vreinterpret_v_u16mf2_i16mf2(__riscv_vnsrl_wx_u16mf2(sumi_h4_i32, 16, vl / 4));
|
3373
|
+
const vint32m1_t sumi_h8 = __riscv_vwadd_vv_i32m1(sumi_h8_0, sumi_h8_1, vl / 4);
|
3374
|
+
const vfloat32m1_t facc = __riscv_vfcvt_f_x_v_f32m1(sumi_h8, vl / 4);
|
3375
|
+
|
3376
|
+
const vfloat32m1_t tmp1 = __riscv_vfmul_vf_f32m1(facc, a_scales[1], vl / 4);
|
3377
|
+
sumf1 = __riscv_vfmacc_vv_f32m1(sumf1, tmp1, b_scales_vec, vl / 4);
|
3378
|
+
}
|
3379
|
+
|
3380
|
+
const int64_t A2 = *(const int64_t *)&a_ptr[l].qs[16];
|
3381
|
+
const int64_t A6 = *(const int64_t *)&a_ptr[l].qs[48];
|
3382
|
+
const int64_t Aa = *(const int64_t *)&a_ptr[l].qs[80];
|
3383
|
+
const int64_t Ae = *(const int64_t *)&a_ptr[l].qs[112];
|
3384
|
+
__asm__ __volatile__("" ::: "memory"); // prevent gcc from emitting fused vlse64, violating alignment
|
3385
|
+
vint16m4_t sumi_l2;
|
3386
|
+
{
|
3387
|
+
const vint8m2_t lhs_0_8 =__riscv_vreinterpret_v_i64m2_i8m2(__riscv_vmv_v_x_i64m2(A2, vl / 4));
|
3388
|
+
const vint8m2_t lhs_1_8 =__riscv_vreinterpret_v_i64m2_i8m2(__riscv_vmv_v_x_i64m2(A6, vl / 4));
|
3389
|
+
const vint8m2_t lhs_2_8 =__riscv_vreinterpret_v_i64m2_i8m2(__riscv_vmv_v_x_i64m2(Aa, vl / 4));
|
3390
|
+
const vint8m2_t lhs_3_8 =__riscv_vreinterpret_v_i64m2_i8m2(__riscv_vmv_v_x_i64m2(Ae, vl / 4));
|
3391
|
+
const vint16m4_t sumi_lo_0 = __riscv_vwmul_vv_i16m4(rhs_vec_lo_0, lhs_0_8, vl * 2);
|
3392
|
+
const vint16m4_t sumi_lo_1 = __riscv_vwmacc_vv_i16m4(sumi_lo_0, rhs_vec_lo_1, lhs_1_8, vl * 2);
|
3393
|
+
const vint16m4_t sumi_hi_0 = __riscv_vwmacc_vv_i16m4(sumi_lo_1, rhs_vec_hi_0, lhs_2_8, vl * 2);
|
3394
|
+
const vint16m4_t sumi_hi_m = __riscv_vwmacc_vv_i16m4(sumi_hi_0, rhs_vec_hi_1, lhs_3_8, vl * 2);
|
3395
|
+
|
3396
|
+
sumi_l2 = sumi_hi_m;
|
3397
|
+
}
|
3398
|
+
|
3399
|
+
{
|
3400
|
+
const vuint32m4_t sumi_i32 = __riscv_vreinterpret_v_i32m4_u32m4(__riscv_vreinterpret_v_i16m4_i32m4(sumi_l2));
|
3401
|
+
const vuint16m2_t sumi_h2_0 = __riscv_vnsrl_wx_u16m2(sumi_i32, 0, vl);
|
3402
|
+
const vuint16m2_t sumi_h2_1 = __riscv_vnsrl_wx_u16m2(sumi_i32, 16, vl);
|
3403
|
+
const vuint16m2_t sumi_h2 = __riscv_vadd_vv_u16m2(sumi_h2_0, sumi_h2_1, vl);
|
3404
|
+
const vuint32m2_t sumi_h2_i32 = __riscv_vreinterpret_v_u16m2_u32m2(sumi_h2);
|
3405
|
+
const vuint16m1_t sumi_h4_0 = __riscv_vnsrl_wx_u16m1(sumi_h2_i32, 0, vl / 2);
|
3406
|
+
const vuint16m1_t sumi_h4_1 = __riscv_vnsrl_wx_u16m1(sumi_h2_i32, 16, vl / 2);
|
3407
|
+
const vuint16m1_t sumi_h4 = __riscv_vadd_vv_u16m1(sumi_h4_0, sumi_h4_1, vl / 2);
|
3408
|
+
const vuint32m1_t sumi_h4_i32 = __riscv_vreinterpret_v_u16m1_u32m1(sumi_h4);
|
3409
|
+
const vint16mf2_t sumi_h8_0 = __riscv_vreinterpret_v_u16mf2_i16mf2(__riscv_vnsrl_wx_u16mf2(sumi_h4_i32, 0, vl / 4));
|
3410
|
+
const vint16mf2_t sumi_h8_1 = __riscv_vreinterpret_v_u16mf2_i16mf2(__riscv_vnsrl_wx_u16mf2(sumi_h4_i32, 16, vl / 4));
|
3411
|
+
const vint32m1_t sumi_h8 = __riscv_vwadd_vv_i32m1(sumi_h8_0, sumi_h8_1, vl / 4);
|
3412
|
+
const vfloat32m1_t facc = __riscv_vfcvt_f_x_v_f32m1(sumi_h8, vl / 4);
|
3413
|
+
|
3414
|
+
const vfloat32m1_t tmp1 = __riscv_vfmul_vf_f32m1(facc, a_scales[2], vl / 4);
|
3415
|
+
sumf2 = __riscv_vfmacc_vv_f32m1(sumf2, tmp1, b_scales_vec, vl / 4);
|
3416
|
+
}
|
3417
|
+
|
3418
|
+
const int64_t A3 = *(const int64_t *)&a_ptr[l].qs[24];
|
3419
|
+
const int64_t A7 = *(const int64_t *)&a_ptr[l].qs[56];
|
3420
|
+
const int64_t Ab = *(const int64_t *)&a_ptr[l].qs[88];
|
3421
|
+
const int64_t Af = *(const int64_t *)&a_ptr[l].qs[120];
|
3422
|
+
__asm__ __volatile__("" ::: "memory"); // prevent gcc from emitting fused vlse64, violating alignment
|
3423
|
+
vint16m4_t sumi_l3;
|
3424
|
+
{
|
3425
|
+
const vint8m2_t lhs_0_8 =__riscv_vreinterpret_v_i64m2_i8m2(__riscv_vmv_v_x_i64m2(A3, vl / 4));
|
3426
|
+
const vint8m2_t lhs_1_8 =__riscv_vreinterpret_v_i64m2_i8m2(__riscv_vmv_v_x_i64m2(A7, vl / 4));
|
3427
|
+
const vint8m2_t lhs_2_8 =__riscv_vreinterpret_v_i64m2_i8m2(__riscv_vmv_v_x_i64m2(Ab, vl / 4));
|
3428
|
+
const vint8m2_t lhs_3_8 =__riscv_vreinterpret_v_i64m2_i8m2(__riscv_vmv_v_x_i64m2(Af, vl / 4));
|
3429
|
+
const vint16m4_t sumi_lo_0 = __riscv_vwmul_vv_i16m4(rhs_vec_lo_0, lhs_0_8, vl * 2);
|
3430
|
+
const vint16m4_t sumi_lo_1 = __riscv_vwmacc_vv_i16m4(sumi_lo_0, rhs_vec_lo_1, lhs_1_8, vl * 2);
|
3431
|
+
const vint16m4_t sumi_hi_0 = __riscv_vwmacc_vv_i16m4(sumi_lo_1, rhs_vec_hi_0, lhs_2_8, vl * 2);
|
3432
|
+
const vint16m4_t sumi_hi_m = __riscv_vwmacc_vv_i16m4(sumi_hi_0, rhs_vec_hi_1, lhs_3_8, vl * 2);
|
3433
|
+
|
3434
|
+
sumi_l3 = sumi_hi_m;
|
3435
|
+
}
|
3436
|
+
|
3437
|
+
{
|
3438
|
+
const vuint32m4_t sumi_i32 = __riscv_vreinterpret_v_i32m4_u32m4(__riscv_vreinterpret_v_i16m4_i32m4(sumi_l3));
|
3439
|
+
const vuint16m2_t sumi_h2_0 = __riscv_vnsrl_wx_u16m2(sumi_i32, 0, vl);
|
3440
|
+
const vuint16m2_t sumi_h2_1 = __riscv_vnsrl_wx_u16m2(sumi_i32, 16, vl);
|
3441
|
+
const vuint16m2_t sumi_h2 = __riscv_vadd_vv_u16m2(sumi_h2_0, sumi_h2_1, vl);
|
3442
|
+
const vuint32m2_t sumi_h2_i32 = __riscv_vreinterpret_v_u16m2_u32m2(sumi_h2);
|
3443
|
+
const vuint16m1_t sumi_h4_0 = __riscv_vnsrl_wx_u16m1(sumi_h2_i32, 0, vl / 2);
|
3444
|
+
const vuint16m1_t sumi_h4_1 = __riscv_vnsrl_wx_u16m1(sumi_h2_i32, 16, vl / 2);
|
3445
|
+
const vuint16m1_t sumi_h4 = __riscv_vadd_vv_u16m1(sumi_h4_0, sumi_h4_1, vl / 2);
|
3446
|
+
const vuint32m1_t sumi_h4_i32 = __riscv_vreinterpret_v_u16m1_u32m1(sumi_h4);
|
3447
|
+
const vint16mf2_t sumi_h8_0 = __riscv_vreinterpret_v_u16mf2_i16mf2(__riscv_vnsrl_wx_u16mf2(sumi_h4_i32, 0, vl / 4));
|
3448
|
+
const vint16mf2_t sumi_h8_1 = __riscv_vreinterpret_v_u16mf2_i16mf2(__riscv_vnsrl_wx_u16mf2(sumi_h4_i32, 16, vl / 4));
|
3449
|
+
const vint32m1_t sumi_h8 = __riscv_vwadd_vv_i32m1(sumi_h8_0, sumi_h8_1, vl / 4);
|
3450
|
+
const vfloat32m1_t facc = __riscv_vfcvt_f_x_v_f32m1(sumi_h8, vl / 4);
|
3451
|
+
|
3452
|
+
const vfloat32m1_t tmp1 = __riscv_vfmul_vf_f32m1(facc, a_scales[3], vl / 4);
|
3453
|
+
sumf3 = __riscv_vfmacc_vv_f32m1(sumf3, tmp1, b_scales_vec, vl / 4);
|
3454
|
+
}
|
3455
|
+
}
|
3456
|
+
__riscv_vse32_v_f32m1(&s[(y * 4 + 0) * bs + x * ncols_interleaved], sumf0, vl / 4);
|
3457
|
+
__riscv_vse32_v_f32m1(&s[(y * 4 + 1) * bs + x * ncols_interleaved], sumf1, vl / 4);
|
3458
|
+
__riscv_vse32_v_f32m1(&s[(y * 4 + 2) * bs + x * ncols_interleaved], sumf2, vl / 4);
|
3459
|
+
__riscv_vse32_v_f32m1(&s[(y * 4 + 3) * bs + x * ncols_interleaved], sumf3, vl / 4);
|
3460
|
+
}
|
3461
|
+
}
|
3462
|
+
|
3463
|
+
return;
|
3464
|
+
}
|
3465
|
+
#endif // #if ! ((defined(_MSC_VER)) && ! defined(__clang__)) && defined(__aarch64__)
|
3466
|
+
float sumf[4][8];
|
3467
|
+
int sumi;
|
3468
|
+
|
3469
|
+
for (int y = 0; y < nr / 4; y++) {
|
3470
|
+
const block_q8_0x4 * a_ptr = (const block_q8_0x4 *) vy + (y * nb);
|
3471
|
+
for (int x = 0; x < nc / ncols_interleaved; x++) {
|
3472
|
+
const block_q4_0x8 * b_ptr = (const block_q4_0x8 *) vx + (x * nb);
|
3473
|
+
for (int m = 0; m < 4; m++) {
|
3474
|
+
for (int j = 0; j < ncols_interleaved; j++) sumf[m][j] = 0.0;
|
3475
|
+
}
|
3476
|
+
for (int l = 0; l < nb; l++) {
|
3477
|
+
for (int k = 0; k < (qk / (2 * blocklen)); k++) {
|
3478
|
+
for (int m = 0; m < 4; m++) {
|
3479
|
+
for (int j = 0; j < ncols_interleaved; j++) {
|
3480
|
+
sumi = 0;
|
3481
|
+
for (int i = 0; i < blocklen; ++i) {
|
3482
|
+
const int v0 = (int8_t) (b_ptr[l].qs[k * ncols_interleaved * blocklen + j * blocklen + i] << 4);
|
3483
|
+
const int v1 = (int8_t) (b_ptr[l].qs[k * ncols_interleaved * blocklen + j * blocklen + i] & 0xF0);
|
3484
|
+
sumi += ((v0 * a_ptr[l].qs[k * 4 * blocklen + m * blocklen + i]) +
|
3485
|
+
(v1 * a_ptr[l].qs[k * 4 * blocklen + m * blocklen + i + qk / 2 * 4])) >> 4;
|
3486
|
+
}
|
3487
|
+
sumf[m][j] += sumi * GGML_FP16_TO_FP32(b_ptr[l].d[j]) * GGML_FP16_TO_FP32(a_ptr[l].d[m]);
|
3488
|
+
}
|
3489
|
+
}
|
3490
|
+
}
|
3491
|
+
}
|
3492
|
+
for (int m = 0; m < 4; m++) {
|
3493
|
+
for (int j = 0; j < ncols_interleaved; j++)
|
3494
|
+
s[(y * 4 + m) * bs + x * ncols_interleaved + j] = sumf[m][j];
|
3495
|
+
}
|
3496
|
+
}
|
3497
|
+
}
|
3498
|
+
}
|
3499
|
+
|
3500
|
+
static void ggml_gemm_iq4_nl_4x4_q8_0(int n, float * GGML_RESTRICT s, size_t bs, const void * GGML_RESTRICT vx, const void * GGML_RESTRICT vy, int nr, int nc) {
|
3501
|
+
const int qk = QK8_0;
|
3502
|
+
const int nb = n / qk;
|
3503
|
+
const int ncols_interleaved = 4;
|
3504
|
+
const int blocklen = 4;
|
3505
|
+
|
3506
|
+
assert (n % qk == 0);
|
3507
|
+
assert (nr % 4 == 0);
|
3508
|
+
assert (nc % ncols_interleaved == 0);
|
3509
|
+
|
3510
|
+
UNUSED(s);
|
3511
|
+
UNUSED(bs);
|
3512
|
+
UNUSED(vx);
|
3513
|
+
UNUSED(vy);
|
3514
|
+
UNUSED(nr);
|
3515
|
+
UNUSED(nc);
|
3516
|
+
UNUSED(nb);
|
3517
|
+
UNUSED(ncols_interleaved);
|
3518
|
+
UNUSED(blocklen);
|
3519
|
+
|
3520
|
+
#if ! ((defined(_MSC_VER)) && ! defined(__clang__)) && defined(__aarch64__) && defined(__ARM_NEON) && defined(__ARM_FEATURE_DOTPROD)
|
3521
|
+
if (ggml_cpu_has_neon() && ggml_cpu_has_dotprod()) {
|
3522
|
+
const int8x16_t kvalues = vld1q_s8(kvalues_iq4nl);
|
3523
|
+
|
3524
|
+
for (int y = 0; y < nr / 4; y++) {
|
3525
|
+
const block_q8_0x4 * a_ptr = (const block_q8_0x4 *) vy + (y * nb);
|
3526
|
+
for (int x = 0; x < nc / ncols_interleaved; x++) {
|
3527
|
+
const block_iq4_nlx4 * b_ptr = (const block_iq4_nlx4 *) vx + (x * nb);
|
3528
|
+
|
3529
|
+
float32x4_t sumf[4];
|
3530
|
+
for (int m = 0; m < 4; m++) {
|
3531
|
+
sumf[m] = vdupq_n_f32(0);
|
3532
|
+
}
|
3533
|
+
|
3534
|
+
for (int l = 0; l < nb; l++) {
|
3535
|
+
float32x4_t a_d = vcvt_f32_f16(vld1_f16((const float16_t *)a_ptr[l].d));
|
3536
|
+
float32x4_t b_d = vcvt_f32_f16(vld1_f16((const float16_t *)b_ptr[l].d));
|
3537
|
+
|
3538
|
+
int32x4_t sumi_0 = vdupq_n_s32(0);
|
3539
|
+
int32x4_t sumi_1 = vdupq_n_s32(0);
|
3540
|
+
int32x4_t sumi_2 = vdupq_n_s32(0);
|
3541
|
+
int32x4_t sumi_3 = vdupq_n_s32(0);
|
3542
|
+
|
3543
|
+
for (int k = 0; k < 4; k++) {
|
3544
|
+
int8x16_t a_0 = vld1q_s8(a_ptr[l].qs + 16 * k + 0);
|
3545
|
+
int8x16_t a_1 = vld1q_s8(a_ptr[l].qs + 16 * k + 64);
|
3546
|
+
|
3547
|
+
uint8x16_t b = vld1q_u8(b_ptr[l].qs + 16 * k);
|
3548
|
+
int8x16_t b_hi = vqtbl1q_s8(kvalues, b >> 4);
|
3549
|
+
int8x16_t b_lo = vqtbl1q_s8(kvalues, b & 0xF);
|
3550
|
+
|
3551
|
+
sumi_0 = vdotq_laneq_s32(sumi_0, b_lo, a_0, 0);
|
3552
|
+
sumi_1 = vdotq_laneq_s32(sumi_1, b_lo, a_0, 1);
|
3553
|
+
sumi_2 = vdotq_laneq_s32(sumi_2, b_lo, a_0, 2);
|
3554
|
+
sumi_3 = vdotq_laneq_s32(sumi_3, b_lo, a_0, 3);
|
3555
|
+
sumi_0 = vdotq_laneq_s32(sumi_0, b_hi, a_1, 0);
|
3556
|
+
sumi_1 = vdotq_laneq_s32(sumi_1, b_hi, a_1, 1);
|
3557
|
+
sumi_2 = vdotq_laneq_s32(sumi_2, b_hi, a_1, 2);
|
3558
|
+
sumi_3 = vdotq_laneq_s32(sumi_3, b_hi, a_1, 3);
|
3559
|
+
}
|
3560
|
+
|
3561
|
+
sumf[0] = vmlaq_f32(sumf[0], vmulq_laneq_f32(b_d, a_d, 0), vcvtq_f32_s32(sumi_0));
|
3562
|
+
sumf[1] = vmlaq_f32(sumf[1], vmulq_laneq_f32(b_d, a_d, 1), vcvtq_f32_s32(sumi_1));
|
3563
|
+
sumf[2] = vmlaq_f32(sumf[2], vmulq_laneq_f32(b_d, a_d, 2), vcvtq_f32_s32(sumi_2));
|
3564
|
+
sumf[3] = vmlaq_f32(sumf[3], vmulq_laneq_f32(b_d, a_d, 3), vcvtq_f32_s32(sumi_3));
|
3565
|
+
}
|
3566
|
+
|
3567
|
+
for (int m = 0; m < 4; m++) {
|
3568
|
+
vst1q_f32(s + (y * 4 + m) * bs + x * 4, sumf[m]);
|
3569
|
+
}
|
3570
|
+
}
|
3571
|
+
}
|
3572
|
+
return;
|
3573
|
+
}
|
3574
|
+
#endif // #if ! ((defined(_MSC_VER)) && ! defined(__clang__)) && defined(__aarch64__) && defined(__ARM_NEON)
|
3575
|
+
{
|
3576
|
+
float sumf[4][4];
|
3577
|
+
int sumi;
|
3578
|
+
|
3579
|
+
for (int y = 0; y < nr / 4; y++) {
|
3580
|
+
const block_q8_0x4 * a_ptr = (const block_q8_0x4 *) vy + (y * nb);
|
3581
|
+
for (int x = 0; x < nc / ncols_interleaved; x++) {
|
3582
|
+
const block_iq4_nlx4 * b_ptr = (const block_iq4_nlx4 *) vx + (x * nb);
|
3583
|
+
for (int m = 0; m < 4; m++) {
|
3584
|
+
for (int j = 0; j < ncols_interleaved; j++) sumf[m][j] = 0.0;
|
3585
|
+
}
|
3586
|
+
for (int l = 0; l < nb; l++) {
|
3587
|
+
for (int k = 0; k < (qk / (2 * blocklen)); k++) {
|
3588
|
+
for (int m = 0; m < 4; m++) {
|
3589
|
+
for (int j = 0; j < ncols_interleaved; j++) {
|
3590
|
+
sumi = 0;
|
3591
|
+
for (int i = 0; i < blocklen; ++i) {
|
3592
|
+
const int v0 = kvalues_iq4nl[b_ptr[l].qs[k * ncols_interleaved * blocklen + j * blocklen + i] & 0x0F];
|
3593
|
+
const int v1 = kvalues_iq4nl[b_ptr[l].qs[k * ncols_interleaved * blocklen + j * blocklen + i] >> 4];
|
3594
|
+
sumi += ((v0 * a_ptr[l].qs[k * 4 * blocklen + m * blocklen + i]) +
|
3595
|
+
(v1 * a_ptr[l].qs[k * 4 * blocklen + m * blocklen + i + qk / 2 * 4]));
|
3596
|
+
}
|
3597
|
+
sumf[m][j] += sumi * GGML_FP16_TO_FP32(b_ptr[l].d[j]) * GGML_FP16_TO_FP32(a_ptr[l].d[m]);
|
3598
|
+
}
|
3599
|
+
}
|
3600
|
+
}
|
3601
|
+
}
|
3602
|
+
for (int m = 0; m < 4; m++) {
|
3603
|
+
for (int j = 0; j < ncols_interleaved; j++)
|
3604
|
+
s[(y * 4 + m) * bs + x * ncols_interleaved + j] = sumf[m][j];
|
3605
|
+
}
|
3606
|
+
}
|
3607
|
+
}
|
3608
|
+
}
|
3609
|
+
}
|
3610
|
+
|
3611
|
+
static block_q4_0x4 make_block_q4_0x4(block_q4_0 * in, unsigned int blck_size_interleave) {
|
3612
|
+
block_q4_0x4 out;
|
3613
|
+
|
3614
|
+
for (int i = 0; i < 4; i++) {
|
3615
|
+
out.d[i] = in[i].d;
|
3616
|
+
}
|
3617
|
+
|
3618
|
+
const int end = QK4_0 * 2 / blck_size_interleave;
|
3619
|
+
|
3620
|
+
if (blck_size_interleave == 8) {
|
3621
|
+
const uint64_t xor_mask = 0x8888888888888888ULL;
|
3622
|
+
for (int i = 0; i < end; ++i) {
|
3623
|
+
int src_id = i % 4;
|
3624
|
+
int src_offset = (i / 4) * blck_size_interleave;
|
3625
|
+
int dst_offset = i * blck_size_interleave;
|
3626
|
+
|
3627
|
+
uint64_t elems;
|
3628
|
+
// Using memcpy to avoid unaligned memory accesses
|
3629
|
+
memcpy(&elems, &in[src_id].qs[src_offset], sizeof(uint64_t));
|
3630
|
+
elems ^= xor_mask;
|
3631
|
+
memcpy(&out.qs[dst_offset], &elems, sizeof(uint64_t));
|
3632
|
+
}
|
3633
|
+
} else if (blck_size_interleave == 4) {
|
3634
|
+
const uint32_t xor_mask = 0x88888888;
|
3635
|
+
for (int i = 0; i < end; ++i) {
|
3636
|
+
int src_id = i % 4;
|
3637
|
+
int src_offset = (i / 4) * blck_size_interleave;
|
3638
|
+
int dst_offset = i * blck_size_interleave;
|
3639
|
+
|
3640
|
+
uint32_t elems;
|
3641
|
+
memcpy(&elems, &in[src_id].qs[src_offset], sizeof(uint32_t));
|
3642
|
+
elems ^= xor_mask;
|
3643
|
+
memcpy(&out.qs[dst_offset], &elems, sizeof(uint32_t));
|
3644
|
+
}
|
3645
|
+
} else {
|
3646
|
+
GGML_ASSERT(false);
|
3647
|
+
}
|
3648
|
+
|
3649
|
+
return out;
|
3650
|
+
}
|
3651
|
+
|
3652
|
+
// interleave 8 block_q4_0s in blocks of blck_size_interleave
|
3653
|
+
// returns an interleaved block_q4_0x8
|
3654
|
+
// in the interleaved block_q4_0x8, place deltas for 8 block_q4_0 blocks
|
3655
|
+
// first, then interleave quants from 8 block_q4_0s in blocks of blck_size_interleave
|
3656
|
+
static block_q4_0x8 make_block_q4_0x8(block_q4_0 * in, unsigned int blck_size_interleave) {
|
3657
|
+
block_q4_0x8 out;
|
3658
|
+
|
3659
|
+
for (int i = 0; i < 8; i++) {
|
3660
|
+
out.d[i] = in[i].d;
|
3661
|
+
}
|
3662
|
+
|
3663
|
+
const int end = QK4_0 * 4 / blck_size_interleave;
|
3664
|
+
const uint64_t xor_mask = 0x8888888888888888ULL;
|
3665
|
+
|
3666
|
+
for (int i = 0; i < end; ++i) {
|
3667
|
+
int src_id = i % 8;
|
3668
|
+
int src_offset = (i / 8) * blck_size_interleave;
|
3669
|
+
int dst_offset = i * blck_size_interleave;
|
3670
|
+
|
3671
|
+
uint64_t elems;
|
3672
|
+
memcpy(&elems, &in[src_id].qs[src_offset], sizeof(uint64_t));
|
3673
|
+
elems ^= xor_mask;
|
3674
|
+
memcpy(&out.qs[dst_offset], &elems, sizeof(uint64_t));
|
3675
|
+
}
|
3676
|
+
|
3677
|
+
return out;
|
3678
|
+
}
|
3679
|
+
|
3680
|
+
static int repack_q4_0_to_q4_0_4_bl(struct ggml_tensor * t, int interleave_block, const void * GGML_RESTRICT data, size_t data_size) {
|
3681
|
+
GGML_ASSERT(t->type == GGML_TYPE_Q4_0);
|
3682
|
+
GGML_ASSERT(interleave_block == 4 || interleave_block == 8);
|
3683
|
+
constexpr int nrows_interleaved = 4;
|
3684
|
+
|
3685
|
+
block_q4_0x4 * dst = (block_q4_0x4 *)t->data;
|
3686
|
+
const block_q4_0 * src = (const block_q4_0 *)data;
|
3687
|
+
block_q4_0 dst_tmp[4];
|
3688
|
+
int nrow = ggml_nrows(t);
|
3689
|
+
int nblocks = t->ne[0] / QK4_0;
|
3690
|
+
|
3691
|
+
GGML_ASSERT(data_size == nrow * nblocks * sizeof(block_q4_0));
|
3692
|
+
|
3693
|
+
if (t->ne[1] % nrows_interleaved != 0 || t->ne[0] % 8 != 0) {
|
3694
|
+
return -1;
|
3695
|
+
}
|
3696
|
+
|
3697
|
+
for (int b = 0; b < nrow; b += nrows_interleaved) {
|
3698
|
+
for (int64_t x = 0; x < nblocks; x++) {
|
3699
|
+
for (int i = 0; i < nrows_interleaved; i++) {
|
3700
|
+
dst_tmp[i] = src[x + i * nblocks];
|
3701
|
+
}
|
3702
|
+
*dst++ = make_block_q4_0x4(dst_tmp, interleave_block);
|
3703
|
+
}
|
3704
|
+
src += nrows_interleaved * nblocks;
|
3705
|
+
}
|
3706
|
+
return 0;
|
3707
|
+
|
3708
|
+
GGML_UNUSED(data_size);
|
3709
|
+
}
|
3710
|
+
|
3711
|
+
static int repack_q4_0_to_q4_0_8_bl(struct ggml_tensor * t, int interleave_block, const void * GGML_RESTRICT data, size_t data_size) {
|
3712
|
+
GGML_ASSERT(t->type == GGML_TYPE_Q4_0);
|
3713
|
+
GGML_ASSERT(interleave_block == 8);
|
3714
|
+
constexpr int nrows_interleaved = 8;
|
3715
|
+
|
3716
|
+
block_q4_0x8 * dst = (block_q4_0x8*)t->data;
|
3717
|
+
const block_q4_0 * src = (const block_q4_0*) data;
|
3718
|
+
block_q4_0 dst_tmp[8];
|
3719
|
+
int nrow = ggml_nrows(t);
|
3720
|
+
int nblocks = t->ne[0] / QK4_0;
|
3721
|
+
|
3722
|
+
GGML_ASSERT(data_size == nrow * nblocks * sizeof(block_q4_0));
|
3723
|
+
|
3724
|
+
if (t->ne[1] % nrows_interleaved != 0 || t->ne[0] % 8 != 0) {
|
3725
|
+
return -1;
|
3726
|
+
}
|
3727
|
+
|
3728
|
+
for (int b = 0; b < nrow; b += nrows_interleaved) {
|
3729
|
+
for (int64_t x = 0; x < nblocks; x++) {
|
3730
|
+
for (int i = 0; i < nrows_interleaved; i++ ) {
|
3731
|
+
dst_tmp[i] = src[x + i * nblocks];
|
3732
|
+
}
|
3733
|
+
*dst++ = make_block_q4_0x8(dst_tmp, interleave_block);
|
3734
|
+
}
|
3735
|
+
src += nrows_interleaved * nblocks;
|
3736
|
+
}
|
3737
|
+
return 0;
|
3738
|
+
|
3739
|
+
GGML_UNUSED(data_size);
|
3740
|
+
}
|
3741
|
+
|
3742
|
+
static block_iq4_nlx4 make_block_iq4_nlx4(block_iq4_nl * in, unsigned int blck_size_interleave) {
|
3743
|
+
block_iq4_nlx4 out;
|
3744
|
+
|
3745
|
+
for (int i = 0; i < 4; i++) {
|
3746
|
+
out.d[i] = in[i].d;
|
3747
|
+
}
|
3748
|
+
|
3749
|
+
const int end = QK4_NL * 2 / blck_size_interleave;
|
3750
|
+
|
3751
|
+
// TODO: this branch seems wrong
|
3752
|
+
//if (blck_size_interleave == 8) {
|
3753
|
+
// for (int i = 0; i < end; ++i) {
|
3754
|
+
// int src_id = i % 4;
|
3755
|
+
// int src_offset = (i / 4) * blck_size_interleave;
|
3756
|
+
// int dst_offset = i * blck_size_interleave;
|
3757
|
+
|
3758
|
+
// // Using memcpy to avoid unaligned memory accesses
|
3759
|
+
// memcpy(&out.qs[dst_offset], &in[src_id].qs[src_offset], sizeof(uint64_t));
|
3760
|
+
// }
|
3761
|
+
//} else
|
3762
|
+
if (blck_size_interleave == 4) {
|
3763
|
+
for (int i = 0; i < end; ++i) {
|
3764
|
+
int src_id = i % 4;
|
3765
|
+
int src_offset = (i / 4) * blck_size_interleave;
|
3766
|
+
int dst_offset = i * blck_size_interleave;
|
3767
|
+
|
3768
|
+
memcpy(&out.qs[dst_offset], &in[src_id].qs[src_offset], sizeof(uint32_t));
|
3769
|
+
}
|
3770
|
+
} else {
|
3771
|
+
GGML_ASSERT(false);
|
3772
|
+
}
|
3773
|
+
|
3774
|
+
return out;
|
3775
|
+
}
|
3776
|
+
|
3777
|
+
static int repack_iq4_nl_to_iq4_nl_4_bl(struct ggml_tensor * t, int interleave_block, const void * GGML_RESTRICT data, size_t data_size) {
|
3778
|
+
GGML_ASSERT(t->type == GGML_TYPE_IQ4_NL);
|
3779
|
+
//GGML_ASSERT(interleave_block == 4 || interleave_block == 8);
|
3780
|
+
GGML_ASSERT(interleave_block == 4);
|
3781
|
+
|
3782
|
+
block_iq4_nlx4 * dst = (block_iq4_nlx4 *)t->data;
|
3783
|
+
const block_iq4_nl * src = (const block_iq4_nl *)data;
|
3784
|
+
block_iq4_nl dst_tmp[4];
|
3785
|
+
int nrow = ggml_nrows(t);
|
3786
|
+
int nrows_interleaved = 4;
|
3787
|
+
int nblocks = t->ne[0] / QK4_0;
|
3788
|
+
|
3789
|
+
GGML_ASSERT(data_size == nrow * nblocks * sizeof(block_iq4_nl));
|
3790
|
+
|
3791
|
+
if (t->ne[1] % nrows_interleaved != 0 || t->ne[0] % 8 != 0) {
|
3792
|
+
return -1;
|
3793
|
+
}
|
3794
|
+
|
3795
|
+
for (int b = 0; b < nrow; b += nrows_interleaved) {
|
3796
|
+
for (int64_t x = 0; x < nblocks; x++) {
|
3797
|
+
for (int i = 0; i < nrows_interleaved; i++) {
|
3798
|
+
dst_tmp[i] = src[x + i * nblocks];
|
3799
|
+
}
|
3800
|
+
*dst++ = make_block_iq4_nlx4(dst_tmp, interleave_block);
|
3801
|
+
}
|
3802
|
+
src += nrows_interleaved * nblocks;
|
3803
|
+
}
|
3804
|
+
return 0;
|
3805
|
+
|
3806
|
+
GGML_UNUSED(data_size);
|
3807
|
+
}
|
3808
|
+
|
3809
|
+
namespace ggml::cpu::aarch64 {
|
3810
|
+
// repack
|
3811
|
+
template <typename BLOC_TYPE, int64_t INTER_SIZE, int64_t NB_COLS>
|
3812
|
+
int repack(struct ggml_tensor *, const void *, size_t);
|
3813
|
+
|
3814
|
+
// TODO: generalise.
|
3815
|
+
template <> int repack<block_q4_0, 4, 4>(struct ggml_tensor * t, const void * data, size_t data_size) {
|
3816
|
+
return repack_q4_0_to_q4_0_4_bl(t, 4, data, data_size);
|
3817
|
+
}
|
3818
|
+
|
3819
|
+
template <> int repack<block_q4_0, 8, 4>(struct ggml_tensor * t, const void * data, size_t data_size) {
|
3820
|
+
return repack_q4_0_to_q4_0_4_bl(t, 8, data, data_size);
|
3821
|
+
}
|
3822
|
+
|
3823
|
+
template <> int repack<block_q4_0, 8, 8>(struct ggml_tensor * t, const void * data, size_t data_size) {
|
3824
|
+
return repack_q4_0_to_q4_0_8_bl(t, 8, data, data_size);
|
3825
|
+
}
|
3826
|
+
|
3827
|
+
template <> int repack<block_iq4_nl, 4, 4>(struct ggml_tensor * t, const void * data, size_t data_size) {
|
3828
|
+
return repack_iq4_nl_to_iq4_nl_4_bl(t, 4, data, data_size);
|
3829
|
+
}
|
3830
|
+
|
3831
|
+
// TODO: needs to be revisited
|
3832
|
+
//template <> int repack<block_iq4_nl, 8, 4>(struct ggml_tensor * t, const void * data, size_t data_size) {
|
3833
|
+
// return repack_iq4_nl_to_iq4_nl_4_bl(t, 8, data, data_size);
|
3834
|
+
//}
|
3835
|
+
|
3836
|
+
// gemv
|
3837
|
+
template <typename BLOC_TYPE, int64_t INTER_SIZE, int64_t NB_COLS>
|
3838
|
+
void gemv(int, float *, size_t, const void *, const void *, int, int);
|
3839
|
+
|
3840
|
+
template <> void gemv<block_q4_0, 4, 4>(int n, float * s, size_t bs, const void * vx, const void * vy, int nr, int nc) {
|
3841
|
+
ggml_gemv_q4_0_4x4_q8_0(n, s, bs, vx, vy, nr, nc);
|
3842
|
+
}
|
3843
|
+
|
3844
|
+
template <> void gemv<block_q4_0, 8, 4>(int n, float * s, size_t bs, const void * vx, const void * vy, int nr, int nc) {
|
3845
|
+
ggml_gemv_q4_0_4x8_q8_0(n, s, bs, vx, vy, nr, nc);
|
3846
|
+
}
|
3847
|
+
|
3848
|
+
template <> void gemv<block_q4_0, 8, 8>(int n, float * s, size_t bs, const void * vx, const void * vy, int nr, int nc) {
|
3849
|
+
ggml_gemv_q4_0_8x8_q8_0(n, s, bs, vx, vy, nr, nc);
|
3850
|
+
}
|
3851
|
+
|
3852
|
+
template <>
|
3853
|
+
void gemv<block_iq4_nl, 4, 4>(int n, float * s, size_t bs, const void * vx, const void * vy, int nr, int nc) {
|
3854
|
+
ggml_gemv_iq4_nl_4x4_q8_0(n, s, bs, vx, vy, nr, nc);
|
3855
|
+
}
|
3856
|
+
|
3857
|
+
// gemm
|
3858
|
+
template <typename BLOC_TYPE, int64_t INTER_SIZE, int64_t NB_COLS>
|
3859
|
+
void gemm(int, float *, size_t, const void *, const void *, int, int);
|
3860
|
+
|
3861
|
+
template <> void gemm<block_q4_0, 4, 4>(int n, float * s, size_t bs, const void * vx, const void * vy, int nr, int nc) {
|
3862
|
+
ggml_gemm_q4_0_4x4_q8_0(n, s, bs, vx, vy, nr, nc);
|
3863
|
+
}
|
3864
|
+
|
3865
|
+
template <> void gemm<block_q4_0, 8, 4>(int n, float * s, size_t bs, const void * vx, const void * vy, int nr, int nc) {
|
3866
|
+
ggml_gemm_q4_0_4x8_q8_0(n, s, bs, vx, vy, nr, nc);
|
3867
|
+
}
|
3868
|
+
|
3869
|
+
template <> void gemm<block_q4_0, 8, 8>(int n, float * s, size_t bs, const void * vx, const void * vy, int nr, int nc) {
|
3870
|
+
ggml_gemm_q4_0_8x8_q8_0(n, s, bs, vx, vy, nr, nc);
|
3871
|
+
}
|
3872
|
+
|
3873
|
+
template <>
|
3874
|
+
void gemm<block_iq4_nl, 4, 4>(int n, float * s, size_t bs, const void * vx, const void * vy, int nr, int nc) {
|
3875
|
+
ggml_gemm_iq4_nl_4x4_q8_0(n, s, bs, vx, vy, nr, nc);
|
3876
|
+
}
|
3877
|
+
|
3878
|
+
class tensor_traits_base : public ggml::cpu::tensor_traits {
|
3879
|
+
public:
|
3880
|
+
virtual int repack(struct ggml_tensor * t, const void * data, size_t data_size) = 0;
|
3881
|
+
};
|
3882
|
+
|
3883
|
+
template <typename BLOC_TYPE, int64_t INTER_SIZE, int64_t NB_COLS> class tensor_traits : public tensor_traits_base {
|
3884
|
+
|
3885
|
+
bool work_size(int /* n_threads */, const struct ggml_tensor * op, size_t & size) override {
|
3886
|
+
// not realy a GGML_TYPE_Q8_0 but same size.
|
3887
|
+
switch (op->op) {
|
3888
|
+
case GGML_OP_MUL_MAT:
|
3889
|
+
size = ggml_row_size(GGML_TYPE_Q8_0, ggml_nelements(op->src[1]));
|
3890
|
+
return true;
|
3891
|
+
case GGML_OP_MUL_MAT_ID:
|
3892
|
+
size = ggml_row_size(GGML_TYPE_Q8_0, ggml_nelements(op->src[1]));
|
3893
|
+
size = GGML_PAD(size, sizeof(int64_t)); // + padding for next bloc.
|
3894
|
+
size += sizeof(int64_t) * (1+op->src[0]->ne[2]) * op->src[1]->ne[2];
|
3895
|
+
return true;
|
3896
|
+
default:
|
3897
|
+
// GGML_ABORT("fatal error");
|
3898
|
+
break;
|
3899
|
+
}
|
3900
|
+
return false;
|
3901
|
+
}
|
3902
|
+
|
3903
|
+
bool compute_forward(struct ggml_compute_params * params, struct ggml_tensor * op) override {
|
3904
|
+
switch (op->op) {
|
3905
|
+
case GGML_OP_MUL_MAT:
|
3906
|
+
forward_mul_mat(params, op);
|
3907
|
+
return true;
|
3908
|
+
case GGML_OP_MUL_MAT_ID:
|
3909
|
+
forward_mul_mat_id(params, op);
|
3910
|
+
return true;
|
3911
|
+
default:
|
3912
|
+
// GGML_ABORT("fatal error");
|
3913
|
+
break;
|
3914
|
+
}
|
3915
|
+
return false;
|
3916
|
+
}
|
3917
|
+
|
3918
|
+
void forward_mul_mat(ggml_compute_params * params, ggml_tensor * op) {
|
3919
|
+
const ggml_tensor * src0 = op->src[0];
|
3920
|
+
const ggml_tensor * src1 = op->src[1];
|
3921
|
+
ggml_tensor * dst = op;
|
3922
|
+
|
3923
|
+
GGML_TENSOR_BINARY_OP_LOCALS
|
3924
|
+
|
3925
|
+
const int ith = params->ith;
|
3926
|
+
const int nth = params->nth;
|
3927
|
+
|
3928
|
+
GGML_ASSERT(ne0 == ne01);
|
3929
|
+
GGML_ASSERT(ne1 == ne11);
|
3930
|
+
GGML_ASSERT(ne2 == ne12);
|
3931
|
+
GGML_ASSERT(ne3 == ne13);
|
3932
|
+
|
3933
|
+
// dst cannot be transposed or permuted
|
3934
|
+
GGML_ASSERT(nb0 == sizeof(float));
|
3935
|
+
GGML_ASSERT(nb0 <= nb1);
|
3936
|
+
GGML_ASSERT(nb1 <= nb2);
|
3937
|
+
GGML_ASSERT(nb2 <= nb3);
|
3938
|
+
|
3939
|
+
GGML_ASSERT(src1->type == GGML_TYPE_F32);
|
3940
|
+
|
3941
|
+
GGML_ASSERT(ggml_n_dims(op->src[0]) == 2);
|
3942
|
+
// GGML_ASSERT(ggml_n_dims(op->src[1]) == 2);
|
3943
|
+
|
3944
|
+
char * wdata = static_cast<char *>(params->wdata);
|
3945
|
+
const size_t nbw1 = ggml_row_size(GGML_TYPE_Q8_0, ne10);
|
3946
|
+
|
3947
|
+
assert(params->wsize >= nbw1 * ne11);
|
3948
|
+
|
3949
|
+
const ggml_from_float_t from_float = ggml_get_type_traits_cpu(GGML_TYPE_Q8_0)->from_float;
|
3950
|
+
|
3951
|
+
int64_t i11_processed = 0;
|
3952
|
+
for (int64_t i11 = ith * 4; i11 < ne11 - ne11 % 4; i11 += nth * 4) {
|
3953
|
+
quantize_mat_q8_0((float *) ((char *) src1->data + i11 * nb11), (void *) (wdata + i11 * nbw1), 4, ne10,
|
3954
|
+
INTER_SIZE);
|
3955
|
+
}
|
3956
|
+
i11_processed = ne11 - ne11 % 4;
|
3957
|
+
for (int64_t i11 = i11_processed + ith; i11 < ne11; i11 += nth) {
|
3958
|
+
from_float((float *) ((char *) src1->data + i11 * nb11), (void *) (wdata + i11 * nbw1), ne10);
|
3959
|
+
}
|
3960
|
+
|
3961
|
+
ggml_barrier(params->threadpool);
|
3962
|
+
|
3963
|
+
const void * src1_wdata = params->wdata;
|
3964
|
+
const size_t src1_col_stride = ggml_row_size(GGML_TYPE_Q8_0, ne10);
|
3965
|
+
int64_t src0_start = (ith * ne01) / nth;
|
3966
|
+
int64_t src0_end = ((ith + 1) * ne01) / nth;
|
3967
|
+
src0_start = (src0_start % NB_COLS) ? src0_start + NB_COLS - (src0_start % NB_COLS) : src0_start;
|
3968
|
+
src0_end = (src0_end % NB_COLS) ? src0_end + NB_COLS - (src0_end % NB_COLS) : src0_end;
|
3969
|
+
if (src0_start >= src0_end) {
|
3970
|
+
return;
|
3971
|
+
}
|
3972
|
+
|
3973
|
+
// If there are more than three rows in src1, use gemm; otherwise, use gemv.
|
3974
|
+
if (ne11 > 3) {
|
3975
|
+
gemm<BLOC_TYPE, INTER_SIZE, NB_COLS>(ne00, (float *) ((char *) dst->data) + src0_start, ne01,
|
3976
|
+
(const char *) src0->data + src0_start * nb01,
|
3977
|
+
(const char *) src1_wdata, ne11 - ne11 % 4, src0_end - src0_start);
|
3978
|
+
}
|
3979
|
+
for (int iter = ne11 - ne11 % 4; iter < ne11; iter++) {
|
3980
|
+
gemv<BLOC_TYPE, INTER_SIZE, NB_COLS>(ne00, (float *) ((char *) dst->data + (iter * nb1)) + src0_start, ne01,
|
3981
|
+
(const char *) src0->data + src0_start * nb01,
|
3982
|
+
(const char *) src1_wdata + (src1_col_stride * iter), 1,
|
3983
|
+
src0_end - src0_start);
|
3984
|
+
}
|
3985
|
+
}
|
3986
|
+
|
3987
|
+
void forward_mul_mat_id(ggml_compute_params * params, ggml_tensor * op) {
|
3988
|
+
const ggml_tensor * src0 = op->src[0];
|
3989
|
+
const ggml_tensor * src1 = op->src[1];
|
3990
|
+
const ggml_tensor * ids = op->src[2];
|
3991
|
+
ggml_tensor * dst = op;
|
3992
|
+
|
3993
|
+
GGML_TENSOR_BINARY_OP_LOCALS
|
3994
|
+
|
3995
|
+
const int ith = params->ith;
|
3996
|
+
const int nth = params->nth;
|
3997
|
+
|
3998
|
+
const ggml_from_float_t from_float = ggml_get_type_traits_cpu(GGML_TYPE_Q8_0)->from_float;
|
3999
|
+
|
4000
|
+
// we don't support permuted src0 or src1
|
4001
|
+
GGML_ASSERT(nb00 == ggml_type_size(src0->type));
|
4002
|
+
GGML_ASSERT(nb10 == ggml_type_size(src1->type));
|
4003
|
+
|
4004
|
+
// dst cannot be transposed or permuted
|
4005
|
+
GGML_ASSERT(nb0 == sizeof(float));
|
4006
|
+
GGML_ASSERT(nb0 <= nb1);
|
4007
|
+
GGML_ASSERT(nb1 <= nb2);
|
4008
|
+
GGML_ASSERT(nb2 <= nb3);
|
4009
|
+
|
4010
|
+
GGML_ASSERT(ne03 == 1);
|
4011
|
+
GGML_ASSERT(ne13 == 1);
|
4012
|
+
GGML_ASSERT(ne3 == 1);
|
4013
|
+
|
4014
|
+
GGML_ASSERT(src1->type == GGML_TYPE_F32);
|
4015
|
+
|
4016
|
+
// row groups
|
4017
|
+
const int n_ids = ids->ne[0]; // n_expert_used
|
4018
|
+
const int n_as = ne02; // n_expert
|
4019
|
+
|
4020
|
+
const size_t nbw1 = ggml_row_size(GGML_TYPE_Q8_0, ne10);
|
4021
|
+
const size_t nbw2 = nbw1*ne11;
|
4022
|
+
const size_t nbw3 = nbw2*ne12;
|
4023
|
+
|
4024
|
+
struct mmid_row_mapping {
|
4025
|
+
int32_t i1;
|
4026
|
+
int32_t i2;
|
4027
|
+
};
|
4028
|
+
|
4029
|
+
GGML_ASSERT(params->wsize >= (GGML_PAD(nbw3, sizeof(int64_t)) + n_as * sizeof(int64_t) +
|
4030
|
+
n_as * ne12 * sizeof(mmid_row_mapping)));
|
4031
|
+
|
4032
|
+
auto wdata = (char *) params->wdata;
|
4033
|
+
auto wdata_src1_end = (char *) wdata + GGML_PAD(nbw3, sizeof(int64_t));
|
4034
|
+
int64_t * matrix_row_counts = (int64_t *) (wdata_src1_end); // [n_as]
|
4035
|
+
struct mmid_row_mapping * matrix_rows = (struct mmid_row_mapping *) (matrix_row_counts + n_as); // [n_as][ne12]
|
4036
|
+
|
4037
|
+
// src1: float32 => block_q8_0
|
4038
|
+
for (int64_t i12 = 0; i12 < ne12; ++i12) {
|
4039
|
+
for (int64_t i11 = ith; i11 < ne11; i11 += nth) {
|
4040
|
+
from_float((float *)((char *) src1->data + i12 * nb12 + i11 * nb11),
|
4041
|
+
(void *) (wdata + i12 * nbw2 + i11 * nbw1),
|
4042
|
+
ne10);
|
4043
|
+
}
|
4044
|
+
}
|
4045
|
+
|
4046
|
+
#define MMID_MATRIX_ROW(row_id, i1) matrix_rows[(row_id) * ne12 + (i1)]
|
4047
|
+
|
4048
|
+
if (ith == 0) {
|
4049
|
+
// initialize matrix_row_counts
|
4050
|
+
memset(matrix_row_counts, 0, n_as * sizeof(int64_t));
|
4051
|
+
|
4052
|
+
// group rows by src0 matrix
|
4053
|
+
for (int32_t iid1 = 0; iid1 < ids->ne[1]; ++iid1) {
|
4054
|
+
for (int32_t id = 0; id < n_ids; ++id) {
|
4055
|
+
const int32_t i02 =
|
4056
|
+
*(const int32_t *) ((const char *) ids->data + iid1 * ids->nb[1] + id * ids->nb[0]);
|
4057
|
+
|
4058
|
+
GGML_ASSERT(i02 >= 0 && i02 < n_as);
|
4059
|
+
|
4060
|
+
MMID_MATRIX_ROW(i02, matrix_row_counts[i02]) = { id, iid1 };
|
4061
|
+
matrix_row_counts[i02] += 1;
|
4062
|
+
}
|
4063
|
+
}
|
4064
|
+
}
|
4065
|
+
|
4066
|
+
ggml_barrier(params->threadpool);
|
4067
|
+
|
4068
|
+
// compute each matrix multiplication in sequence
|
4069
|
+
for (int cur_a = 0; cur_a < n_as; ++cur_a) {
|
4070
|
+
const int64_t cne1 = matrix_row_counts[cur_a];
|
4071
|
+
|
4072
|
+
if (cne1 == 0) {
|
4073
|
+
continue;
|
4074
|
+
}
|
4075
|
+
|
4076
|
+
auto src0_cur = (const char *) src0->data + cur_a*nb02;
|
4077
|
+
|
4078
|
+
//const int64_t nr0 = ne01; // src0 rows
|
4079
|
+
const int64_t nr1 = cne1; // src1 rows
|
4080
|
+
|
4081
|
+
int64_t src0_cur_start = (ith * ne01) / nth;
|
4082
|
+
int64_t src0_cur_end = ((ith + 1) * ne01) / nth;
|
4083
|
+
src0_cur_start =
|
4084
|
+
(src0_cur_start % NB_COLS) ? src0_cur_start + NB_COLS - (src0_cur_start % NB_COLS) : src0_cur_start;
|
4085
|
+
src0_cur_end = (src0_cur_end % NB_COLS) ? src0_cur_end + NB_COLS - (src0_cur_end % NB_COLS) : src0_cur_end;
|
4086
|
+
|
4087
|
+
if (src0_cur_start >= src0_cur_end) return;
|
4088
|
+
|
4089
|
+
for (int ir1 = 0; ir1 < nr1; ir1++) {
|
4090
|
+
struct mmid_row_mapping row_mapping = MMID_MATRIX_ROW(cur_a, ir1);
|
4091
|
+
const int id = row_mapping.i1; // selected expert index
|
4092
|
+
|
4093
|
+
const int64_t i11 = id % ne11;
|
4094
|
+
const int64_t i12 = row_mapping.i2; // row index in src1
|
4095
|
+
|
4096
|
+
const int64_t i1 = id; // selected expert index
|
4097
|
+
const int64_t i2 = i12; // row
|
4098
|
+
|
4099
|
+
auto src1_col = (const char *) wdata + (i11 * nbw1 + i12 * nbw2);
|
4100
|
+
|
4101
|
+
gemv<BLOC_TYPE, INTER_SIZE, NB_COLS>(
|
4102
|
+
ne00, (float *)((char *) dst->data + (i1 * nb1 + i2 * nb2)) + src0_cur_start,
|
4103
|
+
ne01, src0_cur + src0_cur_start * nb01,
|
4104
|
+
src1_col, 1, src0_cur_end - src0_cur_start);
|
4105
|
+
}
|
4106
|
+
}
|
4107
|
+
#undef MMID_MATRIX_ROW
|
4108
|
+
}
|
4109
|
+
|
4110
|
+
int repack(struct ggml_tensor * t, const void * data, size_t data_size) override {
|
4111
|
+
GGML_LOG_DEBUG("%s: repack tensor %s with %s_%dx%d\n", __func__, t->name, ggml_type_name(t->type),
|
4112
|
+
(int) NB_COLS, (int) INTER_SIZE);
|
4113
|
+
return ggml::cpu::aarch64::repack<BLOC_TYPE, INTER_SIZE, NB_COLS>(t, data, data_size);
|
4114
|
+
}
|
4115
|
+
};
|
4116
|
+
|
4117
|
+
// instance for Q4
|
4118
|
+
static const tensor_traits<block_q4_0, 4, 4> q4_0_4x4_q8_0;
|
4119
|
+
static const tensor_traits<block_q4_0, 8, 4> q4_0_4x8_q8_0;
|
4120
|
+
static const tensor_traits<block_q4_0, 8, 8> q4_0_8x8_q8_0;
|
4121
|
+
|
4122
|
+
// instance for IQ4
|
4123
|
+
static const tensor_traits<block_iq4_nl, 4, 4> iq4_nl_4x4_q8_0;
|
4124
|
+
|
4125
|
+
} // namespace ggml::cpu::aarch64
|
4126
|
+
|
4127
|
+
static const ggml::cpu::tensor_traits * ggml_aarch64_get_optimal_repack_type(const struct ggml_tensor * cur) {
|
4128
|
+
if (cur->type == GGML_TYPE_Q4_0) {
|
4129
|
+
if (ggml_cpu_has_avx2() || (ggml_cpu_has_sve() && ggml_cpu_has_matmul_int8() && ggml_cpu_get_sve_cnt() == QK8_0)) {
|
4130
|
+
if (cur->ne[1] % 8 == 0) {
|
4131
|
+
return &ggml::cpu::aarch64::q4_0_8x8_q8_0;
|
4132
|
+
}
|
4133
|
+
}
|
4134
|
+
if (ggml_cpu_has_neon() && ggml_cpu_has_matmul_int8()) {
|
4135
|
+
if (cur->ne[1] % 4 == 0) {
|
4136
|
+
return &ggml::cpu::aarch64::q4_0_4x8_q8_0;
|
4137
|
+
}
|
4138
|
+
}
|
4139
|
+
if (ggml_cpu_has_neon() && ggml_cpu_has_dotprod()) {
|
4140
|
+
if (cur->ne[1] % 4 == 0) {
|
4141
|
+
return &ggml::cpu::aarch64::q4_0_4x4_q8_0;
|
4142
|
+
}
|
4143
|
+
}
|
4144
|
+
} else if (cur->type == GGML_TYPE_IQ4_NL) {
|
4145
|
+
if (ggml_cpu_has_neon() && ggml_cpu_has_dotprod()) {
|
4146
|
+
if (cur->ne[1] % 4 == 0) {
|
4147
|
+
return &ggml::cpu::aarch64::iq4_nl_4x4_q8_0;
|
4148
|
+
}
|
4149
|
+
}
|
4150
|
+
}
|
4151
|
+
|
4152
|
+
return nullptr;
|
4153
|
+
}
|
4154
|
+
|
4155
|
+
static void ggml_backend_cpu_aarch64_buffer_init_tensor(ggml_backend_buffer_t buffer, struct ggml_tensor * tensor) {
|
4156
|
+
tensor->extra = (void *) const_cast<ggml::cpu::tensor_traits *>(ggml_aarch64_get_optimal_repack_type(tensor));
|
4157
|
+
|
4158
|
+
GGML_UNUSED(buffer);
|
4159
|
+
}
|
4160
|
+
|
4161
|
+
static void ggml_backend_cpu_aarch64_buffer_set_tensor(ggml_backend_buffer_t buffer, struct ggml_tensor * tensor,
|
4162
|
+
const void * data, size_t offset, size_t size) {
|
4163
|
+
GGML_ASSERT(offset == 0);
|
4164
|
+
GGML_ASSERT(size == ggml_nbytes(tensor));
|
4165
|
+
|
4166
|
+
auto tensor_traits = (ggml::cpu::aarch64::tensor_traits_base *) tensor->extra;
|
4167
|
+
auto OK = tensor_traits->repack(tensor, data, size);
|
4168
|
+
|
4169
|
+
GGML_ASSERT(OK == 0);
|
4170
|
+
GGML_UNUSED(buffer);
|
4171
|
+
}
|
4172
|
+
|
4173
|
+
static const char * ggml_backend_cpu_aarch64_buffer_type_get_name(ggml_backend_buffer_type_t buft) {
|
4174
|
+
return "CPU_AARCH64";
|
4175
|
+
|
4176
|
+
GGML_UNUSED(buft);
|
4177
|
+
}
|
4178
|
+
|
4179
|
+
static ggml_backend_buffer_t ggml_backend_cpu_aarch64_buffer_type_alloc_buffer(ggml_backend_buffer_type_t buft, size_t size) {
|
4180
|
+
ggml_backend_buffer_t buffer = ggml_backend_buft_alloc_buffer(ggml_backend_cpu_buffer_type(), size);
|
4181
|
+
|
4182
|
+
if (buffer == nullptr) {
|
4183
|
+
return nullptr;
|
4184
|
+
}
|
4185
|
+
|
4186
|
+
buffer->buft = buft;
|
4187
|
+
buffer->iface.init_tensor = ggml_backend_cpu_aarch64_buffer_init_tensor;
|
4188
|
+
buffer->iface.set_tensor = ggml_backend_cpu_aarch64_buffer_set_tensor;
|
4189
|
+
return buffer;
|
4190
|
+
}
|
4191
|
+
|
4192
|
+
static size_t ggml_backend_cpu_aarch64_buffer_type_get_alignment(ggml_backend_buffer_type_t buft) {
|
4193
|
+
return TENSOR_ALIGNMENT;
|
4194
|
+
|
4195
|
+
GGML_UNUSED(buft);
|
4196
|
+
}
|
4197
|
+
|
4198
|
+
namespace ggml::cpu::aarch64 {
|
4199
|
+
class extra_buffer_type : ggml::cpu::extra_buffer_type {
|
4200
|
+
bool supports_op(ggml_backend_dev_t, const struct ggml_tensor * op) override {
|
4201
|
+
if ( op->op == GGML_OP_MUL_MAT &&
|
4202
|
+
op->src[0]->buffer &&
|
4203
|
+
(ggml_n_dims(op->src[0]) == 2) &&
|
4204
|
+
op->src[0]->buffer->buft == ggml_backend_cpu_aarch64_buffer_type() &&
|
4205
|
+
ggml_aarch64_get_optimal_repack_type(op->src[0])
|
4206
|
+
) {
|
4207
|
+
if (op->src[1]->buffer && !ggml_backend_buft_is_host(op->src[1]->buffer->buft)) {
|
4208
|
+
return false;
|
4209
|
+
}
|
4210
|
+
if (op->src[1]->type == GGML_TYPE_F32) {
|
4211
|
+
return true;
|
4212
|
+
}
|
4213
|
+
//if (op->src[1]->type == GGML_TYPE_Q8_0) {
|
4214
|
+
// return true;
|
4215
|
+
//}
|
4216
|
+
// may be possible if Q8_0 packed...
|
4217
|
+
} else if (op->op == GGML_OP_MUL_MAT_ID
|
4218
|
+
&& op->src[0]->buffer
|
4219
|
+
&& (ggml_n_dims(op->src[0]) == 3)
|
4220
|
+
&& op->src[0]->buffer->buft == ggml_backend_cpu_aarch64_buffer_type()
|
4221
|
+
&& ggml_aarch64_get_optimal_repack_type(op->src[0])
|
4222
|
+
) {
|
4223
|
+
if (op->src[1]->buffer && !ggml_backend_buft_is_host(op->src[1]->buffer->buft)) {
|
4224
|
+
return false;
|
4225
|
+
}
|
4226
|
+
if (op->src[1]->type == GGML_TYPE_F32) {
|
4227
|
+
return true;
|
4228
|
+
}
|
4229
|
+
//if (op->src[1]->type == GGML_TYPE_Q8_0) {
|
4230
|
+
// return true;
|
4231
|
+
//}
|
4232
|
+
}
|
4233
|
+
return false;
|
4234
|
+
}
|
4235
|
+
|
4236
|
+
ggml::cpu::tensor_traits * get_tensor_traits(const struct ggml_tensor * op) override {
|
4237
|
+
if (op->op == GGML_OP_MUL_MAT || op->op == GGML_OP_MUL_MAT_ID) {
|
4238
|
+
if (op->src[0]->buffer && op->src[0]->buffer->buft == ggml_backend_cpu_aarch64_buffer_type()) {
|
4239
|
+
return (ggml::cpu::tensor_traits *) op->src[0]->extra;
|
4240
|
+
}
|
4241
|
+
}
|
4242
|
+
return nullptr;
|
4243
|
+
}
|
4244
|
+
};
|
4245
|
+
} // namespace ggml::cpu::aarch64
|
4246
|
+
|
4247
|
+
ggml_backend_buffer_type_t ggml_backend_cpu_aarch64_buffer_type(void) {
|
4248
|
+
static struct ggml_backend_buffer_type ggml_backend_cpu_buffer_type_aarch64 = {
|
4249
|
+
/* .iface = */ {
|
4250
|
+
/* .get_name = */ ggml_backend_cpu_aarch64_buffer_type_get_name,
|
4251
|
+
/* .alloc_buffer = */ ggml_backend_cpu_aarch64_buffer_type_alloc_buffer,
|
4252
|
+
/* .get_alignment = */ ggml_backend_cpu_aarch64_buffer_type_get_alignment,
|
4253
|
+
/* .get_max_size = */ nullptr, // defaults to SIZE_MAX
|
4254
|
+
/* .get_alloc_size = */ nullptr, // defaults to ggml_nbytes
|
4255
|
+
/* .is_host = */ nullptr,
|
4256
|
+
},
|
4257
|
+
/* .device = */ ggml_backend_reg_dev_get(ggml_backend_cpu_reg(), 0),
|
4258
|
+
/* .context = */ new ggml::cpu::aarch64::extra_buffer_type(),
|
4259
|
+
};
|
4260
|
+
|
4261
|
+
return &ggml_backend_cpu_buffer_type_aarch64;
|
4262
|
+
}
|