Repository navigation
Description
Request description
Body
Sorry this took so long to get written up @AGindinson @egebeysel — I started digging into this over a month and a half ago and it kept falling off my plate. Finally got it into a state worth posting.
Problem
I've been comparing the IREE bare-metal path to the TVM AOT executor. In TVM's AOT mode the compiler statically plans all intermediate tensor memory into a single workspace, reports the size at compile time (workspace_size_bytes), and the generated run_model(args, workspace) just writes into memory the caller handed it. On firmware that means a uint8_t workspace[N] in .bss or a stack buffer — no allocator involved at all.
IREE doesn't have that. On the bare-metal/local-sync path, every intermediate buffer is heap-allocated at runtime, right in the middle of an invocation.
The chain looks like this:
- There is a long function calling chain from the stream dialect down to iree/hall, which calls
iree_allocator_malloc_aligned. Andiree_hal_heap_allocator_deallocate_bufferstill literally says// We don't do any pooling yet.
The two bare-metal samples wire up exactly this allocator: samples/baremetal_riscv64/runner.c calls iree_hal_allocator_create_heap("bare-metal", ...), and samples/simple_embedding/device_embedded_sync.c does the same. Even the slab pool path in the sync device ultimately mallocs its slab from the host allocator (cpu_slab_provider.c).
IREE does do memory planning, at the compiler level. EmplaceTransients packs allocas into a shared resource (stream.resource.pack) and --iree-stream-partitioning-favor=min-peak-memory is on by default. But that only cuts down the count of runtime allocations; the packed backing resource is still resolved through the HAL allocator at run time, so it still hits malloc.
Why it matters
On a small MCU with no heap or a tiny heap, that's a problem:
- peak memory becomes nondeterministic (depends on the allocator and fragmentation),
- every invocation does malloc/free,
- and there's no way to pre-reserve the needed bytes at build time, so the firmware engineer can't budget the model.
It's exactly the case the TVM AOT --interface-api=c design was built to avoid — the RFC calls out that the whole point is to "offload all memory management tasks to the calling code."
Is there anything close?
There's an experimental transients externalization path, but it's not usable for the general bare-metal flow today:
EmplaceTransientsmarks packing withstream.experimental.transients;MaterializeTransientSizeQueriesthen emits a<func>_transients_sizefunction and aniree.abi.transients.sizereflection entry — IREE's version of a workspace-size query.- It's only wired up through the Torch frontend (
--iree-torch-externalize-transients, which requires the coarse-fences/async ABI) and passes the transient buffer in as a!hal.bufferprogram input.
Neither the plain llvm-cpu nor the static-library bare-metal flow makes use of it.
Would like
A way to compile a bare-metal/static-library target to a fixed workspace ABI — either:
- expose the total transient size at compile time so the caller can hand IREE a pointer, or
- generate an entry point that takes a workspace argument (like
tvmgen_*_run_model(io..., workspace)).
If that's deliberately out of scope for now, a doc note explaining that the bare-metal path still needs a heap (and roughly how much) would at least be useful for people picking a target.
What component(s) does this issue relate to?
runtime
hal/cpu
Activity
github-actions commentedon Nov 18, 2026
Hello @jokap11 👋
Thank you for submitting an issue to IREE! It looks like it's your first one.
The volume of issues is huge, and triage times may vary. If you need quicker assistance on the issue, consider posting it on IREE Discord and providing short context there.
Feel free to identify the most frequent contributors to the corresponding part of the codebase via Git history/CODEOWNERS and (gently!) tag them below.
Action required: acknowledge IREE project policies
IREE is a Linux Foundation project. All participants are expected to follow the LF Projects Code of Conduct.
Please note that all contributions to IREE, including GitHub issues, must follow our IREE AI Tool Use Policy. This means:
For bug reports, specifics of the use-case, workflow and/or crash scenario usually suffice.
For improvement suggestions, this usually implies deeper understanding of suboptimal code, IR design choices, assumed performance tradeoffs, etc.
Before the issue can be triaged, we kindly ask you to reply to this message and confirm that you understand and accept the proposed policy. As required, please adjust your initial issue description.
If you have any questions, feel free to leave a comment here, or ask away on IREE Discord.
Thank you,
The IREE Community
jokap11 commentedon Nov 18, 2026
I understand the policy and accept it
maxbartel commentedon Nov 20, 2026
Hi!
I have a clarifying question: It seems like IREE has a very experimental path to do this, right? Shouldn't this ticket then be about extending and fixing that one?
From my point of view this is very much a path we would like to support, we just didn't get around to do it yet. It is also a bit more complicated, because it would need to support heterogenous execution. Also just loading the vmfb might be expensive, because the initializer is executed, too. So this would need a bit of design work, but all of this is doable.
In the meantime we should still update the docs saying that heap is required atm, but a better solution is WIP.
Are you interested on working on this or is this more of a request ticket?
jokap11 commentedon Nov 20, 2026
Hi!
Thanks @maxbartel — and yeah, I think you're right that this should just be about extending that experimental path. The deeper I dug, the more it looked like
--iree-torch-externalize-transientsisn't even Torch-specific: EmplaceTransients, the size-query, and the constant-size passes all live in the generic Stream pipeline (Passes.cpp (https://github.com/iree-org/iree/blob/main/compiler/src/iree/compiler/Dialect/Stream/Transforms/Passes.cpp#L337-L376)). What's Torch-only is the automation — the flag that appends the transient !hal.buffer input, and the fact that it's tied to the coarse-fences/async ABI (FuncConversion.cpp (https://github.com/iree-org/iree/blob/main/compiler/plugins/input/Torch/InputConversion/FuncConversion.cpp#L692-L698), which is basically what's in the way of a clean sync run_model(args, workspace) path.The bigger gaps I see are really: heterogeneous execution (that's a real design problem, as you said), getting the buffer insertion off the fences so a sync/bare-metal path can use it, and the fact that even today the sample still allocates
onetransient buffer from the HAL allocator (like a giant Arena) and only exposes the size as a runtime query (main.c (https://github.com/iree-org/iree/blob/main/samples/external_transients/main.c#L200-L208)) — there's no compile-time workspace_size_bytes for the static-library target yet. Also the support of only 1 function call might be also an implementation.How I understand vmfb, this would require an interpreter to load and that is something you can not really afford on a bare-metal device? TVM just uses plain C functions here
Agreed on the docs in the meantime.
Honestly, I'm not deep in the IREE codebase right now, and this would end up being a "vibe.coded" contribution from me. For something that needs actual design work (heterogeneous execution, the vmfb-load/initializer cost you mentioned), I don't think I can write a patch I'd trust maintainers to keep,. So I'd call this a request/discussion ticket for now.
I was just opening the discussion in an IREE meeting if you plan something similar to TVM AOT in this regard for IREE.
That said, I'm happy to help with the parts that don't need too much compiler surgery.
maxbartel commentedon Nov 26, 2026
Makes a lot of sense. We will look into this, but I cannot promise a timeline unfortunately.