aboutsummaryrefslogtreecommitdiff
path: root/benchmarks/mt-vvadd
diff options
context:
space:
mode:
authorHenry Cook <hcook@eecs.berkeley.edu>2014-11-06 17:24:39 -0800
committerHenry Cook <hcook@eecs.berkeley.edu>2014-11-07 16:52:51 -0800
commitd537de7deffa6036dab573ff174b7f8c8e470437 (patch)
treeddc921eb337cda4889570f0251bdba85059a2531 /benchmarks/mt-vvadd
parent5afc6b9bc2e3685220cffb3da66ad9f5f1f7b14f (diff)
downloadriscv-tests-d537de7deffa6036dab573ff174b7f8c8e470437.zip
riscv-tests-d537de7deffa6036dab573ff174b7f8c8e470437.tar.gz
riscv-tests-d537de7deffa6036dab573ff174b7f8c8e470437.tar.bz2
Clean up canonical mt benchmarks and reorganize extra versions in /mt. All versions support support at least 1/2/4 threads.
Diffstat (limited to 'benchmarks/mt-vvadd')
-rw-r--r--benchmarks/mt-vvadd/bmark.mk1
-rw-r--r--benchmarks/mt-vvadd/dataset.h6
-rw-r--r--benchmarks/mt-vvadd/mt-vvadd.c95
-rw-r--r--benchmarks/mt-vvadd/vvadd.c16
4 files changed, 48 insertions, 70 deletions
diff --git a/benchmarks/mt-vvadd/bmark.mk b/benchmarks/mt-vvadd/bmark.mk
index 72b2d34..ff969c1 100644
--- a/benchmarks/mt-vvadd/bmark.mk
+++ b/benchmarks/mt-vvadd/bmark.mk
@@ -10,6 +10,7 @@
mt_vvadd_c_src = \
mt-vvadd.c \
+ vvadd.c \
syscalls.c \
mt_vvadd_riscv_src = \
diff --git a/benchmarks/mt-vvadd/dataset.h b/benchmarks/mt-vvadd/dataset.h
index ce9f936..51f25df 100644
--- a/benchmarks/mt-vvadd/dataset.h
+++ b/benchmarks/mt-vvadd/dataset.h
@@ -1,6 +1,10 @@
+#ifndef __DATASET_H
+#define __DATASET_H
#define DATA_SIZE 1000
+typedef double data_t;
+
static data_t input1_data[DATA_SIZE] =
{
0.00, 15.00, 10.00, 3.00, 14.00, 6.00, 2.00, 18.00, 11.00, 15.00, 11.00, 0.00, 17.00, 16.00, 7.00, 13.00, 18.00, 2.00, 2.00, 5.00,
@@ -163,3 +167,5 @@ static data_t verify_data[DATA_SIZE] =
32.00, 21.00, 26.00, 13.00, 6.00, 24.00, 22.00, 27.00, 17.00, 26.00, 19.00, 21.00, 19.00, 9.00, 21.00, 25.00, 17.00, 27.00, 15.00, 18.00
};
+
+#endif //__DATASET_H
diff --git a/benchmarks/mt-vvadd/mt-vvadd.c b/benchmarks/mt-vvadd/mt-vvadd.c
index 2116115..48eae6a 100644
--- a/benchmarks/mt-vvadd/mt-vvadd.c
+++ b/benchmarks/mt-vvadd/mt-vvadd.c
@@ -24,49 +24,20 @@
//--------------------------------------------------------------------------
// Input/Reference Data
-typedef double data_t;
#include "dataset.h"
//--------------------------------------------------------------------------
// Basic Utilities and Multi-thread Support
-__thread unsigned long coreid;
-
#include "util.h"
-#define stringify_1(s) #s
-#define stringify(s) stringify_1(s)
-#define stats(code) do { \
- unsigned long _c = -rdcycle(), _i = -rdinstret(); \
- code; \
- _c += rdcycle(), _i += rdinstret(); \
- if (coreid == 0) \
- printf("%s: %ld cycles, %ld.%ld cycles/iter, %ld.%ld CPI\n", \
- stringify(code), _c, _c/DATA_SIZE, 10*_c/DATA_SIZE%10, _c/_i, 10*_c/_i%10); \
- } while(0)
//--------------------------------------------------------------------------
// vvadd function
-//perform in-place vvadd
-void __attribute__((noinline)) vvadd(int ncores, size_t n, data_t* __restrict__ x, const data_t* __restrict__ y)
-{
- size_t i;
-
- // interleave accesses
- for (i = coreid; i < n; i+=ncores)
- {
- x[i] = x[i] + y[i];
- }
-}
+extern void __attribute__((noinline)) vvadd(int coreid, int ncores, size_t n, const data_t* x, const data_t* y, data_t* z);
-void __attribute__((noinline)) vvadd_opt(size_t n, data_t* __restrict__ x, const data_t* __restrict__ y)
-{
- // ***************************** //
- // **** ADD YOUR CODE HERE ***** //
- // ***************************** //
-}
//--------------------------------------------------------------------------
// Main
@@ -76,57 +47,41 @@ void __attribute__((noinline)) vvadd_opt(size_t n, data_t* __restrict__ x, const
void thread_entry(int cid, int nc)
{
- coreid = cid;
-
// static allocates data in the binary, which is visible to both threads
static data_t results_data[DATA_SIZE];
- // because we're going to perform an in-place vvadd (and we're going to run
- // it a couple of times) let's copy the input data to a temporary results
- // array
-
- size_t i;
- if (coreid == 0)
- {
- for (i = 0; i < DATA_SIZE; i++)
- results_data[i] = input1_data[i];
- }
-
-
- // Execute the provided, terrible vvadd
+ // First do out-of-place vvadd
barrier(nc);
- stats(vvadd(nc, DATA_SIZE, results_data, input2_data); barrier(nc));
+ stats(vvadd(cid, nc, DATA_SIZE, input1_data, input2_data, results_data); barrier(nc), DATA_SIZE);
-
- // verify
- int res = verifyDouble(DATA_SIZE, results_data, verify_data);
- if (res)
- exit(res);
-
-#if 0
- // reset results from the first trial
- if (coreid == 0)
- {
- for (i=0; i < DATA_SIZE; i++)
- results_data[i] = input1_data[i];
+ if(cid == 0) {
+//#ifdef DEBUG
+ printDoubleArray("out-of-place results: ", DATA_SIZE, results_data);
+ printDoubleArray("out-of-place verify : ", DATA_SIZE, verify_data);
+//#endif
+ int res = verifyDouble(DATA_SIZE, results_data, verify_data);
+ if(res) exit(res);
}
- barrier(nc);
- // Execute your faster vvadd
+ // Second do in-place vvadd
+ // Copying input
+ size_t i;
+ if(cid == 0) {
+ for (i = 0; i < DATA_SIZE; i++)
+ results_data[i] = input1_data[i];
+ }
barrier(nc);
- stats(vvadd_opt(DATA_SIZE, results_data, input2_data); barrier(nc));
-
+ stats(vvadd(cid, nc, DATA_SIZE, results_data, input2_data, results_data); barrier(nc), DATA_SIZE);
+
+ if(cid == 0) {
#ifdef DEBUG
- printDoubleArray("results: ", DATA_SIZE, results_data);
- printDoubleArray("verify : ", DATA_SIZE, verify_data);
+ printDoubleArray("in-place results: ", DATA_SIZE, results_data);
+ printDoubleArray("in-place verify : ", DATA_SIZE, verify_data);
#endif
+ int res = verifyDouble(DATA_SIZE, results_data, verify_data);
+ if(res) exit(res);
+ }
- // verify
- res = verifyDouble(DATA_SIZE, results_data, verify_data);
- if (res)
- exit(res);
barrier(nc);
-#endif
-
exit(0);
}
diff --git a/benchmarks/mt-vvadd/vvadd.c b/benchmarks/mt-vvadd/vvadd.c
new file mode 100644
index 0000000..8f4d43f
--- /dev/null
+++ b/benchmarks/mt-vvadd/vvadd.c
@@ -0,0 +1,16 @@
+#include "stdlib.h"
+#include "dataset.h"
+
+//--------------------------------------------------------------------------
+// vvadd function
+
+void __attribute__((noinline)) vvadd(int coreid, int ncores, size_t n, const data_t* x, const data_t* y, data_t* z)
+{
+ size_t i;
+
+ // interleave accesses
+ for (i = coreid; i < n; i+=ncores)
+ {
+ z[i] = x[i] + y[i];
+ }
+}