You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[TorchToStablehlo] Add support for lowering torch.aten.sort to stablehlo.sort (#4633)
## Description
This PR implements the lowering support for `torch.aten.sort` in the
`convert-torch-to-stablehlo` pass, which is a prerequisite for compiling
operators like `topk` (since `topk` decomposes into `sort` + `slice`).
See semantics in https://openxla.org/stablehlo/spec#sort.
Fix#4337.
## Details
- Implemented `ConvertAtenSortOp` to lower `torch.aten.sort` to
`stablehlo.sort`.
- Used `stablehlo.iota` to generate initial indices along the sorting
dimension.
- Created the comparator region inside `stablehlo.sort` using
`stablehlo.compare` (GT for descending, LT for ascending).
## Testing
- Added regression test case in
`test/Conversion/TorchToStablehlo/reduction.mlir`.
- Verified all unit tests pass with `check-torch-mlir`.
- the output stablehlo mlir is compiled and executed by iree, the result
is expected.
Signed-off-by: hsqStephenZhang <stephenzhang666666@gmail.com>
0 commit comments