elodin-cranelift

Compile and debug StableHLO MLIR simulations through the Cranelift JIT backend.

540|41|Updated Feb 26, 2024
One-click install
npx skills add https://github.com/elodin-sys/elodin --skill elodin-cranelift
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: elodin-cranelift
Source: https://github.com/elodin-sys/elodin/tree/main/.cursor/skills/elodin-cranelift
Command: npx skills add https://github.com/elodin-sys/elodin --skill elodin-cranelift

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Working on Elodin's Cranelift JIT backend requires navigating a dual-ABI compiler pipeline, a StableHLO parser, a tensor runtime, and XLA reference comparisons, and this Skill consolidates the commands, file map, and debugging workflows needed to modify libs/cranelift-mlir/ correctly.

Core Features & Use Cases

  • Op Implementation Guidance: Step-by-step checklist for adding new StableHLO ops across the IR, parser, scalar and pointer-ABI lowering, tensor runtime, and golden tests.
  • Correctness Debugging: Tick checkpoint diagnostic workflow comparing XLA reference outputs against Cranelift outputs element-by-element to isolate diverging simulation values.
  • Regression Testing: Commands for per-op golden tests, full example regression runs with baselines, and large-constant cache verification.
  • Use Case: A simulation example produces wrong attitude values under the Cranelift backend. Use this Skill to capture checkpoint data with ELODIN_CRANELIFT_DEBUG_DIR, run the checkpoint comparator test, identify the diverging output, and reduce it to a minimal tests/ops.rs reproducer before fixing the lowering code.

Quick Start

Ask the assistant to add a new StableHLO op to the Cranelift backend or to debug why a simulation example diverges from the XLA reference using the checkpoint diagnostic tool.

Frequently Asked Questions about elodin-cranelift

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I add a new StableHLO op to the Cranelift backend?

Add an Instruction variant in src/ir.rs, a parser arm in src/parser.rs, lowering arms in both lower_instruction and lower_instruction_mem in src/lower.rs, and a tensor runtime function in src/tensor_rt.rs if the op is N-dimensional. Then add golden tests in tests/ops.rs exercising both ABI paths and run cargo test -p cranelift-mlir.

How do I debug wrong simulation values with the Cranelift backend?

Run the example with ELODIN_BACKEND=cranelift and ELODIN_CRANELIFT_DEBUG_DIR set to capture XLA reference and Cranelift outputs per tick. Then run the checkpoint_test comparator in release mode to compare outputs element-by-element and reduce the diverging output to a minimal tests/ops.rs reproducer.

What is the difference between the cranelift and jax-cpu backends in Elodin?

Cranelift is the default CPU backend that compiles StableHLO MLIR to native code via a JIT, while jax-cpu uses XLA as the reference implementation for correctness. You can switch per-run with the ELODIN_BACKEND environment variable or the backend argument in Python.

Why does a Cranelift simulation segfault in debug mode?

Some JIT paths trip ptr::copy_nonoverlapping debug-mode UB checks, so try running with --release first. Complex sims can also overflow the stack, and NULL pointers in JIT code usually indicate a cross-ABI marshaling bug.

How are large StableHLO constants handled in the Cranelift backend?

Dense hex constants over 1 MB are decoded as raw bytes and interned in a content-addressed cache under ELODIN_CACHE_DIR or ~/.cache/elodin/const-cache. The lowering registers them as imported JIT symbols so constants are not copied into the JIT arena, and CompiledModule must retain the cache handles to avoid dangling mmap pointers.