ggml : fix bug in ggml_compute_forward_sum_f32 (#1162)

The sum over all rows is now computed instead of just the last row
This commit is contained in:
xaedes 2023-04-24 23:02:02 +02:00 committed by GitHub
parent 8a0f8673ba
commit 54bb60e268
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

7
ggml.c
View File

@ -6779,15 +6779,20 @@ static void ggml_compute_forward_sum_f32(
const size_t nb02 = src0->nb[2]; const size_t nb02 = src0->nb[2];
const size_t nb03 = src0->nb[3]; const size_t nb03 = src0->nb[3];
ggml_float sum = 0;
float row_sum = 0;
for (int64_t i03 = 0; i03 < ne03; i03++) { for (int64_t i03 = 0; i03 < ne03; i03++) {
for (int64_t i02 = 0; i02 < ne02; i02++) { for (int64_t i02 = 0; i02 < ne02; i02++) {
for (int64_t i01 = 0; i01 < ne01; i01++) { for (int64_t i01 = 0; i01 < ne01; i01++) {
ggml_vec_sum_f32(ne00, ggml_vec_sum_f32(ne00,
(float *) (dst->data), &row_sum,
(float *) ((char *) src0->data + i01*nb01 + i02*nb02 + i03*nb03)); (float *) ((char *) src0->data + i01*nb01 + i02*nb02 + i03*nb03));
sum += row_sum;
} }
} }
} }
((float *) dst->data)[0] = sum;
} }
static void ggml_compute_forward_sum( static void ggml_compute_forward_sum(