| 1 |
// Auto-generated file. Do not edit! |
| 2 |
// Template: src/qs8-igemm/c4-neondot.c.in |
| 3 |
// Generator: tools/xngen |
| 4 |
// |
| 5 |
// Copyright 2020 Google LLC |
| 6 |
// |
| 7 |
// This source code is licensed under the BSD-style license found in the |
| 8 |
// LICENSE file in the root directory of this source tree. |
| 9 |
|
| 10 |
#include <assert.h> |
| 11 |
|
| 12 |
#include <arm_neon.h> |
| 13 |
|
| 14 |
#include "xnnpack/igemm.h" |
| 15 |
#include "xnnpack/math.h" |
| 16 |
|
| 17 |
|
| 18 |
void xnn_qd8_f16_qc8w_igemm_minmax_ukernel_1x32c4__neondotfp16arith( |
| 19 |
size_t mr, |
| 20 |
size_t nc, |
| 21 |
size_t kc, |
| 22 |
size_t ks, |
| 23 |
const int8_t** restrict a, |
| 24 |
const void* restrict w, |
| 25 |
xnn_float16* restrict c, |
| 26 |
size_t cm_stride, |
| 27 |
size_t cn_stride, |
| 28 |
size_t a_offset, |
| 29 |
const int8_t* zero, |
| 30 |
const int8_t* zero_data, |
| 31 |
const union xnn_f16_minmax_params params[restrict XNN_MIN_ELEMENTS(1)], |
| 32 |
const struct xnn_qd8_quantization_params quantization_params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS |
| 33 |
{ |
| 34 |
assert(mr != 0); |
| 35 |
assert(mr <= 1); |
| 36 |
assert(nc != 0); |
| 37 |
assert(kc != 0); |
| 38 |
assert(ks != 0); |
| 39 |
assert(ks % (1 * sizeof(void*)) == 0); |
| 40 |
assert(a_offset % sizeof(int8_t) == 0); |
| 41 |
assert(a != NULL); |
| 42 |
assert(w != NULL); |
| 43 |
assert(c != NULL); |
| 44 |
|
| 45 |
kc = round_up_po2(kc, 4 * sizeof(int8_t)); |
| 46 |
uint16_t* c0 = (uint16_t*) c; |
| 47 |
|
| 48 |
do { |
| 49 |
const int32x4_t vinput_zero_point = vld1q_dup_s32(&quantization_params->zero_point); |
| 50 |
const int32x4_t vksum0123 = vld1q_s32(w); w = (const int32_t*) w + 4; |
| 51 |
int32x4_t vacc0x0123 = vmulq_s32(vksum0123, vinput_zero_point); |
| 52 |
const int32x4_t vksum4567 = vld1q_s32(w); w = (const int32_t*) w + 4; |
| 53 |
int32x4_t vacc0x4567 = vmulq_s32(vksum4567, vinput_zero_point); |
| 54 |
const int32x4_t vksum89AB = vld1q_s32(w); w = (const int32_t*) w + 4; |
| 55 |
int32x4_t vacc0x89AB = vmulq_s32(vksum89AB, vinput_zero_point); |
| 56 |
const int32x4_t vksumCDEF = vld1q_s32(w); w = (const int32_t*) w + 4; |
| 57 |
int32x4_t vacc0xCDEF = vmulq_s32(vksumCDEF, vinput_zero_point); |
| 58 |
const int32x4_t vksumGHIJ = vld1q_s32(w); w = (const int32_t*) w + 4; |
| 59 |
int32x4_t vacc0xGHIJ = vmulq_s32(vksumGHIJ, vinput_zero_point); |
| 60 |
const int32x4_t vksumKLMN = vld1q_s32(w); w = (const int32_t*) w + 4; |
| 61 |
int32x4_t vacc0xKLMN = vmulq_s32(vksumKLMN, vinput_zero_point); |
| 62 |
const int32x4_t vksumOPQR = vld1q_s32(w); w = (const int32_t*) w + 4; |
| 63 |
int32x4_t vacc0xOPQR = vmulq_s32(vksumOPQR, vinput_zero_point); |
| 64 |
const int32x4_t vksumSTUV = vld1q_s32(w); w = (const int32_t*) w + 4; |
| 65 |
int32x4_t vacc0xSTUV = vmulq_s32(vksumSTUV, vinput_zero_point); |
| 66 |
|
| 67 |
size_t p = ks; |
| 68 |
do { |
| 69 |
const int8_t* restrict a0 = a[0]; |
| 70 |
if XNN_UNPREDICTABLE(a0 != zero) { |
| 71 |
a0 = (const int8_t*) ((uintptr_t) a0 + a_offset); |
| 72 |
} else { |
| 73 |
a0 = zero_data; |
| 74 |
} |
| 75 |
a += 1; |
| 76 |
|
| 77 |
// Inner accumulation loop along the 32 columns. |
| 78 |
size_t k = kc; |
| 79 |
// 2x partial unrolled loop to load 8 bytes at a time. |
| 80 |
while (k >= 8 * sizeof(int8_t)) { |
| 81 |
// Load a 1x8 block of activations. |
| 82 |
const int8x8_t va0x01234567 = vld1_s8(a0); a0 += 8; |
| 83 |
|
| 84 |
// Load a 8x32 block of weights. |
| 85 |
const int8x16_t vb0123x0123 = vld1q_s8(w); w = (const int8_t*) w + 16; |
| 86 |
const int8x16_t vb0123x4567 = vld1q_s8(w); w = (const int8_t*) w + 16; |
| 87 |
const int8x16_t vb0123x89AB = vld1q_s8(w); w = (const int8_t*) w + 16; |
| 88 |
const int8x16_t vb0123xCDEF = vld1q_s8(w); w = (const int8_t*) w + 16; |
| 89 |
const int8x16_t vb0123xGHIJ = vld1q_s8(w); w = (const int8_t*) w + 16; |
| 90 |
const int8x16_t vb0123xKLMN = vld1q_s8(w); w = (const int8_t*) w + 16; |
| 91 |
const int8x16_t vb0123xOPQR = vld1q_s8(w); w = (const int8_t*) w + 16; |
| 92 |
const int8x16_t vb0123xSTUV = vld1q_s8(w); w = (const int8_t*) w + 16; |
| 93 |
const int8x16_t vb4567x0123 = vld1q_s8(w); w = (const int8_t*) w + 16; |
| 94 |
const int8x16_t vb4567x4567 = vld1q_s8(w); w = (const int8_t*) w + 16; |
| 95 |
const int8x16_t vb4567x89AB = vld1q_s8(w); w = (const int8_t*) w + 16; |
| 96 |
const int8x16_t vb4567xCDEF = vld1q_s8(w); w = (const int8_t*) w + 16; |
| 97 |
const int8x16_t vb4567xGHIJ = vld1q_s8(w); w = (const int8_t*) w + 16; |
| 98 |
const int8x16_t vb4567xKLMN = vld1q_s8(w); w = (const int8_t*) w + 16; |
| 99 |
const int8x16_t vb4567xOPQR = vld1q_s8(w); w = (const int8_t*) w + 16; |
| 100 |
const int8x16_t vb4567xSTUV = vld1q_s8(w); w = (const int8_t*) w + 16; |
| 101 |
|
| 102 |
// Multiply-accumulate: 1x8 * 8x32 --> 1x32. |
| 103 |
vacc0x0123 = vdotq_lane_s32(vacc0x0123, vb0123x0123, va0x01234567, 0); |
| 104 |
vacc0x4567 = vdotq_lane_s32(vacc0x4567, vb0123x4567, va0x01234567, 0); |
| 105 |
vacc0x89AB = vdotq_lane_s32(vacc0x89AB, vb0123x89AB, va0x01234567, 0); |
| 106 |
vacc0xCDEF = vdotq_lane_s32(vacc0xCDEF, vb0123xCDEF, va0x01234567, 0); |
| 107 |
vacc0xGHIJ = vdotq_lane_s32(vacc0xGHIJ, vb0123xGHIJ, va0x01234567, 0); |
| 108 |
vacc0xKLMN = vdotq_lane_s32(vacc0xKLMN, vb0123xKLMN, va0x01234567, 0); |
| 109 |
vacc0xOPQR = vdotq_lane_s32(vacc0xOPQR, vb0123xOPQR, va0x01234567, 0); |
| 110 |
vacc0xSTUV = vdotq_lane_s32(vacc0xSTUV, vb0123xSTUV, va0x01234567, 0); |
| 111 |
vacc0x0123 = vdotq_lane_s32(vacc0x0123, vb4567x0123, va0x01234567, 1); |
| 112 |
vacc0x4567 = vdotq_lane_s32(vacc0x4567, vb4567x4567, va0x01234567, 1); |
| 113 |
vacc0x89AB = vdotq_lane_s32(vacc0x89AB, vb4567x89AB, va0x01234567, 1); |
| 114 |
vacc0xCDEF = vdotq_lane_s32(vacc0xCDEF, vb4567xCDEF, va0x01234567, 1); |
| 115 |
vacc0xGHIJ = vdotq_lane_s32(vacc0xGHIJ, vb4567xGHIJ, va0x01234567, 1); |
| 116 |
vacc0xKLMN = vdotq_lane_s32(vacc0xKLMN, vb4567xKLMN, va0x01234567, 1); |
| 117 |
vacc0xOPQR = vdotq_lane_s32(vacc0xOPQR, vb4567xOPQR, va0x01234567, 1); |
| 118 |
vacc0xSTUV = vdotq_lane_s32(vacc0xSTUV, vb4567xSTUV, va0x01234567, 1); |
| 119 |
|
| 120 |
k -= 8 * sizeof(int8_t); |
| 121 |
} |
| 122 |
// Handle up to 4 final positions of `k` |
| 123 |
if XNN_UNLIKELY(k != 0) { |
| 124 |
// Load a 1x4 block of activations. |
| 125 |
const int8x8_t va0x01234567 = vld1_s8(a0); |
| 126 |
|
| 127 |
// Load a 4x32 block of weights. |
| 128 |
const int8x16_t vb0123x0123 = vld1q_s8(w); w = (const int8_t*) w + 16; |
| 129 |
const int8x16_t vb0123x4567 = vld1q_s8(w); w = (const int8_t*) w + 16; |
| 130 |
const int8x16_t vb0123x89AB = vld1q_s8(w); w = (const int8_t*) w + 16; |
| 131 |
const int8x16_t vb0123xCDEF = vld1q_s8(w); w = (const int8_t*) w + 16; |
| 132 |
const int8x16_t vb0123xGHIJ = vld1q_s8(w); w = (const int8_t*) w + 16; |
| 133 |
const int8x16_t vb0123xKLMN = vld1q_s8(w); w = (const int8_t*) w + 16; |
| 134 |
const int8x16_t vb0123xOPQR = vld1q_s8(w); w = (const int8_t*) w + 16; |
| 135 |
const int8x16_t vb0123xSTUV = vld1q_s8(w); w = (const int8_t*) w + 16; |
| 136 |
|
| 137 |
// Multiply-accumulate: 1x4 * 4x32 --> 1x32. |
| 138 |
vacc0x0123 = vdotq_lane_s32(vacc0x0123, vb0123x0123, va0x01234567, 0); |
| 139 |
vacc0x4567 = vdotq_lane_s32(vacc0x4567, vb0123x4567, va0x01234567, 0); |
| 140 |
vacc0x89AB = vdotq_lane_s32(vacc0x89AB, vb0123x89AB, va0x01234567, 0); |
| 141 |
vacc0xCDEF = vdotq_lane_s32(vacc0xCDEF, vb0123xCDEF, va0x01234567, 0); |
| 142 |
vacc0xGHIJ = vdotq_lane_s32(vacc0xGHIJ, vb0123xGHIJ, va0x01234567, 0); |
| 143 |
vacc0xKLMN = vdotq_lane_s32(vacc0xKLMN, vb0123xKLMN, va0x01234567, 0); |
| 144 |
vacc0xOPQR = vdotq_lane_s32(vacc0xOPQR, vb0123xOPQR, va0x01234567, 0); |
| 145 |
vacc0xSTUV = vdotq_lane_s32(vacc0xSTUV, vb0123xSTUV, va0x01234567, 0); |
| 146 |
} |
| 147 |
p -= 1 * sizeof(void*); |
| 148 |
} while (p != 0); |
| 149 |
|
| 150 |
float32x4_t vout0x0123 = vcvtq_f32_s32(vacc0x0123); |
| 151 |
float32x4_t vout0x4567 = vcvtq_f32_s32(vacc0x4567); |
| 152 |
float32x4_t vout0x89AB = vcvtq_f32_s32(vacc0x89AB); |
| 153 |
float32x4_t vout0xCDEF = vcvtq_f32_s32(vacc0xCDEF); |
| 154 |
float32x4_t vout0xGHIJ = vcvtq_f32_s32(vacc0xGHIJ); |
| 155 |
float32x4_t vout0xKLMN = vcvtq_f32_s32(vacc0xKLMN); |
| 156 |
float32x4_t vout0xOPQR = vcvtq_f32_s32(vacc0xOPQR); |
| 157 |
float32x4_t vout0xSTUV = vcvtq_f32_s32(vacc0xSTUV); |
| 158 |
const float32x4_t vinput_scale = vld1q_dup_f32(&quantization_params->inv_scale); |
| 159 |
vout0x0123 = vmulq_f32(vout0x0123, vinput_scale); |
| 160 |
vout0x4567 = vmulq_f32(vout0x4567, vinput_scale); |
| 161 |
vout0x89AB = vmulq_f32(vout0x89AB, vinput_scale); |
| 162 |
vout0xCDEF = vmulq_f32(vout0xCDEF, vinput_scale); |
| 163 |
vout0xGHIJ = vmulq_f32(vout0xGHIJ, vinput_scale); |
| 164 |
vout0xKLMN = vmulq_f32(vout0xKLMN, vinput_scale); |
| 165 |
vout0xOPQR = vmulq_f32(vout0xOPQR, vinput_scale); |
| 166 |
vout0xSTUV = vmulq_f32(vout0xSTUV, vinput_scale); |
| 167 |
|
| 168 |
const float32x4_t vfilter_output_scale0123 = vld1q_f32(w); w = (const float*) w + 4; |
| 169 |
const float32x4_t vfilter_output_scale4567 = vld1q_f32(w); w = (const float*) w + 4; |
| 170 |
const float32x4_t vfilter_output_scale89AB = vld1q_f32(w); w = (const float*) w + 4; |
| 171 |
const float32x4_t vfilter_output_scaleCDEF = vld1q_f32(w); w = (const float*) w + 4; |
| 172 |
const float32x4_t vfilter_output_scaleGHIJ = vld1q_f32(w); w = (const float*) w + 4; |
| 173 |
const float32x4_t vfilter_output_scaleKLMN = vld1q_f32(w); w = (const float*) w + 4; |
| 174 |
const float32x4_t vfilter_output_scaleOPQR = vld1q_f32(w); w = (const float*) w + 4; |
| 175 |
const float32x4_t vfilter_output_scaleSTUV = vld1q_f32(w); w = (const float*) w + 4; |
| 176 |
|
| 177 |
const float32x4_t vbias0123 = vld1q_f32(w); w = (const float*) w + 4; |
| 178 |
#if XNN_ARCH_ARM64 |
| 179 |
vout0x0123 = vfmaq_f32(vbias0123, vout0x0123, vfilter_output_scale0123); |
| 180 |
#else |
| 181 |
vout0x0123 = vmlaq_f32(vbias0123, vout0x0123, vfilter_output_scale0123); |
| 182 |
#endif |
| 183 |
const float32x4_t vbias4567 = vld1q_f32(w); w = (const float*) w + 4; |
| 184 |
#if XNN_ARCH_ARM64 |
| 185 |
vout0x4567 = vfmaq_f32(vbias4567, vout0x4567, vfilter_output_scale4567); |
| 186 |
#else |
| 187 |
vout0x4567 = vmlaq_f32(vbias4567, vout0x4567, vfilter_output_scale4567); |
| 188 |
#endif |
| 189 |
const float32x4_t vbias89AB = vld1q_f32(w); w = (const float*) w + 4; |
| 190 |
#if XNN_ARCH_ARM64 |
| 191 |
vout0x89AB = vfmaq_f32(vbias89AB, vout0x89AB, vfilter_output_scale89AB); |
| 192 |
#else |
| 193 |
vout0x89AB = vmlaq_f32(vbias89AB, vout0x89AB, vfilter_output_scale89AB); |
| 194 |
#endif |
| 195 |
const float32x4_t vbiasCDEF = vld1q_f32(w); w = (const float*) w + 4; |
| 196 |
#if XNN_ARCH_ARM64 |
| 197 |
vout0xCDEF = vfmaq_f32(vbiasCDEF, vout0xCDEF, vfilter_output_scaleCDEF); |
| 198 |
#else |
| 199 |
vout0xCDEF = vmlaq_f32(vbiasCDEF, vout0xCDEF, vfilter_output_scaleCDEF); |
| 200 |
#endif |
| 201 |
const float32x4_t vbiasGHIJ = vld1q_f32(w); w = (const float*) w + 4; |
| 202 |
#if XNN_ARCH_ARM64 |
| 203 |
vout0xGHIJ = vfmaq_f32(vbiasGHIJ, vout0xGHIJ, vfilter_output_scaleGHIJ); |
| 204 |
#else |
| 205 |
vout0xGHIJ = vmlaq_f32(vbiasGHIJ, vout0xGHIJ, vfilter_output_scaleGHIJ); |
| 206 |
#endif |
| 207 |
const float32x4_t vbiasKLMN = vld1q_f32(w); w = (const float*) w + 4; |
| 208 |
#if XNN_ARCH_ARM64 |
| 209 |
vout0xKLMN = vfmaq_f32(vbiasKLMN, vout0xKLMN, vfilter_output_scaleKLMN); |
| 210 |
#else |
| 211 |
vout0xKLMN = vmlaq_f32(vbiasKLMN, vout0xKLMN, vfilter_output_scaleKLMN); |
| 212 |
#endif |
| 213 |
const float32x4_t vbiasOPQR = vld1q_f32(w); w = (const float*) w + 4; |
| 214 |
#if XNN_ARCH_ARM64 |
| 215 |
vout0xOPQR = vfmaq_f32(vbiasOPQR, vout0xOPQR, vfilter_output_scaleOPQR); |
| 216 |
#else |
| 217 |
vout0xOPQR = vmlaq_f32(vbiasOPQR, vout0xOPQR, vfilter_output_scaleOPQR); |
| 218 |
#endif |
| 219 |
const float32x4_t vbiasSTUV = vld1q_f32(w); w = (const float*) w + 4; |
| 220 |
#if XNN_ARCH_ARM64 |
| 221 |
vout0xSTUV = vfmaq_f32(vbiasSTUV, vout0xSTUV, vfilter_output_scaleSTUV); |
| 222 |
#else |
| 223 |
vout0xSTUV = vmlaq_f32(vbiasSTUV, vout0xSTUV, vfilter_output_scaleSTUV); |
| 224 |
#endif |
| 225 |
|
| 226 |
float16x8_t vfp16out0x01234567 = vcombine_f16(vcvt_f16_f32(vout0x0123), vcvt_f16_f32(vout0x4567)); |
| 227 |
float16x8_t vfp16out0x89ABCDEF = vcombine_f16(vcvt_f16_f32(vout0x89AB), vcvt_f16_f32(vout0xCDEF)); |
| 228 |
float16x8_t vfp16out0xGHIJKLMN = vcombine_f16(vcvt_f16_f32(vout0xGHIJ), vcvt_f16_f32(vout0xKLMN)); |
| 229 |
float16x8_t vfp16out0xOPQRSTUV = vcombine_f16(vcvt_f16_f32(vout0xOPQR), vcvt_f16_f32(vout0xSTUV)); |
| 230 |
|
| 231 |
const float16x8_t voutput_min = vreinterpretq_f16_u16(vld1q_dup_u16((const uint16_t*) ¶ms->scalar.min)); |
| 232 |
vfp16out0x01234567 = vmaxq_f16(vfp16out0x01234567, voutput_min); |
| 233 |
vfp16out0x89ABCDEF = vmaxq_f16(vfp16out0x89ABCDEF, voutput_min); |
| 234 |
vfp16out0xGHIJKLMN = vmaxq_f16(vfp16out0xGHIJKLMN, voutput_min); |
| 235 |
vfp16out0xOPQRSTUV = vmaxq_f16(vfp16out0xOPQRSTUV, voutput_min); |
| 236 |
const float16x8_t voutput_max = vreinterpretq_f16_u16(vld1q_dup_u16((const uint16_t*) ¶ms->scalar.max)); |
| 237 |
vfp16out0x01234567 = vminq_f16(vfp16out0x01234567, voutput_max); |
| 238 |
vfp16out0x89ABCDEF = vminq_f16(vfp16out0x89ABCDEF, voutput_max); |
| 239 |
vfp16out0xGHIJKLMN = vminq_f16(vfp16out0xGHIJKLMN, voutput_max); |
| 240 |
vfp16out0xOPQRSTUV = vminq_f16(vfp16out0xOPQRSTUV, voutput_max); |
| 241 |
if XNN_LIKELY(nc >= 32) { |
| 242 |
vst1q_u16(c0, vreinterpretq_u16_f16(vfp16out0x01234567)); |
| 243 |
vst1q_u16(c0 + 8, vreinterpretq_u16_f16(vfp16out0x89ABCDEF)); |
| 244 |
vst1q_u16(c0 + 16, vreinterpretq_u16_f16(vfp16out0xGHIJKLMN)); |
| 245 |
vst1q_u16(c0 + 24, vreinterpretq_u16_f16(vfp16out0xOPQRSTUV)); |
| 246 |
|
| 247 |
a = (const int8_t**restrict) ((uintptr_t) a - ks); |
| 248 |
|
| 249 |
c0 = (uint16_t*) ((uintptr_t) c0 + cn_stride); |
| 250 |
|
| 251 |
nc -= 32; |
| 252 |
} else { |
| 253 |
if (nc & 16) { |
| 254 |
vst1q_u16(c0, vreinterpretq_u16_f16(vfp16out0x01234567)); c0 += 8; |
| 255 |
vfp16out0x01234567 = vfp16out0xGHIJKLMN; |
| 256 |
vst1q_u16(c0, vreinterpretq_u16_f16(vfp16out0x89ABCDEF)); c0 += 8; |
| 257 |
vfp16out0x89ABCDEF = vfp16out0xOPQRSTUV; |
| 258 |
} |
| 259 |
if (nc & 8) { |
| 260 |
vst1q_u16(c0, vreinterpretq_u16_f16(vfp16out0x01234567)); c0 += 8; |
| 261 |
vfp16out0x01234567 = vfp16out0x89ABCDEF; |
| 262 |
} |
| 263 |
float16x4_t vfp16out0x0123 = vget_low_f16(vfp16out0x01234567); |
| 264 |
if (nc & 4) { |
| 265 |
vst1_u16(c0, vreinterpret_u16_f16(vfp16out0x0123)); c0 += 4; |
| 266 |
vfp16out0x0123 = vget_high_f16(vfp16out0x01234567); |
| 267 |
} |
| 268 |
if (nc & 2) { |
| 269 |
vst1_lane_u32((void*) c0, vreinterpret_u32_f16(vfp16out0x0123), 0); c0 += 2; |
| 270 |
vfp16out0x0123 = vext_f16(vfp16out0x0123, vfp16out0x0123, 2); |
| 271 |
} |
| 272 |
if (nc & 1) { |
| 273 |
vst1_lane_u16(c0, vreinterpret_u16_f16(vfp16out0x0123), 0); |
| 274 |
} |
| 275 |
nc = 0; |
| 276 |
} |
| 277 |
} while (nc != 0); |
| 278 |
} |