pub struct CpuFeatures(/* private fields */);Expand description
A set of CPU features, named after rustc target_features.
Unlike SimdSupport, this is not a ladder: a kernel can require any
combination, such as AVX-512 without FMA or F16C on an AVX host.
use lance_core::utils::cpu::CpuFeatures;
// Implied features are included: AVX2 brings AVX along with it.
let needed = CpuFeatures::from_target_features(&["avx2", "fma"]);
assert!(needed.contains(CpuFeatures::AVX));
// A kernel can run here if the host has every feature it needs, and can
// be called directly, without dispatch, if the build baseline does.
let runnable = CpuFeatures::host().contains(needed);
let inlinable = CpuFeatures::baseline().contains(needed);
assert!(runnable || !inlinable);Implementations§
Source§impl CpuFeatures
impl CpuFeatures
pub const SSE2: Self
pub const SSE3: Self
pub const SSSE3: Self
pub const SSE4_1: Self
pub const SSE4_2: Self
pub const POPCNT: Self
pub const AVX: Self
pub const AVX2: Self
pub const FMA: Self
pub const F16C: Self
pub const BMI1: Self
pub const BMI2: Self
pub const AVX512F: Self
pub const AVX512BW: Self
pub const AVX512CD: Self
pub const AVX512DQ: Self
pub const AVX512VL: Self
pub const AVX512FP16: Self
pub const NEON: Self
pub const FP16: Self
pub const LSX: Self
pub const LASX: Self
Sourcepub const fn contains(self, other: Self) -> bool
pub const fn contains(self, other: Self) -> bool
Whether every feature in other is also in self.
Sourcepub const fn baseline() -> Self
pub const fn baseline() -> Self
Features the build enables for all code, e.g. via -C target-cpu.
A kernel whose features are all in the baseline can be called directly
and inlined; see Dispatch.
Sourcepub const fn from_target_feature(name: &str) -> Option<Self>
pub const fn from_target_feature(name: &str) -> Option<Self>
The feature set for one rustc target_feature name, including the
features rustc enables along with it. None if the name is unknown.
Implied features matter for soundness: #[target_feature(enable = "avx512f")] also lets codegen use AVX2, FMA and F16C, so a kernel
declaring it must not run on a host that lacks any of them.
Sourcepub const fn from_target_features(names: &[&str]) -> Self
pub const fn from_target_features(names: &[&str]) -> Self
Union of Self::from_target_feature over names.
§Panics
Panics if a name is unknown. target_kernel!
evaluates this in a const, so a typo is a compile error there.
Trait Implementations§
Source§impl Clone for CpuFeatures
impl Clone for CpuFeatures
impl Copy for CpuFeatures
Source§impl Debug for CpuFeatures
impl Debug for CpuFeatures
Source§impl Default for CpuFeatures
impl Default for CpuFeatures
impl Eq for CpuFeatures
Source§impl Hash for CpuFeatures
impl Hash for CpuFeatures
Source§impl PartialEq for CpuFeatures
impl PartialEq for CpuFeatures
impl StructuralPartialEq for CpuFeatures
Auto Trait Implementations§
impl Freeze for CpuFeatures
impl RefUnwindSafe for CpuFeatures
impl Send for CpuFeatures
impl Sync for CpuFeatures
impl Unpin for CpuFeatures
impl UnsafeUnpin for CpuFeatures
impl UnwindSafe for CpuFeatures
Blanket Implementations§
impl<T> Allocation for T
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.