File: defaultstrategyspeedtest.cpp

package info (click to toggle)
aoflagger 3.4.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 8,960 kB
  • sloc: cpp: 83,076; python: 10,187; sh: 260; makefile: 178
file content (283 lines) | stat: -rw-r--r-- 10,832 bytes parent folder | download | duplicates (2)
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
#include "../../algorithms/combinatorialthresholder.h"
#include "../../algorithms/polarizationstatistics.h"
#include "../../algorithms/testsetgenerator.h"
#include "../../algorithms/thresholdconfig.h"
#include "../../algorithms/siroperator.h"
#include "../../algorithms/sumthreshold.h"
#include "../../algorithms/sumthresholdmissing.h"

#include "../../lua/telescopefile.h"

#include "../../structures/timefrequencydata.h"

#include "../../util/logger.h"
#include "../../util/stopwatch.h"

#include <boost/test/unit_test.hpp>

using algorithms::BackgroundTestSet;
using algorithms::RFITestSet;
using algorithms::SumThreshold;
using algorithms::SumThresholdMissing;
using algorithms::TestSetGenerator;
using algorithms::ThresholdConfig;

namespace {
constexpr size_t nRepeats = 3;
constexpr size_t width = 50000, height = 256;
}  // namespace

BOOST_AUTO_TEST_SUITE(default_strategy_speed,
                      *boost::unit_test::label("experiment") *
                          boost::unit_test::disabled())

TimeFrequencyData prepareData() {
  TimeFrequencyData data = TestSetGenerator::MakeTestSet(
      RFITestSet::GaussianBursts, BackgroundTestSet::Empty, width, height);
  return data.Make(TimeFrequencyData::AmplitudePart);
}

BOOST_AUTO_TEST_CASE(time_masked_sumthreshold_full) {
  TimeFrequencyData data = prepareData();

  ThresholdConfig config;
  config.InitializeLengthsDefault(9);
  const num_t stddev = data.GetSingleImage()->GetStdDev();
  config.InitializeThresholdsFromFirstThreshold(6.0 * stddev,
                                                ThresholdConfig::Rayleigh);

  Image2DCPtr image = data.GetSingleImage();
  Mask2D zero = Mask2D::MakeSetMask<false>(image->Width(), image->Height());
  Mask2D mask(zero);

  double t = 0.0;
  for (size_t i = 0; i != 10; ++i) {
    Stopwatch watch(true);
    config.ExecuteWithMissing(image.get(), &mask, &zero, true, 1.0, 1.0);
    t += watch.Seconds();
    mask = zero;
  }
  std::cout << "10 runs: " << t << '\n';
}

