Skip to content

Commit

Permalink
Bump stablehlo to f7f8e4e35 and drop LLVM local reverts (#18668)
Browse files Browse the repository at this point in the history
Continuing from @hanhanW 's #18659:

Stablehlo cherry-picks:
1. openxla/stablehlo#2572
2. openxla/stablehlo#2573

Torch-mlir cherry-picks:
1. llvm/torch-mlir#3755

---------

Signed-off-by: hanhanW <[email protected]>
Signed-off-by: Benoit Jacob <[email protected]>
Co-authored-by: hanhanW <[email protected]>
  • Loading branch information
bjacob and hanhanW authored Oct 2, 2024
1 parent d341128 commit 7a2705d
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -491,15 +491,15 @@ struct AllGatherOpConversion final
op.getReplicaGroups(), op.getUseGlobalDeviceIds(), rewriter);

// Get the collective element type attribute.
auto resultType = cast<RankedTensorType>(op.getResult().getType());
auto resultType = cast<RankedTensorType>(op.getResult(0).getType());
IREE::Flow::CollectiveElementTypeAttr elementTypeAttr =
IREE::Flow::getCollectiveElementTypeAttr(resultType);
if (!elementTypeAttr) {
return rewriter.notifyMatchFailure(
op, "unsupported element type for collective op");
}
uint64_t allGatherDim = op.getAllGatherDim();
Value gatherInput = adaptor.getOperand();
Value gatherInput = adaptor.getOperands()[0];
SmallVector<int64_t> gatherResultShape(resultType.getShape());

// When all_gather_dim != 0, we need to transpose between 0 and
Expand All @@ -513,7 +513,7 @@ struct AllGatherOpConversion final
// Create an empty tensor for the result.
Value target = rewriter.create<tensor::EmptyOp>(
loc, gatherResultShape,
getElementTypeOrSelf(adaptor.getOperand().getType()));
getElementTypeOrSelf(adaptor.getOperands()[0].getType()));
Value gatherResult = rewriter.create<IREE::Flow::CollectiveAllGatherOp>(
op.getLoc(), elementTypeAttr, target, gatherInput, channel);

Expand Down Expand Up @@ -585,7 +585,7 @@ struct AllReduceOpConversion final
auto reductionOpAttr =
IREE::Flow::CollectiveReductionOpAttr::get(op.getContext(), *redOp);

auto inputType = cast<RankedTensorType>(op.getOperand().getType());
auto inputType = cast<RankedTensorType>(op.getOperand(0).getType());

// Get the collective element type attribute.
IREE::Flow::CollectiveElementTypeAttr elementTypeAttr =
Expand All @@ -597,10 +597,11 @@ struct AllReduceOpConversion final
// Create an empty tensor for the result.
ArrayRef<int64_t> inputShape = inputType.getShape();
Value target = rewriter.create<tensor::EmptyOp>(
loc, inputShape, getElementTypeOrSelf(adaptor.getOperand().getType()));
loc, inputShape,
getElementTypeOrSelf(adaptor.getOperands()[0].getType()));
auto allReduceOp = rewriter.create<IREE::Flow::CollectiveAllReduceOp>(
op.getLoc(), reductionOpAttr, elementTypeAttr, target,
adaptor.getOperand(), channel);
adaptor.getOperands()[0], channel);
rewriter.replaceOp(op, allReduceOp.getResult());
return success();
}
Expand Down Expand Up @@ -676,7 +677,7 @@ struct AllToAllOpConversion final
op.getReplicaGroups(), /*useGlobalDeviceIds=*/std::nullopt, rewriter);

// Get the collective element type attribute.
auto resultType = cast<RankedTensorType>(op.getType());
auto resultType = cast<RankedTensorType>(op.getType(0));
IREE::Flow::CollectiveElementTypeAttr elementTypeAttr =
IREE::Flow::getCollectiveElementTypeAttr(resultType);
if (!elementTypeAttr) {
Expand All @@ -687,7 +688,7 @@ struct AllToAllOpConversion final
uint64_t splitDim = op.getSplitDimension();
uint64_t concatDim = op.getConcatDimension();
uint64_t splitCount = op.getSplitCount();
Value allToAllInput = adaptor.getOperand();
Value allToAllInput = adaptor.getOperands()[0];

// When splitDim != 0, we need to transpose splitDim to 0 before and after
// the all-to-all.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ struct GeneralDotRemoveBatch final

auto dot = rewriter.create<mlir::stablehlo::DotGeneralOp>(
op.getLoc(), ty.clone(ty.getShape().drop_front()), lhs, rhs,
newDimNumbers, op.getPrecisionConfigAttr());
newDimNumbers, op.getPrecisionConfigAttr(), op.getAlgorithmAttr());
rewriter.replaceOpWithNewOp<mlir::stablehlo::ReshapeOp>(op, ty,
dot.getResult());
return success();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ struct EinsumToDotGeneralPattern final
auto dotGeneralOp = rewriter.create<mlir::stablehlo::DotGeneralOp>(
einsum.getLoc(), dotGeneralResultType, einsum.getLhs(), einsum.getRhs(),
dimNumbers,
/*precision_config=*/ArrayAttr{});
/*precision_config=*/ArrayAttr{}, mlir::stablehlo::DotAlgorithmAttr{});

