# apache/tvm architecture

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

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

## Overview

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: [`include/tvm/runtime/base.h`](https://github.com/apache/tvm/blob/main/include/tvm/runtime/base.h) (TVM Runtime), [`python/tvm/relax/expr.py`](https://github.com/apache/tvm/blob/main/python/tvm/relax/expr.py) (Relax Graph IR), [`python/tvm/relax/pipeline.py`](https://github.com/apache/tvm/blob/main/python/tvm/relax/pipeline.py) (Relax Pipeline), [`python/tvm/s_tir/pipeline.py`](https://github.com/apache/tvm/blob/main/python/tvm/s_tir/pipeline.py) (Tensor Scheduling)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_model["Model and IR"]
  node_frontends["Model Frontends"]
  node_relax["Relax Graph IR<br/>[expr.py]"]
  node_ir["Core IR<br/>[module.py]"]
  node_tirx["Tensor IR<br/>[expr.py]"]
end

subgraph group_compile["Compilation"]
  node_relax_passes["Relax Transforms"]
  node_relax_pipeline["Relax Pipeline<br/>[pipeline.py]"]
  node_tir_pipeline["Tensor Lowering"]
  node_stir_pipeline["Tensor Scheduling<br/>[pipeline.py]"]
  node_storage_rewrite["Storage Planning<br/>[storage_rewrite.cc]"]
  node_meta_schedule["Meta-Schedule<br/>[database.h]"]
end

subgraph group_targets["Target Backends"]
  node_target_codegen["Target Codegen<br/>[codegen.h]"]
  node_cuda_ops["CUDA Operations<br/>[op.py]"]
  node_ptx_engine["PTX Instruction Engine<br/>[engine.py]"]
  node_ptx_table["PTX Instruction Table<br/>[table.py]"]
end

subgraph group_runtime["Runtime and Deployment"]
  node_memory["Runtime Memory<br/>[memory_manager.cc]"]
  node_runtime["TVM Runtime<br/>[base.h]"]
  node_rpc["RPC Services<br/>[Server.java]"]
  node_disco["Distributed Runtime<br/>[disco_worker.cc]"]
  node_hexagon["Hexagon Runtime"]
end

node_user(("Model Developer"))
node_artifact["Deployable Module"]

node_user -.->|"imports model"| node_frontends
node_user -.->|"constructs graph"| node_relax
node_frontends -.->|"translates to"| node_relax
node_relax -.->|"uses IR"| node_ir
node_relax_pipeline -->|"applies passes"| node_relax_passes
node_relax_pipeline -->|"transforms module"| node_relax
node_relax_pipeline -.->|"lowers computation"| node_tirx
node_tir_pipeline -->|"lowers IR"| node_tirx
node_stir_pipeline -->|"uses pipeline"| node_tir_pipeline
node_stir_pipeline -.->|"runs rewrite"| node_storage_rewrite
node_stir_pipeline -.->|"tunes schedules"| node_meta_schedule
node_tir_pipeline -.->|"prepares codegen"| node_target_codegen
node_cuda_ops -->|"builds instructions"| node_ptx_engine
node_ptx_engine -->|"queries instruction table"| node_ptx_table
node_target_codegen -.->|"emits module"| node_artifact
node_runtime -.->|"manages allocations"| node_memory
node_artifact -.->|"runs on"| node_runtime
node_user -.->|"deploys remotely"| node_rpc
node_rpc -.->|"serves execution"| node_runtime
node_user -.->|"runs distributed"| node_disco
node_runtime -.->|"supports target"| node_hexagon

click node_frontends "https://github.com/apache/tvm/tree/main/python/tvm/relax/frontend"
click node_relax "https://github.com/apache/tvm/blob/main/python/tvm/relax/expr.py"
click node_ir "https://github.com/apache/tvm/blob/main/python/tvm/ir/module.py"
click node_relax_passes "https://github.com/apache/tvm/tree/main/python/tvm/relax/transform"
click node_relax_pipeline "https://github.com/apache/tvm/blob/main/python/tvm/relax/pipeline.py"
click node_tirx "https://github.com/apache/tvm/blob/main/python/tvm/tirx/expr.py"
click node_tir_pipeline "https://github.com/apache/tvm/blob/main/python/tvm/tirx/compilation_pipeline.py"
click node_stir_pipeline "https://github.com/apache/tvm/blob/main/python/tvm/s_tir/pipeline.py"
click node_storage_rewrite "https://github.com/apache/tvm/blob/main/src/tirx/transform/storage_rewrite.cc"
click node_meta_schedule "https://github.com/apache/tvm/blob/main/include/tvm/s_tir/meta_schedule/database.h"
click node_target_codegen "https://github.com/apache/tvm/blob/main/include/tvm/target/codegen.h"
click node_cuda_ops "https://github.com/apache/tvm/blob/main/python/tvm/backend/cuda/op.py"
click node_ptx_engine "https://github.com/apache/tvm/blob/main/python/tvm/backend/cuda/ptx/engine.py"
click node_ptx_table "https://github.com/apache/tvm/blob/main/python/tvm/backend/cuda/ptx/table.py"
click node_memory "https://github.com/apache/tvm/blob/main/src/runtime/memory/memory_manager.cc"
click node_runtime "https://github.com/apache/tvm/blob/main/include/tvm/runtime/base.h"
click node_rpc "https://github.com/apache/tvm/blob/main/jvm/core/src/main/java/org/apache/tvm/rpc/Server.java"
click node_disco "https://github.com/apache/tvm/blob/main/src/runtime/extra/disco/disco_worker.cc"
click node_hexagon "https://github.com/apache/tvm/blob/main/src/backend/hexagon/runtime/hexagon_thread_manager.h"

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_frontends,node_relax,node_ir,node_tirx toneBlue
class node_relax_passes,node_relax_pipeline,node_tir_pipeline,node_stir_pipeline,node_storage_rewrite,node_meta_schedule toneAmber
class node_target_codegen,node_cuda_ops,node_ptx_engine,node_ptx_table toneMint
class node_memory,node_runtime,node_rpc,node_disco,node_hexagon toneRose
class node_user,node_artifact toneIndigo
```

## Components

### Model and IR

- [Model Frontends](https://github.com/apache/tvm/tree/main/python/tvm/relax/frontend): `python/tvm/relax/frontend`
- [Relax Graph IR](https://github.com/apache/tvm/blob/main/python/tvm/relax/expr.py): `python/tvm/relax/expr.py`
- [Core IR](https://github.com/apache/tvm/blob/main/python/tvm/ir/module.py): `python/tvm/ir/module.py`
- [Tensor IR](https://github.com/apache/tvm/blob/main/python/tvm/tirx/expr.py): `python/tvm/tirx/expr.py`

### Compilation

- [Relax Transforms](https://github.com/apache/tvm/tree/main/python/tvm/relax/transform): `python/tvm/relax/transform`
- [Relax Pipeline](https://github.com/apache/tvm/blob/main/python/tvm/relax/pipeline.py): `python/tvm/relax/pipeline.py`
- [Tensor Lowering](https://github.com/apache/tvm/blob/main/python/tvm/tirx/compilation_pipeline.py): `python/tvm/tirx/compilation_pipeline.py`
- [Tensor Scheduling](https://github.com/apache/tvm/blob/main/python/tvm/s_tir/pipeline.py): `python/tvm/s_tir/pipeline.py`
- [Storage Planning](https://github.com/apache/tvm/blob/main/src/tirx/transform/storage_rewrite.cc): `src/tirx/transform/storage_rewrite.cc`
- [Meta-Schedule](https://github.com/apache/tvm/blob/main/include/tvm/s_tir/meta_schedule/database.h): `include/tvm/s_tir/meta_schedule/database.h`

### Target Backends

- [Target Codegen](https://github.com/apache/tvm/blob/main/include/tvm/target/codegen.h): `include/tvm/target/codegen.h`
- [CUDA Operations](https://github.com/apache/tvm/blob/main/python/tvm/backend/cuda/op.py): `python/tvm/backend/cuda/op.py`
- [PTX Instruction Engine](https://github.com/apache/tvm/blob/main/python/tvm/backend/cuda/ptx/engine.py): `python/tvm/backend/cuda/ptx/engine.py`
- [PTX Instruction Table](https://github.com/apache/tvm/blob/main/python/tvm/backend/cuda/ptx/table.py): `python/tvm/backend/cuda/ptx/table.py`

### Runtime and Deployment

- [Runtime Memory](https://github.com/apache/tvm/blob/main/src/runtime/memory/memory_manager.cc): `src/runtime/memory/memory_manager.cc`
- [TVM Runtime](https://github.com/apache/tvm/blob/main/include/tvm/runtime/base.h): `include/tvm/runtime/base.h`
- [RPC Services](https://github.com/apache/tvm/blob/main/jvm/core/src/main/java/org/apache/tvm/rpc/Server.java): `jvm/core/src/main/java/org/apache/tvm/rpc/Server.java`
- [Distributed Runtime](https://github.com/apache/tvm/blob/main/src/runtime/extra/disco/disco_worker.cc): `src/runtime/extra/disco/disco_worker.cc`
- [Hexagon Runtime](https://github.com/apache/tvm/blob/main/src/backend/hexagon/runtime/hexagon_thread_manager.h): `src/backend/hexagon/runtime/hexagon_thread_manager.h`

### Other components

- **Model Developer**
- **Deployable Module**

## Connections

- Model Developer → Model Frontends: imports model (evidence: `README.md`)
- Model Developer → Relax Graph IR: constructs graph (evidence: `README.md`)
- Model Frontends → Relax Graph IR: translates to (evidence: `README.md`)
- Relax Graph IR → Core IR: uses IR
- Relax Pipeline → Relax Transforms: applies passes (evidence: `python/tvm/relax/pipeline.py`)
- Relax Pipeline → Relax Graph IR: transforms module (evidence: `python/tvm/relax/pipeline.py`)
- Relax Pipeline → Tensor IR: lowers computation (evidence: `README.md`)
- Tensor Lowering → Tensor IR: lowers IR (evidence: `python/tvm/tirx/compilation_pipeline.py`)
- Tensor Scheduling → Tensor Lowering: uses pipeline (evidence: `python/tvm/s_tir/pipeline.py`)
- Tensor Scheduling → Storage Planning: runs rewrite (evidence: `python/tvm/s_tir/pipeline.py`)
- Tensor Scheduling → Meta-Schedule: tunes schedules (evidence: `README.md`)
- Tensor Lowering → Target Codegen: prepares codegen (evidence: `python/tvm/tirx/compilation_pipeline.py`)
- CUDA Operations → PTX Instruction Engine: builds instructions (evidence: `python/tvm/backend/cuda/ptx/engine.py`)
- PTX Instruction Engine → PTX Instruction Table: queries instruction table (evidence: `python/tvm/backend/cuda/ptx/engine.py`)
- Target Codegen → Deployable Module: emits module (evidence: `README.md`)
- TVM Runtime → Runtime Memory: manages allocations
- Deployable Module → TVM Runtime: runs on (evidence: `README.md`)
- Model Developer → RPC Services: deploys remotely (evidence: `README.md`)
- RPC Services → TVM Runtime: serves execution
- Model Developer → Distributed Runtime: runs distributed (evidence: `README.md`)
- TVM Runtime → Hexagon Runtime: supports target
