2019-12-13 13:26:00 -08:00
|
|
|
//===- Builders.cpp - MLIR Declarative Linalg Builders --------------------===//
|
|
|
|
//
|
2020-01-26 03:58:30 +00:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
2019-12-23 09:35:36 -08:00
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2019-12-13 13:26:00 -08:00
|
|
|
//
|
2019-12-23 09:35:36 -08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2019-12-13 13:26:00 -08:00
|
|
|
|
2020-02-10 11:55:02 -05:00
|
|
|
#include "mlir/IR/Builders.h"
|
2020-03-20 14:18:47 -07:00
|
|
|
#include "mlir/Dialect/Affine/EDSC/Intrinsics.h"
|
2020-04-16 17:24:48 -04:00
|
|
|
#include "mlir/Dialect/Linalg/EDSC/Builders.h"
|
2019-12-16 13:32:02 -08:00
|
|
|
#include "mlir/Dialect/Linalg/EDSC/Intrinsics.h"
|
2020-05-11 15:00:48 +02:00
|
|
|
#include "mlir/Dialect/SCF/EDSC/Builders.h"
|
2020-02-10 11:55:02 -05:00
|
|
|
#include "mlir/Dialect/StandardOps/EDSC/Intrinsics.h"
|
[mlir][EDSC] NFC - Move StructuredIndexed and IteratorType out of Linalg
Summary:
This NFC revision will allow those classes to be reused to allow
building structured vector operations.
Reviewers: aartbik, ftynse
Subscribers: arphaman, mehdi_amini, rriddle, jpienaar, burmako, shauheen, antiagainst, arpith-jacob, mgester, lucyrfox, liufengdb, Joonsoo, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D74279
2020-02-08 11:16:22 -05:00
|
|
|
#include "mlir/Dialect/Utils/StructuredOpsUtils.h"
|
2019-12-13 13:26:00 -08:00
|
|
|
#include "mlir/IR/AffineExpr.h"
|
|
|
|
|
|
|
|
using namespace mlir;
|
|
|
|
using namespace mlir::edsc;
|
2019-12-13 16:35:49 -08:00
|
|
|
using namespace mlir::edsc::intrinsics;
|
[mlir][EDSC] Refactor dependencies involving EDSCs.
Summary: This diff removes the dependency of LinalgOps and VectorOps on EDSCs.
Reviewers: jpienaar, ftynse
Reviewed By: ftynse
Subscribers: merge_guards_bot, mgorny, mehdi_amini, rriddle, burmako, shauheen, antiagainst, csigg, arpith-jacob, mgester, lucyrfox, herhut, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D72481
2020-01-15 09:28:12 -05:00
|
|
|
using namespace mlir::linalg;
|
2020-05-11 15:00:48 +02:00
|
|
|
using namespace mlir::scf;
|
[mlir][EDSC] Refactor dependencies involving EDSCs.
Summary: This diff removes the dependency of LinalgOps and VectorOps on EDSCs.
Reviewers: jpienaar, ftynse
Reviewed By: ftynse
Subscribers: merge_guards_bot, mgorny, mehdi_amini, rriddle, burmako, shauheen, antiagainst, csigg, arpith-jacob, mgester, lucyrfox, herhut, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D72481
2020-01-15 09:28:12 -05:00
|
|
|
|
2020-01-02 09:14:23 -05:00
|
|
|
Operation *mlir::edsc::makeGenericLinalgOp(
|
[mlir][EDSC] NFC - Move StructuredIndexed and IteratorType out of Linalg
Summary:
This NFC revision will allow those classes to be reused to allow
building structured vector operations.
Reviewers: aartbik, ftynse
Subscribers: arphaman, mehdi_amini, rriddle, jpienaar, burmako, shauheen, antiagainst, arpith-jacob, mgester, lucyrfox, liufengdb, Joonsoo, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D74279
2020-02-08 11:16:22 -05:00
|
|
|
ArrayRef<IteratorType> iteratorTypes, ArrayRef<StructuredIndexed> inputs,
|
2020-01-21 19:43:27 -05:00
|
|
|
ArrayRef<StructuredIndexed> outputs,
|
2020-06-17 16:46:45 +02:00
|
|
|
function_ref<void(ValueRange)> regionBuilder, ArrayRef<Value> otherValues,
|
|
|
|
ArrayRef<Attribute> otherAttributes) {
|
[mlir][Linalg] Add tensor support to Linalg EDSC Builders
Summary:
This diff extends the Linalg EDSC builders so we can easily create mixed
tensor/buffer linalg.generic ops. This is expected to be useful for
HLO -> Linalg lowering.
The StructuredIndexed struct is made to derive from ValueHandle and can
now capture a type + indexing expressions. This is used to represent return
tensors.
Pointwise unary and binary builders are extended to allow both output buffers
and return tensors. This has implications on the number of region arguments.
Reviewers: ftynse, hanchung, asaadaldien
Subscribers: mehdi_amini, rriddle, jpienaar, burmako, shauheen, antiagainst, arpith-jacob, mgester, lucyrfox, aartbik, liufengdb, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D73149
2020-01-21 19:48:31 -05:00
|
|
|
for (unsigned i = 0, e = outputs.size(); i + 1 < e; ++i)
|
|
|
|
assert(!(outputs[i].getType().isa<RankedTensorType>() &&
|
|
|
|
outputs[i + 1].getType().isa<MemRefType>()) &&
|
|
|
|
"output tensors must be passed after output buffers");
|
2020-04-30 17:44:40 -04:00
|
|
|
auto &builder = edsc::ScopedContext::getBuilderRef();
|
2019-12-13 13:26:00 -08:00
|
|
|
auto *ctx = builder.getContext();
|
2019-12-13 16:35:49 -08:00
|
|
|
unsigned nInputs = inputs.size();
|
2020-01-21 19:43:27 -05:00
|
|
|
unsigned nOutputs = outputs.size();
|
2020-02-08 13:51:10 -05:00
|
|
|
|
|
|
|
SmallVector<SmallVector<AffineExpr, 4>, 4> exprsList;
|
|
|
|
exprsList.reserve(nInputs + nOutputs);
|
|
|
|
for (auto structuredIndexed : inputs)
|
|
|
|
exprsList.emplace_back(structuredIndexed.getExprs().begin(),
|
|
|
|
structuredIndexed.getExprs().end());
|
|
|
|
for (auto structuredIndexed : outputs)
|
|
|
|
exprsList.emplace_back(structuredIndexed.getExprs().begin(),
|
|
|
|
structuredIndexed.getExprs().end());
|
|
|
|
auto maps = AffineMap::inferFromExprList(exprsList);
|
2019-12-13 13:26:00 -08:00
|
|
|
|
2019-12-13 16:35:49 -08:00
|
|
|
unsigned nViews = nInputs + nOutputs;
|
2019-12-23 14:45:01 -08:00
|
|
|
SmallVector<Value, 4> values;
|
2019-12-13 16:35:49 -08:00
|
|
|
values.reserve(nViews);
|
|
|
|
values.append(inputs.begin(), inputs.end());
|
[mlir][Linalg] Add tensor support to Linalg EDSC Builders
Summary:
This diff extends the Linalg EDSC builders so we can easily create mixed
tensor/buffer linalg.generic ops. This is expected to be useful for
HLO -> Linalg lowering.
The StructuredIndexed struct is made to derive from ValueHandle and can
now capture a type + indexing expressions. This is used to represent return
tensors.
Pointwise unary and binary builders are extended to allow both output buffers
and return tensors. This has implications on the number of region arguments.
Reviewers: ftynse, hanchung, asaadaldien
Subscribers: mehdi_amini, rriddle, jpienaar, burmako, shauheen, antiagainst, arpith-jacob, mgester, lucyrfox, aartbik, liufengdb, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D73149
2020-01-21 19:48:31 -05:00
|
|
|
std::copy_if(outputs.begin(), outputs.end(), std::back_inserter(values),
|
|
|
|
[](StructuredIndexed s) { return s.hasValue(); });
|
|
|
|
SmallVector<Type, 4> types;
|
|
|
|
std::copy_if(outputs.begin(), outputs.end(), std::back_inserter(types),
|
|
|
|
[](StructuredIndexed s) { return !s.hasValue(); });
|
2019-12-13 13:26:00 -08:00
|
|
|
|
2020-04-13 14:07:38 -07:00
|
|
|
auto iteratorStrTypes =
|
|
|
|
llvm::to_vector<8>(llvm::map_range(iteratorTypes, toString));
|
2019-12-13 16:35:49 -08:00
|
|
|
// clang-format off
|
2019-12-13 13:26:00 -08:00
|
|
|
auto *op =
|
2020-04-30 17:44:40 -04:00
|
|
|
edsc::ScopedContext::getBuilderRef()
|
2019-12-13 13:26:00 -08:00
|
|
|
.create<linalg::GenericOp>(
|
2019-12-13 16:35:49 -08:00
|
|
|
edsc::ScopedContext::getLocation(),
|
[mlir][Linalg] Add tensor support to Linalg EDSC Builders
Summary:
This diff extends the Linalg EDSC builders so we can easily create mixed
tensor/buffer linalg.generic ops. This is expected to be useful for
HLO -> Linalg lowering.
The StructuredIndexed struct is made to derive from ValueHandle and can
now capture a type + indexing expressions. This is used to represent return
tensors.
Pointwise unary and binary builders are extended to allow both output buffers
and return tensors. This has implications on the number of region arguments.
Reviewers: ftynse, hanchung, asaadaldien
Subscribers: mehdi_amini, rriddle, jpienaar, burmako, shauheen, antiagainst, arpith-jacob, mgester, lucyrfox, aartbik, liufengdb, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D73149
2020-01-21 19:48:31 -05:00
|
|
|
types,
|
2019-12-13 16:35:49 -08:00
|
|
|
values,
|
|
|
|
IntegerAttr::get(IntegerType::get(64, ctx), nInputs),
|
|
|
|
IntegerAttr::get(IntegerType::get(64, ctx), nOutputs),
|
2019-12-13 13:26:00 -08:00
|
|
|
builder.getAffineMapArrayAttr(maps),
|
2019-12-13 16:35:49 -08:00
|
|
|
builder.getStrArrayAttr(iteratorStrTypes),
|
|
|
|
StringAttr() /*doc*/,
|
2020-07-20 18:30:10 +02:00
|
|
|
StringAttr() /*library_call*/,
|
|
|
|
IntegerAttr() /*symbol_source*/
|
2019-12-13 16:35:49 -08:00
|
|
|
/* TODO: other attributes in op */
|
2019-12-13 13:26:00 -08:00
|
|
|
)
|
|
|
|
.getOperation();
|
2019-12-13 16:35:49 -08:00
|
|
|
// clang-format on
|
2019-12-13 13:26:00 -08:00
|
|
|
|
|
|
|
using namespace edsc;
|
|
|
|
SmallVector<Type, 4> blockTypes;
|
2019-12-13 16:35:49 -08:00
|
|
|
blockTypes.reserve(values.size());
|
|
|
|
for (auto it : llvm::enumerate(values))
|
|
|
|
blockTypes.push_back((it.index() < nViews)
|
|
|
|
? getElementTypeOrSelf(it.value())
|
2020-01-11 08:54:04 -08:00
|
|
|
: it.value().getType());
|
2019-12-13 13:26:00 -08:00
|
|
|
|
[mlir][Linalg] Fix Linalg EDSC builders
Summary:
This diff fixes the fact that the method `mlir::edsc::makeGenericLinalgOp`
incorrectly adds 2 blocks to Linalg ops.
Tests are updated accordingly.
Reviewers: ftynse, hanchung, herhut, pifon2a, asaadaldien
Reviewed By: asaadaldien
Subscribers: merge_guards_bot, mehdi_amini, rriddle, jpienaar, burmako, shauheen, antiagainst, arpith-jacob, mgester, lucyrfox, liufengdb, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D72780
2020-01-16 09:30:17 -05:00
|
|
|
assert(op->getNumRegions() == 1);
|
|
|
|
assert(op->getRegion(0).empty());
|
|
|
|
OpBuilder opBuilder(op);
|
|
|
|
ScopedContext scope(opBuilder, op->getLoc());
|
2020-06-17 16:46:45 +02:00
|
|
|
buildInNewBlock(op->getRegion(0), blockTypes, regionBuilder);
|
2020-06-17 13:20:36 -07:00
|
|
|
assert(llvm::hasSingleElement(op->getRegion(0)));
|
2019-12-13 13:26:00 -08:00
|
|
|
return op;
|
|
|
|
}
|
2019-12-13 16:35:49 -08:00
|
|
|
|
2020-06-17 16:46:45 +02:00
|
|
|
void mlir::edsc::ops::mulRegionBuilder(ValueRange args) {
|
2020-02-12 13:43:10 -05:00
|
|
|
using edsc::op::operator+;
|
|
|
|
using edsc::op::operator*;
|
|
|
|
assert(args.size() == 2 && "expected 2 block arguments");
|
2020-04-23 11:00:03 -04:00
|
|
|
Value a(args[0]), b(args[1]);
|
|
|
|
linalg_yield(a * b);
|
2020-02-12 13:43:10 -05:00
|
|
|
}
|
|
|
|
|
2020-06-17 16:46:45 +02:00
|
|
|
void mlir::edsc::ops::macRegionBuilder(ValueRange args) {
|
2019-12-16 13:32:02 -08:00
|
|
|
using edsc::op::operator+;
|
|
|
|
using edsc::op::operator*;
|
|
|
|
assert(args.size() == 3 && "expected 3 block arguments");
|
2020-04-23 11:00:03 -04:00
|
|
|
Value a(args[0]), b(args[1]), c(args[2]);
|
|
|
|
linalg_yield(c + a * b);
|
2019-12-16 13:32:02 -08:00
|
|
|
}
|
|
|
|
|
2020-04-02 21:06:45 -04:00
|
|
|
Operation *mlir::edsc::ops::linalg_generic_pointwise(
|
|
|
|
UnaryPointwiseOpBuilder unaryOp, StructuredIndexed I, StructuredIndexed O) {
|
[mlir][EDSC] NFC - Move StructuredIndexed and IteratorType out of Linalg
Summary:
This NFC revision will allow those classes to be reused to allow
building structured vector operations.
Reviewers: aartbik, ftynse
Subscribers: arphaman, mehdi_amini, rriddle, jpienaar, burmako, shauheen, antiagainst, arpith-jacob, mgester, lucyrfox, liufengdb, Joonsoo, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D74279
2020-02-08 11:16:22 -05:00
|
|
|
SmallVector<IteratorType, 4> iterTypes(O.getExprs().size(),
|
|
|
|
IteratorType::Parallel);
|
[mlir][Linalg] Add tensor support to Linalg EDSC Builders
Summary:
This diff extends the Linalg EDSC builders so we can easily create mixed
tensor/buffer linalg.generic ops. This is expected to be useful for
HLO -> Linalg lowering.
The StructuredIndexed struct is made to derive from ValueHandle and can
now capture a type + indexing expressions. This is used to represent return
tensors.
Pointwise unary and binary builders are extended to allow both output buffers
and return tensors. This has implications on the number of region arguments.
Reviewers: ftynse, hanchung, asaadaldien
Subscribers: mehdi_amini, rriddle, jpienaar, burmako, shauheen, antiagainst, arpith-jacob, mgester, lucyrfox, aartbik, liufengdb, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D73149
2020-01-21 19:48:31 -05:00
|
|
|
if (O.getType().isa<RankedTensorType>()) {
|
2020-06-17 16:46:45 +02:00
|
|
|
auto fun = [&unaryOp](ValueRange args) {
|
[mlir][Linalg] Add tensor support to Linalg EDSC Builders
Summary:
This diff extends the Linalg EDSC builders so we can easily create mixed
tensor/buffer linalg.generic ops. This is expected to be useful for
HLO -> Linalg lowering.
The StructuredIndexed struct is made to derive from ValueHandle and can
now capture a type + indexing expressions. This is used to represent return
tensors.
Pointwise unary and binary builders are extended to allow both output buffers
and return tensors. This has implications on the number of region arguments.
Reviewers: ftynse, hanchung, asaadaldien
Subscribers: mehdi_amini, rriddle, jpienaar, burmako, shauheen, antiagainst, arpith-jacob, mgester, lucyrfox, aartbik, liufengdb, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D73149
2020-01-21 19:48:31 -05:00
|
|
|
assert(args.size() == 1 && "expected 1 block arguments");
|
2020-04-23 11:00:03 -04:00
|
|
|
Value a(args[0]);
|
[mlir][Linalg] Add tensor support to Linalg EDSC Builders
Summary:
This diff extends the Linalg EDSC builders so we can easily create mixed
tensor/buffer linalg.generic ops. This is expected to be useful for
HLO -> Linalg lowering.
The StructuredIndexed struct is made to derive from ValueHandle and can
now capture a type + indexing expressions. This is used to represent return
tensors.
Pointwise unary and binary builders are extended to allow both output buffers
and return tensors. This has implications on the number of region arguments.
Reviewers: ftynse, hanchung, asaadaldien
Subscribers: mehdi_amini, rriddle, jpienaar, burmako, shauheen, antiagainst, arpith-jacob, mgester, lucyrfox, aartbik, liufengdb, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D73149
2020-01-21 19:48:31 -05:00
|
|
|
linalg_yield(unaryOp(a));
|
|
|
|
};
|
|
|
|
return makeGenericLinalgOp(iterTypes, {I}, {O}, fun);
|
|
|
|
}
|
2020-06-17 16:46:45 +02:00
|
|
|
auto fun = [&unaryOp](ValueRange args) {
|
2019-12-16 13:32:02 -08:00
|
|
|
assert(args.size() == 2 && "expected 2 block arguments");
|
2020-04-23 11:00:03 -04:00
|
|
|
Value a(args[0]);
|
2019-12-16 13:32:02 -08:00
|
|
|
linalg_yield(unaryOp(a));
|
|
|
|
};
|
2020-01-21 19:43:27 -05:00
|
|
|
return makeGenericLinalgOp(iterTypes, {I}, {O}, fun);
|
2019-12-16 13:32:02 -08:00
|
|
|
}
|
|
|
|
|
2020-04-02 21:06:45 -04:00
|
|
|
Operation *mlir::edsc::ops::linalg_generic_pointwise_tanh(StructuredIndexed I,
|
|
|
|
StructuredIndexed O) {
|
2020-04-23 11:00:03 -04:00
|
|
|
UnaryPointwiseOpBuilder unOp([](Value a) -> Value { return std_tanh(a); });
|
2020-04-02 21:06:45 -04:00
|
|
|
return linalg_generic_pointwise(unOp, I, O);
|
2019-12-16 13:32:02 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Binary pointwise operation (with broadcast) entry point.
|
2020-04-02 21:06:45 -04:00
|
|
|
Operation *mlir::edsc::ops::linalg_generic_pointwise(
|
|
|
|
BinaryPointwiseOpBuilder binaryOp, StructuredIndexed I1,
|
|
|
|
StructuredIndexed I2, StructuredIndexed O) {
|
[mlir][EDSC] NFC - Move StructuredIndexed and IteratorType out of Linalg
Summary:
This NFC revision will allow those classes to be reused to allow
building structured vector operations.
Reviewers: aartbik, ftynse
Subscribers: arphaman, mehdi_amini, rriddle, jpienaar, burmako, shauheen, antiagainst, arpith-jacob, mgester, lucyrfox, liufengdb, Joonsoo, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D74279
2020-02-08 11:16:22 -05:00
|
|
|
SmallVector<IteratorType, 4> iterTypes(O.getExprs().size(),
|
|
|
|
IteratorType::Parallel);
|
[mlir][Linalg] Add tensor support to Linalg EDSC Builders
Summary:
This diff extends the Linalg EDSC builders so we can easily create mixed
tensor/buffer linalg.generic ops. This is expected to be useful for
HLO -> Linalg lowering.
The StructuredIndexed struct is made to derive from ValueHandle and can
now capture a type + indexing expressions. This is used to represent return
tensors.
Pointwise unary and binary builders are extended to allow both output buffers
and return tensors. This has implications on the number of region arguments.
Reviewers: ftynse, hanchung, asaadaldien
Subscribers: mehdi_amini, rriddle, jpienaar, burmako, shauheen, antiagainst, arpith-jacob, mgester, lucyrfox, aartbik, liufengdb, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D73149
2020-01-21 19:48:31 -05:00
|
|
|
if (O.getType().isa<RankedTensorType>()) {
|
2020-06-17 16:46:45 +02:00
|
|
|
auto fun = [&binaryOp](ValueRange args) {
|
[mlir][Linalg] Add tensor support to Linalg EDSC Builders
Summary:
This diff extends the Linalg EDSC builders so we can easily create mixed
tensor/buffer linalg.generic ops. This is expected to be useful for
HLO -> Linalg lowering.
The StructuredIndexed struct is made to derive from ValueHandle and can
now capture a type + indexing expressions. This is used to represent return
tensors.
Pointwise unary and binary builders are extended to allow both output buffers
and return tensors. This has implications on the number of region arguments.
Reviewers: ftynse, hanchung, asaadaldien
Subscribers: mehdi_amini, rriddle, jpienaar, burmako, shauheen, antiagainst, arpith-jacob, mgester, lucyrfox, aartbik, liufengdb, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D73149
2020-01-21 19:48:31 -05:00
|
|
|
assert(args.size() == 2 && "expected 2 block arguments");
|
2020-04-23 11:00:03 -04:00
|
|
|
Value a(args[0]), b(args[1]);
|
[mlir][Linalg] Add tensor support to Linalg EDSC Builders
Summary:
This diff extends the Linalg EDSC builders so we can easily create mixed
tensor/buffer linalg.generic ops. This is expected to be useful for
HLO -> Linalg lowering.
The StructuredIndexed struct is made to derive from ValueHandle and can
now capture a type + indexing expressions. This is used to represent return
tensors.
Pointwise unary and binary builders are extended to allow both output buffers
and return tensors. This has implications on the number of region arguments.
Reviewers: ftynse, hanchung, asaadaldien
Subscribers: mehdi_amini, rriddle, jpienaar, burmako, shauheen, antiagainst, arpith-jacob, mgester, lucyrfox, aartbik, liufengdb, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D73149
2020-01-21 19:48:31 -05:00
|
|
|
linalg_yield(binaryOp(a, b));
|
|
|
|
};
|
|
|
|
return makeGenericLinalgOp(iterTypes, {I1, I2}, {O}, fun);
|
|
|
|
}
|
2020-06-17 16:46:45 +02:00
|
|
|
auto fun = [&binaryOp](ValueRange args) {
|
2019-12-16 13:32:02 -08:00
|
|
|
assert(args.size() == 3 && "expected 3 block arguments");
|
2020-04-23 11:00:03 -04:00
|
|
|
Value a(args[0]), b(args[1]);
|
2019-12-16 13:32:02 -08:00
|
|
|
linalg_yield(binaryOp(a, b));
|
|
|
|
};
|
2020-01-21 19:43:27 -05:00
|
|
|
return makeGenericLinalgOp(iterTypes, {I1, I2}, {O}, fun);
|
2019-12-16 13:32:02 -08:00
|
|
|
}
|
2019-12-13 16:35:49 -08:00
|
|
|
|
2020-04-02 21:06:45 -04:00
|
|
|
Operation *mlir::edsc::ops::linalg_generic_pointwise_add(StructuredIndexed I1,
|
|
|
|
StructuredIndexed I2,
|
|
|
|
StructuredIndexed O) {
|
2019-12-16 13:32:02 -08:00
|
|
|
using edsc::op::operator+;
|
|
|
|
BinaryPointwiseOpBuilder binOp(
|
2020-04-23 11:00:03 -04:00
|
|
|
[](Value a, Value b) -> Value { return a + b; });
|
2020-04-02 21:06:45 -04:00
|
|
|
return linalg_generic_pointwise(binOp, I1, I2, O);
|
2019-12-16 13:32:02 -08:00
|
|
|
}
|
|
|
|
|
2020-04-02 21:06:45 -04:00
|
|
|
Operation *mlir::edsc::ops::linalg_generic_pointwise_max(StructuredIndexed I1,
|
|
|
|
StructuredIndexed I2,
|
|
|
|
StructuredIndexed O) {
|
2020-04-23 11:00:03 -04:00
|
|
|
BinaryPointwiseOpBuilder binOp([](Value a, Value b) -> Value {
|
2020-06-29 19:35:11 +02:00
|
|
|
using edsc::op::sgt;
|
|
|
|
return std_select(sgt(a, b), a, b);
|
2019-12-16 13:32:02 -08:00
|
|
|
});
|
2020-04-02 21:06:45 -04:00
|
|
|
return linalg_generic_pointwise(binOp, I1, I2, O);
|
2019-12-16 13:32:02 -08:00
|
|
|
}
|
|
|
|
|
2020-04-02 21:06:45 -04:00
|
|
|
Operation *
|
2020-04-23 11:00:03 -04:00
|
|
|
mlir::edsc::ops::linalg_generic_matmul(Value vA, Value vB, Value vC,
|
2020-04-02 21:06:45 -04:00
|
|
|
MatmulRegionBuilder regionBuilder) {
|
2020-01-21 19:43:27 -05:00
|
|
|
// clang-format off
|
2019-12-13 16:35:49 -08:00
|
|
|
AffineExpr m, n, k;
|
|
|
|
bindDims(ScopedContext::getContext(), m, n, k);
|
|
|
|
StructuredIndexed A(vA), B(vB), C(vC);
|
2020-01-02 09:14:23 -05:00
|
|
|
return makeGenericLinalgOp(
|
[mlir][EDSC] NFC - Move StructuredIndexed and IteratorType out of Linalg
Summary:
This NFC revision will allow those classes to be reused to allow
building structured vector operations.
Reviewers: aartbik, ftynse
Subscribers: arphaman, mehdi_amini, rriddle, jpienaar, burmako, shauheen, antiagainst, arpith-jacob, mgester, lucyrfox, liufengdb, Joonsoo, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D74279
2020-02-08 11:16:22 -05:00
|
|
|
{IteratorType::Parallel, IteratorType::Parallel, IteratorType::Reduction},
|
2020-01-21 19:43:27 -05:00
|
|
|
{A({m, k}), B({k, n})},
|
|
|
|
{C({m, n})},
|
2020-02-12 13:43:10 -05:00
|
|
|
regionBuilder);
|
2020-01-21 19:43:27 -05:00
|
|
|
// clang-format on
|
2019-12-16 13:32:02 -08:00
|
|
|
}
|
|
|
|
|
2020-04-02 21:06:45 -04:00
|
|
|
Operation *
|
2020-04-23 11:00:03 -04:00
|
|
|
mlir::edsc::ops::linalg_generic_matmul(Value vA, Value vB, RankedTensorType tC,
|
2020-04-02 21:06:45 -04:00
|
|
|
MatmulRegionBuilder regionBuilder) {
|
[mlir][Linalg] Adding support for linalg_matmul with tensors.
Summary:
This revision provides 2 versions of matmul with tensors to account for the differences in buffer vs value semantics:
1. `C(i, j) = sum_{r_k} A(i, r_k) * B(r_k, j)`
2. `D(i, j) = C(i, j) + sum_{r_k} A(i, r_k) * B(r_k, j)`
Reviewers: ftynse
Subscribers: mehdi_amini, rriddle, jpienaar, burmako, shauheen, antiagainst, arpith-jacob, mgester, lucyrfox, aartbik, liufengdb, Joonsoo, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D73796
2020-01-31 14:42:34 -05:00
|
|
|
// clang-format off
|
|
|
|
AffineExpr m, n, k;
|
|
|
|
bindDims(ScopedContext::getContext(), m, n, k);
|
|
|
|
StructuredIndexed A(vA), B(vB), C(tC);
|
|
|
|
return makeGenericLinalgOp(
|
[mlir][EDSC] NFC - Move StructuredIndexed and IteratorType out of Linalg
Summary:
This NFC revision will allow those classes to be reused to allow
building structured vector operations.
Reviewers: aartbik, ftynse
Subscribers: arphaman, mehdi_amini, rriddle, jpienaar, burmako, shauheen, antiagainst, arpith-jacob, mgester, lucyrfox, liufengdb, Joonsoo, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D74279
2020-02-08 11:16:22 -05:00
|
|
|
{IteratorType::Parallel, IteratorType::Parallel, IteratorType::Reduction},
|
[mlir][Linalg] Adding support for linalg_matmul with tensors.
Summary:
This revision provides 2 versions of matmul with tensors to account for the differences in buffer vs value semantics:
1. `C(i, j) = sum_{r_k} A(i, r_k) * B(r_k, j)`
2. `D(i, j) = C(i, j) + sum_{r_k} A(i, r_k) * B(r_k, j)`
Reviewers: ftynse
Subscribers: mehdi_amini, rriddle, jpienaar, burmako, shauheen, antiagainst, arpith-jacob, mgester, lucyrfox, aartbik, liufengdb, Joonsoo, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D73796
2020-01-31 14:42:34 -05:00
|
|
|
{A({m, k}), B({k, n})},
|
|
|
|
{C({m, n})},
|
2020-02-12 13:43:10 -05:00
|
|
|
regionBuilder);
|
[mlir][Linalg] Adding support for linalg_matmul with tensors.
Summary:
This revision provides 2 versions of matmul with tensors to account for the differences in buffer vs value semantics:
1. `C(i, j) = sum_{r_k} A(i, r_k) * B(r_k, j)`
2. `D(i, j) = C(i, j) + sum_{r_k} A(i, r_k) * B(r_k, j)`
Reviewers: ftynse
Subscribers: mehdi_amini, rriddle, jpienaar, burmako, shauheen, antiagainst, arpith-jacob, mgester, lucyrfox, aartbik, liufengdb, Joonsoo, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D73796
2020-01-31 14:42:34 -05:00
|
|
|
// clang-format on
|
|
|
|
}
|
|
|
|
|
2020-04-02 21:06:45 -04:00
|
|
|
Operation *
|
2020-04-23 11:00:03 -04:00
|
|
|
mlir::edsc::ops::linalg_generic_matmul(Value vA, Value vB, Value vC,
|
|
|
|
RankedTensorType tD,
|
2020-04-02 21:06:45 -04:00
|
|
|
MatmulRegionBuilder regionBuilder) {
|
[mlir][Linalg] Adding support for linalg_matmul with tensors.
Summary:
This revision provides 2 versions of matmul with tensors to account for the differences in buffer vs value semantics:
1. `C(i, j) = sum_{r_k} A(i, r_k) * B(r_k, j)`
2. `D(i, j) = C(i, j) + sum_{r_k} A(i, r_k) * B(r_k, j)`
Reviewers: ftynse
Subscribers: mehdi_amini, rriddle, jpienaar, burmako, shauheen, antiagainst, arpith-jacob, mgester, lucyrfox, aartbik, liufengdb, Joonsoo, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D73796
2020-01-31 14:42:34 -05:00
|
|
|
// clang-format off
|
|
|
|
AffineExpr m, n, k;
|
|
|
|
bindDims(ScopedContext::getContext(), m, n, k);
|
|
|
|
StructuredIndexed A(vA), B(vB), C(vC), D(tD);
|
|
|
|
return makeGenericLinalgOp(
|
[mlir][EDSC] NFC - Move StructuredIndexed and IteratorType out of Linalg
Summary:
This NFC revision will allow those classes to be reused to allow
building structured vector operations.
Reviewers: aartbik, ftynse
Subscribers: arphaman, mehdi_amini, rriddle, jpienaar, burmako, shauheen, antiagainst, arpith-jacob, mgester, lucyrfox, liufengdb, Joonsoo, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D74279
2020-02-08 11:16:22 -05:00
|
|
|
{IteratorType::Parallel, IteratorType::Parallel, IteratorType::Reduction},
|
[mlir][Linalg] Adding support for linalg_matmul with tensors.
Summary:
This revision provides 2 versions of matmul with tensors to account for the differences in buffer vs value semantics:
1. `C(i, j) = sum_{r_k} A(i, r_k) * B(r_k, j)`
2. `D(i, j) = C(i, j) + sum_{r_k} A(i, r_k) * B(r_k, j)`
Reviewers: ftynse
Subscribers: mehdi_amini, rriddle, jpienaar, burmako, shauheen, antiagainst, arpith-jacob, mgester, lucyrfox, aartbik, liufengdb, Joonsoo, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D73796
2020-01-31 14:42:34 -05:00
|
|
|
{A({m, k}), B({k, n}), C({m, n})},
|
|
|
|
{D({m, n})},
|
2020-02-12 13:43:10 -05:00
|
|
|
regionBuilder);
|
[mlir][Linalg] Adding support for linalg_matmul with tensors.
Summary:
This revision provides 2 versions of matmul with tensors to account for the differences in buffer vs value semantics:
1. `C(i, j) = sum_{r_k} A(i, r_k) * B(r_k, j)`
2. `D(i, j) = C(i, j) + sum_{r_k} A(i, r_k) * B(r_k, j)`
Reviewers: ftynse
Subscribers: mehdi_amini, rriddle, jpienaar, burmako, shauheen, antiagainst, arpith-jacob, mgester, lucyrfox, aartbik, liufengdb, Joonsoo, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D73796
2020-01-31 14:42:34 -05:00
|
|
|
// clang-format on
|
|
|
|
}
|
|
|
|
|
2020-04-23 11:00:03 -04:00
|
|
|
Operation *mlir::edsc::ops::linalg_generic_conv_nhwc(Value vI, Value vW,
|
|
|
|
Value vO,
|
2020-04-02 21:06:45 -04:00
|
|
|
ArrayRef<int> strides,
|
|
|
|
ArrayRef<int> dilations) {
|
2019-12-16 13:32:02 -08:00
|
|
|
MLIRContext *ctx = ScopedContext::getContext();
|
2020-07-07 01:35:23 -07:00
|
|
|
// TODO: some template magic to make everything rank-polymorphic.
|
2019-12-16 13:32:02 -08:00
|
|
|
assert((dilations.empty() || dilations.size() == 2) && "only 2-D conv atm");
|
|
|
|
assert((strides.empty() || strides.size() == 2) && "only 2-D conv atm");
|
|
|
|
|
|
|
|
// Some short names.
|
[mlir][EDSC] NFC - Move StructuredIndexed and IteratorType out of Linalg
Summary:
This NFC revision will allow those classes to be reused to allow
building structured vector operations.
Reviewers: aartbik, ftynse
Subscribers: arphaman, mehdi_amini, rriddle, jpienaar, burmako, shauheen, antiagainst, arpith-jacob, mgester, lucyrfox, liufengdb, Joonsoo, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D74279
2020-02-08 11:16:22 -05:00
|
|
|
auto par = IteratorType::Parallel;
|
|
|
|
auto red = IteratorType::Reduction;
|
2019-12-16 13:32:02 -08:00
|
|
|
auto s = strides;
|
|
|
|
auto d = dilations;
|
|
|
|
|
|
|
|
AffineExpr b, f, h, w, kh, kw, c;
|
|
|
|
bindDims(ctx, b, f, h, w, kh, kw, c);
|
|
|
|
unsigned numDims = c.cast<AffineDimExpr>().getPosition() + 1;
|
|
|
|
StructuredIndexed I(vI), W(vW), O(vO);
|
|
|
|
// clang-format off
|
2020-01-21 19:43:27 -05:00
|
|
|
return makeGenericLinalgOp(
|
|
|
|
{par, par, par, par, red, red, red}, {
|
2019-12-16 13:32:02 -08:00
|
|
|
I({b,
|
2020-01-21 19:43:27 -05:00
|
|
|
// Roundtrip to flattened form to serve as canonicalization and ensure
|
|
|
|
// consistent ordering of subexpressions.
|
2019-12-16 13:32:02 -08:00
|
|
|
simplifyAffineExpr(s[0] * h + d[0] * kh, numDims, 0),
|
|
|
|
simplifyAffineExpr(s[1] * w + d[1] * kw, numDims, 0),
|
|
|
|
c}),
|
2020-01-21 19:43:27 -05:00
|
|
|
W({kh, kw, c, f})}, {
|
|
|
|
O({b, h, w, f})},
|
|
|
|
macRegionBuilder);
|
2019-12-16 13:32:02 -08:00
|
|
|
// clang-format on
|
|
|
|
}
|
|
|
|
|
2020-04-02 21:06:45 -04:00
|
|
|
Operation *mlir::edsc::ops::linalg_generic_dilated_conv_nhwc(
|
2020-04-23 11:00:03 -04:00
|
|
|
Value vI, Value vW, Value vO, int depth_multiplier, ArrayRef<int> strides,
|
|
|
|
ArrayRef<int> dilations) {
|
2019-12-16 13:32:02 -08:00
|
|
|
MLIRContext *ctx = ScopedContext::getContext();
|
2020-07-07 01:35:23 -07:00
|
|
|
// TODO: some template magic to make everything rank-polymorphic.
|
2019-12-16 13:32:02 -08:00
|
|
|
assert((dilations.empty() || dilations.size() == 2) && "only 2-D conv atm");
|
|
|
|
assert((strides.empty() || strides.size() == 2) && "only 2-D conv atm");
|
|
|
|
|
|
|
|
// Some short names.
|
[mlir][EDSC] NFC - Move StructuredIndexed and IteratorType out of Linalg
Summary:
This NFC revision will allow those classes to be reused to allow
building structured vector operations.
Reviewers: aartbik, ftynse
Subscribers: arphaman, mehdi_amini, rriddle, jpienaar, burmako, shauheen, antiagainst, arpith-jacob, mgester, lucyrfox, liufengdb, Joonsoo, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D74279
2020-02-08 11:16:22 -05:00
|
|
|
auto par = IteratorType::Parallel;
|
|
|
|
auto red = IteratorType::Reduction;
|
2019-12-16 13:32:02 -08:00
|
|
|
auto s = strides;
|
|
|
|
auto d = dilations;
|
|
|
|
|
|
|
|
// clang-format off
|
|
|
|
AffineExpr b, dm, c, h, w, kh, kw;
|
|
|
|
bindDims(ctx, b, dm, c, h, w, kh, kw);
|
|
|
|
unsigned numDims = kw.cast<AffineDimExpr>().getPosition() + 1;
|
|
|
|
StructuredIndexed I(vI), W(vW), O(vO);
|
2020-01-21 19:43:27 -05:00
|
|
|
return makeGenericLinalgOp(
|
|
|
|
{par, par, par, par, par, red, red}, {
|
2019-12-16 13:32:02 -08:00
|
|
|
I({b,
|
|
|
|
// Roundtrip to flattened form to serve as canonicalization and ensure
|
|
|
|
// consistent ordering of subexpressions.
|
|
|
|
simplifyAffineExpr(s[0] * h + d[0] * kh, numDims, 0),
|
|
|
|
simplifyAffineExpr(s[1] * w + d[1] * kw, numDims, 0),
|
|
|
|
c}),
|
2020-01-21 19:43:27 -05:00
|
|
|
W({kh, kw, c, dm})}, {
|
|
|
|
O({b, h, w, simplifyAffineExpr(c * depth_multiplier + dm, numDims, 0)})},
|
|
|
|
macRegionBuilder);
|
2019-12-13 16:35:49 -08:00
|
|
|
// clang-format on
|
|
|
|
}
|