av1_convolve_2d_test_util.cc 24.7 KB
Newer Older
David Barker's avatar
David Barker committed
1 2 3 4 5 6 7 8 9 10 11 12 13
/*
 * 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 "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"
David Barker's avatar
David Barker committed
17 18

using std::tr1::make_tuple;
Johann's avatar
Johann committed
19
using std::tr1::tuple;
David Barker's avatar
David Barker committed
20 21 22

namespace libaom_test {

23 24
const int kMaxSize = 128 + 32;  // padding

David Barker's avatar
David Barker committed
25 26 27
namespace AV1Convolve2D {

::testing::internal::ParamGenerator<Convolve2DParam> BuildParams(
28
    convolve_2d_func filter, int has_subx, int has_suby, int is_compound) {
29
  return ::testing::Values(make_tuple(filter, has_subx, has_suby, is_compound));
David Barker's avatar
David Barker committed
30 31 32 33 34 35 36 37
}

AV1Convolve2DTest::~AV1Convolve2DTest() {}
void AV1Convolve2DTest::SetUp() { rnd_.Reset(ACMRandom::DeterministicSeed()); }

void AV1Convolve2DTest::TearDown() { libaom_test::ClearSystemState(); }

void AV1Convolve2DTest::RunCheckOutput(convolve_2d_func test_impl) {
38 39 40 41 42 43 44 45
  const int w = kMaxSize, h = kMaxSize;
  const int has_subx = GET_PARAM(1);
  const int has_suby = GET_PARAM(2);
  const int is_compound = GET_PARAM(3);
  int hfilter, vfilter, subx, suby;
  uint8_t input[kMaxSize * kMaxSize];
  DECLARE_ALIGNED(32, CONV_BUF_TYPE, output[MAX_SB_SQUARE]);
  DECLARE_ALIGNED(32, CONV_BUF_TYPE, output2[MAX_SB_SQUARE]);
David Barker's avatar
David Barker committed
46

47
  (void)is_compound;
David Barker's avatar
David Barker committed
48

49 50 51 52
  for (int i = 0; i < h; ++i)
    for (int j = 0; j < w; ++j) input[i * w + j] = rnd_.Rand8();
  for (int i = 0; i < MAX_SB_SQUARE; ++i)
    output[i] = output2[i] = rnd_.Rand31();
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

  for (int block_idx = BLOCK_4X4; block_idx < BLOCK_SIZES_ALL; ++block_idx) {
    const int out_w = block_size_wide[block_idx];
    const int out_h = block_size_high[block_idx];
    for (hfilter = EIGHTTAP_REGULAR; hfilter < INTERP_FILTERS_ALL; ++hfilter) {
      for (vfilter = EIGHTTAP_REGULAR; vfilter < INTERP_FILTERS_ALL;
           ++vfilter) {
        InterpFilterParams filter_params_x =
            av1_get_interp_filter_params((InterpFilter)hfilter);
        InterpFilterParams filter_params_y =
            av1_get_interp_filter_params((InterpFilter)vfilter);
        for (int do_average = 0; do_average <= 1; ++do_average) {
          ConvolveParams conv_params1 = get_conv_params_no_round(
              0, do_average, 0, output, MAX_SB_SIZE, 1);
          ConvolveParams conv_params2 = get_conv_params_no_round(
              0, do_average, 0, output2, MAX_SB_SIZE, 1);

          const int subx_range = has_subx ? 16 : 1;
          const int suby_range = has_suby ? 16 : 1;
          for (subx = 0; subx < subx_range; ++subx) {
            for (suby = 0; suby < suby_range; ++suby) {
              // Choose random locations within the source block
              const int offset_r = 3 + rnd_.PseudoUniform(h - out_h - 7);
              const int offset_c = 3 + rnd_.PseudoUniform(w - out_w - 7);
              av1_convolve_2d_c(input + offset_r * w + offset_c, w, NULL, 0,
                                out_w, out_h, &filter_params_x,
                                &filter_params_y, subx, suby, &conv_params1);
              test_impl(input + offset_r * w + offset_c, w, NULL, 0, out_w,
                        out_h, &filter_params_x, &filter_params_y, subx, suby,
                        &conv_params2);

84 85
              for (int i = 0; i < out_h; ++i) {
                for (int j = 0; j < out_w; ++j) {
86 87 88 89 90 91 92
                  int idx = i * MAX_SB_SIZE + j;
                  ASSERT_EQ(output[idx], output2[idx])
                      << out_w << "x" << out_h << " Pixel mismatch at index "
                      << idx << " = (" << i << ", " << j
                      << "), sub pixel offset = (" << suby << ", " << subx
                      << ")";
                }
David Barker's avatar
David Barker committed
93
              }
94
            }
David Barker's avatar
David Barker committed
95 96
          }
        }
97
      }
David Barker's avatar
David Barker committed
98 99 100
    }
  }
}
101

102
void AV1Convolve2DTest::RunSpeedTest(convolve_2d_func test_impl) {
103 104 105 106
  const int w = kMaxSize, h = kMaxSize;
  const int has_subx = GET_PARAM(1);
  const int has_suby = GET_PARAM(2);
  const int is_compound = GET_PARAM(3);
107 108
  (void)is_compound;

109 110
  uint8_t input[kMaxSize * kMaxSize];
  DECLARE_ALIGNED(32, CONV_BUF_TYPE, output[MAX_SB_SQUARE]);
111

112 113
  for (int i = 0; i < h; ++i)
    for (int j = 0; j < w; ++j) input[i * w + j] = rnd_.Rand8();
114 115 116 117 118 119 120 121 122 123

  int hfilter = EIGHTTAP_REGULAR, vfilter = EIGHTTAP_REGULAR;
  int subx = 0, suby = 0;

  InterpFilterParams filter_params_x =
      av1_get_interp_filter_params((InterpFilter)hfilter);
  InterpFilterParams filter_params_y =
      av1_get_interp_filter_params((InterpFilter)vfilter);
  const int do_average = 0;
  ConvolveParams conv_params2 =
124 125 126 127 128 129 130 131 132
      get_conv_params_no_round(0, do_average, 0, output, MAX_SB_SIZE, 1);

  for (int block_idx = BLOCK_4X4; block_idx < BLOCK_SIZES_ALL; ++block_idx) {
    const int out_w = block_size_wide[block_idx];
    const int out_h = block_size_high[block_idx];
    const int num_loops = 1000000000 / (out_w + out_h);
    aom_usec_timer timer;
    aom_usec_timer_start(&timer);

133
    for (int i = 0; i < num_loops; ++i)
134 135 136 137 138 139 140 141
      test_impl(input, w, NULL, 0, out_w, out_h, &filter_params_x,
                &filter_params_y, subx, suby, &conv_params2);

    aom_usec_timer_mark(&timer);
    const int elapsed_time = static_cast<int>(aom_usec_timer_elapsed(&timer));
    printf("%d,%d convolve %3dx%-3d: %7.2f ns\n", has_subx, has_suby, out_w,
           out_h, 1000.0 * elapsed_time / num_loops);
  }
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
AV1Convolve2DSrTest::~AV1Convolve2DSrTest() {}
void AV1Convolve2DSrTest::SetUp() {
  rnd_.Reset(ACMRandom::DeterministicSeed());
}

void AV1Convolve2DSrTest::TearDown() { libaom_test::ClearSystemState(); }

void AV1Convolve2DSrTest::RunCheckOutput(convolve_2d_func test_impl) {
  const int w = kMaxSize, h = kMaxSize;
  const int has_subx = GET_PARAM(1);
  const int has_suby = GET_PARAM(2);
  const int is_compound = GET_PARAM(3);
  int hfilter, vfilter, subx, suby;
  uint8_t input[kMaxSize * kMaxSize];
  DECLARE_ALIGNED(32, uint8_t, output[MAX_SB_SQUARE]);
  DECLARE_ALIGNED(32, uint8_t, output2[MAX_SB_SQUARE]);

  (void)is_compound;

  for (int i = 0; i < h; ++i)
    for (int j = 0; j < w; ++j) input[i * w + j] = rnd_.Rand8();
  for (int i = 0; i < MAX_SB_SQUARE; ++i)
    output[i] = output2[i] = rnd_.Rand31();

  for (int block_idx = BLOCK_4X4; block_idx < BLOCK_SIZES_ALL; ++block_idx) {
    // Make sure that sizes 2xN and Nx2 are also tested for chroma.
    const int num_sizes =
        (block_size_wide[block_idx] == 4 || block_size_high[block_idx] == 4)
            ? 2
            : 1;
    for (int shift = 0; shift < num_sizes; ++shift) {  // luma and chroma
      const int out_w = block_size_wide[block_idx] >> shift;
      const int out_h = block_size_high[block_idx] >> shift;
      for (hfilter = EIGHTTAP_REGULAR; hfilter < INTERP_FILTERS_ALL;
           ++hfilter) {
        for (vfilter = EIGHTTAP_REGULAR; vfilter < INTERP_FILTERS_ALL;
             ++vfilter) {
          InterpFilterParams filter_params_x =
              av1_get_interp_filter_params((InterpFilter)hfilter);
          InterpFilterParams filter_params_y =
              av1_get_interp_filter_params((InterpFilter)vfilter);
          for (int do_average = 0; do_average <= 1; ++do_average) {
            ConvolveParams conv_params1 =
                get_conv_params_no_round(0, do_average, 0, NULL, 0, 1);
            ConvolveParams conv_params2 =
                get_conv_params_no_round(0, do_average, 0, NULL, 0, 1);

            const int subx_range = has_subx ? 16 : 1;
            const int suby_range = has_suby ? 16 : 1;
            for (subx = 0; subx < subx_range; ++subx) {
              for (suby = 0; suby < suby_range; ++suby) {
                // Choose random locations within the source block
                const int offset_r = 3 + rnd_.PseudoUniform(h - out_h - 7);
                const int offset_c = 3 + rnd_.PseudoUniform(w - out_w - 7);
                av1_convolve_2d_sr_c(input + offset_r * w + offset_c, w, output,
                                     MAX_SB_SIZE, out_w, out_h,
                                     &filter_params_x, &filter_params_y, subx,
                                     suby, &conv_params1);
                test_impl(input + offset_r * w + offset_c, w, output2,
                          MAX_SB_SIZE, out_w, out_h, &filter_params_x,
                          &filter_params_y, subx, suby, &conv_params2);

                if (memcmp(output, output2, sizeof(output))) {
                  for (int i = 0; i < MAX_SB_SIZE; ++i) {
                    for (int j = 0; j < MAX_SB_SIZE; ++j) {
                      int idx = i * MAX_SB_SIZE + j;
                      ASSERT_EQ(output[idx], output2[idx])
                          << out_w << "x" << out_h
                          << " Pixel mismatch at index " << idx << " = (" << i
                          << ", " << j << "), sub pixel offset = (" << suby
                          << ", " << subx << ")";
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

void AV1Convolve2DSrTest::RunSpeedTest(convolve_2d_func test_impl) {
  const int w = kMaxSize, h = kMaxSize;
  const int has_subx = GET_PARAM(1);
  const int has_suby = GET_PARAM(2);
  const int is_compound = GET_PARAM(3);
  (void)is_compound;

  uint8_t input[kMaxSize * kMaxSize];
  DECLARE_ALIGNED(32, uint8_t, output[MAX_SB_SQUARE]);

  for (int i = 0; i < h; ++i)
    for (int j = 0; j < w; ++j) input[i * w + j] = rnd_.Rand8();

  int hfilter = EIGHTTAP_REGULAR, vfilter = EIGHTTAP_REGULAR;
  int subx = 0, suby = 0;

  InterpFilterParams filter_params_x =
      av1_get_interp_filter_params((InterpFilter)hfilter);
  InterpFilterParams filter_params_y =
      av1_get_interp_filter_params((InterpFilter)vfilter);
  const int do_average = 0;
  ConvolveParams conv_params2 =
      get_conv_params_no_round(0, do_average, 0, NULL, 0, 1);

  for (int block_idx = BLOCK_4X4; block_idx < BLOCK_SIZES_ALL; ++block_idx) {
    // Make sure that sizes 2xN and Nx2 are also tested for chroma.
    const int num_sizes =
        (block_size_wide[block_idx] == 4 || block_size_high[block_idx] == 4)
            ? 2
            : 1;
    for (int shift = 0; shift < num_sizes; ++shift) {  // luma and chroma
      const int out_w = block_size_wide[block_idx] >> shift;
      const int out_h = block_size_high[block_idx] >> shift;
      const int num_loops = 1000000000 / (out_w + out_h);
      aom_usec_timer timer;
      aom_usec_timer_start(&timer);

      for (int i = 0; i < num_loops; ++i)
        test_impl(input, w, output, MAX_SB_SIZE, out_w, out_h, &filter_params_x,
                  &filter_params_y, subx, suby, &conv_params2);

      aom_usec_timer_mark(&timer);
      const int elapsed_time = static_cast<int>(aom_usec_timer_elapsed(&timer));
      printf("%d,%d convolve %3dx%-3d: %7.2f ns\n", has_subx, has_suby, out_w,
             out_h, 1000.0 * elapsed_time / num_loops);
    }
  }
}

276
#if CONFIG_JNT_COMP
277 278 279 280 281 282 283 284
AV1JntConvolve2DTest::~AV1JntConvolve2DTest() {}
void AV1JntConvolve2DTest::SetUp() {
  rnd_.Reset(ACMRandom::DeterministicSeed());
}

void AV1JntConvolve2DTest::TearDown() { libaom_test::ClearSystemState(); }

void AV1JntConvolve2DTest::RunCheckOutput(convolve_2d_func test_impl) {
285 286 287 288 289 290 291 292
  const int w = kMaxSize, h = kMaxSize;
  const int has_subx = GET_PARAM(1);
  const int has_suby = GET_PARAM(2);
  const int is_compound = GET_PARAM(3);
  int hfilter, vfilter, subx, suby;
  uint8_t input[kMaxSize * kMaxSize];
  DECLARE_ALIGNED(32, CONV_BUF_TYPE, output[MAX_SB_SQUARE]);
  DECLARE_ALIGNED(32, CONV_BUF_TYPE, output2[MAX_SB_SQUARE]);
293

294
  (void)is_compound;
295

296 297 298 299
  for (int i = 0; i < h; ++i)
    for (int j = 0; j < w; ++j) input[i * w + j] = rnd_.Rand8();
  for (int i = 0; i < MAX_SB_SQUARE; ++i)
    output[i] = output2[i] = rnd_.Rand31();
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

  for (int block_idx = BLOCK_4X4; block_idx < BLOCK_SIZES_ALL; ++block_idx) {
    const int out_w = block_size_wide[block_idx];
    const int out_h = block_size_high[block_idx];
    for (hfilter = EIGHTTAP_REGULAR; hfilter < INTERP_FILTERS_ALL; ++hfilter) {
      for (vfilter = EIGHTTAP_REGULAR; vfilter < INTERP_FILTERS_ALL;
           ++vfilter) {
        InterpFilterParams filter_params_x =
            av1_get_interp_filter_params((InterpFilter)hfilter);
        InterpFilterParams filter_params_y =
            av1_get_interp_filter_params((InterpFilter)vfilter);
        for (int do_average = 0; do_average <= 1; ++do_average) {
          ConvolveParams conv_params1 = get_conv_params_no_round(
              0, do_average, 0, output, MAX_SB_SIZE, 1);
          ConvolveParams conv_params2 = get_conv_params_no_round(
              0, do_average, 0, output2, MAX_SB_SIZE, 1);

          // Test special case where jnt_comp_avg is not used
          conv_params1.use_jnt_comp_avg = 0;
          conv_params2.use_jnt_comp_avg = 0;

          const int subx_range = has_subx ? 16 : 1;
          const int suby_range = has_suby ? 16 : 1;
          for (subx = 0; subx < subx_range; ++subx) {
            for (suby = 0; suby < suby_range; ++suby) {
              // Choose random locations within the source block
              const int offset_r = 3 + rnd_.PseudoUniform(h - out_h - 7);
              const int offset_c = 3 + rnd_.PseudoUniform(w - out_w - 7);
              av1_jnt_convolve_2d_c(input + offset_r * w + offset_c, w, NULL, 0,
                                    out_w, out_h, &filter_params_x,
                                    &filter_params_y, subx, suby,
                                    &conv_params1);
              test_impl(input + offset_r * w + offset_c, w, NULL, 0, out_w,
                        out_h, &filter_params_x, &filter_params_y, subx, suby,
                        &conv_params2);

336 337
              for (int i = 0; i < out_h; ++i) {
                for (int j = 0; j < out_w; ++j) {
338 339 340 341 342 343 344 345
                  int idx = i * MAX_SB_SIZE + j;
                  ASSERT_EQ(output[idx], output2[idx])
                      << "Mismatch at unit tests for av1_jnt_convolve_2d\n"
                      << out_w << "x" << out_h << " Pixel mismatch at index "
                      << idx << " = (" << i << ", " << j
                      << "), sub pixel offset = (" << suby << ", " << subx
                      << ")";
                }
346
              }
347
            }
348 349
          }

350
          // Test different combination of fwd and bck offset weights
351 352
          for (int k = 0; k < 2; ++k) {
            for (int l = 0; l < 4; ++l) {
353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372
              conv_params1.use_jnt_comp_avg = 1;
              conv_params2.use_jnt_comp_avg = 1;
              conv_params1.fwd_offset = quant_dist_lookup_table[k][l][0];
              conv_params1.bck_offset = quant_dist_lookup_table[k][l][1];
              conv_params2.fwd_offset = quant_dist_lookup_table[k][l][0];
              conv_params2.bck_offset = quant_dist_lookup_table[k][l][1];

              for (subx = 0; subx < subx_range; ++subx) {
                for (suby = 0; suby < suby_range; ++suby) {
                  // Choose random locations within the source block
                  const int offset_r = 3 + rnd_.PseudoUniform(h - out_h - 7);
                  const int offset_c = 3 + rnd_.PseudoUniform(w - out_w - 7);
                  av1_jnt_convolve_2d_c(input + offset_r * w + offset_c, w,
                                        NULL, 0, out_w, out_h, &filter_params_x,
                                        &filter_params_y, subx, suby,
                                        &conv_params1);
                  test_impl(input + offset_r * w + offset_c, w, NULL, 0, out_w,
                            out_h, &filter_params_x, &filter_params_y, subx,
                            suby, &conv_params2);

373 374
                  for (int i = 0; i < out_h; ++i) {
                    for (int j = 0; j < out_w; ++j) {
375 376 377 378 379 380 381 382 383
                      int idx = i * MAX_SB_SIZE + j;
                      ASSERT_EQ(output[idx], output2[idx])
                          << "Mismatch at unit tests for "
                             "av1_jnt_convolve_2d\n"
                          << out_w << "x" << out_h
                          << " Pixel mismatch at index " << idx << " = (" << i
                          << ", " << j << "), sub pixel offset = (" << suby
                          << ", " << subx << ")";
                    }
384
                  }
385
                }
386 387
              }
            }
388
          }
389 390 391 392 393 394
        }
      }
    }
  }
}
#endif  // CONFIG_JNT_COMP
David Barker's avatar
David Barker committed
395 396 397 398 399 400
}  // namespace AV1Convolve2D

namespace AV1HighbdConvolve2D {

::testing::internal::ParamGenerator<HighbdConvolve2DParam> BuildParams(
    highbd_convolve_2d_func filter) {
401 402
  return ::testing::Values(make_tuple(8, filter), make_tuple(10, filter),
                           make_tuple(12, filter));
David Barker's avatar
David Barker committed
403 404 405 406 407 408 409 410 411 412 413
}

AV1HighbdConvolve2DTest::~AV1HighbdConvolve2DTest() {}
void AV1HighbdConvolve2DTest::SetUp() {
  rnd_.Reset(ACMRandom::DeterministicSeed());
}

void AV1HighbdConvolve2DTest::TearDown() { libaom_test::ClearSystemState(); }

void AV1HighbdConvolve2DTest::RunCheckOutput(
    highbd_convolve_2d_func test_impl) {
414 415 416 417 418 419
  const int w = kMaxSize, h = kMaxSize;
  const int bd = GET_PARAM(0);
  int hfilter, vfilter, subx, suby;
  uint16_t input[kMaxSize * kMaxSize];
  DECLARE_ALIGNED(32, CONV_BUF_TYPE, output[MAX_SB_SQUARE]);
  DECLARE_ALIGNED(32, CONV_BUF_TYPE, output2[MAX_SB_SQUARE]);
David Barker's avatar
David Barker committed
420

421 422 423 424 425
  for (int i = 0; i < h; ++i)
    for (int j = 0; j < w; ++j)
      input[i * w + j] = rnd_.Rand16() & ((1 << bd) - 1);
  for (int i = 0; i < MAX_SB_SQUARE; ++i)
    output[i] = output2[i] = rnd_.Rand31();
426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455

  for (int block_idx = BLOCK_4X4; block_idx < BLOCK_SIZES_ALL; ++block_idx) {
    const int out_w = block_size_wide[block_idx];
    const int out_h = block_size_high[block_idx];
    for (hfilter = EIGHTTAP_REGULAR; hfilter < INTERP_FILTERS_ALL; ++hfilter) {
      for (vfilter = EIGHTTAP_REGULAR; vfilter < INTERP_FILTERS_ALL;
           ++vfilter) {
        InterpFilterParams filter_params_x =
            av1_get_interp_filter_params((InterpFilter)hfilter);
        InterpFilterParams filter_params_y =
            av1_get_interp_filter_params((InterpFilter)vfilter);
        for (int do_average = 0; do_average <= 1; ++do_average) {
          ConvolveParams conv_params1 = get_conv_params_no_round(
              0, do_average, 0, output, MAX_SB_SIZE, 1);
          ConvolveParams conv_params2 = get_conv_params_no_round(
              0, do_average, 0, output2, MAX_SB_SIZE, 1);

          for (subx = 0; subx < 16; ++subx) {
            for (suby = 0; suby < 16; ++suby) {
              // Choose random locations within the source block
              const int offset_r = 3 + rnd_.PseudoUniform(h - out_h - 7);
              const int offset_c = 3 + rnd_.PseudoUniform(w - out_w - 7);
              av1_highbd_convolve_2d_c(input + offset_r * w + offset_c, w,
                                       output, MAX_SB_SIZE, out_w, out_h,
                                       &filter_params_x, &filter_params_y, subx,
                                       suby, &conv_params1, bd);
              test_impl(input + offset_r * w + offset_c, w, output2,
                        MAX_SB_SIZE, out_w, out_h, &filter_params_x,
                        &filter_params_y, subx, suby, &conv_params2, bd);

456 457
              for (int i = 0; i < out_h; ++i) {
                for (int j = 0; j < out_w; ++j) {
458 459 460 461 462 463 464
                  int idx = i * MAX_SB_SIZE + j;
                  ASSERT_EQ(output[idx], output2[idx])
                      << out_w << "x" << out_h << " Pixel mismatch at index "
                      << idx << " = (" << i << ", " << j
                      << "), sub pixel offset = (" << suby << ", " << subx
                      << ")";
                }
David Barker's avatar
David Barker committed
465
              }
466
            }
David Barker's avatar
David Barker committed
467 468
          }
        }
469
      }
David Barker's avatar
David Barker committed
470 471 472
    }
  }
}
473

474 475 476 477 478 479 480 481 482 483
#if CONFIG_JNT_COMP
AV1HighbdJntConvolve2DTest::~AV1HighbdJntConvolve2DTest() {}
void AV1HighbdJntConvolve2DTest::SetUp() {
  rnd_.Reset(ACMRandom::DeterministicSeed());
}

void AV1HighbdJntConvolve2DTest::TearDown() { libaom_test::ClearSystemState(); }

void AV1HighbdJntConvolve2DTest::RunCheckOutput(
    highbd_convolve_2d_func test_impl) {
484 485 486 487 488 489
  const int w = kMaxSize, h = kMaxSize;
  const int bd = GET_PARAM(0);
  int hfilter, vfilter, subx, suby;
  uint16_t input[kMaxSize * kMaxSize];
  DECLARE_ALIGNED(32, CONV_BUF_TYPE, output[MAX_SB_SQUARE]);
  DECLARE_ALIGNED(32, CONV_BUF_TYPE, output2[MAX_SB_SQUARE]);
490

491 492 493 494 495
  for (int i = 0; i < h; ++i)
    for (int j = 0; j < w; ++j)
      input[i * w + j] = rnd_.Rand16() & ((1 << bd) - 1);
  for (int i = 0; i < MAX_SB_SQUARE; ++i)
    output[i] = output2[i] = rnd_.Rand31();
496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529

  for (int block_idx = BLOCK_4X4; block_idx < BLOCK_SIZES_ALL; ++block_idx) {
    const int out_w = block_size_wide[block_idx];
    const int out_h = block_size_high[block_idx];
    for (hfilter = EIGHTTAP_REGULAR; hfilter < INTERP_FILTERS_ALL; ++hfilter) {
      for (vfilter = EIGHTTAP_REGULAR; vfilter < INTERP_FILTERS_ALL;
           ++vfilter) {
        InterpFilterParams filter_params_x =
            av1_get_interp_filter_params((InterpFilter)hfilter);
        InterpFilterParams filter_params_y =
            av1_get_interp_filter_params((InterpFilter)vfilter);
        for (int do_average = 0; do_average <= 1; ++do_average) {
          ConvolveParams conv_params1 = get_conv_params_no_round(
              0, do_average, 0, output, MAX_SB_SIZE, 1);
          ConvolveParams conv_params2 = get_conv_params_no_round(
              0, do_average, 0, output2, MAX_SB_SIZE, 1);

          // Test special case where jnt_comp_avg is not used
          conv_params1.use_jnt_comp_avg = 0;
          conv_params2.use_jnt_comp_avg = 0;

          for (subx = 0; subx < 16; ++subx) {
            for (suby = 0; suby < 16; ++suby) {
              // Choose random locations within the source block
              const int offset_r = 3 + rnd_.PseudoUniform(h - out_h - 7);
              const int offset_c = 3 + rnd_.PseudoUniform(w - out_w - 7);
              av1_highbd_jnt_convolve_2d_c(input + offset_r * w + offset_c, w,
                                           output, MAX_SB_SIZE, out_w, out_h,
                                           &filter_params_x, &filter_params_y,
                                           subx, suby, &conv_params1, bd);
              test_impl(input + offset_r * w + offset_c, w, output2,
                        MAX_SB_SIZE, out_w, out_h, &filter_params_x,
                        &filter_params_y, subx, suby, &conv_params2, bd);

530 531
              for (int i = 0; i < out_h; ++i) {
                for (int j = 0; j < out_w; ++j) {
532 533 534 535 536 537 538
                  int idx = i * MAX_SB_SIZE + j;
                  ASSERT_EQ(output[idx], output2[idx])
                      << out_w << "x" << out_h << " Pixel mismatch at index "
                      << idx << " = (" << i << ", " << j
                      << "), sub pixel offset = (" << suby << ", " << subx
                      << ")";
                }
539
              }
540
            }
541 542
          }

543
          // Test different combination of fwd and bck offset weights
544 545
          for (int k = 0; k < 2; ++k) {
            for (int l = 0; l < 4; ++l) {
546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565
              conv_params1.use_jnt_comp_avg = 1;
              conv_params2.use_jnt_comp_avg = 1;
              conv_params1.fwd_offset = quant_dist_lookup_table[k][l][0];
              conv_params1.bck_offset = quant_dist_lookup_table[k][l][1];
              conv_params2.fwd_offset = quant_dist_lookup_table[k][l][0];
              conv_params2.bck_offset = quant_dist_lookup_table[k][l][1];

              for (subx = 0; subx < 16; ++subx) {
                for (suby = 0; suby < 16; ++suby) {
                  // Choose random locations within the source block
                  const int offset_r = 3 + rnd_.PseudoUniform(h - out_h - 7);
                  const int offset_c = 3 + rnd_.PseudoUniform(w - out_w - 7);
                  av1_highbd_jnt_convolve_2d_c(
                      input + offset_r * w + offset_c, w, output, MAX_SB_SIZE,
                      out_w, out_h, &filter_params_x, &filter_params_y, subx,
                      suby, &conv_params1, bd);
                  test_impl(input + offset_r * w + offset_c, w, output2,
                            MAX_SB_SIZE, out_w, out_h, &filter_params_x,
                            &filter_params_y, subx, suby, &conv_params2, bd);

566 567
                  for (int i = 0; i < out_h; ++i) {
                    for (int j = 0; j < out_w; ++j) {
568 569 570 571 572 573 574
                      int idx = i * MAX_SB_SIZE + j;
                      ASSERT_EQ(output[idx], output2[idx])
                          << out_w << "x" << out_h
                          << " Pixel mismatch at index " << idx << " = (" << i
                          << ", " << j << "), sub pixel offset = (" << suby
                          << ", " << subx << ")";
                    }
575
                  }
576
                }
577 578
              }
            }
579
          }
580 581 582 583 584 585
        }
      }
    }
  }
}
#endif  // CONFIG_JNT_COMP
David Barker's avatar
David Barker committed
586 587
}  // namespace AV1HighbdConvolve2D
}  // namespace libaom_test