Skip to content
Snippets Groups Projects
Commit 19688aa8 authored by rarbore2's avatar rarbore2
Browse files

Large benches

parent 95aa941b
No related branches found
No related tags found
1 merge request!215Large benches
......@@ -9,7 +9,8 @@ juno_build::juno!("backprop");
// We need this even though we don't use anything from the library because of
// Rust build scripts only linking static libraries into the library, and not
// into the benchmark binary. Ugh!
// into the benchmark binary. Yuck!
#[allow(unused_imports)]
use juno_backprop::*;
fn backprop_bench(c: &mut Criterion) {
......@@ -18,52 +19,56 @@ fn backprop_bench(c: &mut Criterion) {
let mut rng = StdRng::seed_from_u64(7);
let input_n = 65536;
let hidden_n = 16;
let output_n = 1;
let mut bench = |name, input_n: usize| {
let hidden_n = 16;
let output_n = 1;
let mut input_vals = vec![0.0f32; input_n + 1];
input_vals[0] = 1.0;
let mut input_vals = vec![0.0f32; input_n + 1];
input_vals[0] = 1.0;
// For some reason the bpnn_randomize_row function used on target just sets it to 0.1
let target = vec![0.1f32; output_n + 1];
// For some reason the bpnn_randomize_row function used on target just sets it to 0.1
let target = vec![0.1f32; output_n + 1];
let input_weights = (0..(input_n + 1) * (hidden_n + 1))
.map(|_| rng.random::<f32>())
.collect::<Vec<_>>();
let hidden_weights = (0..(hidden_n + 1) * (output_n + 1))
.map(|_| rng.random::<f32>())
.collect::<Vec<_>>();
let input_weights = (0..(input_n + 1) * (hidden_n + 1))
.map(|_| rng.random::<f32>())
.collect::<Vec<_>>();
let hidden_weights = (0..(hidden_n + 1) * (output_n + 1))
.map(|_| rng.random::<f32>())
.collect::<Vec<_>>();
let input_prev_weights = vec![0.0; (input_n + 1) * (hidden_n + 1)];
let hidden_prev_weights = vec![0.0; (hidden_n + 1) * (output_n + 1)];
let input_prev_weights = vec![0.0; (input_n + 1) * (hidden_n + 1)];
let hidden_prev_weights = vec![0.0; (hidden_n + 1) * (output_n + 1)];
let mut r = runner!(backprop);
let input_vals = HerculesImmBox::from(&input_vals as &[f32]);
let target = HerculesImmBox::from(&target as &[f32]);
let mut input_weights = HerculesMutBox::from(input_weights.to_vec());
let mut hidden_weights = HerculesMutBox::from(hidden_weights.to_vec());
let mut input_prev_weights = HerculesMutBox::from(input_prev_weights.to_vec());
let mut hidden_prev_weights = HerculesMutBox::from(hidden_prev_weights.to_vec());
let mut r = runner!(backprop);
let input_vals = HerculesImmBox::from(&input_vals as &[f32]);
let target = HerculesImmBox::from(&target as &[f32]);
let mut input_weights = HerculesMutBox::from(input_weights.to_vec());
let mut hidden_weights = HerculesMutBox::from(hidden_weights.to_vec());
let mut input_prev_weights = HerculesMutBox::from(input_prev_weights.to_vec());
let mut hidden_prev_weights = HerculesMutBox::from(hidden_prev_weights.to_vec());
group.bench_function("backprop bench", |b| {
b.iter(|| {
async_std::task::block_on(async {
r.run(
input_n as u64,
hidden_n as u64,
output_n as u64,
input_vals.to(),
input_weights.to(),
hidden_weights.to(),
target.to(),
input_prev_weights.to(),
hidden_prev_weights.to(),
)
.await
});
})
});
group.bench_function(name, |b| {
b.iter(|| {
async_std::task::block_on(async {
r.run(
input_n as u64,
hidden_n as u64,
output_n as u64,
input_vals.to(),
input_weights.to(),
hidden_weights.to(),
target.to(),
input_prev_weights.to(),
hidden_prev_weights.to(),
)
.await
});
})
});
};
bench("backprop bench small", 65536);
bench("backprop bench large", 33554432);
}
criterion_group!(benches, backprop_bench);
......
......@@ -9,28 +9,41 @@ use juno_bfs::graph_parser::*;
fn bfs_bench(c: &mut Criterion) {
let mut group = c.benchmark_group("bfs bench");
group.sample_size(10);
let mut r = runner!(bfs);
let input = "data/graph4096.txt";
let (nodes, source, edges) = parse_graph(input.into());
let n = nodes.len() as u64;
let m = edges.len() as u64;
let nodes = HerculesImmBox::from(&nodes as &[Node]);
let edges = HerculesImmBox::from(&edges as &[u32]);
group.bench_function("bfs bench 4096", |b| {
let input = "data/graph4096.txt";
let (nodes, source, edges) = parse_graph(input.into()).unwrap();
let n = nodes.len() as u64;
let m = edges.len() as u64;
let nodes = HerculesImmBox::from(&nodes as &[Node]);
let edges = HerculesImmBox::from(&edges as &[u32]);
b.iter(|| {
async_std::task::block_on(async { r.run(n, m, nodes.to(), source, edges.to()).await });
})
});
let input = "data/graph65536.txt";
let (nodes, source, edges) = parse_graph(input.into());
let n = nodes.len() as u64;
let m = edges.len() as u64;
let nodes = HerculesImmBox::from(&nodes as &[Node]);
let edges = HerculesImmBox::from(&edges as &[u32]);
group.bench_function("bfs bench 65536", |b| {
let input = "data/graph65536.txt";
let (nodes, source, edges) = parse_graph(input.into()).unwrap();
let n = nodes.len() as u64;
let m = edges.len() as u64;
let nodes = HerculesImmBox::from(&nodes as &[Node]);
let edges = HerculesImmBox::from(&edges as &[u32]);
b.iter(|| {
async_std::task::block_on(async { r.run(n, m, nodes.to(), source, edges.to()).await });
})
});
group.bench_function("bfs bench 64M", |b| {
let input = "/scratch/aaronjc4/rodinia_3.1/data/bfs/graph64M.txt";
let (nodes, source, edges) = parse_graph(input.into()).expect("PANIC: Couldn't read input file for 64M benchmark. Currently, this benchmark uses a hard-coded path, so it can only be run on the lab machines.");
let n = nodes.len() as u64;
let m = edges.len() as u64;
let nodes = HerculesImmBox::from(&nodes as &[Node]);
let edges = HerculesImmBox::from(&edges as &[u32]);
b.iter(|| {
async_std::task::block_on(async { r.run(n, m, nodes.to(), source, edges.to()).await });
})
......
......@@ -11,16 +11,18 @@ pub struct Node {
pub num_edges: u32,
}
pub fn parse_graph(file: String) -> (Vec<Node>, u32, Vec<u32>) {
let mut file = File::open(file).expect("Error opening input file");
pub fn parse_graph(file: String) -> Result<(Vec<Node>, u32, Vec<u32>), String> {
let mut file = File::open(file).map_err(|err| format!("Error opening input file: {}", err))?;
let mut contents = String::new();
file.read_to_string(&mut contents)
.expect("Error reading input file");
.map_err(|err| format!("Error reading input file: {}", err))?;
let mut parser = nom::combinator::all_consuming(graph_parser);
let (_, result) = parser.parse(&contents).expect("Parser error");
let (_, result) = parser
.parse(&contents)
.map_err(|err| format!("Parsing error: {}", err))?;
result
Ok(result)
}
fn graph_parser<'a>(text: &'a str) -> nom::IResult<&'a str, (Vec<Node>, u32, Vec<u32>)> {
......
......@@ -36,7 +36,7 @@ fn run_bfs(nodes: &[Node], source: u32, edges: &[u32]) -> Vec<i32> {
pub fn bfs_harness(args: BFSInputs) {
let BFSInputs { input } = args;
let (nodes, source, edges) = parse_graph(input);
let (nodes, source, edges) = parse_graph(input).unwrap();
let costs_juno = run_bfs(&nodes, source, &edges);
let costs_ref = rust_bfs::bfs(&nodes, source, &edges);
......
......@@ -10,150 +10,163 @@ use juno_cfd::*;
fn cfd_bench(c: &mut Criterion) {
let mut group = c.benchmark_group("cfd bench");
group.sample_size(10);
let mut r = runner!(euler);
let data_file = "data/fvcorr.domn.097K".to_string();
let iterations = 1;
let block_size = 16;
let FarFieldConditions {
ff_variable,
ff_fc_momentum_x,
ff_fc_momentum_y,
ff_fc_momentum_z,
ff_fc_density_energy,
} = set_far_field_conditions();
let GeometryData {
nelr,
areas,
elements_surrounding_elements,
normals,
} = read_domain_geometry(data_file, block_size);
let mut variables = initialize_variables(nelr, &ff_variable);
let mut euler_bench = |name, data_file, iterations| {
group.bench_function(name, |b| {
let mut r = runner!(euler);
let block_size = 16;
let FarFieldConditions {
ff_variable,
ff_fc_momentum_x,
ff_fc_momentum_y,
ff_fc_momentum_z,
ff_fc_density_energy,
} = set_far_field_conditions();
let GeometryData {
nelr,
areas,
elements_surrounding_elements,
normals,
} = read_domain_geometry(data_file, block_size).expect("PANIC: Couldn't read input for CFD benchmark. Currently, the path for the largest CFD benchmark is hard-coded, so it can only be run on the lab machines.");
let mut variables = initialize_variables(nelr, &ff_variable);
let mut v_density = HerculesMutBox::from(variables.density.as_mut_slice());
let mut v_momentum_x = HerculesMutBox::from(variables.momentum.x.as_mut_slice());
let mut v_momentum_y = HerculesMutBox::from(variables.momentum.y.as_mut_slice());
let mut v_momentum_z = HerculesMutBox::from(variables.momentum.z.as_mut_slice());
let mut v_energy = HerculesMutBox::from(variables.energy.as_mut_slice());
let mut v_density = HerculesMutBox::from(variables.density.as_mut_slice());
let mut v_momentum_x = HerculesMutBox::from(variables.momentum.x.as_mut_slice());
let mut v_momentum_y = HerculesMutBox::from(variables.momentum.y.as_mut_slice());
let mut v_momentum_z = HerculesMutBox::from(variables.momentum.z.as_mut_slice());
let mut v_energy = HerculesMutBox::from(variables.energy.as_mut_slice());
let areas = HerculesImmBox::from(areas.as_slice());
let elements_surrounding_elements =
HerculesImmBox::from(elements_surrounding_elements.as_slice());
let areas = HerculesImmBox::from(areas.as_slice());
let elements_surrounding_elements =
HerculesImmBox::from(elements_surrounding_elements.as_slice());
let normals_x = HerculesImmBox::from(normals.x.as_slice());
let normals_y = HerculesImmBox::from(normals.y.as_slice());
let normals_z = HerculesImmBox::from(normals.z.as_slice());
let normals_x = HerculesImmBox::from(normals.x.as_slice());
let normals_y = HerculesImmBox::from(normals.y.as_slice());
let normals_z = HerculesImmBox::from(normals.z.as_slice());
group.bench_function("cfd bench euler", |b| {
b.iter(|| {
async_std::task::block_on(async {
r.run(
nelr as u64,
iterations as u64,
v_density.to(),
v_momentum_x.to(),
v_momentum_y.to(),
v_momentum_z.to(),
v_energy.to(),
areas.to(),
elements_surrounding_elements.to(),
normals_x.to(),
normals_y.to(),
normals_z.to(),
ff_variable.density,
ff_variable.momentum.x,
ff_variable.momentum.y,
ff_variable.momentum.z,
ff_variable.energy,
ff_fc_density_energy.x,
ff_fc_density_energy.y,
ff_fc_density_energy.z,
ff_fc_momentum_x.x,
ff_fc_momentum_x.y,
ff_fc_momentum_x.z,
ff_fc_momentum_y.x,
ff_fc_momentum_y.y,
ff_fc_momentum_y.z,
ff_fc_momentum_z.x,
ff_fc_momentum_z.y,
ff_fc_momentum_z.z,
)
.await
});
})
});
b.iter(|| {
async_std::task::block_on(async {
r.run(
nelr as u64,
iterations as u64,
v_density.to(),
v_momentum_x.to(),
v_momentum_y.to(),
v_momentum_z.to(),
v_energy.to(),
areas.to(),
elements_surrounding_elements.to(),
normals_x.to(),
normals_y.to(),
normals_z.to(),
ff_variable.density,
ff_variable.momentum.x,
ff_variable.momentum.y,
ff_variable.momentum.z,
ff_variable.energy,
ff_fc_density_energy.x,
ff_fc_density_energy.y,
ff_fc_density_energy.z,
ff_fc_momentum_x.x,
ff_fc_momentum_x.y,
ff_fc_momentum_x.z,
ff_fc_momentum_y.x,
ff_fc_momentum_y.y,
ff_fc_momentum_y.z,
ff_fc_momentum_z.x,
ff_fc_momentum_z.y,
ff_fc_momentum_z.z,
)
.await
});
})
});
};
euler_bench("cfd bench euler small", "data/fvcorr.domn.097K", 1);
euler_bench(
"cfd bench euler large",
"/scratch/aaronjc4/rodinia_3.1/data/cfd/missile.domn.0.2M",
150,
);
let mut r = runner!(pre_euler);
let data_file = "data/fvcorr.domn.097K".to_string();
let iterations = 1;
let block_size = 16;
let FarFieldConditions {
ff_variable,
ff_fc_momentum_x,
ff_fc_momentum_y,
ff_fc_momentum_z,
ff_fc_density_energy,
} = set_far_field_conditions();
let GeometryData {
nelr,
areas,
elements_surrounding_elements,
normals,
} = read_domain_geometry(data_file, block_size);
let mut variables = initialize_variables(nelr, &ff_variable);
let mut pre_euler_bench = |name, data_file, iterations| {
group.bench_function(name, |b| {
let mut r = runner!(pre_euler);
let block_size = 16;
let FarFieldConditions {
ff_variable,
ff_fc_momentum_x,
ff_fc_momentum_y,
ff_fc_momentum_z,
ff_fc_density_energy,
} = set_far_field_conditions();
let GeometryData {
nelr,
areas,
elements_surrounding_elements,
normals,
} = read_domain_geometry(data_file, block_size).expect("PANIC: Couldn't read input for CFD benchmark. Currently, the path for the largest CFD benchmark is hard-coded, so it can only be run on the lab machines.");
let mut variables = initialize_variables(nelr, &ff_variable);
let mut v_density = HerculesMutBox::from(variables.density.as_mut_slice());
let mut v_momentum_x = HerculesMutBox::from(variables.momentum.x.as_mut_slice());
let mut v_momentum_y = HerculesMutBox::from(variables.momentum.y.as_mut_slice());
let mut v_momentum_z = HerculesMutBox::from(variables.momentum.z.as_mut_slice());
let mut v_energy = HerculesMutBox::from(variables.energy.as_mut_slice());
let mut v_density = HerculesMutBox::from(variables.density.as_mut_slice());
let mut v_momentum_x = HerculesMutBox::from(variables.momentum.x.as_mut_slice());
let mut v_momentum_y = HerculesMutBox::from(variables.momentum.y.as_mut_slice());
let mut v_momentum_z = HerculesMutBox::from(variables.momentum.z.as_mut_slice());
let mut v_energy = HerculesMutBox::from(variables.energy.as_mut_slice());
let areas = HerculesImmBox::from(areas.as_slice());
let elements_surrounding_elements =
HerculesImmBox::from(elements_surrounding_elements.as_slice());
let areas = HerculesImmBox::from(areas.as_slice());
let elements_surrounding_elements =
HerculesImmBox::from(elements_surrounding_elements.as_slice());
let normals_x = HerculesImmBox::from(normals.x.as_slice());
let normals_y = HerculesImmBox::from(normals.y.as_slice());
let normals_z = HerculesImmBox::from(normals.z.as_slice());
let normals_x = HerculesImmBox::from(normals.x.as_slice());
let normals_y = HerculesImmBox::from(normals.y.as_slice());
let normals_z = HerculesImmBox::from(normals.z.as_slice());
group.bench_function("cfd bench pre-euler", |b| {
b.iter(|| {
async_std::task::block_on(async {
r.run(
nelr as u64,
iterations as u64,
v_density.to(),
v_momentum_x.to(),
v_momentum_y.to(),
v_momentum_z.to(),
v_energy.to(),
areas.to(),
elements_surrounding_elements.to(),
normals_x.to(),
normals_y.to(),
normals_z.to(),
ff_variable.density,
ff_variable.momentum.x,
ff_variable.momentum.y,
ff_variable.momentum.z,
ff_variable.energy,
ff_fc_density_energy.x,
ff_fc_density_energy.y,
ff_fc_density_energy.z,
ff_fc_momentum_x.x,
ff_fc_momentum_x.y,
ff_fc_momentum_x.z,
ff_fc_momentum_y.x,
ff_fc_momentum_y.y,
ff_fc_momentum_y.z,
ff_fc_momentum_z.x,
ff_fc_momentum_z.y,
ff_fc_momentum_z.z,
)
.await
});
})
});
b.iter(|| {
async_std::task::block_on(async {
r.run(
nelr as u64,
iterations as u64,
v_density.to(),
v_momentum_x.to(),
v_momentum_y.to(),
v_momentum_z.to(),
v_energy.to(),
areas.to(),
elements_surrounding_elements.to(),
normals_x.to(),
normals_y.to(),
normals_z.to(),
ff_variable.density,
ff_variable.momentum.x,
ff_variable.momentum.y,
ff_variable.momentum.z,
ff_variable.energy,
ff_fc_density_energy.x,
ff_fc_density_energy.y,
ff_fc_density_energy.z,
ff_fc_momentum_x.x,
ff_fc_momentum_x.y,
ff_fc_momentum_x.z,
ff_fc_momentum_y.x,
ff_fc_momentum_y.y,
ff_fc_momentum_y.z,
ff_fc_momentum_z.x,
ff_fc_momentum_z.y,
ff_fc_momentum_z.z,
)
.await
});
})
});
};
pre_euler_bench("cfd bench pre-euler small", "data/fvcorr.domn.097K", 1);
pre_euler_bench(
"cfd bench pre-euler large",
"/scratch/aaronjc4/rodinia_3.1/data/cfd/missile.domn.0.2M",
150,
);
}
criterion_group!(benches, cfd_bench);
......
......@@ -237,7 +237,7 @@ pub fn cfd_harness(args: CFDInputs) {
areas,
elements_surrounding_elements,
normals,
} = read_domain_geometry(data_file, block_size);
} = read_domain_geometry(data_file, block_size).unwrap();
let variables = initialize_variables(nelr, &ff_variable);
println!("Running CFD with nelr = {}.", nelr);
......
......@@ -29,7 +29,7 @@ pub struct AlignedSlice<T> {
impl<T> Debug for AlignedSlice<T>
where
T: Debug
T: Debug,
{
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> {
write!(f, "{:?}", self.as_slice())
......@@ -127,7 +127,15 @@ pub struct FarFieldConditions {
}
pub fn set_far_field_conditions() -> FarFieldConditions {
let mut ff_variable = Variable { density: 0.0, momentum: Float3 { x: 0.0, y: 0.0, z: 0.0 }, energy: 0.0 };
let mut ff_variable = Variable {
density: 0.0,
momentum: Float3 {
x: 0.0,
y: 0.0,
z: 0.0,
},
energy: 0.0,
};
let angle_of_attack = std::f32::consts::PI / 180.0 * deg_angle_of_attack;
......@@ -186,19 +194,21 @@ pub struct GeometryData {
pub normals: Normals,
}
pub fn read_domain_geometry<P>(path: P, block_size: usize) -> GeometryData
pub fn read_domain_geometry<P>(path: P, block_size: usize) -> Result<GeometryData, String>
where
P: AsRef<Path>,
{
let mut file = File::open(path).expect("Error opening input file");
let mut file = File::open(path).map_err(|err| format!("Error opening input file: {}", err))?;
let mut contents = String::new();
file.read_to_string(&mut contents)
.expect("Error reading input file");
.map_err(|err| format!("Error reading input file: {}", err))?;
let mut parser = nom::combinator::all_consuming(|s| cfd_parser(block_size, s));
let (_, result) = parser.parse(&contents).expect("Parser error");
let (_, result) = parser
.parse(&contents)
.map_err(|err| format!("Parser error: {}", err))?;
result
Ok(result)
}
fn cfd_parser<'a>(block_size: usize, text: &'a str) -> nom::IResult<&'a str, GeometryData> {
......@@ -240,17 +250,17 @@ fn cfd_parser<'a>(block_size: usize, text: &'a str) -> nom::IResult<&'a str, Geo
let val = i32::from_str(val).unwrap();
let val = if neg { -val } else { val };
elements_surrounding_elements[i + j * nelr] = if val < 0 { -1 } else { val } - 1; // it's coming in with Fortran numbering
let t = nom::character::complete::multispace0(text)?.0;
let (t, val) = nom::number::complete::float(t)?;
text = t;
normals.x[i + j * nelr] = -val;
let t = nom::character::complete::multispace0(text)?.0;
let (t, val) = nom::number::complete::float(t)?;
text = t;
normals.y[i + j * nelr] = -val;
let t = nom::character::complete::multispace0(text)?.0;
let (t, val) = nom::number::complete::float(t)?;
text = t;
......
#![feature(concat_idents)]
use criterion::{criterion_group, criterion_main, Criterion};
use hercules_rt::{runner, HerculesImmBox, HerculesImmBoxTo, HerculesMutBox, HerculesMutBoxTo};
use hercules_rt::{runner, HerculesMutBox, HerculesMutBoxTo};
juno_build::juno!("srad");
......@@ -9,36 +9,39 @@ use juno_srad::*;
fn srad_bench(c: &mut Criterion) {
let mut group = c.benchmark_group("srad bench");
group.sample_size(10);
let mut r = runner!(srad);
let niter = 100;
let lambda = 0.5;
let nrows = 512;
let ncols = 512;
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());
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(),
max,
lambda,
)
.await
});
})
});
let mut bench = |name, niter, nrows, ncols| {
let mut r = runner!(srad);
let lambda = 0.5;
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());
group.bench_function(name, |b| {
b.iter(|| {
async_std::task::block_on(async {
r.run(
nrows as u64,
ncols as u64,
niter as u64,
image_h.to(),
max,
lambda,
)
.await
});
})
});
};
bench("srad bench small", 100, 512, 512);
bench("srad bench large", 30, 2048, 2048);
}
criterion_group!(benches, srad_bench);
......
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