# tqchen/tvm architecture

> Architecture diagram of the GitHub repository tqchen/tvm, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/tqchen/tvm
- Repository: https://github.com/tqchen/tvm

## Overview

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: [`python/tvm/s_tir/pipeline.py`](https://github.com/tqchen/tvm/blob/main/python/tvm/s_tir/pipeline.py) (S-TIR Pipeline), [`include/tvm/runtime/base.h`](https://github.com/tqchen/tvm/blob/main/include/tvm/runtime/base.h) (TVM Runtime), [`python/tvm/tirx/compilation_pipeline.py`](https://github.com/tqchen/tvm/blob/main/python/tvm/tirx/compilation_pipeline.py) (TIRx Pipeline), [`python/tvm/ir/module.py`](https://github.com/tqchen/tvm/blob/main/python/tvm/ir/module.py) (IR Module)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_model["Model and IR"]
  node_relax["Relax Graph IR<br/>[expr.py]"]
  node_ir["IR Module<br/>[module.py]"]
  node_tirx["TIRx Programs<br/>[op.py]"]
end

subgraph group_compile["Lowering and Optimization"]
  node_relaxpipe["Relax Pipeline<br/>[pipeline.py]"]
  node_tirxpipe["TIRx Pipeline"]
  node_stirpipe["S-TIR Pipeline<br/>[pipeline.py]"]
  node_storage["Storage Rewrite<br/>[storage_rewrite.cc]"]
  node_softwarepipe["Software Pipelining"]
end

subgraph group_target["Targets and Scheduling"]
  node_backend["Backend Pipelines<br/>[__init__.py]"]
  node_cuda["CUDA Tile Backend<br/>[pipeline.py]"]
  node_trn["Trainium Backend<br/>[pipeline.py]"]
  node_metaschedule["Meta-Schedule<br/>[database.h]"]
  node_driver["Compile Driver<br/>[build_module.py]"]
  node_codegen["Target Code Generation<br/>[codegen.h]"]
end

subgraph group_runtime["Deployment and Runtime"]
  node_runtime["TVM Runtime<br/>[base.h]"]
  node_memory["Runtime Memory<br/>[memory_manager.cc]"]
  node_rpc["RPC Deployment"]
end

node_engineer(("Model Author"))

node_engineer -.->|"defines model"| node_relax
node_relax -.->|"represented in"| node_ir
node_relaxpipe -->|"dispatches operators"| node_backend
node_relaxpipe -->|"transforms module"| node_ir
node_tirxpipe -->|"transforms module"| node_ir
node_stirpipe -->|"uses compilation pipeline"| node_tirxpipe
node_stirpipe -.->|"adds storage rewrite"| node_storage
node_stirpipe -.->|"adds pipeline injection"| node_softwarepipe
node_backend -.->|"registers backend"| node_cuda
node_trn -->|"uses TIRx passes"| node_tirxpipe
node_metaschedule -.->|"tunes schedules"| node_stirpipe
node_driver -.->|"compiles for target"| node_codegen
node_codegen -.->|"produces deployable module"| node_runtime
node_runtime -.->|"manages allocations"| node_memory
node_runtime -.->|"supports remote execution"| node_rpc

click node_relax "https://github.com/tqchen/tvm/blob/main/python/tvm/relax/expr.py"
click node_ir "https://github.com/tqchen/tvm/blob/main/python/tvm/ir/module.py"
click node_tirx "https://github.com/tqchen/tvm/blob/main/python/tvm/tirx/op.py"
click node_relaxpipe "https://github.com/tqchen/tvm/blob/main/python/tvm/relax/pipeline.py"
click node_tirxpipe "https://github.com/tqchen/tvm/blob/main/python/tvm/tirx/compilation_pipeline.py"
click node_stirpipe "https://github.com/tqchen/tvm/blob/main/python/tvm/s_tir/pipeline.py"
click node_storage "https://github.com/tqchen/tvm/blob/main/src/tirx/transform/storage_rewrite.cc"
click node_softwarepipe "https://github.com/tqchen/tvm/blob/main/src/s_tir/transform/inject_software_pipeline.cc"
click node_backend "https://github.com/tqchen/tvm/blob/main/python/tvm/relax/backend/__init__.py"
click node_cuda "https://github.com/tqchen/tvm/blob/main/python/tvm/backend/cuda/lang/pipeline.py"
click node_trn "https://github.com/tqchen/tvm/blob/main/python/tvm/backend/trn/pipeline.py"
click node_metaschedule "https://github.com/tqchen/tvm/blob/main/include/tvm/s_tir/meta_schedule/database.h"
click node_driver "https://github.com/tqchen/tvm/blob/main/python/tvm/driver/build_module.py"
click node_codegen "https://github.com/tqchen/tvm/blob/main/include/tvm/target/codegen.h"
click node_runtime "https://github.com/tqchen/tvm/blob/main/include/tvm/runtime/base.h"
click node_memory "https://github.com/tqchen/tvm/blob/main/src/runtime/memory/memory_manager.cc"
click node_rpc "https://github.com/tqchen/tvm/blob/main/jvm/core/src/main/java/org/apache/tvm/rpc/ServerProcessor.java"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_relax,node_ir,node_tirx toneBlue
class node_relaxpipe,node_tirxpipe,node_stirpipe,node_storage,node_softwarepipe toneAmber
class node_backend,node_cuda,node_trn,node_metaschedule,node_driver,node_codegen toneMint
class node_runtime,node_memory,node_rpc toneRose
class node_engineer toneIndigo
```

## Components

### Model and IR

- [Relax Graph IR](https://github.com/tqchen/tvm/blob/main/python/tvm/relax/expr.py): `python/tvm/relax/expr.py`
- [IR Module](https://github.com/tqchen/tvm/blob/main/python/tvm/ir/module.py): `python/tvm/ir/module.py`
- [TIRx Programs](https://github.com/tqchen/tvm/blob/main/python/tvm/tirx/op.py): `python/tvm/tirx/op.py`

### Lowering and Optimization

- [Relax Pipeline](https://github.com/tqchen/tvm/blob/main/python/tvm/relax/pipeline.py): `python/tvm/relax/pipeline.py`
- [TIRx Pipeline](https://github.com/tqchen/tvm/blob/main/python/tvm/tirx/compilation_pipeline.py): `python/tvm/tirx/compilation_pipeline.py`
- [S-TIR Pipeline](https://github.com/tqchen/tvm/blob/main/python/tvm/s_tir/pipeline.py): `python/tvm/s_tir/pipeline.py`
- [Storage Rewrite](https://github.com/tqchen/tvm/blob/main/src/tirx/transform/storage_rewrite.cc): `src/tirx/transform/storage_rewrite.cc`
- [Software Pipelining](https://github.com/tqchen/tvm/blob/main/src/s_tir/transform/inject_software_pipeline.cc): `src/s_tir/transform/inject_software_pipeline.cc`

### Targets and Scheduling

- [Backend Pipelines](https://github.com/tqchen/tvm/blob/main/python/tvm/relax/backend/__init__.py): `python/tvm/relax/backend/__init__.py`
- [CUDA Tile Backend](https://github.com/tqchen/tvm/blob/main/python/tvm/backend/cuda/lang/pipeline.py): `python/tvm/backend/cuda/lang/pipeline.py`
- [Trainium Backend](https://github.com/tqchen/tvm/blob/main/python/tvm/backend/trn/pipeline.py): `python/tvm/backend/trn/pipeline.py`
- [Meta-Schedule](https://github.com/tqchen/tvm/blob/main/include/tvm/s_tir/meta_schedule/database.h): `include/tvm/s_tir/meta_schedule/database.h`
- [Compile Driver](https://github.com/tqchen/tvm/blob/main/python/tvm/driver/build_module.py): `python/tvm/driver/build_module.py`
- [Target Code Generation](https://github.com/tqchen/tvm/blob/main/include/tvm/target/codegen.h): `include/tvm/target/codegen.h`

### Deployment and Runtime

- [TVM Runtime](https://github.com/tqchen/tvm/blob/main/include/tvm/runtime/base.h): `include/tvm/runtime/base.h`
- [Runtime Memory](https://github.com/tqchen/tvm/blob/main/src/runtime/memory/memory_manager.cc): `src/runtime/memory/memory_manager.cc`
- [RPC Deployment](https://github.com/tqchen/tvm/blob/main/jvm/core/src/main/java/org/apache/tvm/rpc/ServerProcessor.java): `jvm/core/src/main/java/org/apache/tvm/rpc/ServerProcessor.java`

### Other components

- **Model Author**

## Connections

- Model Author → Relax Graph IR: defines model (evidence: `README.md`)
- Relax Graph IR → IR Module: represented in (evidence: `README.md`)
- Relax Pipeline → Backend Pipelines: dispatches operators (evidence: `python/tvm/relax/pipeline.py`)
- Relax Pipeline → IR Module: transforms module (evidence: `python/tvm/relax/pipeline.py`)
- TIRx Pipeline → IR Module: transforms module (evidence: `python/tvm/tirx/compilation_pipeline.py`)
- S-TIR Pipeline → TIRx Pipeline: uses compilation pipeline (evidence: `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 (evidence: `python/tvm/backend/trn/pipeline.py`)
- Meta-Schedule → S-TIR Pipeline: tunes schedules (evidence: `README.md`)
- Compile Driver → Target Code Generation: compiles for target (evidence: `README.md`)
- Target Code Generation → TVM Runtime: produces deployable module (evidence: `README.md`)
- TVM Runtime → Runtime Memory: manages allocations
- TVM Runtime → RPC Deployment: supports remote execution
