Skip to content

Commit

Permalink
Add benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
skailasa committed Jan 3, 2025
1 parent dae6454 commit 57e8b5d
Show file tree
Hide file tree
Showing 4 changed files with 366 additions and 2 deletions.
8 changes: 8 additions & 0 deletions kifmm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ harness = false
name = "laplace_direct_f32"
harness = false

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

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

[package.metadata.docs.rs]
cargo-args = ["-Zunstable-options", "-Zrustdoc-scrape-examples"]
rustdoc-args = [ "--html-in-header", "./src/docs-header.html" ]
Expand Down
179 changes: 179 additions & 0 deletions kifmm/benches/helmholtz_direct_f32.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
use std::time::Duration;

use criterion::{criterion_group, criterion_main, Criterion};
use green_kernels::traits::Kernel;
use green_kernels::{helmholtz_3d::Helmholtz3dKernel, types::GreenKernelEvalType};
use kifmm::tree::helpers::points_fixture;
use num::{Complex, One};

Check warning on line 7 in kifmm/benches/helmholtz_direct_f32.rs

View workflow job for this annotation

GitHub Actions / Rust style checks (--features "strict")

Diff in /home/runner/work/kifmm/kifmm/kifmm/benches/helmholtz_direct_f32.rs

Check warning on line 7 in kifmm/benches/helmholtz_direct_f32.rs

View workflow job for this annotation

GitHub Actions / Rust style checks

Diff in /home/runner/work/kifmm/kifmm/kifmm/benches/helmholtz_direct_f32.rs

Check warning on line 7 in kifmm/benches/helmholtz_direct_f32.rs

View workflow job for this annotation

GitHub Actions / Rust style checks

Diff in /home/runner/work/kifmm/kifmm/kifmm/benches/helmholtz_direct_f32.rs
use rlst::{c32, c64, rlst_dynamic_array2, RawAccess, RawAccessMut};

Check failure on line 8 in kifmm/benches/helmholtz_direct_f32.rs

View workflow job for this annotation

GitHub Actions / Run Rust tests (stable, mpich, --features "strict")

unused import: `c64`

Check failure on line 8 in kifmm/benches/helmholtz_direct_f32.rs

View workflow job for this annotation

GitHub Actions / Run Rust tests (stable, openmpi, --features "strict")

unused import: `c64`

Check failure on line 8 in kifmm/benches/helmholtz_direct_f32.rs

View workflow job for this annotation

GitHub Actions / Run Rust tests (stable, mpich, --features "strict")

unused import: `c64`

Check failure on line 8 in kifmm/benches/helmholtz_direct_f32.rs

View workflow job for this annotation

GitHub Actions / Run Rust tests (stable, openmpi, --features "strict")

unused import: `c64`


fn multithreaded_direct_f64(c: &mut Criterion) {
let mut group = c.benchmark_group("Multi Threaded Direct f64");

group
.sample_size(10)
.measurement_time(Duration::from_secs(15));

{
let nsources = 20000;
let ntargets = 20000;
let sources = points_fixture::<f32>(nsources, None, None, Some(0));
let targets = points_fixture::<f32>(ntargets, None, None, Some(1));

// FFT based M2L for a vector of charges
let nvecs = 1;
let tmp = vec![Complex::one(); nsources * nvecs];
let mut charges = rlst_dynamic_array2!(c32, [nsources, nvecs]);
charges.data_mut().copy_from_slice(&tmp);
let wavenumber = 1f32;

let kernel = Helmholtz3dKernel::new(wavenumber);

let mut result = rlst_dynamic_array2!(c32, [nsources, nvecs]);

group.bench_function(format!("N={nsources}"), |b| {
b.iter(|| {
kernel.evaluate_mt(
GreenKernelEvalType::Value,
sources.data(),
targets.data(),
charges.data(),
result.data_mut(),
)
})
});
}

{
let nsources = 100000;
let ntargets = 100000;
let sources = points_fixture::<f32>(nsources, None, None, Some(0));
let targets = points_fixture::<f32>(ntargets, None, None, Some(1));

// FFT based M2L for a vector of charges
let nvecs = 1;
let tmp = vec![Complex::one(); nsources * nvecs];

Check warning on line 56 in kifmm/benches/helmholtz_direct_f32.rs

View workflow job for this annotation

GitHub Actions / Rust style checks (--features "strict")

Diff in /home/runner/work/kifmm/kifmm/kifmm/benches/helmholtz_direct_f32.rs

Check warning on line 56 in kifmm/benches/helmholtz_direct_f32.rs

View workflow job for this annotation

GitHub Actions / Rust style checks

Diff in /home/runner/work/kifmm/kifmm/kifmm/benches/helmholtz_direct_f32.rs

Check warning on line 56 in kifmm/benches/helmholtz_direct_f32.rs

View workflow job for this annotation

GitHub Actions / Rust style checks

Diff in /home/runner/work/kifmm/kifmm/kifmm/benches/helmholtz_direct_f32.rs
let mut charges = rlst_dynamic_array2!(c32, [nsources, nvecs]);
charges.data_mut().copy_from_slice(&tmp);
let wavenumber =1f32;

let kernel = Helmholtz3dKernel::new(wavenumber);

let mut result = rlst_dynamic_array2!(c32, [nsources, nvecs]);

group.bench_function(format!("N={nsources}"), |b| {
b.iter(|| {
kernel.evaluate_mt(
GreenKernelEvalType::Value,
sources.data(),
targets.data(),
charges.data(),
result.data_mut(),
)
})
});
}

{
let nsources = 500000;
let ntargets = 500000;
let sources = points_fixture::<f32>(nsources, None, None, Some(0));
let targets = points_fixture::<f32>(ntargets, None, None, Some(1));

// FFT based M2L for a vector of charges
let nvecs = 1;
let tmp = vec![Complex::one(); nsources * nvecs];
let mut charges = rlst_dynamic_array2!(c32, [nsources, nvecs]);
charges.data_mut().copy_from_slice(&tmp);
let wavenumber = 1f32;

let kernel = Helmholtz3dKernel::new(wavenumber);

let mut result = rlst_dynamic_array2!(c32, [nsources, nvecs]);

group.bench_function(format!("N={nsources}"), |b| {
b.iter(|| {
kernel.evaluate_mt(
GreenKernelEvalType::Value,
sources.data(),
targets.data(),
charges.data(),
result.data_mut(),
)
})
});
}
}

