Skip to content

Commit

Permalink
Fix wrong scalar strided access in matrix C of matmul
Browse files Browse the repository at this point in the history
Where I accidentally used "n" I wanted to use "m". The vector access was
correct already.
  • Loading branch information
rofirrim authored and kito-cheng committed May 22, 2024
1 parent 94a2860 commit 9a02dc9
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions doc/rvv-intrinsic-examples.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,16 @@ Consider the following function that implements a naive matrix multiplication.
void matmul_reference(double *a, double *b, double *c, int n, int m, int p) {
for (int i = 0; i < n; ++i)
for (int j = 0; j < m; ++j) {
c[i * n + j] = 0;
c[i * m + j] = 0;
for (int k = 0; k < p; ++k) {
c[i * n + j] += a[i * p + k] * b[k * m + j];
c[i * m + j] += a[i * p + k] * b[k * m + j];
}
}
}
----

The following example is a version of the matrix multiplication. The
accumulation on `c[i * n + j]` is implemented using partial accumulations
accumulation on `c[i * m + j]` is implemented using partial accumulations
followed by a single final accumulation.

.An implementation of a naive matrix multiplication using RVV intrinsics.
Expand Down Expand Up @@ -121,7 +121,7 @@ void matmul_rvv(double *a, double *b, double *c, int n, int m, int p) {
vfloat64m1_t vec_sum =
__riscv_vfredusum_vs_f64m1_f64m1(vec_s, vec_zero, vlmax);
double sum = __riscv_vfmv_f_s_f64m1_f64(vec_sum);
c[i * n + j] = sum;
c[i * m + j] = sum;
}
}
----
Expand Down

0 comments on commit 9a02dc9

Please sign in to comment.