torch-mlir/lib/Conversion
Sean Silva 79928cd2dd Generalize support for elementwise ops.
We plumb through e2e a fair number of interesting cases:
- unary, binary, ternary elementwise ops
- ops like `torch.aten.add.Tensor` that also take a scalar parameter
- static size-1 broadcasting

We allow the static size-1 broadcasting case, but emit a runtime error
in the case of dynamic size-1 broadcasting. This seems like a sweet spot
subset of things that can be lowered directly to linalg, while not being
overly constraining to users. This is consistent with what IREE is doing
for CHLO->Linalg lowering as well
([code](50bf7a87e4/iree/compiler/InputConversion/MHLO/BroadcastingToLinalgPatterns.cpp (L1))).

To test the static size-1 case, we added support for the
`torch.aten.unsqueeze` op and lowering for it through
`linalg.tensor_expand_shape`. This involved a generalization of
`MaximizeValueSemantics` able to handle it (the solution there also
works for `torch.aten.flatten.using_ints` which we need for ResNet
anyway)

Also, a few minor additional changes:
- Add `VerifyInvariantsBeforeBackendLowering` pass, which catches a
  large class of errors before we get to backend lowering (now that we
  are doing dialect conversion, the errors are way nicer if we just emit
  them up front rather than in the guts of a random pattern).
- Minor change to RefBackend to allow `linalg.tensor_expand_shape`.

Recommended review order:
- e2e tests in elementwise.py
- `ConvertElementwiseOp` in TorchToLinalg.cpp + elementwise.mlir test
- `ConvertAtenUnsqueezeOp` in TorchToLinalg.cpp + unsqueeze.mlir test
- RefineTypes.cpp + tests
- MaximizeValueSemantics changes + test
- VerifyInvariantsBeforeBackendLowering pass + test
2021-06-28 13:28:38 -07:00
..
BasicpyToStd Bump llvm-project to 12011b5217929ef8a56c2099c6f3233934ea4fbc 2021-04-27 13:12:33 -07:00
NumpyToTCF Bump llvm-project to 0524a09cc7e1a0797982feacf505825231efbee7 2021-03-23 14:29:05 -07:00
TCFToLinalg Bump llvm-project to 12011b5217929ef8a56c2099c6f3233934ea4fbc 2021-04-27 13:12:33 -07:00
TCFToStd Bump llvm-project to 12011b5217929ef8a56c2099c6f3233934ea4fbc 2021-04-27 13:12:33 -07:00
TCFToTCP Bump llvm-project to 12011b5217929ef8a56c2099c6f3233934ea4fbc 2021-04-27 13:12:33 -07:00
TorchToLinalg Generalize support for elementwise ops. 2021-06-28 13:28:38 -07:00
TorchToSCF Add TorchToSCF pass. 2021-06-23 08:06:43 -07:00
TorchToStd Convert Torch constant ops to std.constant 2021-06-18 12:22:47 -07:00
CMakeLists.txt Add TorchToSCF pass. 2021-06-23 08:06:43 -07:00
PassDetail.h Initial TCF/TCP E2E seed. 2020-05-08 20:20:41 -07:00
Passes.cpp Add TorchToSCF pass. 2021-06-23 08:06:43 -07:00