use super::*;
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum ParallelStrategyKind {
Data,
Tensor,
Pipeline,
}
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
pub struct StrategySet(u8);
impl StrategySet {
pub const NONE: Self = Self(0);
pub const DATA: Self = Self(1 << 0);
pub const TENSOR: Self = Self(1 << 1);
pub const PIPELINE: Self = Self(1 << 2);
pub const ALL: Self = Self(Self::DATA.0 | Self::TENSOR.0 | Self::PIPELINE.0);
#[must_use]
pub const fn contains(self, strategy: ParallelStrategyKind) -> bool {
let bit = match strategy {
ParallelStrategyKind::Data => Self::DATA.0,
ParallelStrategyKind::Tensor => Self::TENSOR.0,
ParallelStrategyKind::Pipeline => Self::PIPELINE.0,
};
self.0 & bit != 0
}
#[must_use]
pub const fn union(self, other: Self) -> Self {
Self(self.0 | other.0)
}
#[must_use]
pub const fn is_empty(self) -> bool {
self.0 == 0
}
}
impl core::ops::BitOr for StrategySet {
type Output = Self;
fn bitor(self, rhs: Self) -> Self::Output {
self.union(rhs)
}
}
impl core::ops::BitOrAssign for StrategySet {
fn bitor_assign(&mut self, rhs: Self) {
*self = self.union(rhs);
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum ParallelStrategy {
Data,
Tensor,
Pipeline,
Auto {
allowed: StrategySet,
},
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum MemoryLimit {
PerRankBytes(usize),
PerDeviceFraction(f64),
}
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
pub enum PlanObjective {
#[default]
MinimizeStepTime,
MinimizeMemory,
MinimizeCommunication,
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct ParallelOptions {
pub strategy: ParallelStrategy,
pub memory_limit: MemoryLimit,
pub remainder: ShardRemainderPolicy,
pub schedule: PipelineSchedule,
pub objective: PlanObjective,
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct StaticParallelOptions {
pub memory_limit: MemoryLimit,
pub remainder: ShardRemainderPolicy,
pub objective: PlanObjective,
}