gemm_common/
lib.rs

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