Add av1_convolve_ x,y _avx2()
[aom.git] / test / av1_convolve_2d_test_util.cc
blob02739ff6e9cd3a68c0ea5e4e77efcc28ad6341b4
1 /*
2 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
4 * This source code is subject to the terms of the BSD 2 Clause License and
5 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6 * was not distributed with this source code in the LICENSE file, you can
7 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8 * Media Patent License 1.0 was not distributed with this source code in the
9 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
12 #include "test/av1_convolve_2d_test_util.h"
14 #include "aom_ports/aom_timer.h"
15 #include "av1/common/common_data.h"
16 #include "av1/common/convolve.h"
18 using std::tr1::tuple;
19 using std::tr1::make_tuple;
21 namespace libaom_test {
23 namespace AV1Convolve2D {
25 ::testing::internal::ParamGenerator<Convolve2DParam> BuildParams(
26 convolve_2d_func filter, int has_subx, int has_suby, int is_compound) {
27 const Convolve2DParam params[] = {
28 make_tuple(4, 4, filter, has_subx, has_suby, is_compound),
29 make_tuple(8, 8, filter, has_subx, has_suby, is_compound),
30 make_tuple(64, 64, filter, has_subx, has_suby, is_compound),
31 make_tuple(4, 16, filter, has_subx, has_suby, is_compound),
32 make_tuple(32, 8, filter, has_subx, has_suby, is_compound),
34 return ::testing::ValuesIn(params);
37 AV1Convolve2DTest::~AV1Convolve2DTest() {}
38 void AV1Convolve2DTest::SetUp() { rnd_.Reset(ACMRandom::DeterministicSeed()); }
40 void AV1Convolve2DTest::TearDown() { libaom_test::ClearSystemState(); }
42 void AV1Convolve2DTest::RunCheckOutput(convolve_2d_func test_impl) {
43 const int w = 128, h = 128;
44 const int out_w = GET_PARAM(0), out_h = GET_PARAM(1);
45 int i, j, k;
46 const int has_subx = GET_PARAM(3);
47 const int has_suby = GET_PARAM(4);
48 const int is_compound = GET_PARAM(5);
49 (void)is_compound;
51 uint8_t *input = new uint8_t[h * w];
53 int output_n = out_h * MAX_SB_SIZE;
54 CONV_BUF_TYPE *output = new CONV_BUF_TYPE[output_n];
55 CONV_BUF_TYPE *output2 = new CONV_BUF_TYPE[output_n];
57 for (i = 0; i < h; ++i)
58 for (j = 0; j < w; ++j) input[i * w + j] = rnd_.Rand8();
60 int hfilter, vfilter, subx, suby;
61 for (hfilter = EIGHTTAP_REGULAR; hfilter < INTERP_FILTERS_ALL; ++hfilter) {
62 for (vfilter = EIGHTTAP_REGULAR; vfilter < INTERP_FILTERS_ALL; ++vfilter) {
63 InterpFilterParams filter_params_x =
64 av1_get_interp_filter_params((InterpFilter)hfilter);
65 InterpFilterParams filter_params_y =
66 av1_get_interp_filter_params((InterpFilter)vfilter);
67 const int do_average = rnd_.Rand8() & 1;
68 ConvolveParams conv_params1 =
69 get_conv_params_no_round(0, do_average, 0, output, MAX_SB_SIZE, 1);
70 ConvolveParams conv_params2 =
71 get_conv_params_no_round(0, do_average, 0, output2, MAX_SB_SIZE, 1);
73 const int subx_range = has_subx ? 16 : 1;
74 const int suby_range = has_suby ? 16 : 1;
75 for (subx = 0; subx < subx_range; ++subx)
76 for (suby = 0; suby < suby_range; ++suby) {
77 // av1_convolve_2d is designed for accumulate two predicted blocks for
78 // compound mode, so we set num_iter to two here.
79 // A larger number may introduce overflow
80 const int num_iters = 2;
81 memset(output, 0, output_n * sizeof(*output));
82 memset(output2, 0, output_n * sizeof(*output2));
83 for (i = 0; i < num_iters; ++i) {
84 // Choose random locations within the source block
85 int offset_r = 3 + rnd_.PseudoUniform(h - out_h - 7);
86 int offset_c = 3 + rnd_.PseudoUniform(w - out_w - 7);
87 av1_convolve_2d_c(input + offset_r * w + offset_c, w, NULL, 0,
88 out_w, out_h, &filter_params_x, &filter_params_y,
89 subx, suby, &conv_params1);
90 test_impl(input + offset_r * w + offset_c, w, NULL, 0, out_w, out_h,
91 &filter_params_x, &filter_params_y, subx, suby,
92 &conv_params2);
94 for (j = 0; j < out_h; ++j)
95 for (k = 0; k < out_w; ++k) {
96 int idx = j * MAX_SB_SIZE + k;
97 ASSERT_EQ(output[idx], output2[idx])
98 << "Pixel mismatch at index " << idx << " = (" << j << ", "
99 << k << "), sub pixel offset = (" << suby << ", " << subx
100 << ")";
106 delete[] input;
107 delete[] output;
108 delete[] output2;
111 void AV1Convolve2DTest::RunSpeedTest(convolve_2d_func test_impl) {
112 const int w = 128, h = 128;
113 const int out_w = GET_PARAM(0), out_h = GET_PARAM(1);
114 int i, j;
115 const int has_subx = GET_PARAM(3);
116 const int has_suby = GET_PARAM(4);
117 const int is_compound = GET_PARAM(5);
118 (void)is_compound;
120 uint8_t *input = new uint8_t[h * w];
122 int output_n = out_h * MAX_SB_SIZE;
123 CONV_BUF_TYPE *output2 = new CONV_BUF_TYPE[output_n];
125 for (i = 0; i < h; ++i)
126 for (j = 0; j < w; ++j) input[i * w + j] = rnd_.Rand8();
128 int hfilter = EIGHTTAP_REGULAR, vfilter = EIGHTTAP_REGULAR;
129 int subx = 0, suby = 0;
131 InterpFilterParams filter_params_x =
132 av1_get_interp_filter_params((InterpFilter)hfilter);
133 InterpFilterParams filter_params_y =
134 av1_get_interp_filter_params((InterpFilter)vfilter);
135 const int do_average = 0;
136 ConvolveParams conv_params2 =
137 get_conv_params_no_round(0, do_average, 0, output2, MAX_SB_SIZE, 1);
138 int x;
140 aom_usec_timer timer;
141 aom_usec_timer_start(&timer);
143 for (x = 0; x < 100000; ++x)
144 test_impl(input, w, NULL, 0, out_w, out_h, &filter_params_x,
145 &filter_params_y, subx, suby, &conv_params2);
147 aom_usec_timer_mark(&timer);
148 const int elapsed_time = static_cast<int>(aom_usec_timer_elapsed(&timer));
149 printf("%d,%d convolve w: %d h: %d time: %5d ms\n", has_subx, has_suby, out_w,
150 out_h, elapsed_time / 1000);
152 delete[] input;
153 delete[] output2;
156 #if CONFIG_JNT_COMP
157 AV1JntConvolve2DTest::~AV1JntConvolve2DTest() {}
158 void AV1JntConvolve2DTest::SetUp() {
159 rnd_.Reset(ACMRandom::DeterministicSeed());
162 void AV1JntConvolve2DTest::TearDown() { libaom_test::ClearSystemState(); }
164 void AV1JntConvolve2DTest::RunCheckOutput(convolve_2d_func test_impl) {
165 const int w = 128, h = 128;
166 const int out_w = GET_PARAM(0), out_h = GET_PARAM(1);
167 int i, j, k, l, m;
168 const int has_subx = GET_PARAM(3);
169 const int has_suby = GET_PARAM(4);
170 const int is_compound = GET_PARAM(5);
171 (void)is_compound;
173 uint8_t *input = new uint8_t[h * w];
175 int output_n = out_h * MAX_SB_SIZE;
176 CONV_BUF_TYPE *output = new CONV_BUF_TYPE[output_n];
177 CONV_BUF_TYPE *output2 = new CONV_BUF_TYPE[output_n];
179 for (i = 0; i < h; ++i)
180 for (j = 0; j < w; ++j) input[i * w + j] = rnd_.Rand8();
182 int hfilter, vfilter, subx, suby;
183 for (hfilter = EIGHTTAP_REGULAR; hfilter < INTERP_FILTERS_ALL; ++hfilter) {
184 for (vfilter = EIGHTTAP_REGULAR; vfilter < INTERP_FILTERS_ALL; ++vfilter) {
185 InterpFilterParams filter_params_x =
186 av1_get_interp_filter_params((InterpFilter)hfilter);
187 InterpFilterParams filter_params_y =
188 av1_get_interp_filter_params((InterpFilter)vfilter);
189 const int do_average = rnd_.Rand8() & 1;
190 ConvolveParams conv_params1 =
191 get_conv_params_no_round(0, do_average, 0, output, MAX_SB_SIZE, 1);
192 ConvolveParams conv_params2 =
193 get_conv_params_no_round(0, do_average, 0, output2, MAX_SB_SIZE, 1);
195 // Test special case where jnt_comp_avg is not used
196 conv_params1.use_jnt_comp_avg = 0;
197 conv_params2.use_jnt_comp_avg = 0;
199 const int subx_range = has_subx ? 16 : 1;
200 const int suby_range = has_suby ? 16 : 1;
201 for (subx = 0; subx < subx_range; ++subx)
202 for (suby = 0; suby < suby_range; ++suby) {
203 // av1_convolve_2d is designed for accumulate two predicted blocks
204 // for compound mode, so we set num_iter to two here.
205 // A larger number may introduce overflow
206 const int num_iters = 2;
207 memset(output, 0, output_n * sizeof(*output));
208 memset(output2, 0, output_n * sizeof(*output2));
209 for (i = 0; i < num_iters; ++i) {
210 // Choose random locations within the source block
211 int offset_r = 3 + rnd_.PseudoUniform(h - out_h - 7);
212 int offset_c = 3 + rnd_.PseudoUniform(w - out_w - 7);
213 av1_jnt_convolve_2d_c(input + offset_r * w + offset_c, w, NULL, 0,
214 out_w, out_h, &filter_params_x,
215 &filter_params_y, subx, suby, &conv_params1);
216 test_impl(input + offset_r * w + offset_c, w, NULL, 0, out_w, out_h,
217 &filter_params_x, &filter_params_y, subx, suby,
218 &conv_params2);
220 for (j = 0; j < out_h; ++j)
221 for (k = 0; k < out_w; ++k) {
222 int idx = j * MAX_SB_SIZE + k;
223 ASSERT_EQ(output[idx], output2[idx])
224 << "Mismatch at unit tests for av1_jnt_convolve_2d\n"
225 << "Pixel mismatch at index " << idx << " = (" << j << ", "
226 << k << "), sub pixel offset = (" << suby << ", " << subx
227 << ")";
232 // Test different combination of fwd and bck offset weights
233 for (l = 0; l < 2; ++l) {
234 for (m = 0; m < 4; ++m) {
235 conv_params1.use_jnt_comp_avg = 1;
236 conv_params2.use_jnt_comp_avg = 1;
237 conv_params1.fwd_offset = quant_dist_lookup_table[l][m][0];
238 conv_params1.bck_offset = quant_dist_lookup_table[l][m][1];
239 conv_params2.fwd_offset = quant_dist_lookup_table[l][m][0];
240 conv_params2.bck_offset = quant_dist_lookup_table[l][m][1];
242 for (subx = 0; subx < subx_range; ++subx)
243 for (suby = 0; suby < suby_range; ++suby) {
244 // av1_convolve_2d is designed for accumulate two predicted blocks
245 // for compound mode, so we set num_iter to two here.
246 // A larger number may introduce overflow
247 const int num_iters = 2;
248 memset(output, 0, output_n * sizeof(*output));
249 memset(output2, 0, output_n * sizeof(*output2));
250 for (i = 0; i < num_iters; ++i) {
251 // Choose random locations within the source block
252 int offset_r = 3 + rnd_.PseudoUniform(h - out_h - 7);
253 int offset_c = 3 + rnd_.PseudoUniform(w - out_w - 7);
254 av1_jnt_convolve_2d_c(input + offset_r * w + offset_c, w, NULL,
255 0, out_w, out_h, &filter_params_x,
256 &filter_params_y, subx, suby,
257 &conv_params1);
258 test_impl(input + offset_r * w + offset_c, w, NULL, 0, out_w,
259 out_h, &filter_params_x, &filter_params_y, subx, suby,
260 &conv_params2);
262 for (j = 0; j < out_h; ++j)
263 for (k = 0; k < out_w; ++k) {
264 int idx = j * MAX_SB_SIZE + k;
265 ASSERT_EQ(output[idx], output2[idx])
266 << "Mismatch at unit tests for av1_jnt_convolve_2d\n"
267 << "Pixel mismatch at index " << idx << " = (" << j
268 << ", " << k << "), sub pixel offset = (" << suby
269 << ", " << subx << ")";
277 delete[] input;
278 delete[] output;
279 delete[] output2;
281 #endif // CONFIG_JNT_COMP
282 } // namespace AV1Convolve2D
284 namespace AV1HighbdConvolve2D {
286 ::testing::internal::ParamGenerator<HighbdConvolve2DParam> BuildParams(
287 highbd_convolve_2d_func filter) {
288 const HighbdConvolve2DParam params[] = {
289 make_tuple(4, 4, 8, filter), make_tuple(8, 8, 8, filter),
290 make_tuple(64, 64, 8, filter), make_tuple(4, 16, 8, filter),
291 make_tuple(32, 8, 8, filter), make_tuple(4, 4, 10, filter),
292 make_tuple(8, 8, 10, filter), make_tuple(64, 64, 10, filter),
293 make_tuple(4, 16, 10, filter), make_tuple(32, 8, 10, filter),
294 make_tuple(4, 4, 12, filter), make_tuple(8, 8, 12, filter),
295 make_tuple(64, 64, 12, filter), make_tuple(4, 16, 12, filter),
296 make_tuple(32, 8, 12, filter),
298 return ::testing::ValuesIn(params);
301 AV1HighbdConvolve2DTest::~AV1HighbdConvolve2DTest() {}
302 void AV1HighbdConvolve2DTest::SetUp() {
303 rnd_.Reset(ACMRandom::DeterministicSeed());
306 void AV1HighbdConvolve2DTest::TearDown() { libaom_test::ClearSystemState(); }
308 void AV1HighbdConvolve2DTest::RunCheckOutput(
309 highbd_convolve_2d_func test_impl) {
310 const int w = 128, h = 128;
311 const int out_w = GET_PARAM(0), out_h = GET_PARAM(1);
312 const int bd = GET_PARAM(2);
313 int i, j, k;
315 uint16_t *input = new uint16_t[h * w];
317 int output_n = out_h * MAX_SB_SIZE;
318 CONV_BUF_TYPE *output = new CONV_BUF_TYPE[output_n];
319 CONV_BUF_TYPE *output2 = new CONV_BUF_TYPE[output_n];
321 for (i = 0; i < h; ++i)
322 for (j = 0; j < w; ++j) input[i * w + j] = rnd_.Rand16() & ((1 << bd) - 1);
324 int hfilter, vfilter, subx, suby;
325 for (hfilter = EIGHTTAP_REGULAR; hfilter < INTERP_FILTERS_ALL; ++hfilter) {
326 for (vfilter = EIGHTTAP_REGULAR; vfilter < INTERP_FILTERS_ALL; ++vfilter) {
327 InterpFilterParams filter_params_x =
328 av1_get_interp_filter_params((InterpFilter)hfilter);
329 InterpFilterParams filter_params_y =
330 av1_get_interp_filter_params((InterpFilter)vfilter);
331 ConvolveParams conv_params1 =
332 get_conv_params_no_round(0, 0, 0, output, MAX_SB_SIZE, 1);
333 ConvolveParams conv_params2 =
334 get_conv_params_no_round(0, 0, 0, output2, MAX_SB_SIZE, 1);
336 for (subx = 0; subx < 16; ++subx)
337 for (suby = 0; suby < 16; ++suby) {
338 // av1_convolve_2d is designed for accumulate two predicted blocks for
339 // compound mode, so we set num_iter to two here.
340 // A larger number may introduce overflow
341 const int num_iters = 2;
342 memset(output, 0, output_n * sizeof(*output));
343 memset(output2, 0, output_n * sizeof(*output2));
344 for (i = 0; i < num_iters; ++i) {
345 // Choose random locations within the source block
346 int offset_r = 3 + rnd_.PseudoUniform(h - out_h - 7);
347 int offset_c = 3 + rnd_.PseudoUniform(w - out_w - 7);
348 av1_highbd_convolve_2d_c(input + offset_r * w + offset_c, w, output,
349 MAX_SB_SIZE, out_w, out_h,
350 &filter_params_x, &filter_params_y, subx,
351 suby, &conv_params1, bd);
352 test_impl(input + offset_r * w + offset_c, w, output2, MAX_SB_SIZE,
353 out_w, out_h, &filter_params_x, &filter_params_y, subx,
354 suby, &conv_params2, bd);
356 for (j = 0; j < out_h; ++j)
357 for (k = 0; k < out_w; ++k) {
358 int idx = j * MAX_SB_SIZE + k;
359 ASSERT_EQ(output[idx], output2[idx])
360 << "Pixel mismatch at index " << idx << " = (" << j << ", "
361 << k << "), sub pixel offset = (" << suby << ", " << subx
362 << ")";
368 delete[] input;
369 delete[] output;
370 delete[] output2;
372 #if CONFIG_JNT_COMP
373 AV1HighbdJntConvolve2DTest::~AV1HighbdJntConvolve2DTest() {}
374 void AV1HighbdJntConvolve2DTest::SetUp() {
375 rnd_.Reset(ACMRandom::DeterministicSeed());
378 void AV1HighbdJntConvolve2DTest::TearDown() { libaom_test::ClearSystemState(); }
380 void AV1HighbdJntConvolve2DTest::RunCheckOutput(
381 highbd_convolve_2d_func test_impl) {
382 const int w = 128, h = 128;
383 const int out_w = GET_PARAM(0), out_h = GET_PARAM(1);
384 const int bd = GET_PARAM(2);
385 int i, j, k, l, m;
387 uint16_t *input = new uint16_t[h * w];
389 int output_n = out_h * MAX_SB_SIZE;
390 CONV_BUF_TYPE *output = new CONV_BUF_TYPE[output_n];
391 CONV_BUF_TYPE *output2 = new CONV_BUF_TYPE[output_n];
393 for (i = 0; i < h; ++i)
394 for (j = 0; j < w; ++j) input[i * w + j] = rnd_.Rand16() & ((1 << bd) - 1);
396 int hfilter, vfilter, subx, suby;
397 for (hfilter = EIGHTTAP_REGULAR; hfilter < INTERP_FILTERS_ALL; ++hfilter) {
398 for (vfilter = EIGHTTAP_REGULAR; vfilter < INTERP_FILTERS_ALL; ++vfilter) {
399 InterpFilterParams filter_params_x =
400 av1_get_interp_filter_params((InterpFilter)hfilter);
401 InterpFilterParams filter_params_y =
402 av1_get_interp_filter_params((InterpFilter)vfilter);
403 ConvolveParams conv_params1 =
404 get_conv_params_no_round(0, 0, 0, output, MAX_SB_SIZE, 1);
405 ConvolveParams conv_params2 =
406 get_conv_params_no_round(0, 0, 0, output2, MAX_SB_SIZE, 1);
408 // Test special case where jnt_comp_avg is not used
409 conv_params1.use_jnt_comp_avg = 0;
410 conv_params2.use_jnt_comp_avg = 0;
412 for (subx = 0; subx < 16; ++subx)
413 for (suby = 0; suby < 16; ++suby) {
414 // av1_convolve_2d is designed for accumulate two predicted blocks for
415 // compound mode, so we set num_iter to two here.
416 // A larger number may introduce overflow
417 const int num_iters = 2;
418 memset(output, 0, output_n * sizeof(*output));
419 memset(output2, 0, output_n * sizeof(*output2));
420 for (i = 0; i < num_iters; ++i) {
421 // Choose random locations within the source block
422 int offset_r = 3 + rnd_.PseudoUniform(h - out_h - 7);
423 int offset_c = 3 + rnd_.PseudoUniform(w - out_w - 7);
424 av1_highbd_jnt_convolve_2d_c(input + offset_r * w + offset_c, w,
425 output, MAX_SB_SIZE, out_w, out_h,
426 &filter_params_x, &filter_params_y,
427 subx, suby, &conv_params1, bd);
428 test_impl(input + offset_r * w + offset_c, w, output2, MAX_SB_SIZE,
429 out_w, out_h, &filter_params_x, &filter_params_y, subx,
430 suby, &conv_params2, bd);
432 for (j = 0; j < out_h; ++j)
433 for (k = 0; k < out_w; ++k) {
434 int idx = j * MAX_SB_SIZE + k;
435 ASSERT_EQ(output[idx], output2[idx])
436 << "Pixel mismatch at index " << idx << " = (" << j << ", "
437 << k << "), sub pixel offset = (" << suby << ", " << subx
438 << ")";
443 // Test different combination of fwd and bck offset weights
444 for (l = 0; l < 2; ++l) {
445 for (m = 0; m < 4; ++m) {
446 conv_params1.use_jnt_comp_avg = 1;
447 conv_params2.use_jnt_comp_avg = 1;
448 conv_params1.fwd_offset = quant_dist_lookup_table[l][m][0];
449 conv_params1.bck_offset = quant_dist_lookup_table[l][m][1];
450 conv_params2.fwd_offset = quant_dist_lookup_table[l][m][0];
451 conv_params2.bck_offset = quant_dist_lookup_table[l][m][1];
453 for (subx = 0; subx < 16; ++subx)
454 for (suby = 0; suby < 16; ++suby) {
455 // av1_convolve_2d is designed for accumulate two predicted blocks
456 // for compound mode, so we set num_iter to two here.
457 // A larger number may introduce overflow
458 const int num_iters = 2;
459 memset(output, 0, output_n * sizeof(*output));
460 memset(output2, 0, output_n * sizeof(*output2));
461 for (i = 0; i < num_iters; ++i) {
462 // Choose random locations within the source block
463 int offset_r = 3 + rnd_.PseudoUniform(h - out_h - 7);
464 int offset_c = 3 + rnd_.PseudoUniform(w - out_w - 7);
465 av1_highbd_jnt_convolve_2d_c(input + offset_r * w + offset_c, w,
466 output, MAX_SB_SIZE, out_w, out_h,
467 &filter_params_x, &filter_params_y,
468 subx, suby, &conv_params1, bd);
469 test_impl(input + offset_r * w + offset_c, w, output2,
470 MAX_SB_SIZE, out_w, out_h, &filter_params_x,
471 &filter_params_y, subx, suby, &conv_params2, bd);
473 for (j = 0; j < out_h; ++j)
474 for (k = 0; k < out_w; ++k) {
475 int idx = j * MAX_SB_SIZE + k;
476 ASSERT_EQ(output[idx], output2[idx])
477 << "Mismatch at unit tests for av1_jnt_convolve_2d\n"
478 << "Pixel mismatch at index " << idx << " = (" << j
479 << ", " << k << "), sub pixel offset = (" << suby
480 << ", " << subx << ")";
488 delete[] input;
489 delete[] output;
490 delete[] output2;
492 #endif // CONFIG_JNT_COMP
493 } // namespace AV1HighbdConvolve2D
494 } // namespace libaom_test