Create the appropriate backend for the given device.
(device: &Device)
| 686 | |
| 687 | /// Create the appropriate backend for the given device. |
| 688 | pub fn create_backend(device: &Device) -> Arc<dyn ComputeBackend> { |
| 689 | match device { |
| 690 | #[cfg(feature = "cuda")] |
| 691 | Device::Cuda(_) => Arc::new(CudaBackend::new(device.clone())), |
| 692 | #[cfg(feature = "metal")] |
| 693 | Device::Metal(_) => Arc::new(MetalBackend::new(device.clone())), |
| 694 | _ => { |
| 695 | // No GPU device — try ROCm first (native AMD), then Vulkan (wgpu) |
| 696 | #[cfg(feature = "rocm")] |
| 697 | match RocmBackend::new() { |
| 698 | Ok(r) => { |
| 699 | log::info!("using ROCm backend (rocBLAS GEMM)"); |
| 700 | return Arc::new(r); |
| 701 | } |
| 702 | Err(e) => log::warn!("ROCm init failed ({e}), trying next backend"), |
| 703 | } |
| 704 | #[cfg(feature = "vulkan")] |
| 705 | match VulkanBackend::new() { |
| 706 | Ok(vk) => { |
| 707 | log::info!("using Vulkan backend for GPU-accelerated ops"); |
| 708 | return Arc::new(vk); |
| 709 | } |
| 710 | Err(e) => log::warn!("Vulkan init failed ({e}), falling back to CPU"), |
| 711 | } |
| 712 | Arc::new(CpuBackend::new()) |
| 713 | } |
| 714 | } |
| 715 | } |