summaryrefslogtreecommitdiffstats
path: root/mlir/lib/Dialect/Linalg/Transforms/Promotion.cpp
diff options
context:
space:
mode:
authorNicolas Vasilache <ntv@google.com>2020-01-11 02:22:00 -0500
committerNicolas Vasilache <ntv@google.com>2020-01-14 17:25:28 -0500
commitf52d71736b10e87b1aa1880b777dc9462a0085ce (patch)
tree3eaa824f59037e0b987abd0c39094ec999e04c3c /mlir/lib/Dialect/Linalg/Transforms/Promotion.cpp
parent8d07f8d98c48ee0a9dca450aaf4e1cabc621ff68 (diff)
downloadbcm5719-llvm-f52d71736b10e87b1aa1880b777dc9462a0085ce.tar.gz
bcm5719-llvm-f52d71736b10e87b1aa1880b777dc9462a0085ce.zip
[mlir][Linalg] Update the semantics, verifier and test for Linalg with tensors.
Summary: This diff fixes issues with the semantics of linalg.generic on tensors that appeared when converting directly from HLO to linalg.generic. The changes are self-contained within MLIR and can be captured and tested independently of XLA. The linalg.generic and indexed_generic are updated to: To allow progressive lowering from the value world (a.k.a tensor values) to the buffer world (a.k.a memref values), a linalg.generic op accepts mixing input and output ranked tensor values with input and output memrefs. ``` %1 = linalg.generic #trait_attribute %A, %B {other-attributes} : tensor<?x?xf32>, memref<?x?xf32, stride_specification> -> (tensor<?x?xf32>) ``` In this case, the number of outputs (args_out) must match the sum of (1) the number of output buffer operands and (2) the number of tensor return values. The semantics is that the linalg.indexed_generic op produces (i.e. allocates and fills) its return values. Tensor values must be legalized by a buffer allocation pass before most transformations can be applied. Such legalization moves tensor return values into output buffer operands and updates the region argument accordingly. Transformations that create control-flow around linalg.indexed_generic operations are not expected to mix with tensors because SSA values do not escape naturally. Still, transformations and rewrites that take advantage of tensor SSA values are expected to be useful and will be added in the near future. Subscribers: bmahjour, mehdi_amini, rriddle, jpienaar, burmako, shauheen, antiagainst, arpith-jacob, mgester, lucyrfox, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D72555
Diffstat (limited to 'mlir/lib/Dialect/Linalg/Transforms/Promotion.cpp')
-rw-r--r--mlir/lib/Dialect/Linalg/Transforms/Promotion.cpp11
1 files changed, 8 insertions, 3 deletions
diff --git a/mlir/lib/Dialect/Linalg/Transforms/Promotion.cpp b/mlir/lib/Dialect/Linalg/Transforms/Promotion.cpp
index eb605699890..3caa8c8d1f0 100644
--- a/mlir/lib/Dialect/Linalg/Transforms/Promotion.cpp
+++ b/mlir/lib/Dialect/Linalg/Transforms/Promotion.cpp
@@ -155,6 +155,8 @@ LinalgOp mlir::linalg::promoteSubViewOperands(OpBuilder &b, LinalgOp op,
SetVector<Value> subViews,
bool dynamicBuffers,
OperationFolder *folder) {
+ assert(op.hasBufferSemantics() && "expected linalg op with buffer semantics");
+
// 1. Promote the specified views and use them in the new op.
ScopedContext scope(b, op.getLoc());
auto promotedBufferAndViews = promoteSubViews(
@@ -164,7 +166,7 @@ LinalgOp mlir::linalg::promoteSubViewOperands(OpBuilder &b, LinalgOp op,
SmallVector<std::pair<Value, Value>, 8> writebackViews;
writebackViews.reserve(subViews.size());
unsigned promotedIdx = 0;
- for (auto view : op.getInputsAndOutputs()) {
+ for (auto view : op.getInputsAndOutputBuffers()) {
if (subViews.count(view) != 0) {
opViews.push_back(promotedBufferAndViews[promotedIdx].fullLocalView);
writebackViews.emplace_back(std::make_pair(
@@ -187,7 +189,7 @@ LinalgOp mlir::linalg::promoteSubViewOperands(OpBuilder &b, LinalgOp op,
// WARNING: MUST use the old op to determine whether the operand view is an
// output.
bool isOutput =
- op.getIndexOfOutput(viewAndPartialLocalView.first).hasValue();
+ op.getIndexOfOutputBuffer(viewAndPartialLocalView.first).hasValue();
if (isOutput)
copy(viewAndPartialLocalView.second, viewAndPartialLocalView.first);
}
@@ -203,11 +205,14 @@ static void promoteSubViews(FuncOp f, bool dynamicBuffers) {
SmallVector<LinalgOp, 8> toErase;
OperationFolder folder(f.getContext());
f.walk([dynamicBuffers, &folder, &toErase](LinalgOp op) {
+ if (!op.hasBufferSemantics())
+ return;
+
// TODO(ntv) some heuristic here to decide what to promote. Atm it is all or
// nothing.
SetVector<Value> subViews;
OpBuilder b(op);
- for (auto it : op.getInputsAndOutputs())
+ for (auto it : op.getInputsAndOutputBuffers())
if (auto sv = dyn_cast_or_null<SubViewOp>(it.getDefiningOp()))
subViews.insert(sv);
if (!subViews.empty()) {
OpenPOWER on IntegriCloud