PandA-2024.02
local_support.c
Go to the documentation of this file.
1 #include "stencil.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  stencil( args->orig, args->sol, args->filter );
11 }
12 
13 /* Input format:
14 %% Section 1
15 TYPE[row_size*col_size]: input matrix
16 %% Section 2
17 TYPE[f_size]: filter coefficients
18 */
19 
20 void input_to_data(int fd, void *vdata) {
21  struct bench_args_t *data = (struct bench_args_t *)vdata;
22  char *p, *s;
23  // Zero-out everything.
24  memset(vdata,0,sizeof(struct bench_args_t));
25  // Load input string
26  p = readfile(fd);
27 
28  s = find_section_start(p,1);
29  STAC(parse_,TYPE,_array)(s, data->orig, row_size*col_size);
30 
31  s = find_section_start(p,2);
32  STAC(parse_,TYPE,_array)(s, data->filter, f_size);
33  free(p);
34 }
35 
36 void data_to_input(int fd, void *vdata) {
37  struct bench_args_t *data = (struct bench_args_t *)vdata;
38 
40  STAC(write_,TYPE,_array)(fd, data->orig, row_size*col_size);
41 
43  STAC(write_,TYPE,_array)(fd, data->filter, f_size);
44 }
45 
46 /* Output format:
47 %% Section 1
48 TYPE[row_size*col_size]: solution matrix
49 */
50 
51 void output_to_data(int fd, void *vdata) {
52  struct bench_args_t *data = (struct bench_args_t *)vdata;
53  char *p, *s;
54  // Zero-out everything.
55  memset(vdata,0,sizeof(struct bench_args_t));
56  // Load input string
57  p = readfile(fd);
58 
59  s = find_section_start(p,1);
60  STAC(parse_,TYPE,_array)(s, data->sol, row_size*col_size);
61  free(p);
62 }
63 
64 void data_to_output(int fd, void *vdata) {
65  struct bench_args_t *data = (struct bench_args_t *)vdata;
66 
68  STAC(write_,TYPE,_array)(fd, data->sol, row_size*col_size);
69 }
70 
71 int check_data( void *vdata, void *vref ) {
72  struct bench_args_t *data = (struct bench_args_t *)vdata;
73  struct bench_args_t *ref = (struct bench_args_t *)vref;
74  int has_errors = 0;
75  int row, col;
76  TYPE diff;
77 
78  for(row=0; row<row_size; row++) {
79  for(col=0; col<col_size; col++) {
80  diff = data->sol[row*col_size + col] - ref->sol[row*col_size + col];
81  has_errors |= (diff<-EPSILON) || (EPSILON<diff);
82  }
83  }
84 
85  // Return true if it's correct.
86  return !has_errors;
87 }
TYPE filter[f_size]
Definition: stencil.h:28
void data_to_input(int fd, void *vdata)
Definition: local_support.c:34
#define EPSILON
Definition: local_support.c:6
#define col_size
Definition: gemm.h:17
int check_data(void *vdata, void *vref)
Definition: local_support.c:70
#define TYPE
Definition: backprop.h:21
#define STAC(f_pfx, t, f_sfx)
Definition: support.h:51
void stencil(TYPE orig[row_size *col_size], TYPE sol[row_size *col_size], TYPE filter[f_size])
Definition: stencil.c:3
int INPUT_SIZE
Definition: local_support.c:4
#define row_size
Definition: gemm.h:16
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
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
TYPE sol[row_size *col_size]
Definition: stencil.h:27
#define f_size
Definition: stencil.h:8
TYPE orig[row_size *col_size]
Definition: stencil.h:26
void run_benchmark(void *vargs)
Definition: local_support.c:6

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