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
// The int8 composition layers and their calibration against tinymind (C++)'s
// QMul (with buildQMulRequantizer), QConcat2_2D (with buildRescaler) and
// QPad2D. tests/golden/compose/stdout.txt is the output of
// scripts/cpp/compose_sweep.cpp, which draws the same scales, parameters and
// tensors from the same generator, in the same order;
// scripts/compare-with-cpp.sh rebuilds it and checks the golden is current.
// See that program for what the cases cover.
// The calibration functions need the `std` feature.
#![cfg(feature = "std")]
// The sweep itself is in tests/sweeps/compose.rs, which bench/ also runs on
// Cortex-M.
#[path = "sweeps/compose.rs"]
mod compose;
use tinymind::int8::Requantizer;
use tinymind::int8::calibration::{build_mul_requantizer, build_rescaler};
struct Calibrate;
impl compose::Calibrate for Calibrate {
fn mul_requantizer(
&mut self,
sa: f32,
sb: f32,
so: f32,
zo: i8,
qmin: i32,
qmax: i32,
) -> Requantizer {
build_mul_requantizer(sa, sb, so, zo.into(), qmin, qmax)
}
fn rescaler(&mut self, s: f32, so: f32, zo: i8, qmin: i32, qmax: i32) -> Requantizer {
build_rescaler(s, so, zo.into(), qmin, qmax)
}
}
#[test]
fn compose_matches_cpp() {
let mut out = String::new();
compose::report(&mut out, &mut Calibrate);
assert_eq!(out, include_str!("golden/compose/stdout.txt"));
}