mod common;
mod common_kernels;
#[cfg(feature = "mkl")]
mod cpu_mkl;
mod cpu_pure;
use std::fmt::Debug;
use crate::tensor::mem_formats::layout::Layout;
use crate::tensor::ops::def_op::OpKind;
use crate::tensor::storage::TensorData;
use crate::tensor::traits::Numeric;
pub trait Dtype: Copy + Numeric {}
impl Dtype for f32 {}
impl Dtype for f64 {}
pub trait ComputeFor<B: Backend>: Dtype {
fn compute(
op: &OpKind<Self>,
output_buffer: Vec<Self>,
output_layout: &Layout,
inputs: &[TensorData<Self>],
) -> TensorData<Self>;
fn compute_inplace(
op: &OpKind<Self>,
output_layout: &Layout,
inputs: Vec<TensorData<Self>>,
output_idx: usize,
) -> TensorData<Self>;
}
pub trait Backend: Sized + Debug {
const SUPPORTS_2D_TRANSPOSED_MATMUL: bool = Self::SUPPORTS_NON_CONTIGUOUS_MATMUL;
const SUPPORTS_NON_CONTIGUOUS_MATMUL: bool;
fn compute<T>(
op: &OpKind<T>,
output_buffer: Vec<T>,
output_layout: &Layout,
inputs: &[TensorData<T>],
) -> TensorData<T>
where
T: Dtype + ComputeFor<Self>;
fn compute_inplace<T>(
op: &OpKind<T>,
output_layout: &Layout,
inputs: Vec<TensorData<T>>,
output_idx: usize,
) -> TensorData<T>
where
T: Dtype + ComputeFor<Self>;
}
#[cfg(feature = "mkl")]
pub type DefaultBackend = cpu_mkl::CpuMkl;
#[cfg(not(feature = "mkl"))]
pub type DefaultBackend = cpu_pure::CpuPure;
pub mod implementation {
#[cfg(feature = "mkl")]
pub use crate::tensor::backend::cpu_mkl::CpuMkl;
pub use crate::tensor::backend::cpu_pure::CpuPure;
}