use super::partition::{Stage, partition, partition_with};
use super::pipeline::{NamedTensor, run_pipeline_local};
use crate::source::ParamSource;
use rlx_ir::Graph;
use rlx_runtime::{CompileOptions, Device};
use std::io;
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
pub struct Pipeline {
stages: Vec<Stage>,
}
impl Pipeline {
pub fn partition(graph: &Graph, n_stages: usize) -> Self {
Self {
stages: partition(graph, n_stages),
}
}
pub fn partition_with(
graph: &Graph,
n_stages: usize,
assign: impl Fn(usize, usize) -> usize,
) -> Self {
Self {
stages: partition_with(graph, n_stages, assign),
}
}
pub fn from_stages(stages: Vec<Stage>) -> Self {
Self { stages }
}
pub fn stages(&self) -> &[Stage] {
&self.stages
}
pub fn len(&self) -> usize {
self.stages.len()
}
pub fn is_empty(&self) -> bool {
self.stages.is_empty()
}
pub fn into_stages(self) -> Vec<Stage> {
self.stages
}
pub fn run_local(
self,
source: &mut dyn ParamSource,
inputs: Vec<NamedTensor>,
device: Device,
opts: &CompileOptions,
) -> Vec<NamedTensor> {
run_pipeline_local(self.stages, source, inputs, device, opts)
}
pub fn run_tcp(
&self,
worker_addrs: &[String],
inputs: Vec<NamedTensor>,
) -> io::Result<Vec<NamedTensor>> {
super::transport::run_pipeline_tcp(&self.stages, worker_addrs, inputs)
}
}