fn singlethreaded_direct_f64(c: &mut Criterion) {
let mut group = c.benchmark_group("Single Threaded Direct f64");

group
.sample_size(10)
.measurement_time(Duration::from_secs(15));

{
let nsources = 5000;
let ntargets = 5000;
let sources = points_fixture::<f32>(nsources, None, None, Some(0));
let targets = points_fixture::<f32>(ntargets, None, None, Some(1));

// FFT based M2L for a vector of charges
let nvecs = 1;
let tmp = vec![Complex::one(); nsources * nvecs];
let mut charges = rlst_dynamic_array2!(c32, [nsources, nvecs]);
charges.data_mut().copy_from_slice(&tmp);
let wavenumber = 1f32;

let kernel = Helmholtz3dKernel::new(wavenumber);

let mut result = rlst_dynamic_array2!(c32, [nsources, nvecs]);

group.bench_function(format!("N={nsources}"), |b| {
b.iter(|| {
kernel.evaluate_st(
GreenKernelEvalType::Value,
sources.data(),
targets.data(),
charges.data(),
result.data_mut(),
)
})
});
}

{
let nsources = 20000;
let ntargets = 20000;
let sources = points_fixture::<f32>(nsources, None, None, Some(0));
let targets = points_fixture::<f32>(ntargets, None, None, Some(1));

// FFT based M2L for a vector of charges
let nvecs = 1;
let tmp = vec![Complex::one(); nsources * nvecs];
let mut charges = rlst_dynamic_array2!(c32, [nsources, nvecs]);
charges.data_mut().copy_from_slice(&tmp);
let wavenumber = 1f32;

let kernel = Helmholtz3dKernel::new(wavenumber);

let mut result = rlst_dynamic_array2!(c32, [nsources, nvecs]);

group.bench_function(format!("N={nsources}"), |b| {
b.iter(|| {
kernel.evaluate_st(
GreenKernelEvalType::Value,
sources.data(),
targets.data(),
charges.data(),
result.data_mut(),
)
})
});
}
}

criterion_group!(d_f64, multithreaded_direct_f64, singlethreaded_direct_f64);

Check warning on line 177 in kifmm/benches/helmholtz_direct_f32.rs

View workflow job for this annotation

GitHub Actions / Rust style checks (--features "strict")

Diff in /home/runner/work/kifmm/kifmm/kifmm/benches/helmholtz_direct_f32.rs

Check warning on line 177 in kifmm/benches/helmholtz_direct_f32.rs

View workflow job for this annotation

GitHub Actions / Rust style checks

Diff in /home/runner/work/kifmm/kifmm/kifmm/benches/helmholtz_direct_f32.rs

Check warning on line 177 in kifmm/benches/helmholtz_direct_f32.rs

View workflow job for this annotation

GitHub Actions / Rust style checks

Diff in /home/runner/work/kifmm/kifmm/kifmm/benches/helmholtz_direct_f32.rs

