bench.rs 4.78 KB
Newer Older
1 2 3 4 5 6 7 8 9
// Copyright (c) 2017-2018, The rav1e contributors. 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.

10
extern crate criterion;
Michael Bebenita's avatar
Michael Bebenita committed
11 12
extern crate rand;
extern crate rav1e;
13

rzumer's avatar
rzumer committed
14
mod predict;
Luca Barbato's avatar
Luca Barbato committed
15
mod transform;
Luca Barbato's avatar
Luca Barbato committed
16
mod me;
17

Raphaël Zumer's avatar
Raphaël Zumer committed
18
use rav1e::*;
19
use rav1e::cdef::cdef_filter_frame;
Kyle Siefring's avatar
Kyle Siefring committed
20
use rav1e::context::*;
Michael Bebenita's avatar
Michael Bebenita committed
21
use rav1e::partition::*;
rzumer's avatar
rzumer committed
22
use rav1e::predict::*;
23
use rav1e::rdo::rdo_cfl_alpha;
Luca Barbato's avatar
Luca Barbato committed
24 25
use transform::transform;

Raphaël Zumer's avatar
Raphaël Zumer committed
26 27 28
use criterion::*;
use std::time::Duration;

rzumer's avatar
rzumer committed
29 30
#[cfg(feature = "comparative_bench")]
mod comparative;
Luca Barbato's avatar
Luca Barbato committed
31

32
fn write_b(c: &mut Criterion) {
Michael Bebenita's avatar
Michael Bebenita committed
33 34 35
  for &tx_size in &[TxSize::TX_4X4, TxSize::TX_8X8] {
    for &qi in &[20, 55] {
      let n = format!("write_b_bench({:?}, {})", tx_size, qi);
36
      c.bench_function(&n, move |b| write_b_bench(b, tx_size, qi));
Luca Barbato's avatar
Luca Barbato committed
37
    }
Michael Bebenita's avatar
Michael Bebenita committed
38
  }
Thomas Daede's avatar
Thomas Daede committed
39 40
}

Luca Barbato's avatar
Luca Barbato committed
41
fn write_b_bench(b: &mut Bencher, tx_size: TxSize, qindex: usize) {
42
  #[cfg(feature = "aom")]
Michael Bebenita's avatar
Michael Bebenita committed
43 44 45 46
  unsafe {
    av1_rtcd();
    aom_dsp_rtcd();
  }
47
  let config =
48
    EncoderConfig { quantizer: qindex, speed_settings: SpeedSettings::from_preset(10), ..Default::default() };
49
  let mut fi = FrameInvariants::new(1024, 1024, config);
Monty Montgomery's avatar
Monty Montgomery committed
50
  let mut w = ec::WriterEncoder::new();
Frank Bossen's avatar
Frank Bossen committed
51
  let fc = CDFContext::new(fi.base_q_idx);
Michael Bebenita's avatar
Michael Bebenita committed
52
  let bc = BlockContext::new(fi.sb_width * 16, fi.sb_height * 16);
53
  let mut fs = FrameState::new(&fi, Default::default());
54
  // For now, restoration unit size is locked to superblock size.
55 56
  let rc = RestorationContext::new(fi.sb_width, fi.sb_height);
  let mut cw = ContextWriter::new(fc, bc, rc);
Michael Bebenita's avatar
Michael Bebenita committed
57 58 59 60 61

  let tx_type = TxType::DCT_DCT;

  let sbx = 0;
  let sby = 0;
62
  let ac = &[0i16; 32 * 32];
Michael Bebenita's avatar
Michael Bebenita committed
63 64 65

  b.iter(|| {
    for &mode in RAV1E_INTRA_MODES {
Michael Bebenita's avatar
Michael Bebenita committed
66
      let sbo = SuperBlockOffset { x: sbx, y: sby };
Michael Bebenita's avatar
Michael Bebenita committed
67
      for p in 1..3 {
68
        fs.qc.update(fi.base_q_idx, tx_size, mode.is_intra(), 8, fi.dc_delta_q[p], fi.ac_delta_q[p]);
Michael Bebenita's avatar
Michael Bebenita committed
69 70
        for by in 0..8 {
          for bx in 0..8 {
71
            // For ex, 8x8 tx should be applied to even numbered (bx,by)
Kyle Siefring's avatar
Kyle Siefring committed
72 73 74 75 76
            if (tx_size.width_mi() >> 1) & bx != 0
              || (tx_size.height_mi() >> 1) & by != 0
            {
              continue;
            };
Michael Bebenita's avatar
Michael Bebenita committed
77
            let bo = sbo.block_offset(bx, by);
Michael Bebenita's avatar
Michael Bebenita committed
78
            let tx_bo = BlockOffset { x: bo.x + bx, y: bo.y + by };
Michael Bebenita's avatar
Michael Bebenita committed
79 80 81 82 83
            let po = tx_bo.plane_offset(&fs.input.planes[p].cfg);
            encode_tx_block(
              &mut fi,
              &mut fs,
              &mut cw,
84
              &mut w,
Michael Bebenita's avatar
Michael Bebenita committed
85 86 87 88 89 90 91
              p,
              &bo,
              mode,
              tx_size,
              tx_type,
              tx_size.block_size(),
              &po,
92
              false,
93 94
              8,
              ac,
95 96
              0,
              false
Michael Bebenita's avatar
Michael Bebenita committed
97 98
            );
          }
99
        }
Michael Bebenita's avatar
Michael Bebenita committed
100 101 102
      }
    }
  });
Luca Barbato's avatar
Luca Barbato committed
103 104
}

