PandA-2024.02
local_support.c
Go to the documentation of this file.
1 #include "gemm.h"
2 #include <string.h>
3 
4 int INPUT_SIZE = sizeof(struct bench_args_t);
5 
6 #define EPSILON ((TYPE)1.0e-6)
7 
8 void run_benchmark( void *vargs ) {
9  struct bench_args_t *args = (struct bench_args_t *)vargs;
10  gemm( args->m1, args->m2, args->prod );
11 }
12 
13 /* Input format:
14 %% Section 1
15 TYPE[N]: matrix 1
16 %% Section 2
17 TYPE[N]: matrix 2
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->m1, N);
30 
31  s = find_section_start(p,2);
32  STAC(parse_,TYPE,_array)(s, data->m2, N);
33  free(p);
34 
35 }
36 
37 void data_to_input(int fd, void *vdata) {
38  struct bench_args_t *data = (struct bench_args_t *)vdata;
39 
41  STAC(write_,TYPE,_array)(fd, data->m1, N);
42 
44  STAC(write_,TYPE,_array)(fd, data->m2, N);
45 }
46 
47 /* Output format:
48 %% Section 1
49 TYPE[N]: output matrix
50 */
51 
52 void output_to_data(int fd, void *vdata) {
53  struct bench_args_t *data = (struct bench_args_t *)vdata;
54  char *p, *s;
55  // Load input string
56  p = readfile(fd);
57 
58  s = find_section_start(p,1);
59  STAC(parse_,TYPE,_array)(s, data->prod, N);
60  free(p);
61 }
62 
63 void data_to_output(int fd, void *vdata) {
64  struct bench_args_t *data = (struct bench_args_t *)vdata;
65 
67  STAC(write_,TYPE,_array)(fd, data->prod, N);
68 }
69 
70 int check_data( void *vdata, void *vref ) {
71  struct bench_args_t *data = (struct bench_args_t *)vdata;
72  struct bench_args_t *ref = (struct bench_args_t *)vref;
73  int has_errors = 0;
74  int r,c;
75  TYPE diff;
76 
77  for( r=0; r<row_size; r++ ) {
78  for( c=0; c<col_size; c++ ) {
79  diff = data->prod[r*row_size + c] - ref->prod[r*row_size+c];
80  has_errors |= (diff<-EPSILON) || (EPSILON<diff);
81  }
82  }
83 
84  // Return true if it's correct.
85  return !has_errors;
86 }
void data_to_input(int fd, void *vdata)
Definition: local_support.c:34
TYPE prod[N]
Definition: gemm.h:36
#define col_size
Definition: gemm.h:17
TYPE m1[N]
Definition: gemm.h:34
#define EPSILON
Definition: local_support.c:6
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
#define row_size
Definition: gemm.h:16
void gemm(TYPE m1[N], TYPE m2[N], TYPE prod[N])
Definition: gemm.c:3
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
TYPE m2[N]
Definition: gemm.h:35
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
double c[TESTS_COUNT]
Definition: add.h:16
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