Skip to content

Native CPU

Mike Wright edited this page Aug 1, 2026 · 1 revision

Native CPU

Native CPU is the baseline complete execution path. It is the right choice for scripting, file-backed data, traces, reproducible experiments, broad model compatibility, and workloads too long for the browser but too small or unsupported for an accelerator fast path.

Run the REPL or a script

cd sw-mlpl/components/cli
cargo run -p mlpl-repl
cargo run -p mlpl-repl -- -f ../../demos/tiny_mlp.mlpl

Use release builds for meaningful timing:

cargo run --release -p mlpl-repl -- -f ../../demos/tiny_lm.mlpl

CPU execution flow

flowchart LR
    Source[MLPL source] --> Lexer[Lexer and parser]
    Lexer --> AST[AST]
    AST --> Eval[Evaluator and environment]
    Eval --> Arrays[Dense CPU arrays]
    Eval --> Tape[Autograd tape]
    Arrays --> Result[Value or visualization]
    Tape --> Optim[Optimizer update]
    Optim --> Eval
    Result --> REPL[Terminal, file, or server response]
Loading

Native-only advantages

  • Read data underneath an explicit --data-dir sandbox.
  • Persist experiment records under --exp-dir.
  • Export structured execution traces.
  • Store visualization artifacts in MLPL_CACHE_DIR rather than printing raw markup.
  • Call allowed HTTP services such as an Ollama-compatible endpoint.
  • Run a long-lived server, multiple clients, and persistent sessions.
  • Build the Rust embedding and native compilation paths.

Why CPU remains important

The CPU evaluator supports the broadest set of language semantics and arbitrary tape-based training. Small tensor sizes often favor CPU because GPU transfer and launch costs dominate. CPU is also the correctness reference for fp32 accelerator parity tests.

Compilation path

The interactive evaluator maximizes language coverage. The mlpl! procedural macro and mlpl build command lower a supported subset to Rust/native code. Use this when startup and deployment simplicity matter, and use interpreter-versus-compiled parity tests for the features in scope.

Read compiler guide, compilation design, and benchmarks in the source repository.

Clone this wiki locally