diff options
| author | Sana Damani <sdamani@gatech.edu> | 2019-10-16 12:08:55 -0700 |
|---|---|---|
| committer | A. Unique TensorFlower <gardener@tensorflow.org> | 2019-10-16 12:19:39 -0700 |
| commit | 3940b90d84d7239f2bc849068df97f1d248554fe (patch) | |
| tree | fdd5fb940df322d6cd358b552ebf7c3d84d72339 /mlir/test/Examples/Toy | |
| parent | e88dbc8c955a9c17d5ef444c716633752ced338c (diff) | |
| download | bcm5719-llvm-3940b90d84d7239f2bc849068df97f1d248554fe.tar.gz bcm5719-llvm-3940b90d84d7239f2bc849068df97f1d248554fe.zip | |
Update Chapter 4 of the Toy tutorial
This Chapter now introduces and makes use of the Interface concept
in MLIR to demonstrate ShapeInference.
END_PUBLIC
Closes tensorflow/mlir#191
PiperOrigin-RevId: 275085151
Diffstat (limited to 'mlir/test/Examples/Toy')
| -rw-r--r-- | mlir/test/Examples/Toy/Ch4/ast.toy | 2 | ||||
| -rw-r--r-- | mlir/test/Examples/Toy/Ch4/codegen.toy | 31 | ||||
| -rw-r--r-- | mlir/test/Examples/Toy/Ch4/invalid.mlir | 6 | ||||
| -rw-r--r-- | mlir/test/Examples/Toy/Ch4/scalar.toy | 6 | ||||
| -rw-r--r-- | mlir/test/Examples/Toy/Ch4/transpose_transpose.toy | 19 | ||||
| -rw-r--r-- | mlir/test/Examples/Toy/Ch4/trivialReshape.toy | 24 |
6 files changed, 21 insertions, 67 deletions
diff --git a/mlir/test/Examples/Toy/Ch4/ast.toy b/mlir/test/Examples/Toy/Ch4/ast.toy index a0897c0ba0c..9576c9c5ced 100644 --- a/mlir/test/Examples/Toy/Ch4/ast.toy +++ b/mlir/test/Examples/Toy/Ch4/ast.toy @@ -10,7 +10,7 @@ def main() { # Define a variable `a` with shape <2, 3>, initialized with the literal value. # The shape is inferred from the supplied literal. var a = [[1, 2, 3], [4, 5, 6]]; - # b is identical to a, the literal array is implicitely reshaped: defining new + # b is identical to a, the literal array is implicitly reshaped: defining new # variables is the way to reshape arrays (element count must match). var b<2, 3> = [1, 2, 3, 4, 5, 6]; # This call will specialize `multiply_transpose` with <2, 3> for both diff --git a/mlir/test/Examples/Toy/Ch4/codegen.toy b/mlir/test/Examples/Toy/Ch4/codegen.toy index ff47f995246..722ff4a2587 100644 --- a/mlir/test/Examples/Toy/Ch4/codegen.toy +++ b/mlir/test/Examples/Toy/Ch4/codegen.toy @@ -13,20 +13,19 @@ def main() { print(d); } -# CHECK-LABEL: func @multiply_transpose(%arg0: !toy.array, %arg1: !toy.array) -# CHECK-NEXT: attributes {toy.generic = true} { -# CHECK-NEXT: %0 = "toy.transpose"(%arg1) : (!toy.array) -> !toy.array -# CHECK-NEXT: %1 = "toy.mul"(%arg0, %0) : (!toy.array, !toy.array) -> !toy.array -# CHECK-NEXT: "toy.return"(%1) : (!toy.array) -> () -# CHECK-NEXT: } - -# CHECK-LABEL: func @main() { -# CHECK-NEXT: %0 = "toy.constant"() {value = dense<{{\[\[}}1.000000e+00, 2.000000e+00, 3.000000e+00], [4.000000e+00, 5.000000e+00, 6.000000e+00]]> : tensor<2x3xf64>} : () -> !toy.array<2, 3> -# CHECK-NEXT: %1 = "toy.reshape"(%0) : (!toy.array<2, 3>) -> !toy.array<2, 3> -# CHECK-NEXT: %2 = "toy.constant"() {value = dense<[1.000000e+00, 2.000000e+00, 3.000000e+00, 4.000000e+00, 5.000000e+00, 6.000000e+00]> : tensor<6xf64>} : () -> !toy.array<6> -# CHECK-NEXT: %3 = "toy.reshape"(%2) : (!toy.array<6>) -> !toy.array<2, 3> -# CHECK-NEXT: %4 = "toy.generic_call"(%1, %3) {callee = "multiply_transpose"} : (!toy.array<2, 3>, !toy.array<2, 3>) -> !toy.array -# CHECK-NEXT: %5 = "toy.generic_call"(%3, %1) {callee = "multiply_transpose"} : (!toy.array<2, 3>, !toy.array<2, 3>) -> !toy.array -# CHECK-NEXT: "toy.print"(%5) : (!toy.array) -> () -# CHECK-NEXT: "toy.return"() : () -> () +# CHECK-LABEL: func @multiply_transpose( +# CHECK-SAME: [[VAL_0:%.*]]: tensor<*xf64>, [[VAL_1:%.*]]: tensor<*xf64>) +# CHECK-NEXT: attributes {toy.generic} { +# CHECK-NEXT: [[VAL_2:%.*]] = "toy.transpose"([[VAL_1]]) : (tensor<*xf64>) -> tensor<*xf64> +# CHECK-NEXT: [[VAL_3:%.*]] = "toy.mul"([[VAL_0]], [[VAL_2]]) : (tensor<*xf64>, tensor<*xf64>) -> tensor<*xf64> +# CHECK-NEXT: "toy.return"([[VAL_3]]) : (tensor<*xf64>) -> () +# CHECK-LABEL: func @main() { +# CHECK-NEXT: [[VAL_4:%.*]] = "toy.constant"() {value = dense<{{\[\[}}1.000000e+00, 2.000000e+00, 3.000000e+00], [4.000000e+00, 5.000000e+00, 6.000000e+00]]> : tensor<2x3xf64>} : () -> tensor<2x3xf64> +# CHECK-NEXT: [[VAL_5:%.*]] = "toy.reshape"([[VAL_4]]) : (tensor<2x3xf64>) -> tensor<2x3xf64> +# CHECK-NEXT: [[VAL_6:%.*]] = "toy.constant"() {value = dense<[1.000000e+00, 2.000000e+00, 3.000000e+00, 4.000000e+00, 5.000000e+00, 6.000000e+00]> : tensor<6xf64>} : () -> tensor<6xf64> +# CHECK-NEXT: [[VAL_7:%.*]] = "toy.reshape"([[VAL_6]]) : (tensor<6xf64>) -> tensor<2x3xf64> +# CHECK-NEXT: [[VAL_8:%.*]] = "toy.generic_call"([[VAL_5]], [[VAL_7]]) {callee = @multiply_transpose} : (tensor<2x3xf64>, tensor<2x3xf64>) -> tensor<*xf64> +# CHECK-NEXT: [[VAL_9:%.*]] = "toy.generic_call"([[VAL_7]], [[VAL_5]]) {callee = @multiply_transpose} : (tensor<2x3xf64>, tensor<2x3xf64>) -> tensor<*xf64> +# CHECK-NEXT: "toy.print"([[VAL_9]]) : (tensor<*xf64>) -> () +# CHECK-NEXT: "toy.return"() : () -> () diff --git a/mlir/test/Examples/Toy/Ch4/invalid.mlir b/mlir/test/Examples/Toy/Ch4/invalid.mlir index d15386640e8..8d1bb27344f 100644 --- a/mlir/test/Examples/Toy/Ch4/invalid.mlir +++ b/mlir/test/Examples/Toy/Ch4/invalid.mlir @@ -1,11 +1,9 @@ // RUN: not toyc-ch4 %s -emit=mlir 2>&1 - -// This IR is not "valid": +// The following IR is not "valid": // - toy.print should not return a value. // - toy.print should take an argument. // - There should be a block terminator. -// This all round-trip since this is opaque for MLIR. func @main() { - %0 = "toy.print"() : () -> !toy.array<2, 3> + %0 = "toy.print"() : () -> tensor<2x3xf64> } diff --git a/mlir/test/Examples/Toy/Ch4/scalar.toy b/mlir/test/Examples/Toy/Ch4/scalar.toy index 6231fc992c3..032b3b02b9d 100644 --- a/mlir/test/Examples/Toy/Ch4/scalar.toy +++ b/mlir/test/Examples/Toy/Ch4/scalar.toy @@ -6,9 +6,9 @@ def main() { } # CHECK-LABEL: func @main() { -# CHECK-NEXT: %0 = "toy.constant"() {value = dense<5.500000e+00> : tensor<1xf64>} : () -> !toy.array<1> -# CHECK-NEXT: %1 = "toy.reshape"(%0) : (!toy.array<1>) -> !toy.array<2, 2> -# CHECK-NEXT: "toy.print"(%1) : (!toy.array<2, 2>) -> () +# CHECK-NEXT: %0 = "toy.constant"() {value = dense<5.500000e+00> : tensor<f64>} : () -> tensor<f64> +# CHECK-NEXT: %1 = "toy.reshape"(%0) : (tensor<f64>) -> tensor<2x2xf64> +# CHECK-NEXT: "toy.print"(%1) : (tensor<2x2xf64>) -> () # CHECK-NEXT: "toy.return"() : () -> () # CHECK-NEXT: } diff --git a/mlir/test/Examples/Toy/Ch4/transpose_transpose.toy b/mlir/test/Examples/Toy/Ch4/transpose_transpose.toy deleted file mode 100644 index 31399eee53f..00000000000 --- a/mlir/test/Examples/Toy/Ch4/transpose_transpose.toy +++ /dev/null @@ -1,19 +0,0 @@ -# RUN: toyc-ch4 %s -emit=mlir 2>&1 | FileCheck %s -# RUN: toyc-ch4 %s -emit=mlir -opt 2>&1 | FileCheck %s --check-prefix=OPT - -def transpose_transpose(x) { - return transpose(transpose(x)); -} - -def main() { - print(transpose_transpose([[1, 2], [3, 4]])); -} - -#CHECK-LABEL: func @transpose_transpose -#CHECK: transpose -#CHECK-LABEL: main - - -#OPT-LABEL: func @transpose_transpose -#OPT-NOT: transpose - diff --git a/mlir/test/Examples/Toy/Ch4/trivialReshape.toy b/mlir/test/Examples/Toy/Ch4/trivialReshape.toy deleted file mode 100644 index c7a805d89ef..00000000000 --- a/mlir/test/Examples/Toy/Ch4/trivialReshape.toy +++ /dev/null @@ -1,24 +0,0 @@ -# RUN: toyc-ch4 %s -emit=mlir 2>&1 | FileCheck %s -# RUN: toyc-ch4 %s -emit=mlir -opt 2>&1 | FileCheck %s --check-prefix=OPT - -# We expect no reshape in this function with optimizations enabled -def foo(a) { - var b<2,1> = a; - var c<2,1> = b; - print(c); -} - -def main() { - var a<2, 1> = [1, 2]; - foo(a); -} - -# without optimizations, match the reshape -#CHECK-LABEL: func @foo -#CHECK: reshape -#CHECK-LABEL: main - -# with optimizations, ensure no reshape -#OPT-LABEL: main -#OPT-LABEL: func @foo_2x1 -#OPT-NOT: reshape |

