SOPT
Sparse OPTimisation
wavelets.cc
Go to the documentation of this file.
1 #include <sstream>
2 #include <benchmark/benchmark.h>
4 
5 unsigned get_size(unsigned requested, unsigned levels) {
6  auto const N = (1u << levels);
7  return requested % N == 0 ? requested : requested + N - requested % N;
8 }
9 std::string get_name(unsigned db) {
10  std::ostringstream sstr;
11  sstr << "DB" << db;
12  return sstr.str();
13 }
14 
15 template <typename TYPE, unsigned DB = 1, unsigned LEVEL = 1>
16 void direct_matrix(benchmark::State &state) {
17  auto const Nx = get_size(state.range_x(), LEVEL);
18  auto const Ny = get_size(state.range_y(), LEVEL);
19  auto const input = sopt::Image<TYPE>::Random(Nx, Ny).eval();
20  auto output = sopt::Image<TYPE>::Zero(Nx, Ny).eval();
21  auto const wavelet = sopt::wavelets::factory(get_name(DB), LEVEL);
22  while (state.KeepRunning()) wavelet.direct(output, input);
23  state.SetBytesProcessed(int64_t(state.iterations()) * int64_t(Nx) * int64_t(Ny) * sizeof(TYPE));
24 }
25 
26 template <typename TYPE, unsigned DB = 1, unsigned LEVEL = 1>
27 void indirect_matrix(benchmark::State &state) {
28  auto const Nx = get_size(state.range_x(), LEVEL);
29  auto const Ny = get_size(state.range_y(), LEVEL);
30  auto const input = sopt::Image<TYPE>::Random(Nx, Ny).eval();
31  auto output = sopt::Image<TYPE>::Zero(Nx, Ny).eval();
32  auto const wavelet = sopt::wavelets::factory(get_name(DB), LEVEL);
33  while (state.KeepRunning()) wavelet.indirect(input, output);
34  state.SetBytesProcessed(int64_t(state.iterations()) * int64_t(Nx) * int64_t(Ny) * sizeof(TYPE));
35 }
36 
37 template <typename TYPE, unsigned DB = 1, unsigned LEVEL = 1>
38 void direct_vector(benchmark::State &state) {
39  auto const Nx = get_size(state.range_x(), LEVEL);
40  auto const input = sopt::Array<TYPE>::Random(Nx).eval();
41  auto output = sopt::Array<TYPE>::Zero(Nx).eval();
42  auto const wavelet = sopt::wavelets::factory(get_name(DB), LEVEL);
43  while (state.KeepRunning()) wavelet.direct(output, input);
44  state.SetBytesProcessed(int64_t(state.iterations()) * int64_t(Nx) * sizeof(TYPE));
45 }
46 template <typename TYPE, unsigned DB = 1, unsigned LEVEL = 1>
47 void indirect_vector(benchmark::State &state) {
48  auto const Nx = get_size(state.range_x(), LEVEL);
49  auto const input = sopt::Array<TYPE>::Random(Nx).eval();
50  auto output = sopt::Array<TYPE>::Zero(Nx).eval();
51  auto const wavelet = sopt::wavelets::factory(get_name(DB), LEVEL);
52  while (state.KeepRunning()) wavelet.indirect(input, output);
53  state.SetBytesProcessed(int64_t(state.iterations()) * int64_t(Nx) * sizeof(TYPE));
54 }
55 
56 auto constexpr n = 64;
57 auto constexpr N = 256 * 3;
58 
59 BENCHMARK_TEMPLATE(direct_matrix, sopt::t_complex, 1, 1)->RangePair(n, N, n, N)->UseRealTime();
60 BENCHMARK_TEMPLATE(direct_matrix, sopt::t_real, 1, 1)->RangePair(n, N, n, N)->UseRealTime();
61 BENCHMARK_TEMPLATE(direct_matrix, sopt::t_complex, 10, 1)->RangePair(n, N, n, N)->UseRealTime();
62 
63 BENCHMARK_TEMPLATE(direct_vector, sopt::t_complex, 1, 1)->Range(n, N)->UseRealTime();
64 BENCHMARK_TEMPLATE(direct_vector, sopt::t_complex, 10, 1)->Range(n, N)->UseRealTime();
65 BENCHMARK_TEMPLATE(direct_vector, sopt::t_complex, 1, 2)->Range(n, N)->UseRealTime();
66 BENCHMARK_TEMPLATE(direct_vector, sopt::t_real, 1, 1)->Range(n, N)->UseRealTime();
67 
68 BENCHMARK_TEMPLATE(indirect_matrix, sopt::t_complex, 1, 1)->RangePair(n, N, n, N)->UseRealTime();
69 BENCHMARK_TEMPLATE(indirect_matrix, sopt::t_real, 1, 1)->RangePair(n, N, n, N)->UseRealTime();
70 BENCHMARK_TEMPLATE(indirect_matrix, sopt::t_complex, 10, 1)->RangePair(n, N, n, N)->UseRealTime();
71 
72 BENCHMARK_TEMPLATE(indirect_vector, sopt::t_complex, 1, 1)->Range(n, N)->UseRealTime();
73 BENCHMARK_TEMPLATE(indirect_vector, sopt::t_complex, 10, 1)->Range(n, N)->UseRealTime();
74 BENCHMARK_TEMPLATE(indirect_vector, sopt::t_complex, 1, 2)->Range(n, N)->UseRealTime();
75 BENCHMARK_TEMPLATE(indirect_vector, sopt::t_real, 1, 1)->Range(n, N)->UseRealTime();
76 
unsigned get_size(unsigned requested, unsigned levels)
Definition: wavelets.cc:5
BENCHMARK_TEMPLATE(direct_matrix, sopt::t_complex, 1, 1) -> RangePair(n, N, n, N) ->UseRealTime()
void direct_vector(benchmark::State &state)
Definition: wavelets.cc:38
BENCHMARK_MAIN()
void direct_matrix(benchmark::State &state)
Definition: wavelets.cc:16
void indirect_vector(benchmark::State &state)
Definition: wavelets.cc:47
void indirect_matrix(benchmark::State &state)
Definition: wavelets.cc:27
constexpr auto n
Definition: wavelets.cc:56
constexpr auto N
Definition: wavelets.cc:57
std::string get_name(unsigned db)
Definition: wavelets.cc:9
Wavelet factory(const std::string &name, t_uint nlevels)
Creates a wavelet transform object.
Definition: wavelets.cc:8
double t_real
Root of the type hierarchy for real numbers.
Definition: types.h:17
Eigen::Array< T, Eigen::Dynamic, Eigen::Dynamic > Image
A 2-dimensional list of elements of given type.
Definition: types.h:39
Eigen::Array< T, Eigen::Dynamic, 1 > Array
A 1-dimensional list of elements of given type.
Definition: types.h:34
std::complex< t_real > t_complex
Root of the type hierarchy for (real) complex numbers.
Definition: types.h:19