PURIFY
Next-generation radio interferometric imaging
measurement_operator.cc
Go to the documentation of this file.
1 #include <chrono>
2 #include <benchmark/benchmark.h>
3 #include "benchmarks/utilities.h"
4 #include "purify/operators.h"
5 
6 using namespace purify;
7 
8 // -------------- Constructor benchmark -------------------------//
9 
10 void degrid_operator_ctor(benchmark::State &state) {
11  // Generating random uv(w) coverage
12  t_int const rows = state.range(0);
13  t_int const cols = state.range(0);
14  t_int const number_of_vis = state.range(1);
15  auto uv_data = b_utilities::random_measurements(number_of_vis);
16 
17  const t_real FoV = 1; // deg
18  const t_real cellsize = FoV / cols * 60. * 60.;
19  const bool w_term = false;
20  // Keep count of the benchmark repetitions
21  static t_uint counter = 0;
22  counter++;
23  // benchmark the creation of measurement operator
24  if ((counter % 10) == 1) {
25  auto sky_measurements = measurementoperator::init_degrid_operator_2d<Vector<t_complex>>(
26  uv_data, rows, cols, cellsize, cellsize, 2, kernels::kernel::kb, state.range(2),
27  state.range(2), w_term);
28  }
29  while (state.KeepRunning()) {
30  auto start = std::chrono::high_resolution_clock::now();
31  auto sky_measurements = measurementoperator::init_degrid_operator_2d<Vector<t_complex>>(
32  uv_data, rows, cols, cellsize, cellsize, 2, kernels::kernel::kb, state.range(2),
33  state.range(2), w_term);
34  auto end = std::chrono::high_resolution_clock::now();
35 
36  state.SetIterationTime(b_utilities::duration(start, end));
37  }
38 
39  state.SetBytesProcessed(int64_t(state.iterations()) * (number_of_vis + rows * cols) *
40  sizeof(t_complex));
41 }
42 
43 // ----------------- Application benchmarks -----------------------//
44 
45 class DegridOperatorFixture : public ::benchmark::Fixture {
46  public:
47  void SetUp(const ::benchmark::State &state) {
48  // Keep count of the benchmark repetitions
49  m_counter++;
50 
51  // Reading image from file and create temporary image
52  bool newImage = updateImage(state.range(0));
53 
54  // Generating random uv(w) coverage
55  bool newMeasurements = m_uv_data.size() != state.range(1);
56  if (newMeasurements) {
57  t_real const sigma_m = constant::pi / 3;
58  m_uv_data = utilities::random_sample_density(state.range(1), 0, sigma_m);
59  }
60 
61  // Create measurement operator
62  bool newKernel = m_kernel != state.range(2);
63  if (newImage || newMeasurements || newKernel) {
64  const t_real FoV = 1; // deg
65  const t_real cellsize = FoV / m_imsizex * 60. * 60.;
66  const bool w_term = false;
67  m_kernel = state.range(2);
68  m_degridOperator = measurementoperator::init_degrid_operator_2d<Vector<t_complex>>(
69  m_uv_data, m_imsizey, m_imsizex, cellsize, cellsize, 2, kernels::kernel::kb, m_kernel,
70  m_kernel, w_term);
71  }
72  }
73 
74  void TearDown(const ::benchmark::State &state) {}
75 
76  virtual bool updateImage(t_uint newSize) = 0;
77 
78  t_uint m_counter;
79 
80  t_uint m_imsizex;
81  t_uint m_imsizey;
82 
84 
85  t_uint m_kernel;
86  std::shared_ptr<sopt::LinearTransform<Vector<t_complex>> const> m_degridOperator;
87 };
88 
90  public:
91  virtual bool updateImage(t_uint newSize) {
92  return b_utilities::updateImage(newSize, m_image, m_imsizex, m_imsizey);
93  }
94 
95  Image<t_complex> m_image;
96 };
97 
99  public:
100  virtual bool updateImage(t_uint newSize) {
101  return b_utilities::updateEmptyImage(newSize, m_image, m_imsizex, m_imsizey);
102  }
103 
104  Vector<t_complex> m_image;
105 };
106 
107 BENCHMARK_DEFINE_F(DegridOperatorDirectFixture, Apply)(benchmark::State &state) {
108  // Benchmark the application of the operator
109  if ((m_counter % 10) == 1) {
110  m_uv_data.vis = (*m_degridOperator) * Image<t_complex>::Map(m_image.data(), m_image.size(), 1);
111  }
112  while (state.KeepRunning()) {
113  auto start = std::chrono::high_resolution_clock::now();
114  m_uv_data.vis = (*m_degridOperator) * Image<t_complex>::Map(m_image.data(), m_image.size(), 1);
115  auto end = std::chrono::high_resolution_clock::now();
116  state.SetIterationTime(b_utilities::duration(start, end));
117  }
118 
119  state.SetBytesProcessed(int64_t(state.iterations()) * (state.range(1) + m_imsizey * m_imsizex) *
120  sizeof(t_complex));
121 }
122 
123 BENCHMARK_DEFINE_F(DegridOperatorAdjointFixture, Apply)(benchmark::State &state) {
124  // Benchmark the application of the adjoint operator
125  if ((m_counter % 10) == 1) {
126  m_image = m_degridOperator->adjoint() * m_uv_data.vis;
127  }
128  while (state.KeepRunning()) {
129  auto start = std::chrono::high_resolution_clock::now();
130  m_image = m_degridOperator->adjoint() * m_uv_data.vis;
131  auto end = std::chrono::high_resolution_clock::now();
132  state.SetIterationTime(b_utilities::duration(start, end));
133  }
134 
135  state.SetBytesProcessed(int64_t(state.iterations()) * (state.range(1) + m_imsizey * m_imsizex) *
136  sizeof(t_complex));
137 }
138 
139 BENCHMARK_REGISTER_F(DegridOperatorDirectFixture, Apply)
140  //->Apply(b_utilities::Arguments)
141  ->Args({1024, 1000000, 4})
142  ->Args({1024, 10000000, 4})
143  ->UseManualTime()
144  ->Repetitions(10)
145  //->ReportAggregatesOnly(true)
146  ->Unit(benchmark::kMillisecond);
147 
148 BENCHMARK_REGISTER_F(DegridOperatorAdjointFixture, Apply)
149  //->Apply(b_utilities::Arguments)
150  ->Args({1024, 1000000, 4})
151  ->Args({1024, 10000000, 4})
152  ->UseManualTime()
153  ->Repetitions(10)
154  //->ReportAggregatesOnly(true)
155  ->Unit(benchmark::kMillisecond);
156 
BENCHMARK_MAIN()
void degrid_operator_ctor(benchmark::State &state)
BENCHMARK_DEFINE_F(DegridOperatorDirectFixture, Apply)(benchmark
Args({1024, 1000000, 4}) -> Args({1024, 10000000, 4}) ->UseManualTime() ->Repetitions(10) ->Unit(benchmark::kMillisecond)
virtual bool updateImage(t_uint newSize)
virtual bool updateImage(t_uint newSize)
virtual bool updateImage(t_uint newSize)=0
void TearDown(const ::benchmark::State &state)
void SetUp(const ::benchmark::State &state)
utilities::vis_params m_uv_data
std::shared_ptr< sopt::LinearTransform< Vector< t_complex > > const > m_degridOperator
bool updateImage(t_uint newSize, Image< t_complex > &image, t_uint &sizex, t_uint &sizey)
Definition: utilities.cc:32
bool updateEmptyImage(t_uint newSize, Vector< t_complex > &image, t_uint &sizex, t_uint &sizey)
Definition: utilities.cc:44
double duration(std::chrono::high_resolution_clock::time_point start, std::chrono::high_resolution_clock::time_point end)
Definition: utilities.cc:26
utilities::vis_params random_measurements(t_int size, const t_real max_w, const t_int id, const bool cache_visibilities)
Definition: utilities.cc:96
const t_real pi
mathematical constant
Definition: types.h:70
utilities::vis_params random_sample_density(const t_int vis_num, const t_real mean, const t_real standard_deviation, const t_real rms_w)
Generates a random visibility coverage.