Skip to content

Commit

Permalink
[apps] Fix errors and make all scalar programs work
Browse files Browse the repository at this point in the history
  • Loading branch information
mp-17 committed Feb 1, 2024
1 parent a9e2381 commit 4642386
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 20 deletions.
4 changes: 2 additions & 2 deletions apps/benchmarks/benchmark/fconv3d.bmark
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ void warm_caches(uint64_t heat) {
#ifndef SCALAR
fconv3d_CHx7x7(o, i, f, M, N, CH, F);
#else
fconv3d_CVxFxF(o, i, f, M, N, CH, F);
fconv3d_CHx7x7(o, i, f, M, N, CH, F);
#endif
// The following artificial warming ensures, with a larger cache,
// not to experience any cache misses
Expand All @@ -71,7 +71,7 @@ int main() {
#ifndef SCALAR
fconv3d_CHx7x7(o, i, f, M, N, CH, F);
#else
fconv3d_CVxFxF(o, i, f, M, N, CH, F);
fconv3d_CHx7x7(o, i, f, M, N, CH, F);
#endif
else {
printf("Error: the filter size is different from 7.\n");
Expand Down
7 changes: 4 additions & 3 deletions apps/benchmarks/benchmark/pathfinder.bmark
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
extern int32_t num_runs;
extern int32_t rows;
extern int32_t cols;
extern int src[] __attribute__((aligned(4 * NR_LANES), section(".l2")));
extern int wall[] __attribute__((aligned(4 * NR_LANES), section(".l2")));
extern int result_v[] __attribute__((aligned(4 * NR_LANES), section(".l2")));

Expand All @@ -35,7 +36,7 @@ void warm_caches(uint64_t heat) {
#ifndef SCALAR
run_vector(wall, result_v, cols, rows, num_runs);
#else
run(wall, result_v, cols, rows, num_runs);
run(wall, result_v, src, cols, rows, num_runs);
#endif
}

Expand Down Expand Up @@ -65,15 +66,15 @@ int main() {
#ifndef SCALAR
run_vector(wall, result_v, cols, rows, num_runs);
#else
run(wall, result_v, cols, rows, num_runs);
run(wall, result_v, src, cols, rows, num_runs);
#endif
stop_timer();
} else {
start_timer();
#ifndef SCALAR
run_vector_short_m4(wall, result_v, cols, rows, num_runs, neutral_value);
#else
run(wall, result_v, cols, rows, num_runs, neutral_value);
run(wall, result_v, src, cols, rows, num_runs);
#endif
stop_timer();
}
Expand Down
2 changes: 1 addition & 1 deletion apps/benchmarks/benchmark/roi_align.bmark
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ int main() {
#ifndef SCALAR
roi_align_fake_kernel_asm(image_data, crops_data_vec, 0, 0, 0, 0, DEPTH);
#else
roi_align_fake_kernel_asm(image_data, crops_data_vec, 0, 0, 0, 0, DEPTH);
#endif
roi_align_fake_kernel_scalar(image_data, crops_data_vec, 0, 0, 0, 0, DEPTH);
stop_timer();

runtime = get_timer();
Expand Down
4 changes: 2 additions & 2 deletions apps/benchmarks/benchmark/softmax.bmark
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ void warm_caches(uint64_t heat) {
#ifndef SCALAR
softmax_vec(i, o_v, channels, innerSize);
#else
softmax(i, o_v, channels, innerSize);
softmax(i, o_v, buf, channels, innerSize);
#endif
}

Expand All @@ -62,7 +62,7 @@ int main() {
#ifndef SCALAR
softmax_vec(i, o_v, channels, innerSize);
#else
softmax(i, o_v, channels, innerSize);
softmax(i, o_v, buf, channels, innerSize);
#endif
stop_timer();

Expand Down
1 change: 1 addition & 0 deletions apps/exp/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ int main() {
runtime = get_timer();
printf("The execution took %d cycles.\n", runtime);
#else
printf("SCALAR CODE! \n");
start_timer();
exp_1xf64_scalar_bmark(exponents_f64, results_f64, N_f64);
stop_timer();
Expand Down
2 changes: 1 addition & 1 deletion apps/fconv3d/fconv3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include <stdint.h>
#include <stdio.h>

double* conv3d_CHxFxF_scalar(double *o, double *i, double *f, int64_t M, int64_t N,
double* fconv3d_CHxFxF_scalar(double *o, double *i, double *f, int64_t M, int64_t N,
int64_t C, int64_t F);

void fconv3d_CHx7x7(double *o, double *i, double *f, int64_t M, int64_t N,
Expand Down
14 changes: 6 additions & 8 deletions apps/fconv3d/fconv3d_3x7x7.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,19 @@
extern int64_t event_trigger;

// a - 2D matrix (as a 1D array), w - kernel
double* conv3d_CHxFxF_scalar(double *o, double *i, double *f, int64_t M, int64_t N,
double* fconv3d_CHxFxF_scalar(double *o, double *i, double *f, int64_t M, int64_t N,
int64_t C, int64_t F) {
double acc;
int i;
int r;
int j;
int k1, k2;
int l1, l2;
int t1, t2;
int ch;

for(i = 0; i < (M + 2*F - 1); i++)
for(r = 0; r < (M + 2*F - 1); r++)
{
t1 = i * N; // loop invariants
t1 = r * N; // loop invariants
for(j = 0; j < (N + 2*F - 1); j++)
{
acc = 0.0;
Expand All @@ -76,15 +76,13 @@ double* conv3d_CHxFxF_scalar(double *o, double *i, double *f, int64_t M, int64_t
t2 = k1 * F; // loop invariants
for(l1 = F - 1, l2 = 0; l1 >= 0; l1--, l2++)
{
acc += w[t2 + l1 + F * F * ch] * a[(i + k2) * N + (j + l2) + (M + 2*F - 1) * (N + 2*F - 1) * ch];
acc += f[t2 + l1 + F * F * ch] * i[(r + k2) * (N + 2*F - 1) + (j + l2) + (M + 2*F - 1) * (N + 2*F - 1) * ch];
}
}
}
result[t1 + j] = acc;
o[t1 + j] = acc;
}
}

return result;
}

void fconv3d_CHx7x7(double *o, double *i, double *f, int64_t M, int64_t N,
Expand Down
2 changes: 1 addition & 1 deletion apps/fconv3d/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ int main() {
#ifndef SCALAR
fconv3d_CHx7x7(o, i, f, M, N, CH, F);
#else
fconv3d_CHxFxF_scalar(golden_o, i, f, M, N, CH, F);
fconv3d_CHx7x7(o, i, f, M, N, CH, F);
#endif
else
printf("Error: the filter size is different from 7.\n");
Expand Down
4 changes: 2 additions & 2 deletions apps/fmatmul/kernel/fmatmul.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ void fmatmul_scalar(double *c, const double *a, const double *b,
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;
c[i * P + j] = 0;
for (unsigned int k = 0; k < N; k++) {
c[i][j] += a[i][k] * b[k][j];
c[i * P + j] += a[i * N + k] * b[k * P + j];
}
}
}
Expand Down
13 changes: 13 additions & 0 deletions apps/fmatmul/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,19 @@ int main() {
printf("The performance is %f FLOP/cycle (%f%% utilization).\n",
performance, utilization);

#ifdef SCALAR
printf("Scalar code!\n");
// Verify scalar code
// Clear golden matrix
for (int r = 0; r < s; ++r) {
for (int c = 0; c < s; ++c) {
g[r * s + c] = 0;
}
}
// Run scalar on the ex-golden matrix
fmatmul_scalar(g, a, b, s, s, s);
#endif

// Verify the result only for s == M (to keep it simple)
if (s == M) {
printf("Verifying result...\n");
Expand Down
17 changes: 17 additions & 0 deletions apps/roi_align/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,23 @@ int main() {
stop_timer();
runtime_v = get_timer();
printf("Vector benchmark complete.\n");
printf("Scalar benchmark running...\n");
roi_align_fake_kernel_scalar(image_data, crops_data, left_x_index,
right_x_index, b, y, DEPTH);
printf("Scalar benchmark complete...\n");

// Check for errors
err = verify_result(crops_data, crops_data_vec, result_size, DELTA);

if (err != 0) {
// Fix return code to match the index of the faulty element
err = (err == -1) ? 0 : err;
printf("Failed. Index %d: %x != %x\n", err, *((uint32_t *)&crops_data[err]),
*((uint32_t *)&crops_data_vec[err]));
return err + 1;
} else {
printf("Passed.\n");
}

#endif

Expand Down

0 comments on commit 4642386

Please sign in to comment.