pub trait Renderer {
// Required methods
fn render(
&self,
uop: &Arc<UOp>,
name: Option<&str>,
) -> Result<RenderedKernel>;
fn backend_name(&self) -> &str;
fn decompositor(&self) -> Option<TypedPatternMatcher<()>>;
}Expand description
Backend-agnostic code generation interface.
Implementers generate executable code from optimized UOp graphs. Different backends (LLVM, CUDA, Metal, etc.) implement this trait to generate code in their respective formats.
Required Methods§
Sourcefn render(&self, uop: &Arc<UOp>, name: Option<&str>) -> Result<RenderedKernel>
fn render(&self, uop: &Arc<UOp>, name: Option<&str>) -> Result<RenderedKernel>
Render a UOp graph into executable code.
Takes an optimized UOp graph (typically from the scheduler/optimizer) and generates code that can be compiled and executed.
§Arguments
uop- The root UOp of the computation graphname- Optional name for the kernel (used for debugging/caching)
§Returns
A RenderedKernel containing the generated code and metadata.
Sourcefn backend_name(&self) -> &str
fn backend_name(&self) -> &str
Get the backend name (e.g., “llvm”, “cuda”, “metal”).
Sourcefn decompositor(&self) -> Option<TypedPatternMatcher<()>>
fn decompositor(&self) -> Option<TypedPatternMatcher<()>>
Returns decomposition patterns for operations this backend doesn’t support.
Backends that support all transcendental operations natively (e.g., LLVM)
should return None. Backends that need decomposition (e.g., CPU interpreter)
should return a PatternMatcher containing the decomposition rules.
§Example
fn decompositor(&self) -> Option<TypedPatternMatcher<()>> {
// LLVM has native transcendentals
None
}