1 unstable release

Uses new Rust 2024

0.1.0-alpha.3 May 20, 2026

#445 in Programming languages


Used in 4 crates (2 directly)

MIT license

3.5MB
55K SLoC

Code generation for svod tensor operations.

This crate provides backend-agnostic code generation infrastructure for converting optimized UOp graphs into executable code.

Architecture

  • Traits: Backend-agnostic interfaces (Renderer)
  • LLVM: LLVM IR code generation for CPU execution
  • Future: CUDA, Metal, OpenCL renderers

Usage

use svod_codegen::{llvm, program_pipeline};

let linear = svod_ir::UOp::linear(svod_schedule::linearize_with_cfg(optimized_uop_graph).into());
let kernel = llvm::text::render(&linear, Some("kernel"))?;
// Canonical staged flow: PROGRAM -> LINEAR -> SOURCE -> BINARY.
// See `program_pipeline` for the strict staged entrypoints.

Pre-render invariants

Direct callers of Renderer::render (and the per-backend render free functions) must pass a LINEAR-stage UOp produced by svod_schedule::linearize::line_rewrite_cleanups. The cleanup pass lowers gated LOADs into IF/STORE/ENDIF and provides the alt value that per-backend op handlers rely on; backends report Error::InvalidGraph if these invariants are violated. The staged entrypoints in program_pipeline run the cleanup pass automatically.


svod-codegen

Backend code generation from optimized UOp graphs.

Example

use svod_codegen::{Renderer, render};

let code = render(&kernel_graph, backend)?;

Backends

Backend Output Feature Default
Clang C source → clang -c → JIT ELF loader always yes
LLVM JIT LLVM IR text → clang -x ir → JIT ELF loader always no
MLIR MLIR (arith/scf/llvm dialects) → MLIR ExecutionEngine mlir no

Select at runtime via SVOD_CPU_BACKEND env var (clang, llvm, mlir).

Planned:

  • PTX renderer (CUDA)
  • Metal renderer
  • WebGPU (WGSL) renderer

Testing

cargo test -p svod-codegen

Dependencies

~15–23MB
~345K SLoC