BOOST_AUTO_TEST_CASE(time_sumthreshold_n_hori) {
  TimeFrequencyData data = prepareData();

  ThresholdConfig config;
  config.InitializeLengthsDefault(9);
  const num_t stddev = data.GetSingleImage()->GetStdDev();
  config.InitializeThresholdsFromFirstThreshold(6.0 * stddev,
                                                ThresholdConfig::Rayleigh);
  double hor = 0.0, sseHor = 0.0, avxHorDumas = 0.0, selectedHor = 0.0,
         missing = 0.0;
  for (unsigned i = 0; i < 9; ++i) {
    const unsigned length = config.GetHorizontalLength(i);
    const double threshold = config.GetHorizontalThreshold(i);
    Image2DCPtr input = data.GetSingleImage();
    Mask2D scratch = Mask2D::MakeUnsetMask(input->Width(), input->Height());
    SumThreshold::VerticalScratch vScratch(input->Width(), input->Height());

    Mask2D mask(*data.GetSingleMask()), maskInp;
    Mask2D zero = Mask2D::MakeSetMask<false>(mask.Width(), mask.Height());
    Stopwatch watch(true);
    for (size_t j = 0; j != nRepeats; ++j) {
      maskInp = mask;
      SumThreshold::HorizontalLargeReference(input.get(), &maskInp, &scratch,
                                             length, threshold);
    }
    hor += watch.Seconds();
    Logger::Info << "Horizontal, length " << length << ": " << watch.ToString()
                 << '\n';

    mask = *data.GetSingleMask();
    watch.Reset(true);
    for (size_t j = 0; j != nRepeats; ++j) {
      maskInp = mask;
      SumThresholdMissing::Horizontal(*input, maskInp, zero, scratch, length,
                                      threshold);
    }
    missing += watch.Seconds();
    Logger::Info << "Horizontal with missing, length " << length << ": "
                 << watch.ToString() << '\n';

#if defined(__SSE__) || defined(__x86_64__)
    if (__builtin_cpu_supports("sse")) {
      mask = *data.GetSingleMask();
      watch.Reset(true);
      for (size_t j = 0; j != nRepeats; ++j) {
        maskInp = mask;
        SumThreshold::HorizontalLargeSSE(input.get(), &maskInp, &scratch,
                                         length, threshold);
      }
      sseHor += watch.Seconds();
      Logger::Info << "SSE Horizontal, length " << length << ": "
                   << watch.ToString() << '\n';
    }
#endif

#if defined(__AVX2__) || defined(__x86_64__)
    if (__builtin_cpu_supports("avx2")) {
      mask = *data.GetSingleMask();
      watch.Reset(true);
      for (size_t j = 0; j != nRepeats; ++j) {
        maskInp = mask;
        SumThreshold::HorizontalAVXDumas(input.get(), &maskInp, length,
                                         threshold);
      }
      avxHorDumas += watch.Seconds();
      Logger::Info << "AVX Horizontal Dumas, length " << length << ": "
                   << watch.ToString() << '\n';
    }
#endif

    mask = *data.GetSingleMask();
    watch.Reset(true);
    for (size_t j = 0; j != nRepeats; ++j) {
      maskInp = mask;
      SumThreshold::HorizontalLarge(input.get(), &maskInp, &scratch, length,
                                    threshold);
    }
    selectedHor += watch.Seconds();
    Logger::Info << "Selected horizontal, length " << length << ": "
                 << watch.ToString() << '\n';

    Logger::Info << "Summed values:\n"
                 << "- Horizontal ref  : " << hor << "\n"
                 << "- Horizontal missing  : " << missing << "\n"
                 << "- Horizontal SSE  : " << sseHor << "\n"
                 << "- Horizontal AVX D: " << avxHorDumas << "\n"
                 << "- Selected horiz  : " << selectedHor << "\n";
  }
}

