Skip to content

Commit

Permalink
[mlir] Add an interface to allow operations to specify how they can b…
Browse files Browse the repository at this point in the history
…e tiled.

An interface to allow for tiling of operations is introduced. The
tiling of the linalg.pad_tensor operation is modified to use this
interface.

Differential Revision: https://reviews.llvm.org/D108611
  • Loading branch information
MaheshRavishankar committed Aug 30, 2021
1 parent 3fefeba commit ba72cfe
Show file tree
Hide file tree
Showing 14 changed files with 460 additions and 241 deletions.
1 change: 1 addition & 0 deletions mlir/include/mlir/Dialect/Linalg/IR/LinalgOps.h
Expand Up @@ -25,6 +25,7 @@
#include "mlir/Interfaces/CopyOpInterface.h"
#include "mlir/Interfaces/InferTypeOpInterface.h"
#include "mlir/Interfaces/SideEffectInterfaces.h"
#include "mlir/Interfaces/TilingInterface.h"
#include "mlir/Interfaces/ViewLikeInterface.h"
#include "mlir/Support/LLVM.h"

Expand Down
6 changes: 5 additions & 1 deletion mlir/include/mlir/Dialect/Linalg/IR/LinalgOps.td
Expand Up @@ -18,6 +18,7 @@ include "mlir/Interfaces/ControlFlowInterfaces.td"
include "mlir/Interfaces/InferTypeOpInterface.td"
include "mlir/Interfaces/LoopLikeInterface.td"
include "mlir/Interfaces/SideEffectInterfaces.td"
include "mlir/Interfaces/TilingInterface.td"
include "mlir/Interfaces/ViewLikeInterface.td"

// Base class for Linalg dialect ops that do not correspond to library calls.
Expand Down Expand Up @@ -130,7 +131,10 @@ def Linalg_InitTensorOp : Linalg_Op<"init_tensor",

def Linalg_PadTensorOp : Linalg_Op<"pad_tensor",
[AttrSizedOperandSegments, NoSideEffect,
DeclareOpInterfaceMethods<ReifyRankedShapedTypeOpInterface>]> {
DeclareOpInterfaceMethods<ReifyRankedShapedTypeOpInterface>,
DeclareOpInterfaceMethods<TilingInterface,
["getDestinationOperands", "getLoopIteratorTypes", "getLoopBounds",
"getTiledImplementation"]>]> {
let summary = "tensor pad operation";
let description = [{
`linalg.pad_tensor` is an operation that pads the `source` tensor
Expand Down
1 change: 1 addition & 0 deletions mlir/include/mlir/Interfaces/CMakeLists.txt
Expand Up @@ -6,6 +6,7 @@ add_mlir_interface(DerivedAttributeOpInterface)
add_mlir_interface(InferTypeOpInterface)
add_mlir_interface(LoopLikeInterface)
add_mlir_interface(SideEffectInterfaces)
add_mlir_interface(TilingInterface)
add_mlir_interface(VectorInterfaces)
add_mlir_interface(ViewLikeInterface)

Expand Down
26 changes: 26 additions & 0 deletions mlir/include/mlir/Interfaces/TilingInterface.h
@@ -0,0 +1,26 @@
//===- TilingInterface.h - Interface for tiling operations ------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file contains the definitions of the TilingInterface defined in
// `TilingInterface.td`.
//
//===----------------------------------------------------------------------===//

#ifndef MLIR_INTERFACES_TILINGINTERFACE_H_
#define MLIR_INTERFACES_TILINGINTERFACE_H_

#include "mlir/IR/Builders.h"
#include "mlir/IR/BuiltinTypes.h"
#include "mlir/IR/Operation.h"
#include "mlir/Interfaces/ViewLikeInterface.h"
#include "mlir/Support/LLVM.h"

/// Include the ODS generated interface header files.
#include "mlir/Interfaces/TilingInterface.h.inc"

#endif // MLIR_INTERFACES_TILINGINTERFACE_H_
95 changes: 95 additions & 0 deletions mlir/include/mlir/Interfaces/TilingInterface.td
@@ -0,0 +1,95 @@
//===- TilingInterface.td - Interface for tiling operations *- tablegen -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file contains an interface to allow operations to generate a tiled
// implementation of themselves.
//
//===----------------------------------------------------------------------===//

#ifndef MLIR_TILINGINTERFACE
#define MLIR_TILINGINTERFACE

include "mlir/IR/OpBase.td"

def TilingInterface : OpInterface<"TilingInterface"> {
let description = [{
Interface for allowing operations to expose information needed to
tile them (similar to LinalgOp, but without having access to
indexing maps)
}];
let cppNamespace = "::mlir";
let methods = [
InterfaceMethod<
/*desc=*/[{
Returns a list of operands into which the result of the
tiled implementation is written into. With `tensor`
operands, this will be used as the initial tensor into which
the tiled results are inserted into. With `memref` operands,
this will be the operand into which the result of the tiled
operation is written into.
}],
/*retType=*/"SmallVector<Value>",
/*methodName=*/"getDestinationOperands",
/*args=*/(ins "OpBuilder &":$b),
/*methodBody=*/"",
/*defaultImplementation=*/"return ValueRange{};"
>,
InterfaceMethod<
/*desc=*/[{
Returns a list of `StringRef`s that describe the number of
loops and the iterator types of the operation. The list is
expected to use
`getParallelIteratorTypeName()`/`getReductionIteratorTypeName()`
from MLIR Structured Op Utils.
}],
/*retType=*/"SmallVector<StringRef>",
/*methodName=*/"getLoopIteratorTypes"
>,
InterfaceMethod<
/*desc=*/[{
Returns a list of ranges that describe the loop bounds and
step for the loops of the operation.
}],
/*retTy=*/"SmallVector<Range>",
/*methodName=*/"getLoopBounds",
/*args=*/(ins "OpBuilder &":$b)
>,
InterfaceMethod<
/*desc=*/[{
Method to generate the tiled implementation of an operation.

The iteration space of the operation is returned by
`getLoopBounds`. The caller provides the information of the
tile within this iteration space whose implementation the
caller needs.
- `dest` are the Value into which the result of the tiled
operation is to be inserted into. The type of the `dest`
Values is same as the types returned by
`getDestinationOperands` method.
- `offsets` provides the offset of the tile within the
iteration space
- `sizes` provides the size of the tile.

The method returns the operation that is the tiled
implementation.
}],
/*retType=*/"Operation *",
/*methodName=*/"getTiledImplementation",
/*args=*/(ins
"OpBuilder &":$b,
"ValueRange ":$dest,
"ArrayRef<OpFoldResult> ":$offsets,
"ArrayRef<OpFoldResult> ":$sizes),
/*methodBody=*/"",
/*defaultImplementation=*/[{
return nullptr;
}]
>
];
}
#endif // MLIR_TILINGINTERFACE
4 changes: 3 additions & 1 deletion mlir/lib/Dialect/Linalg/IR/CMakeLists.txt
Expand Up @@ -18,9 +18,11 @@ add_mlir_dialect_library(MLIRLinalg
MLIRIR
MLIRParser
MLIRSideEffectInterfaces
MLIRViewLikeInterface
MLIRSCF
MLIRStandard
MLIRMath
MLIRMemRef
MLIRTensor
MLIRTilingInterface
MLIRViewLikeInterface
)

0 comments on commit ba72cfe

Please sign in to comment.