#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum GpuBackend {
Cuda,
Metal,
Wgpu,
Cpu,
}
#[must_use]
pub fn gpu_backend() -> GpuBackend {
#[cfg(feature = "gpu-cuda")]
{
if crate::gpu::cuda_available() {
return GpuBackend::Cuda;
}
}
#[cfg(feature = "gpu-metal")]
{
if crate::metal::metal_available() {
return GpuBackend::Metal;
}
}
#[cfg(feature = "gpu-wgpu")]
{
if crate::wgpu_forward::wgpu_available() {
return GpuBackend::Wgpu;
}
}
GpuBackend::Cpu
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn selects_cpu_without_gpu_features() {
#[cfg(not(any(feature = "gpu-cuda", feature = "gpu-metal", feature = "gpu-wgpu")))]
assert_eq!(gpu_backend(), GpuBackend::Cpu);
}
#[test]
fn backend_variants_are_distinct() {
assert_ne!(GpuBackend::Cuda, GpuBackend::Wgpu);
assert_ne!(GpuBackend::Wgpu, GpuBackend::Cpu);
assert_ne!(GpuBackend::Cuda, GpuBackend::Metal);
assert_ne!(GpuBackend::Metal, GpuBackend::Wgpu);
assert_ne!(GpuBackend::Metal, GpuBackend::Cpu);
}
}