[Docs] Add Relax VM architecture documentation#19389
[Docs] Add Relax VM architecture documentation#19389MasterJH5574 merged 1 commit intoapache:mainfrom
Conversation
There was a problem hiding this comment.
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.
| 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 |
There was a problem hiding this comment.
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.
| 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 |
| if before_run: | ||
| print(f"About to call: {func_symbol}") | ||
| return VMInstrumentReturnKind.NO_OP | ||
|
|
||
| vm.set_instrument(my_instrument) | ||
| vm["main"](inp) | ||
|
|
There was a problem hiding this comment.
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.
| 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) |
docs/arch/relax_vm.rst) for the Relax VirtualMachine, 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).
docs/arch/index.rstinto a brief summary with across-reference to the new page, and add
relax_vmto the toctree.