#[cfg(all(feature = "accelerate", target_os = "macos"))]
#[allow(unsafe_code)]
mod accelerate;
#[allow(clippy::module_inception)]
mod backend;
#[cfg(all(feature = "cuda", target_os = "linux"))]
#[allow(unsafe_code)]
mod cuda;
#[cfg(all(feature = "metal", target_os = "macos"))]
#[allow(unsafe_code)]
mod metal;
#[cfg(any(
all(feature = "accelerate", target_os = "macos"),
all(feature = "cuda", target_os = "linux")
))]
mod operand;
#[cfg(feature = "simd")]
#[allow(unsafe_code)]
mod simd;
pub use backend::{Backend, BackendUnavailable};
use crate::{GemmTask, MapOperation};
pub(crate) fn gemm_f32(task: &GemmTask<'_, f32>) -> Option<Vec<f32>> {
#[cfg(all(feature = "accelerate", target_os = "macos"))]
if let Some(product) = accelerate::gemm_f32(task) {
return Some(product);
}
#[cfg(all(feature = "metal", target_os = "macos"))]
if let Some(product) = metal::gemm_f32(task) {
return Some(product);
}
#[cfg(all(feature = "cuda", target_os = "linux"))]
if let Some(product) = cuda::gemm_f32(task) {
return Some(product);
}
#[cfg(feature = "simd")]
if let Some(product) = simd::gemm_f32(task) {
return Some(product);
}
let _ = task;
None
}
pub(crate) fn gemm_f64(task: &GemmTask<'_, f64>) -> Option<Vec<f64>> {
#[cfg(all(feature = "accelerate", target_os = "macos"))]
if let Some(product) = accelerate::gemm_f64(task) {
return Some(product);
}
#[cfg(all(feature = "cuda", target_os = "linux"))]
if let Some(product) = cuda::gemm_f64(task) {
return Some(product);
}
#[cfg(feature = "simd")]
if let Some(product) = simd::gemm_f64(task) {
return Some(product);
}
let _ = task;
None
}
pub(crate) fn map_f32(operation: MapOperation, elements: &[f32]) -> Option<Vec<f32>> {
#[cfg(all(feature = "metal", target_os = "macos"))]
if let Some(mapped) = metal::map_f32(operation, elements) {
return Some(mapped);
}
#[cfg(all(feature = "accelerate", target_os = "macos"))]
if let Some(mapped) = accelerate::map_f32(operation, elements) {
return Some(mapped);
}
let _ = (operation, elements);
None
}
pub(crate) fn map_f64(operation: MapOperation, elements: &[f64]) -> Option<Vec<f64>> {
#[cfg(all(feature = "accelerate", target_os = "macos"))]
if let Some(mapped) = accelerate::map_f64(operation, elements) {
return Some(mapped);
}
let _ = (operation, elements);
None
}