Skip to main content

wave_runtime/
backend.rs

1// Copyright 2026 Ojima Abraham
2// SPDX-License-Identifier: Apache-2.0
3
4//! Backend translation wrapper for the WAVE runtime.
5//!
6//! Translates compiled WAVE binary (.wbin) data into vendor-specific GPU
7//! source code using the appropriate backend crate (Metal, PTX, HIP, or SYCL).
8
9use crate::device::GpuVendor;
10use crate::error::RuntimeError;
11
12/// Translate a WAVE binary to vendor-specific source code.
13///
14/// # Errors
15///
16/// Returns `RuntimeError::Backend` if the translation fails or the vendor
17/// is the emulator (which does not need translation).
18pub fn translate_to_vendor(wbin: &[u8], vendor: GpuVendor) -> Result<String, RuntimeError> {
19    match vendor {
20        GpuVendor::Apple => {
21            wave_metal::compile(wbin).map_err(|e| RuntimeError::Backend(e.to_string()))
22        }
23        GpuVendor::Nvidia => {
24            wave_ptx::compile(wbin, 75).map_err(|e| RuntimeError::Backend(e.to_string()))
25        }
26        GpuVendor::Amd => wave_hip::compile(wbin).map_err(|e| RuntimeError::Backend(e.to_string())),
27        GpuVendor::Intel => {
28            wave_sycl::compile(wbin).map_err(|e| RuntimeError::Backend(e.to_string()))
29        }
30        GpuVendor::Emulator => Err(RuntimeError::Backend(
31            "emulator does not require backend translation".into(),
32        )),
33    }
34}