From e1e4202c28b67e08aa2c687332dc0752fcd6d81c Mon Sep 17 00:00:00 2001 From: Christian Legnitto Date: Wed, 26 Mar 2025 10:59:37 -0400 Subject: [PATCH] Deal with overflow for flops calculation This wasn't working with larger matrices. Also labeled it GFlops as that is what is being output. --- blog/2024-11-25-optimizing-matmul/code/bin/blog/src/bin.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/blog/2024-11-25-optimizing-matmul/code/bin/blog/src/bin.rs b/blog/2024-11-25-optimizing-matmul/code/bin/blog/src/bin.rs index 2ddfd1f..5f7d20e 100644 --- a/blog/2024-11-25-optimizing-matmul/code/bin/blog/src/bin.rs +++ b/blog/2024-11-25-optimizing-matmul/code/bin/blog/src/bin.rs @@ -158,9 +158,10 @@ fn run_test>(multiplier: U, size: (u32, u32, u3 // Calculate FLOPS let flop_span = span!(Level::DEBUG, "calculate_flops"); let _flop_enter = flop_span.enter(); - let ops = 2.0 * (m * n * k) as f64; - let flops = ops / compute_time.as_secs_f64() / 1e9; - info!("Flops: {}", flops); + let ops = 2.0 * (m as u64 * n as u64 * k as u64) as f64; + let flops = ops / compute_time.as_secs_f64(); + let gflops = flops / 1e9; + info!("GFlops: {}", gflops); drop(_flop_enter); // Verification phase