Remove smips/host-debugging cruft
[riscv-tests.git] / benchmarks / mt-vvadd / mt-vvadd.c
index 60aa2e7c4efb5e4fb396290fd5f5793dbcfe02bb..54c960236d542f26fd9dfbbf88f9baa35379ad9c 100644 (file)
@@ -1,3 +1,5 @@
+// See LICENSE for license details.
+
 //**************************************************************************
 // Vector-vector add benchmark
 //--------------------------------------------------------------------------
 //**************************************************************************
 // Vector-vector add benchmark
 //--------------------------------------------------------------------------
@@ -10,9 +12,6 @@
 // generated using the vvadd_gendata.pl perl script and dumped
 // to a file named dataset.h 
 
 // generated using the vvadd_gendata.pl perl script and dumped
 // to a file named dataset.h 
 
-// to print out arrays, etc.
-//#define DEBUG
-
 //--------------------------------------------------------------------------
 // Includes 
 
 //--------------------------------------------------------------------------
 // Includes 
 
 //--------------------------------------------------------------------------
 // Input/Reference Data
 
 //--------------------------------------------------------------------------
 // Input/Reference Data
 
-typedef double data_t;
 #include "dataset.h"
  
   
 //--------------------------------------------------------------------------
 // Basic Utilities and Multi-thread Support
 
 #include "dataset.h"
  
   
 //--------------------------------------------------------------------------
 // Basic Utilities and Multi-thread Support
 
-__thread unsigned long coreid;
-unsigned long ncores;
-#define ncores ncores
-
 #include "util.h"
    
 #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
 
  
 //--------------------------------------------------------------------------
 // vvadd function
 
-//perform in-place vvadd
-void __attribute__((noinline)) vvadd(size_t n, data_t* __restrict__ x, const data_t* __restrict__ y)
-{
-   size_t i;
+extern void __attribute__((noinline)) vvadd(int coreid, int ncores, size_t n, const data_t* x, const data_t* y, data_t* z);
 
 
-   // interleave accesses
-   for (i = coreid; i < n; i+=ncores)
-   {
-      x[i] = x[i] + y[i];
-   }
-}
-
-void __attribute__((noinline)) vvadd_opt(size_t n, data_t* __restrict__ x, const data_t* __restrict__ y)
-{
-   // ***************************** //
-   // **** ADD YOUR CODE HERE ***** //
-   // ***************************** //
-}
 
 //--------------------------------------------------------------------------
 // Main
 
 //--------------------------------------------------------------------------
 // Main
@@ -78,58 +46,33 @@ void __attribute__((noinline)) vvadd_opt(size_t n, data_t* __restrict__ x, const
   
 void thread_entry(int cid, int nc)
 {
   
 void thread_entry(int cid, int nc)
 {
-   coreid = cid;
-   ncores = nc;
-
    // static allocates data in the binary, which is visible to both threads
    static data_t results_data[DATA_SIZE];
    
    // 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];
+   // First do out-of-place vvadd
+   barrier(nc);
+   stats(vvadd(cid, nc, DATA_SIZE, input1_data, input2_data, results_data); barrier(nc), DATA_SIZE);
+   if(cid == 0) {
+     int res = verifyDouble(DATA_SIZE, results_data, verify_data);
+     if(res) exit(res);
    }
 
    }
 
-
-   // Execute the provided, terrible vvadd
-   barrier();
-   stats(vvadd(DATA_SIZE, results_data, input2_data); barrier());
+   // 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(cid, nc, DATA_SIZE, results_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) {
+     int res = verifyDouble(DATA_SIZE, results_data, verify_data);
+     if(res) exit(res);
    }
    }
-   barrier();
-
-   // Execute your faster vvadd
-   barrier();
-   stats(vvadd_opt(DATA_SIZE, results_data, input2_data); barrier());
-
-#ifdef DEBUG
-   printDoubleArray("results: ", DATA_SIZE, results_data);
-   printDoubleArray("verify : ", DATA_SIZE, verify_data);
-#endif
    
    
-   // verify
-   res = verifyDouble(DATA_SIZE, results_data, verify_data);
-   if (res)
-      exit(res);
-   barrier();
-#endif
-
+   barrier(nc);
    exit(0);
 }
    exit(0);
 }