torch-mlir/lib/Conversion/TorchToLinalg
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
..
CMakeLists.txt Re-organize project structure to separate PyTorch dependencies from core project. (#2542) 2023-11-02 19:45:55 -07:00
DataMovement.cpp [NFC] Change to *cast instead of .*cast variants (#3405) 2024-05-30 23:45:13 -07:00
IndirectDataMovement.cpp [NFC] Change to *cast instead of .*cast variants (#3405) 2024-05-30 23:45:13 -07:00
Linear.cpp [TorchToLinalg] add support for quantized group conv (#3341) 2024-06-03 21:57:44 +05:30
Pooling.cpp [NFC] Change to *cast instead of .*cast variants (#3405) 2024-05-30 23:45:13 -07:00
PopulatePatterns.h Re-enable custom op support 2022-08-16 22:49:08 +05:30
Random.cpp [NFC] Change to *cast instead of .*cast variants (#3405) 2024-05-30 23:45:13 -07:00
Reduction.cpp [NFC] Change to *cast instead of .*cast variants (#3405) 2024-05-30 23:45:13 -07:00
TensorConstructors.cpp [NFC] Change to *cast instead of .*cast variants (#3405) 2024-05-30 23:45:13 -07:00
TensorScalarInterop.cpp [NFC] Change to *cast instead of .*cast variants (#3405) 2024-05-30 23:45:13 -07:00
TorchToLinalg.cpp [NFC] Remove unused header files (#3386) 2024-05-30 14:30:36 +08:00
Uncategorized.cpp [Stablehlo] support uint8 (#3367) 2024-06-04 09:04:59 +08:00
Utils.cpp [NFC] Change to *cast instead of .*cast variants (#3405) 2024-05-30 23:45:13 -07:00