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