decuda 0.1.1

CUDA to HIP, SYCL, OpenCL, and Rust GPU migration tool — automatic source-code translator for porting CUDA C++ kernels to AMD ROCm HIP, Intel oneAPI SYCL, Khronos OpenCL, and Rust GPU (cust / rust-gpu)
Documentation
//! Per-target translation backends.
//!
//! Each backend implements [`TargetBackend::emit`], turning a CUDA
//! `TranslationUnit` into the target's source code (HIP C++, SYCL C++,
//! OpenCL C, or Rust). Backends are registered in [`for_target`] and
//! orchestrated by the `emit` module.

use crate::cli::Target;
use crate::ir::TranslationUnit;

pub mod hip;
pub mod opencl;
pub mod rust;
pub mod sycl;

/// Backend trait. Implementations are pure functions from source + IR to
/// emitted target source.
pub trait TargetBackend {
    /// The header banner printed at the top of emitted files.
    fn banner(&self, src: &str) -> String;

    /// Translate the unit's source to this target's output.
    fn emit(&self, unit: &TranslationUnit) -> String;
}

/// Dispatch to the right backend by target.
pub fn for_target(target: Target) -> Box<dyn TargetBackend> {
    match target {
        Target::Hip => Box::new(hip::HipBackend),
        Target::Sycl => Box::new(sycl::SyclBackend),
        Target::Rust => Box::new(rust::RustBackend),
        Target::Opencl => Box::new(opencl::OpenClBackend),
        Target::All => Box::new(hip::HipBackend),
    }
}