-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[mlir][python] fix python_test dialect and I32/I64ElementsBuilder #70871
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
Conversation
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
@llvm/pr-subscribers-mlir Author: Maksim Levental (makslevental) ChangesThis PR fixes the Full diff: https://github.com/llvm/llvm-project/pull/70871.diff 3 Files Affected:
diff --git a/mlir/python/mlir/ir.py b/mlir/python/mlir/ir.py
index 43553f3118a51fc..cf4228c2a63a91b 100644
--- a/mlir/python/mlir/ir.py
+++ b/mlir/python/mlir/ir.py
@@ -277,7 +277,7 @@ def _f64ElementsAttr(x, context):
def _i32ElementsAttr(x, context):
return DenseElementsAttr.get(
np.array(x, dtype=np.int32),
- type=IntegerType.get_signed(32, context=context),
+ type=IntegerType.get_signless(32, context=context),
context=context,
)
@@ -285,7 +285,7 @@ def _i32ElementsAttr(x, context):
def _i64ElementsAttr(x, context):
return DenseElementsAttr.get(
np.array(x, dtype=np.int64),
- type=IntegerType.get_signed(64, context=context),
+ type=IntegerType.get_signless(64, context=context),
context=context,
)
diff --git a/mlir/test/python/dialects/python_test.py b/mlir/test/python/dialects/python_test.py
index 3d4cd087fbfed8f..472db7e5124dbed 100644
--- a/mlir/test/python/dialects/python_test.py
+++ b/mlir/test/python/dialects/python_test.py
@@ -17,8 +17,7 @@ def run(f):
@run
def testAttributes():
with Context() as ctx, Location.unknown():
- ctx.allow_unregistered_dialects = True
-
+ test.register_python_test_dialect(ctx)
#
# Check op construction with attributes.
#
@@ -28,7 +27,7 @@ def testAttributes():
two = IntegerAttr.get(i32, 2)
unit = UnitAttr.get()
- # CHECK: "python_test.attributed_op"() {
+ # CHECK: python_test.attributed_op {
# CHECK-DAG: mandatory_i32 = 1 : i32
# CHECK-DAG: optional_i32 = 2 : i32
# CHECK-DAG: unit
@@ -36,7 +35,7 @@ def testAttributes():
op = test.AttributedOp(one, optional_i32=two, unit=unit)
print(f"{op}")
- # CHECK: "python_test.attributed_op"() {
+ # CHECK: python_test.attributed_op {
# CHECK: mandatory_i32 = 2 : i32
# CHECK: }
op2 = test.AttributedOp(two)
@@ -48,21 +47,21 @@ def testAttributes():
assert "additional" not in op.attributes
- # CHECK: "python_test.attributed_op"() {
+ # CHECK: python_test.attributed_op {
# CHECK-DAG: additional = 1 : i32
# CHECK-DAG: mandatory_i32 = 2 : i32
# CHECK: }
op2.attributes["additional"] = one
print(f"{op2}")
- # CHECK: "python_test.attributed_op"() {
+ # CHECK: python_test.attributed_op {
# CHECK-DAG: additional = 2 : i32
# CHECK-DAG: mandatory_i32 = 2 : i32
# CHECK: }
op2.attributes["additional"] = two
print(f"{op2}")
- # CHECK: "python_test.attributed_op"() {
+ # CHECK: python_test.attributed_op {
# CHECK-NOT: additional = 2 : i32
# CHECK: mandatory_i32 = 2 : i32
# CHECK: }
@@ -139,7 +138,7 @@ def testAttributes():
@run
def attrBuilder():
with Context() as ctx, Location.unknown():
- ctx.allow_unregistered_dialects = True
+ test.register_python_test_dialect(ctx)
# CHECK: python_test.attributes_op
op = test.AttributesOp(
# CHECK-DAG: x_affinemap = affine_map<() -> (2)>
@@ -177,10 +176,10 @@ def attrBuilder():
x_i16=42, # CHECK-DAG: x_i16 = 42 : i16
x_i32=6, # CHECK-DAG: x_i32 = 6 : i32
x_i32arr=[4, 5], # CHECK-DAG: x_i32arr = [4 : i32, 5 : i32]
- x_i32elems=[5, 6], # CHECK-DAG: x_i32elems = dense<[5, 6]> : tensor<2xsi32>
+ x_i32elems=[5, 6], # CHECK-DAG: x_i32elems = dense<[5, 6]> : tensor<2xi32>
x_i64=9, # CHECK-DAG: x_i64 = 9 : i64
x_i64arr=[7, 8], # CHECK-DAG: x_i64arr = [7, 8]
- x_i64elems=[8, 9], # CHECK-DAG: x_i64elems = dense<[8, 9]> : tensor<2xsi64>
+ x_i64elems=[8, 9], # CHECK-DAG: x_i64elems = dense<[8, 9]> : tensor<2xi64>
x_i64svecarr=[10, 11], # CHECK-DAG: x_i64svecarr = [10, 11]
x_i8=11, # CHECK-DAG: x_i8 = 11 : i8
x_idx=10, # CHECK-DAG: x_idx = 10 : index
diff --git a/mlir/test/python/python_test_ops.td b/mlir/test/python/python_test_ops.td
index d79714301ae951e..95301985e3fde03 100644
--- a/mlir/test/python/python_test_ops.td
+++ b/mlir/test/python/python_test_ops.td
@@ -32,7 +32,9 @@ class TestAttr<string name, string attrMnemonic>
}
class TestOp<string mnemonic, list<Trait> traits = []>
- : Op<Python_Test_Dialect, mnemonic, traits>;
+ : Op<Python_Test_Dialect, mnemonic, traits> {
+ let assemblyFormat = "operands attr-dict functional-type(operands, results)";
+}
//===----------------------------------------------------------------------===//
// Type definitions.
|
rkayaith
approved these changes
Oct 31, 2023
Good catch, thanks! |
Guzhu-AMD
pushed a commit
to GPUOpen-Drivers/llvm-project
that referenced
this pull request
Nov 2, 2023
Local branch amd-gfx 1c0d172 Merged main:157ba33007fe into amd-gfx:f5e3081cf03f Remote branch main 2ab14df [mlir][python] fix python_test dialect and I32/I64ElementsBuilder (llvm#70871)
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.
This PR fixes the
I32ElementsAttr
andI64ElementsAttr
builders and tests them through thepython_test
dialect.