-
Notifications
You must be signed in to change notification settings - Fork 14.9k
[mlir][XeGPU] Update utils for LayoutAttr and SliceAttr support #154819
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
Changes from 5 commits
ad5d0a8
0e34f36
a84014f
f3af2c3
35c6489
c49546a
a723f21
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -185,6 +185,9 @@ def DistributeLayoutAttr: AttrInterface<"DistributeLayoutAttr"> { | |
InterfaceMethod<"Check the availability of workgroup level layouts", | ||
"bool", | ||
"isForWorkgroup">, | ||
InterfaceMethod<"Check the availability of subgroup level layouts", | ||
"bool", | ||
"isForSubgroup">, | ||
InterfaceMethod<"Get the rank of attribute", | ||
"int64_t", | ||
"getRank">, | ||
|
@@ -202,9 +205,21 @@ def DistributeLayoutAttr: AttrInterface<"DistributeLayoutAttr"> { | |
InterfaceMethod<"Get the SgData field of the attribute as integer array", | ||
"std::optional<SmallVector<int64_t>>", | ||
"getSgDataAsInt">, | ||
InterfaceMethod<"Get the InstData field of the attribute as integer array", | ||
"std::optional<SmallVector<int64_t>>", | ||
"getInstDataAsInt">, | ||
InterfaceMethod<"Get the LaneLayout field of the attribute as integer array", | ||
"std::optional<SmallVector<int64_t>>", | ||
"getLaneLayoutAsInt">, | ||
InterfaceMethod<"Get the LaneData field of the attribute as integer array", | ||
"std::optional<SmallVector<int64_t>>", | ||
"getLaneDataAsInt">, | ||
InterfaceMethod<"Derive a new layout by dropping sgLayout and sgData", | ||
"xegpu::DistributeLayoutAttr", | ||
"dropSgLayoutAndData">, | ||
InterfaceMethod<"Derive a new layout by dropping InstData", | ||
"xegpu::DistributeLayoutAttr", | ||
"dropInstData">, | ||
InterfaceMethod<[{Delinearizes a linear subgroup ID into its multidimensional | ||
indices based on the effective subgroup layout.}], | ||
"FailureOr<SmallVector<Value>>", | ||
|
@@ -388,6 +403,24 @@ def XeGPU_LayoutAttr : XeGPUAttr<"Layout", "layout", [DistributeLayoutAttr]> { | |
return std::nullopt; | ||
} | ||
|
||
std::optional<SmallVector<int64_t>> getInstDataAsInt() const { | ||
|
||
if (DenseI32ArrayAttr inst = getInstData()) | ||
return llvm::to_vector_of<int64_t>(inst.asArrayRef()); | ||
return std::nullopt; | ||
} | ||
|
||
std::optional<SmallVector<int64_t>> getLaneLayoutAsInt() const { | ||
if (DenseI32ArrayAttr layout = getLaneLayout()) | ||
return llvm::to_vector_of<int64_t>(layout.asArrayRef()); | ||
return std::nullopt; | ||
} | ||
|
||
std::optional<SmallVector<int64_t>> getLaneDataAsInt() const { | ||
if (DenseI32ArrayAttr data = getLaneData()) | ||
return llvm::to_vector_of<int64_t>(data.asArrayRef()); | ||
return std::nullopt; | ||
} | ||
|
||
/// Delinearizes a linear subgroup ID into its multidimensional indices | ||
/// based on the effective subgroup layout. | ||
FailureOr<SmallVector<Value>> | ||
|
@@ -488,6 +521,42 @@ def XeGPU_SliceAttr : XeGPUAttr<"Slice", "slice", [DistributeLayoutAttr]> { | |
return std::nullopt; | ||
} | ||
|
||
/// Returns the InstData of the attribute, computed by applying | ||
/// the slice dimensions to the underlying LayoutAttr. | ||
std::optional<SmallVector<int64_t>> getInstDataAsInt() const { | ||
SliceAttr attr = flatten(); | ||
auto parent = dyn_cast<LayoutAttr>(attr.getParent()); | ||
if (auto inst = parent.getInstDataAsInt()) { | ||
ArrayRef<int64_t> dims = attr.getDims().asArrayRef(); | ||
return XeGPUDialect::slice(llvm::ArrayRef<int64_t>(*inst), dims); | ||
} | ||
return std::nullopt; | ||
} | ||
|
||
/// Returns the LaneLayout of the attribute, computed by applying | ||
/// the slice dimensions to the underlying LayoutAttr. | ||
std::optional<SmallVector<int64_t>> getLaneLayoutAsInt() const { | ||
SliceAttr attr = flatten(); | ||
auto parent = dyn_cast<LayoutAttr>(attr.getParent()); | ||
if (auto layout = parent.getLaneLayoutAsInt()) { | ||
ArrayRef<int64_t> dims = attr.getDims().asArrayRef(); | ||
return XeGPUDialect::slice(llvm::ArrayRef<int64_t>(*layout), dims); | ||
} | ||
return std::nullopt; | ||
} | ||
|
||
/// Returns the LaneData of the attribute, computed by applying | ||
/// the slice dimensions to the underlying LayoutAttr. | ||
std::optional<SmallVector<int64_t>> getLaneDataAsInt() const { | ||
SliceAttr attr = flatten(); | ||
auto parent = dyn_cast<LayoutAttr>(attr.getParent()); | ||
if (auto data = parent.getLaneDataAsInt()) { | ||
ArrayRef<int64_t> dims = attr.getDims().asArrayRef(); | ||
return XeGPUDialect::slice(llvm::ArrayRef<int64_t>(*data), dims); | ||
} | ||
return std::nullopt; | ||
} | ||
|
||
SliceAttr dropSgLayoutAndData() { | ||
SliceAttr attr = flatten(); | ||
auto parent = dyn_cast<LayoutAttr>(attr.getParent()); | ||
|
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.
nit:
hasSgLayouts
express the intenstion better.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.
fixed.
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.
I rolled back the naming after thinking it twice. I don't want to mess up it with sgLayout field.