Skip to content

Commit

Permalink
Add f32 amd bences
Browse files Browse the repository at this point in the history
  • Loading branch information
skailasa committed Jan 11, 2025
1 parent ad923b6 commit d8afe35
Show file tree
Hide file tree
Showing 14 changed files with 1,774 additions and 51 deletions.
10 changes: 9 additions & 1 deletion kifmm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,15 @@ criterion = { version = "0.5.*", features = ["html_reports"]}
cbindgen = "0.26.0"

[[bench]]
name = "laplace_f32"
name = "laplace_f32_amd_uniform"
harness = false

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

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

[[bench]]
Expand Down
166 changes: 166 additions & 0 deletions kifmm/benches/laplace_f32_amd_sphere.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
use std::time::Duration;

use criterion::{criterion_group, criterion_main, Criterion};
use green_kernels::{laplace_3d::Laplace3dKernel, types::GreenKernelEvalType};
use kifmm::fmm::types::FmmSvdMode;
use kifmm::fmm::types::{BlasFieldTranslationSaRcmp, FftFieldTranslation, SingleNodeBuilder};
use kifmm::traits::field::{SourceToTargetTranslation, TargetTranslation};
use kifmm::traits::fmm::{DataAccess, Evaluate};
use kifmm::traits::tree::{SingleFmmTree, SingleTree};
use kifmm::tree::helpers::{points_fixture, points_fixture_sphere};
use rlst::{rlst_dynamic_array2, RawAccess, RawAccessMut};

fn laplace_potentials_f32(c: &mut Criterion) {
let mut group = c.benchmark_group("F32 Potentials");

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

let n_sources = 1000000;
let n_targets = 1000000;
let sources = points_fixture_sphere::<f32>(n_sources);

Check warning on line 22 in kifmm/benches/laplace_f32_amd_sphere.rs

View workflow job for this annotation

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

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

Check warning on line 22 in kifmm/benches/laplace_f32_amd_sphere.rs

View workflow job for this annotation

GitHub Actions / Rust style checks

Diff in /home/runner/work/kifmm/kifmm/kifmm/benches/laplace_f32_amd_sphere.rs
let targets = points_fixture_sphere::<f32>(n_targets);


let nvecs = 1;
let tmp = vec![1.0; n_sources * nvecs];
let mut charges = rlst_dynamic_array2!(f32, [n_sources, nvecs]);
charges.data_mut().copy_from_slice(&tmp);

// 3 Digits
{
// FFT based M2L for a vector of charges
// FMM parameters
let n_crit = None;
let depth = Some(5);
let e = 5;
let expansion_order = vec![e; depth.unwrap() as usize + 1];
let prune_empty = true;
let block_size = Some(64);

let mut fmm_fft = SingleNodeBuilder::new(false)
.tree(sources.data(), targets.data(), n_crit, depth, prune_empty)
.unwrap()
.parameters(
charges.data(),
&expansion_order,
Laplace3dKernel::new(),
GreenKernelEvalType::Value,
FftFieldTranslation::new(block_size),
)
.unwrap()
.build()
.unwrap();

group.bench_function(format!("M2L=FFT digits=3"), |b| {
b.iter(|| fmm_fft.evaluate())
});

group.bench_function(format!("M2L=FFT digits=3, M2L "), |b| {
b.iter(|| {
for level in 2..=fmm_fft.tree().target_tree().depth() {
fmm_fft.m2l(level).unwrap();
}
})
});

group.bench_function(format!("M2L=FFT digits=3, P2P "), |b| {
b.iter(|| fmm_fft.p2p().unwrap())
});

// BLAS based M2L for a vector of charges
// FMM parameters
let n_crit = None;
let depth = Some(4);
let e = 3;
let expansion_order = vec![e; depth.unwrap() as usize + 1];
let prune_empty = true;
let surface_diff = Some(2);
let svd_mode = crate::FmmSvdMode::new(true, None, None, Some(20), None);
let svd_threshold = None;

let mut fmm_blas = SingleNodeBuilder::new(false)
.tree(sources.data(), targets.data(), n_crit, depth, prune_empty)
.unwrap()
.parameters(
charges.data(),
&expansion_order,
Laplace3dKernel::new(),
GreenKernelEvalType::Value,
BlasFieldTranslationSaRcmp::new(svd_threshold, surface_diff, svd_mode),
)
.unwrap()
.build()
.unwrap();

group.bench_function(format!("M2L=BLAS digits=3"), |b| {
b.iter(|| fmm_blas.evaluate())
});

group.bench_function(format!("M2L=BLAS digits=3, M2L "), |b| {
b.iter(|| {
for level in 2..=fmm_blas.tree().target_tree().depth() {
fmm_blas.m2l(level).unwrap();
}
})
});

group.bench_function(format!("M2L=BLAS digits=3, P2P "), |b| {

Check warning on line 109 in kifmm/benches/laplace_f32_amd_sphere.rs

View workflow job for this annotation

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

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

Check warning on line 109 in kifmm/benches/laplace_f32_amd_sphere.rs

View workflow job for this annotation

GitHub Actions / Rust style checks

Diff in /home/runner/work/kifmm/kifmm/kifmm/benches/laplace_f32_amd_sphere.rs
b.iter(|| fmm_blas.p2p().unwrap())
});

}

let nvecs = 5;
let tmp = vec![1.0; n_sources * nvecs];
let mut charges = rlst_dynamic_array2!(f32, [n_sources, nvecs]);
charges.data_mut().copy_from_slice(&tmp);

// 3 Digits matrix
{
// BLAS based M2L for a matrix of charges
// FMM parameters
let n_crit = None;
let depth = Some(4);
let e = 3;
let expansion_order = vec![e; depth.unwrap() as usize + 1];
let prune_empty = true;
let surface_diff = Some(2);
let svd_mode = crate::FmmSvdMode::new(true, None, None, Some(20), None);
let svd_threshold = None;

let mut fmm_blas = SingleNodeBuilder::new(false)
.tree(sources.data(), targets.data(), n_crit, depth, prune_empty)
.unwrap()
.parameters(
charges.data(),
&expansion_order,
Laplace3dKernel::new(),
GreenKernelEvalType::Value,
BlasFieldTranslationSaRcmp::new(svd_threshold, surface_diff, svd_mode),
)
.unwrap()
.build()
.unwrap();

group.bench_function(format!("M2L=BLAS digits=3 nvecs=5"), |b| {
b.iter(|| fmm_blas.evaluate())
});

group.bench_function(format!("M2L=BLAS digits=3 nvecs=5, M2L "), |b| {
b.iter(|| {
for level in 2..=fmm_blas.tree().target_tree().depth() {
fmm_blas.m2l(level).unwrap();
}
})
});

group.bench_function(format!("M2L=BLAS digits=3 nvecs=5, P2P "), |b| {
b.iter(|| fmm_blas.p2p().unwrap())
});
}
}

