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  stencil3d( args->C, args->orig, args->sol );
11 }
12 
13 /* Input format:
14 %% Section 1
15 TYPE[2]: stencil coefficients (inner/outer)
16 %% Section 2
17 TYPE[SIZE]: input matrix
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  // Load input string
24  p = readfile(fd);
25 
26  s = find_section_start(p,1);
27  STAC(parse_,TYPE,_array)(s, data->C, 2);
28 
29  s = find_section_start(p,2);
30  STAC(parse_,TYPE,_array)(s, data->orig, SIZE);
31  free(p);
32 }
33 
34 void data_to_input(int fd, void *vdata) {
35  struct bench_args_t *data = (struct bench_args_t *)vdata;
36 
38  STAC(write_,TYPE,_array)(fd, data->C, 2);
39 
41  STAC(write_,TYPE,_array)(fd, data->orig, SIZE);
42 }
43 
44 /* Output format:
45 %% Section 1
46 TYPE[SIZE]: solution matrix
47 */
48 
49 void output_to_data(int fd, void *vdata) {
50  struct bench_args_t *data = (struct bench_args_t *)vdata;
51  char *p, *s;
52  // Load input string
53  p = readfile(fd);
54 
55  s = find_section_start(p,1);
56  STAC(parse_,TYPE,_array)(s, data->sol, SIZE);
57  free(p);
58 }
59 
60 void data_to_output(int fd, void *vdata) {
61  struct bench_args_t *data = (struct bench_args_t *)vdata;
62 
64  STAC(write_,TYPE,_array)(fd, data->sol, SIZE);
65 }
66 
67 int check_data( void *vdata, void *vref ) {
68  struct bench_args_t *data = (struct bench_args_t *)vdata;
69  struct bench_args_t *ref = (struct bench_args_t *)vref;
70  int has_errors = 0;
71  int i;
72  TYPE diff;
73 
74  for(i=0; i<SIZE; i++) {
75  diff = data->sol[i] - ref->sol[i];
76  has_errors |= (diff<-EPSILON) || (EPSILON<diff);
77  }
78 
79  // Return true if it's correct.
80  return !has_errors;
81 }
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
#define TYPE
Definition: backprop.h:21
#define STAC(f_pfx, t, f_sfx)
Definition: support.h:51
int INPUT_SIZE
Definition: local_support.c:4
void data_to_output(int fd, void *vdata)
Definition: local_support.c:63
int write_section_header(int fd)
#define EPSILON
Definition: local_support.c:6
void output_to_data(int fd, void *vdata)
Definition: local_support.c:49
void stencil3d(TYPE C[2], TYPE orig[SIZE], TYPE sol[SIZE])
Definition: stencil.c:10
char * readfile(int fd)
Definition: support.c:34
TYPE C[2]
Definition: stencil.h:30
#define SIZE
Definition: adpcm.c:775
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
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