Skip to content

Commit

Permalink
Revert "[mlir][Linalg] Improve region support in Linalg ops."
Browse files Browse the repository at this point in the history
This reverts commit 973e133.

It triggers an issue in gcc5 that require investigation, the build is
broken with:

/tmp/ccdpj3B9.s: Assembler messages:
/tmp/ccdpj3B9.s:5821: Error: symbol `_ZNSt17_Function_handlerIFvjjEUljjE2_E9_M_invokeERKSt9_Any_dataOjS6_' is already defined
/tmp/ccdpj3B9.s:5860: Error: symbol `_ZNSt14_Function_base13_Base_managerIUljjE2_E10_M_managerERSt9_Any_dataRKS3_St18_Manager_operation' is already defined
  • Loading branch information
joker-eph committed Feb 12, 2021
1 parent a7538fe commit 3f22547
Show file tree
Hide file tree
Showing 11 changed files with 280 additions and 316 deletions.
31 changes: 23 additions & 8 deletions mlir/include/mlir/Dialect/Linalg/IR/LinalgInterfaces.td
Original file line number Diff line number Diff line change
Expand Up @@ -1056,6 +1056,20 @@ def LinalgStructuredInterface : OpInterface<"LinalgOp"> {
//===------------------------------------------------------------------===//
// Other static interface methods.
//===------------------------------------------------------------------===//
StaticInterfaceMethod<
/*desc=*/[{
Create an operation of the current type with the given location,
operands, and attributes.
}],
/*retTy=*/"Operation *",
/*methodName=*/"create",
(ins "OpBuilder &":$builder, "Location":$loc, "TypeRange":$resultTypes,
"ValueRange":$operands,
"ArrayRef<NamedAttribute>":$attributes), [{
return builder.create<ConcreteOp>(
loc, resultTypes, operands, attributes);
}]
>,
InterfaceMethod<
/*desc=*/[{
Clone the current operation with the given location and operands. This
Expand All @@ -1068,13 +1082,14 @@ def LinalgStructuredInterface : OpInterface<"LinalgOp"> {
(ins "OpBuilder &":$b, "Location":$loc, "TypeRange":$resultTypes,
"ValueRange":$operands),
[{
BlockAndValueMapping bvm;
OperationState state(
loc, ConcreteOp::getOperationName(), operands, resultTypes,
$_op->getAttrs());
for (Region &r : $_op->getRegions())
r.cloneInto(state.addRegion(), bvm);
return b.createOperation(state);
BlockAndValueMapping map;
unsigned numRegions = $_op->getNumRegions();
Operation *res = create(b, loc, resultTypes, operands, $_op->getAttrs());
assert(res->getNumRegions() == numRegions && "inconsistent # regions");
for (unsigned ridx = 0; ridx < numRegions; ++ridx)
$_op->getRegion(ridx).cloneInto(
&res->getRegion(ridx), map);
return res;
}]
>,
StaticInterfaceMethod<
Expand All @@ -1083,7 +1098,7 @@ def LinalgStructuredInterface : OpInterface<"LinalgOp"> {
Returns a null function if this named op does not define a region
builder.
}],
/*retTy=*/"std::function<void(Block &, ValueRange)>",
/*retTy=*/"std::function<void(Block &)>",
/*methodName=*/"getRegionBuilder",
(ins),
[{ return ConcreteOp::getRegionBuilder(); }]
Expand Down
42 changes: 15 additions & 27 deletions mlir/include/mlir/Dialect/Linalg/IR/LinalgStructuredOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,14 @@ def CopyOp : LinalgStructured_Op<"copy", [CopyOpInterface]> {
AnyStridedMemRef:$output,
OptionalAttr<AffineMapAttr>:$inputPermutation,
OptionalAttr<AffineMapAttr>:$outputPermutation);
let regions = (region AnyRegion:$region);

let builders = [
OpBuilderDAG<(ins "Value":$input, "Value":$output,
CArg<"AffineMap", "AffineMap()">:$inputPermutation,
CArg<"AffineMap", "AffineMap()">:$outputPermutation,
CArg<"ArrayRef<NamedAttribute>", "{}">:$attrs)>];
// TODO: this should go away once the usage of OptionalAttr triggers emission
// of builders with default arguments left unspecified.
let builders = [OpBuilderDAG<(ins "Value":$input, "Value":$output),
[{
return build(
$_builder, $_state, input, output, AffineMapAttr(), AffineMapAttr());
}]>];

let extraClassDeclaration = structuredOpsDecls # [{
ValueRange inputs() { return getOperands().take_front(); }
Expand Down Expand Up @@ -145,31 +146,24 @@ def CopyOp : LinalgStructured_Op<"copy", [CopyOpInterface]> {
Value getSource() { return input();}
Value getTarget() { return output(); }

static void regionBuilder(Block &block, ValueRange captures);
static std::function<void(Block &block, ValueRange captures)>
getRegionBuilder() {
return &regionBuilder;
static std::function<void(Block &)> getRegionBuilder() {
return nullptr;
}
static unsigned getNumRegionArgs() { return 2; }
}];
let verifier = [{ return ::verify(*this); }];

let assemblyFormat = [{
`(` $input `,` $output `)` attr-dict `:`
type($input) `,` type($output)
custom<CopyOpRegion>($region, ref(type($input)), ref(type($input)))
`(` operands `)` attr-dict `:` type(operands)
}];

let hasFolder = 1;
let hasCanonicalizer = 1;
let skipDefaultBuilders = 1;
}

def FillOp : LinalgStructured_Op<"fill", []> {
let arguments = (ins AnyShaped:$output,
AnyTypeOf<[AnyFloat, AnySignlessInteger, AnyVector]>:$value);
let results = (outs Optional<AnyRankedTensor>:$result);
let regions = (region AnyRegion:$region);
let extraClassDeclaration = structuredOpsDecls # [{
ValueRange inputs() { return {}; }
ValueRange outputs() { return getOperands().take_front(); }
Expand All @@ -189,18 +183,13 @@ def FillOp : LinalgStructured_Op<"fill", []> {
extractOrIdentityMap(llvm::None, getNumParallelLoops(), context)});
}

static void regionBuilder(Block &block, ValueRange captures);
static std::function<void(Block &block, ValueRange captures)>
getRegionBuilder() {
return &regionBuilder;
static std::function<void(Block &)> getRegionBuilder() {
return nullptr;
}
static unsigned getNumRegionArgs() { return 1; }
}];

