diff --git a/src/rust/rust-stream/rustfmt.toml b/src/rust/rust-stream/rustfmt.toml index aa2f0e9..66b6235 100644 --- a/src/rust/rust-stream/rustfmt.toml +++ b/src/rust/rust-stream/rustfmt.toml @@ -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 diff --git a/src/rust/rust-stream/src/lib.rs b/src/rust/rust-stream/src/lib.rs index 3ac72c3..41ac0c2 100644 --- a/src/rust/rust-stream/src/lib.rs +++ b/src/rust/rust-stream/src/lib.rs @@ -174,7 +174,7 @@ where StreamData: RustStream { ); } - stream.init_arrays(); + let init = stream.run_init_arrays(); let tabulate = |xs: &Vec, name: &str, t_size: usize| -> Vec<(&str, String)> { let tail = &xs[1..]; // tail only @@ -235,10 +235,47 @@ where StreamData: RustStream { }; }; + 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::>(), + ); + } 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), @@ -251,14 +288,16 @@ where StreamData: RustStream { } 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()); diff --git a/src/rust/rust-stream/src/stream.rs b/src/rust/rust-stream/src/stream.rs index 560c6f1..86de56b 100644 --- a/src/rust/rust-stream/src/stream.rs +++ b/src/rust/rust-stream/src/stream.rs @@ -132,6 +132,18 @@ pub trait RustStream { 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>, T) { let mut timings: AllTiming> = AllTiming { copy: vec![Duration::default(); n], diff --git a/src/rust/rust-stream/tests/integration_test.rs b/src/rust/rust-stream/tests/integration_test.rs index 8031a79..0170546 100644 --- a/src/rust/rust-stream/tests/integration_test.rs +++ b/src/rust/rust-stream/tests/integration_test.rs @@ -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!(