[Triton] Integrate reorder-loop-loads into LoopUnroll pass#775
Conversation
|
Please refer to PR 763 to add the C++ macro switch. |
|
Thanks for working on this optimization. Could you please avoid modifying the upstream Would it also be possible to move as much of the backend-specific implementation as possible out of upstream Triton-owned directories and into the TLE subtree? If a hook in an upstream-owned file is unavoidable, please keep it minimal and place the TLE-specific code behind the appropriate TLE build guard. This will minimize divergence from upstream and make ownership of the extension explicit. Please update the relevant call sites and tests to use |
There was a problem hiding this comment.
Please add this test to nv3.6-build-and-test.yml
Addresses PR feedback by removing `reorder` from upstream `tl.range` and moving it entirely into the TLE namespace, minimizing upstream Triton modifications. Frontend changes: - Remove `reorder` parameter from `triton.language.range` (python/triton/language/core.py) - Introduce `tle.range(..., reorder=False)` that inherits from `tl.range` and adds the `reorder` boolean parameter (python/triton/experimental/tle/language/gpu/core.py) - Export `tle.range` through TLE language API (__init__.py files) - Update compiler to recognize `tle.range` iterator (python/triton/compiler/code_generator.py) Backend changes: - Extract all reorder-loop-loads implementation (~108 lines) from LoopUnroll.cpp into dedicated TLE-owned files: - third_party/tle/dialect/include/Transforms/ReorderLoopLoads.h - third_party/tle/dialect/lib/Transforms/ReorderLoopLoads.cpp - Keep minimal hook in LoopUnroll.cpp behind __FLAGTREE_REORDER_LOOP_LOADS__ guard - Conditionally compile TLE implementation only when FLAGTREE_TLE is enabled (lib/Dialect/Triton/Transforms/CMakeLists.txt) Call sites: - Update tutorial to use `tle.range(..., reorder=True)` (python/tutorials/12-fused_inv_rope_fp8_quant_reorder.py) Impact: - Upstream `tl.range` remains unchanged - Clear ownership: `reorder` is explicitly a FlagTree/TLE extension - Minimal upstream footprint: reduces divergence from mainline Triton
Background
In Triton kernels, load operations and compute operations are interleaved after loop unrolling. On some hardware, this interleaving prevents memory access latency from being effectively hidden — because each load's result is immediately consumed by the computation that follows it, leaving the pipeline underutilized.
The ideal approach is to hoist (cluster) the load operations from each unrolled iteration to the front, so that multiple loads can be in-flight simultaneously, thereby exploiting memory system bandwidth and hiding latency.
Design
1. Reorder logic integrated into LoopUnroll
For loops with
tt.reorderattribute:Key helpers:
willFullyUnroll()(static trip count check),collectDepsInBlock()(transitive dep collection),reorderLoadsInRange()(load-first reordering preserving relative order within each group).2. User interface
Added
reorder=Falseparameter totl.range. Whenreorder=Truewithloop_unroll_factorset, thett.reorderattribute is attached to thescf.for, triggering load clustering during unroll.Performance
fused_inv_rope_fp8_quant