105 106 107 108 109 110 111 112 113
fn cdef_frame(c: &mut Criterion) {
  let w = 128;
  let h = 128;
  let n = format!("cdef_frame({}, {})", w, h);
  c.bench_function(&n, move |b| cdef_frame_bench(b, w, h));
}

fn cdef_frame_bench(b: &mut Bencher, w: usize, h: usize) {
  let config =
114
    EncoderConfig { quantizer: 100, speed_settings: SpeedSettings::from_preset(10), ..Default::default() };
115 116
  let fi = FrameInvariants::new(w, h, config);
  let mut bc = BlockContext::new(fi.sb_width * 16, fi.sb_height * 16);
117
  let mut fs = FrameState::new(&fi, Default::default());
118 119 120 121

  b.iter(|| cdef_filter_frame(&fi, &mut fs.rec, &mut bc, 8));
}

122 123 124 125 126 127 128 129 130 131 132 133 134 135
fn cfl_rdo(c: &mut Criterion) {
  for &bsize in &[
    BlockSize::BLOCK_4X4,
    BlockSize::BLOCK_8X8,
    BlockSize::BLOCK_16X16,
    BlockSize::BLOCK_32X32
  ] {
    let n = format!("cfl_rdo({:?})", bsize);
    c.bench_function(&n, move |b| cfl_rdo_bench(b, bsize));
  }
}

fn cfl_rdo_bench(b: &mut Bencher, bsize: BlockSize) {
  let config =
136
    EncoderConfig { quantizer: 100, speed_settings: SpeedSettings::from_preset(10), ..Default::default() };
137
  let fi = FrameInvariants::new(1024, 1024, config);
138
  let mut fs = FrameState::new(&fi, Default::default());
139
  let offset = BlockOffset { x: 1, y: 1 };
140
  b.iter(|| rdo_cfl_alpha(&mut fs, &offset, bsize, 8, Default::default()))
141 142
}

Kyle Siefring's avatar
Kyle Siefring committed
143
criterion_group!(intra_prediction, predict::pred_bench,);
144

145
criterion_group!(cfl, cfl_rdo);
146
criterion_group!(cdef, cdef_frame);
147
criterion_group!(write_block, write_b);
148 149 150 151
criterion_group!{ name = me;
                  config = Criterion::default().warm_up_time(Duration::new(1,0));
                  targets = me::get_sad
}
152

rzumer's avatar
rzumer committed
153
#[cfg(feature = "comparative_bench")]
154
criterion_main!(comparative::intra_prediction);
rzumer's avatar
rzumer committed
155 156

#[cfg(not(feature = "comparative_bench"))]
Luca Barbato's avatar
Luca Barbato committed
157
criterion_main!(write_block, intra_prediction, cdef, cfl, me, transform);