[Backend] Refactor OptimizeDescriptorEncoding to common path#9709
Conversation
|
We are working on improving our handling of tensors descriptors. It is split into two parts:
cc: @antiagainst |
|
What part of the logic will be different for AMD? The logic in this pass seems fairly generic except for the part about |
Our current implementation requires these four functions
|
323776d to
c63d6db
Compare
c63d6db to
ca53687
Compare
|
I have updated this PR. We now require only two callbacks:
Rest of the infrastructure is common.
|
| assignMemoryLayouts(m); | ||
|
|
||
| // Fallback shared encoding callback | ||
| auto buildFallbackSharedEncoding = |
There was a problem hiding this comment.
Rather than using lambda, maybe just create it as a free function like isTMACompatibleEncoding to be symmetric.
| ctx, swizEnc.getVec(), swizEnc.getPerPhase(), swizEnc.getMaxPhase(), | ||
| order, newCgaEnc); | ||
| } | ||
| if (auto paddedEnc = dyn_cast<ttg::PaddedSharedEncodingAttr>(encoding)) { |
There was a problem hiding this comment.
I guess we can remove this part and add it later together with the AMD logic.
| /// Utility class to assign memory layouts to tensor descriptors in a module. | ||
| class AssignDescriptorMemoryLayouts { | ||
| public: | ||
| AssignDescriptorMemoryLayouts() = default; |
There was a problem hiding this comment.
Is this constructor needed?
|
@antiagainst Thank you, PR updated with suggested revisions |
ThomasRaoux
left a comment
There was a problem hiding this comment.
makes sense but I still think it should be refactored a little bit hopefully my comments make sense to you
| struct DescriptorAnalysisCallbacks { | ||
| /// Callback to check for compatible shared encoding | ||
| llvm::function_ref<bool(Attribute)> isCompatibleSharedEncoding; | ||
|
|
||
| /// create a fallback encoding given the shape, order, cga layout and | ||
| /// element type | ||
| llvm::function_ref<Attribute(mlir::MLIRContext *, ArrayRef<int64_t>, | ||
| ArrayRef<unsigned>, CGAEncodingAttr, Type)> | ||
| buildFallbackSharedEncoding; | ||
| }; |
There was a problem hiding this comment.
a struct with a bunch of callbacks seems like a convoluted way to make virtual functions. How about we make those virtual functions in AssignDescriptorMemoryLayouts or DescriptorAnalysisCallbacks?
| #include "llvm/ADT/PriorityWorklist.h" | ||
| #include <unordered_set> | ||
|
|
||
| namespace ttg = mlir::triton::gpu; |
There was a problem hiding this comment.
overall the idea to separate things out make sense but on the style I think calling this file Utils is misleading. At this point this is really the whole implementation of the pass rather than a set of generic utils functions.
My suggestion is make a generic class with some overloaded functions and inherit those in a target specific way.
I know the result is very similar but I think mixing up passes and utils is going to be confusing.
There was a problem hiding this comment.
Thank you for the feedback. Agreed, I have renamed the file.
I have a new revision which addresses the following:
- A base class
AssignDescriptorMemoryLayoutsnow implements the core logic for layout assignment and provides virtual methods for backend overloads. Moved the core logic functions to the class. - Renamed from
DescriptorUtilstoDescriptorMemoryLayouts
| #include <unordered_set> | ||
|
|
||
| namespace mlir::triton::gpu { | ||
| // Forward declarations |
There was a problem hiding this comment.
nit: meaningless comment
- Move common utilties of this to DescriptorUtils - Provide functors to customize backend specific decisions
- Introduce only two callbacks - Callback for building backend fallback layout - Callback for checking backend compatible encoding - Move updateEncodingForShape to common place - Adapt updateEncodingForShape to handle padded layout
- Fix comment
92ff3a7 to
e028faf
Compare
…lang#9709) A base class `AssignDescriptorMemoryLayouts` now implements the core logic for layout assignment and provides virtual methods for backend overloads. Moved the core logic functions to the class.
…lang#9709) A base class `AssignDescriptorMemoryLayouts` now implements the core logic for layout assignment and provides virtual methods for backend overloads. Moved the core logic functions to the class.
…lang#9709) A base class `AssignDescriptorMemoryLayouts` now implements the core logic for layout assignment and provides virtual methods for backend overloads. Moved the core logic functions to the class.
New contributor declaration
I am not making a trivial change, such as fixing a typo in a comment.
I have written a PR description following these
rules.
I have run
pre-commit run --from-ref origin/main --to-ref HEAD.Select one of the following.
/testforlittests/unittestfor C++ tests/python/testfor end-to-end testsSelect one of the following.
littests.littests I have added follow these best practices,including the "tests should be minimal" section. (Usually running Python code
and using the instructions it generates is not minimal.)