Skip to main content

Backend

Trait Backend 

Source
pub trait Backend: Send + Sync {
    // Required method
    fn compile(
        &self,
        graph: Graph,
        options: &CompileOptions,
    ) -> Box<dyn ExecutableGraph>;

    // Provided methods
    fn compile_lir(
        &self,
        lir: LirModule,
        options: &CompileOptions,
    ) -> Box<dyn ExecutableGraph> { ... }
    fn compile_hir(
        &self,
        hir: HirModule,
        device: Device,
        options: &CompileOptions,
    ) -> Result<Box<dyn ExecutableGraph>, LowerError> { ... }
    fn compile_module(
        &self,
        module: GraphModule,
        device: Device,
        options: &CompileOptions,
    ) -> Result<Box<dyn ExecutableGraph>, LowerError> { ... }
    fn supported_ops(&self) -> &'static [OpKind] { ... }
}
Expand description

Backend implementation trait.

Single compile entry point. New compile-time knobs are added to CompileOptions, not as new trait methods.

Send + Sync because backends are stateless factories — multiple threads can call compile concurrently. The returned Box<dyn ExecutableGraph> is Send (moveable to a worker thread) but not Sync (run/run_slots take &mut self).

Required Methods§

Source

fn compile( &self, graph: Graph, options: &CompileOptions, ) -> Box<dyn ExecutableGraph>

Compile a graph for this backend with the given options.

Provided Methods§

Source

fn compile_lir( &self, lir: LirModule, options: &CompileOptions, ) -> Box<dyn ExecutableGraph>

Compile pre-optimized LIR (HIR → MIR → LIR pipeline output). Default re-enters Self::compile — backends should override when they can reuse the embedded buffer plan.

Source

fn compile_hir( &self, hir: HirModule, device: Device, options: &CompileOptions, ) -> Result<Box<dyn ExecutableGraph>, LowerError>

HIR-first compile: lower blocks, run fusion pipeline, emit executable.

Source

fn compile_module( &self, module: GraphModule, device: Device, options: &CompileOptions, ) -> Result<Box<dyn ExecutableGraph>, LowerError>

[GraphModule] compile — unified HIR/MIR/LIR entry.

Source

fn supported_ops(&self) -> &'static [OpKind]

PLAN L4: declare which OpKinds this backend can lower. Default: empty slice = “no claim made — accept everything” (preserves existing behavior; backends opt in by overriding). When non-empty, the LegalizeForBackend pass will refuse to compile a graph that contains an op outside this set, instead of silently falling through to slower / wrong dispatch.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§