arXiv:2611.03710cs.PLOct 2026

Manuscript Offprint

arXiv:2611.03710

te-comp: A Complete MLIR Compiler Generating Self-Contained C Inference Engines for MCUs

Van Chan Ngo

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

ABSTRACT

Deploying deep learning on microcontrollers (MCUs) requires fitting both the model weights and runtime activations within tens to hundreds of kilobytes of SRAM and Flash. Existing approaches either use an interpreter with a pre-written kernel library or combine a Python code generator with hand-written C kernels. This incurs dispatch overhead and requires framework dependencies. None produces self-contained, dependency-free C code specialized to a given model.

In this paper, we present te-comp, the first complete MLIR-based compiler that takes a standard model in .tflite or .safetensors format and emits all C source files needed for deployment: the inference engine (kernels, weight arrays, memory layout) and the RTOS integration layer with zero runtime dependencies.

On 10 MCUNet CNN benchmarks, te-comp outperforms MCUNet TinyEngine by using 38% less SRAM (up to 5.9×) and 15% less Flash, while generating complete C code rather than linking a pre-written kernel library. To demonstrate, we use te-comp to compile an 8.3M-parameter GPT-Neo transformer (TinyStories-v2) and deploy it on a single-core Cortex-M7 at 160 MHz. The full firmware uses 249 KB of 512 KB SRAM and 3.62 MB of 4 MB Flash and achieves approximately 1 token/s interactive text generation via Q4.0 weight quantization, a stateful int4 KV cache, and vocabulary pruning—a capability no existing MCU inference framework supports.

1 INTRODUCTION

Microcontrollers (MCUs) power billions of embedded devices, from wearable health monitors and keyword-spotting earbuds to industrial sensors and autonomous vehicles. Running deep learning inference directly on these devices eliminates cloud round-trips, reduces latency to microseconds, and preserves user privacy. However, MCUs operate under extreme resource constraints: typical ARM Cortex-M4/M7 targets offer 128–512 KB of SRAM, 512 KB–4 MB of Flash, and clock speeds of 160–400 MHz with no GPU, no virtual memory, and no dynamic allocation. Existing deployment approaches fall into the following categories, each with fundamental limitations.

Interpreter runtimes (TFLite Micro (David et al., 2021), ExecuTorch (Meta AI, 2024)) load a serialized model and dispatch operations through a generic interpreter loop. This is portable but incurs 20–50 KB of SRAM overhead from dispatch tables, op resolvers, and runtime buffer management. Latency suffers from indirect function calls on every operator. Neither framework supports large language model (LLM) inference on MCUs.

Library-based code generators (MCUNet (Lin et al., 2020; 2021)) use a Python script to generate a model-specific dispatch function that calls into a hand-written C kernel library (33 source files for MCUNet). This achieves near-optimal latency through carefully tuned SMLAD-based kernels, but adding a new operator requires writing new C files, and the generated code depends on the entire kernel library at link time.

General-purpose ML compilers (Apache TVM (Chen et al., 2018), IREE (Google, 2023), Glow (Rotem et al., 2019)) use compiler IRs to optimize models, but none produces deployable bare-metal code for Cortex-M microcontrollers. TVM's Cortex-M support is immature and still requires a runtime. IREE and Glow target GPUs and Cortex-A mobile processors.

None of these approaches produces self-contained, dependency-free C code specialized to a specific input model. We believe that this is the right abstraction for deployment: the output should be plain C code that firmware engineers just drop into any existing project and call with simple APIs without an interpreter, kernel library, or framework dependencies.

We present te-comp, the first complete MLIR-based compiler that achieves this goal. Given a standard model in .tflite for int8 CNNs or .safetensors for trans-

*Equal contribution ¹TeComp AI, CA, US. Correspondence to: Van Chan Ngo vchngo@gmail.com.

formers, it produces:

  • {model}_engine.c/.h: The complete inference engine with all kernels as nested loops, weight arrays in .rodata, and the activation arena in .bss.

  • inference_task.c / inference_api.h: Integration layer (FreeRTOS or bare-metal).

  • CMakeLists.txt: Drop-in CMake library.

Every loop bound, buffer offset, and arithmetic constant is a compile-time literal specialized to the input model (easy to optimize for machine code). The generated code has zero external function calls, not even memcpy. It achieves this through a multi-level MLIR compilation pipeline. A custom te dialect captures 34 quantized NN operations with all metadata and composable optimization passes progressively lower and optimize the IR before emitting C code. Our contributions are:

  1. Self-contained C code. Given any input model, te-comp emits all C artifacts needed for deployment: the inference engine, RTOS glue code, a public API header, and a CMake library target with zero runtime dependencies. No other tool produces this complete output.

  2. LLM inference on Cortex-M7. te-comp compiles an 8.3M-parameter GPT-Neo (TinyStories-v2) to a self-contained C engine using 249 KB SRAM and 3.62 MB Flash (measured on hardware), achieving ~1 token/s interactive generation. No existing MCU framework supports this capability.

  3. Outperforms MCUNet. On all 10 CNN benchmarks, te-comp outperforms for both peak SRAM (avg 0.62×, up to 5.9× less) and Flash (avg 0.86×, up to 32% less).

  4. Numerical accuracy. te-comp matches TFLite on 10 int8 models with 50-70+ layers by generating identical ground-truth label accuracy.