Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[transform] add disc_linalg_ext::multi_level_pack op #838

Merged
merged 1 commit into from
Dec 7, 2022
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
4 changes: 3 additions & 1 deletion scripts/python/tao_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,8 @@ def test_tao_compiler(root, args):
"//tensorflow/compiler/mlir/disc/tools/disc-source-emitter/tests/..."
]
TARGET_DISC_TRANSFORM_DIALECT_TESTS = [
"//tensorflow/compiler/mlir/disc/tools/disc-transform/transforms/tests/..."
"//tensorflow/compiler/mlir/disc/tools/disc-transform/transforms/tests/...",
"//tensorflow/compiler/mlir/disc/tools/disc-transform/LinalgExt/tests/...",
]

TARGET_DISC_REPLAY_TEST = "//tensorflow/compiler/mlir/disc/tools/disc-replay:disc-replay-test"
Expand All @@ -388,6 +389,7 @@ def bazel_test(target, flag=""):
if targets is not None and target not in targets:
return
logger.info("Testing bazel target: " + target)
flag += " --experimental_ui_max_stdouterr_bytes=-1 "
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could be in ./tao_compiler/.bazelrc.user.

execute(" ".join([BAZEL_BUILD_CMD, flag, target]))
execute(" ".join([BAZEL_TEST_CMD, flag + ' --test_env=TF_CPP_VMODULE=disc_compiler=1 --test_env=TF_ENABLE_ONEDNN_OPTS=0' , target]))

Expand Down
2 changes: 2 additions & 0 deletions tao_compiler/mlir/disc/tools/disc-opt/disc-opt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ limitations under the License.
#include "tensorflow/compiler/mlir/disc/IR/disc_shape_ops.h"
#include "tensorflow/compiler/mlir/disc/IR/hlo_disc_ops.h"
#include "tensorflow/compiler/mlir/disc/IR/lhlo_disc_ops.h"
#include "tensorflow/compiler/mlir/disc/tools/disc-transform/LinalgExt/LinalgExtDialect.h"
#include "tensorflow/compiler/mlir/disc/tools/disc-transform/TransformOps/TransformOpsExt.h"
#include "tensorflow/compiler/mlir/disc/tools/disc-transform/transforms/register_passes.h"
#include "tensorflow/compiler/mlir/disc/transforms/register_passes.h"
Expand All @@ -56,6 +57,7 @@ int main(int argc, char** argv) {
registry.insert<mlir::lmhlo_disc::LmhloDiscDialect>();
registry.insert<mlir::lmhlo_gpu::LmhloGpuDialect>();
registry.insert<mlir::disc_ral::RalDialect>();
registry.insert<mlir::disc_ral::disc_linalg_ext::DISCLinalgExtDialect>();
registry.insert<mlir::TF::TensorFlowDialect>();
registry.insert<mlir::disc_shape::DISCShapeDialect>();
registry.insert<mlir::iree_compiler::IREE::LinalgExt::IREELinalgExtDialect,
Expand Down
124 changes: 124 additions & 0 deletions tao_compiler/mlir/disc/tools/disc-transform/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,129 @@ package_group(
],
)

td_library(
name = "LinalgExtTdFiles",
srcs = glob([
"LinalgExt/*.td",
]),
deps = [
"@llvm-project//mlir:BuiltinDialectTdFiles",
"@llvm-project//mlir:InferTypeOpInterfaceTdFiles",
"@llvm-project//mlir:OpBaseTdFiles",
"@llvm-project//mlir:PDLDialectTdFiles",
"@llvm-project//mlir:SideEffectInterfacesTdFiles",
"@llvm-project//mlir:TransformDialectTdFiles",
],
)

gentbl_cc_library(
name = "DISCLinalgExtIncGen",
tbl_outs = [
(
[
"--dialect=disc_linalg_ext",
"--gen-dialect-decls",
],
"LinalgExt/LinalgExtDialect.h.inc",
),
(
[
"--dialect=disc_linalg_ext",
"--gen-dialect-defs",
],
"LinalgExt/LinalgExtDialect.cc.inc",
),
(
["--gen-op-decls"],
"LinalgExt/LinalgExtOps.h.inc",
),
(
["--gen-op-defs"],
"LinalgExt/LinalgExtOps.cc.inc",
),
(
["--gen-typedef-decls"],
"LinalgExt/LinalgExtTypes.h.inc",
),
(
["--gen-typedef-defs"],
"LinalgExt/LinalgExtTypes.cc.inc",
),
],
tblgen = "@llvm-project//mlir:mlir-tblgen",
td_file = "LinalgExt/LinalgExtOps.td",
deps = [
":LinalgExtTdFiles",
"@llvm-project//mlir:CallInterfacesTdFiles",
"@llvm-project//mlir:ControlFlowInterfacesTdFiles",
"@llvm-project//mlir:InferTypeOpInterfaceTdFiles",
"@llvm-project//mlir:TilingInterfaceTdFiles",
"@llvm-project//mlir:ViewLikeInterfaceTdFiles",
],
)

