Vector Optimized Library of Kernels  3.0.0
Architecture-tuned implementations of math kernels
qa_utils.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2011 - 2020, 2022 Free Software Foundation, Inc.
4  *
5  * This file is part of VOLK
6  *
7  * SPDX-License-Identifier: LGPL-3.0-or-later
8  */
9 
10 #ifndef VOLK_QA_UTILS_H
11 #define VOLK_QA_UTILS_H
12 
13 #include <stdbool.h> // for bool, false
14 #include <volk/volk.h> // for volk_func_desc_t
15 #include <cstdlib> // for NULL
16 #include <map> // for map
17 #include <string> // for string, basic_string
18 #include <vector> // for vector
19 
20 #include "volk/volk_complex.h" // for lv_32fc_t
21 
22 /************************************************
23  * VOLK QA type definitions *
24  ************************************************/
25 struct volk_type_t {
26  bool is_float;
27  bool is_scalar;
28  bool is_signed;
29  bool is_complex;
30  int size;
31  std::string str;
32 };
33 
35 {
36 public:
37  std::string name;
38  double time;
39  std::string units;
40  bool pass;
41 };
42 
44 {
45 public:
46  std::string name;
47  std::string config_name;
48  unsigned int vlen;
49  unsigned int iter;
50  std::map<std::string, volk_test_time_t> results;
51  std::string best_arch_a;
52  std::string best_arch_u;
53 };
54 
56 {
57 private:
58  float _tol;
59  lv_32fc_t _scalar;
60  unsigned int _vlen;
61  unsigned int _iter;
62  bool _benchmark_mode;
63  bool _absolute_mode;
64  std::string _kernel_regex;
65 
66 public:
67  // ctor
70  unsigned int vlen,
71  unsigned int iter,
72  bool benchmark_mode,
73  std::string kernel_regex)
74  : _tol(tol),
75  _scalar(scalar),
76  _vlen(vlen),
77  _iter(iter),
78  _benchmark_mode(benchmark_mode),
79  _absolute_mode(false),
80  _kernel_regex(kernel_regex){};
81  // setters
82  void set_tol(float tol) { _tol = tol; };
83  void set_scalar(lv_32fc_t scalar) { _scalar = scalar; };
84  void set_vlen(unsigned int vlen) { _vlen = vlen; };
85  void set_iter(unsigned int iter) { _iter = iter; };
86  void set_benchmark(bool benchmark) { _benchmark_mode = benchmark; };
87  void set_regex(std::string regex) { _kernel_regex = regex; };
88  // getters
89  float tol() { return _tol; };
90  lv_32fc_t scalar() { return _scalar; };
91  unsigned int vlen() { return _vlen; };
92  unsigned int iter() { return _iter; };
93  bool benchmark_mode() { return _benchmark_mode; };
94  bool absolute_mode() { return _absolute_mode; };
95  std::string kernel_regex() { return _kernel_regex; };
97  {
98  volk_test_params_t t(*this);
99  t._tol = tol;
100  t._absolute_mode = true;
101  return t;
102  }
104  {
105  volk_test_params_t t(*this);
106  t._tol = tol;
107  return t;
108  }
109 };
110 
112 {
113 private:
114  volk_func_desc_t _desc;
115  void (*_kernel_ptr)();
116  std::string _name;
117  volk_test_params_t _test_parameters;
118  std::string _puppet_master_name;
119 
120 public:
121  volk_func_desc_t desc() { return _desc; };
122  void (*kernel_ptr())() { return _kernel_ptr; };
123  std::string name() { return _name; };
124  std::string puppet_master_name() { return _puppet_master_name; };
125  volk_test_params_t test_parameters() { return _test_parameters; };
126  // normal ctor
128  void (*t_kernel_ptr)(),
129  std::string name,
131  : _desc(desc),
132  _kernel_ptr(t_kernel_ptr),
133  _name(name),
134  _test_parameters(test_parameters),
135  _puppet_master_name("NULL"){};
136  // ctor for puppets
138  void (*t_kernel_ptr)(),
139  std::string name,
140  std::string puppet_master_name,
142  : _desc(desc),
143  _kernel_ptr(t_kernel_ptr),
144  _name(name),
145  _test_parameters(test_parameters),
146  _puppet_master_name(puppet_master_name){};
147 };
148 
149 /************************************************
150  * VOLK QA functions *
151  ************************************************/
153 
154 float uniform(void);
155 void random_floats(float* buf, unsigned n);
156 
158  void (*)(),
159  std::string,
161  std::vector<volk_test_results_t>* results = NULL,
162  std::string puppet_master_name = "NULL");
163 
165  void (*)(),
166  std::string,
167  float,
168  lv_32fc_t,
169  unsigned int,
170  unsigned int,
171  std::vector<volk_test_results_t>* results = NULL,
172  std::string puppet_master_name = "NULL",
173  bool absolute_mode = false,
174  bool benchmark_mode = false);
175 
176 #define VOLK_PROFILE(func, test_params, results) \
177  run_volk_tests(func##_get_func_desc(), \
178  (void (*)())func##_manual, \
179  std::string(#func), \
180  test_params, \
181  results, \
182  "NULL")
183 #define VOLK_PUPPET_PROFILE(func, puppet_master_func, test_params, results) \
184  run_volk_tests(func##_get_func_desc(), \
185  (void (*)())func##_manual, \
186  std::string(#func), \
187  test_params, \
188  results, \
189  std::string(#puppet_master_func))
190 typedef void (*volk_fn_1arg)(void*,
191  unsigned int,
192  const char*); // one input, operate in place
193 typedef void (*volk_fn_2arg)(void*, void*, unsigned int, const char*);
194 typedef void (*volk_fn_3arg)(void*, void*, void*, unsigned int, const char*);
195 typedef void (*volk_fn_4arg)(void*, void*, void*, void*, unsigned int, const char*);
197  void*, float, unsigned int, const char*); // one input vector, one scalar float input
198 typedef void (*volk_fn_2arg_s32f)(void*, void*, float, unsigned int, const char*);
199 typedef void (*volk_fn_3arg_s32f)(void*, void*, void*, float, unsigned int, const char*);
201  void*,
202  lv_32fc_t,
203  unsigned int,
204  const char*); // one input vector, one scalar float input
205 typedef void (*volk_fn_2arg_s32fc)(void*, void*, lv_32fc_t, unsigned int, const char*);
207  void*, void*, void*, lv_32fc_t, unsigned int, const char*);
208 
209 #endif // VOLK_QA_UTILS_H
Definition: qa_utils.h:112
volk_func_desc_t desc()
Definition: qa_utils.h:121
std::string puppet_master_name()
Definition: qa_utils.h:124
void(*)() kernel_ptr()
Definition: qa_utils.h:122
volk_test_params_t test_parameters()
Definition: qa_utils.h:125
volk_test_case_t(volk_func_desc_t desc, void(*t_kernel_ptr)(), std::string name, std::string puppet_master_name, volk_test_params_t test_parameters)
Definition: qa_utils.h:137
std::string name()
Definition: qa_utils.h:123
volk_test_case_t(volk_func_desc_t desc, void(*t_kernel_ptr)(), std::string name, volk_test_params_t test_parameters)
Definition: qa_utils.h:127
Definition: qa_utils.h:56
lv_32fc_t scalar()
Definition: qa_utils.h:90
unsigned int iter()
Definition: qa_utils.h:92
volk_test_params_t make_absolute(float tol)
Definition: qa_utils.h:96
volk_test_params_t make_tol(float tol)
Definition: qa_utils.h:103
unsigned int vlen()
Definition: qa_utils.h:91
void set_tol(float tol)
Definition: qa_utils.h:82
bool absolute_mode()
Definition: qa_utils.h:94
void set_iter(unsigned int iter)
Definition: qa_utils.h:85
void set_benchmark(bool benchmark)
Definition: qa_utils.h:86
void set_scalar(lv_32fc_t scalar)
Definition: qa_utils.h:83
void set_vlen(unsigned int vlen)
Definition: qa_utils.h:84
std::string kernel_regex()
Definition: qa_utils.h:95
volk_test_params_t(float tol, lv_32fc_t scalar, unsigned int vlen, unsigned int iter, bool benchmark_mode, std::string kernel_regex)
Definition: qa_utils.h:68
void set_regex(std::string regex)
Definition: qa_utils.h:87
float tol()
Definition: qa_utils.h:89
bool benchmark_mode()
Definition: qa_utils.h:93
Definition: qa_utils.h:44
std::string name
Definition: qa_utils.h:46
std::string config_name
Definition: qa_utils.h:47
unsigned int iter
Definition: qa_utils.h:49
std::map< std::string, volk_test_time_t > results
Definition: qa_utils.h:50
std::string best_arch_a
Definition: qa_utils.h:51
std::string best_arch_u
Definition: qa_utils.h:52
unsigned int vlen
Definition: qa_utils.h:48
Definition: qa_utils.h:35
double time
Definition: qa_utils.h:38
std::string name
Definition: qa_utils.h:37
std::string units
Definition: qa_utils.h:39
bool pass
Definition: qa_utils.h:40
volk_type_t volk_type_from_string(std::string)
Definition: qa_utils.cc:123
void(* volk_fn_1arg)(void *, unsigned int, const char *)
Definition: qa_utils.h:190
void(* volk_fn_3arg)(void *, void *, void *, unsigned int, const char *)
Definition: qa_utils.h:194
void(* volk_fn_3arg_s32fc)(void *, void *, void *, lv_32fc_t, unsigned int, const char *)
Definition: qa_utils.h:206
void(* volk_fn_2arg_s32f)(void *, void *, float, unsigned int, const char *)
Definition: qa_utils.h:198
float uniform(void)
void(* volk_fn_4arg)(void *, void *, void *, void *, unsigned int, const char *)
Definition: qa_utils.h:195
void(* volk_fn_2arg)(void *, void *, unsigned int, const char *)
Definition: qa_utils.h:193
void(* volk_fn_1arg_s32f)(void *, float, unsigned int, const char *)
Definition: qa_utils.h:196
void(* volk_fn_1arg_s32fc)(void *, lv_32fc_t, unsigned int, const char *)
Definition: qa_utils.h:200
bool run_volk_tests(volk_func_desc_t, void(*)(), std::string, volk_test_params_t, std::vector< volk_test_results_t > *results=NULL, std::string puppet_master_name="NULL")
Definition: qa_utils.cc:500
void(* volk_fn_3arg_s32f)(void *, void *, void *, float, unsigned int, const char *)
Definition: qa_utils.h:199
void(* volk_fn_2arg_s32fc)(void *, void *, lv_32fc_t, unsigned int, const char *)
Definition: qa_utils.h:205
void random_floats(float *buf, unsigned n)
Definition: qa_utils.h:25
bool is_signed
Definition: qa_utils.h:28
bool is_complex
Definition: qa_utils.h:29
bool is_scalar
Definition: qa_utils.h:27
std::string str
Definition: qa_utils.h:31
bool is_float
Definition: qa_utils.h:26
int size
Definition: qa_utils.h:30
__VOLK_DECL_BEGIN struct volk_func_desc volk_func_desc_t
Get description parameters for this kernel.
Definition: volk.tmpl.h:89
VOLK_API void
Call into a specific implementation given by name.
Definition: volk.tmpl.h:101
float complex lv_32fc_t
Definition: volk_complex.h:74