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
//! CUDA API database enumeration example: print every API decuda knows about,
//! grouped by whether each backend has an automatic mapping.
//!
//! Run with: `cargo run --example list_apis`
//! Restrict to one backend with: `cargo run --example list_apis -- hip`

use decuda::cli::Target;
use decuda::cuda_db;

fn main() {
    let target = std::env::args_os()
        .nth(1)
        .map(|s| s.to_string_lossy().into_owned())
        .filter(|s| !s.is_empty());

    let db = cuda_db::database();
    let want = target.as_deref();

    println!("decuda knows {} CUDA API entries.\n", db.len());

    for (name, info) in db {
        let line = match want {
            Some("hip") => format!("{name:<32} hip={}", fmt_opt(info.hip)),
            Some("sycl") => format!("{name:<32} sycl={}", fmt_opt(info.sycl)),
            Some("rust") => format!("{name:<32} rust={}", fmt_opt(info.rust)),
            Some("opencl") => format!("{name:<32} opencl={}", fmt_opt(info.opencl)),
            _ => format!(
                "{name:<32} hip={} sycl={} rust={} opencl={}",
                fmt_opt(info.hip),
                fmt_opt(info.sycl),
                fmt_opt(info.rust),
                fmt_opt(info.opencl),
            ),
        };
        println!("{line}");
    }

    // Demonstrate the supports() predicate for a chosen target.
    let t = match want {
        Some("hip") => Some(Target::Hip),
        Some("sycl") => Some(Target::Sycl),
        Some("rust") => Some(Target::Rust),
        Some("opencl") => Some(Target::Opencl),
        _ => None,
    };
    if let Some(t) = t {
        let supported = db.values().filter(|info| info.supports(t)).count();
        println!("\n{supported} entries have an automatic mapping for {t:?}.");
    }
}

fn fmt_opt(o: Option<&str>) -> String {
    match o {
        Some(s) => s.to_string(),
        None => "(none)".to_string(),
    }
}