Skip to content

Commit fbb01ef

Browse files
hexagon: add reduce sum in fp32
1 parent 0b24150 commit fbb01ef

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

ggml/src/ggml-hexagon/htp/hvx-utils.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,23 @@ static inline HVX_Vector hvx_vec_qf32_reduce_sum(HVX_Vector in) {
405405
return hvx_vec_qf32_reduce_sum_n(in, 32);
406406
}
407407

408+
static inline HVX_Vector hvx_vec_fp32_reduce_sum_n(HVX_Vector in, unsigned int n) {
409+
unsigned int total = n * 4; // total vec nbytes
410+
unsigned int width = 4; // fp32 nbytes
411+
412+
HVX_Vector sum = in, sum_t;
413+
while (width < total) {
414+
sum_t = Q6_V_vror_VR(sum, width); // rotate right
415+
sum = Q6_Vsf_equals_Vqf32(Q6_Vqf32_vadd_VsfVsf(sum, sum_t)); // elementwise sum
416+
width = width << 1;
417+
}
418+
return sum;
419+
}
420+
421+
static inline HVX_Vector hvx_vec_fp32_reduce_sum(HVX_Vector in) {
422+
return hvx_vec_fp32_reduce_sum_n(in, 32);
423+
}
424+
408425
static inline HVX_Vector hvx_vec_reduce_max_fp16(HVX_Vector in) {
409426
unsigned total = 128; // total vec nbytes
410427
unsigned width = 2; // fp16 nbytes

0 commit comments

Comments
 (0)