Skip to content

[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
merged 1 commit into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions mlir/python/mlir/ir.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,15 +277,15 @@ 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,
)

@register_attribute_builder("I64ElementsAttr")
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,
)

Expand Down
19 changes: 9 additions & 10 deletions mlir/test/python/dialects/python_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
#
Expand All @@ -28,15 +27,15 @@ 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
# CHECK: }
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)
Expand All @@ -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: }
Expand Down Expand Up @@ -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)>
Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion mlir/test/python/python_test_ops.td
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down