Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion externals/llvm-project
Submodule llvm-project updated 14481 files
2 changes: 1 addition & 1 deletion externals/stablehlo
Submodule stablehlo updated 75 files
+19 −0 BUILD.bazel
+2 −1 MODULE.bazel
+423 −1,433 MODULE.bazel.lock
+2 −2 WORKSPACE.bazel
+1 −1 build_tools/llvm_version.txt
+3 −0 docs/dynamism.md
+1 −1 docs/generated/FuncBuilder.md
+5 −5 docs/generated/StablehloBuilder.md
+26 −0 docs/generated/stablehlo_passes.md
+4 −4 docs/spec.md
+2 −2 examples/c++/ExampleAdd.cpp
+10 −1 stablehlo/conversions/linalg/tests/miscellaneous.mlir
+6 −6 stablehlo/conversions/linalg/tests/pointwise.mlir
+3 −3 stablehlo/conversions/linalg/transforms/LegalizeToLinalgUtils.cpp
+194 −192 stablehlo/conversions/linalg/transforms/MapStablehloToScalarOp.h
+31 −19 stablehlo/conversions/linalg/transforms/StablehloLegalizeToLinalg.cpp
+3 −1 stablehlo/conversions/linalg/transforms/StablehloToArith.cpp
+12 −14 stablehlo/conversions/linalg/transforms/StablehloToLinalgPointwise.cpp
+182 −179 stablehlo/conversions/linalg/transforms/StablehloToLinalgRandom.cpp
+70 −70 stablehlo/conversions/linalg/transforms/StablehloToLinalgReduce.cpp
+5 −6 stablehlo/conversions/linalg/transforms/TypeConversion.cpp
+9 −0 stablehlo/conversions/tosa/tests/binary.mlir
+60 −23 stablehlo/conversions/tosa/transforms/StablehloLegalizeToTosa.cpp
+6 −6 stablehlo/conversions/tosa/transforms/StablehloLegalizeToTosa.pdll
+9 −11 stablehlo/conversions/tosa/transforms/StablehloQuantLegalizeToTosaRescale.cpp
+19 −19 stablehlo/conversions/tosa/transforms/TosaRescaleLegalizeToStablehlo.cpp
+1 −1 stablehlo/dialect/Base.cpp
+1 −1 stablehlo/dialect/Base.td
+2 −2 stablehlo/dialect/ChloOps.cpp
+136 −79 stablehlo/dialect/StablehloOps.cpp
+40 −29 stablehlo/dialect/StablehloOps.h
+2 −2 stablehlo/dialect/Version.cpp
+1 −1 stablehlo/dialect/Version.h
+1 −1 stablehlo/dialect/VhloTypes.cpp
+4 −1 stablehlo/integrations/cpp/builder/MlirBuilderTblgen.cpp
+26 −0 stablehlo/integrations/cpp/builder/StablehloBuilder.cpp
+13 −0 stablehlo/integrations/cpp/builder/StablehloBuilder.h
+76 −0 stablehlo/integrations/cpp/builder/StablehloBuilderTest.cpp
+1 −1 stablehlo/integrations/python/mlir/dialects/InterpreterOps.td
+8 −22 stablehlo/integrations/python/tests/testdata_generator_test.py
+2 −2 stablehlo/reference/InterpreterInstrumentWithProbe.cpp
+10 −9 stablehlo/reference/InterpreterOps.cpp
+2 −0 stablehlo/tests/BUILD.bazel
+1 −0 stablehlo/tests/CMakeLists.txt
+78 −34 stablehlo/tests/TestUtils.cpp
+5 −0 stablehlo/tests/TestUtils.td
+322 −0 stablehlo/tests/ops_broadcasting.mlir
+100 −15 stablehlo/tests/transforms/stablehlo_aggressive_folder.mlir
+109 −0 stablehlo/tests/transforms/stablehlo_aggressive_simplification.mlir
+44 −0 stablehlo/tests/transforms/stablehlo_check_shape_assertions.mlir
+3 −3 stablehlo/tests/transforms/stablehlo_refine_shapes.mlir
+26 −0 stablehlo/tests/transforms/stablehlo_target_independent_optimization.mlir
+10 −0 stablehlo/transforms/CMakeLists.txt
+557 −525 stablehlo/transforms/ChloLegalizeToStablehlo.cpp
+6 −6 stablehlo/transforms/PassUtils.cpp
+29 −0 stablehlo/transforms/Passes.td
+74 −66 stablehlo/transforms/ShapeLegalizeToStablehlo.cpp
+297 −0 stablehlo/transforms/StablehloBroadcastLowering.cpp
+68 −0 stablehlo/transforms/StablehloBroadcastLowering.h
+4 −4 stablehlo/transforms/StablehloCanonicalizeDynamism.cpp
+204 −0 stablehlo/transforms/StablehloCheckShapeAssertions.cpp
+18 −18 stablehlo/transforms/StablehloCompatibilityExpander.cpp
+6 −6 stablehlo/transforms/StablehloLegalizeCompositeToCall.cpp
+7 −7 stablehlo/transforms/StablehloLegalizeDeprecatedOps.cpp
+263 −239 stablehlo/transforms/StablehloLegalizeQuantToMath.cpp
+5 −7 stablehlo/transforms/StablehloLegalizeQuantizedOpToQDQ.cpp
+5 −5 stablehlo/transforms/StablehloLegalizeToVhlo.cpp
+6 −4 stablehlo/transforms/StablehloRefineArguments.cpp
+7 −6 stablehlo/transforms/StablehloRefineShapes.cpp
+11 −9 stablehlo/transforms/StablehloWrapInComposite.cpp
+6 −5 stablehlo/transforms/VhloLegalizeToStablehlo.cpp
+4 −4 stablehlo/transforms/conversions/TypeConversion.cpp
+153 −25 stablehlo/transforms/optimization/StablehloAggressiveFolder.cpp
+100 −50 stablehlo/transforms/optimization/StablehloAggressiveSimplification.cpp
+104 −31 stablehlo/transforms/optimization/StablehloAggressiveSimplificationPatterns.td
33 changes: 23 additions & 10 deletions lib/Conversion/Utils/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,18 @@ Value createZeroInitTensor(OpBuilder &b, Location loc, ValueRange sizes,
Value initTensor =
tensor::EmptyOp::create(b, loc, getAsOpFoldResult(sizes), elemTy);

Type fillValElemTy = elemTy;
if (auto dtypeComplex = dyn_cast<mlir::ComplexType>(elemTy))
fillValElemTy = cast<mlir::FloatType>(dtypeComplex.getElementType());

Value c0 = arith::ConstantOp::create(b, loc, b.getZeroAttr(fillValElemTy));
Value c0;
if (auto dtypeComplex = dyn_cast<mlir::ComplexType>(elemTy)) {
// For complex types, create a complex zero (0.0 + 0.0j)
Type floatType = cast<mlir::FloatType>(dtypeComplex.getElementType());
Value realZero =
arith::ConstantOp::create(b, loc, b.getZeroAttr(floatType));
Value imagZero =
arith::ConstantOp::create(b, loc, b.getZeroAttr(floatType));
c0 = complex::CreateOp::create(b, loc, elemTy, realZero, imagZero);
} else {
c0 = arith::ConstantOp::create(b, loc, b.getZeroAttr(elemTy));
}
return linalg::FillOp::create(b, loc, c0, initTensor).getResult(0);
}

