Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(benches): add binaries to bench scaling of non-conflicting transactions #240

Merged
merged 11 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ honeycomb-render = { version = "0.6.0", path = "./honeycomb-render" }

# common
cfg-if = "1"
rayon = "1.10.0"
rustversion = "1.0.18"
thiserror = "2.0.3"

Expand Down
10 changes: 10 additions & 0 deletions benches/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ _single_precision = []
[dependencies]
cfg-if.workspace = true
honeycomb.workspace = true
rayon.workspace = true

[dev-dependencies]
honeycomb-core = { workspace = true, features = ["utils"] }
Expand All @@ -34,6 +35,14 @@ path = "src/builder.rs"
name = "grisubal"
path = "src/grisubal.rs"

[[bin]]
name = "shift"
path = "src/shift.rs"

[[bin]]
name = "shift-nc"
path = "src/shift_no_conflict.rs"

# benches

## Core benchmarks
Expand Down Expand Up @@ -86,3 +95,4 @@ harness = false
name = "triangulate-quads"
path = "benches/triangulate/quads.rs"
harness = false

66 changes: 66 additions & 0 deletions benches/src/shift.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
use rayon::prelude::*;

use honeycomb::core::stm::atomically;
use honeycomb::prelude::{
CMap2, CMapBuilder, DartIdType, Orbit2, OrbitPolicy, Vertex2, VertexIdType, NULL_DART_ID,
};

imrn99 marked this conversation as resolved.
Show resolved Hide resolved
fn main() {
// ./binary grid_size n_rounds
let args: Vec<String> = std::env::args().collect();
let n_squares = args
.get(1)
.and_then(|s| s.parse::<usize>().ok())
.unwrap_or(256);
let n_rounds = args
.get(2)
.and_then(|s| s.parse::<usize>().ok())
.unwrap_or(100);

let map: CMap2<f64> = CMapBuilder::unit_grid(n_squares).build().unwrap();

// fetch all vertices that are not on the boundary of the map
let tmp: Vec<(VertexIdType, Vec<VertexIdType>)> = map
.fetch_vertices()
.identifiers
.into_iter()
.filter_map(|v| {
if Orbit2::new(&map, OrbitPolicy::Vertex, v as DartIdType)
.any(|d| map.beta::<2>(d) == NULL_DART_ID)
{
None
} else {
Some((
v,
Orbit2::new(&map, OrbitPolicy::Vertex, v as DartIdType)
.map(|d| map.vertex_id(map.beta::<2>(d)))
.collect(),
))
}
})
.collect();
// main loop
let mut round = 0;
loop {
tmp.par_iter().for_each(|(vid, neigh)| {
atomically(|trans| {
let mut new_val = Vertex2::default();
for v in neigh {
let vertex = map.read_vertex(trans, *v)?.unwrap();
new_val.0 += vertex.0;
new_val.1 += vertex.1;
}
new_val.0 /= neigh.len() as f64;
new_val.1 /= neigh.len() as f64;
map.write_vertex(trans, *vid, new_val)
});
});

round += 1;
if round >= n_rounds {
break;
}
}

std::hint::black_box(map);
}
84 changes: 84 additions & 0 deletions benches/src/shift_no_conflict.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
use rayon::prelude::*;

use honeycomb::core::stm::atomically;
use honeycomb::prelude::{
CMap2, CMapBuilder, DartIdType, Orbit2, OrbitPolicy, Vertex2, VertexIdType, NULL_DART_ID,
};

imrn99 marked this conversation as resolved.
Show resolved Hide resolved
fn main() {
// ./binary grid_size n_rounds
let args: Vec<String> = std::env::args().collect();
let n_squares = args
.get(1)
.and_then(|s| s.parse::<usize>().ok())
.unwrap_or(256);
let n_rounds = args
.get(2)
.and_then(|s| s.parse::<usize>().ok())
.unwrap_or(100);

let map: CMap2<f64> = CMapBuilder::unit_grid(n_squares).build().unwrap();

// fetch all vertices that are not on the boundary of the map
let tmp = map
.fetch_vertices()
.identifiers
.into_iter()
.filter_map(|v| {
if Orbit2::new(&map, OrbitPolicy::Vertex, v as DartIdType)
.any(|d| map.beta::<2>(d) == NULL_DART_ID)
{
None
} else {
Some((
v,
Orbit2::new(&map, OrbitPolicy::Vertex, v as DartIdType)
.map(|d| map.vertex_id(map.beta::<2>(d)))
.collect(),
))
}
});

#[allow(clippy::type_complexity)]
let (first_batch, second_batch): (
Vec<(VertexIdType, Vec<VertexIdType>)>,
Vec<(VertexIdType, Vec<VertexIdType>)>,
) = tmp.partition(|(v, _)| ((v - 1) / 4) % 2 == 0); // this yields 2 ind. batches, just trust me

// main loop
let mut round = 0;
loop {
first_batch.par_iter().for_each(|(vid, neigh)| {
atomically(|trans| {
let mut new_val = Vertex2::default();
for v in neigh {
let vertex = map.read_vertex(trans, *v)?.unwrap();
new_val.0 += vertex.0;
new_val.1 += vertex.1;
}
new_val.0 /= neigh.len() as f64;
new_val.1 /= neigh.len() as f64;
map.write_vertex(trans, *vid, new_val)
});
});
second_batch.par_iter().for_each(|(vid, neigh)| {
atomically(|trans| {
let mut new_val = Vertex2::default();
for v in neigh {
let vertex = map.read_vertex(trans, *v)?.unwrap();
new_val.0 += vertex.0;
new_val.1 += vertex.1;
}
new_val.0 /= neigh.len() as f64;
new_val.1 /= neigh.len() as f64;
map.write_vertex(trans, *vid, new_val)
});
});
round += 1;
if round >= n_rounds {
break;
}
}

std::hint::black_box(map);
}
1 change: 1 addition & 0 deletions honeycomb-kernels/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ publish = true
[dependencies]
honeycomb-core = { workspace = true, features = ["io", "utils"] }
num-traits.workspace = true
rayon = "1.10.0"
thiserror.workspace = true
vtkio.workspace = true

Expand Down