Skip to main content

Renderer

Trait Renderer 

Source
pub trait Renderer: Send + Sync {
    // Required methods
    fn render(&self, ast: &Arc<UOp>, name: Option<&str>) -> Result<ProgramSpec>;
    fn device(&self) -> &DeviceSpec;

    // Provided method
    fn decompositor(&self) -> Option<TypedPatternMatcher<()>> { ... }
}
Expand description

A renderer that transforms UOp graphs into source code.

This trait abstracts over different code generation backends:

  • LLVM IR generator
  • CUDA C generator
  • Metal Shading Language generator
  • WGSL generator

Required Methods§

Source

fn render(&self, ast: &Arc<UOp>, name: Option<&str>) -> Result<ProgramSpec>

Render a UOp graph into source code.

§Arguments
  • ast - The kernel AST (UOp graph rooted at KERNEL op)
  • name - Optional kernel name for debugging (e.g., “r_g16l16R32u4”). Falls back to “kernel” if None.
§Returns

A ProgramSpec containing:

  • Generated source code
  • Entry point name
  • Variable list
  • Work sizes (for GPU backends)
Source

fn device(&self) -> &DeviceSpec

Get the device spec for this renderer.

This is used for cache key construction and device selection.

Provided Methods§

Source

fn decompositor(&self) -> Option<TypedPatternMatcher<()>>

Returns decomposition patterns for operations this backend doesn’t support.

This is used by the realization pass to decompose complex operations into simpler primitives before rendering.

§Default Implementation

Returns None, meaning no decomposition is needed (backend supports all ops). Backends that don’t support certain operations (e.g., transcendentals) should override this to return appropriate patterns.

Implementors§