gemm_common/
lib.rs

1#![cfg_attr(
2    all(feature = "nightly", any(target_arch = "x86", target_arch = "x86_64")),
3    feature(stdarch_x86_avx512),
4    feature(avx512_target_feature)
5)]
6#![cfg_attr(not(feature = "std"), no_std)]
7
8use core::sync::atomic::{AtomicBool, Ordering::Relaxed};
9
10#[cfg(feature = "wasm-simd128-enable")]
11pub const DEFAULT_WASM_SIMD128: bool = true;
12
13#[cfg(not(feature = "wasm-simd128-enable"))]
14pub const DEFAULT_WASM_SIMD128: bool = false;
15
16static WASM_SIMD128: AtomicBool = AtomicBool::new(DEFAULT_WASM_SIMD128);
17
18#[inline]
19pub fn get_wasm_simd128() -> bool {
20    WASM_SIMD128.load(Relaxed)
21}
22#[inline]
23pub fn set_wasm_simd128(enable: bool) {
24    WASM_SIMD128.store(enable, Relaxed)
25}
26
27extern crate alloc;
28
29pub mod cache;
30
31pub mod gemm;
32pub mod gemv;
33pub mod gevv;
34
35pub mod horizontal_microkernel;
36pub mod microkernel;
37
38pub mod pack_operands;
39pub mod simd;
40
41pub use pulp;
42
43#[derive(Copy, Clone, Debug)]
44pub enum Parallelism {
45    None,
46    #[cfg(feature = "rayon")]
47    Rayon(usize),
48}
49
50pub struct Ptr<T: ?Sized>(pub *mut T);
51
52impl<T: ?Sized> Clone for Ptr<T> {
53    #[inline]
54    fn clone(&self) -> Self {
55        *self
56    }
57}
58impl<T: ?Sized> Copy for Ptr<T> {}
59
60unsafe impl<T: ?Sized> Send for Ptr<T> {}
61unsafe impl<T: ?Sized> Sync for Ptr<T> {}
62
63impl<T> Ptr<T> {
64    #[inline(always)]
65    pub fn wrapping_offset(self, offset: isize) -> Self {
66        Ptr::<T>(self.0.wrapping_offset(offset))
67    }
68    #[inline(always)]
69    pub fn wrapping_add(self, offset: usize) -> Self {
70        Ptr::<T>(self.0.wrapping_add(offset))
71    }
72}
73
74#[cfg(not(feature = "std"))]
75#[macro_export]
76macro_rules! feature_detected {
77    ($tt: tt) => {
78        cfg!(feature = $tt)
79    };
80}
81
82#[cfg(all(feature = "std", any(target_arch = "x86", target_arch = "x86_64")))]
83#[macro_export]
84macro_rules! feature_detected {
85    ($tt: tt) => {
86        ::std::arch::is_x86_feature_detected!($tt)
87    };
88}
89#[cfg(all(feature = "std", target_arch = "aarch64"))]
90#[macro_export]
91macro_rules! feature_detected {
92    ($tt: tt) => {
93        ::std::arch::is_aarch64_feature_detected!($tt)
94    };
95}
96#[cfg(all(feature = "std", target_family = "wasm"))]
97#[macro_export]
98macro_rules! feature_detected {
99    ("simd128") => {
100        $crate::get_wasm_simd128()
101    };
102}