weirflow 0.1.0

GPU-first dataflow analysis primitives for Vyre and Santh compiler pipelines.
Documentation
use super::*;

// ------------------------------------------------------------------
// 22. Additional parameterized success tests for scale
// ------------------------------------------------------------------

macro_rules! dispatch_with_n_resources_test {
    ($name:ident, $n:expr) => {
        #[test]
        fn $name() {
            let b = backend();
            let a = adapter(&b);
            let mut resources = Vec::new();
            for _ in 0..$n {
                resources.push(a.allocate_resident(64).unwrap());
            }
            a.dispatch_resident(&program(), &resources, None).unwrap();
            assert_eq!(b.dispatch_count(), 1);
            assert_eq!(b.take_dispatches()[0].resource_handles.len(), $n);
            for r in resources {
                a.free_resident(r).unwrap();
            }
            assert!(b.alive_resources().is_empty());
        }
    };
}

dispatch_with_n_resources_test!(ifds_vyre_resident_dispatch_with_2_resources, 2);
dispatch_with_n_resources_test!(ifds_vyre_resident_dispatch_with_5_resources, 5);
dispatch_with_n_resources_test!(ifds_vyre_resident_dispatch_with_10_resources, 10);

macro_rules! sequence_with_n_steps_test {
    ($name:ident, $n:expr) => {
        #[test]
        fn $name() {
            let b = backend();
            let a = adapter(&b);
            let r = a.allocate_resident(64).unwrap();
            let p = program();
            let mut resources = Vec::new();
            let mut steps: Vec<(
                &vyre::ir::Program,
                &[vyre::backend::Resource],
                Option<[u32; 3]>,
            )> = Vec::new();
            for _ in 0..$n {
                resources.push(r.clone());
            }
            for res in &resources {
                steps.push((&p, std::slice::from_ref(res), None));
            }
            a.dispatch_resident_sequence_read_ranges_into(&steps, &[], &mut [])
                .unwrap();
            assert_eq!(b.dispatch_count(), $n);
            a.free_resident(r).unwrap();
        }
    };
}

sequence_with_n_steps_test!(ifds_vyre_resident_sequence_with_2_steps, 2);
sequence_with_n_steps_test!(ifds_vyre_resident_sequence_with_4_steps, 4);
sequence_with_n_steps_test!(ifds_vyre_resident_sequence_with_8_steps, 8);

macro_rules! repeated_with_n_repeats_test {
    ($name:ident, $n:expr) => {
        #[test]
        fn $name() {
            let b = backend();
            let a = adapter(&b);
            let r = a.allocate_resident(64).unwrap();
            let p = program();
            let resources = [r.clone()];
            a.dispatch_resident_repeated_sequence_read_ranges_into(
                &[],
                &[(&p, &resources[..], None)],
                $n,
                &[],
                &mut [],
            )
            .unwrap();
            assert_eq!(b.dispatch_count(), $n);
            a.free_resident(r).unwrap();
        }
    };
}

repeated_with_n_repeats_test!(ifds_vyre_resident_repeated_with_2_repeats, 2);
repeated_with_n_repeats_test!(ifds_vyre_resident_repeated_with_5_repeats, 5);
repeated_with_n_repeats_test!(ifds_vyre_resident_repeated_with_10_repeats, 10);