gentbl_cc_library(
name = "DISCLinalgExtInterfacesIncGen",
tbl_outs = [
(
["--gen-op-interface-decls"],
"LinalgExt/LinalgExtOpInterfaces.h.inc",
),
(
["--gen-op-interface-defs"],
"LinalgExt/LinalgExtOpInterfaces.cc.inc",
),
(
["--gen-type-interface-decls"],
"LinalgExt/LinalgExtTypeInterfaces.h.inc",
),
(
["--gen-type-interface-defs"],
"LinalgExt/LinalgExtTypeInterfaces.cc.inc",
),
],
tblgen = "@llvm-project//mlir:mlir-tblgen",
td_file = "LinalgExt/LinalgExtInterfaces.td",
deps = [
":LinalgExtTdFiles",
],
)

cc_library(
name = "DISCLinalgExtDialect",
srcs = glob([
"LinalgExt/*.cc",
]),
hdrs = glob([
"LinalgExt/*.h",
]),
deps = [
":DISCLinalgExtIncGen",
":DISCLinalgExtInterfacesIncGen",
"@llvm-project//llvm:Support",
"@llvm-project//mlir:AffineDialect",
"@llvm-project//mlir:AffineUtils",
"@llvm-project//mlir:ArithDialect",
"@llvm-project//mlir:ArithUtils",
"@llvm-project//mlir:ControlFlowInterfaces",
"@llvm-project//mlir:DialectUtils",
"@llvm-project//mlir:FuncDialect",
"@llvm-project//mlir:IR",
"@llvm-project//mlir:InferTypeOpInterface",
"@llvm-project//mlir:LinalgDialect",
"@llvm-project//mlir:MathDialect",
"@llvm-project//mlir:MemRefDialect",
"@llvm-project//mlir:Pass",
"@llvm-project//mlir:SCFDialect",
"@llvm-project//mlir:SideEffectInterfaces",
"@llvm-project//mlir:Support",
"@llvm-project//mlir:TensorDialect",
"@llvm-project//mlir:TensorUtils",
"@llvm-project//mlir:ViewLikeInterface",
],
alwayslink = 1,
)

