# flagos-ai/flagtree architecture

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

- Interactive diagram: https://gitdiagram.com/flagos-ai/flagtree
- Repository: https://github.com/flagos-ai/flagtree
- Video tour (about a minute): https://gitdiagram.com/flagos-ai/flagtree/video

## Overview

FlagTree is a unified Triton-based compiler for AI accelerators, with language extensions and backend-specific support. The primary workflow is kernel authoring, compilation through Triton and GPU-oriented IR, hardware-specific lowering, then backend execution. Its internal compiler layers include layout analysis and loop pipelining; TLE adds portable-to-hardware-specific programming layers. The README documents multi-backend support and TLE capabilities, while sampled sources focus on compiler IR and pipelining, so several workflow links are shown as unverified rather than inferred as certain.

Main entry points: [`lib/Dialect/TritonGPU/IR/Ops.cpp`](https://github.com/flagos-ai/flagtree/blob/main/lib/Dialect/TritonGPU/IR/Ops.cpp) (TritonGPU IR), [`lib/Dialect/TritonGPU/Transforms/Pipeliner/SoftwarePipeliner.cpp`](https://github.com/flagos-ai/flagtree/blob/main/lib/Dialect/TritonGPU/Transforms/Pipeliner/SoftwarePipeliner.cpp) (Software pipeliner), [`python/triton/language/core.py`](https://github.com/flagos-ai/flagtree/blob/main/python/triton/language/core.py) (Triton language), [`python/triton/compiler/compiler.py`](https://github.com/flagos-ai/flagtree/blob/main/python/triton/compiler/compiler.py) (Compiler API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_authoring["Kernel authoring"]
  node_language["Triton language<br/>[core.py]"]
  node_gluon["Gluon language<br/>[_core.py]"]
end

subgraph group_compiler["Triton compiler"]
  node_compiler_api["Compiler API<br/>[compiler.py]"]
  node_triton_ir["Triton IR<br/>[Ops.cpp]"]
end

subgraph group_gpu["GPU optimization"]
  node_gpu_ir["TritonGPU IR<br/>[Ops.cpp]"]
  node_layout_analysis["Layout analysis<br/>[Utility.cpp]"]
  node_layout_model["Linear layouts<br/>[LinearLayout.cpp]"]
  node_gpu_optimization["GPU transforms<br/>[Utility.cpp]"]
  node_pipeline["Software pipeliner"]
  node_pipeline_expander["Pipeline expander"]
end

subgraph group_backends["Backend integration"]
  node_nvidia_ir["NVIDIA GPU IR<br/>[Ops.cpp]"]
  node_nvidia_lowering["NVIDIA transforms<br/>[MMALowering.cpp]"]
  node_llvm_lowering["LLVM lowering<br/>[Utility.cpp]"]
  node_backend_runtime["Backend runtime<br/>[driver.py]"]
end

subgraph group_extensions["TLE extensions"]
  node_tle_lite_struct["TLE Lite / Struct<br/>[core.py]"]
  node_tle_raw["TLE Raw<br/>[typing.py]"]
end

node_developer(("Kernel developer"))
node_accelerator(("AI accelerator"))

node_developer -.->|"writes kernels"| node_language
node_developer -.->|"writes kernels"| node_gluon
node_language -.->|"compiles through"| node_compiler_api
node_gluon -.->|"compiles through"| node_compiler_api
node_compiler_api -.->|"produces IR"| node_triton_ir
node_triton_ir -.->|"converts to"| node_gpu_ir
node_gpu_ir -.->|"analyzes layouts"| node_layout_analysis
node_layout_analysis -->|"uses layouts"| node_layout_model
node_gpu_ir -.->|"transforms"| node_gpu_optimization
node_gpu_optimization -.->|"includes pipelining"| node_pipeline
node_pipeline -->|"expands schedule"| node_pipeline_expander
node_pipeline -->|"handles MMA"| node_nvidia_ir
node_gpu_ir -->|"specializes for NVIDIA"| node_nvidia_ir
node_nvidia_ir -.->|"lowers operations"| node_nvidia_lowering
node_gpu_ir -.->|"lowers to LLVM"| node_llvm_lowering
node_llvm_lowering -.->|"emits code for"| node_backend_runtime
node_backend_runtime -.->|"launches kernels"| node_accelerator
node_developer -.->|"uses extensions"| node_tle_lite_struct
node_tle_lite_struct -.->|"can use lower-level"| node_tle_raw
node_tle_raw -.->|"extends Triton"| node_language

click node_language "https://github.com/flagos-ai/flagtree/blob/main/python/triton/language/core.py"
click node_gluon "https://github.com/flagos-ai/flagtree/blob/main/python/triton/experimental/gluon/language/_core.py"
click node_compiler_api "https://github.com/flagos-ai/flagtree/blob/main/python/triton/compiler/compiler.py"
click node_triton_ir "https://github.com/flagos-ai/flagtree/blob/main/lib/Dialect/Triton/IR/Ops.cpp"
click node_gpu_ir "https://github.com/flagos-ai/flagtree/blob/main/lib/Dialect/TritonGPU/IR/Ops.cpp"
click node_layout_analysis "https://github.com/flagos-ai/flagtree/blob/main/lib/Analysis/Utility.cpp"
click node_layout_model "https://github.com/flagos-ai/flagtree/blob/main/lib/Tools/LinearLayout.cpp"
click node_gpu_optimization "https://github.com/flagos-ai/flagtree/blob/main/lib/Dialect/TritonGPU/Transforms/Utility.cpp"
click node_pipeline "https://github.com/flagos-ai/flagtree/blob/main/lib/Dialect/TritonGPU/Transforms/Pipeliner/SoftwarePipeliner.cpp"
click node_pipeline_expander "https://github.com/flagos-ai/flagtree/blob/main/lib/Dialect/TritonGPU/Transforms/Pipeliner/PipelineExpander.cpp"
click node_nvidia_ir "https://github.com/flagos-ai/flagtree/blob/main/lib/Dialect/TritonNvidiaGPU/IR/Ops.cpp"
click node_nvidia_lowering "https://github.com/flagos-ai/flagtree/blob/main/lib/Dialect/TritonNvidiaGPU/Transforms/MMALowering.cpp"
click node_llvm_lowering "https://github.com/flagos-ai/flagtree/blob/main/lib/Conversion/TritonGPUToLLVM/Utility.cpp"
click node_backend_runtime "https://github.com/flagos-ai/flagtree/blob/main/python/triton/backends/driver.py"
click node_tle_lite_struct "https://github.com/flagos-ai/flagtree/blob/main/python/triton/experimental/tle/language/core.py"
click node_tle_raw "https://github.com/flagos-ai/flagtree/blob/main/python/triton/experimental/tle/raw/typing.py"

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_language,node_gluon toneBlue
class node_compiler_api,node_triton_ir toneAmber
class node_gpu_ir,node_layout_analysis,node_layout_model,node_gpu_optimization,node_pipeline,node_pipeline_expander toneMint
class node_nvidia_ir,node_nvidia_lowering,node_llvm_lowering,node_backend_runtime toneRose
class node_tle_lite_struct,node_tle_raw,node_developer,node_accelerator toneIndigo
```

## Components

### Kernel authoring

- [Triton language](https://github.com/flagos-ai/flagtree/blob/main/python/triton/language/core.py): `python/triton/language/core.py`
- [Gluon language](https://github.com/flagos-ai/flagtree/blob/main/python/triton/experimental/gluon/language/_core.py): `python/triton/experimental/gluon/language/_core.py`

### Triton compiler

- [Compiler API](https://github.com/flagos-ai/flagtree/blob/main/python/triton/compiler/compiler.py): `python/triton/compiler/compiler.py`
- [Triton IR](https://github.com/flagos-ai/flagtree/blob/main/lib/Dialect/Triton/IR/Ops.cpp): `lib/Dialect/Triton/IR/Ops.cpp`

### GPU optimization

- [TritonGPU IR](https://github.com/flagos-ai/flagtree/blob/main/lib/Dialect/TritonGPU/IR/Ops.cpp): `lib/Dialect/TritonGPU/IR/Ops.cpp`
- [Layout analysis](https://github.com/flagos-ai/flagtree/blob/main/lib/Analysis/Utility.cpp): `lib/Analysis/Utility.cpp`
- [Linear layouts](https://github.com/flagos-ai/flagtree/blob/main/lib/Tools/LinearLayout.cpp): `lib/Tools/LinearLayout.cpp`
- [GPU transforms](https://github.com/flagos-ai/flagtree/blob/main/lib/Dialect/TritonGPU/Transforms/Utility.cpp): `lib/Dialect/TritonGPU/Transforms/Utility.cpp`
- [Software pipeliner](https://github.com/flagos-ai/flagtree/blob/main/lib/Dialect/TritonGPU/Transforms/Pipeliner/SoftwarePipeliner.cpp): `lib/Dialect/TritonGPU/Transforms/Pipeliner/SoftwarePipeliner.cpp`
- [Pipeline expander](https://github.com/flagos-ai/flagtree/blob/main/lib/Dialect/TritonGPU/Transforms/Pipeliner/PipelineExpander.cpp): `lib/Dialect/TritonGPU/Transforms/Pipeliner/PipelineExpander.cpp`

### Backend integration

- [NVIDIA GPU IR](https://github.com/flagos-ai/flagtree/blob/main/lib/Dialect/TritonNvidiaGPU/IR/Ops.cpp): `lib/Dialect/TritonNvidiaGPU/IR/Ops.cpp`
- [NVIDIA transforms](https://github.com/flagos-ai/flagtree/blob/main/lib/Dialect/TritonNvidiaGPU/Transforms/MMALowering.cpp): `lib/Dialect/TritonNvidiaGPU/Transforms/MMALowering.cpp`
- [LLVM lowering](https://github.com/flagos-ai/flagtree/blob/main/lib/Conversion/TritonGPUToLLVM/Utility.cpp): `lib/Conversion/TritonGPUToLLVM/Utility.cpp`
- [Backend runtime](https://github.com/flagos-ai/flagtree/blob/main/python/triton/backends/driver.py): `python/triton/backends/driver.py`

### TLE extensions

- [TLE Lite / Struct](https://github.com/flagos-ai/flagtree/blob/main/python/triton/experimental/tle/language/core.py): `python/triton/experimental/tle/language/core.py`
- [TLE Raw](https://github.com/flagos-ai/flagtree/blob/main/python/triton/experimental/tle/raw/typing.py): `python/triton/experimental/tle/raw/typing.py`

### Other components

- **Kernel developer**
- **AI accelerator**

## Connections

- Kernel developer → Triton language: writes kernels
- Kernel developer → Gluon language: writes kernels
- Triton language → Compiler API: compiles through
- Gluon language → Compiler API: compiles through
- Compiler API → Triton IR: produces IR
- Triton IR → TritonGPU IR: converts to
- TritonGPU IR → Layout analysis: analyzes layouts
- Layout analysis → Linear layouts: uses layouts (evidence: `lib/Analysis/Utility.cpp`)
- TritonGPU IR → GPU transforms: transforms
- GPU transforms → Software pipeliner: includes pipelining
- Software pipeliner → Pipeline expander: expands schedule (evidence: `lib/Dialect/TritonGPU/Transforms/Pipeliner/SoftwarePipeliner.cpp`)
- Software pipeliner → NVIDIA GPU IR: handles MMA (evidence: `lib/Dialect/TritonGPU/Transforms/Pipeliner/SoftwarePipeliner.cpp`)
- TritonGPU IR → NVIDIA GPU IR: specializes for NVIDIA
- NVIDIA GPU IR → NVIDIA transforms: lowers operations
- TritonGPU IR → LLVM lowering: lowers to LLVM
- LLVM lowering → Backend runtime: emits code for
- Backend runtime → AI accelerator: launches kernels
- Kernel developer → TLE Lite / Struct: uses extensions
- TLE Lite / Struct → TLE Raw: can use lower-level
- TLE Raw → Triton language: extends Triton
