From 444bb1f1bbbd7450fd30acc4ac1091fe916a740f Mon Sep 17 00:00:00 2001 From: Andrey Portnoy Date: Tue, 6 Jun 2023 11:19:53 -0700 Subject: [PATCH] [mlir][Toy] Remove unnecessary transpose from chapter 1 example The call to 'multiply_transpose' in the initialization of the variable 'f' was intended to have a shape mismatch. However the variable 'a' has shape <2, 3> and the variable 'c' has shape <3, 2>, so the arguments 'transpose(a)' and 'c' have in fact compatible shapes (<3, 2> both), the opposite of what is wanted here. This commit removes the transpose so that arguments 'a' and 'c' have incompatible shapes <2, 3> and <3, 2>, respectively. Reviewed By: mehdi_amini Differential Revision: https://reviews.llvm.org/D151897 --- mlir/docs/Tutorials/Toy/Ch-1.md | 16 +++++++--------- mlir/test/Examples/Toy/Ch1/ast.toy | 14 ++++++-------- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/mlir/docs/Tutorials/Toy/Ch-1.md b/mlir/docs/Tutorials/Toy/Ch-1.md index 6838c34..09cee88 100644 --- a/mlir/docs/Tutorials/Toy/Ch-1.md +++ b/mlir/docs/Tutorials/Toy/Ch-1.md @@ -61,9 +61,9 @@ def main() { # trigger another specialization of `multiply_transpose`. var e = multiply_transpose(c, d); - # Finally, calling into `multiply_transpose` with incompatible shape will - # trigger a shape inference error. - var f = multiply_transpose(transpose(a), c); + # Finally, calling into `multiply_transpose` with incompatible shapes + # (<2, 3> and <3, 2>) will trigger a shape inference error. + var f = multiply_transpose(a, c); } ``` @@ -74,7 +74,7 @@ The AST from the above code is fairly straightforward; here is a dump of it: ``` Module: Function - Proto 'multiply_transpose' @test/Examples/Toy/Ch1/ast.toy:4:1' + Proto 'multiply_transpose' @test/Examples/Toy/Ch1/ast.toy:4:1 Params: [a, b] Block { Return @@ -87,7 +87,7 @@ Module: ] } // Block Function - Proto 'main' @test/Examples/Toy/Ch1/ast.toy:8:1' + Proto 'main' @test/Examples/Toy/Ch1/ast.toy:8:1 Params: [] Block { VarDecl a<> @test/Examples/Toy/Ch1/ast.toy:11:3 @@ -111,10 +111,8 @@ Module: ] VarDecl f<> @test/Examples/Toy/Ch1/ast.toy:28:3 Call 'multiply_transpose' [ @test/Examples/Toy/Ch1/ast.toy:28:11 - Call 'transpose' [ @test/Examples/Toy/Ch1/ast.toy:28:30 - var: a @test/Examples/Toy/Ch1/ast.toy:28:40 - ] - var: c @test/Examples/Toy/Ch1/ast.toy:28:44 + var: a @test/Examples/Toy/Ch1/ast.toy:28:30 + var: c @test/Examples/Toy/Ch1/ast.toy:28:33 ] } // Block ``` diff --git a/mlir/test/Examples/Toy/Ch1/ast.toy b/mlir/test/Examples/Toy/Ch1/ast.toy index dc209a0..4af2d25 100644 --- a/mlir/test/Examples/Toy/Ch1/ast.toy +++ b/mlir/test/Examples/Toy/Ch1/ast.toy @@ -23,9 +23,9 @@ def main() { # A new call with `<3, 2>` for both dimension will trigger another # specialization of `multiply_transpose`. var e = multiply_transpose(c, d); - # Finally, calling into `multiply_transpose` with incompatible shape will - # trigger a shape inference error. - var f = multiply_transpose(transpose(a), c); + # Finally, calling into `multiply_transpose` with incompatible shapes + # (<2, 3> and <3, 2>) will trigger a shape inference error. + var f = multiply_transpose(a, c); } @@ -68,9 +68,7 @@ def main() { # CHECK-NEXT: ] # CHECK-NEXT: VarDecl f<> @{{.*}}ast.toy:28:3 # CHECK-NEXT: Call 'multiply_transpose' [ @{{.*}}ast.toy:28:11 -# CHECK-NEXT: Call 'transpose' [ @{{.*}}ast.toy:28:30 -# CHECK-NEXT: var: a @{{.*}}ast.toy:28:40 -# CHECK-NEXT: ] -# CHECK-NEXT: var: c @{{.*}}ast.toy:28:44 +# CHECK-NEXT: var: a @{{.*}}ast.toy:28:30 +# CHECK-NEXT: var: c @{{.*}}ast.toy:28:33 # CHECK-NEXT: ] - +# CHECK-NEXT: } // Block -- 2.7.4