Skip to content
Snippets Groups Projects
main.rs 1.1 KiB
Newer Older
  • Learn to ignore specific revisions
  • #![feature(concat_idents)]
    
    rarbore2's avatar
    rarbore2 committed
    use std::iter::zip;
    
    rarbore2's avatar
    rarbore2 committed
    
    
    rarbore2's avatar
    rarbore2 committed
    use rand::random;
    
    
    rarbore2's avatar
    rarbore2 committed
    use hercules_rt::{runner, HerculesImmBox, HerculesImmBoxTo, HerculesMutBox};
    
    rarbore2's avatar
    rarbore2 committed
    
    
    rarbore2's avatar
    rarbore2 committed
    juno_build::juno!("matmul");
    
    
    fn main() {
    
        async_std::task::block_on(async {
    
    rarbore2's avatar
    rarbore2 committed
            const I: usize = 256;
    
    rarbore2's avatar
    rarbore2 committed
            const J: usize = 64;
    
    rarbore2's avatar
    rarbore2 committed
            const K: usize = 128;
    
    rarbore2's avatar
    rarbore2 committed
            let a: Box<[i32]> = (0..I * J).map(|_| random::<i32>() % 100).collect();
            let b: Box<[i32]> = (0..J * K).map(|_| random::<i32>() % 100).collect();
    
    rarbore2's avatar
    rarbore2 committed
            let mut correct_c: Box<[i32]> = (0..I * K).map(|_| 0).collect();
            for i in 0..I {
                for k in 0..K {
                    for j in 0..J {
                        correct_c[i * K + k] += a[i * J + j] * b[j * K + k];
                    }
                }
            }
    
    rarbore2's avatar
    rarbore2 committed
            let a = HerculesImmBox::from(a.as_ref());
            let b = HerculesImmBox::from(b.as_ref());
            let mut r = runner!(matmul);
    
    Aaron Councilman's avatar
    Aaron Councilman committed
            let mut c: HerculesMutBox<i32> =
                HerculesMutBox::from(r.run(I as u64, J as u64, K as u64, a.to(), b.to()).await);
    
    rarbore2's avatar
    rarbore2 committed
            assert_eq!(c.as_slice(), correct_c.as_ref());
    
    rarbore2's avatar
    rarbore2 committed
    
    #[test]
    fn matmul_test() {
        main();
    }