criterion_main!(d_f64);
179 changes: 179 additions & 0 deletions kifmm/benches/helmholtz_direct_f64.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
use std::time::Duration;

use criterion::{criterion_group, criterion_main, Criterion};
use green_kernels::traits::Kernel;
use green_kernels::{helmholtz_3d::Helmholtz3dKernel, types::GreenKernelEvalType};
use kifmm::tree::helpers::points_fixture;
use num::{Complex, One};

Check warning on line 7 in kifmm/benches/helmholtz_direct_f64.rs

View workflow job for this annotation

GitHub Actions / Rust style checks (--features "strict")

Diff in /home/runner/work/kifmm/kifmm/kifmm/benches/helmholtz_direct_f64.rs

Check warning on line 7 in kifmm/benches/helmholtz_direct_f64.rs

View workflow job for this annotation

GitHub Actions / Rust style checks

Diff in /home/runner/work/kifmm/kifmm/kifmm/benches/helmholtz_direct_f64.rs

Check warning on line 7 in kifmm/benches/helmholtz_direct_f64.rs

View workflow job for this annotation

GitHub Actions / Rust style checks

Diff in /home/runner/work/kifmm/kifmm/kifmm/benches/helmholtz_direct_f64.rs
use rlst::{c64, rlst_dynamic_array2, RawAccess, RawAccessMut};


fn multithreaded_direct_f64(c: &mut Criterion) {
let mut group = c.benchmark_group("Multi Threaded Direct f64");

group
.sample_size(10)
.measurement_time(Duration::from_secs(15));

{
let nsources = 20000;
let ntargets = 20000;
let sources = points_fixture::<f64>(nsources, None, None, Some(0));
let targets = points_fixture::<f64>(ntargets, None, None, Some(1));

// FFT based M2L for a vector of charges
let nvecs = 1;
let tmp = vec![Complex::one(); nsources * nvecs];
let mut charges = rlst_dynamic_array2!(c64, [nsources, nvecs]);
charges.data_mut().copy_from_slice(&tmp);
let wavenumber = 1f64;

let kernel = Helmholtz3dKernel::new(wavenumber);

let mut result = rlst_dynamic_array2!(c64, [nsources, nvecs]);

group.bench_function(format!("N={nsources}"), |b| {
b.iter(|| {
kernel.evaluate_mt(
GreenKernelEvalType::Value,
sources.data(),
targets.data(),
charges.data(),
result.data_mut(),
)
})
});
}

{
let nsources = 100000;
let ntargets = 100000;
let sources = points_fixture::<f64>(nsources, None, None, Some(0));
let targets = points_fixture::<f64>(ntargets, None, None, Some(1));

// FFT based M2L for a vector of charges
let nvecs = 1;
let tmp = vec![Complex::one(); nsources * nvecs];

Check warning on line 56 in kifmm/benches/helmholtz_direct_f64.rs

View workflow job for this annotation

GitHub Actions / Rust style checks (--features "strict")

Diff in /home/runner/work/kifmm/kifmm/kifmm/benches/helmholtz_direct_f64.rs

Check warning on line 56 in kifmm/benches/helmholtz_direct_f64.rs

View workflow job for this annotation

GitHub Actions / Rust style checks

Diff in /home/runner/work/kifmm/kifmm/kifmm/benches/helmholtz_direct_f64.rs

Check warning on line 56 in kifmm/benches/helmholtz_direct_f64.rs

View workflow job for this annotation

GitHub Actions / Rust style checks

Diff in /home/runner/work/kifmm/kifmm/kifmm/benches/helmholtz_direct_f64.rs
let mut charges = rlst_dynamic_array2!(c64, [nsources, nvecs]);
charges.data_mut().copy_from_slice(&tmp);
let wavenumber =1f64;

let kernel = Helmholtz3dKernel::new(wavenumber);

let mut result = rlst_dynamic_array2!(c64, [nsources, nvecs]);

group.bench_function(format!("N={nsources}"), |b| {
b.iter(|| {
kernel.evaluate_mt(
GreenKernelEvalType::Value,
sources.data(),
targets.data(),
charges.data(),
result.data_mut(),
)
})
});
}

{
let nsources = 500000;
let ntargets = 500000;
let sources = points_fixture::<f64>(nsources, None, None, Some(0));
let targets = points_fixture::<f64>(ntargets, None, None, Some(1));

// FFT based M2L for a vector of charges
let nvecs = 1;
let tmp = vec![Complex::one(); nsources * nvecs];
let mut charges = rlst_dynamic_array2!(c64, [nsources, nvecs]);
charges.data_mut().copy_from_slice(&tmp);
let wavenumber = 1f64;

let kernel = Helmholtz3dKernel::new(wavenumber);

let mut result = rlst_dynamic_array2!(c64, [nsources, nvecs]);

group.bench_function(format!("N={nsources}"), |b| {
b.iter(|| {
kernel.evaluate_mt(
GreenKernelEvalType::Value,
sources.data(),
targets.data(),
charges.data(),
result.data_mut(),
)
})
});
}
}

