| 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_128x1__hvx( |
| 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 - 128 * sizeof(float); |
| 40 |
while XNN_LIKELY(mc >= 128 * 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 vacc0 = xnn_set1_f32(*w); w += 1; |
| 48 |
HVX_Vector vacc1 = vacc0; |
| 49 |
HVX_Vector vacc2 = vacc0; |
| 50 |
HVX_Vector vacc3 = vacc0; |
| 51 |
if XNN_LIKELY(nnz != 0) { |
| 52 |
do { |
| 53 |
const intptr_t diff = *dmap++; |
| 54 |
const HVX_Vector vi0 = xnn_loadu_f32(input); |
| 55 |
const HVX_Vector vi1 = xnn_loadu_f32(input + 32); |
| 56 |
const HVX_Vector vi2 = xnn_loadu_f32(input + 64); |
| 57 |
const HVX_Vector vi3 = xnn_loadu_f32(input + 96); |
| 58 |
input = (const float*) ((uintptr_t) input + (uintptr_t) diff); |
| 59 |
|
| 60 |
const HVX_Vector vw = xnn_set1_f32(*w); w += 1; |
| 61 |
|
| 62 |
vacc0 = xnn_fmadd_f32(vi0, vw, vacc0); |
| 63 |
vacc1 = xnn_fmadd_f32(vi1, vw, vacc1); |
| 64 |
vacc2 = xnn_fmadd_f32(vi2, vw, vacc2); |
| 65 |
vacc3 = xnn_fmadd_f32(vi3, vw, vacc3); |
| 66 |
} while (--nnz != 0); |
| 67 |
} |
| 68 |
HVX_Vector vout0 = xnn_min_f32(vacc0, vmax); |
| 69 |
HVX_Vector vout1 = xnn_min_f32(vacc1, vmax); |
| 70 |
HVX_Vector vout2 = xnn_min_f32(vacc2, vmax); |
| 71 |
HVX_Vector vout3 = xnn_min_f32(vacc3, vmax); |
| 72 |
vout0 = xnn_max_f32(vout0, vmin); |
| 73 |
vout1 = xnn_max_f32(vout1, vmin); |
| 74 |
vout2 = xnn_max_f32(vout2, vmin); |
| 75 |
vout3 = xnn_max_f32(vout3, vmin); |
| 76 |
|
| 77 |
xnn_storeu_f32(output, vout0); |
| 78 |
xnn_storeu_f32(output + 32, vout1); |
| 79 |
xnn_storeu_f32(output + 64, vout2); |
| 80 |
xnn_storeu_f32(output + 96, vout3); |
| 81 |
output = (float*) ((uintptr_t) output + output_stride); |
| 82 |
} while (--n != 0); |
| 83 |
output = (float*) ((uintptr_t) output - output_decrement); |
| 84 |
input += 128; |
| 85 |
mc -= 128 * sizeof(float); |
| 86 |
} |
| 87 |
if XNN_UNLIKELY(mc != 0) { |
| 88 |
output_decrement += 64 * sizeof(float); |
| 89 |
if (mc & (64 * sizeof(float))) { |
| 90 |
const float* w = weights; |
| 91 |
const int32_t* dmap = widx_dmap; |
| 92 |
const uint32_t* nnzmap = nidx_nnzmap; |
| 93 |
size_t n = nc; |
| 94 |
do { |
| 95 |
uint32_t nnz = *nnzmap++; |
| 96 |
HVX_Vector vacc0 = xnn_set1_f32(*w); w += 1; |
| 97 |
HVX_Vector vacc1 = vacc0; |
| 98 |
if XNN_LIKELY(nnz != 0) { |
| 99 |
do { |
| 100 |
const intptr_t diff = *dmap++; |
| 101 |
const HVX_Vector vi0 = xnn_loadu_f32(input); |
| 102 |
const HVX_Vector vi1 = xnn_loadu_f32(input + 32); |
| 103 |
input = (const float*) ((uintptr_t) input + (uintptr_t) diff); |
| 104 |
const HVX_Vector vw = xnn_set1_f32(*w); w += 1; |
| 105 |
vacc0 = xnn_fmadd_f32(vi0, vw, vacc0); |
| 106 |
vacc1 = xnn_fmadd_f32(vi1, vw, vacc1); |
| 107 |
} while (--nnz != 0); |
| 108 |
} |
| 109 |
HVX_Vector vout0 = xnn_min_f32(vacc0, vmax); |
| 110 |
HVX_Vector vout1 = xnn_min_f32(vacc1, vmax); |
| 111 |
vout0 = xnn_max_f32(vout0, vmin); |
| 112 |
vout1 = xnn_max_f32(vout1, vmin); |
| 113 |
|
| 114 |
xnn_storeu_f32(output, vout0); |
| 115 |
xnn_storeu_f32(output + 32, vout1); |
| 116 |
output = (float*) ((uintptr_t) output + output_stride); |
| 117 |
} while (--n != 0); |
| 118 |
output = (float*) ((uintptr_t) output - output_decrement); |
| 119 |
input += 64; |
| 120 |
} |
| 121 |
output_decrement += 32 * sizeof(float); |
| 122 |
if (mc & (32 * sizeof(float))) { |
| 123 |
const float* w = weights; |
| 124 |
const int32_t* dmap = widx_dmap; |
| 125 |
const uint32_t* nnzmap = nidx_nnzmap; |
| 126 |
size_t n = nc; |
| 127 |
do { |
| 128 |
uint32_t nnz = *nnzmap++; |
| 129 |
HVX_Vector vacc0 = xnn_set1_f32(*w); w += 1; |
| 130 |
if XNN_LIKELY(nnz != 0) { |
| 131 |
do { |
| 132 |
const intptr_t diff = *dmap++; |
| 133 |
const HVX_Vector vi0 = xnn_loadu_f32(input); |
| 134 |
input = (const float*) ((uintptr_t) input + (uintptr_t) diff); |
| 135 |
const HVX_Vector vw = xnn_set1_f32(*w); w += 1; |
| 136 |
vacc0 = xnn_fmadd_f32(vi0, vw, vacc0); |
| 137 |
} while (--nnz != 0); |
| 138 |
} |
| 139 |
HVX_Vector vout0 = xnn_min_f32(vacc0, vmax); |
| 140 |
vout0 = xnn_max_f32(vout0, vmin); |
| 141 |
|
| 142 |
xnn_storeu_f32(output, vout0); |
| 143 |
output = (float*) ((uintptr_t) output + output_stride); |
| 144 |
} while (--n != 0); |
| 145 |
output = (float*) ((uintptr_t) output - output_decrement); |
| 146 |
input += 32; |
| 147 |
} |
| 148 |
output_decrement += 16 * sizeof(float); |
| 149 |
if (mc & (16 * sizeof(float))) { |
| 150 |
const float* w = weights; |
| 151 |
const int32_t* dmap = widx_dmap; |
| 152 |
const uint32_t* nnzmap = nidx_nnzmap; |
| 153 |
size_t n = nc; |
| 154 |
do { |
| 155 |
uint32_t nnz = *nnzmap++; |
| 156 |
HVX_Vector vacc0 = xnn_set1_f32(*w); w += 1; |
| 157 |
if XNN_LIKELY(nnz != 0) { |
| 158 |
do { |
| 159 |
const intptr_t diff = *dmap++; |
| 160 |
const HVX_Vector vi0 = xnn_loadu_f32(input); |
| 161 |
input = (const float*) ((uintptr_t) input + (uintptr_t) diff); |
| 162 |
const HVX_Vector vw = xnn_set1_f32(*w); w += 1; |
| 163 |
vacc0 = xnn_fmadd_f32(vi0, vw, vacc0); |
| 164 |
} while (--nnz != 0); |
| 165 |
} |
| 166 |
HVX_Vector vout0 = xnn_min_f32(vacc0, vmax); |
| 167 |
vout0 = xnn_max_f32(vout0, vmin); |
| 168 |
|
| 169 |
xnn_store_tail_f32(output, vout0, 16); |
| 170 |
output = (float*) ((uintptr_t) output + output_stride); |
| 171 |
} while (--n != 0); |
| 172 |
output = (float*) ((uintptr_t) output - output_decrement); |
| 173 |
input += 16; |
| 174 |
} |
| 175 |
output_decrement += 8 * sizeof(float); |
| 176 |
if (mc & (8 * sizeof(float))) { |
| 177 |
const float* w = weights; |
| 178 |
const int32_t* dmap = widx_dmap; |
| 179 |
const uint32_t* nnzmap = nidx_nnzmap; |
| 180 |
size_t n = nc; |
| 181 |
do { |
| 182 |
uint32_t nnz = *nnzmap++; |
| 183 |
HVX_Vector vacc0 = xnn_set1_f32(*w); w += 1; |
| 184 |
if XNN_LIKELY(nnz != 0) { |
| 185 |
do { |
| 186 |
const intptr_t diff = *dmap++; |
| 187 |
const HVX_Vector vi0 = xnn_loadu_f32(input); |
| 188 |
input = (const float*) ((uintptr_t) input + (uintptr_t) diff); |
| 189 |
const HVX_Vector vw = xnn_set1_f32(*w); w += 1; |
| 190 |
vacc0 = xnn_fmadd_f32(vi0, vw, vacc0); |
| 191 |
} while (--nnz != 0); |
| 192 |
} |
| 193 |
HVX_Vector vout0 = xnn_min_f32(vacc0, vmax); |
| 194 |
vout0 = xnn_max_f32(vout0, vmin); |
| 195 |
|
| 196 |
xnn_store_tail_f32(output, vout0, 8); |
| 197 |
output = (float*) ((uintptr_t) output + output_stride); |
| 198 |
} while (--n != 0); |
| 199 |
output = (float*) ((uintptr_t) output - output_decrement); |
| 200 |
input += 8; |
| 201 |
} |
| 202 |
output_decrement += 4 * sizeof(float); |
| 203 |
if (mc & (4 * sizeof(float))) { |
| 204 |
const float* w = weights; |
| 205 |
const int32_t* dmap = widx_dmap; |
| 206 |
const uint32_t* nnzmap = nidx_nnzmap; |
| 207 |
size_t n = nc; |
| 208 |
do { |
| 209 |
uint32_t nnz = *nnzmap++; |
| 210 |
HVX_Vector vacc0 = xnn_set1_f32(*w); w += 1; |
| 211 |
if XNN_LIKELY(nnz != 0) { |
| 212 |
do { |
| 213 |
const intptr_t diff = *dmap++; |
| 214 |
const HVX_Vector vi0 = xnn_loadu_f32(input); |
| 215 |
input = (const float*) ((uintptr_t) input + (uintptr_t) diff); |
| 216 |
const HVX_Vector vw = xnn_set1_f32(*w); w += 1; |
| 217 |
vacc0 = xnn_fmadd_f32(vi0, vw, vacc0); |
| 218 |
} while (--nnz != 0); |
| 219 |
} |
| 220 |
HVX_Vector vout0 = xnn_min_f32(vacc0, vmax); |
| 221 |
vout0 = xnn_max_f32(vout0, vmin); |
| 222 |
|
| 223 |
xnn_store_tail_f32(output, vout0, 4); |
| 224 |
output = (float*) ((uintptr_t) output + output_stride); |
| 225 |
} while (--n != 0); |
| 226 |
output = (float*) ((uintptr_t) output - output_decrement); |
| 227 |
input += 4; |
| 228 |
} |
| 229 |
output_decrement += 2 * sizeof(float); |
| 230 |
if (mc & (2 * sizeof(float))) { |
| 231 |
const float* w = weights; |
| 232 |
const int32_t* dmap = widx_dmap; |
| 233 |
const uint32_t* nnzmap = nidx_nnzmap; |
| 234 |
size_t n = nc; |
| 235 |
do { |
| 236 |
uint32_t nnz = *nnzmap++; |
| 237 |
HVX_Vector vacc0 = xnn_set1_f32(*w); w += 1; |
| 238 |
if XNN_LIKELY(nnz != 0) { |
| 239 |
do { |
| 240 |
const intptr_t diff = *dmap++; |
| 241 |
const HVX_Vector vi0 = xnn_loadu_f32(input); |
| 242 |
input = (const float*) ((uintptr_t) input + (uintptr_t) diff); |
| 243 |
const HVX_Vector vw = xnn_set1_f32(*w); w += 1; |
| 244 |
vacc0 = xnn_fmadd_f32(vi0, vw, vacc0); |
| 245 |
} while (--nnz != 0); |
| 246 |
} |
| 247 |
HVX_Vector vout0 = xnn_min_f32(vacc0, vmax); |
| 248 |
vout0 = xnn_max_f32(vout0, vmin); |
| 249 |
|
| 250 |
xnn_store_tail_f32(output, vout0, 2); |
| 251 |
output = (float*) ((uintptr_t) output + output_stride); |
| 252 |
} while (--n != 0); |
| 253 |
output = (float*) ((uintptr_t) output - output_decrement); |
| 254 |
input += 2; |
| 255 |
} |
| 256 |
if (mc & (1 * sizeof(float))) { |
| 257 |
const float* w = weights; |
| 258 |
const int32_t* dmap = widx_dmap; |
| 259 |
const uint32_t* nnzmap = nidx_nnzmap; |
| 260 |
size_t n = nc; |
| 261 |
do { |
| 262 |
uint32_t nnz = *nnzmap++; |
| 263 |
HVX_Vector vacc0 = xnn_set1_f32(*w); w += 1; |
| 264 |
if XNN_LIKELY(nnz != 0) { |
| 265 |
do { |
| 266 |
const intptr_t diff = *dmap++; |
| 267 |
const HVX_Vector vi0 = xnn_loadu_f32(input); |
| 268 |
input = (const float*) ((uintptr_t) input + (uintptr_t) diff); |
| 269 |
const HVX_Vector vw = xnn_set1_f32(*w); w += 1; |
| 270 |
vacc0 = xnn_fmadd_f32(vi0, vw, vacc0); |
| 271 |
} while (--nnz != 0); |
| 272 |
} |
| 273 |
HVX_Vector vout0 = xnn_min_f32(vacc0, vmax); |
| 274 |
vout0 = xnn_max_f32(vout0, vmin); |
| 275 |
|
| 276 |
xnn_store_tail_f32(output, vout0, 1); |
| 277 |
output = (float*) ((uintptr_t) output + output_stride); |
| 278 |
} while (--n != 0); |
| 279 |
} |
| 280 |
} |
| 281 |
} |