Expand All @@ -147,11 +154,17 @@ Value createOneInitTensor(OpBuilder &b, Location loc, ValueRange sizes,
Value initTensor =
tensor::EmptyOp::create(b, loc, getAsOpFoldResult(sizes), elemTy);

Type fillValElemTy = elemTy;
if (auto dtypeComplex = dyn_cast<mlir::ComplexType>(elemTy))
fillValElemTy = cast<mlir::FloatType>(dtypeComplex.getElementType());

Value c1 = arith::ConstantOp::create(b, loc, b.getOneAttr(fillValElemTy));
Value c1;
if (auto dtypeComplex = dyn_cast<mlir::ComplexType>(elemTy)) {
// For complex types, create a complex one (1.0 + 0.0j)
Type floatType = cast<mlir::FloatType>(dtypeComplex.getElementType());
Value realOne = arith::ConstantOp::create(b, loc, b.getOneAttr(floatType));
Value imagZero =
arith::ConstantOp::create(b, loc, b.getZeroAttr(floatType));
c1 = complex::CreateOp::create(b, loc, elemTy, realOne, imagZero);
} else {
c1 = arith::ConstantOp::create(b, loc, b.getOneAttr(elemTy));
}
return linalg::FillOp::create(b, loc, c1, initTensor).getResult(0);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
//===----------------------------------------------------------------------===//

#include "mlir/Dialect/Arith/IR/Arith.h"
#include "mlir/Dialect/ControlFlow/Transforms/StructuralTypeConversions.h"
#include "mlir/Dialect/Func/IR/FuncOps.h"
#include "mlir/Dialect/Func/Transforms/FuncConversions.h"
#include "mlir/IR/BuiltinOps.h"
Expand Down Expand Up @@ -60,14 +61,14 @@ void populateFuncBackendTypeConversionPatterns(TypeConverter &typeConverter,
populateFunctionOpInterfaceTypeConversionPattern<func::FuncOp>(patterns,
typeConverter);
target.addDynamicallyLegalOp<func::FuncOp>([&](func::FuncOp op) {
return typeConverter.isSignatureLegal(op.getFunctionType()) &&
typeConverter.isLegal(&op.getBody());
return typeConverter.isSignatureLegal(op.getFunctionType());
});
populateCallOpTypeConversionPattern(patterns, typeConverter);
target.addDynamicallyLegalOp<func::CallOp>(
[&](func::CallOp op) { return typeConverter.isLegal(op); });

populateBranchOpInterfaceTypeConversionPattern(patterns, typeConverter);
cf::populateCFStructuralTypeConversionsAndLegality(typeConverter, patterns,
target);
populateReturnOpTypeConversionPattern(patterns, typeConverter);
target.addLegalOp<ModuleOp>();

Expand Down
1 change: 1 addition & 0 deletions lib/Dialect/TorchConversion/Transforms/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
set(LinkedLibs
MLIRFuncTransforms
MLIRControlFlowTransforms
MLIRIR
MLIRLinalgTransforms
MLIRMemRefTransforms
Expand Down
6 changes: 4 additions & 2 deletions test/Conversion/TorchToLinalg/spectral.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
// CHECK-DAG: %[[CST_0:.*]] = arith.constant dense<{{.*}}> : tensor<9x5xcomplex<f32>>
// CHECK: %[[VAR0:.*]] = torch_c.to_builtin_tensor %arg0 : !torch.vtensor<[16,9],f32> -> tensor<16x9xf32>
// CHECK-DAG: %[[VAR1:.*]] = tensor.empty() : tensor<16x5xcomplex<f32>>
// CHECK: %[[VAR2:.*]] = linalg.fill ins(%[[CST]] : f32) outs(%[[VAR1]] : tensor<16x5xcomplex<f32>>) -> tensor<16x5xcomplex<f32>>
// CHECK-DAG: %[[CPLX:.*]] = complex.create %[[CST]], %[[CST]] : complex<f32>
// CHECK: %[[VAR2:.*]] = linalg.fill ins(%[[CPLX]] : complex<f32>) outs(%[[VAR1]] : tensor<16x5xcomplex<f32>>) -> tensor<16x5xcomplex<f32>>
// CHECK: %[[VAR3:.*]] = linalg.generic {indexing_maps = [#map, #map1, #map2], iterator_types = ["parallel", "reduction", "parallel"]} ins(%[[VAR0]], %[[CST_0]] : tensor<16x9xf32>, tensor<9x5xcomplex<f32>>) outs(%[[VAR2]] : tensor<16x5xcomplex<f32>>) {
// CHECK: ^bb0(%in: f32, %in_1: complex<f32>, %out: complex<f32>):
// CHECK: %[[VAR5:.*]] = complex.re %in_1 : complex<f32>
Expand Down Expand Up @@ -41,7 +42,8 @@ func.func @torch.aten.fft_rfft$2d_last_dim(%arg0: !torch.vtensor<[16,9],f32>) ->
// CHECK-DAG: %[[VAR1:.*]] = tensor.empty() : tensor<23x36xf32>
// CHECK: %[[TRANSPOSED:.*]] = linalg.transpose ins(%[[VAR0]] : tensor<36x23xf32>) outs(%[[VAR1]] : tensor<23x36xf32>) permutation = [1, 0]
// CHECK-DAG: %[[VAR2:.*]] = tensor.empty() : tensor<23x19xcomplex<f32>>
// CHECK: %[[VAR3:.*]] = linalg.fill ins(%[[CST]] : f32) outs(%[[VAR2]] : tensor<23x19xcomplex<f32>>) -> tensor<23x19xcomplex<f32>>
// CHECK-DAG: %[[CPLX:.*]] = complex.create %[[CST]], %[[CST]] : complex<f32>
// CHECK: %[[VAR3:.*]] = linalg.fill ins(%[[CPLX]] : complex<f32>) outs(%[[VAR2]] : tensor<23x19xcomplex<f32>>) -> tensor<23x19xcomplex<f32>>
// CHECK: %[[VAR4:.*]] = linalg.generic {indexing_maps = [#map, #map1, #map2], iterator_types = ["parallel", "reduction", "parallel"]} ins(%[[TRANSPOSED]], %[[CST_0]] : tensor<23x36xf32>, tensor<36x19xcomplex<f32>>) outs(%[[VAR3]] : tensor<23x19xcomplex<f32>>) {
// CHECK: ^bb0(%in: f32, %in_2: complex<f32>, %out: complex<f32>):
// CHECK: %[[VAR7:.*]] = complex.re %in_2 : complex<f32>
Expand Down
Loading