Skip to main content

Program

Trait Program 

Source
pub trait Program {
    // 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.

Note: This trait does not require Send + Sync because some backends (like LLVM JIT) use non-thread-safe types. Programs are typically executed on the same thread where they were compiled, and caching/sharing is handled at a higher level.

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