FlagTree extensible framework#
FlagTree extensible framework is specifically designed to support multi-backend compilation and three-level compiler languages, as mentioned in the Features section.
Backend extensions: FlagTree follows a plugin-based architecture, where each backend is self-contained in
third_party/[backend_name]/. Each backend implements the BaseBackend interface, defines its compilation pipeline throughadd_stages(), and provides backend-specific optimizations and code generation. This design allows adding new backends without modifying the core Triton code.Language and compiler optimization extensions: For existing Triton code, FlagTree adopts incremental extensions for full compatibility with native Triton. These extensions include the following modification to the common architecture:
Modifications to Existing Triton Files: FlagTree incrementally extends Tritonβs compilation pipeline by modifying existing files. For example,
python/triton/runtime/jit.pyis extended to parse#@hint:comments and route TLE syntax, attaching hints to AST nodes. TTIR dialect definition files (.td) are extended with new attribute definitions to encode hints as MLIR attributes on operations likett.load. Backend compiler files (for example,backend/compiler.py) are extended to register new optimization passes that process hints and TLE operations, integrating with the existing pass management infrastructure.New Files Added: FlagTree introduces a complete TLE module as new files in
third_party/tle/, including dialect definitions (operations liketle.dsl_region), transformation pass implementations (memory space assignment, async load lowering, and so on.), LLVM conversion passes, and Python language bindings. This modular design keeps TLE independent from core Triton while integrating through the extended TTIR attributes and backend pass registration mechanism, enabling features like shared memory management and pipeline optimizations without modifying the common architecture.
For TLE specifically, FlagTree maximizes separation between TLE language extensions (python/triton/experimental/tle/) and TLE MLIR dialect (third_party/tle/). TLE language constructs are defined in Python and integrated through the AST processing pipeline, while TLE dialect operations are implemented in C++/MLIR and integrated through the compilation pipeline. This separation allows language features and IR transformations to evolve independently, improving maintainability and enabling different backends to adopt TLE features at different stages of the compilation pipeline.
The following code structure shows how FlagTree organizes its extensions:
flagtree/
βββ python/
β βββ triton/ # Triton core (existing)
β β βββ compiler/
β β β βββ code_generator.py # [EXTENDED] TLE module dispatch, Hints extraction
β β β βββ compiler.py
β β βββ language/
β β β βββ core.py # [EXTENDED] Hints
β β β βββ semantic.py # [EXTENDED] Hints
β β βββ runtime/
β β β βββ jit.py # [EXTENDED] Hints
β β βββ experimental/ # Language extensions
β β βββ tle/ # TLE (Triton Language Extensions)
β β βββ language/ # TLE language definition (extends AST Processing)
β β β βββ core.py # TLE-Lite: Core TLE language features (for example, tle.load)
β β β βββ [gpu/npu]/ # TLE-Struct: GPU-specific and NPU-specific constructs
β β β β βββ core.py
β β β β βββ semantic.py
β β β β βββ types.py
β β β βββ raw/ # TLE-Raw: Raw MLIR programming interface
β β β βββ core.py
β β β βββ semantic.py
β β βββ raw/ # TLE-Raw implementation (extends AST Processing)
β β βββ mlir/ # MLIR code generation for TLE-Raw
β β β βββ codegen.py
β β β βββ runtime.py
β β βββ runtime.py # Runtime support for TLE-Raw
β βββ tutorials/ # Tutorials and examples (not in code path)
β β βββ tle/ # TLE examples
β β βββ 01-sparse-mla.py
β β βββ raw/ # TLE-Raw examples
β βββ test/ # Test code (not in code path)
β βββ tle/ # TLE tests
β βββ integration/ # Integration tests
β βββ unit/ # Unit tests
β βββ run_tests.py
β
βββ third_party/
βββ [backend_name]/ # Backend-specific extensions
β βββ backend/
β β βββ compiler.py # [EXTENDED] TLE and HINTS pass dispatch
β βββ include/ # TTIR dialect definitions (may extend tt.load with attributes)
β βββ lib/
βββ tle/ # TLE MLIR extensions
β βββ dialect/ # TLE dialect implementation
β βββ include/IR/
β βββ lib/IR/
β βββ lib/Conversion/
β βββ lib/Transforms/
βββ flir/ # FLIR: FlagTree-maintained common Linalg, including HINTS pass
Note
The code structure above shows only the key files and directories relevant to FlagTreeβs extensions. Many other files and subdirectories in the codebase are omitted for clarity.