File: wavelets.cc

package info (click to toggle)
sopt 5.0.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,704 kB
  • sloc: cpp: 13,620; xml: 182; makefile: 6
file content (77 lines) | stat: -rw-r--r-- 3,818 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include <sstream>
#include <benchmark/benchmark.h>
#include "sopt/wavelets/wavelets.h"

unsigned get_size(unsigned requested, unsigned levels) {
  auto const N = (1u << levels);
  return requested % N == 0 ? requested : requested + N - requested % N;
}
std::string get_name(unsigned db) {
  std::ostringstream sstr;
  sstr << "DB" << db;
  return sstr.str();
}

template <typename TYPE, unsigned DB = 1, unsigned LEVEL = 1>
void direct_matrix(benchmark::State &state) {
  auto const Nx = get_size(state.range_x(), LEVEL);
  auto const Ny = get_size(state.range_y(), LEVEL);
  auto const input = sopt::Image<TYPE>::Random(Nx, Ny).eval();
  auto output = sopt::Image<TYPE>::Zero(Nx, Ny).eval();
  auto const wavelet = sopt::wavelets::factory(get_name(DB), LEVEL);
  while (state.KeepRunning()) wavelet.direct(output, input);
  state.SetBytesProcessed(int64_t(state.iterations()) * int64_t(Nx) * int64_t(Ny) * sizeof(TYPE));
}

template <typename TYPE, unsigned DB = 1, unsigned LEVEL = 1>
void indirect_matrix(benchmark::State &state) {
  auto const Nx = get_size(state.range_x(), LEVEL);
  auto const Ny = get_size(state.range_y(), LEVEL);
  auto const input = sopt::Image<TYPE>::Random(Nx, Ny).eval();
  auto output = sopt::Image<TYPE>::Zero(Nx, Ny).eval();
  auto const wavelet = sopt::wavelets::factory(get_name(DB), LEVEL);
  while (state.KeepRunning()) wavelet.indirect(input, output);
  state.SetBytesProcessed(int64_t(state.iterations()) * int64_t(Nx) * int64_t(Ny) * sizeof(TYPE));
}

template <typename TYPE, unsigned DB = 1, unsigned LEVEL = 1>
void direct_vector(benchmark::State &state) {
  auto const Nx = get_size(state.range_x(), LEVEL);
  auto const input = sopt::Array<TYPE>::Random(Nx).eval();
  auto output = sopt::Array<TYPE>::Zero(Nx).eval();
  auto const wavelet = sopt::wavelets::factory(get_name(DB), LEVEL);
  while (state.KeepRunning()) wavelet.direct(output, input);
  state.SetBytesProcessed(int64_t(state.iterations()) * int64_t(Nx) * sizeof(TYPE));
}
template <typename TYPE, unsigned DB = 1, unsigned LEVEL = 1>
void indirect_vector(benchmark::State &state) {
  auto const Nx = get_size(state.range_x(), LEVEL);
  auto const input = sopt::Array<TYPE>::Random(Nx).eval();
  auto output = sopt::Array<TYPE>::Zero(Nx).eval();
  auto const wavelet = sopt::wavelets::factory(get_name(DB), LEVEL);
  while (state.KeepRunning()) wavelet.indirect(input, output);
  state.SetBytesProcessed(int64_t(state.iterations()) * int64_t(Nx) * sizeof(TYPE));
}

auto constexpr n = 64;
auto constexpr N = 256 * 3;

BENCHMARK_TEMPLATE(direct_matrix, sopt::t_complex, 1, 1)->RangePair(n, N, n, N)->UseRealTime();
BENCHMARK_TEMPLATE(direct_matrix, sopt::t_real, 1, 1)->RangePair(n, N, n, N)->UseRealTime();
BENCHMARK_TEMPLATE(direct_matrix, sopt::t_complex, 10, 1)->RangePair(n, N, n, N)->UseRealTime();

BENCHMARK_TEMPLATE(direct_vector, sopt::t_complex, 1, 1)->Range(n, N)->UseRealTime();
BENCHMARK_TEMPLATE(direct_vector, sopt::t_complex, 10, 1)->Range(n, N)->UseRealTime();
BENCHMARK_TEMPLATE(direct_vector, sopt::t_complex, 1, 2)->Range(n, N)->UseRealTime();
BENCHMARK_TEMPLATE(direct_vector, sopt::t_real, 1, 1)->Range(n, N)->UseRealTime();

BENCHMARK_TEMPLATE(indirect_matrix, sopt::t_complex, 1, 1)->RangePair(n, N, n, N)->UseRealTime();
BENCHMARK_TEMPLATE(indirect_matrix, sopt::t_real, 1, 1)->RangePair(n, N, n, N)->UseRealTime();
BENCHMARK_TEMPLATE(indirect_matrix, sopt::t_complex, 10, 1)->RangePair(n, N, n, N)->UseRealTime();

BENCHMARK_TEMPLATE(indirect_vector, sopt::t_complex, 1, 1)->Range(n, N)->UseRealTime();
BENCHMARK_TEMPLATE(indirect_vector, sopt::t_complex, 10, 1)->Range(n, N)->UseRealTime();
BENCHMARK_TEMPLATE(indirect_vector, sopt::t_complex, 1, 2)->Range(n, N)->UseRealTime();
BENCHMARK_TEMPLATE(indirect_vector, sopt::t_real, 1, 1)->Range(n, N)->UseRealTime();

BENCHMARK_MAIN();