let assemblyFormat = [{
`(` $output `,` $value `)` attr-dict `:`
type($output) `,` type($value) (`->` type($result)^)?
custom<FillOpRegion>($region, ref(type($output)), ref($value))
`(` operands `)` attr-dict `:` type(operands) (`->` type($result)^)?
}];

let builders = [
Expand Down Expand Up @@ -279,8 +268,7 @@ class PoolingBase_Op<string mnemonic, list<OpTrait> props>
return padding().getValue().getValue<int64_t>({i, 1});
}

static std::function<void(Block &, ValueRange captures)> getRegionBuilder()
{
static std::function<void(Block &)> getRegionBuilder() {
return nullptr;
}
}];
Expand Down Expand Up @@ -531,7 +519,7 @@ class GenericOpBase<string mnemonic> : LinalgStructuredBase_Op<mnemonic, [
library_call()->str() : "op_has_no_registered_library_name";
}

static std::function<void(Block &, ValueRange)> getRegionBuilder() {
static std::function<void(Block &)> getRegionBuilder() {
return nullptr;
}
}];
Expand Down
8 changes: 1 addition & 7 deletions mlir/lib/Conversion/LinalgToStandard/LinalgToStandard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,7 @@ LogicalResult mlir::linalg::CopyTransposeRewrite::matchAndRewrite(
if (in == op.input() && out == op.output())
return failure();

auto libraryCallName = getLibraryCallSymbolRef(op, rewriter);
if (!libraryCallName)
return failure();

rewriter.replaceOpWithNewOp<mlir::CallOp>(
op, libraryCallName.getValue(), TypeRange(),
createTypeCanonicalizedMemRefOperands(rewriter, op.getLoc(), {in, out}));
rewriter.replaceOpWithNewOp<CopyOp>(op, in, out);
return success();
}

Expand Down
13 changes: 9 additions & 4 deletions mlir/lib/Dialect/Linalg/EDSC/Builders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ Operation *mlir::edsc::makeGenericLinalgOp(
ArrayRef<StructuredIndexed> outputs, TypeRange resultTensorTypes,
function_ref<void(ValueRange)> regionBuilder, ArrayRef<Value> otherValues,
ArrayRef<Attribute> otherAttributes) {
OpBuilder &builder = edsc::ScopedContext::getBuilderRef();

// Build maps
SmallVector<SmallVector<AffineExpr, 4>, 4> exprsList;
exprsList.reserve(inputs.size() + outputs.size());
Expand All @@ -52,10 +54,13 @@ Operation *mlir::edsc::makeGenericLinalgOp(
resultTensorTypes,
inputValues,
outputValues,
maps,
iteratorStrTypes,
""/*doc*/,
""/*library_call*/)
builder.getAffineMapArrayAttr(maps),
builder.getStrArrayAttr(iteratorStrTypes),
StringAttr() /*doc*/,
StringAttr() /*library_call*/,
ArrayAttr() /*sparse*/
/* TODO: other attributes in op */
)
.getOperation();
// clang-format on

Expand Down
Loading

0 comments on commit 3f22547

Please sign in to comment.