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
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
|
/*
* Copyright (c) 2016, Alliance for Open Media. All rights reserved
*
* This source code is subject to the terms of the BSD 2 Clause License and
* the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
* was not distributed with this source code in the LICENSE file, you can
* obtain it at www.aomedia.org/license/software. If the Alliance for Open
* Media Patent License 1.0 was not distributed with this source code in the
* PATENTS file, you can obtain it at www.aomedia.org/license/patent.
*/
#include <ctime>
#include <tuple>
#include "third_party/googletest/src/googletest/include/gtest/gtest.h"
#include "config/av1_rtcd.h"
#include "test/acm_random.h"
#include "test/register_state_check.h"
#include "test/util.h"
#include "aom_ports/aom_timer.h"
#include "av1/common/mv.h"
#include "av1/common/restoration.h"
namespace {
using libaom_test::ACMRandom;
using std::make_tuple;
using std::tuple;
typedef int (*SgrFunc)(const uint8_t *dat8, int width, int height, int stride,
int eps, const int *xqd, uint8_t *dst8, int dst_stride,
int32_t *tmpbuf, int bit_depth, int highbd);
// Test parameter list:
// <tst_fun_>
typedef tuple<SgrFunc> FilterTestParam;
class AV1SelfguidedFilterTest
: public ::testing::TestWithParam<FilterTestParam> {
public:
~AV1SelfguidedFilterTest() override = default;
void SetUp() override {}
protected:
void RunSpeedTest() {
tst_fun_ = GET_PARAM(0);
const int pu_width = RESTORATION_PROC_UNIT_SIZE;
const int pu_height = RESTORATION_PROC_UNIT_SIZE;
const int width = 256, height = 256, stride = 288, out_stride = 288;
const int NUM_ITERS = 2000;
int i, j, k;
uint8_t *input_ =
(uint8_t *)aom_memalign(32, stride * (height + 32) * sizeof(uint8_t));
ASSERT_NE(input_, nullptr);
uint8_t *output_ = (uint8_t *)aom_memalign(
32, out_stride * (height + 32) * sizeof(uint8_t));
ASSERT_NE(output_, nullptr);
int32_t *tmpbuf = (int32_t *)aom_memalign(32, RESTORATION_TMPBUF_SIZE);
ASSERT_NE(tmpbuf, nullptr);
uint8_t *input = input_ + stride * 16 + 16;
uint8_t *output = output_ + out_stride * 16 + 16;
ACMRandom rnd(ACMRandom::DeterministicSeed());
for (i = -16; i < height + 16; ++i)
for (j = -16; j < width + 16; ++j)
input[i * stride + j] = rnd.Rand16() & 0xFF;
int xqd[2] = { SGRPROJ_PRJ_MIN0 + rnd.PseudoUniform(SGRPROJ_PRJ_MAX0 + 1 -
SGRPROJ_PRJ_MIN0),
SGRPROJ_PRJ_MIN1 + rnd.PseudoUniform(SGRPROJ_PRJ_MAX1 + 1 -
SGRPROJ_PRJ_MIN1) };
// Fix a parameter set, since the speed depends slightly on r.
// Change this to test different combinations of values of r.
int eps = 15;
av1_loop_restoration_precal();
aom_usec_timer ref_timer;
aom_usec_timer_start(&ref_timer);
for (i = 0; i < NUM_ITERS; ++i) {
for (k = 0; k < height; k += pu_height)
for (j = 0; j < width; j += pu_width) {
int w = AOMMIN(pu_width, width - j);
int h = AOMMIN(pu_height, height - k);
uint8_t *input_p = input + k * stride + j;
uint8_t *output_p = output + k * out_stride + j;
const int ret_c = av1_apply_selfguided_restoration_c(
input_p, w, h, stride, eps, xqd, output_p, out_stride, tmpbuf, 8,
0);
ASSERT_EQ(ret_c, 0);
}
}
aom_usec_timer_mark(&ref_timer);
const int64_t ref_time = aom_usec_timer_elapsed(&ref_timer);
aom_usec_timer tst_timer;
aom_usec_timer_start(&tst_timer);
for (i = 0; i < NUM_ITERS; ++i) {
for (k = 0; k < height; k += pu_height)
for (j = 0; j < width; j += pu_width) {
int w = AOMMIN(pu_width, width - j);
int h = AOMMIN(pu_height, height - k);
uint8_t *input_p = input + k * stride + j;
uint8_t *output_p = output + k * out_stride + j;
const int ret_tst = tst_fun_(input_p, w, h, stride, eps, xqd,
output_p, out_stride, tmpbuf, 8, 0);
ASSERT_EQ(ret_tst, 0);
}
}
aom_usec_timer_mark(&tst_timer);
const int64_t tst_time = aom_usec_timer_elapsed(&tst_timer);
std::cout << "[ ] C time = " << ref_time / 1000
<< " ms, SIMD time = " << tst_time / 1000 << " ms\n";
EXPECT_GT(ref_time, tst_time)
<< "Error: AV1SelfguidedFilterTest.SpeedTest, SIMD slower than C.\n"
<< "C time: " << ref_time << " us\n"
<< "SIMD time: " << tst_time << " us\n";
aom_free(input_);
aom_free(output_);
aom_free(tmpbuf);
}
void RunCorrectnessTest() {
tst_fun_ = GET_PARAM(0);
const int pu_width = RESTORATION_PROC_UNIT_SIZE;
const int pu_height = RESTORATION_PROC_UNIT_SIZE;
// Set the maximum width/height to test here. We actually test a small
// range of sizes *up to* this size, so that we can check, eg.,
// the behaviour on tiles which are not a multiple of 4 wide.
const int max_w = 260, max_h = 260, stride = 672, out_stride = 672;
const int NUM_ITERS = 81;
int i, j, k;
uint8_t *input_ =
(uint8_t *)aom_memalign(32, stride * (max_h + 32) * sizeof(uint8_t));
ASSERT_NE(input_, nullptr);
uint8_t *output_ = (uint8_t *)aom_memalign(
32, out_stride * (max_h + 32) * sizeof(uint8_t));
ASSERT_NE(output_, nullptr);
uint8_t *output2_ = (uint8_t *)aom_memalign(
32, out_stride * (max_h + 32) * sizeof(uint8_t));
ASSERT_NE(output2_, nullptr);
int32_t *tmpbuf = (int32_t *)aom_memalign(32, RESTORATION_TMPBUF_SIZE);
ASSERT_NE(tmpbuf, nullptr);
uint8_t *input = input_ + stride * 16 + 16;
uint8_t *output = output_ + out_stride * 16 + 16;
uint8_t *output2 = output2_ + out_stride * 16 + 16;
ACMRandom rnd(ACMRandom::DeterministicSeed());
av1_loop_restoration_precal();
for (i = 0; i < NUM_ITERS; ++i) {
for (j = -16; j < max_h + 16; ++j)
for (k = -16; k < max_w + 16; ++k)
input[j * stride + k] = rnd.Rand16() & 0xFF;
int xqd[2] = { SGRPROJ_PRJ_MIN0 + rnd.PseudoUniform(SGRPROJ_PRJ_MAX0 + 1 -
SGRPROJ_PRJ_MIN0),
SGRPROJ_PRJ_MIN1 + rnd.PseudoUniform(SGRPROJ_PRJ_MAX1 + 1 -
SGRPROJ_PRJ_MIN1) };
int eps = rnd.PseudoUniform(1 << SGRPROJ_PARAMS_BITS);
// Test various tile sizes around 256x256
int test_w = max_w - (i / 9);
int test_h = max_h - (i % 9);
for (k = 0; k < test_h; k += pu_height)
for (j = 0; j < test_w; j += pu_width) {
int w = AOMMIN(pu_width, test_w - j);
int h = AOMMIN(pu_height, test_h - k);
uint8_t *input_p = input + k * stride + j;
uint8_t *output_p = output + k * out_stride + j;
uint8_t *output2_p = output2 + k * out_stride + j;
const int ret_tst = tst_fun_(input_p, w, h, stride, eps, xqd,
output_p, out_stride, tmpbuf, 8, 0);
ASSERT_EQ(ret_tst, 0);
const int ret_c = av1_apply_selfguided_restoration_c(
input_p, w, h, stride, eps, xqd, output2_p, out_stride, tmpbuf, 8,
0);
ASSERT_EQ(ret_c, 0);
}
for (j = 0; j < test_h; ++j)
for (k = 0; k < test_w; ++k) {
ASSERT_EQ(output[j * out_stride + k], output2[j * out_stride + k]);
}
}
aom_free(input_);
aom_free(output_);
aom_free(output2_);
aom_free(tmpbuf);
}
private:
SgrFunc tst_fun_;
};
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(AV1SelfguidedFilterTest);
TEST_P(AV1SelfguidedFilterTest, DISABLED_SpeedTest) { RunSpeedTest(); }
TEST_P(AV1SelfguidedFilterTest, CorrectnessTest) { RunCorrectnessTest(); }
#if HAVE_SSE4_1
INSTANTIATE_TEST_SUITE_P(
SSE4_1, AV1SelfguidedFilterTest,
::testing::Values(av1_apply_selfguided_restoration_sse4_1));
#endif
#if HAVE_AVX2
INSTANTIATE_TEST_SUITE_P(
AVX2, AV1SelfguidedFilterTest,
::testing::Values(av1_apply_selfguided_restoration_avx2));
#endif
#if HAVE_NEON
INSTANTIATE_TEST_SUITE_P(
NEON, AV1SelfguidedFilterTest,
::testing::Values(av1_apply_selfguided_restoration_neon));
#endif
#if CONFIG_AV1_HIGHBITDEPTH
// Test parameter list:
// <tst_fun_, bit_depth>
typedef tuple<SgrFunc, int> HighbdFilterTestParam;
class AV1HighbdSelfguidedFilterTest
: public ::testing::TestWithParam<HighbdFilterTestParam> {
public:
~AV1HighbdSelfguidedFilterTest() override = default;
void SetUp() override {}
protected:
void RunSpeedTest() {
tst_fun_ = GET_PARAM(0);
const int pu_width = RESTORATION_PROC_UNIT_SIZE;
const int pu_height = RESTORATION_PROC_UNIT_SIZE;
const int width = 256, height = 256, stride = 288, out_stride = 288;
const int NUM_ITERS = 2000;
int i, j, k;
int bit_depth = GET_PARAM(1);
int mask = (1 << bit_depth) - 1;
uint16_t *input_ =
(uint16_t *)aom_memalign(32, stride * (height + 32) * sizeof(uint16_t));
ASSERT_NE(input_, nullptr);
uint16_t *output_ = (uint16_t *)aom_memalign(
32, out_stride * (height + 32) * sizeof(uint16_t));
ASSERT_NE(output_, nullptr);
int32_t *tmpbuf = (int32_t *)aom_memalign(32, RESTORATION_TMPBUF_SIZE);
ASSERT_NE(tmpbuf, nullptr);
uint16_t *input = input_ + stride * 16 + 16;
uint16_t *output = output_ + out_stride * 16 + 16;
ACMRandom rnd(ACMRandom::DeterministicSeed());
for (i = -16; i < height + 16; ++i)
for (j = -16; j < width + 16; ++j)
input[i * stride + j] = rnd.Rand16() & mask;
int xqd[2] = { SGRPROJ_PRJ_MIN0 + rnd.PseudoUniform(SGRPROJ_PRJ_MAX0 + 1 -
SGRPROJ_PRJ_MIN0),
SGRPROJ_PRJ_MIN1 + rnd.PseudoUniform(SGRPROJ_PRJ_MAX1 + 1 -
SGRPROJ_PRJ_MIN1) };
// Fix a parameter set, since the speed depends slightly on r.
// Change this to test different combinations of values of r.
int eps = 15;
av1_loop_restoration_precal();
aom_usec_timer ref_timer;
aom_usec_timer_start(&ref_timer);
for (i = 0; i < NUM_ITERS; ++i) {
for (k = 0; k < height; k += pu_height)
for (j = 0; j < width; j += pu_width) {
int w = AOMMIN(pu_width, width - j);
int h = AOMMIN(pu_height, height - k);
uint16_t *input_p = input + k * stride + j;
uint16_t *output_p = output + k * out_stride + j;
av1_apply_selfguided_restoration_c(
CONVERT_TO_BYTEPTR(input_p), w, h, stride, eps, xqd,
CONVERT_TO_BYTEPTR(output_p), out_stride, tmpbuf, bit_depth, 1);
}
}
aom_usec_timer_mark(&ref_timer);
const int64_t ref_time = aom_usec_timer_elapsed(&ref_timer);
aom_usec_timer tst_timer;
aom_usec_timer_start(&tst_timer);
for (i = 0; i < NUM_ITERS; ++i) {
for (k = 0; k < height; k += pu_height)
for (j = 0; j < width; j += pu_width) {
int w = AOMMIN(pu_width, width - j);
int h = AOMMIN(pu_height, height - k);
uint16_t *input_p = input + k * stride + j;
uint16_t *output_p = output + k * out_stride + j;
tst_fun_(CONVERT_TO_BYTEPTR(input_p), w, h, stride, eps, xqd,
CONVERT_TO_BYTEPTR(output_p), out_stride, tmpbuf, bit_depth,
1);
}
}
aom_usec_timer_mark(&tst_timer);
const int64_t tst_time = aom_usec_timer_elapsed(&tst_timer);
std::cout << "[ ] C time = " << ref_time / 1000
<< " ms, SIMD time = " << tst_time / 1000 << " ms\n";
EXPECT_GT(ref_time, tst_time)
<< "Error: AV1HighbdSelfguidedFilterTest.SpeedTest, SIMD slower than "
"C.\n"
<< "C time: " << ref_time << " us\n"
<< "SIMD time: " << tst_time << " us\n";
aom_free(input_);
aom_free(output_);
aom_free(tmpbuf);
}
void RunCorrectnessTest() {
tst_fun_ = GET_PARAM(0);
const int pu_width = RESTORATION_PROC_UNIT_SIZE;
const int pu_height = RESTORATION_PROC_UNIT_SIZE;
// Set the maximum width/height to test here. We actually test a small
// range of sizes *up to* this size, so that we can check, eg.,
// the behaviour on tiles which are not a multiple of 4 wide.
const int max_w = 260, max_h = 260, stride = 672, out_stride = 672;
const int NUM_ITERS = 81;
int i, j, k;
int bit_depth = GET_PARAM(1);
int mask = (1 << bit_depth) - 1;
uint16_t *input_ =
(uint16_t *)aom_memalign(32, stride * (max_h + 32) * sizeof(uint16_t));
ASSERT_NE(input_, nullptr);
uint16_t *output_ = (uint16_t *)aom_memalign(
32, out_stride * (max_h + 32) * sizeof(uint16_t));
ASSERT_NE(output_, nullptr);
uint16_t *output2_ = (uint16_t *)aom_memalign(
32, out_stride * (max_h + 32) * sizeof(uint16_t));
ASSERT_NE(output2_, nullptr);
int32_t *tmpbuf = (int32_t *)aom_memalign(32, RESTORATION_TMPBUF_SIZE);
ASSERT_NE(tmpbuf, nullptr);
uint16_t *input = input_ + stride * 16 + 16;
uint16_t *output = output_ + out_stride * 16 + 16;
uint16_t *output2 = output2_ + out_stride * 16 + 16;
ACMRandom rnd(ACMRandom::DeterministicSeed());
av1_loop_restoration_precal();
for (i = 0; i < NUM_ITERS; ++i) {
for (j = -16; j < max_h + 16; ++j)
for (k = -16; k < max_w + 16; ++k)
input[j * stride + k] = rnd.Rand16() & mask;
int xqd[2] = { SGRPROJ_PRJ_MIN0 + rnd.PseudoUniform(SGRPROJ_PRJ_MAX0 + 1 -
SGRPROJ_PRJ_MIN0),
SGRPROJ_PRJ_MIN1 + rnd.PseudoUniform(SGRPROJ_PRJ_MAX1 + 1 -
SGRPROJ_PRJ_MIN1) };
int eps = rnd.PseudoUniform(1 << SGRPROJ_PARAMS_BITS);
// Test various tile sizes around 256x256
int test_w = max_w - (i / 9);
int test_h = max_h - (i % 9);
for (k = 0; k < test_h; k += pu_height)
for (j = 0; j < test_w; j += pu_width) {
int w = AOMMIN(pu_width, test_w - j);
int h = AOMMIN(pu_height, test_h - k);
uint16_t *input_p = input + k * stride + j;
uint16_t *output_p = output + k * out_stride + j;
uint16_t *output2_p = output2 + k * out_stride + j;
tst_fun_(CONVERT_TO_BYTEPTR(input_p), w, h, stride, eps, xqd,
CONVERT_TO_BYTEPTR(output_p), out_stride, tmpbuf, bit_depth,
1);
av1_apply_selfguided_restoration_c(
CONVERT_TO_BYTEPTR(input_p), w, h, stride, eps, xqd,
CONVERT_TO_BYTEPTR(output2_p), out_stride, tmpbuf, bit_depth, 1);
}
for (j = 0; j < test_h; ++j)
for (k = 0; k < test_w; ++k)
ASSERT_EQ(output[j * out_stride + k], output2[j * out_stride + k]);
}
aom_free(input_);
aom_free(output_);
aom_free(output2_);
aom_free(tmpbuf);
}
private:
SgrFunc tst_fun_;
};
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(AV1HighbdSelfguidedFilterTest);
TEST_P(AV1HighbdSelfguidedFilterTest, DISABLED_SpeedTest) { RunSpeedTest(); }
TEST_P(AV1HighbdSelfguidedFilterTest, CorrectnessTest) { RunCorrectnessTest(); }
#if HAVE_SSE4_1
const int highbd_params_sse4_1[] = { 8, 10, 12 };
INSTANTIATE_TEST_SUITE_P(
SSE4_1, AV1HighbdSelfguidedFilterTest,
::testing::Combine(
::testing::Values(av1_apply_selfguided_restoration_sse4_1),
::testing::ValuesIn(highbd_params_sse4_1)));
#endif
#if HAVE_AVX2
const int highbd_params_avx2[] = { 8, 10, 12 };
INSTANTIATE_TEST_SUITE_P(
AVX2, AV1HighbdSelfguidedFilterTest,
::testing::Combine(::testing::Values(av1_apply_selfguided_restoration_avx2),
::testing::ValuesIn(highbd_params_avx2)));
#endif
#if HAVE_NEON
const int highbd_params_neon[] = { 8, 10, 12 };
INSTANTIATE_TEST_SUITE_P(
NEON, AV1HighbdSelfguidedFilterTest,
::testing::Combine(::testing::Values(av1_apply_selfguided_restoration_neon),
::testing::ValuesIn(highbd_params_neon)));
#endif
#endif // CONFIG_AV1_HIGHBITDEPTH
} // namespace
|