Skip to content

Commit

Permalink
Add init/read timing for Rust
Browse files Browse the repository at this point in the history
  • Loading branch information
tom91136 committed Oct 7, 2023
1 parent 5f3741e commit 512a6fa
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/rust/rust-stream/rustfmt.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ use_field_init_shorthand = false
force_explicit_abi = true
condense_wildcard_suffixes = false
color = "Auto"
required_version = "1.4.38"
required_version = "1.6.0"
unstable_features = false
disable_all_formatting = false
skip_children = false
Expand Down
47 changes: 43 additions & 4 deletions src/rust/rust-stream/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ where StreamData<T, D, A>: RustStream<T> {
);
}

stream.init_arrays();
let init = stream.run_init_arrays();

let tabulate = |xs: &Vec<Duration>, name: &str, t_size: usize| -> Vec<(&str, String)> {
let tail = &xs[1..]; // tail only
Expand Down Expand Up @@ -235,10 +235,47 @@ where StreamData<T, D, A>: RustStream<T> {
};
};

let show_setup = |init: Duration, read: Duration| {
let setup = vec![
("Init", init.as_secs_f64(), 3 * array_bytes),
("Read", read.as_secs_f64(), 3 * array_bytes),
];
if option.csv {
tabulate_all(
setup
.iter()
.map(|(name, elapsed, t_size)| {
vec![
("phase", name.to_string()),
("n_elements", option.arraysize.to_string()),
("sizeof", t_size.to_string()),
(
if option.mibibytes { "max_mibytes_per_sec" } else { "max_mbytes_per_sec" },
(mega_scale * (*t_size as f64) / elapsed).to_string(),
),
("runtime", elapsed.to_string()),
]
})
.collect::<Vec<_>>(),
);
} else {
for (name, elapsed, t_size) in setup {
println!(
"{}: {:.5} s (={:.5} {})",
name,
elapsed,
mega_scale * (t_size as f64) / elapsed,
if option.mibibytes { "MiBytes/sec" } else { "MBytes/sec" }
);
}
}
};

let solutions_correct = match benchmark {
Benchmark::All => {
let (results, sum) = stream.run_all(option.numtimes);
stream.read_arrays();
let read = stream.run_read_arrays();
show_setup(init, read);
let correct = check_solution(benchmark, option.numtimes, &stream, Some(sum));
tabulate_all(vec![
tabulate(&results.copy, "Copy", 2 * array_bytes),
Expand All @@ -251,14 +288,16 @@ where StreamData<T, D, A>: RustStream<T> {
}
Benchmark::NStream => {
let results = stream.run_nstream(option.numtimes);
stream.read_arrays();
let read = stream.run_read_arrays();
show_setup(init, read);
let correct = check_solution(benchmark, option.numtimes, &stream, None);
tabulate_all(vec![tabulate(&results, "Nstream", 4 * array_bytes)]);
correct
}
Benchmark::Triad => {
let results = stream.run_triad(option.numtimes);
stream.read_arrays();
let read = stream.run_read_arrays();
show_setup(init, read);
let correct = check_solution(benchmark, option.numtimes, &stream, None);
let total_bytes = 3 * array_bytes * option.numtimes;
let bandwidth = giga_scale * (total_bytes as f64 / results.as_secs_f64());
Expand Down
12 changes: 12 additions & 0 deletions src/rust/rust-stream/src/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,18 @@ pub trait RustStream<T: Default> {
fn nstream(&mut self);
fn dot(&mut self) -> T;

fn run_init_arrays(&mut self) -> Duration {
timed(|| {
self.init_arrays();
})
}

fn run_read_arrays(&mut self) -> Duration {
timed(|| {
self.read_arrays();
})
}

fn run_all(&mut self, n: usize) -> (AllTiming<Vec<Duration>>, T) {
let mut timings: AllTiming<Vec<Duration>> = AllTiming {
copy: vec![Duration::default(); n],
Expand Down
8 changes: 4 additions & 4 deletions src/rust/rust-stream/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ use rstest::rstest;

#[rstest]
fn test_main(
#[values(0, 1, 2, 3, 4)] device: usize, //
#[values("", "--pin")] pin: &str, //
#[values("", "--malloc")] malloc: &str, //
#[values("", "--init")] init: &str, //
#[values(0, 1, 2, 3, 4)] device: usize, //
#[values("", "--pin")] pin: &str, //
#[values("", "--malloc")] malloc: &str, //
#[values("", "--init")] init: &str, //
#[values("", "--triad-only", "--nstream-only")] option: &str, //
) {
let line = format!(
Expand Down

0 comments on commit 512a6fa

Please sign in to comment.