pub trait AmxSupport {
fn has_amx() -> bool;
}
pub trait Avx512Support {
fn has_avx512() -> bool;
}
pub trait FmaSupport {
fn has_fma() -> bool;
}
#[cfg(target_arch = "x86_64")]
#[inline]
pub fn has_fma3() -> bool {
use std::sync::OnceLock;
static CACHED: OnceLock<bool> = OnceLock::new();
*CACHED.get_or_init(|| std::is_x86_feature_detected!("fma"))
}
#[cfg(not(target_arch = "x86_64"))]
#[inline]
pub fn has_fma3() -> bool {
false
}
impl FmaSupport for f32 {
#[inline]
fn has_fma() -> bool {
has_fma3()
}
}
impl FmaSupport for f64 {
#[inline]
fn has_fma() -> bool {
has_fma3()
}
}
impl FmaSupport for Bf16 {
#[inline]
fn has_fma() -> bool {
has_fma3()
}
}
impl AmxSupport for Bf16 {
#[inline]
fn has_amx() -> bool {
#[cfg(target_arch = "x86_64")]
{
has_amx_bf16()
}
#[cfg(not(target_arch = "x86_64"))]
{
false
}
}
}
impl AmxSupport for i8 {
#[inline]
fn has_amx() -> bool {
#[cfg(target_arch = "x86_64")]
{
has_amx_int8()
}
#[cfg(not(target_arch = "x86_64"))]
{
false
}
}
}
impl Avx512Support for Bf16 {
#[inline]
fn has_avx512() -> bool {
#[cfg(target_arch = "x86_64")]
{
has_avx512_bf16_tile()
}
#[cfg(not(target_arch = "x86_64"))]
{
false
}
}
}
impl Avx512Support for i8 {
#[inline]
fn has_avx512() -> bool {
#[cfg(target_arch = "x86_64")]
{
has_avx512_vnni_tile()
}
#[cfg(not(target_arch = "x86_64"))]
{
false
}
}
}
#[cfg(target_arch = "x86_64")]
#[inline]
fn has_amx_bf16() -> bool {
use std::sync::OnceLock;
static CACHED: OnceLock<bool> = OnceLock::new();
*CACHED.get_or_init(|| false)
}
#[cfg(target_arch = "x86_64")]
#[inline]
fn has_amx_int8() -> bool {
use std::sync::OnceLock;
static CACHED: OnceLock<bool> = OnceLock::new();
*CACHED.get_or_init(|| false)
}
#[cfg(target_arch = "x86_64")]
#[inline]
fn has_avx512_bf16_tile() -> bool {
use std::sync::OnceLock;
static CACHED: OnceLock<bool> = OnceLock::new();
*CACHED.get_or_init(|| {
std::is_x86_feature_detected!("avx512f")
&& std::is_x86_feature_detected!("avx512bw")
&& std::is_x86_feature_detected!("avx512vl")
})
}
#[cfg(target_arch = "x86_64")]
#[inline]
pub fn has_avx_vnni() -> bool {
use std::sync::OnceLock;
static CACHED: OnceLock<bool> = OnceLock::new();
*CACHED.get_or_init(|| std::is_x86_feature_detected!("avxvnni"))
}
#[cfg(target_arch = "x86_64")]
#[inline]
fn has_avx512_vnni_tile() -> bool {
use std::sync::OnceLock;
static CACHED: OnceLock<bool> = OnceLock::new();
*CACHED.get_or_init(|| {
std::is_x86_feature_detected!("avx512f") && std::is_x86_feature_detected!("avx512vnni")
})
}
use eunomia::Bf16;