How microsoft/triton-shared works
Project type and purpose
• This is a compiler‐related project: a shared middle‐layer for the Triton compiler that lowers Triton IR into MLIR core dialects (Linalg, Tensor, Memref), enabling reuse of analyses and backends across Triton targets and other languages.
• Primary use cases:
• Stand‐alone conversion tool (triton-shared-opt) for Triton→MLIR transformations
• Out-of-tree backend component for Triton (e.g., reference CPU backend via Python driver)
• Integration in Triton’s compilation pipeline to emit hardware‐specific IR
File structure
• Top‐level build and governance: CMakeLists.txt, .github/, LICENSE, CONTRIBUTING.md
• Core middle layer source:
• include/triton-shared/ – public headers (subdirs: Analysis, Conversion, Dialect, Transform, Utils)
• lib/ – implementation of analyses, conversion passes, dialects, transforms, utils
• Backend glue:
• backend/compiler.py & backend/driver.py – Python bindings and driver for the reference CPU backend
• backend/include/ExecutionEngine – CRunner utilities, sanitizer helpers
• Tools:
• tools/triton-shared-opt/ – standalone CLI executable that wires MLIR passes and registration of Triton‐shared dialects
• Python integration: python/examples/ – sample Triton programs and pytest harness
• Scripts: build and sanitizer setup under scripts/
• Tests:
• test/ – lit tests covering conversion scenarios, Sanitizer tests
• Python example tests under python/examples run with pytest
README for additional insights
• Describes compiler pipeline:
[Triton IR] → [Middle Layer (MLIR Linalg & Memref)] → [HW-specific IR]
• Key analyses: Pointer analysis, Use analysis, Mask analysis
• Conversion passes: TritonToLinalg, bufferization, lowering of loads/stores to memref ops, translation of elementwise ops to linalg.generic, dot→linalg.matmul, reduce→linalg.reduce
• Build & usage instructions: CMake + Ninja + pybind11 for Python driver, plugin registration via TRITON_PLUGIN_DIRS
1. Triton Frontend (external)
• Triton IR generator (from Python/CLI)
2. Middle Layer (this project)
• Public API (headers in include/triton-shared/)
• Implementation libraries (lib/*)
• Analyses (Pointer, Use, Mask)
• Conversion Passes (TritonToLinalg, StructuredToMemref, TritonArithToLinalg, etc.)
• Dialect definitions (TritonStructured, TPtr, TritonTilingExt)
• Transforms (AddLLVMDebugInfo)
3. Tools & Drivers
• triton-shared-opt CLI (in tools/)
• Python driver (backend/driver.py, backend/compiler.py)
4. Backend / Hardware‐specific IR (external)
5. Tests and Examples
• lit tests (test/)
• Python examples & pytest (python/examples/)
6. Build System & Scripts
• CMake, Ninja targets, sanitizer scripts (scripts/)
1. Triton Frontend → invokes triton-shared‐opt OR Triton plugin registration
2. triton-shared‐opt / Python driver → MLIR Pass Manager →
a. Analyses → Conversion Passes → Bufferization → HW‐specific IR
3. Conversion Passes ↔ Dialect Definitions (they register ops/types)
4. Tests/Examples → Python driver / CLI tool → Middle Layer → validate IR dumps
c. Architectural patterns and principles
• Compiler pipeline / pass‐manager architecture
• Modular layering: clear separation of Analysis, Conversion, Dialect, Transform, Utils
• Plugin pattern for dialect registration (MLIR dialect registry)
• Out-of-tree backend integration via Python driver and CMake targets
d. Relevant technologies & frameworks
• MLIR (Linalg, Tensor, Memref dialects)
• LLVM (for code generation, sanitizers)
• CMake & Ninja (build)
• Python (pybind11 bindings, pytest)
• Triton compiler (as submodule)
Detail without overthinking
• Directory’s role as a separate component if it has unique functionality
• Detail both C++ and Python integration surfaces
• Build & test subsystems to give a full picture of how the project fits into Triton’s end-to-end pipeline