#![allow(
clippy::expect_used,
clippy::panic,
clippy::print_stderr,
clippy::cast_possible_wrap,
clippy::float_cmp
)]
use std::io::Write;
fn splitmix64(state: &mut u64) -> u64 {
*state = state.wrapping_add(0x9E37_79B9_7F4A_7C15);
let mut z = *state;
z = (z ^ (z >> 30)).wrapping_mul(0xBF58_476D_1CE4_E5B9);
z = (z ^ (z >> 27)).wrapping_mul(0x94D0_49BB_1331_11EB);
z ^ (z >> 31)
}
fn fill_matrix(rows: usize, cols: usize, seed: u64) -> Vec<f64> {
let mut state = seed;
let mut buf = Vec::with_capacity(rows * cols);
for _ in 0..(rows * cols) {
let r = splitmix64(&mut state);
let bits = (r >> 12) & ((1_u64 << 52) - 1);
let exp_bias = 1023_u64;
let f = f64::from_bits((exp_bias << 52) | bits) - 1.5;
buf.push(f);
}
buf
}
fn main() {
const K: usize = 100;
const D: usize = 50;
const N: usize = 16;
let a = fill_matrix(K, D, 0x1234_5678_9ABC_DEF0);
let b = fill_matrix(D, N, 0x0FED_CBA9_8765_4321);
let mut c = vec![0.0_f64; K * N];
unsafe {
matrixmultiply::dgemm(
K,
D,
N,
1.0,
a.as_ptr(),
D as isize,
1,
b.as_ptr(),
N as isize,
1,
0.0,
c.as_mut_ptr(),
N as isize,
1,
);
}
if c.iter().all(|&v| v == 0.0) {
eprintln!("ERROR: dgemm produced all-zero output");
std::process::exit(1);
}
let stdout = std::io::stdout();
let mut out = stdout.lock();
for v in &c {
out.write_all(&v.to_le_bytes()).expect("write to stdout");
}
eprintln!(
"Wrote {} bytes ({} f64 values) to stdout; pipe through `sha256sum` to compare across hosts.",
c.len() * 8,
c.len()
);
}