BOOST_AUTO_TEST_CASE(time_sumthreshold_n_vert) {
  TimeFrequencyData data = prepareData();

  ThresholdConfig config;
  config.InitializeLengthsDefault(9);
  const num_t stddev = data.GetSingleImage()->GetStdDev();
  config.InitializeThresholdsFromFirstThreshold(6.0 * stddev,
                                                ThresholdConfig::Rayleigh);
  double vert = 0.0, sseVert = 0.0, avxVert = 0.0, avxVertDumas = 0.0,
         missingRef = 0.0, missingStacked = 0.0, missingConsecutive = 0.0,
         selectedVer = 0.0;
  for (unsigned i = 0; i < 9; ++i) {
    const unsigned length = config.GetHorizontalLength(i);
    const double threshold = config.GetHorizontalThreshold(i);
    Image2DCPtr input = data.GetSingleImage();
    Mask2D scratch = Mask2D::MakeUnsetMask(input->Width(), input->Height());
    SumThreshold::VerticalScratch vScratch(input->Width(), input->Height());

    Mask2D mask(*data.GetSingleMask()), maskInp;
    Mask2D zero = Mask2D::MakeSetMask<false>(mask.Width(), mask.Height());

    Stopwatch watch(true);
    for (size_t j = 0; j != nRepeats; ++j) {
      maskInp = mask;
      SumThreshold::VerticalLargeReference(input.get(), &maskInp, &scratch,
                                           length, threshold);
    }
    vert += watch.Seconds();
    Logger::Info << "Vertical, length " << length << ": " << watch.ToString()
                 << '\n';

    mask = *data.GetSingleMask();
    watch.Reset(true);
    for (size_t j = 0; j != nRepeats; ++j) {
      maskInp = mask;
      SumThresholdMissing::VerticalReference(*input, maskInp, zero, scratch,
                                             length, threshold);
    }
    missingRef += watch.Seconds();
    Logger::Info << "Vertical missing ref, length " << length << ": "
                 << watch.ToString() << '\n';

    mask = *data.GetSingleMask();
    watch.Reset(true);
    SumThresholdMissing::VerticalCache vCache;
    SumThresholdMissing::InitializeVertical(vCache, *input, zero);
    for (size_t j = 0; j != nRepeats; ++j) {
      maskInp = mask;
      SumThresholdMissing::VerticalStacked(vCache, *input, maskInp, zero,
                                           scratch, length, threshold);
    }
    missingStacked += watch.Seconds();
    Logger::Info << "Vertical missing stacked, length " << length << ": "
                 << watch.ToString() << '\n';

    mask = *data.GetSingleMask();
    watch.Reset(true);
    for (size_t j = 0; j != nRepeats; ++j) {
      maskInp = mask;
      SumThresholdMissing::VerticalConsecutive(*input, maskInp, zero, scratch,
                                               length, threshold);
    }
    missingConsecutive += watch.Seconds();
    Logger::Info << "Vertical missing consecutive, length " << length << ": "
                 << watch.ToString() << '\n';

#if defined(__SSE__) || defined(__x86_64__)
    if (__builtin_cpu_supports("sse")) {
      mask = *data.GetSingleMask();
      watch.Reset(true);
      for (size_t j = 0; j != nRepeats; ++j) {
        maskInp = mask;
        SumThreshold::VerticalLargeSSE(input.get(), &maskInp, &scratch, length,
                                       threshold);
      }
      sseVert += watch.Seconds();
      Logger::Info << "SSE Vertical, length " << length << ": "
                   << watch.ToString() << '\n';
    }
#endif

#if defined(__AVX2__) || defined(__x86_64__)
    if (__builtin_cpu_supports("avx2")) {
      mask = *data.GetSingleMask();
      watch.Reset(true);
      for (size_t j = 0; j != nRepeats; ++j) {
        maskInp = mask;
        SumThreshold::VerticalLargeAVX(input.get(), &maskInp, &scratch, length,
                                       threshold);
      }
      avxVert += watch.Seconds();
      Logger::Info << "AVX Vertical, length " << length << ": "
                   << watch.ToString() << '\n';

      mask = *data.GetSingleMask();
      watch.Reset(true);
      for (size_t j = 0; j != nRepeats; ++j) {
        maskInp = mask;
        SumThreshold::VerticalAVXDumas(input.get(), &maskInp, &vScratch, length,
                                       threshold);
      }
      avxVertDumas += watch.Seconds();
      Logger::Info << "AVX Vertical Dumas, length " << length << ": "
                   << watch.ToString() << '\n';
    }
#endif

    mask = *data.GetSingleMask();
    watch.Reset(true);
    for (size_t j = 0; j != nRepeats; ++j) {
      maskInp = mask;
      SumThreshold::VerticalLarge(input.get(), &maskInp, &scratch, &vScratch,
                                  length, threshold);
    }
    selectedVer += watch.Seconds();
    Logger::Info << "Selected vertical, length " << length << ": "
                 << watch.ToString() << '\n';

    Logger::Info << "Summed values:\n"
                 << "- Vertical ref        : " << vert << "\n"
                 << "- Vertical missing ref: " << missingRef << "\n"
                 << "- Vertical m. stacked : " << missingStacked << "\n"
                 << "- Vertical m. consec  : " << missingConsecutive << "\n"
                 << "- Vertical SSE        : " << sseVert << "\n"
                 << "- Vertical AVX        : " << avxVert << "\n"
                 << "- Vertical AVX D      : " << avxVertDumas << "\n"
                 << "- Selected vertic     : " << selectedVer << "\n";
  }
}

BOOST_AUTO_TEST_SUITE_END()