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  bbgemm( 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 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->m1, N);
41 
43  STAC(write_,TYPE,_array)(fd, data->m2, N);
44 }
45 
46 /* Output format:
47 %% Section 1
48 TYPE[N]: output 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  // Load input string
55  p = readfile(fd);
56 
57  s = find_section_start(p,1);
58  STAC(parse_,TYPE,_array)(s, data->prod, N);
59  free(p);
60 }
61 
62 void data_to_output(int fd, void *vdata) {
63  struct bench_args_t *data = (struct bench_args_t *)vdata;
64 
66  STAC(write_,TYPE,_array)(fd, data->prod, N);
67 }
68 
69 int check_data( void *vdata, void *vref ) {
70  struct bench_args_t *data = (struct bench_args_t *)vdata;
71  struct bench_args_t *ref = (struct bench_args_t *)vref;
72  int has_errors = 0;
73  int r,c;
74  TYPE diff;
75 
76  for( r=0; r<row_size; r++ ) {
77  for( c=0; c<col_size; c++ ) {
78  diff = data->prod[r*row_size + c] - ref->prod[r*row_size+c];
79  has_errors |= (diff<-EPSILON) || (EPSILON<diff);
80  }
81  }
82 
83  // Return true if it's correct.
84  return !has_errors;
85 }
void bbgemm(TYPE m1[N], TYPE m2[N], TYPE prod[N])
Definition: gemm.c:10
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
int check_data(void *vdata, void *vref)
Definition: local_support.c:70
#define EPSILON
Definition: local_support.c:6
#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 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