Skip to main content

weir/fixed_point_resident_plan/
owned.rs

1use super::{generic::PlanBuilder, FixedPointResidentPlan};
2use crate::fixed_point_graph::FixedPointForwardGraph;
3use crate::fixed_point_resident::FixedPointResidentGraph;
4use crate::fixed_point_resident_frontier::FixedPointResidentFrontierScratch;
5
6impl FixedPointResidentPlan {
7    /// Upload graph buffers and bind them to a compiled pipeline.
8    pub fn new(
9        backend: &dyn vyre::VyreBackend,
10        graph: &FixedPointForwardGraph,
11        pipeline: std::sync::Arc<dyn vyre::CompiledPipeline>,
12    ) -> Result<Self, vyre::BackendError> {
13        Ok(Self {
14            inner: PlanBuilder {
15                graph: FixedPointResidentGraph::upload(backend, graph)?,
16                pipeline,
17            },
18        })
19    }
20
21    /// Free resident graph and reusable frontier resources owned around this plan.
22    pub fn free_with_frontier(
23        self,
24        backend: &dyn vyre::VyreBackend,
25        resident_frontier: &mut FixedPointResidentFrontierScratch,
26    ) -> Result<(), vyre::BackendError> {
27        let frontier_result = resident_frontier.clear(backend);
28        let graph_result = self.inner.graph.free(backend);
29        match (frontier_result, graph_result) {
30            (Err(error), _) | (_, Err(error)) => Err(error),
31            (Ok(()), Ok(())) => Ok(()),
32        }
33    }
34
35    /// Free resident graph resources owned by this plan.
36    pub fn free(self, backend: &dyn vyre::VyreBackend) -> Result<(), vyre::BackendError> {
37        self.inner.graph.free(backend)
38    }
39}