48eae6ad363a077339d7113525472600b397ddcd
[riscv-tests.git] / benchmarks / mt-vvadd / mt-vvadd.c
1 //**************************************************************************
2 // Vector-vector add benchmark
3 //--------------------------------------------------------------------------
4 // Author : Andrew Waterman
5 // TA : Christopher Celio
6 // Student :
7 //
8 // This benchmark adds two vectors and writes the results to a
9 // third vector. The input data (and reference data) should be
10 // generated using the vvadd_gendata.pl perl script and dumped
11 // to a file named dataset.h
12
13 // to print out arrays, etc.
14 //#define DEBUG
15
16 //--------------------------------------------------------------------------
17 // Includes
18
19 #include <string.h>
20 #include <stdlib.h>
21 #include <stdio.h>
22
23
24 //--------------------------------------------------------------------------
25 // Input/Reference Data
26
27 #include "dataset.h"
28
29
30 //--------------------------------------------------------------------------
31 // Basic Utilities and Multi-thread Support
32
33 #include "util.h"
34
35
36 //--------------------------------------------------------------------------
37 // vvadd function
38
39 extern void __attribute__((noinline)) vvadd(int coreid, int ncores, size_t n, const data_t* x, const data_t* y, data_t* z);
40
41
42 //--------------------------------------------------------------------------
43 // Main
44 //
45 // all threads start executing thread_entry(). Use their "coreid" to
46 // differentiate between threads (each thread is running on a separate core).
47
48 void thread_entry(int cid, int nc)
49 {
50 // static allocates data in the binary, which is visible to both threads
51 static data_t results_data[DATA_SIZE];
52
53 // First do out-of-place vvadd
54 barrier(nc);
55 stats(vvadd(cid, nc, DATA_SIZE, input1_data, input2_data, results_data); barrier(nc), DATA_SIZE);
56
57 if(cid == 0) {
58 //#ifdef DEBUG
59 printDoubleArray("out-of-place results: ", DATA_SIZE, results_data);
60 printDoubleArray("out-of-place verify : ", DATA_SIZE, verify_data);
61 //#endif
62 int res = verifyDouble(DATA_SIZE, results_data, verify_data);
63 if(res) exit(res);
64 }
65
66 // Second do in-place vvadd
67 // Copying input
68 size_t i;
69 if(cid == 0) {
70 for (i = 0; i < DATA_SIZE; i++)
71 results_data[i] = input1_data[i];
72 }
73 barrier(nc);
74 stats(vvadd(cid, nc, DATA_SIZE, results_data, input2_data, results_data); barrier(nc), DATA_SIZE);
75
76 if(cid == 0) {
77 #ifdef DEBUG
78 printDoubleArray("in-place results: ", DATA_SIZE, results_data);
79 printDoubleArray("in-place verify : ", DATA_SIZE, verify_data);
80 #endif
81 int res = verifyDouble(DATA_SIZE, results_data, verify_data);
82 if(res) exit(res);
83 }
84
85 barrier(nc);
86 exit(0);
87 }