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  ellpack( args->nzval, args->cols, args->vec, args->out );
11 }
12 
13 /* Input format:
14 %% Section 1
15 TYPE[N*L]: the nonzeros of the matrix
16 %% Section 2
17 int32_t[N*L]: the column index of the nonzeros
18 %% Section 3
19 TYPE[N]: the dense vector
20 */
21 
22 void input_to_data(int fd, void *vdata) {
23  struct bench_args_t *data = (struct bench_args_t *)vdata;
24  char *p, *s;
25  // Zero-out everything.
26  memset(vdata,0,sizeof(struct bench_args_t));
27  // Load input string
28  p = readfile(fd);
29 
30  s = find_section_start(p,1);
31  STAC(parse_,TYPE,_array)(s, data->nzval, N*L);
32 
33  s = find_section_start(p,2);
34  parse_int32_t_array(s, data->cols, N*L);
35 
36  s = find_section_start(p,3);
37  STAC(parse_,TYPE,_array)(s, data->vec, N);
38  free(p);
39 }
40 
41 void data_to_input(int fd, void *vdata) {
42  struct bench_args_t *data = (struct bench_args_t *)vdata;
43 
45  STAC(write_,TYPE,_array)(fd, data->nzval, N*L);
46 
48  write_int32_t_array(fd, data->cols, N*L);
49 
51  STAC(write_,TYPE,_array)(fd, data->vec, N);
52 }
53 
54 /* Output format:
55 %% Section 1
56 TYPE[N]: The output vector
57 */
58 
59 void output_to_data(int fd, void *vdata) {
60  struct bench_args_t *data = (struct bench_args_t *)vdata;
61  char *p, *s;
62  // Load input string
63  p = readfile(fd);
64 
65  s = find_section_start(p,1);
66  STAC(parse_,TYPE,_array)(s, data->out, N);
67  free(p);
68 }
69 
70 void data_to_output(int fd, void *vdata) {
71  struct bench_args_t *data = (struct bench_args_t *)vdata;
72 
74  STAC(write_,TYPE,_array)(fd, data->out, N);
75 }
76 
77 int check_data( void *vdata, void *vref ) {
78  struct bench_args_t *data = (struct bench_args_t *)vdata;
79  struct bench_args_t *ref = (struct bench_args_t *)vref;
80  int has_errors = 0;
81  int i;
82  TYPE diff;
83 
84  for(i=0; i<N; i++) {
85  diff = data->out[i] - ref->out[i];
86  has_errors |= (diff<-EPSILON) || (EPSILON<diff);
87  }
88 
89  // Return true if it's correct.
90  return !has_errors;
91 }
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)
void ellpack(TYPE nzval[N *L], int32_t cols[N *L], TYPE vec[N], TYPE out[N])
Definition: spmv.c:8
#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
TYPE nzval[N *L]
Definition: spmv.h:22
#define EPSILON
Definition: local_support.c:6
int INPUT_SIZE
Definition: local_support.c:4
int parse_int32_t_array(char *s, int32_t *arr, int n)
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
#define L
Definition: spmv.h:13
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
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