Skip to content

Commit 3e79f4d

Browse files
[MLIR][Arith] Fix arith::AtomicRMWKind::maximumf's identity value (#70312)
-- In order to compute maximum, we should always initialise the result with the largest negative value possible for the concerned element type, instead of the smallest. -- This commit essentially adds a fix to this issue. Signed-off-by: Abhishek Varma <[email protected]>
1 parent b67d370 commit 3e79f4d

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

mlir/lib/Dialect/Arith/IR/ArithOps.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2412,7 +2412,7 @@ TypedAttr mlir::arith::getIdentityValueAttr(AtomicRMWKind kind, Type resultType,
24122412
const llvm::fltSemantics &semantic =
24132413
llvm::cast<FloatType>(resultType).getFloatSemantics();
24142414
APFloat identity = useOnlyFiniteValue
2415-
? APFloat::getSmallest(semantic, /*Negative=*/true)
2415+
? APFloat::getLargest(semantic, /*Negative=*/true)
24162416
: APFloat::getInf(semantic, /*Negative=*/true);
24172417
return builder.getFloatAttr(resultType, identity);
24182418
}

mlir/test/Dialect/Linalg/transform-op-decompose.mlir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ func.func @softmax(%arg0: tensor<2x16x32xf32>, %dst: tensor<2x16x32xf32>) -> ten
210210
// CHECK-LABEL: func.func @softmax(
211211
// CHECK-SAME: %[[ARG0:[a-zA-Z0-9_]+]]: tensor<2x16x32xf32>, %[[DST:[a-zA-Z0-9_]+]]: tensor<2x16x32xf32>) -> tensor<2x16x32xf32> {
212212
// CHECK-DAG: %[[D1:.+]] = tensor.empty() : tensor<2x16xf32>
213-
// CHECK-DAG: %[[CST:.+]] = arith.constant -1.401300e-45 : f32
213+
// CHECK-DAG: %[[CST:.+]] = arith.constant -3.40282347E+38 : f32
214214
// CHECK: %[[D2:.+]] = linalg.fill ins(%[[CST]] : f32) outs(%[[D1]] : tensor<2x16xf32>) -> tensor<2x16xf32>
215215
// CHECK: %[[D3:.+]] = linalg.generic {indexing_maps = [#[[$MAP]], #[[$MAP1]]], iterator_types = ["parallel",
216216
// CHECK-SAME: "parallel", "reduction"]} ins(%[[ARG0]] : tensor<2x16x32xf32>) outs(%[[D2]] : tensor<2x16xf32>) {

mlir/test/Dialect/Linalg/transform-op-split-reduction.mlir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ func.func @generic_split_3d_ninf(%input: tensor<32x2xf32>, %input_2: tensor<5x32
176176
// CHECK-DAG: #[[$MAP3:.*]] = affine_map<(d0, d1, d2) -> (d0, d1, d2)>
177177
// CHECK-DAG: #[[$MAP4:.*]] = affine_map<(d0, d1, d2) -> (d0, d1)>
178178
// CHECK-LABEL: func @generic_split_3d_ninf
179-
// CHECK-DAG: %[[ID:.*]] = arith.constant -1.401300e-45 : f32
179+
// CHECK-DAG: %[[ID:.*]] = arith.constant -3.40282347E+38 : f32
180180
// CHECK-DAG: %[[I1:.*]] = tensor.expand_shape %{{.*}}[0, 1], [2]] : tensor<32x2xf32> into tensor<4x8x2xf32>
181181
// CHECK-DAG: %[[I2:.*]] = tensor.expand_shape %{{.*}}[0], [1, 2]] : tensor<5x32xf32> into tensor<5x4x8xf32>
182182
// CHECK-DAG: %[[INI:.*]] = tensor.empty() : tensor<5x2x4xf32>

0 commit comments

Comments
 (0)