提交 f7620b08 编写于 作者: A A. Unique TensorFlower 提交者: TensorFlower Gardener

Support legalizing some TF.XlaGather ops in the TFLite converter

The current implementation only supports legalizing ops which can be canonicalized
to an mhlo.slice but the coverage will improve as handling for mhlo.gather improves
in the lower layers.

PiperOrigin-RevId: 330752224
Change-Id: I2a690bba8355ffaa5d4c467c668a7f109c020246
上级 3091cf8e
......@@ -643,4 +643,17 @@ func @lower_rfft_to_rfft2d(%input: tensor<10x20x30xf32>, %fft_len: tensor<1xi32>
// CHECK: %[[SQE:.*]] = "tf.Squeeze"(%[[RFF]]) {squeeze_dims = [-2]} : (tensor<10x20x1x30xcomplex<f64>>) -> tensor<10x20x30xcomplex<f64>>
}
// CHECK-LABEL: xla_gather_to_slice
func @xla_gather_to_slice(%arg0 : tensor<1x9x104x768xf32>) -> tensor<*xf32> {
%0 = "tf.Const"() {value = dense<0> : tensor<1xi32>} : () -> tensor<1xi32>
%1 = "tf.Const"() {value = dense<[1, 9, 23, 768]> : tensor<4xi32>} : () -> tensor<4xi32>
%2 = "tf.XlaGather"(%arg0, %0, %1) {device = "", dimension_numbers = "\0A\04\00\01\02\03\1A\01\02", indices_are_sorted = false} : (tensor<1x9x104x768xf32>, tensor<1xi32>, tensor<4xi32>) -> tensor<*xf32>
return %2 : tensor<*xf32>
// CHECK: %[[CST:.*]] = constant dense<0> : tensor<4xi64>
// CHECK: %[[CST0:.*]] = constant dense<[1, 9, 23, 768]> : tensor<4xi64>
// CHECK: %[[V0:.*]] = "tf.Slice"(%arg0, %[[CST]], %[[CST0]]) : (tensor<1x9x104x768xf32>, tensor<4xi64>, tensor<4xi64>) -> tensor<*xf32>
// CHECK: return %[[V0]] : tensor<*xf32>
}
}
......@@ -790,10 +790,13 @@ LogicalResult ConvertTf2XlaOps(FuncOp func, MLIRContext *context) {
target.addLegalOp<ModuleOp>();
target.addLegalOp<FuncOp>();
target.addIllegalOp<TF::XlaConvOp>();
target.addIllegalOp<TF::XlaGatherOp>();
OwningRewritePatternList patterns;
mhlo::PopulateLegalizeTfWithTf2XlaPatterns("XLA_CPU_JIT", patterns);
mhlo::PopulateLegalizeTfPatterns(context, &patterns);
TF::PopulateLegalizeHloToTfPatterns(&patterns, context);
mhlo::GatherOp::getCanonicalizationPatterns(patterns, context);
return applyPartialConversion(func, target, patterns);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册