Skip to content
Snippets Groups Projects

Set up cava benchmark

Merged rarbore2 requested to merge cava_opt_3 into main
Files
3
@@ -10,11 +10,11 @@ juno_build::juno!("matmul");
@@ -10,11 +10,11 @@ juno_build::juno!("matmul");
fn main() {
fn main() {
async_std::task::block_on(async {
async_std::task::block_on(async {
const I: usize = 256;
const I: usize = 256;
const J: usize = 8; // hardcoded constant in matmul.hir
const J: usize = 64;
const K: usize = 128;
const K: usize = 128;
let a: Box<[f32]> = (0..I * J).map(|_| random::<f32>()).collect();
let a: Box<[i32]> = (0..I * J).map(|_| random::<i32>() % 100).collect();
let b: Box<[f32]> = (0..J * K).map(|_| random::<f32>()).collect();
let b: Box<[i32]> = (0..J * K).map(|_| random::<i32>() % 100).collect();
let mut correct_c: Box<[f32]> = (0..I * K).map(|_| 0.0).collect();
let mut correct_c: Box<[i32]> = (0..I * K).map(|_| 0).collect();
for i in 0..I {
for i in 0..I {
for k in 0..K {
for k in 0..K {
for j in 0..J {
for j in 0..J {
@@ -22,13 +22,11 @@ fn main() {
@@ -22,13 +22,11 @@ fn main() {
}
}
}
}
}
}
let a = HerculesImmBox::from(&a as &[f32]);
let a = HerculesImmBox::from(a.as_ref());
let b = HerculesImmBox::from(&b as &[f32]);
let b = HerculesImmBox::from(b.as_ref());
let mut r = runner!(matmul);
let mut r = runner!(matmul);
let mut c = HerculesMutBox::from(r.run(I as u64, J as u64, K as u64, a.to(), b.to()).await);
let mut c: HerculesMutBox<i32> = HerculesMutBox::from(r.run(I as u64, J as u64, K as u64, a.to(), b.to()).await);
for (calc, correct) in zip(c.as_slice().into_iter().map(|x: &mut f32| *x), correct_c) {
assert_eq!(c.as_slice(), correct_c.as_ref());
assert!((calc - correct).abs() < 0.0001, "{} != {}", calc, correct);
}
});
});
}
}
Loading