summaryrefslogtreecommitdiffstats
path: root/third_party/aom/test/disflow_test.cc
blob: 124c9a96c784c243622e019eefb11fe9060f2bf3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*
 * Copyright (c) 2023, 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 "aom_dsp/flow_estimation/disflow.h"

#include "third_party/googletest/src/googletest/include/gtest/gtest.h"

#include "config/aom_dsp_rtcd.h"
#include "test/acm_random.h"
#include "test/register_state_check.h"
#include "test/util.h"
#include "test/yuv_video_source.h"

namespace {

using ComputeFlowAtPointFunc = void (*)(const uint8_t *src, const uint8_t *ref,
                                        int x, int y, int width, int height,
                                        int stride, double *u, double *v);

class ComputeFlowTest
    : public ::testing::TestWithParam<ComputeFlowAtPointFunc> {
 public:
  ComputeFlowTest()
      : target_func_(GetParam()),
        rnd_(libaom_test::ACMRandom::DeterministicSeed()) {}

 protected:
  void RunCheckOutput(int run_times);
  ComputeFlowAtPointFunc target_func_;

  libaom_test::ACMRandom rnd_;
};
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(ComputeFlowTest);

void ComputeFlowTest::RunCheckOutput(int run_times) {
  constexpr int kWidth = 352;
  constexpr int kHeight = 288;

  ::libaom_test::YUVVideoSource video("bus_352x288_420_f20_b8.yuv",
                                      AOM_IMG_FMT_I420, kWidth, kHeight, 30, 1,
                                      0, 2);
  // Use Y (Luminance) plane.
  video.Begin();
  uint8_t *src = video.img()->planes[0];
  ASSERT_NE(src, nullptr);
  video.Next();
  uint8_t *ref = video.img()->planes[0];
  ASSERT_NE(ref, nullptr);

  // Pick a random value between -5 and 5. The range was chosen arbitrarily as
  // u and v can take any kind of value in practise, but it shouldn't change the
  // outcome of the tests.
  const double u_rand = (static_cast<double>(rnd_.Rand8()) / 255) * 10 - 5;
  double u_ref = u_rand;
  double u_test = u_rand;

  const double v_rand = (static_cast<double>(rnd_.Rand8()) / 255) * 10 - 5;
  double v_ref = v_rand;
  double v_test = v_rand;

  // Pick a random point in the frame. If the frame is 352x288, that means we
  // can call the function on all values of x comprised between 8 and 344, and
  // all values of y comprised between 8 and 280.
  const int x = rnd_((kWidth - 8) - 8 + 1) + 8;
  const int y = rnd_((kHeight - 8) - 8 + 1) + 8;

  aom_usec_timer ref_timer, test_timer;

  aom_compute_flow_at_point_c(src, ref, x, y, kWidth, kHeight, kWidth, &u_ref,
                              &v_ref);

  target_func_(src, ref, x, y, kWidth, kHeight, kWidth, &u_test, &v_test);

  if (run_times > 1) {
    aom_usec_timer_start(&ref_timer);
    for (int i = 0; i < run_times; ++i) {
      aom_compute_flow_at_point_c(src, ref, x, y, kWidth, kHeight, kWidth,
                                  &u_ref, &v_ref);
    }
    aom_usec_timer_mark(&ref_timer);
    const double elapsed_time_c =
        static_cast<double>(aom_usec_timer_elapsed(&ref_timer));

    aom_usec_timer_start(&test_timer);
    for (int i = 0; i < run_times; ++i) {
      target_func_(src, ref, x, y, kWidth, kHeight, kWidth, &u_test, &v_test);
    }
    aom_usec_timer_mark(&test_timer);
    const double elapsed_time_simd =
        static_cast<double>(aom_usec_timer_elapsed(&test_timer));

    printf("c_time=%fns \t simd_time=%fns \t speedup=%.2f\n", elapsed_time_c,
           elapsed_time_simd, (elapsed_time_c / elapsed_time_simd));
  } else {
    ASSERT_EQ(u_ref, u_test);
    ASSERT_EQ(v_ref, v_test);
  }
}

TEST_P(ComputeFlowTest, CheckOutput) { RunCheckOutput(1); }

TEST_P(ComputeFlowTest, DISABLED_Speed) { RunCheckOutput(10000000); }

#if HAVE_SSE4_1
INSTANTIATE_TEST_SUITE_P(SSE4_1, ComputeFlowTest,
                         ::testing::Values(aom_compute_flow_at_point_sse4_1));
#endif

#if HAVE_NEON
INSTANTIATE_TEST_SUITE_P(NEON, ComputeFlowTest,
                         ::testing::Values(aom_compute_flow_at_point_neon));
#endif

}  // namespace