use core::fmt::{Debug, Display};
use cubecl::tile::launch::{Refusal, Vectorization};
use crate::Hardware;
use crate::microkernel::{CubePlanes, KernelEstimate};
pub trait Microkernel: Debug + Clone + PartialEq + Sized {
type WorkItem: Debug + Clone;
type Settings: Debug + Clone + Display;
type Operand: Debug + Copy + Eq;
type CubeSpace: Debug + Clone;
const DECLINE: &'static str;
fn settings(hw: &Hardware) -> Vec<Self::Settings>;
fn candidates(
hw: &Hardware,
item: &Self::WorkItem,
settings: &Self::Settings,
) -> impl Iterator<Item = Self>;
fn admits(_item: &Self::WorkItem) -> Result<(), Refusal> {
Ok(())
}
fn decline(_settings: &Self::Settings) -> &'static str {
Self::DECLINE
}
fn best(
hw: &Hardware,
item: &Self::WorkItem,
settings: &Self::Settings,
) -> Result<Self, Refusal> {
Self::admits(item)?;
Self::candidates(hw, item, settings)
.next()
.ok_or(Refusal::Declined {
why: Self::decline(settings),
})
}
fn vectorize(
&self,
cube_space: &Self::CubeSpace,
vectorization: &mut Vectorization<Self::Operand>,
);
fn estimate(
&self,
item: &Self::WorkItem,
cube_space: &Self::CubeSpace,
planes: CubePlanes,
estimate: &mut KernelEstimate,
);
}