# tenstorrent/tt-mlir architecture

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

- Interactive diagram: https://gitdiagram.com/tenstorrent/tt-mlir
- Repository: https://github.com/tenstorrent/tt-mlir

## Overview

##### Main Components
– StableHLO conversion (e.g. ArithToStableHLO, and StableHLOToTTIR)
– TTIR Decomposition and Generic conversion passes (TTIRToLinalg, TTIRToTTIRDecomposition, TTIRToTTMetal, etc.)
– TTKernel and TTNN conversion passes (TTKernelToEmitC, TTNNToEmitC)
- Runtime and Target Code Generation – Represent the runtime libraries and target support (found in “runtime”, “lib/Target”, etc.) which include TTMetal, TTNN, and additional linking layers.
- Frontend/Tools and Integration – Include a separate block for the “tools” and “python” layers which provide:
– Compiler utilities (tt-mlir-opt, tt-mlir-translate, LSP server)
– Python bindings for integration and testing (modules in python/ttmlir and python/pykernel)
- Testing & CI Infrastructure – Although not central to the execution flow, mention that there’s an extensive suite of unit tests and lit tests, represented by the “test” directory. This highlights the project’s verification process.

##### Relationships and Data Flow
- That the “tools” interact with the compiler core (e.g. via command-line utilities and LSP integration) and support testing, debugging, and performance reporting.

##### Architectural Patterns and Technologies
- Layered, modular structure. Each transformation pass is designed to handle specific dialect translation and optimization tasks.

##### Final Overview
- It’s essential to be detailed: each major component (dialect definitions, conversion passes, runtime support, tools, and test harness) should be individually identified. This separation is critical since the project’s extensibility relies on its modular design and layered IR transformations.
- Incorporate the key technologies: MLIR as the foundation, C++ as the implementation language with CMake-based build configuration, and Python for scripting and testing support.

## Diagram (Mermaid)

```mermaid
flowchart TD
    A["Input MLIR IR"]:::input
    B["Base MLIR Framework"]:::mlir
    C["TT-MLIR Dialect Layer"]:::dialect
    D["Conversion Pass Pipelines"]:::conversion
    E["Runtime & Target Code Generation"]:::runtime
    F["Frontend/Tools & Integration"]:::tools
    G["Testing & CI Infrastructure"]:::test

    A -->|"parses"| B
    B -->|"registers dialects"| C
    C -->|"transforms IR"| D
    D -->|"lowers to target code"| E

    %% Tools interact with core components and support testing
    F -->|"invokes/utilizes"| C
    F -->|"triggers passes"| D
    F -->|"interfaces with"| E
    F -->|"reports/tests"| G

    %% Click Events for components
    click B "https://github.com/tenstorrent/tt-mlir/blob/main/cmake/modules/FindMLIR.cmake"
    click C "https://github.com/tenstorrent/tt-mlir/tree/main/include/ttmlir/Dialect"
    click C "https://github.com/tenstorrent/tt-mlir/tree/main/lib/Dialect"
    click D "https://github.com/tenstorrent/tt-mlir/tree/main/include/ttmlir/Conversion"
    click D "https://github.com/tenstorrent/tt-mlir/tree/main/lib/Conversion"
    click E "https://github.com/tenstorrent/tt-mlir/tree/main/runtime"
    click E "https://github.com/tenstorrent/tt-mlir/tree/main/lib/Target"
    click F "https://github.com/tenstorrent/tt-mlir/tree/main/tools/ttmlir-opt"
    click F "https://github.com/tenstorrent/tt-mlir/tree/main/tools/ttmlir-translate"
    click F "https://github.com/tenstorrent/tt-mlir/tree/main/python/ttmlir"
    click F "https://github.com/tenstorrent/tt-mlir/tree/main/include/ttmlir/Bindings/Python"
    click G "https://github.com/tenstorrent/tt-mlir/tree/main/test"
    click G "https://github.com/tenstorrent/tt-mlir/blob/main/.github"

    %% Styles
    classDef input fill:#ffffff,stroke:#333,stroke-width:2px;
    classDef mlir fill:#A2D9CE,stroke:#333,stroke-width:2px;
    classDef dialect fill:#AED6F1,stroke:#333,stroke-width:2px;
    classDef conversion fill:#A9DFBF,stroke:#333,stroke-width:2px;
    classDef runtime fill:#F9E79F,stroke:#333,stroke-width:2px;
    classDef tools fill:#F5B7B1,stroke:#333,stroke-width:2px;
    classDef test fill:#D2B4DE,stroke:#333,stroke-width:2px;
```
