use eyre::{Result, eyre};
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Precision {
Fp32,
Tf32,
Bf16,
}
impl Precision {
const ALL: [Self; 3] = [Self::Fp32, Self::Tf32, Self::Bf16];
pub fn as_str(self) -> &'static str {
match self {
Self::Fp32 => "fp32",
Self::Tf32 => "tf32",
Self::Bf16 => "bf16",
}
}
}
impl std::fmt::Display for Precision {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.pad(self.as_str())
}
}
impl std::str::FromStr for Precision {
type Err = eyre::Report;
fn from_str(s: &str) -> Result<Self> {
Self::ALL
.into_iter()
.find(|p| p.as_str() == s)
.ok_or_else(|| eyre!("unknown precision {s:?}, expected fp32, tf32 or bf16"))
}
}