Skip to main content

Crate ruxla_stablehlo

Crate ruxla_stablehlo 

Source
Expand description

Lowering of the ruxla IR to StableHLO.

lower turns a Function into a StableHLO module in the MLIR text format, with the function as the public @main. Each primitive emits its own operations through LowerCx; this crate provides the context, assigns SSA names, emits constants, and places nested functions (such as the bodies of jit) in the same module.

The text is consumed in two places: the PJRT runtime compiles it with XLA, and the Python package embeds it in the modules JAX compiles. The link module merges modules exported from JAX into ruxla’s modules.

§Examples

use ruxla_ir::{AVal, Atom, DType, Eqn, Function, Params, Var};

let x = Var::new(AVal::new([2], DType::F32));
let y = Var::new(AVal::new([2], DType::F32));
let eqn = Eqn {
    prim: ruxla_prims::MUL,
    inputs: vec![Atom::Var(x.clone()), Atom::Var(x.clone())],
    params: Params::None,
    outputs: vec![y.clone()],
    loc: None,
};
let f = Function { invars: vec![x], eqns: vec![eqn], outvars: vec![y.into()], ..Function::default() };
let module = ruxla_stablehlo::lower(&f, ruxla_ir::lowering::Target::Pjrt).unwrap();
assert!(module.contains("func.func public @main(%arg0: tensor<2xf32>) -> (tensor<2xf32>)"));
assert!(module.contains("\"stablehlo.multiply\"(%arg0, %arg0)"));

Modules§

link
Linking StableHLO modules at the text level.

Structs§

LowerOptions
How lower_with lowers a function.

Functions§

lower
Lowers a function to a StableHLO module whose public @main is the function, for the given target.
lower_with
lower with options (the platform and donated inputs).