-
Notifications
You must be signed in to change notification settings - Fork 160
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
tao_compiler/mlir/disc/tools/disc-transform/LinalgExt/LinalgExtBase.td
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
37 changes: 37 additions & 0 deletions
37
tao_compiler/mlir/disc/tools/disc-transform/LinalgExt/LinalgExtDialect.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
19 changes: 19 additions & 0 deletions
19
tao_compiler/mlir/disc/tools/disc-transform/LinalgExt/LinalgExtDialect.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_ |
83 changes: 83 additions & 0 deletions
83
tao_compiler/mlir/disc/tools/disc-transform/LinalgExt/LinalgExtInterfaces.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
.