PURIFY
Next-generation radio interferometric imaging
measurement_operator_af.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_gpu.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  // benchmark the creation of measurement operator
21  while (state.KeepRunning()) {
22  auto start = std::chrono::high_resolution_clock::now();
23 #ifdef PURIFY_CPU
24  auto sky_measurements = measurementoperator::init_degrid_operator_2d<Vector<t_complex>>(
25  uv_data, rows, cols, cellsize, cellsize, 2, kernels::kernel::kb, state.range(2),
26  state.range(2), w_term);
27 #else
29  uv_data, rows, cols, cellsize, cellsize, 2, kernels::kernel::kb, state.range(2),
30  state.range(2), w_term);
31 
32 #endif
33  auto end = std::chrono::high_resolution_clock::now();
34 
35  state.SetIterationTime(b_utilities::duration(start, end));
36  }
37 
38  state.SetBytesProcessed(int64_t(state.iterations()) * (number_of_vis + rows * cols) *
39  sizeof(t_complex));
40 }
41 /*
42 BENCHMARK(degrid_operator_ctor)
43  //->Apply(b_utilities::Arguments)
44  ->Args({128, 1000, 4})
45  // ->Args({128, 1000, 4})
46  ->UseManualTime()
47  ->Repetitions(10)
48  ->ReportAggregatesOnly(true)
49  ->Unit(benchmark::kMillisecond);
50 */
51 // ----------------- Application benchmarks -----------------------//
52 
53 class DegridOperatorFixture : public ::benchmark::Fixture {
54  public:
55  void SetUp(const ::benchmark::State &state) {
56  af::setDevice(0);
57  af::setBackend(AF_BACKEND_CUDA);
58  // Keep count of the benchmark repetitions
59  m_counter++;
60 
61  // Reading image from file and create temporary image
62  bool newImage = updateImage(state.range(0));
63 
64  // Generating random uv(w) coverage
65  bool newMeasurements = b_utilities::updateMeasurements(state.range(1), m_uv_data);
66 
67  // Create measurement operator
68  bool newKernel = m_kernel != state.range(2);
69  if (newImage || newMeasurements || newKernel) {
70  const t_real FoV = 1; // deg
71  const t_real cellsize = FoV / m_imsizex * 60. * 60.;
72  const bool w_term = false;
73  m_kernel = state.range(2);
74 #ifdef PURIFY_CPU
75  m_degridOperator = measurementoperator::init_degrid_operator_2d<Vector<t_complex>>(
76  m_uv_data, m_imsizey, m_imsizex, cellsize, cellsize, 2, kernels::kernel::kb, m_kernel,
77  m_kernel, w_term);
78 #else
80  m_uv_data, m_imsizey, m_imsizex, cellsize, cellsize, 2, kernels::kernel::kb, m_kernel,
81  m_kernel, w_term);
82 #endif
83  }
84  }
85 
86  void TearDown(const ::benchmark::State &state) {}
87 
88  virtual bool updateImage(t_uint newSize) = 0;
89 
90  t_uint m_counter;
91 
92  t_uint m_imsizex;
93  t_uint m_imsizey;
94 
95  utilities::vis_params m_uv_data;
96 
97  t_uint m_kernel;
98  std::shared_ptr<sopt::LinearTransform<Vector<t_complex>> const> m_degridOperator;
99 };
100 
102  public:
103  virtual bool updateImage(t_uint newSize) {
104  return b_utilities::updateImage(newSize, m_image, m_imsizex, m_imsizey);
105  }
106 
107  Image<t_complex> m_image;
108 };
109 
111  public:
112  virtual bool updateImage(t_uint newSize) {
113  return b_utilities::updateEmptyImage(newSize, m_image, m_imsizex, m_imsizey);
114  }
115 
116  Vector<t_complex> m_image;
117 };
118 
119 BENCHMARK_DEFINE_F(DegridOperatorDirectFixture, Apply)(benchmark::State &state) {
120  // Benchmark the application of the operator
121  if ((m_counter % 10) == 1) {
122  m_uv_data.vis = (*m_degridOperator) * Image<t_complex>::Map(m_image.data(), m_image.size(), 1);
123  }
124  while (state.KeepRunning()) {
125  auto start = std::chrono::high_resolution_clock::now();
126  m_uv_data.vis = (*m_degridOperator) * Image<t_complex>::Map(m_image.data(), m_image.size(), 1);
127  auto end = std::chrono::high_resolution_clock::now();
128  state.SetIterationTime(b_utilities::duration(start, end));
129  }
130 
131  state.SetBytesProcessed(int64_t(state.iterations()) * (state.range(1) + m_imsizey * m_imsizex) *
132  sizeof(t_complex));
133 }
134 
135 BENCHMARK_DEFINE_F(DegridOperatorAdjointFixture, Apply)(benchmark::State &state) {
136  // Benchmark the application of the adjoint operator
137  if ((m_counter % 10) == 1) {
138  m_image = m_degridOperator->adjoint() * m_uv_data.vis;
139  }
140  while (state.KeepRunning()) {
141  auto start = std::chrono::high_resolution_clock::now();
142  m_image = m_degridOperator->adjoint() * m_uv_data.vis;
143  auto end = std::chrono::high_resolution_clock::now();
144  state.SetIterationTime(b_utilities::duration(start, end));
145  }
146 
147  state.SetBytesProcessed(int64_t(state.iterations()) * (state.range(1) + m_imsizey * m_imsizex) *
148  sizeof(t_complex));
149 }
150 
151 BENCHMARK_REGISTER_F(DegridOperatorDirectFixture, Apply)
152  //->Apply(b_utilities::Arguments)
153  ->Args({256, 500000, 4})
154  ->Args({512, 500000, 4})
155  ->Args({1024, 500000, 4})
156  ->Args({2048, 500000, 4})
157  // ->Args({4096, 100000, 4})
158  ->UseManualTime()
159  ->Repetitions(10)
160  ->ReportAggregatesOnly(true)
161  ->Unit(benchmark::kMillisecond);
162 
163 BENCHMARK_REGISTER_F(DegridOperatorAdjointFixture, Apply)
164  //->Apply(b_utilities::Arguments)
165  ->Args({256, 500000, 4})
166  ->Args({512, 500000, 4})
167  ->Args({1024, 500000, 4})
168  ->Args({2048, 500000, 4})
169  // ->Args({4096, 100000, 4})
170  ->UseManualTime()
171  ->Repetitions(10)
172  ->ReportAggregatesOnly(true)
173  ->Unit(benchmark::kMillisecond);
174 
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)
Args({256, 500000, 4}) -> Args({512, 500000, 4}) ->Args({1024, 500000, 4}) ->Args({2048, 500000, 4}) ->UseManualTime() ->Repetitions(10) ->ReportAggregatesOnly(true) ->Unit(benchmark::kMillisecond)
BENCHMARK_MAIN()
void degrid_operator_ctor(benchmark::State &state)
BENCHMARK_DEFINE_F(DegridOperatorDirectFixture, Apply)(benchmark
bool updateMeasurements(t_uint newSize, utilities::vis_params &data)
Definition: utilities.cc:54
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
std::shared_ptr< sopt::LinearTransform< T > > init_degrid_operator_2d(const Vector< t_real > &u, const Vector< t_real > &v, const Vector< t_real > &w, const Vector< t_complex > &weights, const t_uint &imsizey, const t_uint &imsizex, const t_real &oversample_ratio=2, const kernels::kernel kernel=kernels::kernel::kb, const t_uint Ju=4, const t_uint Jv=4, const bool w_stacking=false, const t_real &cellx=1, const t_real &celly=1)
Returns linear transform that is the standard degridding operator.
Definition: operators.h:608