Skip to main content

Program

Trait Program 

Source
pub trait Program: Send + Sync {
    // Required methods
    unsafe fn execute(
        &self,
        buffers: &[*mut u8],
        vals: &[i64],
        global_size: Option<[usize; 3]>,
        local_size: Option<[usize; 3]>,
    ) -> Result<()>;
    fn name(&self) -> &str;
}
Expand description

A compiled, executable kernel program.

This trait abstracts over different backend executors (LLVM JIT, CUDA, Metal, etc.). Each backend implements this to provide unified execution interface.

Implementations must be stateless and reentrant from the host perspective. The runtime caches and shares programs across execution plans, and may invoke the same program from multiple host threads when dependency analysis proves the buffer accesses are independent.

§Tinygrad Alignment

This trait follows Tinygrad’s Program interface where variable values are passed as a positional tuple/array (vals) rather than a named HashMap. The order matches var_names in CompiledSpec.

Required Methods§

Source

unsafe fn execute( &self, buffers: &[*mut u8], vals: &[i64], global_size: Option<[usize; 3]>, local_size: Option<[usize; 3]>, ) -> Result<()>

Execute the kernel with given buffers and variable values.

§Arguments
  • buffers - Raw pointers to buffer data (input and output buffers)
  • vals - Variable values in positional order (matches var_names in CompiledSpec)
  • global_size - Global work size (for GPU backends, None for CPU)
  • local_size - Local work size (for GPU backends, None for CPU)
§Safety

This is unsafe because:

  • Buffer pointers must be valid and properly aligned
  • Buffer sizes must match what the kernel expects
  • Caller must ensure no data races during execution
Source

fn name(&self) -> &str

Get the kernel name (for debugging/profiling).

Implementors§