PandA-2024.02
local_support.c
Go to the documentation of this file.
1 #include "fft.h"
2 #include <string.h>
3 
4 int INPUT_SIZE = sizeof(struct bench_args_t);
5 
6 #define EPSILON ((double)1.0e-6)
7 
8 void run_benchmark( void *vargs ) {
9  struct bench_args_t *args = (struct bench_args_t *)vargs;
10  fft(args->real, args->img, args->real_twid, args->img_twid );
11 }
12 
13 /* Input format:
14 %% Section 1
15 double: signal (real part)
16 %% Section 2
17 double: signal (complex part)
18 %% Section 3
19 double: twiddle factor (real part)
20 %% Section 4
21 double: twiddle factor (complex part)
22 */
23 
24 void input_to_data(int fd, void *vdata) {
25  struct bench_args_t *data = (struct bench_args_t *)vdata;
26  char *p, *s;
27  // Load input string
28  p = readfile(fd);
29 
30  s = find_section_start(p,1);
31  parse_double_array(s, data->real, FFT_SIZE);
32 
33  s = find_section_start(p,2);
34  parse_double_array(s, data->img, FFT_SIZE);
35 
36  s = find_section_start(p,3);
38 
39  s = find_section_start(p,4);
41  free(p);
42 }
43 
44 void data_to_input(int fd, void *vdata) {
45  struct bench_args_t *data = (struct bench_args_t *)vdata;
46 
48  write_double_array(fd, data->real, FFT_SIZE);
49 
51  write_double_array(fd, data->img, FFT_SIZE);
52 
55 
57  write_double_array(fd, data->img_twid, FFT_SIZE/2);
58 }
59 
60 /* Output format:
61 %% Section 1
62 double: freq (real part)
63 %% Section 2
64 double: freq (complex part)
65 */
66 
67 void output_to_data(int fd, void *vdata) {
68  struct bench_args_t *data = (struct bench_args_t *)vdata;
69  char *p, *s;
70  // Zero-out everything.
71  memset(vdata,0,sizeof(struct bench_args_t));
72  // Load input string
73  p = readfile(fd);
74 
75  s = find_section_start(p,1);
76  parse_double_array(s, data->real, FFT_SIZE);
77 
78  s = find_section_start(p,2);
79  parse_double_array(s, data->img, FFT_SIZE);
80  free(p);
81 }
82 
83 void data_to_output(int fd, void *vdata) {
84  struct bench_args_t *data = (struct bench_args_t *)vdata;
85 
87  write_double_array(fd, data->real, FFT_SIZE);
88 
90  write_double_array(fd, data->img, FFT_SIZE);
91 }
92 
93 int check_data( void *vdata, void *vref ) {
94  struct bench_args_t *data = (struct bench_args_t *)vdata;
95  struct bench_args_t *ref = (struct bench_args_t *)vref;
96  int has_errors = 0;
97  int i;
98  double real_diff, img_diff;
99 
100  for(i=0; i<FFT_SIZE; i++) {
101  real_diff = data->real[i] - ref->real[i];
102  img_diff = data->img[i] - ref->img[i];
103  has_errors |= (real_diff<-EPSILON) || (EPSILON<real_diff);
104  //if( has_errors )
105  //printf("%d (real): %f (%f)\n", i, real_diff, EPSILON);
106  has_errors |= (img_diff<-EPSILON) || (EPSILON<img_diff);
107  //if( has_errors )
108  //printf("%d (img): %f (%f)\n", i, img_diff, EPSILON);
109  }
110 
111  // Return true if it's correct.
112  return !has_errors;
113 }
double real[FFT_SIZE]
Definition: fft.h:15
double img[FFT_SIZE]
Definition: fft.h:16
#define FFT_SIZE
Definition: fft.h:5
void data_to_input(int fd, void *vdata)
Definition: local_support.c:34
#define EPSILON
Definition: local_support.c:6
int check_data(void *vdata, void *vref)
Definition: local_support.c:70
double real_twid[FFT_SIZE/2]
Definition: fft.h:17
double img_twid[FFT_SIZE/2]
Definition: fft.h:18
int INPUT_SIZE
Definition: local_support.c:4
int write_double_array(int fd, double *arr, int n)
void data_to_output(int fd, void *vdata)
Definition: local_support.c:63
void fft(double real[FFT_SIZE], double img[FFT_SIZE], double real_twid[FFT_SIZE/2], double img_twid[FFT_SIZE/2])
Definition: fft.c:3
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
int parse_double_array(char *s, double *arr, int n)
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