Skip to content

Commit

Permalink
[apps] Add fmatmul scalar kernel
Browse files Browse the repository at this point in the history
  • Loading branch information
mp-17 committed Jan 16, 2024
1 parent 594ce81 commit 57f3228
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
8 changes: 8 additions & 0 deletions apps/benchmarks/benchmark/fmatmul.bmark
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ void warm_caches(uint64_t heat) {
volatile double buf;

for (uint64_t k = 0; k < heat; ++k)
#ifndef SCALAR
fmatmul(c, a, b, M, N, P);
#else
fmatmul_scalar(c, a, b, M, N, P);
#endif
#ifdef AD_HOC_WARMING
// Vector stores have invalidated the A mtx cache lines!
// Fetch them again
Expand All @@ -62,7 +66,11 @@ int main() {
// Measure runtime with a hot cache
HW_CNT_READY;
start_timer();
#ifndef SCALAR
fmatmul(c, a, b, M, N, P);
#else
fmatmul_scalar(c, a, b, M, N, P);
#endif
stop_timer();

int64_t runtime = get_timer();
Expand Down
13 changes: 13 additions & 0 deletions apps/fmatmul/kernel/fmatmul.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,19 @@

#define MIN(a, b) ((a) < (b) ? (a) : (b))

void fmatmul_scalar(double *c, const double *a, const double *b,
const unsigned long int M, const unsigned long int N,
const unsigned long int P) {
for (unsigned int i = 0; i < M; i++) {
for (unsigned int j = 0; j < P; j++) {
c[i][j] = 0;
for (unsigned int k = 0; k < N; k++) {
c[i][j] += a[i][k] * b[k][j];
}
}
}
}

void fmatmul(double *c, const double *a, const double *b,
const unsigned long int M, const unsigned long int N,
const unsigned long int P) {
Expand Down
4 changes: 4 additions & 0 deletions apps/fmatmul/kernel/fmatmul.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
void fmatmul(double *c, const double *a, const double *b, unsigned long int m,
unsigned long int n, unsigned long int p);

void fmatmul_scalar(double *c, const double *a, const double *b,
const unsigned long int M, const unsigned long int N,
const unsigned long int P);

void fmatmul_4x4(double *c, const double *a, const double *b,
unsigned long int m, unsigned long int n, unsigned long int p);
void fmatmul_vec_4x4_slice_init();
Expand Down

0 comments on commit 57f3228

Please sign in to comment.