Skip unnecessary boundary-check masks in RewriteTensorDescriptorToPointerPass#10034
Open
gkmhub wants to merge 1 commit intotriton-lang:mainfrom
Open
Skip unnecessary boundary-check masks in RewriteTensorDescriptorToPointerPass#10034gkmhub wants to merge 1 commit intotriton-lang:mainfrom
gkmhub wants to merge 1 commit intotriton-lang:mainfrom
Conversation
…ptorToPointerPass Summary: CONTEXT: RewriteTensorDescriptorToPointerPass unconditionally generates masked loads/stores for all tensor descriptor accesses, even when the access is provably in-bounds. This causes ~20% perf regression vs the block pointer path for backends without TMA hardware. WHAT: Add two mechanisms to skip unnecessary mask generation: 1. Static in-bounds analysis (isStaticallyInBounds) that checks offset[i] + blockShape[i] <= shape[i] at compile time. 2. skip_boundary_check UnitAttr on descriptor_load/descriptor_store that frontends can set when they guarantee in-bounds access. Fixes triton-lang#10033
Collaborator
|
If the semantic of descriptor ops (which is meant to map to TMA kind of HW) is a problem one alternative is to mimic what is currently in the front end for block_ptr and get array indexing support purely in SW: https://github.com/triton-lang/triton/blob/main/python/triton/language/core.py#L1743. We transitioned some kernels using this solution and it was fairly simple. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
RewriteTensorDescriptorToPointerPassunconditionally generates masked loads/stores for all tensor descriptor accesses. In contrast, the block pointer path (RewriteTensorPointerPass) respectsboundary_check=[]and produces unmasked loads/stores when no boundary checking is needed.This causes backends that lower tensor descriptors to pointer arithmetic (i.e., backends without TMA hardware) to always pay the cost of masked memory operations, even for provably in-bounds accesses (~20% perf regression in our benchmarks).
This PR adds two complementary mechanisms to skip unnecessary mask generation:
Static in-bounds analysis (
isStaticallyInBounds): compile-time check that verifiesoffset[i] + blockShape[i] <= shape[i]for all dimensions. When provably in-bounds, the pass emits unmaskedtt.load/tt.store.skip_boundary_checkattribute: a newUnitAttrontt.descriptor_loadandtt.descriptor_storethat frontends (e.g., Inductor) can set when they guarantee the access is in-bounds. On backends with TMA hardware, this attribute is simply ignored.Fixes #10033
Files Changed
include/triton/Dialect/Triton/IR/TritonOps.td— addUnitAttr:$skip_boundary_checktoDescriptorLoadOpandDescriptorStoreOplib/Dialect/Triton/Transforms/RewriteTensorDescriptorToPointer.cpp— addisStaticallyInBounds()and conditionally skip mask/other generationpython/src/ir.cc— threadskipBoundaryCheckthroughcreate_descriptor_load/create_descriptor_storepython/triton/language/core.py— addskip_boundary_checkparameter totensor_descriptor_base.load()and.store()python/triton/language/semantic.py— thread parameter throughdescriptor_load/descriptor_storepython/triton/runtime/interpreter.py— accept (and ignore) the new parametertest/Triton/tensor-descriptors-in-bounds.mlir— 10 LIT test cases covering in-bounds, out-of-bounds, and skip_boundary_check scenariosTest Plan
tensor-descriptors-in-bounds.mlir) with 10 cases:skip_boundary_checkattribute on load/store with dynamic shapesskip_boundary_checkbehaves identically