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 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
|
#include <chrono>
#include <benchmark/benchmark.h>
#include "benchmarks/utilities.h"
#include "purify/operators_gpu.h"
using namespace purify;
// -------------- Constructor benchmark -------------------------//
void degrid_operator_ctor(benchmark::State &state) {
// Generating random uv(w) coverage
t_int const rows = state.range(0);
t_int const cols = state.range(0);
t_int const number_of_vis = state.range(1);
auto uv_data = b_utilities::random_measurements(number_of_vis);
const t_real FoV = 1; // deg
const t_real cellsize = FoV / cols * 60. * 60.;
const bool w_term = false;
// benchmark the creation of measurement operator
while (state.KeepRunning()) {
auto start = std::chrono::high_resolution_clock::now();
#ifdef PURIFY_CPU
auto sky_measurements = measurementoperator::init_degrid_operator_2d<Vector<t_complex>>(
uv_data, rows, cols, cellsize, cellsize, 2, kernels::kernel::kb, state.range(2),
state.range(2), w_term);
#else
auto sky_measurements = gpu::measurementoperator::init_degrid_operator_2d(
uv_data, rows, cols, cellsize, cellsize, 2, kernels::kernel::kb, state.range(2),
state.range(2), w_term);
#endif
auto end = std::chrono::high_resolution_clock::now();
state.SetIterationTime(b_utilities::duration(start, end));
}
state.SetBytesProcessed(int64_t(state.iterations()) * (number_of_vis + rows * cols) *
sizeof(t_complex));
}
/*
BENCHMARK(degrid_operator_ctor)
//->Apply(b_utilities::Arguments)
->Args({128, 1000, 4})
// ->Args({128, 1000, 4})
->UseManualTime()
->Repetitions(10)
->ReportAggregatesOnly(true)
->Unit(benchmark::kMillisecond);
*/
// ----------------- Application benchmarks -----------------------//
class DegridOperatorFixture : public ::benchmark::Fixture {
public:
void SetUp(const ::benchmark::State &state) {
af::setDevice(0);
af::setBackend(AF_BACKEND_CUDA);
// Keep count of the benchmark repetitions
m_counter++;
// Reading image from file and create temporary image
bool newImage = updateImage(state.range(0));
// Generating random uv(w) coverage
bool newMeasurements = b_utilities::updateMeasurements(state.range(1), m_uv_data);
// Create measurement operator
bool newKernel = m_kernel != state.range(2);
if (newImage || newMeasurements || newKernel) {
const t_real FoV = 1; // deg
const t_real cellsize = FoV / m_imsizex * 60. * 60.;
const bool w_term = false;
m_kernel = state.range(2);
#ifdef PURIFY_CPU
m_degridOperator = measurementoperator::init_degrid_operator_2d<Vector<t_complex>>(
m_uv_data, m_imsizey, m_imsizex, cellsize, cellsize, 2, kernels::kernel::kb, m_kernel,
m_kernel, w_term);
#else
m_degridOperator = gpu::measurementoperator::init_degrid_operator_2d(
m_uv_data, m_imsizey, m_imsizex, cellsize, cellsize, 2, kernels::kernel::kb, m_kernel,
m_kernel, w_term);
#endif
}
}
void TearDown(const ::benchmark::State &state) {}
virtual bool updateImage(t_uint newSize) = 0;
t_uint m_counter;
t_uint m_imsizex;
t_uint m_imsizey;
utilities::vis_params m_uv_data;
t_uint m_kernel;
std::shared_ptr<sopt::LinearTransform<Vector<t_complex>> const> m_degridOperator;
};
class DegridOperatorDirectFixture : public DegridOperatorFixture {
public:
virtual bool updateImage(t_uint newSize) {
return b_utilities::updateImage(newSize, m_image, m_imsizex, m_imsizey);
}
Image<t_complex> m_image;
};
class DegridOperatorAdjointFixture : public DegridOperatorFixture {
public:
virtual bool updateImage(t_uint newSize) {
return b_utilities::updateEmptyImage(newSize, m_image, m_imsizex, m_imsizey);
}
Vector<t_complex> m_image;
};
BENCHMARK_DEFINE_F(DegridOperatorDirectFixture, Apply)(benchmark::State &state) {
// Benchmark the application of the operator
if ((m_counter % 10) == 1) {
m_uv_data.vis = (*m_degridOperator) * Image<t_complex>::Map(m_image.data(), m_image.size(), 1);
}
while (state.KeepRunning()) {
auto start = std::chrono::high_resolution_clock::now();
m_uv_data.vis = (*m_degridOperator) * Image<t_complex>::Map(m_image.data(), m_image.size(), 1);
auto end = std::chrono::high_resolution_clock::now();
state.SetIterationTime(b_utilities::duration(start, end));
}
state.SetBytesProcessed(int64_t(state.iterations()) * (state.range(1) + m_imsizey * m_imsizex) *
sizeof(t_complex));
}
BENCHMARK_DEFINE_F(DegridOperatorAdjointFixture, Apply)(benchmark::State &state) {
// Benchmark the application of the adjoint operator
if ((m_counter % 10) == 1) {
m_image = m_degridOperator->adjoint() * m_uv_data.vis;
}
while (state.KeepRunning()) {
auto start = std::chrono::high_resolution_clock::now();
m_image = m_degridOperator->adjoint() * m_uv_data.vis;
auto end = std::chrono::high_resolution_clock::now();
state.SetIterationTime(b_utilities::duration(start, end));
}
state.SetBytesProcessed(int64_t(state.iterations()) * (state.range(1) + m_imsizey * m_imsizex) *
sizeof(t_complex));
}
BENCHMARK_REGISTER_F(DegridOperatorDirectFixture, Apply)
//->Apply(b_utilities::Arguments)
->Args({256, 500000, 4})
->Args({512, 500000, 4})
->Args({1024, 500000, 4})
->Args({2048, 500000, 4})
// ->Args({4096, 100000, 4})
->UseManualTime()
->Repetitions(10)
->ReportAggregatesOnly(true)
->Unit(benchmark::kMillisecond);
BENCHMARK_REGISTER_F(DegridOperatorAdjointFixture, Apply)
//->Apply(b_utilities::Arguments)
->Args({256, 500000, 4})
->Args({512, 500000, 4})
->Args({1024, 500000, 4})
->Args({2048, 500000, 4})
// ->Args({4096, 100000, 4})
->UseManualTime()
->Repetitions(10)
->ReportAggregatesOnly(true)
->Unit(benchmark::kMillisecond);
BENCHMARK_MAIN();
|