PandA-2024.02
local_support.c
Go to the documentation of this file.
1 #include "spmv.h"
2 #include <string.h>
3 
4 int INPUT_SIZE = sizeof(struct bench_args_t);
5 
6 #define EPSILON 1.0e-6
7 
8 void run_benchmark( void *vargs ) {
9  struct bench_args_t *args = (struct bench_args_t *)vargs;
10  spmv( args->val, args->cols, args->rowDelimiters, args->vec, args->out );
11 }
12 
13 /* Input format:
14 %% Section 1
15 TYPE[NNZ]: the nonzeros of the matrix
16 %% Section 2
17 int32_t[NNZ]: the column index of the nonzeros
18 %% Section 3
19 int32_t[N+1]: the start of each row of nonzeros
20 %% Section 4
21 TYPE[N]: the dense vector
22 */
23 
24 void input_to_data(int fd, void *vdata) {
25  struct bench_args_t *data = (struct bench_args_t *)vdata;
26  char *p, *s;
27  // Zero-out everything.
28  memset(vdata,0,sizeof(struct bench_args_t));
29  // Load input string
30  p = readfile(fd);
31 
32  s = find_section_start(p,1);
33  STAC(parse_,TYPE,_array)(s, data->val, NNZ);
34 
35  s = find_section_start(p,2);
36  parse_int32_t_array(s, data->cols, NNZ);
37 
38  s = find_section_start(p,3);
39  parse_int32_t_array(s, data->rowDelimiters, N+1);
40 
41  s = find_section_start(p,4);
42  STAC(parse_,TYPE,_array)(s, data->vec, N);
43  free(p);
44 }
45 
46 void data_to_input(int fd, void *vdata) {
47  struct bench_args_t *data = (struct bench_args_t *)vdata;
48 
50  STAC(write_,TYPE,_array)(fd, data->val, NNZ);
51 
53  write_int32_t_array(fd, data->cols, NNZ);
54 
56  write_int32_t_array(fd, data->rowDelimiters, N+1);
57 
59  STAC(write_,TYPE,_array)(fd, data->vec, N);
60 }
61 
62 /* Output format:
63 %% Section 1
64 TYPE[N]: The output vector
65 */
66 
67 void output_to_data(int fd, void *vdata) {
68  struct bench_args_t *data = (struct bench_args_t *)vdata;
69  char *p, *s;
70  // Load input string
71  p = readfile(fd);
72 
73  s = find_section_start(p,1);
74  STAC(parse_,TYPE,_array)(s, data->out, N);
75  free(p);
76 }
77 
78 void data_to_output(int fd, void *vdata) {
79  struct bench_args_t *data = (struct bench_args_t *)vdata;
80 
82  STAC(write_,TYPE,_array)(fd, data->out, N);
83 }
84 
85 int check_data( void *vdata, void *vref ) {
86  struct bench_args_t *data = (struct bench_args_t *)vdata;
87  struct bench_args_t *ref = (struct bench_args_t *)vref;
88  int has_errors = 0;
89  int i;
90  TYPE diff;
91 
92  for(i=0; i<N; i++) {
93  diff = data->out[i] - ref->out[i];
94  has_errors |= (diff<-EPSILON) || (EPSILON<diff);
95  }
96 
97  // Return true if it's correct.
98  return !has_errors;
99 }
void spmv(TYPE val[NNZ], int32_t cols[NNZ], int32_t rowDelimiters[N+1], TYPE vec[N], TYPE out[N])
Definition: spmv.c:8
int32_t rowDelimiters[N+1]
Definition: spmv.h:24
void data_to_input(int fd, void *vdata)
Definition: local_support.c:34
int check_data(void *vdata, void *vref)
Definition: local_support.c:70
int write_int32_t_array(int fd, int32_t *arr, int n)
#define TYPE
Definition: backprop.h:21
int32_t cols[NNZ]
Definition: spmv.h:23
#define STAC(f_pfx, t, f_sfx)
Definition: support.h:51
int INPUT_SIZE
Definition: local_support.c:4
int parse_int32_t_array(char *s, int32_t *arr, int n)
#define NNZ
Definition: spmv.h:11
TYPE vec[N]
Definition: spmv.h:25
void data_to_output(int fd, void *vdata)
Definition: local_support.c:63
int write_section_header(int fd)
void output_to_data(int fd, void *vdata)
Definition: local_support.c:49
#define N
Definition: dfdiv.c:60
char * readfile(int fd)
Definition: support.c:34
void input_to_data(int fd, void *vdata)
Definition: local_support.c:18
char * find_section_start(char *s, int n)
Definition: support.c:56
#define EPSILON
Definition: local_support.c:6
TYPE val[NNZ]
Definition: spmv.h:22
void run_benchmark(void *vargs)
Definition: local_support.c:6
TYPE out[N]
Definition: spmv.h:26

Generated on Mon Feb 12 2024 13:02:49 for PandA-2024.02 by doxygen 1.8.13