Skip to content

Commit a498541

Browse files
dchauhan-armljfitz
authored andcommitted
[MLIR][TOSA] Fix f16/bf16 support for MaxPool2D (llvm#69332)
Currently, the MaxPool2D operation in the TOSA MLIR dialect does not accept half-precision Fp16 and Bf16 tensors, converse to what is stated in the [TOSA Specification](https://www.mlplatform.org/tosa/tosa_spec.html#_max_pool2d). This patch fixes the verifier to accept the two datatypes for input/output tensors, and adds related LIT test cases in Tosa/ops.mlir
1 parent 3a5f724 commit a498541

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

mlir/lib/Conversion/TosaToLinalg/TosaToLinalgNamed.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,7 @@ class MaxPool2dConverter : public OpRewritePattern<tosa::MaxPool2dOp> {
768768

769769
// Determine what the initial value needs to be for the max pool op.
770770
TypedAttr initialAttr;
771-
if (resultETy.isF32())
771+
if (resultETy.isF32() || resultETy.isBF16() || resultETy.isF16())
772772
initialAttr = rewriter.getFloatAttr(
773773
resultETy, APFloat::getLargest(
774774
cast<FloatType>(resultETy).getFloatSemantics(), true));

mlir/test/Dialect/Tosa/ops.mlir

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,26 @@ func.func @test_matmul(%arg0: tensor<1x14x19xf32>, %arg1: tensor<1x19x28xf32>) -
8383
}
8484

8585
// -----
86-
// CHECK-LABEL: max_pool2d
87-
func.func @test_max_pool2d(%arg0: tensor<1x32x32x8xf32>) -> tensor<1x32x32x8xf32> {
86+
// CHECK-LABEL: max_pool2d_f32
87+
func.func @test_max_pool2d_f32(%arg0: tensor<1x32x32x8xf32>) -> tensor<1x32x32x8xf32> {
8888
%0 = tosa.max_pool2d %arg0 {kernel = array<i64: 1, 1>, pad = array<i64: 0, 0, 0, 0>, stride = array<i64: 1, 1>} : (tensor<1x32x32x8xf32>) -> tensor<1x32x32x8xf32>
8989
return %0 : tensor<1x32x32x8xf32>
9090
}
9191

92+
// -----
93+
// CHECK-LABEL: max_pool2d_bf16
94+
func.func @test_max_pool2d_bf16(%arg0: tensor<1x32x32x8xbf16>) -> tensor<1x32x32x8xbf16> {
95+
%0 = tosa.max_pool2d %arg0 {kernel = array<i64: 1, 1>, pad = array<i64: 0, 0, 0, 0>, stride = array<i64: 1, 1>} : (tensor<1x32x32x8xbf16>) -> tensor<1x32x32x8xbf16>
96+
return %0 : tensor<1x32x32x8xbf16>
97+
}
98+
99+
// -----
100+
// CHECK-LABEL: max_pool2d_f16
101+
func.func @test_max_pool2d_f16(%arg0: tensor<1x32x32x8xf16>) -> tensor<1x32x32x8xf16> {
102+
%0 = tosa.max_pool2d %arg0 {kernel = array<i64: 1, 1>, pad = array<i64: 0, 0, 0, 0>, stride = array<i64: 1, 1>} : (tensor<1x32x32x8xf16>) -> tensor<1x32x32x8xf16>
103+
return %0 : tensor<1x32x32x8xf16>
104+
}
105+
92106
// -----
93107
// CHECK-LABEL: rfft2d
94108
func.func @test_rfft2d(%arg0: tensor<13x8x16xf32>) -> (tensor<13x8x9xf32>, tensor<13x8x9xf32>) {

0 commit comments

Comments
 (0)