Skip to content

[Docs] Add Relax VM architecture documentation#19389

Merged
MasterJH5574 merged 1 commit intoapache:mainfrom
tlopex:doc203
Apr 12, 2026
Merged

[Docs] Add Relax VM architecture documentation#19389
MasterJH5574 merged 1 commit intoapache:mainfrom
tlopex:doc203

Conversation

@tlopex
Copy link
Copy Markdown
Member

@tlopex tlopex commented Apr 11, 2026

  • 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.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a comprehensive architecture document for the Relax Virtual Machine (VM) and updates the main architecture index to point to this new resource. The new documentation covers the end-to-end compilation flow, instruction set, executable format, and runtime execution model. Feedback provided focuses on improving the accuracy of the binary format description and ensuring code snippets are complete by adding missing imports.

Comment on lines +217 to +219
The binary format includes a magic number (``0xD225DE2F4214151E``), a version string
(currently ``"0.14"``), followed by four sections: globals (the function table), memory scopes,
constant pool, and bytecode. ``AsText()`` and ``AsPython()`` provide human-readable representations
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The documentation mentions four sections in the binary format, but according to include/tvm/runtime/vm/executable.h (lines 183-203), there are five sections: globals, memory scopes, constant pool, bytecode, and packed function names. It would be more accurate to include the packed function names section in this list.

Suggested change
The binary format includes a magic number (``0xD225DE2F4214151E``), a version string
(currently ``"0.14"``), followed by four sections: globals (the function table), memory scopes,
constant pool, and bytecode. ``AsText()`` and ``AsPython()`` provide human-readable representations
The binary format includes a magic number (``0xD225DE2F4214151E``), a version string
(currently ``"0.14"``), followed by five sections: globals (the function table), memory scopes,
constant pool, bytecode, and packed function names. ``AsText()`` and ``AsPython()`` provide

Comment on lines +385 to +391
if before_run:
print(f"About to call: {func_symbol}")
return VMInstrumentReturnKind.NO_OP

vm.set_instrument(my_instrument)
vm["main"](inp)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The instrumentation example uses VMInstrumentReturnKind.NO_OP, but VMInstrumentReturnKind is not imported in the snippet. For completeness and to make the example directly runnable, please add the necessary import from tvm.runtime.vm.

Suggested change
if before_run:
print(f"About to call: {func_symbol}")
return VMInstrumentReturnKind.NO_OP
vm.set_instrument(my_instrument)
vm["main"](inp)
from tvm.runtime.vm import VMInstrumentReturnKind
def my_instrument(func, func_symbol, before_run, ret_value, *args):
if before_run:
print(f"About to call: {func_symbol}")
return VMInstrumentReturnKind.NO_OP
vm.set_instrument(my_instrument)
vm["main"](inp)

@tlopex
Copy link
Copy Markdown
Member Author

tlopex commented Apr 12, 2026

cc @MasterJH5574

@MasterJH5574 MasterJH5574 merged commit 1d02ac3 into apache:main Apr 12, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants