How apache/tvm works
Apache TVM is a Python-first machine-learning compiler and deployment framework. Its principal workflow imports or constructs a model, represents and transforms it in Relax, lowers computation through tensor-level IR and target-specific code generation, then compiles it for deployment through TVM’s runtime. The repository also includes scheduling and tuning, accelerator backends, and RPC/distributed runtime capabilities. The graph emphasizes these product stages; several subsystem links are documented or inferred from the project’s stated design because their implementation files were not sampled.
Main entry points: base.h TVM Runtime · expr.py Relax Graph IR · relax/pipeline.py Relax Pipeline · s_tir/pipeline.py Tensor Scheduling
Components 21
Model and IR
- Model Frontends
python/tvm/relax/frontend - Relax Graph IR
python/tvm/relax/expr.py - Core IR
python/tvm/ir/module.py - Tensor IR
python/tvm/tirx/expr.py
Compilation
- Relax Transforms
python/tvm/relax/transform - Relax Pipeline
python/tvm/relax/pipeline.py - Tensor Lowering
python/tvm/tirx/compilation_pipeline.py - Tensor Scheduling
python/tvm/s_tir/pipeline.py - Storage Planning
src/tirx/transform/storage_rewrite.cc - Meta-Schedule
include/tvm/s_tir/meta_schedule/database.h
Target Backends
- Target Codegen
include/tvm/target/codegen.h - CUDA Operations
python/tvm/backend/cuda/op.py - PTX Instruction Engine
python/tvm/backend/cuda/ptx/engine.py - PTX Instruction Table
python/tvm/backend/cuda/ptx/table.py
Runtime and Deployment
- Runtime Memory
src/runtime/memory/memory_manager.cc - TVM Runtime
include/tvm/runtime/base.h - RPC Services
jvm/core/src/main/java/org/apache/tvm/rpc/Server.java - Distributed Runtime
src/runtime/extra/disco/disco_worker.cc - Hexagon Runtime
src/backend/hexagon/runtime/hexagon_thread_manager.h
Other components
- Model Developer
- Deployable Module
Connections 21
- Model Developer → Model Frontends: imports model
README.md - Model Developer → Relax Graph IR: constructs graph
README.md - Model Frontends → Relax Graph IR: translates to
README.md - Relax Graph IR → Core IR: uses IR
- Relax Pipeline → Relax Transforms: applies passes
python/tvm/relax/pipeline.py - Relax Pipeline → Relax Graph IR: transforms module
python/tvm/relax/pipeline.py - Relax Pipeline → Tensor IR: lowers computation
README.md - Tensor Lowering → Tensor IR: lowers IR
python/tvm/tirx/compilation_pipeline.py - Tensor Scheduling → Tensor Lowering: uses pipeline
python/tvm/s_tir/pipeline.py - Tensor Scheduling → Storage Planning: runs rewrite
python/tvm/s_tir/pipeline.py - Tensor Scheduling → Meta-Schedule: tunes schedules
README.md - Tensor Lowering → Target Codegen: prepares codegen
python/tvm/tirx/compilation_pipeline.py - CUDA Operations → PTX Instruction Engine: builds instructions
python/tvm/backend/cuda/ptx/engine.py - PTX Instruction Engine → PTX Instruction Table: queries instruction table
python/tvm/backend/cuda/ptx/engine.py - Target Codegen → Deployable Module: emits module
README.md - TVM Runtime → Runtime Memory: manages allocations
- Deployable Module → TVM Runtime: runs on
README.md - Model Developer → RPC Services: deploys remotely
README.md - RPC Services → TVM Runtime: serves execution
- Model Developer → Distributed Runtime: runs distributed
README.md - TVM Runtime → Hexagon Runtime: supports target