ComputeTarget

Trait ComputeTarget 

Source
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§

Source

fn source_extension(&self) -> &str

2026-09-25: File extension of kernel source files, without the dot ("cu" for NvidiaTarget).

Source

fn output_extension(&self) -> &str

2026-09-25: File extension of compiled modules, without the dot ("ptx" for NvidiaTarget).

Source

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).

Source

fn find_compiler(&self) -> Option<PathBuf>

2026-09-25: The compiler executable, or None if it is not installed.

Source

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.

Source

fn vendor(&self) -> Vendor

Implementors§