Skip to content

Commit 2ab14df

Browse files
authored
[mlir][python] fix python_test dialect and I32/I64ElementsBuilder (#70871)
This PR fixes the `I32ElementsAttr` and `I64ElementsAttr` builders and tests them through the `python_test` dialect.
1 parent 87f6717 commit 2ab14df

File tree

3 files changed

+14
-13
lines changed

3 files changed

+14
-13
lines changed

mlir/python/mlir/ir.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,15 +277,15 @@ def _f64ElementsAttr(x, context):
277277
def _i32ElementsAttr(x, context):
278278
return DenseElementsAttr.get(
279279
np.array(x, dtype=np.int32),
280-
type=IntegerType.get_signed(32, context=context),
280+
type=IntegerType.get_signless(32, context=context),
281281
context=context,
282282
)
283283

284284
@register_attribute_builder("I64ElementsAttr")
285285
def _i64ElementsAttr(x, context):
286286
return DenseElementsAttr.get(
287287
np.array(x, dtype=np.int64),
288-
type=IntegerType.get_signed(64, context=context),
288+
type=IntegerType.get_signless(64, context=context),
289289
context=context,
290290
)
291291

mlir/test/python/dialects/python_test.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ def run(f):
1717
@run
1818
def testAttributes():
1919
with Context() as ctx, Location.unknown():
20-
ctx.allow_unregistered_dialects = True
21-
20+
test.register_python_test_dialect(ctx)
2221
#
2322
# Check op construction with attributes.
2423
#
@@ -28,15 +27,15 @@ def testAttributes():
2827
two = IntegerAttr.get(i32, 2)
2928
unit = UnitAttr.get()
3029

31-
# CHECK: "python_test.attributed_op"() {
30+
# CHECK: python_test.attributed_op {
3231
# CHECK-DAG: mandatory_i32 = 1 : i32
3332
# CHECK-DAG: optional_i32 = 2 : i32
3433
# CHECK-DAG: unit
3534
# CHECK: }
3635
op = test.AttributedOp(one, optional_i32=two, unit=unit)
3736
print(f"{op}")
3837

39-
# CHECK: "python_test.attributed_op"() {
38+
# CHECK: python_test.attributed_op {
4039
# CHECK: mandatory_i32 = 2 : i32
4140
# CHECK: }
4241
op2 = test.AttributedOp(two)
@@ -48,21 +47,21 @@ def testAttributes():
4847

4948
assert "additional" not in op.attributes
5049

51-
# CHECK: "python_test.attributed_op"() {
50+
# CHECK: python_test.attributed_op {
5251
# CHECK-DAG: additional = 1 : i32
5352
# CHECK-DAG: mandatory_i32 = 2 : i32
5453
# CHECK: }
5554
op2.attributes["additional"] = one
5655
print(f"{op2}")
5756

58-
# CHECK: "python_test.attributed_op"() {
57+
# CHECK: python_test.attributed_op {
5958
# CHECK-DAG: additional = 2 : i32
6059
# CHECK-DAG: mandatory_i32 = 2 : i32
6160
# CHECK: }
6261
op2.attributes["additional"] = two
6362
print(f"{op2}")
6463

65-
# CHECK: "python_test.attributed_op"() {
64+
# CHECK: python_test.attributed_op {
6665
# CHECK-NOT: additional = 2 : i32
6766
# CHECK: mandatory_i32 = 2 : i32
6867
# CHECK: }
@@ -139,7 +138,7 @@ def testAttributes():
139138
@run
140139
def attrBuilder():
141140
with Context() as ctx, Location.unknown():
142-
ctx.allow_unregistered_dialects = True
141+
test.register_python_test_dialect(ctx)
143142
# CHECK: python_test.attributes_op
144143
op = test.AttributesOp(
145144
# CHECK-DAG: x_affinemap = affine_map<() -> (2)>
@@ -177,10 +176,10 @@ def attrBuilder():
177176
x_i16=42, # CHECK-DAG: x_i16 = 42 : i16
178177
x_i32=6, # CHECK-DAG: x_i32 = 6 : i32
179178
x_i32arr=[4, 5], # CHECK-DAG: x_i32arr = [4 : i32, 5 : i32]
180-
x_i32elems=[5, 6], # CHECK-DAG: x_i32elems = dense<[5, 6]> : tensor<2xsi32>
179+
x_i32elems=[5, 6], # CHECK-DAG: x_i32elems = dense<[5, 6]> : tensor<2xi32>
181180
x_i64=9, # CHECK-DAG: x_i64 = 9 : i64
182181
x_i64arr=[7, 8], # CHECK-DAG: x_i64arr = [7, 8]
183-
x_i64elems=[8, 9], # CHECK-DAG: x_i64elems = dense<[8, 9]> : tensor<2xsi64>
182+
x_i64elems=[8, 9], # CHECK-DAG: x_i64elems = dense<[8, 9]> : tensor<2xi64>
184183
x_i64svecarr=[10, 11], # CHECK-DAG: x_i64svecarr = [10, 11]
185184
x_i8=11, # CHECK-DAG: x_i8 = 11 : i8
186185
x_idx=10, # CHECK-DAG: x_idx = 10 : index

mlir/test/python/python_test_ops.td

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ class TestAttr<string name, string attrMnemonic>
3232
}
3333

3434
class TestOp<string mnemonic, list<Trait> traits = []>
35-
: Op<Python_Test_Dialect, mnemonic, traits>;
35+
: Op<Python_Test_Dialect, mnemonic, traits> {
36+
let assemblyFormat = "operands attr-dict functional-type(operands, results)";
37+
}
3638

3739
//===----------------------------------------------------------------------===//
3840
// Type definitions.

0 commit comments

Comments
 (0)