torch-mlir/lib/Conversion/TorchToStablehlo
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
..
Basic.cpp [Stablehlo] support uint8 (#3367) 2024-06-04 09:04:59 +08:00
CMakeLists.txt [Stablehlo] lowering aten.randn & aten.normal_functional to mhlo.rng … (#3328) 2024-05-11 15:33:37 +08:00
GatherScatter.cpp [Stablehlo] support uint8 (#3367) 2024-06-04 09:04:59 +08:00
Linear.cpp [Torch]Support conv_transpose1d and conv_transpose3d (#3286) 2024-06-03 15:11:12 +08:00
Pooling.cpp [NFC] Change to *cast instead of .*cast variants (#3405) 2024-05-30 23:45:13 -07:00
PopulatePatterns.h [Stablehlo] lowering aten.randn & aten.normal_functional to mhlo.rng … (#3328) 2024-05-11 15:33:37 +08:00
Reduction.cpp [NFC] Change to *cast instead of .*cast variants (#3405) 2024-05-30 23:45:13 -07:00
Rng.cpp [NFC] Remove unused header files (#3386) 2024-05-30 14:30:36 +08:00
StablehloLegalizeUtils.cpp [NFC] Remove unused header files (#3386) 2024-05-30 14:30:36 +08:00
TorchToStablehlo.cpp [Stablehlo] support uint8 (#3367) 2024-06-04 09:04:59 +08:00
Utils.cpp [Stablehlo] add torch_to_stablehlo::getBackendTypeForScalarType (#2975) 2024-03-04 23:31:54 +08:00
Utils.h [Stablehlo] add torch_to_stablehlo::getBackendTypeForScalarType (#2975) 2024-03-04 23:31:54 +08:00
ViewLike.cpp [NFC] Change to *cast instead of .*cast variants (#3405) 2024-05-30 23:45:13 -07:00