Skip to content
Snippets Groups Projects
Commit 747b2f41 authored by Russel Arbore's avatar Russel Arbore
Browse files

srad bench

parent 5f96afc7
No related branches found
No related tags found
1 merge request!200Rodinia benches
Pipeline #201875 passed
......@@ -1493,6 +1493,7 @@ version = "0.1.0"
dependencies = [
"async-std",
"clap",
"criterion",
"hercules_rt",
"juno_build",
"nom 8.0.0",
......
......@@ -8,6 +8,9 @@ edition = "2021"
name = "juno_srad"
path = "src/main.rs"
[lib]
path = "src/lib.rs"
[features]
cuda = ["juno_build/cuda", "hercules_rt/cuda"]
......@@ -21,3 +24,10 @@ async-std = "*"
clap = { version = "*", features = ["derive"] }
with_builtin_macros = "0.1.0"
nom = "*"
[dev-dependencies]
criterion = { version = "0.5", features = ["html_reports"] }
[[bench]]
name = "srad_bench"
harness = false
#![feature(concat_idents)]
use criterion::{criterion_group, criterion_main, Criterion};
use hercules_rt::{runner, HerculesImmBox, HerculesImmBoxTo, HerculesMutBox, HerculesMutBoxTo};
juno_build::juno!("srad");
use juno_srad::*;
fn srad_bench(c: &mut Criterion) {
let mut group = c.benchmark_group("srad bench");
let mut r = runner!(srad);
let niter = 100;
let lambda = 0.5;
let nrows = 502;
let ncols = 458;
let image = "data/image.pgm".to_string();
let Image {
image: image_ori,
max,
rows: image_ori_rows,
cols: image_ori_cols,
} = read_graphics(image);
let image = resize(&image_ori, image_ori_rows, image_ori_cols, nrows, ncols);
let mut image_h = HerculesMutBox::from(image.clone());
let mut iN = (0..nrows).map(|i| i as i32 - 1).collect::<Vec<_>>();
let mut iS = (0..nrows).map(|i| i as i32 + 1).collect::<Vec<_>>();
let mut jW = (0..ncols).map(|j| j as i32 - 1).collect::<Vec<_>>();
let mut jE = (0..ncols).map(|j| j as i32 + 1).collect::<Vec<_>>();
// Fix boundary conditions
iN[0] = 0;
iS[nrows - 1] = (nrows - 1) as i32;
jW[0] = 0;
jE[ncols - 1] = (ncols - 1) as i32;
let iN_h = HerculesImmBox::from(iN.as_slice());
let iS_h = HerculesImmBox::from(iS.as_slice());
let jW_h = HerculesImmBox::from(jW.as_slice());
let jE_h = HerculesImmBox::from(jE.as_slice());
group.bench_function("srad bench", |b| {
b.iter(|| {
async_std::task::block_on(async {
r.run(
nrows as u64,
ncols as u64,
niter as u64,
image_h.to(),
iN_h.to(),
iS_h.to(),
jW_h.to(),
jE_h.to(),
max,
lambda,
)
.await
});
})
});
}
criterion_group!(benches, srad_bench);
criterion_main!(benches);
#![feature(concat_idents)]
mod graphics;
mod rust_srad;
pub use graphics::*;
use clap::Parser;
use hercules_rt::{runner, HerculesImmBox, HerculesImmBoxTo, HerculesMutBox, HerculesMutBoxTo};
juno_build::juno!("srad");
#[derive(Parser)]
#[clap(author, version, about, long_about = None)]
pub struct SRADInputs {
pub niter: usize,
pub lambda: f32,
pub nrows: usize,
pub ncols: usize,
pub image: String,
#[clap(short, long)]
pub output: Option<String>,
#[clap(short, long)]
pub verify: bool,
#[clap(long = "output-verify", value_name = "PATH")]
pub output_verify: Option<String>,
}
pub fn srad_harness(args: SRADInputs) {
async_std::task::block_on(async {
let SRADInputs {
niter,
lambda,
nrows,
ncols,
image,
output,
verify,
output_verify,
} = args;
let Image {
image: image_ori,
max,
rows: image_ori_rows,
cols: image_ori_cols,
} = read_graphics(image);
let image = resize(&image_ori, image_ori_rows, image_ori_cols, nrows, ncols);
let mut image_h = HerculesMutBox::from(image.clone());
let mut iN = (0..nrows).map(|i| i as i32 - 1).collect::<Vec<_>>();
let mut iS = (0..nrows).map(|i| i as i32 + 1).collect::<Vec<_>>();
let mut jW = (0..ncols).map(|j| j as i32 - 1).collect::<Vec<_>>();
let mut jE = (0..ncols).map(|j| j as i32 + 1).collect::<Vec<_>>();
// Fix boundary conditions
iN[0] = 0;
iS[nrows - 1] = (nrows - 1) as i32;
jW[0] = 0;
jE[ncols - 1] = (ncols - 1) as i32;
let iN_h = HerculesImmBox::from(iN.as_slice());
let iS_h = HerculesImmBox::from(iS.as_slice());
let jW_h = HerculesImmBox::from(jW.as_slice());
let jE_h = HerculesImmBox::from(jE.as_slice());
let mut runner = runner!(srad);
let result: Vec<f32> = HerculesMutBox::from(
runner
.run(
nrows as u64,
ncols as u64,
niter as u64,
image_h.to(),
iN_h.to(),
iS_h.to(),
jW_h.to(),
jE_h.to(),
max,
lambda,
)
.await,
)
.as_slice()
.to_vec();
if let Some(output) = output {
write_graphics(output, &result, nrows, ncols, max);
}
if verify {
let mut rust_result = image;
rust_srad::srad(
nrows,
ncols,
niter,
&mut rust_result,
&iN,
&iS,
&jW,
&jE,
max,
lambda,
);
if let Some(output) = output_verify {
write_graphics(output, &rust_result, nrows, ncols, max);
}
let max_diff = result
.iter()
.zip(rust_result.iter())
.map(|(a, b)| (*a as i32 - *b as i32).abs())
.max()
.unwrap_or(0);
assert!(
max_diff <= 1,
"Verification failed: maximum pixel difference of {} exceeds threshold of 1",
max_diff
);
}
})
}
#![feature(concat_idents)]
mod graphics;
mod rust_srad;
use graphics::*;
use clap::Parser;
use hercules_rt::{runner, HerculesImmBox, HerculesImmBoxTo, HerculesMutBox, HerculesMutBoxTo};
juno_build::juno!("srad");
#[derive(Parser)]
#[clap(author, version, about, long_about = None)]
struct SRADInputs {
niter: usize,
lambda: f32,
nrows: usize,
ncols: usize,
image: String,
#[clap(short, long)]
output: Option<String>,
#[clap(short, long)]
verify: bool,
#[clap(long = "output-verify", value_name = "PATH")]
output_verify: Option<String>,
}
fn srad_harness(args: SRADInputs) {
async_std::task::block_on(async {
let SRADInputs {
niter,
lambda,
nrows,
ncols,
image,
output,
verify,
output_verify,
} = args;
let Image {
image: image_ori,
max,
rows: image_ori_rows,
cols: image_ori_cols,
} = read_graphics(image);
let image = resize(&image_ori, image_ori_rows, image_ori_cols, nrows, ncols);
let mut image_h = HerculesMutBox::from(image.clone());
let mut iN = (0..nrows).map(|i| i as i32 - 1).collect::<Vec<_>>();
let mut iS = (0..nrows).map(|i| i as i32 + 1).collect::<Vec<_>>();
let mut jW = (0..ncols).map(|j| j as i32 - 1).collect::<Vec<_>>();
let mut jE = (0..ncols).map(|j| j as i32 + 1).collect::<Vec<_>>();
// Fix boundary conditions
iN[0] = 0;
iS[nrows - 1] = (nrows - 1) as i32;
jW[0] = 0;
jE[ncols - 1] = (ncols - 1) as i32;
let iN_h = HerculesImmBox::from(iN.as_slice());
let iS_h = HerculesImmBox::from(iS.as_slice());
let jW_h = HerculesImmBox::from(jW.as_slice());
let jE_h = HerculesImmBox::from(jE.as_slice());
let mut runner = runner!(srad);
let result: Vec<f32> = HerculesMutBox::from(
runner
.run(
nrows as u64,
ncols as u64,
niter as u64,
image_h.to(),
iN_h.to(),
iS_h.to(),
jW_h.to(),
jE_h.to(),
max,
lambda,
)
.await,
)
.as_slice()
.to_vec();
if let Some(output) = output {
write_graphics(output, &result, nrows, ncols, max);
}
if verify {
let mut rust_result = image;
rust_srad::srad(
nrows,
ncols,
niter,
&mut rust_result,
&iN,
&iS,
&jW,
&jE,
max,
lambda,
);
if let Some(output) = output_verify {
write_graphics(output, &rust_result, nrows, ncols, max);
}
let max_diff = result
.iter()
.zip(rust_result.iter())
.map(|(a, b)| (*a as i32 - *b as i32).abs())
.max()
.unwrap_or(0);
assert!(
max_diff <= 1,
"Verification failed: maximum pixel difference of {} exceeds threshold of 1",
max_diff
);
}
})
}
use juno_srad::*;
fn main() {
let args = SRADInputs::parse();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment