| 1 |
// Auto-generated file. Do not edit! |
| 2 |
// Template: src/f32-spmm/hvx.c.in |
| 3 |
// Generator: tools/xngen |
| 4 |
// |
| 5 |
// Copyright 2024 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 <hvx_hexagon_protos.h> |
| 13 |
#include <hexagon_protos.h> |
| 14 |
#include <hexagon_types.h> |
| 15 |
|
| 16 |
#include "xnnpack/simd/f32-hvx.h" |
| 17 |
|
| 18 |
#include "xnnpack/prefetch.h" |
| 19 |
#include "xnnpack/spmm.h" |
| 20 |
|
| 21 |
void xnn_f32_spmm_minmax_ukernel_64x1__hvx_x4( |
| 22 |
size_t mc, |
| 23 |
size_t nc, |
| 24 |
const float* input, |
| 25 |
const float* weights, |
| 26 |
const int32_t* widx_dmap, |
| 27 |
const uint32_t* nidx_nnzmap, |
| 28 |
float* output, |
| 29 |
size_t output_stride, |
| 30 |
const union xnn_f32_minmax_params params[restrict XNN_MIN_ELEMENTS(1)]) |
| 31 |
{ |
| 32 |
assert(mc != 0); |
| 33 |
assert(mc % sizeof(float) == 0); |
| 34 |
assert(nc != 0); |
| 35 |
|
| 36 |
const HVX_Vector vmin = xnn_set1_f32(params->scalar.min); |
| 37 |
const HVX_Vector vmax = xnn_set1_f32(params->scalar.max); |
| 38 |
|
| 39 |
size_t output_decrement = output_stride * nc - 64 * sizeof(float); |
| 40 |
while XNN_LIKELY(mc >= 64 * sizeof(float)) { |
| 41 |
const float* w = weights; |
| 42 |
const int32_t* dmap = widx_dmap; |
| 43 |
const uint32_t* nnzmap = nidx_nnzmap; |
| 44 |
size_t n = nc; |
| 45 |
do { |
| 46 |
uint32_t nnz = *nnzmap++; |
| 47 |
HVX_Vector vacc0x0 = xnn_set1_f32(*w); w += 1; |
| 48 |
HVX_Vector vacc0x1 = xnn_zero_f32(); |
| 49 |
HVX_Vector vacc0x2 = xnn_zero_f32(); |
| 50 |
HVX_Vector vacc0x3 = xnn_zero_f32(); |
| 51 |
HVX_Vector vacc1x0 = vacc0x0; |
| 52 |
HVX_Vector vacc1x1 = xnn_zero_f32(); |
| 53 |
HVX_Vector vacc1x2 = xnn_zero_f32(); |
| 54 |
HVX_Vector vacc1x3 = xnn_zero_f32(); |
| 55 |
for (; nnz >= 4; nnz -= 4) { |
| 56 |
const intptr_t diff0 = dmap[0]; |
| 57 |
const intptr_t diff1 = dmap[1]; |
| 58 |
const intptr_t diff2 = dmap[2]; |
| 59 |
const intptr_t diff3 = dmap[3]; |
| 60 |
dmap += 4; |
| 61 |
const HVX_Vector vi0x0 = xnn_loadu_f32(input); |
| 62 |
const HVX_Vector vi1x0 = xnn_loadu_f32(input + 32); |
| 63 |
input = (const float*) ((uintptr_t) input + (uintptr_t) diff0); |
| 64 |
|
| 65 |
const HVX_Vector vw0 = xnn_set1_f32(*w); w += 1; |
| 66 |
|
| 67 |
vacc0x0 = xnn_fmadd_f32(vi0x0, vw0, vacc0x0); |
| 68 |
vacc1x0 = xnn_fmadd_f32(vi1x0, vw0, vacc1x0); |
| 69 |
const HVX_Vector vi0x1 = xnn_loadu_f32(input); |
| 70 |
const HVX_Vector vi1x1 = xnn_loadu_f32(input + 32); |
| 71 |
input = (const float*) ((uintptr_t) input + (uintptr_t) diff1); |
| 72 |
|
| 73 |
const HVX_Vector vw1 = xnn_set1_f32(*w); w += 1; |
| 74 |
|
| 75 |
vacc0x1 = xnn_fmadd_f32(vi0x1, vw1, vacc0x1); |
| 76 |
vacc1x1 = xnn_fmadd_f32(vi1x1, vw1, vacc1x1); |
| 77 |
const HVX_Vector vi0x2 = xnn_loadu_f32(input); |
| 78 |
const HVX_Vector vi1x2 = xnn_loadu_f32(input + 32); |
| 79 |
input = (const float*) ((uintptr_t) input + (uintptr_t) diff2); |
| 80 |
|
| 81 |
const HVX_Vector vw2 = xnn_set1_f32(*w); w += 1; |
| 82 |
|
| 83 |
vacc0x2 = xnn_fmadd_f32(vi0x2, vw2, vacc0x2); |
| 84 |
vacc1x2 = xnn_fmadd_f32(vi1x2, vw2, vacc1x2); |
| 85 |
const HVX_Vector vi0x3 = xnn_loadu_f32(input); |
| 86 |
const HVX_Vector vi1x3 = xnn_loadu_f32(input + 32); |
| 87 |
input = (const float*) ((uintptr_t) input + (uintptr_t) diff3); |
| 88 |
|
| 89 |
const HVX_Vector vw3 = xnn_set1_f32(*w); w += 1; |
| 90 |
|
| 91 |
vacc0x3 = xnn_fmadd_f32(vi0x3, vw3, vacc0x3); |
| 92 |
vacc1x3 = xnn_fmadd_f32(vi1x3, vw3, vacc1x3); |
| 93 |
} |
| 94 |
HVX_Vector vacc0 = vacc0x0; |
| 95 |
HVX_Vector vacc1 = vacc1x0; |
| 96 |
vacc0 = xnn_add_f32(vacc0, vacc0x1); |
| 97 |
vacc1 = xnn_add_f32(vacc1, vacc1x1); |
| 98 |
vacc0 = xnn_add_f32(vacc0, vacc0x2); |
| 99 |
vacc1 = xnn_add_f32(vacc1, vacc1x2); |
| 100 |
vacc0 = xnn_add_f32(vacc0, vacc0x3); |
| 101 |
vacc1 = xnn_add_f32(vacc1, vacc1x3); |
| 102 |
if XNN_LIKELY(nnz != 0) { |
| 103 |
do { |
| 104 |
const intptr_t diff = *dmap++; |
| 105 |
const HVX_Vector vi0 = xnn_loadu_f32(input); |
| 106 |
const HVX_Vector vi1 = xnn_loadu_f32(input + 32); |
| 107 |
input = (const float*) ((uintptr_t) input + (uintptr_t) diff); |
| 108 |
|
| 109 |
const HVX_Vector vw = xnn_set1_f32(*w); w += 1; |
| 110 |
|
| 111 |
vacc0 = xnn_fmadd_f32(vi0, vw, vacc0); |
| 112 |
vacc1 = xnn_fmadd_f32(vi1, vw, vacc1); |
| 113 |
} while (--nnz != 0); |
| 114 |
} |
| 115 |
HVX_Vector vout0 = xnn_min_f32(vacc0, vmax); |
| 116 |
HVX_Vector vout1 = xnn_min_f32(vacc1, vmax); |
| 117 |
vout0 = xnn_max_f32(vout0, vmin); |
| 118 |
vout1 = xnn_max_f32(vout1, vmin); |
| 119 |
|
| 120 |
xnn_storeu_f32(output, vout0); |
| 121 |
xnn_storeu_f32(output + 32, vout1); |
| 122 |
output = (float*) ((uintptr_t) output + output_stride); |
| 123 |
} while (--n != 0); |
| 124 |
output = (float*) ((uintptr_t) output - output_decrement); |
| 125 |
input += 64; |
| 126 |
mc -= 64 * sizeof(float); |
| 127 |
} |
| 128 |
if XNN_UNLIKELY(mc != 0) { |
| 129 |
output_decrement += 32 * sizeof(float); |
| 130 |
if (mc & (32 * sizeof(float))) { |
| 131 |
const float* w = weights; |
| 132 |
const int32_t* dmap = widx_dmap; |
| 133 |
const uint32_t* nnzmap = nidx_nnzmap; |
| 134 |
size_t n = nc; |
| 135 |
do { |
| 136 |
uint32_t nnz = *nnzmap++; |
| 137 |
HVX_Vector vacc0 = xnn_set1_f32(*w); w += 1; |
| 138 |
if XNN_LIKELY(nnz != 0) { |
| 139 |
do { |
| 140 |
const intptr_t diff = *dmap++; |
| 141 |
const HVX_Vector vi0 = xnn_loadu_f32(input); |
| 142 |
input = (const float*) ((uintptr_t) input + (uintptr_t) diff); |
| 143 |
const HVX_Vector vw = xnn_set1_f32(*w); w += 1; |
| 144 |
vacc0 = xnn_fmadd_f32(vi0, vw, vacc0); |
| 145 |
} while (--nnz != 0); |
| 146 |
} |
| 147 |
HVX_Vector vout0 = xnn_min_f32(vacc0, vmax); |
| 148 |
vout0 = xnn_max_f32(vout0, vmin); |
| 149 |
|
| 150 |
xnn_storeu_f32(output, vout0); |
| 151 |
output = (float*) ((uintptr_t) output + output_stride); |
| 152 |
} while (--n != 0); |
| 153 |
output = (float*) ((uintptr_t) output - output_decrement); |
| 154 |
input += 32; |
| 155 |
} |
| 156 |
output_decrement += 16 * sizeof(float); |
| 157 |
if (mc & (16 * sizeof(float))) { |
| 158 |
const float* w = weights; |
| 159 |
const int32_t* dmap = widx_dmap; |
| 160 |
const uint32_t* nnzmap = nidx_nnzmap; |
| 161 |
size_t n = nc; |
| 162 |
do { |
| 163 |
uint32_t nnz = *nnzmap++; |
| 164 |
HVX_Vector vacc0 = xnn_set1_f32(*w); w += 1; |
| 165 |
if XNN_LIKELY(nnz != 0) { |
| 166 |
do { |
| 167 |
const intptr_t diff = *dmap++; |
| 168 |
const HVX_Vector vi0 = xnn_loadu_f32(input); |
| 169 |
input = (const float*) ((uintptr_t) input + (uintptr_t) diff); |
| 170 |
const HVX_Vector vw = xnn_set1_f32(*w); w += 1; |
| 171 |
vacc0 = xnn_fmadd_f32(vi0, vw, vacc0); |
| 172 |
} while (--nnz != 0); |
| 173 |
} |
| 174 |
HVX_Vector vout0 = xnn_min_f32(vacc0, vmax); |
| 175 |
vout0 = xnn_max_f32(vout0, vmin); |
| 176 |
|
| 177 |
xnn_store_tail_f32(output, vout0, 16); |
| 178 |
output = (float*) ((uintptr_t) output + output_stride); |
| 179 |
} while (--n != 0); |
| 180 |
output = (float*) ((uintptr_t) output - output_decrement); |
| 181 |
input += 16; |
| 182 |
} |
| 183 |
output_decrement += 8 * sizeof(float); |
| 184 |
if (mc & (8 * sizeof(float))) { |
| 185 |
const float* w = weights; |
| 186 |
const int32_t* dmap = widx_dmap; |
| 187 |
const uint32_t* nnzmap = nidx_nnzmap; |
| 188 |
size_t n = nc; |
| 189 |
do { |
| 190 |
uint32_t nnz = *nnzmap++; |
| 191 |
HVX_Vector vacc0 = xnn_set1_f32(*w); w += 1; |
| 192 |
if XNN_LIKELY(nnz != 0) { |
| 193 |
do { |
| 194 |
const intptr_t diff = *dmap++; |
| 195 |
const HVX_Vector vi0 = xnn_loadu_f32(input); |
| 196 |
input = (const float*) ((uintptr_t) input + (uintptr_t) diff); |
| 197 |
const HVX_Vector vw = xnn_set1_f32(*w); w += 1; |
| 198 |
vacc0 = xnn_fmadd_f32(vi0, vw, vacc0); |
| 199 |
} while (--nnz != 0); |
| 200 |
} |
| 201 |
HVX_Vector vout0 = xnn_min_f32(vacc0, vmax); |
| 202 |
vout0 = xnn_max_f32(vout0, vmin); |
| 203 |
|
| 204 |
xnn_store_tail_f32(output, vout0, 8); |
| 205 |
output = (float*) ((uintptr_t) output + output_stride); |
| 206 |
} while (--n != 0); |
| 207 |
output = (float*) ((uintptr_t) output - output_decrement); |
| 208 |
input += 8; |
| 209 |
} |
| 210 |
output_decrement += 4 * sizeof(float); |
| 211 |
if (mc & (4 * sizeof(float))) { |
| 212 |
const float* w = weights; |
| 213 |
const int32_t* dmap = widx_dmap; |
| 214 |
const uint32_t* nnzmap = nidx_nnzmap; |
| 215 |
size_t n = nc; |
| 216 |
do { |
| 217 |
uint32_t nnz = *nnzmap++; |
| 218 |
HVX_Vector vacc0 = xnn_set1_f32(*w); w += 1; |
| 219 |
if XNN_LIKELY(nnz != 0) { |
| 220 |
do { |
| 221 |
const intptr_t diff = *dmap++; |
| 222 |
const HVX_Vector vi0 = xnn_loadu_f32(input); |
| 223 |
input = (const float*) ((uintptr_t) input + (uintptr_t) diff); |
| 224 |
const HVX_Vector vw = xnn_set1_f32(*w); w += 1; |
| 225 |
vacc0 = xnn_fmadd_f32(vi0, vw, vacc0); |
| 226 |
} while (--nnz != 0); |
| 227 |
} |
| 228 |
HVX_Vector vout0 = xnn_min_f32(vacc0, vmax); |
| 229 |
vout0 = xnn_max_f32(vout0, vmin); |
| 230 |
|
| 231 |
xnn_store_tail_f32(output, vout0, 4); |
| 232 |
output = (float*) ((uintptr_t) output + output_stride); |
| 233 |
} while (--n != 0); |
| 234 |
output = (float*) ((uintptr_t) output - output_decrement); |
| 235 |
input += 4; |
| 236 |
} |
| 237 |
output_decrement += 2 * sizeof(float); |
| 238 |
if (mc & (2 * sizeof(float))) { |
| 239 |
const float* w = weights; |
| 240 |
const int32_t* dmap = widx_dmap; |
| 241 |
const uint32_t* nnzmap = nidx_nnzmap; |
| 242 |
size_t n = nc; |
| 243 |
do { |
| 244 |
uint32_t nnz = *nnzmap++; |
| 245 |
HVX_Vector vacc0 = xnn_set1_f32(*w); w += 1; |
| 246 |
if XNN_LIKELY(nnz != 0) { |
| 247 |
do { |
| 248 |
const intptr_t diff = *dmap++; |
| 249 |
const HVX_Vector vi0 = xnn_loadu_f32(input); |
| 250 |
input = (const float*) ((uintptr_t) input + (uintptr_t) diff); |
| 251 |
const HVX_Vector vw = xnn_set1_f32(*w); w += 1; |
| 252 |
vacc0 = xnn_fmadd_f32(vi0, vw, vacc0); |
| 253 |
} while (--nnz != 0); |
| 254 |
} |
| 255 |
HVX_Vector vout0 = xnn_min_f32(vacc0, vmax); |
| 256 |
vout0 = xnn_max_f32(vout0, vmin); |
| 257 |
|
| 258 |
xnn_store_tail_f32(output, vout0, 2); |
| 259 |
output = (float*) ((uintptr_t) output + output_stride); |
| 260 |
} while (--n != 0); |
| 261 |
output = (float*) ((uintptr_t) output - output_decrement); |
| 262 |
input += 2; |
| 263 |
} |
| 264 |
if (mc & (1 * sizeof(float))) { |
| 265 |
const float* w = weights; |
| 266 |
const int32_t* dmap = widx_dmap; |
| 267 |
const uint32_t* nnzmap = nidx_nnzmap; |
| 268 |
size_t n = nc; |
| 269 |
do { |
| 270 |
uint32_t nnz = *nnzmap++; |
| 271 |
HVX_Vector vacc0 = xnn_set1_f32(*w); w += 1; |
| 272 |
if XNN_LIKELY(nnz != 0) { |
| 273 |
do { |
| 274 |
const intptr_t diff = *dmap++; |
| 275 |
const HVX_Vector vi0 = xnn_loadu_f32(input); |
| 276 |
input = (const float*) ((uintptr_t) input + (uintptr_t) diff); |
| 277 |
const HVX_Vector vw = xnn_set1_f32(*w); w += 1; |
| 278 |
vacc0 = xnn_fmadd_f32(vi0, vw, vacc0); |
| 279 |
} while (--nnz != 0); |
| 280 |
} |
| 281 |
HVX_Vector vout0 = xnn_min_f32(vacc0, vmax); |
| 282 |
vout0 = xnn_max_f32(vout0, vmin); |
| 283 |
|
| 284 |
xnn_store_tail_f32(output, vout0, 1); |
| 285 |
output = (float*) ((uintptr_t) output + output_stride); |
| 286 |
} while (--n != 0); |
| 287 |
} |
| 288 |
} |
| 289 |
} |