-
Notifications
You must be signed in to change notification settings - Fork 15k
[WIP][MLIR] Use IntValidAlignment for alignment attributes #158137
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
base: main
Are you sure you want to change the base?
Conversation
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
@llvm/pr-subscribers-mlir @llvm/pr-subscribers-mlir-memref Author: None (jiang1997) ChangesThis PR is still a work in progress, thanks for your patience! Full diff: https://github.com/llvm/llvm-project/pull/158137.diff 3 Files Affected:
diff --git a/mlir/include/mlir/Dialect/MemRef/IR/MemRefOps.td b/mlir/include/mlir/Dialect/MemRef/IR/MemRefOps.td
index 513a9a18198a3..671cc05e963b4 100644
--- a/mlir/include/mlir/Dialect/MemRef/IR/MemRefOps.td
+++ b/mlir/include/mlir/Dialect/MemRef/IR/MemRefOps.td
@@ -1163,7 +1163,7 @@ def MemRef_GlobalOp : MemRef_Op<"global", [Symbol]> {
MemRefTypeAttr:$type,
OptionalAttr<AnyAttr>:$initial_value,
UnitAttr:$constant,
- OptionalAttr<I64Attr>:$alignment);
+ OptionalAttr<IntValidAlignment<I64Attr>>:$alignment);
let assemblyFormat = [{
($sym_visibility^)?
@@ -1231,8 +1231,7 @@ def LoadOp : MemRef_Op<"load",
[MemRead]>:$memref,
Variadic<Index>:$indices,
DefaultValuedOptionalAttr<BoolAttr, "false">:$nontemporal,
- ConfinedAttr<OptionalAttr<I64Attr>,
- [AllAttrOf<[IntPositive, IntPowerOf2]>]>:$alignment);
+ OptionalAttr<IntValidAlignment<I64Attr>>:$alignment);
let builders = [
OpBuilder<(ins "Value":$memref,
@@ -1965,8 +1964,7 @@ def MemRef_StoreOp : MemRef_Op<"store",
[MemWrite]>:$memref,
Variadic<Index>:$indices,
DefaultValuedOptionalAttr<BoolAttr, "false">:$nontemporal,
- ConfinedAttr<OptionalAttr<I64Attr>,
- [AllAttrOf<[IntPositive, IntPowerOf2]>]>:$alignment);
+ OptionalAttr<IntValidAlignment<I64Attr>>:$alignment);
let builders = [
OpBuilder<(ins "Value":$valueToStore,
diff --git a/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVCooperativeMatrixOps.td b/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVCooperativeMatrixOps.td
index fd75532ae3d70..827ac901d22de 100644
--- a/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVCooperativeMatrixOps.td
+++ b/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVCooperativeMatrixOps.td
@@ -129,7 +129,7 @@ def SPIRV_KHRCooperativeMatrixLoadOp : SPIRV_KhrVendorOp<"CooperativeMatrixLoad"
SPIRV_KHR_CooperativeMatrixLayoutAttr:$matrix_layout,
SPIRV_Integer:$stride,
OptionalAttr<SPIRV_MemoryAccessAttr>:$memory_operand,
- OptionalAttr<I32Attr>:$alignment
+ OptionalAttr<IntValidAlignment<I32Attr>>:$alignment
);
let results = (outs
@@ -214,7 +214,7 @@ def SPIRV_KHRCooperativeMatrixStoreOp : SPIRV_KhrVendorOp<"CooperativeMatrixStor
SPIRV_KHR_CooperativeMatrixLayoutAttr:$matrix_layout,
SPIRV_Integer:$stride,
OptionalAttr<SPIRV_MemoryAccessAttr>:$memory_operand,
- OptionalAttr<I32Attr>:$alignment
+ OptionalAttr<IntValidAlignment<I32Attr>>:$alignment
);
let results = (outs);
diff --git a/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVMemoryOps.td b/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVMemoryOps.td
index 6253601a7c2b2..6108decdb9706 100644
--- a/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVMemoryOps.td
+++ b/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVMemoryOps.td
@@ -121,9 +121,9 @@ def SPIRV_CopyMemoryOp : SPIRV_Op<"CopyMemory", []> {
SPIRV_AnyPtr:$target,
SPIRV_AnyPtr:$source,
OptionalAttr<SPIRV_MemoryAccessAttr>:$memory_access,
- OptionalAttr<I32Attr>:$alignment,
+ OptionalAttr<IntValidAlignment<I32Attr>>:$alignment,
OptionalAttr<SPIRV_MemoryAccessAttr>:$source_memory_access,
- OptionalAttr<I32Attr>:$source_alignment
+ OptionalAttr<IntValidAlignment<I32Attr>>:$source_alignment
);
let results = (outs);
|
@llvm/pr-subscribers-mlir-spirv Author: None (jiang1997) ChangesThis PR is still a work in progress, thanks for your patience! Full diff: https://github.com/llvm/llvm-project/pull/158137.diff 3 Files Affected:
diff --git a/mlir/include/mlir/Dialect/MemRef/IR/MemRefOps.td b/mlir/include/mlir/Dialect/MemRef/IR/MemRefOps.td
index 513a9a18198a3..671cc05e963b4 100644
--- a/mlir/include/mlir/Dialect/MemRef/IR/MemRefOps.td
+++ b/mlir/include/mlir/Dialect/MemRef/IR/MemRefOps.td
@@ -1163,7 +1163,7 @@ def MemRef_GlobalOp : MemRef_Op<"global", [Symbol]> {
MemRefTypeAttr:$type,
OptionalAttr<AnyAttr>:$initial_value,
UnitAttr:$constant,
- OptionalAttr<I64Attr>:$alignment);
+ OptionalAttr<IntValidAlignment<I64Attr>>:$alignment);
let assemblyFormat = [{
($sym_visibility^)?
@@ -1231,8 +1231,7 @@ def LoadOp : MemRef_Op<"load",
[MemRead]>:$memref,
Variadic<Index>:$indices,
DefaultValuedOptionalAttr<BoolAttr, "false">:$nontemporal,
- ConfinedAttr<OptionalAttr<I64Attr>,
- [AllAttrOf<[IntPositive, IntPowerOf2]>]>:$alignment);
+ OptionalAttr<IntValidAlignment<I64Attr>>:$alignment);
let builders = [
OpBuilder<(ins "Value":$memref,
@@ -1965,8 +1964,7 @@ def MemRef_StoreOp : MemRef_Op<"store",
[MemWrite]>:$memref,
Variadic<Index>:$indices,
DefaultValuedOptionalAttr<BoolAttr, "false">:$nontemporal,
- ConfinedAttr<OptionalAttr<I64Attr>,
- [AllAttrOf<[IntPositive, IntPowerOf2]>]>:$alignment);
+ OptionalAttr<IntValidAlignment<I64Attr>>:$alignment);
let builders = [
OpBuilder<(ins "Value":$valueToStore,
diff --git a/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVCooperativeMatrixOps.td b/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVCooperativeMatrixOps.td
index fd75532ae3d70..827ac901d22de 100644
--- a/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVCooperativeMatrixOps.td
+++ b/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVCooperativeMatrixOps.td
@@ -129,7 +129,7 @@ def SPIRV_KHRCooperativeMatrixLoadOp : SPIRV_KhrVendorOp<"CooperativeMatrixLoad"
SPIRV_KHR_CooperativeMatrixLayoutAttr:$matrix_layout,
SPIRV_Integer:$stride,
OptionalAttr<SPIRV_MemoryAccessAttr>:$memory_operand,
- OptionalAttr<I32Attr>:$alignment
+ OptionalAttr<IntValidAlignment<I32Attr>>:$alignment
);
let results = (outs
@@ -214,7 +214,7 @@ def SPIRV_KHRCooperativeMatrixStoreOp : SPIRV_KhrVendorOp<"CooperativeMatrixStor
SPIRV_KHR_CooperativeMatrixLayoutAttr:$matrix_layout,
SPIRV_Integer:$stride,
OptionalAttr<SPIRV_MemoryAccessAttr>:$memory_operand,
- OptionalAttr<I32Attr>:$alignment
+ OptionalAttr<IntValidAlignment<I32Attr>>:$alignment
);
let results = (outs);
diff --git a/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVMemoryOps.td b/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVMemoryOps.td
index 6253601a7c2b2..6108decdb9706 100644
--- a/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVMemoryOps.td
+++ b/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVMemoryOps.td
@@ -121,9 +121,9 @@ def SPIRV_CopyMemoryOp : SPIRV_Op<"CopyMemory", []> {
SPIRV_AnyPtr:$target,
SPIRV_AnyPtr:$source,
OptionalAttr<SPIRV_MemoryAccessAttr>:$memory_access,
- OptionalAttr<I32Attr>:$alignment,
+ OptionalAttr<IntValidAlignment<I32Attr>>:$alignment,
OptionalAttr<SPIRV_MemoryAccessAttr>:$source_memory_access,
- OptionalAttr<I32Attr>:$source_alignment
+ OptionalAttr<IntValidAlignment<I32Attr>>:$source_alignment
);
let results = (outs);
|
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.
Hello @jiang1997, thank you for contributing!
I will do a more thorough review a little bit later today (although it already looks quite good). I've noticed that the CI has detected some errors. You can also run locally and these errors should be detected locally as well. (Let me know if you need help running tests locally).
At least the first error reported in the CI comes from the file located in the following path llvm-project/llvm-project/mlir/test/Dialect/MemRef/invalid.mlir
Here is the full error log:
# .---command stderr------------
# | /home/gha/actions-runner/_work/llvm-project/llvm-project/mlir/test/Dialect/MemRef/invalid.mlir:384:58: error: unexpected error: custom op 'memref.global' 'memref.global' op attribute 'alignment' failed to satisfy constraint: 64-bit signless integer attribute whose value is positive and whose value is a power of two > 0
# | memref.global "private" @gv : memref<4xf32> = dense<1.0> { alignment = 63 }
# | ^
# | /home/gha/actions-runner/_work/llvm-project/llvm-project/mlir/test/Dialect/MemRef/invalid.mlir:383:4: error: expected error "alignment attribute value 63 is not a power of 2" was not produced
# | // expected-error @+1 {{alignment attribute value 63 is not a power of 2}}
# | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# `-----------------------------
# error: command failed with exit status: 1
At least for this case (and possibly others) the memref.global
operation has a custom verification. This custom verification can be found on file mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp
. The test case above was expecting this custom verification's error message, but once you change the alignment property to be constrained by the new attribute, the verification message has changed.
What you can do in this case is change the test case to match the new error message and remove the couple lines of code that correspond to the verification of the alignment attribute inside LogicalResult GlobalOp::verify
. Specifically, these ones:
if (std::optional<uint64_t> alignAttr = getAlignment()) {
uint64_t alignment = *alignAttr;
if (!llvm::isPowerOf2_64(alignment))
return emitError() << "alignment attribute value " << alignment
<< " is not a power of 2";
}
As I mentioned earlier, I'll try to do a more thorough review later today, this is just of the first error here. Thanks for contributing!
@amd-eochoalo When I change line 1166 from llvm-project/mlir/include/mlir/Dialect/MemRef/IR/MemRefOps.td Lines 1161 to 1166 in 0c3cf20
So the check in MemRefOps.cpp becomes redundant. llvm-project/mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp Lines 1555 to 1558 in 0c3cf20
In summary, I should probably update the expected error message in invalid.mlir (as done here) and remove the redundant check in MemRefOps.cpp if necessary. |
This PR is still a work in progress, thanks for your patience!
#155677