torch-mlir/lib
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
..
Backend Rewrite error reporting of e2e tests. 2021-05-20 11:28:20 -07:00
CAPI Add a !torch.float type. 2021-06-17 09:24:18 -07:00
Conversion Generalize support for elementwise ops. 2021-06-28 13:28:38 -07:00
Dialect Generalize support for elementwise ops. 2021-06-28 13:28:38 -07:00
Interfaces Add AllowsTypeRefinement trait and use it to improve RefineTypes 2021-04-30 10:57:02 -07:00
RefBackend Generalize support for elementwise ops. 2021-06-28 13:28:38 -07:00
Typing Bump llvm-project to c68d2895a1f4019b387c69d1e5eec31b0eb5e7b0 2021-02-22 12:23:24 -08:00
CMakeLists.txt Significantly restructure torch/aten import design. 2021-05-19 13:37:39 -07:00
InitAll.cpp Significantly restructure torch/aten import design. 2021-05-19 13:37:39 -07:00