Skip to content

Commit be9d8cc

Browse files
committed
benches.
1 parent 5fde35f commit be9d8cc

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

linalg/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,5 +97,10 @@ name = "x86_64"
9797
harness = false
9898

9999
[[bench]]
100+
bench = false
100101
name = "intel"
101102
harness = false
103+
104+
[[bench]]
105+
name = "activations"
106+
harness = false

linalg/benches/activations.rs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
use criterion::{black_box, criterion_group, criterion_main, BatchSize, BenchmarkId, Criterion};
2+
use tract_linalg::frame::activations::{definitions, reference, ActivationKer, Program};
3+
4+
fn crit(c: &mut Criterion, name: &str, r: impl Fn(f32) -> f32, prog: &Program<f32>) {
5+
let mut group = c.benchmark_group(name);
6+
for size in [1i32, 32, 256, 1024, 8192].iter() {
7+
group.throughput(criterion::Throughput::Elements(*size as u64));
8+
group.bench_with_input(BenchmarkId::new("Reference", size), size, |b, size| {
9+
b.iter_batched(
10+
|| vec![1.0f32; *size as usize],
11+
|v| {
12+
for x in v {
13+
r(black_box(x));
14+
}
15+
},
16+
BatchSize::LargeInput,
17+
)
18+
});
19+
#[allow(unused_mut)]
20+
let mut vms = vec!(tract_linalg::generic::activations::SActivations::act());
21+
#[cfg(target_arch="aarch64")]
22+
{
23+
vms.push(tract_linalg::arm64::arm64simd_act_f32_32n::act());
24+
}
25+
26+
for vm in vms {
27+
group.bench_with_input(BenchmarkId::new(vm.name(), size), size, |b, size| {
28+
b.iter_batched(
29+
|| vec![1.0f32; *size as usize],
30+
|mut v| vm.run(prog, &mut v),
31+
BatchSize::LargeInput,
32+
)
33+
});
34+
}
35+
}
36+
}
37+
38+
fn criterion_benchmark(c: &mut Criterion) {
39+
crit(c, "relu", reference::relu, &definitions::relu());
40+
crit(c, "hardswish", reference::hardswish, &definitions::hard_swish());
41+
/*
42+
crit(c, "exp2f", reference::exp2f, &definitions::exp2f());
43+
crit(c, "sigmoid", reference::sigmoid, &definitions::sigmoid());
44+
*/
45+
}
46+
47+
criterion_group!(benches, criterion_benchmark);
48+
criterion_main!(benches);

linalg/src/frame/activations.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ pub union OpOrConst<T: LADatum> {
142142
}
143143

144144
pub trait Activation<T: LADatum>: Send + Sync + Debug + dyn_clone::DynClone {
145+
fn name(&self) -> &'static str;
145146
fn run(&self, prog: &Program<T>, vec: &mut [T]) -> TractResult<()>;
146147
}
147148

@@ -159,6 +160,10 @@ where
159160
T: LADatum,
160161
K: ActivationKer<T> + Clone,
161162
{
163+
fn name(&self) -> &'static str {
164+
K::name()
165+
}
166+
162167
fn run(&self, program: &Program<T>, vec: &mut [T]) -> TractResult<()> {
163168
let ker_program = program.translate();
164169
run_over_slice_with_alignment(

0 commit comments

Comments
 (0)