#[macro_export]
#[doc(hidden)]
macro_rules! dispatch_f16_type {
($T:ident, $body:block, $dtype:expr, $error_op:expr, $type:ty) => {{
#[cfg(feature = "f16")]
{
type $T = $type;
$body
}
#[cfg(not(feature = "f16"))]
{
return Err($crate::error::Error::FeatureRequired {
dtype: $dtype,
feature: "f16",
});
}
}};
}
#[macro_export]
#[doc(hidden)]
macro_rules! dispatch_fp8_type {
($T:ident, $body:block, $dtype:expr, $error_op:expr, $type:ty) => {{
#[cfg(feature = "fp8")]
{
type $T = $type;
$body
}
#[cfg(not(feature = "fp8"))]
{
return Err($crate::error::Error::FeatureRequired {
dtype: $dtype,
feature: "fp8",
});
}
}};
}
#[macro_export]
macro_rules! dispatch_dtype {
($dtype:expr, $T:ident => $body:block, $error_op:expr) => {
match $dtype {
$crate::dtype::DType::F64 => {
type $T = f64;
$body
}
$crate::dtype::DType::F32 => {
type $T = f32;
$body
}
$crate::dtype::DType::F16 => {
$crate::dispatch_f16_type!($T, $body, $dtype, $error_op, half::f16)
}
$crate::dtype::DType::BF16 => {
$crate::dispatch_f16_type!($T, $body, $dtype, $error_op, half::bf16)
}
$crate::dtype::DType::FP8E4M3 => {
$crate::dispatch_fp8_type!($T, $body, $dtype, $error_op, $crate::dtype::FP8E4M3)
}
$crate::dtype::DType::FP8E5M2 => {
$crate::dispatch_fp8_type!($T, $body, $dtype, $error_op, $crate::dtype::FP8E5M2)
}
$crate::dtype::DType::I64 => {
type $T = i64;
$body
}
$crate::dtype::DType::I32 => {
type $T = i32;
$body
}
$crate::dtype::DType::I16 => {
type $T = i16;
$body
}
$crate::dtype::DType::I8 => {
type $T = i8;
$body
}
$crate::dtype::DType::U64 => {
type $T = u64;
$body
}
$crate::dtype::DType::U32 => {
type $T = u32;
$body
}
$crate::dtype::DType::U16 => {
type $T = u16;
$body
}
$crate::dtype::DType::U8 => {
type $T = u8;
$body
}
$crate::dtype::DType::Bool => {
return Err($crate::error::Error::UnsupportedDType {
dtype: $dtype,
op: $error_op,
})
}
$crate::dtype::DType::Complex64 => {
type $T = $crate::dtype::Complex64;
$body
}
$crate::dtype::DType::Complex128 => {
type $T = $crate::dtype::Complex128;
$body
}
}
};
}