• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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>
15 #include <tuple>
16 
17 #include "config/aom_config.h"
18 #include "config/av1_rtcd.h"
19 
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 
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 
38 typedef std::tuple<BLOCK_SIZE, buildcompdiffwtdmaskd_func>
39     BuildCompDiffwtdMaskDParam;
40 
41 #if HAVE_SSE4_1
BuildParams(buildcompdiffwtdmaskd_func filter)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> {
51  public:
~BuildCompDiffwtdMaskTest()52   virtual ~BuildCompDiffwtdMaskTest() {}
53 
TearDown()54   virtual void TearDown() { libaom_test::ClearSystemState(); }
55   void RunTest(buildcompdiffwtdmaskd_func test_impl, const int is_speed,
56                const DIFFWTD_MASK_TYPE type);
57 
58  private:
59   ACMRandom rnd_;
60 };
61 
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 
67 typedef std::tuple<int, buildcompdiffwtdmaskd16_func, BLOCK_SIZE>
68     BuildCompDiffwtdMaskD16Param;
69 
70 #if HAVE_SSE4_1 || HAVE_NEON
BuildParams(buildcompdiffwtdmaskd16_func filter)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 }
77 #endif
78 class BuildCompDiffwtdMaskD16Test
79     : public ::testing::TestWithParam<BuildCompDiffwtdMaskD16Param> {
80  public:
~BuildCompDiffwtdMaskD16Test()81   ~BuildCompDiffwtdMaskD16Test() {}
TearDown()82   virtual void TearDown() { libaom_test::ClearSystemState(); }
SetUp()83   void SetUp() { rnd_.Reset(ACMRandom::DeterministicSeed()); }
84 
85  protected:
86   void RunCheckOutput(buildcompdiffwtdmaskd16_func test_impl);
87   void RunSpeedTest(buildcompdiffwtdmaskd16_func test_impl,
88                     DIFFWTD_MASK_TYPE mask_type);
89   libaom_test::ACMRandom rnd_;
90 };  // class BuildCompDiffwtdMaskD16Test
91 
RunCheckOutput(buildcompdiffwtdmaskd16_func test_impl)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 
103   ConvolveParams conv_params = get_conv_params_no_round(0, 0, NULL, 0, 1, bd);
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 
RunSpeedTest(buildcompdiffwtdmaskd16_func test_impl,DIFFWTD_MASK_TYPE mask_type)133 void BuildCompDiffwtdMaskD16Test::RunSpeedTest(
134     buildcompdiffwtdmaskd16_func test_impl, DIFFWTD_MASK_TYPE mask_type) {
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 
143   ConvolveParams conv_params = get_conv_params_no_round(0, 0, NULL, 0, 1, bd);
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 
153   const int num_loops = 10000000 / (width + height);
154   aom_usec_timer timer;
155   aom_usec_timer_start(&timer);
156 
157   for (int i = 0; i < num_loops; ++i)
158     av1_build_compound_diffwtd_mask_d16_c(mask, mask_type, src0, width, src1,
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));
164 
165   aom_usec_timer timer1;
166   aom_usec_timer_start(&timer1);
167 
168   for (int i = 0; i < num_loops; ++i)
169     test_impl(mask, mask_type, src0, width, src1, width, height, width,
170               &conv_params, bd);
171 
172   aom_usec_timer_mark(&timer1);
173   const int elapsed_time1 = static_cast<int>(aom_usec_timer_elapsed(&timer1));
174   printf("av1_build_compound_diffwtd_mask_d16  %3dx%-3d: %7.2f \n", width,
175          height, elapsed_time / double(elapsed_time1));
176 }
177 #if HAVE_SSE4_1
RunTest(buildcompdiffwtdmaskd_func test_impl,const int is_speed,const DIFFWTD_MASK_TYPE type)178 void BuildCompDiffwtdMaskTest::RunTest(buildcompdiffwtdmaskd_func test_impl,
179                                        const int is_speed,
180                                        const DIFFWTD_MASK_TYPE type) {
181   const int sb_type = GET_PARAM(0);
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) {
203     test_impl(mask_test, type, src0, width, src1, width, height, width);
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 
TEST_P(BuildCompDiffwtdMaskTest,match)219 TEST_P(BuildCompDiffwtdMaskTest, match) {
220   RunTest(GET_PARAM(1), 0, DIFFWTD_38);
221   RunTest(GET_PARAM(1), 0, DIFFWTD_38_INV);
222 }
TEST_P(BuildCompDiffwtdMaskTest,DISABLED_Speed)223 TEST_P(BuildCompDiffwtdMaskTest, DISABLED_Speed) {
224   RunTest(GET_PARAM(1), 1, DIFFWTD_38);
225   RunTest(GET_PARAM(1), 1, DIFFWTD_38_INV);
226 }
227 #endif
TEST_P(BuildCompDiffwtdMaskD16Test,CheckOutput)228 TEST_P(BuildCompDiffwtdMaskD16Test, CheckOutput) {
229   RunCheckOutput(GET_PARAM(1));
230 }
231 
TEST_P(BuildCompDiffwtdMaskD16Test,DISABLED_Speed)232 TEST_P(BuildCompDiffwtdMaskD16Test, DISABLED_Speed) {
233   RunSpeedTest(GET_PARAM(1), DIFFWTD_38);
234   RunSpeedTest(GET_PARAM(1), DIFFWTD_38_INV);
235 }
236 
237 #if HAVE_SSE4_1
238 INSTANTIATE_TEST_SUITE_P(SSE4_1, BuildCompDiffwtdMaskTest,
239                          BuildParams(av1_build_compound_diffwtd_mask_sse4_1));
240 
241 INSTANTIATE_TEST_SUITE_P(
242     SSE4_1, BuildCompDiffwtdMaskD16Test,
243     BuildParams(av1_build_compound_diffwtd_mask_d16_sse4_1));
244 #endif
245 
246 #if HAVE_AVX2
247 INSTANTIATE_TEST_SUITE_P(AVX2, BuildCompDiffwtdMaskTest,
248                          BuildParams(av1_build_compound_diffwtd_mask_avx2));
249 
250 INSTANTIATE_TEST_SUITE_P(AVX2, BuildCompDiffwtdMaskD16Test,
251                          BuildParams(av1_build_compound_diffwtd_mask_d16_avx2));
252 #endif
253 
254 #if HAVE_NEON
255 INSTANTIATE_TEST_SUITE_P(NEON, BuildCompDiffwtdMaskD16Test,
256                          BuildParams(av1_build_compound_diffwtd_mask_d16_neon));
257 #endif
258 
259 }  // namespace
260