| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
#include <assert.h> |
| 11 |
|
| 12 |
#include "xnnpack/math.h" |
| 13 |
#include "xnnpack/spmm.h" |
| 14 |
|
| 15 |
|
| 16 |
void xnn_f32_spmm_minmax_ukernel_2x1__scalar_pipelined( |
| 17 |
size_t mc, |
| 18 |
size_t nc, |
| 19 |
const float* input, |
| 20 |
const float* weights, |
| 21 |
const int32_t* widx_dmap, |
| 22 |
const uint32_t* nidx_nnzmap, |
| 23 |
float* output, |
| 24 |
size_t output_stride, |
| 25 |
const union xnn_f32_minmax_params params[restrict XNN_MIN_ELEMENTS(1)]) |
| 26 |
{ |
| 27 |
assert(mc != 0); |
| 28 |
assert(mc % sizeof(float) == 0); |
| 29 |
assert(nc != 0); |
| 30 |
|
| 31 |
const float vmin = params->scalar.min; |
| 32 |
const float vmax = params->scalar.max; |
| 33 |
size_t output_decrement = output_stride * nc - 2 * sizeof(float); |
| 34 |
while XNN_LIKELY(mc >= 2 * sizeof(float)) { |
| 35 |
const float* w = weights; |
| 36 |
const int32_t* dmap = widx_dmap; |
| 37 |
const uint32_t* nnzmap = nidx_nnzmap; |
| 38 |
float vw = *w++; |
| 39 |
intptr_t diff = *dmap++; |
| 40 |
float vi0 = input[0]; |
| 41 |
float vi1 = input[1]; |
| 42 |
size_t n = nc; |
| 43 |
do { |
| 44 |
uint32_t nnz = *nnzmap++; |
| 45 |
float vacc0 = vw; |
| 46 |
float vacc1 = vw; |
| 47 |
vw = *w++; |
| 48 |
if XNN_LIKELY(nnz != 0) { |
| 49 |
do { |
| 50 |
vacc0 += vi0 * vw; |
| 51 |
vacc1 += vi1 * vw; |
| 52 |
input = (const float*restrict) ((uintptr_t) input + (uintptr_t) diff); |
| 53 |
|
| 54 |
diff = *dmap++; |
| 55 |
vw = *w++; |
| 56 |
vi0 = input[0]; |
| 57 |
vi1 = input[1]; |
| 58 |
} while (--nnz != 0); |
| 59 |
} |
| 60 |
float vout0 = math_min_f32(vacc0, vmax); |
| 61 |
float vout1 = math_min_f32(vacc1, vmax); |
| 62 |
vout0 = math_max_f32(vout0, vmin); |
| 63 |
vout1 = math_max_f32(vout1, vmin); |
| 64 |
output[0] = vout0; |
| 65 |
output[1] = vout1; |
| 66 |
output = (float*restrict) ((uintptr_t) output + output_stride); |
| 67 |
} while (--n != 0); |
| 68 |
output = (float*restrict) ((uintptr_t) output - output_decrement); |
| 69 |
input += 2; |
| 70 |
mc -= 2 * sizeof(float); |
| 71 |
} |
| 72 |
if XNN_UNLIKELY(mc != 0) { |
| 73 |
output_decrement += 1 * sizeof(float); |
| 74 |
if (mc & (1 * sizeof(float))) { |
| 75 |
const float* w = weights; |
| 76 |
const int32_t* dmap = widx_dmap; |
| 77 |
const uint32_t* nnzmap = nidx_nnzmap; |
| 78 |
float vw = *w++; |
| 79 |
intptr_t diff = *dmap++; |
| 80 |
float vi0 = input[0]; |
| 81 |
size_t n = nc; |
| 82 |
do { |
| 83 |
uint32_t nnz = *nnzmap++; |
| 84 |
float vacc0 = vw; |
| 85 |
vw = *w++; |
| 86 |
if XNN_LIKELY(nnz != 0) { |
| 87 |
do { |
| 88 |
vacc0 += vi0 * vw; |
| 89 |
input = (const float*restrict) ((uintptr_t) input + (uintptr_t) diff); |
| 90 |
|
| 91 |
diff = *dmap++; |
| 92 |
vw = *w++; |
| 93 |
vi0 = input[0]; |
| 94 |
} while (--nnz != 0); |
| 95 |
} |
| 96 |
float vout0 = math_min_f32(vacc0, vmax); |
| 97 |
vout0 = math_max_f32(vout0, vmin); |
| 98 |
output[0] = vout0; |
| 99 |
output = (float*restrict) ((uintptr_t) output + output_stride); |
| 100 |
} while (--n != 0); |
| 101 |
output = (float*restrict) ((uintptr_t) output - output_decrement); |
| 102 |
input += 1; |
| 103 |
} |
| 104 |
} |
| 105 |
} |