TECHNOLOGY

IREE VM modules and contexts: sharing code does not mean sharing mutable module state

In this article
THE QUICK TAKE

An IREE module can be reused as code while separate contexts hold their own mutable module state; external resource sharing still needs explicit analysis.

Two callers need the same code but different program state

An application wants several independent instances of a compiled program. Copying the module bytes for every caller may be unnecessary, while sharing a single mutable execution state may be incorrect. Distinguish the code object from the context that instantiates it. This is a runtime ownership decision rather than a question of whether a model file can be loaded twice. Identify which state must remain independent and which expensive read-only resources may legitimately be shared.

Modules and contexts have different responsibilities

The invocation execution model describes read-only modules reused across contexts and contexts carrying mutable module state. A context links and instantiates its modules. Reusing a module object therefore does not automatically imply that every context observes the same mutable globals. Conversely, context-local module state does not establish complete physical isolation of all resources reachable through external native code or shared device objects. Keep those claims separate.

VM instances provide a broader hosting boundary

The virtual machine design explains the VM and its modules, including runtime subsystems. A compiled user program is not the only module involved: device access and parameter access can be supplied through other modules. Record which modules participate in each context and which resources they reference. The hybrid architecture guide provides background on host and device responsibilities, but does not determine how this application should partition mutable state.

High-level sessions arrange the runtime objects

The C API guide describes instances, sessions, contexts and modules in the embedding workflow. Follow ownership and release rules of the API actually used instead of translating product-level terminology into assumed object lifetimes. A session may organize calls and state without becoming an application-wide isolation policy. Validate separate stateful invocations and resource cleanup under the intended hosting arrangement, including any native modules that hold resources outside the compiled program’s ordinary globals.

Review sharing by resource category

Create an inventory covering module code, context state, device allocations, parameters and application-native resources. State who creates, retains and releases each category. The allocation lifetime guide helps explain why shared references need explicit lifetime relationships. Test that changes intended to remain local do not leak through an accidentally shared external object. This yields a concrete reuse design, rather than either duplicating everything indiscriminately or assuming that a shared compiled module forces all callers into one mutable state space.

Earn rental income from GPUs

Have idle GPUs or looking to fund AI infrastructure? Retrivium finds a rental platform, sets up the server and helps you assess income and costs with a pilot.

Explore GPU hosting
← All articles