Skip to content

Commit 1d02ac3

Browse files
authored
[Docs] Add Relax VM architecture documentation (#19389)
- Add a dedicated architecture document (`docs/arch/relax_vm.rst`) for the Relax Virtual Machine, covering the compilation pipeline (Relax IR → VMCodeGen → VMExecutable), the 4-opcode instruction set and encoding format, the register-based execution model (VMFrame, RunLoop, VMClosure dispatch), built-in operations, serialization, and the Python-level interface (direct invocation, stateful API, profiling, instrumentation). - Refactor the inline VM section in `docs/arch/index.rst` into a brief summary with a cross-reference to the new page, and add `relax_vm` to the toctree.
1 parent 481aa6e commit 1d02ac3

2 files changed

Lines changed: 453 additions & 17 deletions

File tree

docs/arch/index.rst

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -243,23 +243,18 @@ Relax Virtual Machine
243243

244244
Relax defines *what* to compute — it is a graph-level IR that describes the operators and dataflow
245245
of a model. The Relax Virtual Machine (VM) handles *how* to run it — it is the runtime component
246-
that executes the compiled result. During compilation, ``tvm.compile()`` invokes ``VMCodeGen`` to
247-
translate Relax functions into a compact bytecode representation. The resulting ``VMExecutable``
248-
bundles the bytecode together with a constant pool and per-function metadata, and can be serialized
249-
to disk for deployment.
250-
251-
The VM uses a register-based interpreter with an intentionally minimal instruction set — only four
252-
opcodes: ``Call``, ``Ret``, ``Goto``, and ``If``. The VM itself performs no mathematical computation;
253-
it only orchestrates control flow (function calls, conditional branches, loops). The actual
254-
compute-intensive work — matrix multiplications, convolutions, and other operators — is carried out
255-
by TIR functions that have been compiled down to native GPU/CPU kernels, or by external libraries
256-
such as cuBLAS and cuDNN. The VM dispatches to them through the PackedFunc mechanism. Internally the
257-
VM recognizes three function kinds: *PackedFunc* for external C/C++ functions, *VMFunc* for
258-
bytecode-interpreted Relax functions, and *VMTIRFunc* for compiled TIR kernels.
259-
260-
On the Python side, users interact with the VM through ``relax.VirtualMachine(executable, device)``,
261-
which provides both a direct invocation interface and a stateful set-input / invoke / get-output
262-
interface suitable for RPC-based remote execution.
246+
that executes the compiled result. The VM uses a register-based interpreter with only four opcodes
247+
(``Call``, ``Ret``, ``Goto``, ``If``) and performs no mathematical computation itself — it
248+
orchestrates control flow while dispatching actual work to compiled TIR kernels or external
249+
libraries.
250+
251+
See :ref:`relax-vm-arch` for the full architecture documentation, including the compilation
252+
pipeline, instruction set details, execution model, and Python interface.
253+
254+
.. toctree::
255+
:maxdepth: 1
256+
257+
relax_vm
263258

264259
Disco: Distributed Runtime
265260
^^^^^^^^^^^^^^^^^^^^^^^^^^

0 commit comments

Comments
 (0)