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
2026-09-25: How one vendor compiles kernel source files into loadable
modules. NvidiaTarget is the only implementation.
The diagram shows the flow of the kernel build, which uses its own trait of
the same name in crates/kernels/build_target.rs, not this one.
[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
2026-09-25: File extension of kernel source files, without the dot
("cu" for NvidiaTarget).
Sourcefn output_extension(&self) -> &str
fn output_extension(&self) -> &str
2026-09-25: File extension of compiled modules, without the dot
("ptx" for NvidiaTarget).
Sourcefn output_is_text(&self) -> bool
fn output_is_text(&self) -> bool
2026-09-25: Whether the compiled output is text (include_str! can
embed it) or binary (include_bytes! only).
Sourcefn find_compiler(&self) -> Option<PathBuf>
fn find_compiler(&self) -> Option<PathBuf>
2026-09-25: The compiler executable, or None if it 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>
2026-09-25: Compile one kernel source file.
source: the kernel source file;output: where to write the compiled module;arch: the target architecture string (e.g."sm_121f");extra_flags: appended to the compiler arguments.
Returns Err with a message if the compiler cannot be started or
fails; for NvidiaTarget the message carries nvcc’s stderr, and a
path that is not UTF-8 panics.