fn singlethreaded_direct_f64(c: &mut Criterion) {
let mut group = c.benchmark_group("Single Threaded Direct f64");

group
.sample_size(10)
.measurement_time(Duration::from_secs(15));

{
let nsources = 5000;
let ntargets = 5000;
let sources = points_fixture::<f64>(nsources, None, None, Some(0));
let targets = points_fixture::<f64>(ntargets, None, None, Some(1));

// FFT based M2L for a vector of charges
let nvecs = 1;
let tmp = vec![Complex::one(); nsources * nvecs];
let mut charges = rlst_dynamic_array2!(c64, [nsources, nvecs]);
charges.data_mut().copy_from_slice(&tmp);
let wavenumber = 1f64;

let kernel = Helmholtz3dKernel::new(wavenumber);

let mut result = rlst_dynamic_array2!(c64, [nsources, nvecs]);

group.bench_function(format!("N={nsources}"), |b| {
b.iter(|| {
kernel.evaluate_st(
GreenKernelEvalType::Value,
sources.data(),
targets.data(),
charges.data(),
result.data_mut(),
)
})
});
}

{
let nsources = 20000;
let ntargets = 20000;
let sources = points_fixture::<f64>(nsources, None, None, Some(0));
let targets = points_fixture::<f64>(ntargets, None, None, Some(1));

// FFT based M2L for a vector of charges
let nvecs = 1;
let tmp = vec![Complex::one(); nsources * nvecs];
let mut charges = rlst_dynamic_array2!(c64, [nsources, nvecs]);
charges.data_mut().copy_from_slice(&tmp);
let wavenumber = 1f64;

let kernel = Helmholtz3dKernel::new(wavenumber);

let mut result = rlst_dynamic_array2!(c64, [nsources, nvecs]);

group.bench_function(format!("N={nsources}"), |b| {
b.iter(|| {
kernel.evaluate_st(
GreenKernelEvalType::Value,
sources.data(),
targets.data(),
charges.data(),
result.data_mut(),
)
})
});
}
}

criterion_group!(d_f64, multithreaded_direct_f64, singlethreaded_direct_f64);

Check warning on line 177 in kifmm/benches/helmholtz_direct_f64.rs

View workflow job for this annotation

GitHub Actions / Rust style checks (--features "strict")

Diff in /home/runner/work/kifmm/kifmm/kifmm/benches/helmholtz_direct_f64.rs

Check warning on line 177 in kifmm/benches/helmholtz_direct_f64.rs

View workflow job for this annotation

GitHub Actions / Rust style checks

Diff in /home/runner/work/kifmm/kifmm/kifmm/benches/helmholtz_direct_f64.rs

Check warning on line 177 in kifmm/benches/helmholtz_direct_f64.rs

View workflow job for this annotation

GitHub Actions / Rust style checks

Diff in /home/runner/work/kifmm/kifmm/kifmm/benches/helmholtz_direct_f64.rs

criterion_main!(d_f64);
2 changes: 0 additions & 2 deletions kifmm/benches/laplace_direct_f64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ use green_kernels::{laplace_3d::Laplace3dKernel, types::GreenKernelEvalType};
use kifmm::tree::helpers::points_fixture;

Check warning on line 6 in kifmm/benches/laplace_direct_f64.rs

View workflow job for this annotation

GitHub Actions / Rust style checks (--features "strict")

Diff in /home/runner/work/kifmm/kifmm/kifmm/benches/laplace_direct_f64.rs

Check warning on line 6 in kifmm/benches/laplace_direct_f64.rs

View workflow job for this annotation

GitHub Actions / Rust style checks

Diff in /home/runner/work/kifmm/kifmm/kifmm/benches/laplace_direct_f64.rs

Check warning on line 6 in kifmm/benches/laplace_direct_f64.rs

View workflow job for this annotation

GitHub Actions / Rust style checks

Diff in /home/runner/work/kifmm/kifmm/kifmm/benches/laplace_direct_f64.rs
use rlst::{rlst_dynamic_array2, RawAccess, RawAccessMut};

extern crate blas_src;
extern crate lapack_src;

fn multithreaded_direct_f64(c: &mut Criterion) {
let mut group = c.benchmark_group("Multi Threaded Direct f64");
Expand Down

0 comments on commit 57e8b5d

Please sign in to comment.