| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
#include <assert.h> |
| 11 |
|
| 12 |
#include <arm_neon.h> |
| 13 |
|
| 14 |
#include "xnnpack/prefetch.h" |
| 15 |
#include "xnnpack/spmm.h" |
| 16 |
|
| 17 |
|
| 18 |
void xnn_f32_spmm_minmax_ukernel_4x4__aarch64_neonfma( |
| 19 |
size_t mc, |
| 20 |
size_t nc, |
| 21 |
const float* input, |
| 22 |
const float* weights, |
| 23 |
const int32_t* widx_dmap, |
| 24 |
const uint32_t* nidx_nnzmap, |
| 25 |
float* output, |
| 26 |
size_t output_stride, |
| 27 |
const union xnn_f32_minmax_params params[restrict XNN_MIN_ELEMENTS(1)]) |
| 28 |
{ |
| 29 |
assert(mc != 0); |
| 30 |
assert(mc % sizeof(float) == 0); |
| 31 |
assert(nc != 0); |
| 32 |
|
| 33 |
#if XNN_ARCH_ARM64 |
| 34 |
const float32x4x2_t vminmax = vld2q_dup_f32(¶ms->scalar.min); |
| 35 |
const float32x4_t vmin = vminmax.val[0]; |
| 36 |
const float32x4_t vmax = vminmax.val[1]; |
| 37 |
#else |
| 38 |
const float32x2x2_t vminmax = vld2_dup_f32(¶ms->scalar.min); |
| 39 |
const float32x4_t vmin = vcombine_f32(vminmax.val[0], vminmax.val[0]); |
| 40 |
const float32x4_t vmax = vcombine_f32(vminmax.val[1], vminmax.val[1]); |
| 41 |
#endif |
| 42 |
|
| 43 |
size_t output_decrement = output_stride * nc - 4 * sizeof(float); |
| 44 |
while XNN_LIKELY(mc >= 4 * sizeof(float)) { |
| 45 |
const float* w = weights; |
| 46 |
const int32_t* dmap = widx_dmap; |
| 47 |
const uint32_t* nnzmap = nidx_nnzmap; |
| 48 |
size_t n = nc; |
| 49 |
while (n >= 4) { |
| 50 |
uint32_t nnz = *nnzmap++; |
| 51 |
float32x4_t vacc0123n0 = vld1q_dup_f32(w); w += 1; |
| 52 |
float32x4_t vacc0123n1 = vld1q_dup_f32(w); w += 1; |
| 53 |
float32x4_t vacc0123n2 = vld1q_dup_f32(w); w += 1; |
| 54 |
float32x4_t vacc0123n3 = vld1q_dup_f32(w); w += 1; |
| 55 |
if XNN_LIKELY(nnz != 0) { |
| 56 |
do { |
| 57 |
const intptr_t diff = *dmap++; |
| 58 |
const float32x4_t vi0123 = vld1q_f32(input); |
| 59 |
input = (const float*) ((uintptr_t) input + (uintptr_t) diff); |
| 60 |
xnn_prefetch_to_l1(input + 16); |
| 61 |
const float32x4_t vw = vld1q_f32(w); w += 4; |
| 62 |
xnn_prefetch_to_l1(w + 32); |
| 63 |
vacc0123n0 = vfmaq_laneq_f32(vacc0123n0, vi0123, vw, 0); |
| 64 |
vacc0123n1 = vfmaq_laneq_f32(vacc0123n1, vi0123, vw, 1); |
| 65 |
vacc0123n2 = vfmaq_laneq_f32(vacc0123n2, vi0123, vw, 2); |
| 66 |
vacc0123n3 = vfmaq_laneq_f32(vacc0123n3, vi0123, vw, 3); |
| 67 |
} while (--nnz != 0); |
| 68 |
} |
| 69 |
float32x4_t vout0123n0 = vminq_f32(vacc0123n0, vmax); |
| 70 |
float32x4_t vout0123n1 = vminq_f32(vacc0123n1, vmax); |
| 71 |
float32x4_t vout0123n2 = vminq_f32(vacc0123n2, vmax); |
| 72 |
float32x4_t vout0123n3 = vminq_f32(vacc0123n3, vmax); |
| 73 |
|
| 74 |
vout0123n0 = vmaxq_f32(vout0123n0, vmin); |
| 75 |
vout0123n1 = vmaxq_f32(vout0123n1, vmin); |
| 76 |
vout0123n2 = vmaxq_f32(vout0123n2, vmin); |
| 77 |
vout0123n3 = vmaxq_f32(vout0123n3, vmin); |
| 78 |
|
| 79 |
vst1q_f32(output + 0, vout0123n0); |
| 80 |
output = (float*) ((uintptr_t) output + output_stride); |
| 81 |
vst1q_f32(output + 0, vout0123n1); |
| 82 |
output = (float*) ((uintptr_t) output + output_stride); |
| 83 |
vst1q_f32(output + 0, vout0123n2); |
| 84 |
output = (float*) ((uintptr_t) output + output_stride); |
| 85 |
vst1q_f32(output + 0, vout0123n3); |
| 86 |
output = (float*) ((uintptr_t) output + output_stride); |
| 87 |
n -= 4; |
| 88 |
} |
| 89 |
|
| 90 |
|
| 91 |
if XNN_UNLIKELY(n != 0) { |
| 92 |
do { |
| 93 |
uint32_t nnz = *nnzmap++; |
| 94 |
float32x4_t vacc0123 = vld1q_dup_f32(w); w += 1; |
| 95 |
if XNN_LIKELY(nnz != 0) { |
| 96 |
do { |
| 97 |
const intptr_t diff = *dmap++; |
| 98 |
const float32x4_t vi0123 = vld1q_f32(input); |
| 99 |
input = (const float*) ((uintptr_t) input + (uintptr_t) diff); |
| 100 |
xnn_prefetch_to_l1(input + 16); |
| 101 |
const float32x4_t vw = vld1q_dup_f32(w); w += 1; |
| 102 |
xnn_prefetch_to_l1(w + 32); |
| 103 |
vacc0123 = vfmaq_f32(vacc0123, vi0123, vw); |
| 104 |
} while (--nnz != 0); |
| 105 |
} |
| 106 |
float32x4_t vout0123 = vminq_f32(vacc0123, vmax); |
| 107 |
|
| 108 |
vout0123 = vmaxq_f32(vout0123, vmin); |
| 109 |
|
| 110 |
vst1q_f32(output + 0, vout0123); |
| 111 |
output = (float*) ((uintptr_t) output + output_stride); |
| 112 |
n -= 1; |
| 113 |
} while (n != 0); |
| 114 |
} |
| 115 |
output = (float*) ((uintptr_t) output - output_decrement); |
| 116 |
input += 4; |
| 117 |
mc -= 4 * sizeof(float); |
| 118 |
} |
| 119 |
if XNN_UNLIKELY(mc != 0) { |
| 120 |
output_decrement += 2 * sizeof(float); |
| 121 |
if (mc & (2 * sizeof(float))) { |
| 122 |
const float* w = weights; |
| 123 |
const int32_t* dmap = widx_dmap; |
| 124 |
const uint32_t* nnzmap = nidx_nnzmap; |
| 125 |
size_t n = nc; |
| 126 |
while (n >= 4) { |
| 127 |
uint32_t nnz = *nnzmap++; |
| 128 |
float32x2_t vacc01n0 = vld1_dup_f32(w); w += 1; |
| 129 |
float32x2_t vacc01n1 = vld1_dup_f32(w); w += 1; |
| 130 |
float32x2_t vacc01n2 = vld1_dup_f32(w); w += 1; |
| 131 |
float32x2_t vacc01n3 = vld1_dup_f32(w); w += 1; |
| 132 |
if XNN_LIKELY(nnz != 0) { |
| 133 |
do { |
| 134 |
const intptr_t diff = *dmap++; |
| 135 |
const float32x2_t vi01 = vld1_f32(input); |
| 136 |
input = (const float*) ((uintptr_t) input + (uintptr_t) diff); |
| 137 |
const float32x4_t vw = vld1q_f32(w); w += 4; |
| 138 |
|
| 139 |
vacc01n0 = vfma_laneq_f32(vacc01n0, vi01, vw, 0); |
| 140 |
vacc01n1 = vfma_laneq_f32(vacc01n1, vi01, vw, 1); |
| 141 |
vacc01n2 = vfma_laneq_f32(vacc01n2, vi01, vw, 2); |
| 142 |
vacc01n3 = vfma_laneq_f32(vacc01n3, vi01, vw, 3); |
| 143 |
} while (--nnz != 0); |
| 144 |
} |
| 145 |
float32x2_t vout01n0 = vmin_f32(vacc01n0, vget_low_f32(vmax)); |
| 146 |
float32x2_t vout01n1 = vmin_f32(vacc01n1, vget_low_f32(vmax)); |
| 147 |
float32x2_t vout01n2 = vmin_f32(vacc01n2, vget_low_f32(vmax)); |
| 148 |
float32x2_t vout01n3 = vmin_f32(vacc01n3, vget_low_f32(vmax)); |
| 149 |
|
| 150 |
vout01n0 = vmax_f32(vout01n0, vget_low_f32(vmin)); |
| 151 |
vout01n1 = vmax_f32(vout01n1, vget_low_f32(vmin)); |
| 152 |
vout01n2 = vmax_f32(vout01n2, vget_low_f32(vmin)); |
| 153 |
vout01n3 = vmax_f32(vout01n3, vget_low_f32(vmin)); |
| 154 |
|
| 155 |
vst1_f32(output + 0, vout01n0); |
| 156 |
output = (float*) ((uintptr_t) output + output_stride); |
| 157 |
vst1_f32(output + 0, vout01n1); |
| 158 |
output = (float*) ((uintptr_t) output + output_stride); |
| 159 |
vst1_f32(output + 0, vout01n2); |
| 160 |
output = (float*) ((uintptr_t) output + output_stride); |
| 161 |
vst1_f32(output + 0, vout01n3); |
| 162 |
output = (float*) ((uintptr_t) output + output_stride); |
| 163 |
n -= 4; |
| 164 |
} |
| 165 |
|
| 166 |
|
| 167 |
if XNN_UNLIKELY(n != 0) { |
| 168 |
do { |
| 169 |
uint32_t nnz = *nnzmap++; |
| 170 |
float32x2_t vacc01 = vld1_dup_f32(w); w += 1; |
| 171 |
if XNN_LIKELY(nnz != 0) { |
| 172 |
do { |
| 173 |
const intptr_t diff = *dmap++; |
| 174 |
const float32x2_t vi01 = vld1_f32(input); |
| 175 |
input = (const float*) ((uintptr_t) input + (uintptr_t) diff); |
| 176 |
const float32x2_t vw = vld1_dup_f32(w); w += 1; |
| 177 |
vacc01 = vfma_f32(vacc01, vi01, vw); |
| 178 |
} while (--nnz != 0); |
| 179 |
} |
| 180 |
float32x2_t vout01 = vmin_f32(vacc01, vget_low_f32(vmax)); |
| 181 |
vout01 = vmax_f32(vout01, vget_low_f32(vmin)); |
| 182 |
|
| 183 |
vst1_f32(output, vout01); |
| 184 |
output = (float*) ((uintptr_t) output + output_stride); |
| 185 |
n -= 1; |
| 186 |
} while (n != 0); |
| 187 |
} |
| 188 |
output = (float*) ((uintptr_t) output - output_decrement); |
| 189 |
input += 2; |
| 190 |
} |
| 191 |
output_decrement += 1 * sizeof(float); |
| 192 |
if (mc & (1 * sizeof(float))) { |
| 193 |
const float* w = weights; |
| 194 |
const int32_t* dmap = widx_dmap; |
| 195 |
const uint32_t* nnzmap = nidx_nnzmap; |
| 196 |
size_t n = nc; |
| 197 |
while (n >= 4) { |
| 198 |
uint32_t nnz = *nnzmap++; |
| 199 |
float32x2_t vacc0n0 = vld1_dup_f32(w); w += 1; |
| 200 |
float32x2_t vacc0n1 = vld1_dup_f32(w); w += 1; |
| 201 |
float32x2_t vacc0n2 = vld1_dup_f32(w); w += 1; |
| 202 |
float32x2_t vacc0n3 = vld1_dup_f32(w); w += 1; |
| 203 |
if XNN_LIKELY(nnz != 0) { |
| 204 |
do { |
| 205 |
const intptr_t diff = *dmap++; |
| 206 |
const float32x2_t vi0 = vld1_dup_f32(input); |
| 207 |
input = (const float*) ((uintptr_t) input + (uintptr_t) diff); |
| 208 |
const float32x4_t vw = vld1q_f32(w); w += 4; |
| 209 |
|
| 210 |
vacc0n0 = vfma_laneq_f32(vacc0n0, vi0, vw, 0); |
| 211 |
vacc0n1 = vfma_laneq_f32(vacc0n1, vi0, vw, 1); |
| 212 |
vacc0n2 = vfma_laneq_f32(vacc0n2, vi0, vw, 2); |
| 213 |
vacc0n3 = vfma_laneq_f32(vacc0n3, vi0, vw, 3); |
| 214 |
} while (--nnz != 0); |
| 215 |
} |
| 216 |
float32x2_t vout0n0 = vmin_f32(vacc0n0, vget_low_f32(vmax)); |
| 217 |
float32x2_t vout0n1 = vmin_f32(vacc0n1, vget_low_f32(vmax)); |
| 218 |
float32x2_t vout0n2 = vmin_f32(vacc0n2, vget_low_f32(vmax)); |
| 219 |
float32x2_t vout0n3 = vmin_f32(vacc0n3, vget_low_f32(vmax)); |
| 220 |
|
| 221 |
vout0n0 = vmax_f32(vout0n0, vget_low_f32(vmin)); |
| 222 |
vout0n1 = vmax_f32(vout0n1, vget_low_f32(vmin)); |
| 223 |
vout0n2 = vmax_f32(vout0n2, vget_low_f32(vmin)); |
| 224 |
vout0n3 = vmax_f32(vout0n3, vget_low_f32(vmin)); |
| 225 |
|
| 226 |
vst1_lane_f32(output + 0, vout0n0, 0); |
| 227 |
output = (float*) ((uintptr_t) output + output_stride); |
| 228 |
vst1_lane_f32(output + 0, vout0n1, 0); |
| 229 |
output = (float*) ((uintptr_t) output + output_stride); |
| 230 |
vst1_lane_f32(output + 0, vout0n2, 0); |
| 231 |
output = (float*) ((uintptr_t) output + output_stride); |
| 232 |
vst1_lane_f32(output + 0, vout0n3, 0); |
| 233 |
output = (float*) ((uintptr_t) output + output_stride); |
| 234 |
n -= 4; |
| 235 |
} |
| 236 |
|
| 237 |
|
| 238 |
if XNN_UNLIKELY(n != 0) { |
| 239 |
do { |
| 240 |
uint32_t nnz = *nnzmap++; |
| 241 |
float32x2_t vacc0 = vld1_dup_f32(w); w += 1; |
| 242 |
if XNN_LIKELY(nnz != 0) { |
| 243 |
do { |
| 244 |
const intptr_t diff = *dmap++; |
| 245 |
const float32x2_t vi0 = vld1_dup_f32(input); |
| 246 |
input = (const float*) ((uintptr_t) input + (uintptr_t) diff); |
| 247 |
const float32x2_t vw = vld1_dup_f32(w); w += 1; |
| 248 |
vacc0 = vfma_f32(vacc0, vi0, vw); |
| 249 |
} while (--nnz != 0); |
| 250 |
} |
| 251 |
float32x2_t vout0 = vmin_f32(vacc0, vget_low_f32(vmax)); |
| 252 |
vout0 = vmax_f32(vout0, vget_low_f32(vmin)); |
| 253 |
|
| 254 |
vst1_lane_f32(output, vout0, 1); |
| 255 |
output = (float*) ((uintptr_t) output + output_stride); |
| 256 |
n -= 1; |
| 257 |
} while (n != 0); |
| 258 |
} |
| 259 |
output = (float*) ((uintptr_t) output - output_decrement); |
| 260 |
input += 1; |
| 261 |
} |
| 262 |
} |
| 263 |
} |