Peng Bin | 640ea40 | 2018-03-30 14:12:53 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017, 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 <stdint.h> |
| 13 | #include <stdio.h> |
| 14 | #include <string.h> |
sarahparker | a543df5 | 2018-11-02 16:02:05 -0700 | [diff] [blame] | 15 | #include <tuple> |
Peng Bin | 640ea40 | 2018-03-30 14:12:53 +0800 | [diff] [blame] | 16 | |
Tom Finegan | 60e653d | 2018-05-22 11:34:58 -0700 | [diff] [blame] | 17 | #include "config/aom_config.h" |
Tom Finegan | 44702c8 | 2018-05-22 13:00:39 -0700 | [diff] [blame] | 18 | #include "config/av1_rtcd.h" |
Tom Finegan | 60e653d | 2018-05-22 11:34:58 -0700 | [diff] [blame] | 19 | |
Peng Bin | 640ea40 | 2018-03-30 14:12:53 +0800 | [diff] [blame] | 20 | #include "aom_ports/mem.h" |
| 21 | #include "av1/common/scan.h" |
| 22 | #include "av1/common/txb_common.h" |
| 23 | #include "test/acm_random.h" |
| 24 | #include "test/clear_system_state.h" |
| 25 | #include "test/register_state_check.h" |
| 26 | #include "test/util.h" |
| 27 | #include "third_party/googletest/src/googletest/include/gtest/gtest.h" |
| 28 | |
| 29 | namespace { |
| 30 | using libaom_test::ACMRandom; |
| 31 | |
Sachin Kumar Garg | 5b7e5e2 | 2018-06-20 19:00:12 +0530 | [diff] [blame] | 32 | typedef void (*buildcompdiffwtdmaskd_func)(uint8_t *mask, |
| 33 | DIFFWTD_MASK_TYPE mask_type, |
| 34 | const uint8_t *src0, int src0_stride, |
| 35 | const uint8_t *src1, int src1_stride, |
| 36 | int h, int w); |
| 37 | |
sarahparker | a543df5 | 2018-11-02 16:02:05 -0700 | [diff] [blame] | 38 | typedef std::tuple<BLOCK_SIZE, buildcompdiffwtdmaskd_func> |
Sachin Kumar Garg | 5b7e5e2 | 2018-06-20 19:00:12 +0530 | [diff] [blame] | 39 | BuildCompDiffwtdMaskDParam; |
| 40 | |
| 41 | #if HAVE_SSE4_1 |
| 42 | ::testing::internal::ParamGenerator<BuildCompDiffwtdMaskDParam> BuildParams( |
| 43 | buildcompdiffwtdmaskd_func filter) { |
| 44 | return ::testing::Combine(::testing::Range(BLOCK_4X4, BLOCK_SIZES_ALL), |
| 45 | ::testing::Values(filter)); |
| 46 | } |
| 47 | #endif |
| 48 | |
| 49 | class BuildCompDiffwtdMaskTest |
| 50 | : public ::testing::TestWithParam<BuildCompDiffwtdMaskDParam> { |
Peng Bin | 640ea40 | 2018-03-30 14:12:53 +0800 | [diff] [blame] | 51 | public: |
| 52 | virtual ~BuildCompDiffwtdMaskTest() {} |
| 53 | |
| 54 | virtual void TearDown() { libaom_test::ClearSystemState(); } |
Sachin Kumar Garg | 5b7e5e2 | 2018-06-20 19:00:12 +0530 | [diff] [blame] | 55 | void RunTest(buildcompdiffwtdmaskd_func test_impl, const int is_speed, |
Peng Bin | 640ea40 | 2018-03-30 14:12:53 +0800 | [diff] [blame] | 56 | const DIFFWTD_MASK_TYPE type); |
| 57 | |
| 58 | private: |
| 59 | ACMRandom rnd_; |
| 60 | }; |
| 61 | |
Ravi Chaudhary | ea665b0 | 2018-04-10 18:39:47 +0530 | [diff] [blame] | 62 | typedef void (*buildcompdiffwtdmaskd16_func)( |
| 63 | uint8_t *mask, DIFFWTD_MASK_TYPE mask_type, const CONV_BUF_TYPE *src0, |
| 64 | int src0_stride, const CONV_BUF_TYPE *src1, int src1_stride, int h, int w, |
| 65 | ConvolveParams *conv_params, int bd); |
| 66 | |
sarahparker | a543df5 | 2018-11-02 16:02:05 -0700 | [diff] [blame] | 67 | typedef std::tuple<int, buildcompdiffwtdmaskd16_func, BLOCK_SIZE> |
Ravi Chaudhary | ea665b0 | 2018-04-10 18:39:47 +0530 | [diff] [blame] | 68 | BuildCompDiffwtdMaskD16Param; |
| 69 | |
Sachin Kumar Garg | d78396e | 2018-06-21 11:46:30 +0530 | [diff] [blame] | 70 | #if HAVE_SSE4_1 || HAVE_NEON |
Ravi Chaudhary | ea665b0 | 2018-04-10 18:39:47 +0530 | [diff] [blame] | 71 | ::testing::internal::ParamGenerator<BuildCompDiffwtdMaskD16Param> BuildParams( |
| 72 | buildcompdiffwtdmaskd16_func filter) { |
| 73 | return ::testing::Combine(::testing::Range(8, 13, 2), |
| 74 | ::testing::Values(filter), |
| 75 | ::testing::Range(BLOCK_4X4, BLOCK_SIZES_ALL)); |
| 76 | } |
Sachin Kumar Garg | d78396e | 2018-06-21 11:46:30 +0530 | [diff] [blame] | 77 | #endif |
Ravi Chaudhary | ea665b0 | 2018-04-10 18:39:47 +0530 | [diff] [blame] | 78 | class BuildCompDiffwtdMaskD16Test |
| 79 | : public ::testing::TestWithParam<BuildCompDiffwtdMaskD16Param> { |
| 80 | public: |
| 81 | ~BuildCompDiffwtdMaskD16Test() {} |
| 82 | virtual void TearDown() { libaom_test::ClearSystemState(); } |
| 83 | void SetUp() { rnd_.Reset(ACMRandom::DeterministicSeed()); } |
| 84 | |
| 85 | protected: |
| 86 | void RunCheckOutput(buildcompdiffwtdmaskd16_func test_impl); |
Xing Jin | aa218b2 | 2018-08-22 13:24:59 +0800 | [diff] [blame] | 87 | void RunSpeedTest(buildcompdiffwtdmaskd16_func test_impl, |
| 88 | DIFFWTD_MASK_TYPE mask_type); |
Ravi Chaudhary | ea665b0 | 2018-04-10 18:39:47 +0530 | [diff] [blame] | 89 | libaom_test::ACMRandom rnd_; |
| 90 | }; // class BuildCompDiffwtdMaskD16Test |
| 91 | |
| 92 | void BuildCompDiffwtdMaskD16Test::RunCheckOutput( |
| 93 | buildcompdiffwtdmaskd16_func test_impl) { |
| 94 | const int block_idx = GET_PARAM(2); |
| 95 | const int bd = GET_PARAM(0); |
| 96 | const int width = block_size_wide[block_idx]; |
| 97 | const int height = block_size_high[block_idx]; |
| 98 | DECLARE_ALIGNED(16, uint8_t, mask_ref[2 * MAX_SB_SQUARE]); |
| 99 | DECLARE_ALIGNED(16, uint8_t, mask_test[2 * MAX_SB_SQUARE]); |
| 100 | DECLARE_ALIGNED(32, uint16_t, src0[MAX_SB_SQUARE]); |
| 101 | DECLARE_ALIGNED(32, uint16_t, src1[MAX_SB_SQUARE]); |
| 102 | |
Peng Bin | f7b11f5 | 2018-08-09 17:29:39 +0800 | [diff] [blame] | 103 | ConvolveParams conv_params = get_conv_params_no_round(0, 0, NULL, 0, 1, bd); |
Ravi Chaudhary | ea665b0 | 2018-04-10 18:39:47 +0530 | [diff] [blame] | 104 | |
| 105 | int in_precision = |
| 106 | bd + 2 * FILTER_BITS - conv_params.round_0 - conv_params.round_1 + 2; |
| 107 | |
| 108 | for (int i = 0; i < MAX_SB_SQUARE; i++) { |
| 109 | src0[i] = rnd_.Rand16() & ((1 << in_precision) - 1); |
| 110 | src1[i] = rnd_.Rand16() & ((1 << in_precision) - 1); |
| 111 | } |
| 112 | |
| 113 | for (int mask_type = 0; mask_type < DIFFWTD_MASK_TYPES; mask_type++) { |
| 114 | av1_build_compound_diffwtd_mask_d16_c( |
| 115 | mask_ref, (DIFFWTD_MASK_TYPE)mask_type, src0, width, src1, width, |
| 116 | height, width, &conv_params, bd); |
| 117 | |
| 118 | test_impl(mask_test, (DIFFWTD_MASK_TYPE)mask_type, src0, width, src1, width, |
| 119 | height, width, &conv_params, bd); |
| 120 | |
| 121 | for (int r = 0; r < height; ++r) { |
| 122 | for (int c = 0; c < width; ++c) { |
| 123 | ASSERT_EQ(mask_ref[c + r * width], mask_test[c + r * width]) |
| 124 | << "Mismatch at unit tests for BuildCompDiffwtdMaskD16Test\n" |
| 125 | << " Pixel mismatch at index " |
| 126 | << "[" << r << "," << c << "] " |
| 127 | << " @ " << width << "x" << height << " inv " << mask_type; |
| 128 | } |
| 129 | } |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | void BuildCompDiffwtdMaskD16Test::RunSpeedTest( |
Xing Jin | aa218b2 | 2018-08-22 13:24:59 +0800 | [diff] [blame] | 134 | buildcompdiffwtdmaskd16_func test_impl, DIFFWTD_MASK_TYPE mask_type) { |
Ravi Chaudhary | ea665b0 | 2018-04-10 18:39:47 +0530 | [diff] [blame] | 135 | const int block_idx = GET_PARAM(2); |
| 136 | const int bd = GET_PARAM(0); |
| 137 | const int width = block_size_wide[block_idx]; |
| 138 | const int height = block_size_high[block_idx]; |
| 139 | DECLARE_ALIGNED(16, uint8_t, mask[MAX_SB_SQUARE]); |
| 140 | DECLARE_ALIGNED(32, uint16_t, src0[MAX_SB_SQUARE]); |
| 141 | DECLARE_ALIGNED(32, uint16_t, src1[MAX_SB_SQUARE]); |
| 142 | |
Peng Bin | f7b11f5 | 2018-08-09 17:29:39 +0800 | [diff] [blame] | 143 | ConvolveParams conv_params = get_conv_params_no_round(0, 0, NULL, 0, 1, bd); |
Ravi Chaudhary | ea665b0 | 2018-04-10 18:39:47 +0530 | [diff] [blame] | 144 | |
| 145 | int in_precision = |
| 146 | bd + 2 * FILTER_BITS - conv_params.round_0 - conv_params.round_1 + 2; |
| 147 | |
| 148 | for (int i = 0; i < MAX_SB_SQUARE; i++) { |
| 149 | src0[i] = rnd_.Rand16() & ((1 << in_precision) - 1); |
| 150 | src1[i] = rnd_.Rand16() & ((1 << in_precision) - 1); |
| 151 | } |
| 152 | |
Xing Jin | aa218b2 | 2018-08-22 13:24:59 +0800 | [diff] [blame] | 153 | const int num_loops = 10000000 / (width + height); |
Ravi Chaudhary | ea665b0 | 2018-04-10 18:39:47 +0530 | [diff] [blame] | 154 | aom_usec_timer timer; |
| 155 | aom_usec_timer_start(&timer); |
| 156 | |
| 157 | for (int i = 0; i < num_loops; ++i) |
Xing Jin | aa218b2 | 2018-08-22 13:24:59 +0800 | [diff] [blame] | 158 | av1_build_compound_diffwtd_mask_d16_c(mask, mask_type, src0, width, src1, |
Ravi Chaudhary | ea665b0 | 2018-04-10 18:39:47 +0530 | [diff] [blame] | 159 | width, height, width, &conv_params, |
| 160 | bd); |
| 161 | |
| 162 | aom_usec_timer_mark(&timer); |
| 163 | const int elapsed_time = static_cast<int>(aom_usec_timer_elapsed(&timer)); |
Ravi Chaudhary | ea665b0 | 2018-04-10 18:39:47 +0530 | [diff] [blame] | 164 | |
| 165 | aom_usec_timer timer1; |
| 166 | aom_usec_timer_start(&timer1); |
| 167 | |
| 168 | for (int i = 0; i < num_loops; ++i) |
Xing Jin | aa218b2 | 2018-08-22 13:24:59 +0800 | [diff] [blame] | 169 | test_impl(mask, mask_type, src0, width, src1, width, height, width, |
Ravi Chaudhary | ea665b0 | 2018-04-10 18:39:47 +0530 | [diff] [blame] | 170 | &conv_params, bd); |
| 171 | |
| 172 | aom_usec_timer_mark(&timer1); |
| 173 | const int elapsed_time1 = static_cast<int>(aom_usec_timer_elapsed(&timer1)); |
Xing Jin | aa218b2 | 2018-08-22 13:24:59 +0800 | [diff] [blame] | 174 | printf("av1_build_compound_diffwtd_mask_d16 %3dx%-3d: %7.2f \n", width, |
| 175 | height, elapsed_time / double(elapsed_time1)); |
Ravi Chaudhary | ea665b0 | 2018-04-10 18:39:47 +0530 | [diff] [blame] | 176 | } |
Sachin Kumar Garg | d78396e | 2018-06-21 11:46:30 +0530 | [diff] [blame] | 177 | #if HAVE_SSE4_1 |
Sachin Kumar Garg | 5b7e5e2 | 2018-06-20 19:00:12 +0530 | [diff] [blame] | 178 | void BuildCompDiffwtdMaskTest::RunTest(buildcompdiffwtdmaskd_func test_impl, |
| 179 | const int is_speed, |
Peng Bin | 640ea40 | 2018-03-30 14:12:53 +0800 | [diff] [blame] | 180 | const DIFFWTD_MASK_TYPE type) { |
Sachin Kumar Garg | 5b7e5e2 | 2018-06-20 19:00:12 +0530 | [diff] [blame] | 181 | const int sb_type = GET_PARAM(0); |
Peng Bin | 640ea40 | 2018-03-30 14:12:53 +0800 | [diff] [blame] | 182 | const int width = block_size_wide[sb_type]; |
| 183 | const int height = block_size_high[sb_type]; |
| 184 | DECLARE_ALIGNED(16, uint8_t, mask_ref[MAX_SB_SQUARE]); |
| 185 | DECLARE_ALIGNED(16, uint8_t, mask_test[MAX_SB_SQUARE]); |
| 186 | DECLARE_ALIGNED(16, uint8_t, src0[MAX_SB_SQUARE]); |
| 187 | DECLARE_ALIGNED(16, uint8_t, src1[MAX_SB_SQUARE]); |
| 188 | ACMRandom rnd(ACMRandom::DeterministicSeed()); |
| 189 | for (int i = 0; i < width * height; i++) { |
| 190 | src0[i] = rnd.Rand8(); |
| 191 | src1[i] = rnd.Rand8(); |
| 192 | } |
| 193 | const int run_times = is_speed ? (10000000 / (width + height)) : 1; |
| 194 | aom_usec_timer timer; |
| 195 | aom_usec_timer_start(&timer); |
| 196 | for (int i = 0; i < run_times; ++i) { |
| 197 | av1_build_compound_diffwtd_mask_c(mask_ref, type, src0, width, src1, width, |
| 198 | height, width); |
| 199 | } |
| 200 | const double t1 = get_time_mark(&timer); |
| 201 | aom_usec_timer_start(&timer); |
| 202 | for (int i = 0; i < run_times; ++i) { |
Sachin Kumar Garg | 5b7e5e2 | 2018-06-20 19:00:12 +0530 | [diff] [blame] | 203 | test_impl(mask_test, type, src0, width, src1, width, height, width); |
Peng Bin | 640ea40 | 2018-03-30 14:12:53 +0800 | [diff] [blame] | 204 | } |
| 205 | const double t2 = get_time_mark(&timer); |
| 206 | if (is_speed) { |
| 207 | printf("mask %d %3dx%-3d:%7.2f/%7.2fns", type, width, height, t1, t2); |
| 208 | printf("(%3.2f)\n", t1 / t2); |
| 209 | } |
| 210 | for (int r = 0; r < height; ++r) { |
| 211 | for (int c = 0; c < width; ++c) { |
| 212 | ASSERT_EQ(mask_ref[c + r * width], mask_test[c + r * width]) |
| 213 | << "[" << r << "," << c << "] " << run_times << " @ " << width << "x" |
| 214 | << height << " inv " << type; |
| 215 | } |
| 216 | } |
| 217 | } |
| 218 | |
| 219 | TEST_P(BuildCompDiffwtdMaskTest, match) { |
Sachin Kumar Garg | 5b7e5e2 | 2018-06-20 19:00:12 +0530 | [diff] [blame] | 220 | RunTest(GET_PARAM(1), 0, DIFFWTD_38); |
| 221 | RunTest(GET_PARAM(1), 0, DIFFWTD_38_INV); |
Peng Bin | 640ea40 | 2018-03-30 14:12:53 +0800 | [diff] [blame] | 222 | } |
| 223 | TEST_P(BuildCompDiffwtdMaskTest, DISABLED_Speed) { |
Sachin Kumar Garg | 5b7e5e2 | 2018-06-20 19:00:12 +0530 | [diff] [blame] | 224 | RunTest(GET_PARAM(1), 1, DIFFWTD_38); |
| 225 | RunTest(GET_PARAM(1), 1, DIFFWTD_38_INV); |
Peng Bin | 640ea40 | 2018-03-30 14:12:53 +0800 | [diff] [blame] | 226 | } |
Sachin Kumar Garg | d78396e | 2018-06-21 11:46:30 +0530 | [diff] [blame] | 227 | #endif |
Ravi Chaudhary | ea665b0 | 2018-04-10 18:39:47 +0530 | [diff] [blame] | 228 | TEST_P(BuildCompDiffwtdMaskD16Test, CheckOutput) { |
| 229 | RunCheckOutput(GET_PARAM(1)); |
| 230 | } |
| 231 | |
| 232 | TEST_P(BuildCompDiffwtdMaskD16Test, DISABLED_Speed) { |
Xing Jin | aa218b2 | 2018-08-22 13:24:59 +0800 | [diff] [blame] | 233 | RunSpeedTest(GET_PARAM(1), DIFFWTD_38); |
| 234 | RunSpeedTest(GET_PARAM(1), DIFFWTD_38_INV); |
Ravi Chaudhary | ea665b0 | 2018-04-10 18:39:47 +0530 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | #if HAVE_SSE4_1 |
Cheng Chen | 96786fe | 2020-02-14 17:28:25 -0800 | [diff] [blame] | 238 | INSTANTIATE_TEST_SUITE_P(SSE4_1, BuildCompDiffwtdMaskTest, |
| 239 | BuildParams(av1_build_compound_diffwtd_mask_sse4_1)); |
Ravi Chaudhary | ea665b0 | 2018-04-10 18:39:47 +0530 | [diff] [blame] | 240 | |
Cheng Chen | 96786fe | 2020-02-14 17:28:25 -0800 | [diff] [blame] | 241 | INSTANTIATE_TEST_SUITE_P( |
Ravi Chaudhary | ea665b0 | 2018-04-10 18:39:47 +0530 | [diff] [blame] | 242 | SSE4_1, BuildCompDiffwtdMaskD16Test, |
| 243 | BuildParams(av1_build_compound_diffwtd_mask_d16_sse4_1)); |
| 244 | #endif |
| 245 | |
Xing Jin | aa218b2 | 2018-08-22 13:24:59 +0800 | [diff] [blame] | 246 | #if HAVE_AVX2 |
Cheng Chen | 96786fe | 2020-02-14 17:28:25 -0800 | [diff] [blame] | 247 | INSTANTIATE_TEST_SUITE_P(AVX2, BuildCompDiffwtdMaskTest, |
| 248 | BuildParams(av1_build_compound_diffwtd_mask_avx2)); |
Xing Jin | aa218b2 | 2018-08-22 13:24:59 +0800 | [diff] [blame] | 249 | |
Cheng Chen | 96786fe | 2020-02-14 17:28:25 -0800 | [diff] [blame] | 250 | INSTANTIATE_TEST_SUITE_P(AVX2, BuildCompDiffwtdMaskD16Test, |
| 251 | BuildParams(av1_build_compound_diffwtd_mask_d16_avx2)); |
Xing Jin | aa218b2 | 2018-08-22 13:24:59 +0800 | [diff] [blame] | 252 | #endif |
| 253 | |
Sachin Kumar Garg | d78396e | 2018-06-21 11:46:30 +0530 | [diff] [blame] | 254 | #if HAVE_NEON |
Cheng Chen | 96786fe | 2020-02-14 17:28:25 -0800 | [diff] [blame] | 255 | INSTANTIATE_TEST_SUITE_P(NEON, BuildCompDiffwtdMaskD16Test, |
| 256 | BuildParams(av1_build_compound_diffwtd_mask_d16_neon)); |
Sachin Kumar Garg | d78396e | 2018-06-21 11:46:30 +0530 | [diff] [blame] | 257 | #endif |
| 258 | |
Peng Bin | 640ea40 | 2018-03-30 14:12:53 +0800 | [diff] [blame] | 259 | } // namespace |