gentbl_cc_library(
name = "transform_ops_inc_gen",
compatible_with = get_compatible_with_cloud(),
Expand Down Expand Up @@ -78,6 +201,7 @@ cc_library(
"TransformOps/TransformOpsExt.h",
],
deps = [
":DISCLinalgExtDialect",
":disc_transform_utils",
":transform_ops_inc_gen",
"@iree-dialects//:IREELinalgExtDialect",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright 2022 The BladeDISC Authors. All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef IREE_DIALECT_LINALGEXT_BASE
#define IREE_DIALECT_LINALGEXT_BASE

include "mlir/IR/OpBase.td"

//===----------------------------------------------------------------------===//
// Dialect definition
//===----------------------------------------------------------------------===//

def DISCLinalgExt_Dialect : Dialect {
let name = "disc_linalg_ext";
let cppNamespace = "::mlir::disc_ral::disc_linalg_ext";
let description = [{
The `disc_linalg_ext` dialect is intended to experiment more support for
non-structured operations, ie, can not be represented in Linalg operations.
}];
let hasCanonicalizer = 1;
let useDefaultAttributePrinterParser = 0;
}

//===----------------------------------------------------------------------===//
// Type definitions
//===----------------------------------------------------------------------===//

class RankedTensorOrMemRefOf<list<Type> allowedTypes> :
ShapedContainerType<allowedTypes,
Or<[IsMemRefTypePred, And<[IsTensorTypePred, HasRankPred]>]>,
"ranked tensor or memref", "::mlir::ShapedType">;

def AnyRankedTensorOrMemRefType : RankedTensorOrMemRefOf<[AnyType]>;

#endif // IREE_DIALECT_LINALGEXT_BASE
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright 2022 The BladeDISC Authors. All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "tensorflow/compiler/mlir/disc/tools/disc-transform/LinalgExt/LinalgExtDialect.h"

#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/TypeSwitch.h"
#include "llvm/Support/SourceMgr.h"
#include "mlir/IR/Attributes.h"
#include "mlir/IR/DialectImplementation.h"
#include "mlir/IR/OpDefinition.h"
#include "mlir/IR/OpImplementation.h"
#include "tensorflow/compiler/mlir/disc/tools/disc-transform/LinalgExt/LinalgExtDialect.cc.inc"
#include "tensorflow/compiler/mlir/disc/tools/disc-transform/LinalgExt/LinalgExtOps.h"

namespace mlir {
namespace disc_ral {
namespace disc_linalg_ext {

void DISCLinalgExtDialect::initialize() {
#define GET_OP_LIST
addOperations<
#include "tensorflow/compiler/mlir/disc/tools/disc-transform/LinalgExt/LinalgExtOps.cc.inc"
>();
}

} // namespace disc_linalg_ext
} // namespace disc_ral
} // namespace mlir
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright 2022 The BladeDISC Authors. All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef DISC_TOOLS_DISC_TRANSFORM_LINALGEXT_DIALECT_EXT_
#define DISC_TOOLS_DISC_TRANSFORM_LINALGEXT_DIALECT_EXT_

#include "mlir/IR/Dialect.h"
#include "mlir/IR/OpDefinition.h"
#include "tensorflow/compiler/mlir/disc/tools/disc-transform/LinalgExt/LinalgExtDialect.h.inc"

#endif // DISC_TOOLS_DISC_TRANSFORM_LINALGEXT_DIALECT_EXT_
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// Copyright 2022 The BladeDISC Authors. All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "tensorflow/compiler/mlir/disc/tools/disc-transform/LinalgExt/LinalgExtInterfaces.h"

#include "mlir/Dialect/Arith/IR/Arith.h"
#include "mlir/Dialect/MemRef/IR/MemRef.h"
#include "mlir/Dialect/Tensor/IR/Tensor.h"

namespace mlir {
namespace disc_ral {
namespace disc_linalg_ext {

namespace detail {

LogicalResult verifyLinalgExtOpInterface(Operation* op) {
LinalgExtOp linalgExtOp = cast<LinalgExtOp>(op);
if (op->getNumResults()) {
if (op->getNumResults() != linalgExtOp.getNumOutputs()) {
return linalgExtOp.emitOpError(
"expected number of outputs to be same as the number of results");
}
for (auto en : llvm::enumerate(op->getResultTypes())) {
Type outputType = linalgExtOp.getOutputs()[en.index()].getType();
if (en.value() != outputType) {
return linalgExtOp.emitOpError("expected type of `outs` operand #")
<< en.index() << " " << outputType
<< " to be same as result type " << en.value();
}
}
}
return success();
}

} // namespace detail

#include "tensorflow/compiler/mlir/disc/tools/disc-transform/LinalgExt/LinalgExtOpInterfaces.cc.inc"

template <typename Ty, typename DimOpTy>
static void getDimValues(OpBuilder& b, Location loc, Value v, Ty t,
SmallVector<Value>& dimVals) {
for (auto dim : llvm::enumerate(t.getShape())) {
if (ShapedType::isDynamic(dim.value())) {
dimVals.push_back(b.create<DimOpTy>(loc, v, dim.index()));
} else {
dimVals.push_back(b.create<arith::ConstantIndexOp>(loc, dim.value()));
}
}
}

LogicalResult LinalgExtOp::reifyResultShapes(
OpBuilder& b, ReifiedRankedShapedTypeDims& reifiedReturnShapes) {
Operation* op = getOperation();
for (auto output : getOutputs()) {
SmallVector<Value> dims;
Type outputType = output.getType();
if (auto rankedTensorType = outputType.dyn_cast<RankedTensorType>()) {
getDimValues<RankedTensorType, tensor::DimOp>(b, op->getLoc(), output,
rankedTensorType, dims);
} else if (auto memrefType = outputType.dyn_cast<MemRefType>()) {
getDimValues<MemRefType, memref::DimOp>(b, op->getLoc(), output,
memrefType, dims);
} else if (!outputType.isIntOrIndexOrFloat()) {
return op->emitOpError(
"invalid type for output operand, expected tensor, "
"memref or scalar type");
}
reifiedReturnShapes.emplace_back(std::move(dims));
}
return success();
}

} // namespace disc_linalg_ext
} // namespace disc_ral
} // namespace mlir
Loading