use crate::{Refusal, Rendezvous, Space};
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, Default)]
pub enum Delivery {
#[default]
SyncPerUnit,
AsyncPerUnit,
AsyncBulk,
Tma,
Procedural,
}
const TMA_MAX_BOX_DIM: usize = 256;
impl Delivery {
pub const TMA_STAGE_ALIGNMENT: usize = 1024;
pub fn moves(self, stage: &Space) -> Result<(), Refusal> {
match self {
Delivery::SyncPerUnit
| Delivery::AsyncPerUnit
| Delivery::AsyncBulk
| Delivery::Procedural => Ok(()),
Delivery::Tma => match stage
.extents()
.into_iter()
.find(|&(_, edge)| edge > TMA_MAX_BOX_DIM)
{
Some((axis, edge)) => Err(Refusal::BoxPastDescriptor {
axis,
edge,
most: TMA_MAX_BOX_DIM,
}),
None => Ok(()),
},
}
}
pub fn is_tma(&self) -> bool {
matches!(self, Delivery::Tma)
}
pub(crate) fn is_async(&self) -> bool {
match self {
Delivery::SyncPerUnit | Delivery::Procedural => false,
Delivery::AsyncPerUnit | Delivery::AsyncBulk | Delivery::Tma => true,
}
}
pub(crate) fn rendezvous(&self) -> Rendezvous {
if self.is_async() {
Rendezvous::Barrier
} else {
Rendezvous::Cube
}
}
pub(crate) fn through_async_proxy(&self) -> bool {
matches!(self, Delivery::AsyncBulk | Delivery::Tma)
}
pub(crate) fn every_unit_fills(&self) -> bool {
match self {
Delivery::SyncPerUnit | Delivery::AsyncPerUnit | Delivery::Procedural => true,
Delivery::AsyncBulk | Delivery::Tma => false,
}
}
}