criterion_group!(laplace_p_f32, laplace_potentials_f32);
criterion_main!(laplace_p_f32);
165 changes: 165 additions & 0 deletions kifmm/benches/laplace_f32_amd_spheroid.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
use std::time::Duration;

use criterion::{criterion_group, criterion_main, Criterion};
use green_kernels::{laplace_3d::Laplace3dKernel, types::GreenKernelEvalType};
use kifmm::fmm::types::FmmSvdMode;
use kifmm::fmm::types::{BlasFieldTranslationSaRcmp, FftFieldTranslation, SingleNodeBuilder};
use kifmm::traits::field::{SourceToTargetTranslation, TargetTranslation};
use kifmm::traits::fmm::{DataAccess, Evaluate};
use kifmm::traits::tree::{SingleFmmTree, SingleTree};
use kifmm::tree::helpers::{points_fixture, points_fixture_oblate_spheroid};
use rlst::{rlst_dynamic_array2, RawAccess, RawAccessMut};

fn laplace_potentials_f32(c: &mut Criterion) {
let mut group = c.benchmark_group("F32 Potentials");

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

let n_sources = 1000000;
let n_targets = 1000000;
let sources = points_fixture_oblate_spheroid::<f32>(n_sources, 1.0, 0.5);
let targets = points_fixture_oblate_spheroid(n_targets, 1.0, 0.5);

let nvecs = 1;
let tmp = vec![1.0; n_sources * nvecs];
let mut charges = rlst_dynamic_array2!(f32, [n_sources, nvecs]);
charges.data_mut().copy_from_slice(&tmp);

// 3 Digits
{
// FFT based M2L for a vector of charges
// FMM parameters
let n_crit = None;
let depth = Some(5);
let e = 5;
let expansion_order = vec![e; depth.unwrap() as usize + 1];
let prune_empty = true;
let block_size = Some(64);

let mut fmm_fft = SingleNodeBuilder::new(false)
.tree(sources.data(), targets.data(), n_crit, depth, prune_empty)
.unwrap()
.parameters(
charges.data(),
&expansion_order,
Laplace3dKernel::new(),
GreenKernelEvalType::Value,
FftFieldTranslation::new(block_size),
)
.unwrap()
.build()
.unwrap();

group.bench_function(format!("M2L=FFT digits=3"), |b| {
b.iter(|| fmm_fft.evaluate())
});

group.bench_function(format!("M2L=FFT digits=3, M2L "), |b| {
b.iter(|| {
for level in 2..=fmm_fft.tree().target_tree().depth() {
fmm_fft.m2l(level).unwrap();
}
})
});

group.bench_function(format!("M2L=FFT digits=3, P2P "), |b| {
b.iter(|| fmm_fft.p2p().unwrap())
});

// BLAS based M2L for a vector of charges
// FMM parameters
let n_crit = None;
let depth = Some(4);
let e = 4;
let expansion_order = vec![e; depth.unwrap() as usize + 1];
let prune_empty = true;
let surface_diff = Some(1);
let svd_mode = crate::FmmSvdMode::new(true, None, None, Some(5), None);
let svd_threshold = None;

let mut fmm_blas = SingleNodeBuilder::new(false)
.tree(sources.data(), targets.data(), n_crit, depth, prune_empty)
.unwrap()
.parameters(
charges.data(),
&expansion_order,
Laplace3dKernel::new(),
GreenKernelEvalType::Value,
BlasFieldTranslationSaRcmp::new(svd_threshold, surface_diff, svd_mode),
)
.unwrap()
.build()
.unwrap();

group.bench_function(format!("M2L=BLAS digits=3"), |b| {
b.iter(|| fmm_blas.evaluate())
});

group.bench_function(format!("M2L=BLAS digits=3, M2L "), |b| {
b.iter(|| {
for level in 2..=fmm_blas.tree().target_tree().depth() {
fmm_blas.m2l(level).unwrap();
}
})
});

group.bench_function(format!("M2L=BLAS digits=3, P2P "), |b| {

Check warning on line 108 in kifmm/benches/laplace_f32_amd_spheroid.rs

View workflow job for this annotation

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

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

Check warning on line 108 in kifmm/benches/laplace_f32_amd_spheroid.rs

View workflow job for this annotation

GitHub Actions / Rust style checks

Diff in /home/runner/work/kifmm/kifmm/kifmm/benches/laplace_f32_amd_spheroid.rs
b.iter(|| fmm_blas.p2p().unwrap())
});

}

let nvecs = 5;
let tmp = vec![1.0; n_sources * nvecs];
let mut charges = rlst_dynamic_array2!(f32, [n_sources, nvecs]);
charges.data_mut().copy_from_slice(&tmp);

// 3 Digits matrix
{
// BLAS based M2L for a matrix of charges
// FMM parameters
let n_crit = None;
let depth = Some(4);
let e = 4;
let expansion_order = vec![e; depth.unwrap() as usize + 1];
let prune_empty = true;
let surface_diff = Some(1);
let svd_mode = crate::FmmSvdMode::new(true, None, None, Some(5), None);
let svd_threshold = None;

let mut fmm_blas = SingleNodeBuilder::new(false)
.tree(sources.data(), targets.data(), n_crit, depth, prune_empty)
.unwrap()
.parameters(
charges.data(),
&expansion_order,
Laplace3dKernel::new(),
GreenKernelEvalType::Value,
BlasFieldTranslationSaRcmp::new(svd_threshold, surface_diff, svd_mode),
)
.unwrap()
.build()
.unwrap();

group.bench_function(format!("M2L=BLAS digits=3 nvecs=5"), |b| {
b.iter(|| fmm_blas.evaluate())
});

group.bench_function(format!("M2L=BLAS digits=3 nvecs=5, M2L "), |b| {
b.iter(|| {
for level in 2..=fmm_blas.tree().target_tree().depth() {
fmm_blas.m2l(level).unwrap();
}
})
});

group.bench_function(format!("M2L=BLAS digits=3 nvecs=5, P2P "), |b| {
b.iter(|| fmm_blas.p2p().unwrap())
});
}
}

criterion_group!(laplace_p_f32, laplace_potentials_f32);
criterion_main!(laplace_p_f32);
Loading

0 comments on commit d8afe35

Please sign in to comment.