Skip to content

Commit

Permalink
dialects: (tosa) turn attributes into properties (#3188)
Browse files Browse the repository at this point in the history
The attributes are actually properties in tosa.
I got fooled by the `ParsePropInAttrDict` ☹️
  • Loading branch information
jorendumoulin authored Sep 19, 2024
1 parent 8b0ec7a commit c0713ea
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 16 deletions.
6 changes: 3 additions & 3 deletions tests/filecheck/dialects/tosa/ops.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
%2 = tosa.rescale %0 {double_round = false, input_zp = 127 : i32, multiplier = array<i32: 1073741824>, output_zp = -1 : i32, per_channel = false, scale32 = true, shift = array<i32: 30>} : (tensor<12x34xi32>) -> tensor<12x34xi32>


// CHECK: module {
// CHECK: builtin.module {
// CHECK-NEXT: %0 = "test.op"() : () -> tensor<12x34xi32>
// CHECK-NEXT: %1 = tosa.clamp %0 {"max_fp" = 1.000000e+00 : f32, "max_int" = 1 : i64, "min_fp" = 0.000000e+00 : f32, "min_int" = 0 : i64} : (tensor<12x34xi32>) -> tensor<12x34xi32>
// CHECK-NEXT: %2 = tosa.rescale %0 {"double_round" = false, "input_zp" = 127 : i32, "multiplier" = array<i32: 1073741824>, "output_zp" = -1 : i32, "per_channel" = false, "scale32" = true, "shift" = array<i32: 30>} : (tensor<12x34xi32>) -> tensor<12x34xi32>
// CHECK-NEXT: %1 = tosa.clamp %0 {"min_int" = 0 : i64, "max_int" = 1 : i64, "min_fp" = 0.000000e+00 : f32, "max_fp" = 1.000000e+00 : f32} : (tensor<12x34xi32>) -> tensor<12x34xi32>
// CHECK-NEXT: %2 = tosa.rescale %0 {"input_zp" = 127 : i32, "output_zp" = -1 : i32, "multiplier" = array<i32: 1073741824>, "shift" = array<i32: 30>, "scale32" = true, "double_round" = false, "per_channel" = false} : (tensor<12x34xi32>) -> tensor<12x34xi32>
// CHECK-NEXT: }
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: xdsl-opt %s | xdsl-opt | mlir-opt | filecheck %s
// RUN: xdsl-opt %s | xdsl-opt --print-op-generic | mlir-opt --mlir-print-op-generic | xdsl-opt | mlir-opt | filecheck %s

%0 = "test.op"() : () -> tensor<12x34xi32>
%1 = tosa.clamp %0 {min_fp = 0.0 : f32, max_fp = 1.0: f32, min_int = 0 : i64, max_int = 1 : i64} : (tensor<12x34xi32>) -> tensor<12x34xi32>
Expand Down
29 changes: 17 additions & 12 deletions xdsl/dialects/tosa.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
from xdsl.ir import Dialect
from xdsl.irdl import (
IRDLOperation,
attr_def,
ParsePropInAttrDict,
irdl_op_definition,
operand_def,
prop_def,
result_def,
)

Expand All @@ -26,15 +27,17 @@ class ClampOp(IRDLOperation):

name = "tosa.clamp"

min_int = attr_def(IntegerAttr[I64])
max_int = attr_def(IntegerAttr[I64])
min_int = prop_def(IntegerAttr[I64])
max_int = prop_def(IntegerAttr[I64])

min_fp = attr_def(FloatAttr[AnyFloat])
max_fp = attr_def(FloatAttr[AnyFloat])
min_fp = prop_def(FloatAttr[AnyFloat])
max_fp = prop_def(FloatAttr[AnyFloat])

input = operand_def(TensorType)
output = result_def(TensorType)

irdl_options = [ParsePropInAttrDict()]

assembly_format = "$input attr-dict `:` `(` type($input) `)` `->` type($output)"


Expand All @@ -46,17 +49,19 @@ class RescaleOp(IRDLOperation):

name = "tosa.rescale"

input_zp = attr_def(IntegerAttr[I32])
output_zp = attr_def(IntegerAttr[I32])
multiplier = attr_def(DenseArrayBase)
shift = attr_def(DenseArrayBase)
scale32 = attr_def(BoolAttr)
double_round = attr_def(BoolAttr)
per_channel = attr_def(BoolAttr)
input_zp = prop_def(IntegerAttr[I32])
output_zp = prop_def(IntegerAttr[I32])
multiplier = prop_def(DenseArrayBase)
shift = prop_def(DenseArrayBase)
scale32 = prop_def(BoolAttr)
double_round = prop_def(BoolAttr)
per_channel = prop_def(BoolAttr)

input = operand_def(TensorType)
output = result_def(TensorType)

irdl_options = [ParsePropInAttrDict()]

assembly_format = "$input attr-dict `:` `(` type($input) `)` `->` type($output)"


Expand Down

0 comments on commit c0713ea

Please sign in to comment.