Stop using tohost/fromhost registers
[riscv-tests.git] / benchmarks / spmv / spmv_main.c
1 // See LICENSE for license details.
2
3 //**************************************************************************
4 // Double-precision general matrix multiplication benchmark
5 //--------------------------------------------------------------------------
6
7 #include "util.h"
8
9 //--------------------------------------------------------------------------
10 // Input/Reference Data
11
12 #include "dataset1.h"
13
14 void spmv(int r, const double* val, const int* idx, const double* x,
15 const int* ptr, double* y)
16 {
17 for (int i = 0; i < r; i++)
18 {
19 int k;
20 double yi0 = 0, yi1 = 0, yi2 = 0, yi3 = 0;
21 for (k = ptr[i]; k < ptr[i+1]-3; k+=4)
22 {
23 yi0 += val[k+0]*x[idx[k+0]];
24 yi1 += val[k+1]*x[idx[k+1]];
25 yi2 += val[k+2]*x[idx[k+2]];
26 yi3 += val[k+3]*x[idx[k+3]];
27 }
28 for ( ; k < ptr[i+1]; k++)
29 {
30 yi0 += val[k]*x[idx[k]];
31 }
32 y[i] = (yi0+yi1)+(yi2+yi3);
33 }
34 }
35
36 //--------------------------------------------------------------------------
37 // Main
38
39 int main( int argc, char* argv[] )
40 {
41 double y[R];
42
43 #if PREALLOCATE
44 spmv(R, val, idx, x, ptr, y);
45 #endif
46
47 setStats(1);
48 spmv(R, val, idx, x, ptr, y);
49 setStats(0);
50
51 return verifyDouble(R, y, verify_data);
52 }