if (isNaturalOrder) {
// The dot_general is already in an appropriate result order.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ struct TransposeReshapeGenericDotGeneral final

auto newOp = rewriter.create<mlir::stablehlo::DotGeneralOp>(
op.getLoc(), newResultType, lhs, rhs, dimensionNumbers,
op.getPrecisionConfigAttr());
op.getPrecisionConfigAttr(), op.getAlgorithmAttr());

// Copy over unknown attributes as we currently rely on it to let user tune
// lowering parameters.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,8 @@ struct HouseholderReflectorRewriter final
auto dotNums = mlir::stablehlo::DotDimensionNumbersAttr::get(
b.getContext(), batch, batch, lhsContract, rhsContract);
Value dot = b.create<mlir::stablehlo::DotGeneralOp>(
householder0.getType(), args[0], householder, dotNums, nullptr);
householder0.getType(), args[0], householder, dotNums, nullptr,
mlir::stablehlo::DotAlgorithmAttr{});
b.create<scf::YieldOp>(loc, dot);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func.func @conditional_nested(%arg0: tensor<f32>, %arg1: tensor<f32>) -> tensor<
func.func @case2(%arg0 : tensor<i32>, %arg1 : tensor<4xf32>, %arg2 : tensor<4xf32>) -> tensor<4xf32> {

// CHECK-NEXT: %[[VAL_3:.*]] = stablehlo.constant dense<0> : tensor<i32>
// CHECK: %[[VAL_4:.*]] = stablehlo.compare EQ, %[[VAL_0]], %[[VAL_3]], NOTYPE : (tensor<i32>, tensor<i32>) -> tensor<i1>
// CHECK: %[[VAL_4:.*]] = stablehlo.compare EQ, %[[VAL_0]], %[[VAL_3]] : (tensor<i32>, tensor<i32>) -> tensor<i1>
// CHECK: %[[VAL_5:.*]] = tensor.extract %[[VAL_4]][] : tensor<i1>
// CHECK: %[[VAL_6:.*]] = scf.if %[[VAL_5]] -> (tensor<4xf32>) {
%1 = "stablehlo.case"(%arg0) ({
Expand Down Expand Up @@ -180,7 +180,7 @@ func.func @case2(%arg0 : tensor<i32>, %arg1 : tensor<4xf32>, %arg2 : tensor<4xf3
func.func @case3(%arg0 : tensor<i32>, %arg1 : tensor<4xf32>, %arg2 : tensor<4xf32>, %arg3 : tensor<4xf32>) -> tensor<4xf32> {

// CHECK-NEXT: %[[VAL_4:.*]] = stablehlo.constant dense<0> : tensor<i32>
// CHECK: %[[VAL_5:.*]] = stablehlo.compare EQ, %[[VAL_0]], %[[VAL_4]], NOTYPE : (tensor<i32>, tensor<i32>) -> tensor<i1>
// CHECK: %[[VAL_5:.*]] = stablehlo.compare EQ, %[[VAL_0]], %[[VAL_4]] : (tensor<i32>, tensor<i32>) -> tensor<i1>
// CHECK: %[[VAL_6:.*]] = tensor.extract %[[VAL_5]][] : tensor<i1>
// CHECK: %[[VAL_7:.*]] = scf.if %[[VAL_6]] -> (tensor<4xf32>) {
%1 = "stablehlo.case"(%arg0) ({
Expand All @@ -191,7 +191,7 @@ func.func @case3(%arg0 : tensor<i32>, %arg1 : tensor<4xf32>, %arg2 : tensor<4xf3

// CHECK: } else {
// CHECK-NEXT: %[[VAL_9:.*]] = stablehlo.constant dense<1> : tensor<i32>
// CHECK: %[[VAL_10:.*]] = stablehlo.compare EQ, %[[VAL_0]], %[[VAL_9]], NOTYPE : (tensor<i32>, tensor<i32>) -> tensor<i1>
// CHECK: %[[VAL_10:.*]] = stablehlo.compare EQ, %[[VAL_0]], %[[VAL_9]] : (tensor<i32>, tensor<i32>) -> tensor<i1>
// CHECK: %[[VAL_11:.*]] = tensor.extract %[[VAL_10]][] : tensor<i1>
// CHECK: %[[VAL_12:.*]] = scf.if %[[VAL_11]] -> (tensor<4xf32>) {
}, {
Expand Down
1 change: 1 addition & 0 deletions compiler/src/iree/compiler/Tools/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ iree_compiler_cc_library(
"@llvm-project//mlir:MLProgramDialect",
"@llvm-project//mlir:MathDialect",
"@llvm-project//mlir:MemRefDialect",
"@llvm-project//mlir:QuantOps",
"@llvm-project//mlir:SCFDialect",
"@llvm-project//mlir:SCFToGPU",
"@llvm-project//mlir:SCFTransforms",
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/iree/compiler/Tools/init_mlir_dialects.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
#include "mlir/Dialect/NVGPU/IR/NVGPUDialect.h"
#include "mlir/Dialect/PDL/IR/PDL.h"
#include "mlir/Dialect/PDLInterp/IR/PDLInterp.h"
#include "mlir/Dialect/Quant/QuantOps.h"
#include "mlir/Dialect/Quant/IR/Quant.h"
#include "mlir/Dialect/SCF/IR/SCF.h"
#include "mlir/Dialect/SCF/TransformOps/SCFTransformOps.h"
#include "mlir/Dialect/SPIRV/IR/SPIRVDialect.h"
Expand Down Expand Up @@ -81,7 +81,7 @@ inline void registerMlirDialects(DialectRegistry &registry) {
pdl::PDLDialect,
pdl_interp::PDLInterpDialect,
scf::SCFDialect,
quant::QuantizationDialect,
quant::QuantDialect,
spirv::SPIRVDialect,
arm_neon::ArmNeonDialect,
arm_sve::ArmSVEDialect,
Expand Down
2 changes: 1 addition & 1 deletion third_party/llvm-project
Submodule llvm-project updated 39 files
+2 −6 mlir/include/mlir/Dialect/Quant/CMakeLists.txt
+6 −0 mlir/include/mlir/Dialect/Quant/IR/CMakeLists.txt
+16 −6 mlir/include/mlir/Dialect/Quant/IR/Quant.h
+297 −0 mlir/include/mlir/Dialect/Quant/IR/QuantBase.td
+0 −0 mlir/include/mlir/Dialect/Quant/IR/QuantDialectBytecode.td
+243 −0 mlir/include/mlir/Dialect/Quant/IR/QuantOps.td
+7 −3 mlir/include/mlir/Dialect/Quant/IR/QuantTypes.h
+0 −103 mlir/include/mlir/Dialect/Quant/QuantOps.td
+0 −74 mlir/include/mlir/Dialect/Quant/QuantOpsBase.td
+5 −0 mlir/include/mlir/Dialect/Quant/Transforms/CMakeLists.txt
+29 −0 mlir/include/mlir/Dialect/Quant/Transforms/Passes.h
+49 −0 mlir/include/mlir/Dialect/Quant/Transforms/Passes.td
+4 −4 mlir/include/mlir/Dialect/Quant/Utils/FakeQuantSupport.h
+4 −4 mlir/include/mlir/Dialect/Quant/Utils/UniformSupport.h
+1 −1 mlir/include/mlir/Dialect/Tosa/IR/TosaOpBase.td
+2 −2 mlir/include/mlir/Dialect/Tosa/Utils/QuantUtils.h
+2 −2 mlir/include/mlir/InitAllDialects.h
+2 −0 mlir/include/mlir/InitAllPasses.h
+3 −3 mlir/lib/CAPI/Dialect/Quant.cpp
+1 −0 mlir/lib/Dialect/Quant/CMakeLists.txt
+4 −4 mlir/lib/Dialect/Quant/IR/QuantDialectBytecode.cpp
+2 −2 mlir/lib/Dialect/Quant/IR/QuantDialectBytecode.h
+187 −22 mlir/lib/Dialect/Quant/IR/QuantOps.cpp
+44 −3 mlir/lib/Dialect/Quant/IR/QuantTypes.cpp
+5 −10 mlir/lib/Dialect/Quant/IR/TypeParser.cpp
+26 −0 mlir/lib/Dialect/Quant/Transforms/CMakeLists.txt
+676 −0 mlir/lib/Dialect/Quant/Transforms/LowerQuantOps.cpp
+114 −0 mlir/lib/Dialect/Quant/Transforms/StripFuncQuantTypes.cpp
+2 −2 mlir/lib/Dialect/Quant/Utils/FakeQuantSupport.cpp
+1 −1 mlir/lib/Dialect/Quant/Utils/UniformSupport.cpp
+1 −1 mlir/lib/Dialect/Tosa/IR/TosaCanonicalizations.cpp
+1 −1 mlir/lib/Dialect/Tosa/IR/TosaOps.cpp
+117 −17 mlir/test/Dialect/Quant/canonicalize.mlir
+258 −0 mlir/test/Dialect/Quant/invalid.mlir
+511 −0 mlir/test/Dialect/Quant/lower-quant-ops.mlir
+151 −0 mlir/test/Dialect/Quant/ops.mlir
+25 −0 mlir/test/Dialect/Quant/parse-uniform-invalid.mlir
+88 −0 mlir/test/Dialect/Quant/strip-func-quant-types.mlir
+55 −13 utils/bazel/llvm-project-overlay/mlir/BUILD.bazel
2 changes: 1 addition & 1 deletion third_party/stablehlo
Submodule stablehlo updated 6601 files
2 changes: 1 addition & 1 deletion third_party/torch-mlir

0 comments on commit 7a2705d

Please sign in to comment.