pub trait ComputeTarget {
// Required methods
fn source_extension(&self) -> &str;
fn output_extension(&self) -> &str;
fn output_is_text(&self) -> bool;
fn find_compiler(&self) -> Option<PathBuf>;
fn compile(
&self,
source: &Path,
output: &Path,
arch: &str,
extra_flags: &[String],
) -> Result<(), String>;
fn vendor(&self) -> Vendor;
}Expand description
Build-time compilation target contract.
Each hardware vendor implements this trait to describe how kernel source
files are compiled into loadable binary modules. The build script
(atlas-kernels/build.rs) uses this trait to compile kernels without
knowing the specific compiler or binary format.
§Lifecycle
[build.rs] [runtime]
.cu / .metal / .cl GpuBackend::new(modules)
│ │
▼ ▼
ComputeTarget::compile() GpuBackend::kernel(name, fn)
│ │
▼ ▼
.ptx / .metallib / .spv GpuBackend::launch(handle, ...)
│
▼
include_str!() / include_bytes!()
│
▼
Embedded in binary as &str / &[u8]Required Methods§
Sourcefn source_extension(&self) -> &str
fn source_extension(&self) -> &str
File extension for kernel source files (without dot).
Examples: "cu" (NVIDIA), "metal" (Apple), "cl" (OpenCL).
Sourcefn output_extension(&self) -> &str
fn output_extension(&self) -> &str
File extension for compiled kernel modules (without dot).
Examples: "ptx" (NVIDIA), "metallib" (Apple), "spv" (SPIR-V).
Sourcefn output_is_text(&self) -> bool
fn output_is_text(&self) -> bool
Whether compiled output is text (can use include_str!) or binary
(must use include_bytes!).
PTX is text; SPIR-V and metallib are binary.
Sourcefn find_compiler(&self) -> Option<PathBuf>
fn find_compiler(&self) -> Option<PathBuf>
Find the compiler executable path.
Returns None if the compiler is not installed.
Sourcefn compile(
&self,
source: &Path,
output: &Path,
arch: &str,
extra_flags: &[String],
) -> Result<(), String>
fn compile( &self, source: &Path, output: &Path, arch: &str, extra_flags: &[String], ) -> Result<(), String>
Compile a single kernel source file to the target binary format.
source: path to the kernel source file (e.g.,rms_norm.cu)output: path to write the compiled output (e.g.,rms_norm.ptx)arch: target architecture string from HARDWARE.toml (e.g.,"sm_121f")extra_flags: additional compiler flags from KERNEL.toml
Returns Ok(()) on success, Err with compiler output on failure.