Skip to content

Commit

Permalink
benches.
Browse files Browse the repository at this point in the history
  • Loading branch information
kali committed May 22, 2023
1 parent b504cf9 commit 5ce9d17
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
5 changes: 5 additions & 0 deletions linalg/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,10 @@ name = "x86_64"
harness = false

[[bench]]
bench = false
name = "intel"
harness = false

[[bench]]
name = "activations"
harness = false
48 changes: 48 additions & 0 deletions linalg/benches/activations.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
use criterion::{black_box, criterion_group, criterion_main, BatchSize, BenchmarkId, Criterion};
use tract_linalg::frame::activations::{definitions, reference, ActivationKer, Program};

fn crit(c: &mut Criterion, name: &str, r: impl Fn(f32) -> f32, prog: &Program<f32>) {
let mut group = c.benchmark_group(name);
for size in [1i32, 32, 256, 1024, 8192].iter() {
group.throughput(criterion::Throughput::Elements(*size as u64));
group.bench_with_input(BenchmarkId::new("Reference", size), size, |b, size| {
b.iter_batched(
|| vec![1.0f32; *size as usize],
|v| {
for x in v {
r(black_box(x));
}
},
BatchSize::LargeInput,
)
});
#[allow(unused_mut)]
let mut vms = vec!(tract_linalg::generic::activations::SActivations::act());
#[cfg(target_arch="aarch64")]
{
vms.push(tract_linalg::arm64::arm64simd_act_f32_32n::act());
}

for vm in vms {
group.bench_with_input(BenchmarkId::new(vm.name(), size), size, |b, size| {
b.iter_batched(
|| vec![1.0f32; *size as usize],
|mut v| vm.run(prog, &mut v),
BatchSize::LargeInput,
)
});
}
}
}

fn criterion_benchmark(c: &mut Criterion) {
crit(c, "relu", reference::relu, &definitions::relu());
crit(c, "hardswish", reference::hardswish, &definitions::hard_swish());
/*
crit(c, "exp2f", reference::exp2f, &definitions::exp2f());
crit(c, "sigmoid", reference::sigmoid, &definitions::sigmoid());
*/
}

criterion_group!(benches, criterion_benchmark);
criterion_main!(benches);
5 changes: 5 additions & 0 deletions linalg/src/frame/activations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ pub union OpOrConst<T: LADatum> {
}

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

Expand All @@ -159,6 +160,10 @@ where
T: LADatum,
K: ActivationKer<T> + Clone,
{
fn name(&self) -> &'static str {
K::name()
}

fn run(&self, program: &Program<T>, vec: &mut [T]) -> TractResult<()> {
let ker_program = program.translate();
run_over_slice_with_alignment(
Expand Down

0 comments on commit 5ce9d17

Please sign in to comment.