weirflow 0.1.0

GPU-first dataflow analysis primitives for Vyre and Santh compiler pipelines.
Documentation
use super::super::{DirectResidentIfdsBatch, DirectResidentIfdsGraphKey};
use crate::ifds_gpu::IfdsResidentDispatch;

impl<R> DirectResidentIfdsBatch<R>
where
    R: Clone,
{
    #[allow(clippy::too_many_arguments)]
    pub fn solve<D>(
        &mut self,
        dispatch: &D,
        num_procs: u32,
        blocks_per_proc: u32,
        facts_per_proc: u32,
        intra_edges: &[(u32, u32, u32)],
        inter_edges: &[(u32, u32, u32, u32)],
        flow_gen: &[(u32, u32, u32)],
        flow_kill: &[(u32, u32, u32)],
        seed_facts: &[(u32, u32, u32)],
        max_iterations: u32,
    ) -> Result<Vec<u32>, String>
    where
        D: IfdsResidentDispatch<Resource = R>,
    {
        let mut result = crate::staging_reserve::reserved_vec(
            seed_facts.len(),
            "direct resident IFDS result fact",
        )?;
        self.solve_into(
            dispatch,
            num_procs,
            blocks_per_proc,
            facts_per_proc,
            intra_edges,
            inter_edges,
            flow_gen,
            flow_kill,
            seed_facts,
            max_iterations,
            &mut result,
        )?;
        Ok(result)
    }

    #[allow(clippy::too_many_arguments)]
    fn direct_graph_key(
        num_procs: u32,
        blocks_per_proc: u32,
        facts_per_proc: u32,
        intra_edges: &[(u32, u32, u32)],
        inter_edges: &[(u32, u32, u32, u32)],
        flow_gen: &[(u32, u32, u32)],
        flow_kill: &[(u32, u32, u32)],
    ) -> DirectResidentIfdsGraphKey {
        DirectResidentIfdsGraphKey::from_edges(
            num_procs,
            blocks_per_proc,
            facts_per_proc,
            intra_edges,
            inter_edges,
            flow_gen,
            flow_kill,
        )
    }

    /// Solve one seed set into caller-owned result storage, preparing and
    /// caching the direct-resident CSR if needed.
    #[allow(clippy::too_many_arguments)]
    pub fn solve_into<D>(
        &mut self,
        dispatch: &D,
        num_procs: u32,
        blocks_per_proc: u32,
        facts_per_proc: u32,
        intra_edges: &[(u32, u32, u32)],
        inter_edges: &[(u32, u32, u32, u32)],
        flow_gen: &[(u32, u32, u32)],
        flow_kill: &[(u32, u32, u32)],
        seed_facts: &[(u32, u32, u32)],
        max_iterations: u32,
        result: &mut Vec<u32>,
    ) -> Result<(), String>
    where
        D: IfdsResidentDispatch<Resource = R>,
    {
        let graph_key = DirectResidentIfdsGraphKey::from_edges(
            num_procs,
            blocks_per_proc,
            facts_per_proc,
            intra_edges,
            inter_edges,
            flow_gen,
            flow_kill,
        );
        self.solve_single_validated_graph_key_into(
            dispatch,
            graph_key,
            intra_edges,
            inter_edges,
            flow_gen,
            flow_kill,
            seed_facts,
            max_iterations,
            result,
        )
    }

    /// Solve many seed sets into caller-owned result storage, preparing and
    /// caching the direct-resident CSR if needed.
    #[allow(clippy::too_many_arguments)]
    pub fn solve_many_into<D>(
        &mut self,
        dispatch: &D,
        num_procs: u32,
        blocks_per_proc: u32,
        facts_per_proc: u32,
        intra_edges: &[(u32, u32, u32)],
        inter_edges: &[(u32, u32, u32, u32)],
        flow_gen: &[(u32, u32, u32)],
        flow_kill: &[(u32, u32, u32)],
        seed_sets: &[&[(u32, u32, u32)]],
        max_iterations: u32,
        results: &mut Vec<Vec<u32>>,
    ) -> Result<(), String>
    where
        D: IfdsResidentDispatch<Resource = R>,
    {
        if seed_sets.is_empty() {
            results.clear();
            return Ok(());
        }
        if seed_sets.iter().all(|seed_facts| seed_facts.is_empty()) {
            crate::dispatch_decode::require_positive_iterations(
                "weir direct resident IFDS solve many with direct graph key into",
                max_iterations,
            )?;
            super::resize_and_clear_result_slots(results, seed_sets.len())?;
            return Ok(());
        }
        let graph_key = Self::direct_graph_key(
            num_procs,
            blocks_per_proc,
            facts_per_proc,
            intra_edges,
            inter_edges,
            flow_gen,
            flow_kill,
        );
        self.solve_many_validated_graph_key_into(
            dispatch,
            graph_key,
            intra_edges,
            inter_edges,
            flow_gen,
            flow_kill,
            seed_sets,
            max_iterations,
            results,
        )
    }
}