-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[mlir][XeGPU] add WgToSg distribution pattern for load_matrix and store_matrix. #154403
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
fd09d12
refactor
chencha3 6fc6ec7
refactor createNdOp
chencha3 9af1f7f
fix typo
chencha3 93acad2
cleanup
chencha3 ce07282
rename isWgLayout to isForWorkgroup
chencha3 9ae490c
cleanup getNumSubgroups
chencha3 36e3e3d
update comments
chencha3 6d0458f
cleanup
chencha3 69ff3ca
fix format
chencha3 4f93bcb
rename genIndexAdd
chencha3 2fb9ac7
refactor
chencha3 af6f83f
refactor
chencha3 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -175,22 +175,31 @@ def XeGPU_FenceScopeAttr: | |
| let assemblyFormat = "$value"; | ||
| } | ||
|
|
||
| def LayoutTrait: AttrInterface<"LayoutTrait"> { | ||
| def DistributeLayoutAttrInterface: AttrInterface<"DistributeLayoutAttrInterface"> { | ||
| let cppNamespace = "::mlir::xegpu"; | ||
| let description = [{ | ||
| Common trait for all XeGPU layouts. | ||
| }]; | ||
|
|
||
| let methods = [ | ||
| InterfaceMethod<"Check the availability of workgroup level layouts", | ||
| "bool", | ||
| "isWgLayout">, | ||
| InterfaceMethod<"Get the rank of attribute", | ||
| "int64_t", | ||
| "getRank">, | ||
| InterfaceMethod<"Get the num of effective subgroups", | ||
| "int64_t", | ||
| "getNumSubgroups">, | ||
| InterfaceMethod<"Get the SgLayout field of the attribute as integer array", | ||
| "std::optional<SmallVector<int64_t>>", | ||
| "getSgLayoutAsInt">, | ||
| InterfaceMethod<"Get the SgData field of the attribute as integer array", | ||
| "std::optional<SmallVector<int64_t>>", | ||
| "getSgDataAsInt">, | ||
| InterfaceMethod<"Derive a new layout by dropping sgLayout and sgData", | ||
| "xegpu::DistributeLayoutAttrInterface", | ||
| "dropSgLayoutAndData">, | ||
| InterfaceMethod<[{Delinearizes a linear subgroup ID into its multidimensional | ||
| indices based on the effective subgroup layout.}], | ||
| "FailureOr<SmallVector<Value>>", | ||
|
|
@@ -206,7 +215,7 @@ def LayoutTrait: AttrInterface<"LayoutTrait"> { | |
| ]; | ||
| } | ||
|
|
||
| def XeGPU_LayoutAttr : XeGPUAttr<"Layout", "layout", [LayoutTrait]> { | ||
| def XeGPU_LayoutAttr : XeGPUAttr<"Layout", "layout", [DistributeLayoutAttrInterface]> { | ||
| let summary = [{ | ||
| Describes the data distribution to subgroups and work-items for a tensor | ||
| specified by the tensor descriptor. | ||
|
|
@@ -346,6 +355,13 @@ def XeGPU_LayoutAttr : XeGPUAttr<"Layout", "layout", [LayoutTrait]> { | |
| return 0; | ||
| } | ||
|
|
||
| int64_t getNumSubgroups() { | ||
| std::optional<SmallVector<int64_t>> sgLayout = getSgLayoutAsInt(); | ||
| if (sgLayout.has_value()) | ||
| return computeProduct(*sgLayout); | ||
| return 0; | ||
| } | ||
|
|
||
| LayoutAttr dropSgLayoutAndData() { | ||
| // avoid every field of the attribute is nullptr, which may lead to segment fault | ||
| if (!getInstData() && !getLaneLayout()) | ||
|
|
@@ -393,7 +409,7 @@ def XeGPU_LayoutAttr : XeGPUAttr<"Layout", "layout", [LayoutTrait]> { | |
| } | ||
|
|
||
|
|
||
| def XeGPU_SliceAttr : XeGPUAttr<"Slice", "slice", [LayoutTrait]> { | ||
| def XeGPU_SliceAttr : XeGPUAttr<"Slice", "slice", [DistributeLayoutAttrInterface]> { | ||
| let summary = [{Describes the data distribution and sharing among subgroups or work-items.}]; | ||
|
|
||
| let description = [{ | ||
|
|
@@ -420,7 +436,7 @@ def XeGPU_SliceAttr : XeGPUAttr<"Slice", "slice", [LayoutTrait]> { | |
| }]; | ||
|
|
||
| let parameters = (ins | ||
| "xegpu::LayoutTrait": $parent, | ||
| "xegpu::DistributeLayoutAttrInterface": $parent, | ||
| "DenseI64ArrayAttr": $dims | ||
| ); | ||
|
|
||
|
|
@@ -450,6 +466,13 @@ def XeGPU_SliceAttr : XeGPUAttr<"Slice", "slice", [LayoutTrait]> { | |
| return parent.isSgLayout(); | ||
| } | ||
|
|
||
| int64_t getNumSubgroups() { | ||
| std::optional<SmallVector<int64_t>> sgLayout = getSgLayoutAsInt(); | ||
| if (sgLayout.has_value()) | ||
| return computeProduct(*sgLayout); | ||
| return 0; | ||
|
||
| } | ||
|
|
||
| /// Returns the SgLayout of the attribute, computed by applying | ||
| /// the slice dimensions to the underlying LayoutAttr. | ||
| std::optional<SmallVector<int64_t>> getSgLayoutAsInt() const { | ||
|
|
@@ -474,6 +497,20 @@ def XeGPU_SliceAttr : XeGPUAttr<"Slice", "slice", [LayoutTrait]> { | |
| return std::nullopt; | ||
| } | ||
|
|
||
| SliceAttr dropSgLayoutAndData() { | ||
| SliceAttr attr = flatten(); | ||
| auto parent = dyn_cast<LayoutAttr>(attr.getParent()); | ||
| parent = parent.dropSgLayoutAndData(); | ||
| return SliceAttr::get(getContext(), parent, attr.getDims()); | ||
| } | ||
|
|
||
| SliceAttr dropInstData() { | ||
| SliceAttr attr = flatten(); | ||
| auto parent = dyn_cast<LayoutAttr>(attr.getParent()); | ||
| parent = parent.dropInstData(); | ||
| return SliceAttr::get(getContext(), parent, attr.getDims()); | ||
| } | ||
|
|
||
| /// flatten a nested SliceAttr, e.g., for 2-level nested SliceAttr | ||
| /// #xegpu.slice<#xegpu.slice<#xegpu.layout<sg_layout = [4, 8, 12]>, dims = [0]>, dims = [0]> | ||
| /// it will coalese two slice operations and return a simplified SliceAttr | ||
|
|
||
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
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should rename this to isSgLayout as its confusing...the layout specifies how the subgroups are laid out, there is nothing like WgLayout
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
renamed it to
isForWorkgroup. sounds good to you?