torch-mlir/lib/Dialect/TorchConversion/Transforms
Yuanqiang Liu 50f7103098
[Stablehlo] support uint8 (#3367)
Support lowering unsigned integer type to stablehlo as discussed in
https://github.com/llvm/torch-mlir/pull/2184.

The things I do in this PR:
1. create `setupBackendTypeConversionForStablehlo()`,
`createFuncBackendTypeConversionForStablehloPass` and
`createFinalizingBackendTypeConversionForStablehloPass`.
2. remove `InferTypeOpInterface` from `torch_c.to_builtin_tensor`,
because it's different result type between linalg backend and stablehlo
backend:
```
// linalg backend
func.func @forward(%arg0: !torch.vtensor<[3],ui8>) -> tensor<3xf32> {
    %c = torch_c.to_builtin_tensor %arg0 : (!torch.vtensor<[3], ui8> -> tensor<3xi8>
    %0 = tensor.empty() : tensor<3xf32>
    %1 = linalg.generic {indexing_maps = [#map, #map], iterator_types = ["parallel"]} ins(%arg0 : tensor<3xi8>) outs(%0 : tensor<3xf32>) {
    ^bb0(%in: i8, %out: f32):
      %2 = arith.uitofp %in : i8 to f32
      linalg.yield %2 : f32
    } -> tensor<3xf32>
    return %1 : tensor<3xf32>
}
// stablehlo backend
func.func @forward(%arg0: !torch.vtensor<[3],ui8>) -> tensor<3xf32> {
    %c = torch_c.to_builtin_tensor %arg0 : (!torch.vtensor<[3], ui8> -> tensor<3xui8>
    %0 = stablehlo.convert %arg0 : (tensor<3xui8> -> tensor<3xf32>
    return %0 : tensor<3xf32>
}
```
3. fix stablehlo and linalg's conversion
2024-06-04 09:04:59 +08:00
..
BackendTypeConversion.cpp [Stablehlo] support uint8 (#3367) 2024-06-04 09:04:59 +08:00
BackendTypeConversionPasses.cpp [Stablehlo] support uint8 (#3367) 2024-06-04 09:04:59 +08:00
CMakeLists.txt [NFC reformat] Run pre-commit on all files and format misc. 2024-04-27 14:08:09 -07:00
ConvertCustomQuantOp.cpp [NFC] Remove unused header files (#3386) 2024-05-30 14:30:36 +08:00
PassDetail.h Migrate passes in TorchConversion to use FunctionOpInterface. (#2935) 2024-02-20 08:54:02 -08:00
Passes.cpp [Stablehlo] support uint8 (#3367) 2024-06-04 09:04:59 +08:00
UnpackQuantTensor.cpp Fix deprecated uses of cast/dyn_cast/dyn_cast_or_null/isa (#3243) 2024-04-27 14:00:56 -07:00
VerifyLinalgOnTensorsBackendContract.cpp [NFC] Remove unused header files (#3386) 2024-05-30 14:30:36 +08:00
VerifyStablehloBackendContract.cpp [stablehlo] verify stablehlo backend contract (#3338) 2024-05-16 11:03:43 +08:00
VerifyTosaBackendContract.cpp [NFC] Remove unused header files (#3386) 2024-05-30 14:30:36 +08:00