From 68569dee1416593955c1570d638b3d9250b33012 Mon Sep 17 00:00:00 2001 From: trav90 Date: Mon, 15 Oct 2018 21:45:30 -0500 Subject: Import aom library This is the reference implementation for the Alliance for Open Media's av1 video code. The commit used was 4d668d7feb1f8abd809d1bca0418570a7f142a36. --- third_party/aom/test/sum_squares_test.cc | 192 +++++++++++++++++++++++++++++++ 1 file changed, 192 insertions(+) create mode 100644 third_party/aom/test/sum_squares_test.cc (limited to 'third_party/aom/test/sum_squares_test.cc') diff --git a/third_party/aom/test/sum_squares_test.cc b/third_party/aom/test/sum_squares_test.cc new file mode 100644 index 000000000..b8701c196 --- /dev/null +++ b/third_party/aom/test/sum_squares_test.cc @@ -0,0 +1,192 @@ +/* + * 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 +#include +#include + +#include "third_party/googletest/src/googletest/include/gtest/gtest.h" + +#include "./aom_config.h" +#include "./aom_dsp_rtcd.h" +#include "aom_ports/mem.h" +#include "test/acm_random.h" +#include "test/clear_system_state.h" +#include "test/register_state_check.h" +#include "test/util.h" +#include "test/function_equivalence_test.h" + +using libaom_test::ACMRandom; +using libaom_test::FunctionEquivalenceTest; + +namespace { +const int kNumIterations = 10000; + +static const int16_t kInt13Max = (1 << 12) - 1; + +typedef uint64_t (*SSI16Func)(const int16_t *src, int stride, int width, + int height); +typedef libaom_test::FuncParam TestFuncs; + +class SumSquaresTest : public ::testing::TestWithParam { + public: + virtual ~SumSquaresTest() {} + virtual void SetUp() { params_ = this->GetParam(); } + + virtual void TearDown() { libaom_test::ClearSystemState(); } + + protected: + TestFuncs params_; +}; + +TEST_P(SumSquaresTest, OperationCheck) { + ACMRandom rnd(ACMRandom::DeterministicSeed()); + DECLARE_ALIGNED(16, int16_t, src[256 * 256]); + + int failed = 0; + + const int msb = 11; // Up to 12 bit input + const int limit = 1 << (msb + 1); + + for (int k = 0; k < kNumIterations; k++) { + int width = 4 * rnd(32); // Up to 128x128 + int height = 4 * rnd(32); // Up to 128x128 + int stride = 4 << rnd(7); // Up to 256 stride + while (stride < width) { // Make sure it's valid + stride = 4 << rnd(7); + } + + for (int ii = 0; ii < height; ii++) { + for (int jj = 0; jj < width; jj++) { + src[ii * stride + jj] = rnd(2) ? rnd(limit) : -rnd(limit); + } + } + + const uint64_t res_ref = params_.ref_func(src, stride, width, height); + uint64_t res_tst; + ASM_REGISTER_STATE_CHECK(res_tst = + params_.tst_func(src, stride, width, height)); + + if (!failed) { + failed = res_ref != res_tst; + EXPECT_EQ(res_ref, res_tst) + << "Error: Sum Squares Test" + << " C output does not match optimized output."; + } + } +} + +TEST_P(SumSquaresTest, ExtremeValues) { + ACMRandom rnd(ACMRandom::DeterministicSeed()); + DECLARE_ALIGNED(16, int16_t, src[256 * 256]); + + int failed = 0; + + const int msb = 11; // Up to 12 bit input + const int limit = 1 << (msb + 1); + + for (int k = 0; k < kNumIterations; k++) { + int width = 4 * rnd(32); // Up to 128x128 + int height = 4 * rnd(32); // Up to 128x128 + int stride = 4 << rnd(7); // Up to 256 stride + while (stride < width) { // Make sure it's valid + stride = 4 << rnd(7); + } + + int val = rnd(2) ? limit - 1 : -(limit - 1); + for (int ii = 0; ii < height; ii++) { + for (int jj = 0; jj < width; jj++) { + src[ii * stride + jj] = val; + } + } + + const uint64_t res_ref = params_.ref_func(src, stride, width, height); + uint64_t res_tst; + ASM_REGISTER_STATE_CHECK(res_tst = + params_.tst_func(src, stride, width, height)); + + if (!failed) { + failed = res_ref != res_tst; + EXPECT_EQ(res_ref, res_tst) + << "Error: Sum Squares Test" + << " C output does not match optimized output."; + } + } +} + +#if HAVE_SSE2 + +INSTANTIATE_TEST_CASE_P( + SSE2, SumSquaresTest, + ::testing::Values(TestFuncs(&aom_sum_squares_2d_i16_c, + &aom_sum_squares_2d_i16_sse2))); + +#endif // HAVE_SSE2 + +////////////////////////////////////////////////////////////////////////////// +// 1D version +////////////////////////////////////////////////////////////////////////////// + +typedef uint64_t (*F1D)(const int16_t *src, uint32_t N); +typedef libaom_test::FuncParam TestFuncs1D; + +class SumSquares1DTest : public FunctionEquivalenceTest { + protected: + static const int kIterations = 1000; + static const int kMaxSize = 256; +}; + +TEST_P(SumSquares1DTest, RandomValues) { + DECLARE_ALIGNED(16, int16_t, src[kMaxSize * kMaxSize]); + + for (int iter = 0; iter < kIterations && !HasFatalFailure(); ++iter) { + for (int i = 0; i < kMaxSize * kMaxSize; ++i) + src[i] = rng_(kInt13Max * 2 + 1) - kInt13Max; + + const int N = rng_(2) ? rng_(kMaxSize * kMaxSize + 1 - kMaxSize) + kMaxSize + : rng_(kMaxSize) + 1; + + const uint64_t ref_res = params_.ref_func(src, N); + uint64_t tst_res; + ASM_REGISTER_STATE_CHECK(tst_res = params_.tst_func(src, N)); + + ASSERT_EQ(ref_res, tst_res); + } +} + +TEST_P(SumSquares1DTest, ExtremeValues) { + DECLARE_ALIGNED(16, int16_t, src[kMaxSize * kMaxSize]); + + for (int iter = 0; iter < kIterations && !HasFatalFailure(); ++iter) { + if (rng_(2)) { + for (int i = 0; i < kMaxSize * kMaxSize; ++i) src[i] = kInt13Max; + } else { + for (int i = 0; i < kMaxSize * kMaxSize; ++i) src[i] = -kInt13Max; + } + + const int N = rng_(2) ? rng_(kMaxSize * kMaxSize + 1 - kMaxSize) + kMaxSize + : rng_(kMaxSize) + 1; + + const uint64_t ref_res = params_.ref_func(src, N); + uint64_t tst_res; + ASM_REGISTER_STATE_CHECK(tst_res = params_.tst_func(src, N)); + + ASSERT_EQ(ref_res, tst_res); + } +} + +#if HAVE_SSE2 +INSTANTIATE_TEST_CASE_P(SSE2, SumSquares1DTest, + ::testing::Values(TestFuncs1D( + aom_sum_squares_i16_c, aom_sum_squares_i16_sse2))); + +#endif // HAVE_SSE2 +} // namespace -- cgit v1.2.3 From bbcc64772580c8a979288791afa02d30bc476d2e Mon Sep 17 00:00:00 2001 From: trav90 Date: Fri, 19 Oct 2018 21:52:15 -0500 Subject: Update aom to v1.0.0 Update aom to commit id d14c5bb4f336ef1842046089849dee4a301fbbf0. --- third_party/aom/test/sum_squares_test.cc | 114 +++++++++++++++---------------- 1 file changed, 54 insertions(+), 60 deletions(-) (limited to 'third_party/aom/test/sum_squares_test.cc') diff --git a/third_party/aom/test/sum_squares_test.cc b/third_party/aom/test/sum_squares_test.cc index b8701c196..c03ebad4a 100644 --- a/third_party/aom/test/sum_squares_test.cc +++ b/third_party/aom/test/sum_squares_test.cc @@ -15,8 +15,9 @@ #include "third_party/googletest/src/googletest/include/gtest/gtest.h" -#include "./aom_config.h" -#include "./aom_dsp_rtcd.h" +#include "config/aom_config.h" +#include "config/aom_dsp_rtcd.h" + #include "aom_ports/mem.h" #include "test/acm_random.h" #include "test/clear_system_state.h" @@ -39,89 +40,82 @@ typedef libaom_test::FuncParam TestFuncs; class SumSquaresTest : public ::testing::TestWithParam { public: virtual ~SumSquaresTest() {} - virtual void SetUp() { params_ = this->GetParam(); } - - virtual void TearDown() { libaom_test::ClearSystemState(); } - - protected: - TestFuncs params_; -}; - -TEST_P(SumSquaresTest, OperationCheck) { - ACMRandom rnd(ACMRandom::DeterministicSeed()); - DECLARE_ALIGNED(16, int16_t, src[256 * 256]); - - int failed = 0; - - const int msb = 11; // Up to 12 bit input - const int limit = 1 << (msb + 1); + virtual void SetUp() { + params_ = this->GetParam(); + rnd_.Reset(ACMRandom::DeterministicSeed()); + src_ = reinterpret_cast(aom_memalign(16, 256 * 256 * 2)); + ASSERT_TRUE(src_ != NULL); + } - for (int k = 0; k < kNumIterations; k++) { - int width = 4 * rnd(32); // Up to 128x128 - int height = 4 * rnd(32); // Up to 128x128 - int stride = 4 << rnd(7); // Up to 256 stride - while (stride < width) { // Make sure it's valid - stride = 4 << rnd(7); - } + virtual void TearDown() { + libaom_test::ClearSystemState(); + aom_free(src_); + } + void RunTest(int isRandom); + void GenRandomData(int width, int height, int stride) { + const int msb = 11; // Up to 12 bit input + const int limit = 1 << (msb + 1); for (int ii = 0; ii < height; ii++) { for (int jj = 0; jj < width; jj++) { - src[ii * stride + jj] = rnd(2) ? rnd(limit) : -rnd(limit); + src_[ii * stride + jj] = rnd_(2) ? rnd_(limit) : -rnd_(limit); } } + } - const uint64_t res_ref = params_.ref_func(src, stride, width, height); - uint64_t res_tst; - ASM_REGISTER_STATE_CHECK(res_tst = - params_.tst_func(src, stride, width, height)); - - if (!failed) { - failed = res_ref != res_tst; - EXPECT_EQ(res_ref, res_tst) - << "Error: Sum Squares Test" - << " C output does not match optimized output."; + void GenExtremeData(int width, int height, int stride) { + const int msb = 11; // Up to 12 bit input + const int limit = 1 << (msb + 1); + const int val = rnd_(2) ? limit - 1 : -(limit - 1); + for (int ii = 0; ii < height; ii++) { + for (int jj = 0; jj < width; jj++) { + src_[ii * stride + jj] = val; + } } } -} -TEST_P(SumSquaresTest, ExtremeValues) { - ACMRandom rnd(ACMRandom::DeterministicSeed()); - DECLARE_ALIGNED(16, int16_t, src[256 * 256]); + protected: + TestFuncs params_; + int16_t *src_; + ACMRandom rnd_; +}; +void SumSquaresTest::RunTest(int isRandom) { int failed = 0; - - const int msb = 11; // Up to 12 bit input - const int limit = 1 << (msb + 1); - for (int k = 0; k < kNumIterations; k++) { - int width = 4 * rnd(32); // Up to 128x128 - int height = 4 * rnd(32); // Up to 128x128 - int stride = 4 << rnd(7); // Up to 256 stride - while (stride < width) { // Make sure it's valid - stride = 4 << rnd(7); + const int width = 4 * (rnd_(31) + 1); // Up to 128x128 + const int height = 4 * (rnd_(31) + 1); // Up to 128x128 + int stride = 4 << rnd_(7); // Up to 256 stride + while (stride < width) { // Make sure it's valid + stride = 4 << rnd_(7); } - - int val = rnd(2) ? limit - 1 : -(limit - 1); - for (int ii = 0; ii < height; ii++) { - for (int jj = 0; jj < width; jj++) { - src[ii * stride + jj] = val; - } + if (isRandom) { + GenRandomData(width, height, stride); + } else { + GenExtremeData(width, height, stride); } - - const uint64_t res_ref = params_.ref_func(src, stride, width, height); + const uint64_t res_ref = params_.ref_func(src_, stride, width, height); uint64_t res_tst; ASM_REGISTER_STATE_CHECK(res_tst = - params_.tst_func(src, stride, width, height)); + params_.tst_func(src_, stride, width, height)); if (!failed) { failed = res_ref != res_tst; EXPECT_EQ(res_ref, res_tst) - << "Error: Sum Squares Test" - << " C output does not match optimized output."; + << "Error: Sum Squares Test [" << width << "x" << height + << "] C output does not match optimized output."; } } } +TEST_P(SumSquaresTest, OperationCheck) { + RunTest(1); // GenRandomData +} + +TEST_P(SumSquaresTest, ExtremeValues) { + RunTest(0); // GenExtremeData +} + #if HAVE_SSE2 INSTANTIATE_TEST_CASE_P( -- cgit v1.2.3 From d2499ead93dc4298c0882fe98902acb1b5209f99 Mon Sep 17 00:00:00 2001 From: trav90 Date: Fri, 19 Oct 2018 23:05:00 -0500 Subject: Update libaom to commit ID 1e227d41f0616de9548a673a83a21ef990b62591 --- third_party/aom/test/sum_squares_test.cc | 42 ++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'third_party/aom/test/sum_squares_test.cc') diff --git a/third_party/aom/test/sum_squares_test.cc b/third_party/aom/test/sum_squares_test.cc index c03ebad4a..f10998498 100644 --- a/third_party/aom/test/sum_squares_test.cc +++ b/third_party/aom/test/sum_squares_test.cc @@ -52,6 +52,7 @@ class SumSquaresTest : public ::testing::TestWithParam { aom_free(src_); } void RunTest(int isRandom); + void RunSpeedTest(); void GenRandomData(int width, int height, int stride) { const int msb = 11; // Up to 12 bit input @@ -108,6 +109,38 @@ void SumSquaresTest::RunTest(int isRandom) { } } +void SumSquaresTest::RunSpeedTest() { + for (int block = BLOCK_4X4; block < BLOCK_SIZES_ALL; block++) { + const int width = block_size_wide[block]; // Up to 128x128 + const int height = block_size_high[block]; // Up to 128x128 + int stride = 4 << rnd_(7); // Up to 256 stride + while (stride < width) { // Make sure it's valid + stride = 4 << rnd_(7); + } + GenExtremeData(width, height, stride); + const int num_loops = 1000000000 / (width + height); + aom_usec_timer timer; + aom_usec_timer_start(&timer); + + for (int i = 0; i < num_loops; ++i) + params_.ref_func(src_, stride, width, height); + + aom_usec_timer_mark(&timer); + const int elapsed_time = static_cast(aom_usec_timer_elapsed(&timer)); + printf("SumSquaresTest C %3dx%-3d: %7.2f ns\n", width, height, + 1000.0 * elapsed_time / num_loops); + + aom_usec_timer timer1; + aom_usec_timer_start(&timer1); + for (int i = 0; i < num_loops; ++i) + params_.tst_func(src_, stride, width, height); + aom_usec_timer_mark(&timer1); + const int elapsed_time1 = static_cast(aom_usec_timer_elapsed(&timer1)); + printf("SumSquaresTest Test %3dx%-3d: %7.2f ns\n", width, height, + 1000.0 * elapsed_time1 / num_loops); + } +} + TEST_P(SumSquaresTest, OperationCheck) { RunTest(1); // GenRandomData } @@ -116,6 +149,8 @@ TEST_P(SumSquaresTest, ExtremeValues) { RunTest(0); // GenExtremeData } +TEST_P(SumSquaresTest, DISABLED_Speed) { RunSpeedTest(); } + #if HAVE_SSE2 INSTANTIATE_TEST_CASE_P( @@ -125,6 +160,13 @@ INSTANTIATE_TEST_CASE_P( #endif // HAVE_SSE2 +#if HAVE_AVX2 +INSTANTIATE_TEST_CASE_P( + AVX2, SumSquaresTest, + ::testing::Values(TestFuncs(&aom_sum_squares_2d_i16_c, + &aom_sum_squares_2d_i16_avx2))); +#endif // HAVE_AVX2 + ////////////////////////////////////////////////////////////////////////////// // 1D version ////////////////////////////////////////////////////////////////////////////// -- cgit v1.2.3