How tqchen/tvm works
Apache TVM is a Python-first machine-learning compiler that transforms models into deployable modules. Its principal workflow represents a model at graph level in Relax, lowers and optimizes tensor programs through TIRx/S-TIR pipelines, then compiles for a target and runs on TVM’s runtime. The README also identifies cross-level optimization, customizable transformations, scheduling, and deployment as central capabilities. Pipeline excerpts establish several internal handoffs; links to unsampled compiler and runtime stages are shown as unverified rather than asserted as inspected.
Main entry points: pipeline.py S-TIR Pipeline · base.h TVM Runtime · compilation_pipeline.py TIRx Pipeline · module.py IR Module
Components 18
Model and IR
- Relax Graph IR
python/tvm/relax/expr.py - IR Module
python/tvm/ir/module.py - TIRx Programs
python/tvm/tirx/op.py
Lowering and Optimization
- Relax Pipeline
python/tvm/relax/pipeline.py - TIRx Pipeline
python/tvm/tirx/compilation_pipeline.py - S-TIR Pipeline
python/tvm/s_tir/pipeline.py - Storage Rewrite
src/tirx/transform/storage_rewrite.cc - Software Pipelining
src/s_tir/transform/inject_software_pipeline.cc
Targets and Scheduling
- Backend Pipelines
python/tvm/relax/backend/__init__.py - CUDA Tile Backend
python/tvm/backend/cuda/lang/pipeline.py - Trainium Backend
python/tvm/backend/trn/pipeline.py - Meta-Schedule
include/tvm/s_tir/meta_schedule/database.h - Compile Driver
python/tvm/driver/build_module.py - Target Code Generation
include/tvm/target/codegen.h
Deployment and Runtime
- TVM Runtime
include/tvm/runtime/base.h - Runtime Memory
src/runtime/memory/memory_manager.cc - RPC Deployment
jvm/core/src/main/java/org/apache/tvm/rpc/ServerProcessor.java
Other components
- Model Author
Connections 15
- Model Author → Relax Graph IR: defines model
README.md - Relax Graph IR → IR Module: represented in
README.md - Relax Pipeline → Backend Pipelines: dispatches operators
python/tvm/relax/pipeline.py - Relax Pipeline → IR Module: transforms module
python/tvm/relax/pipeline.py - TIRx Pipeline → IR Module: transforms module
python/tvm/tirx/compilation_pipeline.py - S-TIR Pipeline → TIRx Pipeline: uses compilation pipeline
python/tvm/s_tir/pipeline.py - S-TIR Pipeline → Storage Rewrite: adds storage rewrite
- S-TIR Pipeline → Software Pipelining: adds pipeline injection
- Backend Pipelines → CUDA Tile Backend: registers backend
- Trainium Backend → TIRx Pipeline: uses TIRx passes
python/tvm/backend/trn/pipeline.py - Meta-Schedule → S-TIR Pipeline: tunes schedules
README.md - Compile Driver → Target Code Generation: compiles for target
README.md - Target Code Generation → TVM Runtime: produces deployable module
README.md - TVM Runtime → Runtime Memory: manages allocations
- TVM Runtime → RPC Deployment: supports remote execution