David Barker | ce110cc | 2017-02-22 10:38:59 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2016, Alliance for Open Media. All rights reserved |
| 3 | * |
| 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. |
| 10 | */ |
| 11 | |
| 12 | #include <ctime> |
| 13 | |
| 14 | #include "third_party/googletest/src/googletest/include/gtest/gtest.h" |
| 15 | |
| 16 | #include "./av1_rtcd.h" |
| 17 | #include "test/acm_random.h" |
| 18 | #include "test/clear_system_state.h" |
| 19 | #include "test/register_state_check.h" |
| 20 | #include "test/util.h" |
| 21 | |
Yaowu Xu | abdf655 | 2017-11-29 08:41:52 -0800 | [diff] [blame] | 22 | #include "aom_ports/aom_timer.h" |
David Barker | ce110cc | 2017-02-22 10:38:59 +0000 | [diff] [blame] | 23 | #include "av1/common/mv.h" |
| 24 | #include "av1/common/restoration.h" |
| 25 | |
| 26 | namespace { |
| 27 | |
David Barker | ce110cc | 2017-02-22 10:38:59 +0000 | [diff] [blame] | 28 | using libaom_test::ACMRandom; |
Johann | 123e8a6 | 2017-12-28 14:40:49 -0800 | [diff] [blame] | 29 | using std::tr1::make_tuple; |
| 30 | using std::tr1::tuple; |
David Barker | ce110cc | 2017-02-22 10:38:59 +0000 | [diff] [blame] | 31 | |
Imdad Sardharwalla | c6acc53 | 2018-01-03 15:18:24 +0000 | [diff] [blame] | 32 | typedef void (*SgrFunc)(const uint8_t *dat8, int width, int height, int stride, |
| 33 | int eps, const int *xqd, uint8_t *dst8, int dst_stride, |
| 34 | int32_t *tmpbuf, int bit_depth, int highbd); |
| 35 | |
| 36 | // Test parameter list: |
| 37 | // <tst_fun_> |
| 38 | typedef tuple<SgrFunc> FilterTestParam; |
David Barker | ce110cc | 2017-02-22 10:38:59 +0000 | [diff] [blame] | 39 | |
| 40 | class AV1SelfguidedFilterTest |
| 41 | : public ::testing::TestWithParam<FilterTestParam> { |
| 42 | public: |
| 43 | virtual ~AV1SelfguidedFilterTest() {} |
| 44 | virtual void SetUp() {} |
| 45 | |
| 46 | virtual void TearDown() { libaom_test::ClearSystemState(); } |
| 47 | |
| 48 | protected: |
| 49 | void RunSpeedTest() { |
Imdad Sardharwalla | c6acc53 | 2018-01-03 15:18:24 +0000 | [diff] [blame] | 50 | tst_fun_ = GET_PARAM(0); |
Debargha Mukherjee | 1330dfd | 2017-09-03 22:22:27 -0700 | [diff] [blame] | 51 | const int pu_width = RESTORATION_PROC_UNIT_SIZE; |
| 52 | const int pu_height = RESTORATION_PROC_UNIT_SIZE; |
Debargha Mukherjee | e168a78 | 2017-08-31 12:30:10 -0700 | [diff] [blame] | 53 | const int width = 256, height = 256, stride = 288, out_stride = 288; |
David Barker | ce110cc | 2017-02-22 10:38:59 +0000 | [diff] [blame] | 54 | const int NUM_ITERS = 2000; |
Debargha Mukherjee | 1330dfd | 2017-09-03 22:22:27 -0700 | [diff] [blame] | 55 | int i, j, k; |
David Barker | ce110cc | 2017-02-22 10:38:59 +0000 | [diff] [blame] | 56 | |
Debargha Mukherjee | e168a78 | 2017-08-31 12:30:10 -0700 | [diff] [blame] | 57 | uint8_t *input_ = |
Imdad Sardharwalla | c6acc53 | 2018-01-03 15:18:24 +0000 | [diff] [blame] | 58 | (uint8_t *)aom_memalign(32, stride * (height + 32) * sizeof(uint8_t)); |
Debargha Mukherjee | e168a78 | 2017-08-31 12:30:10 -0700 | [diff] [blame] | 59 | uint8_t *output_ = (uint8_t *)aom_memalign( |
Imdad Sardharwalla | c6acc53 | 2018-01-03 15:18:24 +0000 | [diff] [blame] | 60 | 32, out_stride * (height + 32) * sizeof(uint8_t)); |
| 61 | int32_t *tmpbuf = (int32_t *)aom_memalign(32, RESTORATION_TMPBUF_SIZE); |
Debargha Mukherjee | e168a78 | 2017-08-31 12:30:10 -0700 | [diff] [blame] | 62 | uint8_t *input = input_ + stride * 16 + 16; |
| 63 | uint8_t *output = output_ + out_stride * 16 + 16; |
David Barker | ce110cc | 2017-02-22 10:38:59 +0000 | [diff] [blame] | 64 | |
| 65 | ACMRandom rnd(ACMRandom::DeterministicSeed()); |
| 66 | |
Debargha Mukherjee | e168a78 | 2017-08-31 12:30:10 -0700 | [diff] [blame] | 67 | for (i = -16; i < height + 16; ++i) |
| 68 | for (j = -16; j < width + 16; ++j) |
| 69 | input[i * stride + j] = rnd.Rand16() & 0xFF; |
David Barker | ce110cc | 2017-02-22 10:38:59 +0000 | [diff] [blame] | 70 | |
Johann | f152ff6 | 2018-02-08 14:33:07 -0800 | [diff] [blame] | 71 | int xqd[2] = { SGRPROJ_PRJ_MIN0 + rnd.PseudoUniform(SGRPROJ_PRJ_MAX0 + 1 - |
| 72 | SGRPROJ_PRJ_MIN0), |
| 73 | SGRPROJ_PRJ_MIN1 + rnd.PseudoUniform(SGRPROJ_PRJ_MAX1 + 1 - |
| 74 | SGRPROJ_PRJ_MIN1) }; |
David Barker | ce110cc | 2017-02-22 10:38:59 +0000 | [diff] [blame] | 75 | // Fix a parameter set, since the speed depends slightly on r. |
| 76 | // Change this to test different combinations of values of r. |
David Barker | 5765fad | 2017-03-08 11:27:09 +0000 | [diff] [blame] | 77 | int eps = 15; |
David Barker | ce110cc | 2017-02-22 10:38:59 +0000 | [diff] [blame] | 78 | |
| 79 | av1_loop_restoration_precal(); |
| 80 | |
Imdad Sardharwalla | d051e56 | 2018-02-02 09:42:07 +0000 | [diff] [blame] | 81 | aom_usec_timer ref_timer; |
| 82 | aom_usec_timer_start(&ref_timer); |
| 83 | for (i = 0; i < NUM_ITERS; ++i) { |
| 84 | for (k = 0; k < height; k += pu_height) |
| 85 | for (j = 0; j < width; j += pu_width) { |
| 86 | int w = AOMMIN(pu_width, width - j); |
| 87 | int h = AOMMIN(pu_height, height - k); |
| 88 | uint8_t *input_p = input + k * stride + j; |
| 89 | uint8_t *output_p = output + k * out_stride + j; |
| 90 | apply_selfguided_restoration_c(input_p, w, h, stride, eps, xqd, |
| 91 | output_p, out_stride, tmpbuf, 8, 0); |
| 92 | } |
| 93 | } |
| 94 | aom_usec_timer_mark(&ref_timer); |
| 95 | const int64_t ref_time = aom_usec_timer_elapsed(&ref_timer); |
| 96 | |
| 97 | aom_usec_timer tst_timer; |
| 98 | aom_usec_timer_start(&tst_timer); |
David Barker | ce110cc | 2017-02-22 10:38:59 +0000 | [diff] [blame] | 99 | for (i = 0; i < NUM_ITERS; ++i) { |
Debargha Mukherjee | 1330dfd | 2017-09-03 22:22:27 -0700 | [diff] [blame] | 100 | for (k = 0; k < height; k += pu_height) |
| 101 | for (j = 0; j < width; j += pu_width) { |
| 102 | int w = AOMMIN(pu_width, width - j); |
| 103 | int h = AOMMIN(pu_height, height - k); |
| 104 | uint8_t *input_p = input + k * stride + j; |
| 105 | uint8_t *output_p = output + k * out_stride + j; |
Imdad Sardharwalla | c6acc53 | 2018-01-03 15:18:24 +0000 | [diff] [blame] | 106 | tst_fun_(input_p, w, h, stride, eps, xqd, output_p, out_stride, |
| 107 | tmpbuf, 8, 0); |
Debargha Mukherjee | 1330dfd | 2017-09-03 22:22:27 -0700 | [diff] [blame] | 108 | } |
David Barker | ce110cc | 2017-02-22 10:38:59 +0000 | [diff] [blame] | 109 | } |
Imdad Sardharwalla | d051e56 | 2018-02-02 09:42:07 +0000 | [diff] [blame] | 110 | aom_usec_timer_mark(&tst_timer); |
| 111 | const int64_t tst_time = aom_usec_timer_elapsed(&tst_timer); |
David Barker | ce110cc | 2017-02-22 10:38:59 +0000 | [diff] [blame] | 112 | |
Imdad Sardharwalla | d051e56 | 2018-02-02 09:42:07 +0000 | [diff] [blame] | 113 | std::cout << "[ ] C time = " << ref_time / 1000 |
| 114 | << " ms, SIMD time = " << tst_time / 1000 << " ms\n"; |
| 115 | |
| 116 | EXPECT_GT(ref_time, tst_time) |
| 117 | << "Error: AV1SelfguidedFilterTest.SpeedTest, SIMD slower than C.\n" |
| 118 | << "C time: " << ref_time << " us\n" |
| 119 | << "SIMD time: " << tst_time << " us\n"; |
David Barker | ce110cc | 2017-02-22 10:38:59 +0000 | [diff] [blame] | 120 | |
Debargha Mukherjee | e168a78 | 2017-08-31 12:30:10 -0700 | [diff] [blame] | 121 | aom_free(input_); |
| 122 | aom_free(output_); |
David Barker | ce110cc | 2017-02-22 10:38:59 +0000 | [diff] [blame] | 123 | aom_free(tmpbuf); |
David Barker | ce110cc | 2017-02-22 10:38:59 +0000 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | void RunCorrectnessTest() { |
Imdad Sardharwalla | c6acc53 | 2018-01-03 15:18:24 +0000 | [diff] [blame] | 127 | tst_fun_ = GET_PARAM(0); |
Debargha Mukherjee | 1330dfd | 2017-09-03 22:22:27 -0700 | [diff] [blame] | 128 | const int pu_width = RESTORATION_PROC_UNIT_SIZE; |
| 129 | const int pu_height = RESTORATION_PROC_UNIT_SIZE; |
David Barker | bcc5535 | 2017-03-10 15:04:52 +0000 | [diff] [blame] | 130 | // Set the maximum width/height to test here. We actually test a small |
| 131 | // range of sizes *up to* this size, so that we can check, eg., |
| 132 | // the behaviour on tiles which are not a multiple of 4 wide. |
| 133 | const int max_w = 260, max_h = 260, stride = 672, out_stride = 672; |
David Barker | 5765fad | 2017-03-08 11:27:09 +0000 | [diff] [blame] | 134 | const int NUM_ITERS = 81; |
David Barker | ce110cc | 2017-02-22 10:38:59 +0000 | [diff] [blame] | 135 | int i, j, k; |
| 136 | |
Debargha Mukherjee | e168a78 | 2017-08-31 12:30:10 -0700 | [diff] [blame] | 137 | uint8_t *input_ = |
Imdad Sardharwalla | c6acc53 | 2018-01-03 15:18:24 +0000 | [diff] [blame] | 138 | (uint8_t *)aom_memalign(32, stride * (max_h + 32) * sizeof(uint8_t)); |
Debargha Mukherjee | e168a78 | 2017-08-31 12:30:10 -0700 | [diff] [blame] | 139 | uint8_t *output_ = (uint8_t *)aom_memalign( |
Imdad Sardharwalla | c6acc53 | 2018-01-03 15:18:24 +0000 | [diff] [blame] | 140 | 32, out_stride * (max_h + 32) * sizeof(uint8_t)); |
Debargha Mukherjee | e168a78 | 2017-08-31 12:30:10 -0700 | [diff] [blame] | 141 | uint8_t *output2_ = (uint8_t *)aom_memalign( |
Imdad Sardharwalla | c6acc53 | 2018-01-03 15:18:24 +0000 | [diff] [blame] | 142 | 32, out_stride * (max_h + 32) * sizeof(uint8_t)); |
| 143 | int32_t *tmpbuf = (int32_t *)aom_memalign(32, RESTORATION_TMPBUF_SIZE); |
David Barker | ce110cc | 2017-02-22 10:38:59 +0000 | [diff] [blame] | 144 | |
Debargha Mukherjee | e168a78 | 2017-08-31 12:30:10 -0700 | [diff] [blame] | 145 | uint8_t *input = input_ + stride * 16 + 16; |
| 146 | uint8_t *output = output_ + out_stride * 16 + 16; |
| 147 | uint8_t *output2 = output2_ + out_stride * 16 + 16; |
| 148 | |
David Barker | ce110cc | 2017-02-22 10:38:59 +0000 | [diff] [blame] | 149 | ACMRandom rnd(ACMRandom::DeterministicSeed()); |
| 150 | |
| 151 | av1_loop_restoration_precal(); |
| 152 | |
| 153 | for (i = 0; i < NUM_ITERS; ++i) { |
Debargha Mukherjee | e168a78 | 2017-08-31 12:30:10 -0700 | [diff] [blame] | 154 | for (j = -16; j < max_h + 16; ++j) |
| 155 | for (k = -16; k < max_w + 16; ++k) |
| 156 | input[j * stride + k] = rnd.Rand16() & 0xFF; |
David Barker | ce110cc | 2017-02-22 10:38:59 +0000 | [diff] [blame] | 157 | |
Johann | f152ff6 | 2018-02-08 14:33:07 -0800 | [diff] [blame] | 158 | int xqd[2] = { SGRPROJ_PRJ_MIN0 + rnd.PseudoUniform(SGRPROJ_PRJ_MAX0 + 1 - |
| 159 | SGRPROJ_PRJ_MIN0), |
| 160 | SGRPROJ_PRJ_MIN1 + rnd.PseudoUniform(SGRPROJ_PRJ_MAX1 + 1 - |
| 161 | SGRPROJ_PRJ_MIN1) }; |
David Barker | ce110cc | 2017-02-22 10:38:59 +0000 | [diff] [blame] | 162 | int eps = rnd.PseudoUniform(1 << SGRPROJ_PARAMS_BITS); |
| 163 | |
David Barker | 5765fad | 2017-03-08 11:27:09 +0000 | [diff] [blame] | 164 | // Test various tile sizes around 256x256 |
David Barker | bcc5535 | 2017-03-10 15:04:52 +0000 | [diff] [blame] | 165 | int test_w = max_w - (i / 9); |
| 166 | int test_h = max_h - (i % 9); |
David Barker | 5765fad | 2017-03-08 11:27:09 +0000 | [diff] [blame] | 167 | |
Debargha Mukherjee | 1330dfd | 2017-09-03 22:22:27 -0700 | [diff] [blame] | 168 | for (k = 0; k < test_h; k += pu_height) |
| 169 | for (j = 0; j < test_w; j += pu_width) { |
| 170 | int w = AOMMIN(pu_width, test_w - j); |
| 171 | int h = AOMMIN(pu_height, test_h - k); |
| 172 | uint8_t *input_p = input + k * stride + j; |
| 173 | uint8_t *output_p = output + k * out_stride + j; |
| 174 | uint8_t *output2_p = output2 + k * out_stride + j; |
Imdad Sardharwalla | c6acc53 | 2018-01-03 15:18:24 +0000 | [diff] [blame] | 175 | tst_fun_(input_p, w, h, stride, eps, xqd, output_p, out_stride, |
| 176 | tmpbuf, 8, 0); |
Debargha Mukherjee | 1330dfd | 2017-09-03 22:22:27 -0700 | [diff] [blame] | 177 | apply_selfguided_restoration_c(input_p, w, h, stride, eps, xqd, |
Rupert Swarbrick | 625e50b | 2017-11-22 11:49:55 +0000 | [diff] [blame] | 178 | output2_p, out_stride, tmpbuf, 8, 0); |
Debargha Mukherjee | 1330dfd | 2017-09-03 22:22:27 -0700 | [diff] [blame] | 179 | } |
Imdad Sardharwalla | c6acc53 | 2018-01-03 15:18:24 +0000 | [diff] [blame] | 180 | |
David Barker | 5765fad | 2017-03-08 11:27:09 +0000 | [diff] [blame] | 181 | for (j = 0; j < test_h; ++j) |
Debargha Mukherjee | e168a78 | 2017-08-31 12:30:10 -0700 | [diff] [blame] | 182 | for (k = 0; k < test_w; ++k) { |
David Barker | ce110cc | 2017-02-22 10:38:59 +0000 | [diff] [blame] | 183 | ASSERT_EQ(output[j * out_stride + k], output2[j * out_stride + k]); |
Debargha Mukherjee | e168a78 | 2017-08-31 12:30:10 -0700 | [diff] [blame] | 184 | } |
David Barker | ce110cc | 2017-02-22 10:38:59 +0000 | [diff] [blame] | 185 | } |
| 186 | |
Debargha Mukherjee | e168a78 | 2017-08-31 12:30:10 -0700 | [diff] [blame] | 187 | aom_free(input_); |
| 188 | aom_free(output_); |
| 189 | aom_free(output2_); |
David Barker | ce110cc | 2017-02-22 10:38:59 +0000 | [diff] [blame] | 190 | aom_free(tmpbuf); |
David Barker | ce110cc | 2017-02-22 10:38:59 +0000 | [diff] [blame] | 191 | } |
Imdad Sardharwalla | c6acc53 | 2018-01-03 15:18:24 +0000 | [diff] [blame] | 192 | |
| 193 | private: |
| 194 | SgrFunc tst_fun_; |
David Barker | ce110cc | 2017-02-22 10:38:59 +0000 | [diff] [blame] | 195 | }; |
| 196 | |
Imdad Sardharwalla | c6acc53 | 2018-01-03 15:18:24 +0000 | [diff] [blame] | 197 | TEST_P(AV1SelfguidedFilterTest, DISABLED_SpeedTest) { RunSpeedTest(); } |
David Barker | ce110cc | 2017-02-22 10:38:59 +0000 | [diff] [blame] | 198 | TEST_P(AV1SelfguidedFilterTest, CorrectnessTest) { RunCorrectnessTest(); } |
| 199 | |
David Barker | ce110cc | 2017-02-22 10:38:59 +0000 | [diff] [blame] | 200 | #if HAVE_SSE4_1 |
| 201 | INSTANTIATE_TEST_CASE_P(SSE4_1, AV1SelfguidedFilterTest, |
Imdad Sardharwalla | c6acc53 | 2018-01-03 15:18:24 +0000 | [diff] [blame] | 202 | ::testing::Values(apply_selfguided_restoration_sse4_1)); |
David Barker | ce110cc | 2017-02-22 10:38:59 +0000 | [diff] [blame] | 203 | #endif |
| 204 | |
Imdad Sardharwalla | c6acc53 | 2018-01-03 15:18:24 +0000 | [diff] [blame] | 205 | #if HAVE_AVX2 |
| 206 | INSTANTIATE_TEST_CASE_P(AVX2, AV1SelfguidedFilterTest, |
| 207 | ::testing::Values(apply_selfguided_restoration_avx2)); |
| 208 | #endif |
| 209 | |
| 210 | // Test parameter list: |
| 211 | // <tst_fun_, bit_depth> |
| 212 | typedef tuple<SgrFunc, int> HighbdFilterTestParam; |
David Barker | 4d2af5d | 2017-03-09 11:46:50 +0000 | [diff] [blame] | 213 | |
| 214 | class AV1HighbdSelfguidedFilterTest |
| 215 | : public ::testing::TestWithParam<HighbdFilterTestParam> { |
| 216 | public: |
| 217 | virtual ~AV1HighbdSelfguidedFilterTest() {} |
| 218 | virtual void SetUp() {} |
| 219 | |
| 220 | virtual void TearDown() { libaom_test::ClearSystemState(); } |
| 221 | |
| 222 | protected: |
| 223 | void RunSpeedTest() { |
Imdad Sardharwalla | c6acc53 | 2018-01-03 15:18:24 +0000 | [diff] [blame] | 224 | tst_fun_ = GET_PARAM(0); |
Debargha Mukherjee | 1330dfd | 2017-09-03 22:22:27 -0700 | [diff] [blame] | 225 | const int pu_width = RESTORATION_PROC_UNIT_SIZE; |
| 226 | const int pu_height = RESTORATION_PROC_UNIT_SIZE; |
Debargha Mukherjee | e168a78 | 2017-08-31 12:30:10 -0700 | [diff] [blame] | 227 | const int width = 256, height = 256, stride = 288, out_stride = 288; |
David Barker | 4d2af5d | 2017-03-09 11:46:50 +0000 | [diff] [blame] | 228 | const int NUM_ITERS = 2000; |
Debargha Mukherjee | 1330dfd | 2017-09-03 22:22:27 -0700 | [diff] [blame] | 229 | int i, j, k; |
Imdad Sardharwalla | c6acc53 | 2018-01-03 15:18:24 +0000 | [diff] [blame] | 230 | int bit_depth = GET_PARAM(1); |
David Barker | 4d2af5d | 2017-03-09 11:46:50 +0000 | [diff] [blame] | 231 | int mask = (1 << bit_depth) - 1; |
| 232 | |
Debargha Mukherjee | e168a78 | 2017-08-31 12:30:10 -0700 | [diff] [blame] | 233 | uint16_t *input_ = |
Imdad Sardharwalla | c6acc53 | 2018-01-03 15:18:24 +0000 | [diff] [blame] | 234 | (uint16_t *)aom_memalign(32, stride * (height + 32) * sizeof(uint16_t)); |
Debargha Mukherjee | e168a78 | 2017-08-31 12:30:10 -0700 | [diff] [blame] | 235 | uint16_t *output_ = (uint16_t *)aom_memalign( |
Imdad Sardharwalla | c6acc53 | 2018-01-03 15:18:24 +0000 | [diff] [blame] | 236 | 32, out_stride * (height + 32) * sizeof(uint16_t)); |
| 237 | int32_t *tmpbuf = (int32_t *)aom_memalign(32, RESTORATION_TMPBUF_SIZE); |
Debargha Mukherjee | e168a78 | 2017-08-31 12:30:10 -0700 | [diff] [blame] | 238 | uint16_t *input = input_ + stride * 16 + 16; |
| 239 | uint16_t *output = output_ + out_stride * 16 + 16; |
David Barker | 4d2af5d | 2017-03-09 11:46:50 +0000 | [diff] [blame] | 240 | |
| 241 | ACMRandom rnd(ACMRandom::DeterministicSeed()); |
| 242 | |
Debargha Mukherjee | e168a78 | 2017-08-31 12:30:10 -0700 | [diff] [blame] | 243 | for (i = -16; i < height + 16; ++i) |
| 244 | for (j = -16; j < width + 16; ++j) |
| 245 | input[i * stride + j] = rnd.Rand16() & mask; |
David Barker | 4d2af5d | 2017-03-09 11:46:50 +0000 | [diff] [blame] | 246 | |
Johann | f152ff6 | 2018-02-08 14:33:07 -0800 | [diff] [blame] | 247 | int xqd[2] = { SGRPROJ_PRJ_MIN0 + rnd.PseudoUniform(SGRPROJ_PRJ_MAX0 + 1 - |
| 248 | SGRPROJ_PRJ_MIN0), |
| 249 | SGRPROJ_PRJ_MIN1 + rnd.PseudoUniform(SGRPROJ_PRJ_MAX1 + 1 - |
| 250 | SGRPROJ_PRJ_MIN1) }; |
David Barker | 4d2af5d | 2017-03-09 11:46:50 +0000 | [diff] [blame] | 251 | // Fix a parameter set, since the speed depends slightly on r. |
| 252 | // Change this to test different combinations of values of r. |
| 253 | int eps = 15; |
| 254 | |
| 255 | av1_loop_restoration_precal(); |
| 256 | |
Imdad Sardharwalla | d051e56 | 2018-02-02 09:42:07 +0000 | [diff] [blame] | 257 | aom_usec_timer ref_timer; |
| 258 | aom_usec_timer_start(&ref_timer); |
| 259 | for (i = 0; i < NUM_ITERS; ++i) { |
| 260 | for (k = 0; k < height; k += pu_height) |
| 261 | for (j = 0; j < width; j += pu_width) { |
| 262 | int w = AOMMIN(pu_width, width - j); |
| 263 | int h = AOMMIN(pu_height, height - k); |
| 264 | uint16_t *input_p = input + k * stride + j; |
| 265 | uint16_t *output_p = output + k * out_stride + j; |
| 266 | apply_selfguided_restoration_c( |
| 267 | CONVERT_TO_BYTEPTR(input_p), w, h, stride, eps, xqd, |
| 268 | CONVERT_TO_BYTEPTR(output_p), out_stride, tmpbuf, bit_depth, 1); |
| 269 | } |
| 270 | } |
| 271 | aom_usec_timer_mark(&ref_timer); |
| 272 | const int64_t ref_time = aom_usec_timer_elapsed(&ref_timer); |
| 273 | |
| 274 | aom_usec_timer tst_timer; |
| 275 | aom_usec_timer_start(&tst_timer); |
David Barker | 4d2af5d | 2017-03-09 11:46:50 +0000 | [diff] [blame] | 276 | for (i = 0; i < NUM_ITERS; ++i) { |
Debargha Mukherjee | 1330dfd | 2017-09-03 22:22:27 -0700 | [diff] [blame] | 277 | for (k = 0; k < height; k += pu_height) |
| 278 | for (j = 0; j < width; j += pu_width) { |
| 279 | int w = AOMMIN(pu_width, width - j); |
| 280 | int h = AOMMIN(pu_height, height - k); |
| 281 | uint16_t *input_p = input + k * stride + j; |
| 282 | uint16_t *output_p = output + k * out_stride + j; |
Imdad Sardharwalla | c6acc53 | 2018-01-03 15:18:24 +0000 | [diff] [blame] | 283 | tst_fun_(CONVERT_TO_BYTEPTR(input_p), w, h, stride, eps, xqd, |
| 284 | CONVERT_TO_BYTEPTR(output_p), out_stride, tmpbuf, bit_depth, |
| 285 | 1); |
Debargha Mukherjee | 1330dfd | 2017-09-03 22:22:27 -0700 | [diff] [blame] | 286 | } |
David Barker | 4d2af5d | 2017-03-09 11:46:50 +0000 | [diff] [blame] | 287 | } |
Imdad Sardharwalla | d051e56 | 2018-02-02 09:42:07 +0000 | [diff] [blame] | 288 | aom_usec_timer_mark(&tst_timer); |
| 289 | const int64_t tst_time = aom_usec_timer_elapsed(&tst_timer); |
David Barker | 4d2af5d | 2017-03-09 11:46:50 +0000 | [diff] [blame] | 290 | |
Imdad Sardharwalla | d051e56 | 2018-02-02 09:42:07 +0000 | [diff] [blame] | 291 | std::cout << "[ ] C time = " << ref_time / 1000 |
| 292 | << " ms, SIMD time = " << tst_time / 1000 << " ms\n"; |
| 293 | |
| 294 | EXPECT_GT(ref_time, tst_time) |
| 295 | << "Error: AV1HighbdSelfguidedFilterTest.SpeedTest, SIMD slower than " |
| 296 | "C.\n" |
| 297 | << "C time: " << ref_time << " us\n" |
| 298 | << "SIMD time: " << tst_time << " us\n"; |
David Barker | 4d2af5d | 2017-03-09 11:46:50 +0000 | [diff] [blame] | 299 | |
Debargha Mukherjee | e168a78 | 2017-08-31 12:30:10 -0700 | [diff] [blame] | 300 | aom_free(input_); |
| 301 | aom_free(output_); |
David Barker | 4d2af5d | 2017-03-09 11:46:50 +0000 | [diff] [blame] | 302 | aom_free(tmpbuf); |
David Barker | 4d2af5d | 2017-03-09 11:46:50 +0000 | [diff] [blame] | 303 | } |
| 304 | |
| 305 | void RunCorrectnessTest() { |
Imdad Sardharwalla | c6acc53 | 2018-01-03 15:18:24 +0000 | [diff] [blame] | 306 | tst_fun_ = GET_PARAM(0); |
Debargha Mukherjee | 1330dfd | 2017-09-03 22:22:27 -0700 | [diff] [blame] | 307 | const int pu_width = RESTORATION_PROC_UNIT_SIZE; |
| 308 | const int pu_height = RESTORATION_PROC_UNIT_SIZE; |
David Barker | bcc5535 | 2017-03-10 15:04:52 +0000 | [diff] [blame] | 309 | // Set the maximum width/height to test here. We actually test a small |
| 310 | // range of sizes *up to* this size, so that we can check, eg., |
| 311 | // the behaviour on tiles which are not a multiple of 4 wide. |
| 312 | const int max_w = 260, max_h = 260, stride = 672, out_stride = 672; |
David Barker | 4d2af5d | 2017-03-09 11:46:50 +0000 | [diff] [blame] | 313 | const int NUM_ITERS = 81; |
| 314 | int i, j, k; |
Imdad Sardharwalla | c6acc53 | 2018-01-03 15:18:24 +0000 | [diff] [blame] | 315 | int bit_depth = GET_PARAM(1); |
David Barker | 4d2af5d | 2017-03-09 11:46:50 +0000 | [diff] [blame] | 316 | int mask = (1 << bit_depth) - 1; |
| 317 | |
Debargha Mukherjee | e168a78 | 2017-08-31 12:30:10 -0700 | [diff] [blame] | 318 | uint16_t *input_ = |
Imdad Sardharwalla | c6acc53 | 2018-01-03 15:18:24 +0000 | [diff] [blame] | 319 | (uint16_t *)aom_memalign(32, stride * (max_h + 32) * sizeof(uint16_t)); |
Debargha Mukherjee | e168a78 | 2017-08-31 12:30:10 -0700 | [diff] [blame] | 320 | uint16_t *output_ = (uint16_t *)aom_memalign( |
Imdad Sardharwalla | c6acc53 | 2018-01-03 15:18:24 +0000 | [diff] [blame] | 321 | 32, out_stride * (max_h + 32) * sizeof(uint16_t)); |
Debargha Mukherjee | e168a78 | 2017-08-31 12:30:10 -0700 | [diff] [blame] | 322 | uint16_t *output2_ = (uint16_t *)aom_memalign( |
Imdad Sardharwalla | c6acc53 | 2018-01-03 15:18:24 +0000 | [diff] [blame] | 323 | 32, out_stride * (max_h + 32) * sizeof(uint16_t)); |
| 324 | int32_t *tmpbuf = (int32_t *)aom_memalign(32, RESTORATION_TMPBUF_SIZE); |
David Barker | 4d2af5d | 2017-03-09 11:46:50 +0000 | [diff] [blame] | 325 | |
Debargha Mukherjee | e168a78 | 2017-08-31 12:30:10 -0700 | [diff] [blame] | 326 | uint16_t *input = input_ + stride * 16 + 16; |
| 327 | uint16_t *output = output_ + out_stride * 16 + 16; |
| 328 | uint16_t *output2 = output2_ + out_stride * 16 + 16; |
| 329 | |
David Barker | 4d2af5d | 2017-03-09 11:46:50 +0000 | [diff] [blame] | 330 | ACMRandom rnd(ACMRandom::DeterministicSeed()); |
| 331 | |
| 332 | av1_loop_restoration_precal(); |
| 333 | |
| 334 | for (i = 0; i < NUM_ITERS; ++i) { |
Debargha Mukherjee | e168a78 | 2017-08-31 12:30:10 -0700 | [diff] [blame] | 335 | for (j = -16; j < max_h + 16; ++j) |
| 336 | for (k = -16; k < max_w + 16; ++k) |
| 337 | input[j * stride + k] = rnd.Rand16() & mask; |
David Barker | 4d2af5d | 2017-03-09 11:46:50 +0000 | [diff] [blame] | 338 | |
Johann | f152ff6 | 2018-02-08 14:33:07 -0800 | [diff] [blame] | 339 | int xqd[2] = { SGRPROJ_PRJ_MIN0 + rnd.PseudoUniform(SGRPROJ_PRJ_MAX0 + 1 - |
| 340 | SGRPROJ_PRJ_MIN0), |
| 341 | SGRPROJ_PRJ_MIN1 + rnd.PseudoUniform(SGRPROJ_PRJ_MAX1 + 1 - |
| 342 | SGRPROJ_PRJ_MIN1) }; |
David Barker | 4d2af5d | 2017-03-09 11:46:50 +0000 | [diff] [blame] | 343 | int eps = rnd.PseudoUniform(1 << SGRPROJ_PARAMS_BITS); |
| 344 | |
| 345 | // Test various tile sizes around 256x256 |
David Barker | bcc5535 | 2017-03-10 15:04:52 +0000 | [diff] [blame] | 346 | int test_w = max_w - (i / 9); |
| 347 | int test_h = max_h - (i % 9); |
David Barker | 4d2af5d | 2017-03-09 11:46:50 +0000 | [diff] [blame] | 348 | |
Debargha Mukherjee | 1330dfd | 2017-09-03 22:22:27 -0700 | [diff] [blame] | 349 | for (k = 0; k < test_h; k += pu_height) |
| 350 | for (j = 0; j < test_w; j += pu_width) { |
| 351 | int w = AOMMIN(pu_width, test_w - j); |
| 352 | int h = AOMMIN(pu_height, test_h - k); |
| 353 | uint16_t *input_p = input + k * stride + j; |
| 354 | uint16_t *output_p = output + k * out_stride + j; |
| 355 | uint16_t *output2_p = output2 + k * out_stride + j; |
Imdad Sardharwalla | c6acc53 | 2018-01-03 15:18:24 +0000 | [diff] [blame] | 356 | tst_fun_(CONVERT_TO_BYTEPTR(input_p), w, h, stride, eps, xqd, |
| 357 | CONVERT_TO_BYTEPTR(output_p), out_stride, tmpbuf, bit_depth, |
| 358 | 1); |
Rupert Swarbrick | 625e50b | 2017-11-22 11:49:55 +0000 | [diff] [blame] | 359 | apply_selfguided_restoration_c( |
| 360 | CONVERT_TO_BYTEPTR(input_p), w, h, stride, eps, xqd, |
| 361 | CONVERT_TO_BYTEPTR(output2_p), out_stride, tmpbuf, bit_depth, 1); |
Debargha Mukherjee | 1330dfd | 2017-09-03 22:22:27 -0700 | [diff] [blame] | 362 | } |
| 363 | |
David Barker | 4d2af5d | 2017-03-09 11:46:50 +0000 | [diff] [blame] | 364 | for (j = 0; j < test_h; ++j) |
| 365 | for (k = 0; k < test_w; ++k) |
| 366 | ASSERT_EQ(output[j * out_stride + k], output2[j * out_stride + k]); |
| 367 | } |
| 368 | |
Debargha Mukherjee | e168a78 | 2017-08-31 12:30:10 -0700 | [diff] [blame] | 369 | aom_free(input_); |
| 370 | aom_free(output_); |
| 371 | aom_free(output2_); |
David Barker | 4d2af5d | 2017-03-09 11:46:50 +0000 | [diff] [blame] | 372 | aom_free(tmpbuf); |
David Barker | 4d2af5d | 2017-03-09 11:46:50 +0000 | [diff] [blame] | 373 | } |
Imdad Sardharwalla | c6acc53 | 2018-01-03 15:18:24 +0000 | [diff] [blame] | 374 | |
| 375 | private: |
| 376 | SgrFunc tst_fun_; |
David Barker | 4d2af5d | 2017-03-09 11:46:50 +0000 | [diff] [blame] | 377 | }; |
| 378 | |
Imdad Sardharwalla | c6acc53 | 2018-01-03 15:18:24 +0000 | [diff] [blame] | 379 | TEST_P(AV1HighbdSelfguidedFilterTest, DISABLED_SpeedTest) { RunSpeedTest(); } |
David Barker | 4d2af5d | 2017-03-09 11:46:50 +0000 | [diff] [blame] | 380 | TEST_P(AV1HighbdSelfguidedFilterTest, CorrectnessTest) { RunCorrectnessTest(); } |
| 381 | |
Tom Finegan | 9f02130 | 2017-09-07 07:49:42 -0700 | [diff] [blame] | 382 | #if HAVE_SSE4_1 |
Imdad Sardharwalla | c6acc53 | 2018-01-03 15:18:24 +0000 | [diff] [blame] | 383 | const int highbd_params_sse4_1[] = { 8, 10, 12 }; |
| 384 | INSTANTIATE_TEST_CASE_P( |
| 385 | SSE4_1, AV1HighbdSelfguidedFilterTest, |
| 386 | ::testing::Combine(::testing::Values(apply_selfguided_restoration_sse4_1), |
| 387 | ::testing::ValuesIn(highbd_params_sse4_1))); |
| 388 | #endif |
| 389 | |
| 390 | #if HAVE_AVX2 |
| 391 | const int highbd_params_avx2[] = { 8, 10, 12 }; |
| 392 | INSTANTIATE_TEST_CASE_P( |
| 393 | AVX2, AV1HighbdSelfguidedFilterTest, |
| 394 | ::testing::Combine(::testing::Values(apply_selfguided_restoration_avx2), |
| 395 | ::testing::ValuesIn(highbd_params_avx2))); |
David Barker | 4d2af5d | 2017-03-09 11:46:50 +0000 | [diff] [blame] | 396 | #endif |
David Barker | 4d2af5d | 2017-03-09 11:46:50 +0000 | [diff] [blame] | 397 | |
David Barker | ce110cc | 2017-02-22 10:38:59 +0000 | [diff] [blame] | 398 | } // namespace |