Skip to content

Commit 1abd8d1

Browse files
[mlir][Interfaces] Add SubsetOpInterface and SubsetExtractionOpInterface (#70617)
There is currently an op interface for subset insertion ops (`SubsetInsertionOpInterface`), but not for subset extraction ops. This commit adds `SubsetExtractionOpInterface` to `mlir/Interfaces`, as well as a common dependent op interface: `SubsetOpInterface`. - `SubsetOpInterface` is for ops that operate on tensor subsets. It provides interface methods to check if two subset ops operate on equivalent or disjoint subsets. Ops that implement this interface must implement either `SubsetExtractionOpInterface` or `SubsetInsertionOpInterface`. - `SubsetExtractionOpInterface` is for ops that extract from a tensor at a subset. E.g., `tensor.extract_slice`, `tensor.gather`, `vector.transfer_read`. Current implemented only on `tensor.extract_slice`. - `SubsetInsertionOpInterface` is for ops that insert into a destination tensor at a subset. E.g., `tensor.insert_slice`, `tensor.parallel_insert_slice`, `tensor.scatter`, `vector.transfer_write`. Currently only implemented on `tensor.insert_slice`, `tensor.parallel_insert_slice`. Other changes: - Rename `SubsetInsertionOpInterface.td` to `SubsetOpInterface.td`. - Add helper functions to `ValueBoundsOpInterface.cpp` for checking whether two slices are disjoint. The new interfaces will be utilized by a new "loop-invariant subset hoisting" transformation. (This new transform is roughly what `Linalg/Transforms/SubsetHoisting.cpp` is doing, but in a generic and interface-driven way.)
1 parent 8b91de5 commit 1abd8d1

27 files changed

+654
-290
lines changed

mlir/include/mlir/Dialect/Bufferization/IR/Bufferization.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#include "mlir/Interfaces/CopyOpInterface.h"
1616
#include "mlir/Interfaces/DestinationStyleOpInterface.h"
1717
#include "mlir/Interfaces/InferTypeOpInterface.h"
18-
#include "mlir/Interfaces/SubsetInsertionOpInterface.h"
18+
#include "mlir/Interfaces/SubsetOpInterface.h"
1919

2020
//===----------------------------------------------------------------------===//
2121
// Bufferization Dialect

mlir/include/mlir/Dialect/Bufferization/IR/BufferizationOps.td

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ include "mlir/Dialect/Bufferization/IR/BufferizationBase.td"
1515
include "mlir/Interfaces/DestinationStyleOpInterface.td"
1616
include "mlir/Interfaces/InferTypeOpInterface.td"
1717
include "mlir/Interfaces/SideEffectInterfaces.td"
18-
include "mlir/Interfaces/SubsetInsertionOpInterface.td"
18+
include "mlir/Interfaces/SubsetOpInterface.td"
1919
include "mlir/Interfaces/CopyOpInterface.td"
2020

2121
class Bufferization_Op<string mnemonic, list<Trait> traits = []>
@@ -220,6 +220,7 @@ def Bufferization_MaterializeInDestinationOp
220220
AllElementTypesMatch<["source", "dest"]>,
221221
BufferizableOpInterface, DestinationStyleOpInterface,
222222
DeclareOpInterfaceMethods<ReifyRankedShapedTypeOpInterface>,
223+
DeclareOpInterfaceMethods<SubsetOpInterface>,
223224
DeclareOpInterfaceMethods<SubsetInsertionOpInterface,
224225
["getSourceOperand", "getValuesNeededToBuildSubsetExtraction",
225226
"buildSubsetExtraction", "isEquivalentSubset"]>,

mlir/include/mlir/Dialect/Linalg/Transforms/SubsetInsertionOpInterfaceImpl.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ namespace mlir {
1313
class DialectRegistry;
1414

1515
namespace linalg {
16-
void registerSubsetInsertionOpInterfaceExternalModels(
17-
DialectRegistry &registry);
16+
void registerSubsetOpInterfaceExternalModels(DialectRegistry &registry);
1817
} // namespace linalg
1918
} // namespace mlir
2019

mlir/include/mlir/Dialect/Tensor/Transforms/SubsetInsertionOpInterfaceImpl.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ namespace mlir {
1313
class DialectRegistry;
1414

1515
namespace tensor {
16-
void registerSubsetInsertionOpInterfaceExternalModels(
17-
DialectRegistry &registry);
16+
void registerSubsetOpInterfaceExternalModels(DialectRegistry &registry);
1817
} // namespace tensor
1918
} // namespace mlir
2019

mlir/include/mlir/InitAllDialects.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ inline void registerAllDialects(DialectRegistry &registry) {
151151
cf::registerBufferDeallocationOpInterfaceExternalModels(registry);
152152
gpu::registerBufferDeallocationOpInterfaceExternalModels(registry);
153153
linalg::registerBufferizableOpInterfaceExternalModels(registry);
154-
linalg::registerSubsetInsertionOpInterfaceExternalModels(registry);
154+
linalg::registerSubsetOpInterfaceExternalModels(registry);
155155
linalg::registerTilingInterfaceExternalModels(registry);
156156
linalg::registerValueBoundsOpInterfaceExternalModels(registry);
157157
memref::registerAllocationOpInterfaceExternalModels(registry);
@@ -167,7 +167,7 @@ inline void registerAllDialects(DialectRegistry &registry) {
167167
tensor::registerBufferizableOpInterfaceExternalModels(registry);
168168
tensor::registerFindPayloadReplacementOpInterfaceExternalModels(registry);
169169
tensor::registerInferTypeOpInterfaceExternalModels(registry);
170-
tensor::registerSubsetInsertionOpInterfaceExternalModels(registry);
170+
tensor::registerSubsetOpInterfaceExternalModels(registry);
171171
tensor::registerTilingInterfaceExternalModels(registry);
172172
tensor::registerValueBoundsOpInterfaceExternalModels(registry);
173173
vector::registerBufferizableOpInterfaceExternalModels(registry);

mlir/include/mlir/Interfaces/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ add_mlir_interface(ParallelCombiningOpInterface)
1212
add_mlir_interface(RuntimeVerifiableOpInterface)
1313
add_mlir_interface(ShapedOpInterfaces)
1414
add_mlir_interface(SideEffectInterfaces)
15-
add_mlir_interface(SubsetInsertionOpInterface)
15+
add_mlir_interface(SubsetOpInterface)
1616
add_mlir_interface(TilingInterface)
1717
add_mlir_interface(ValueBoundsOpInterface)
1818
add_mlir_interface(VectorInterfaces)

mlir/include/mlir/Interfaces/SubsetInsertionOpInterface.h

Lines changed: 0 additions & 27 deletions
This file was deleted.

mlir/include/mlir/Interfaces/SubsetInsertionOpInterface.td

Lines changed: 0 additions & 155 deletions
This file was deleted.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
//===- SubsetOpInterface.h - Tensor Subsets ---------------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef MLIR_INTERFACES_SUBSETOPINTERFACE_H_
10+
#define MLIR_INTERFACES_SUBSETOPINTERFACE_H_
11+
12+
#include "mlir/IR/OpDefinition.h"
13+
14+
namespace mlir {
15+
class SubsetOpInterface;
16+
class SubsetExtractionOpInterface;
17+
class SubsetInsertionOpInterface;
18+
19+
namespace detail {
20+
21+
/// Return the destination/"init" operand of the op if it implements the
22+
/// `DestinationStyleOpInterface` and has exactly one "init" operand. Asserts
23+
/// otherwise.
24+
OpOperand &defaultGetDestinationOperand(Operation *op);
25+
26+
/// Return the updated destination result of the op if it implements the
27+
/// `DestinationStyleOpInterface`.
28+
OpResult defaultGetUpdatedDestination(Operation *op);
29+
30+
/// Default implementation of `isEquivalentSubset`.
31+
bool defaultIsEquivalentSubset(Operation *op, Value candidate,
32+
function_ref<bool(Value, Value)> equivalenceFn);
33+
34+
/// Verify `SubsetOpInterface`.
35+
LogicalResult verifySubsetOpInterface(SubsetOpInterface op);
36+
37+
/// Verify `SubsetExtractionOpInterface`.
38+
LogicalResult verifySubsetExtractionOpInterface(SubsetExtractionOpInterface op);
39+
40+
} // namespace detail
41+
} // namespace mlir
42+
43+
#include "mlir/Interfaces/SubsetOpInterface.h.inc"
44+
45+
#endif // MLIR_INTERFACES_SUBSETOPINTERFACE_H_

0 commit comments

Comments
 (0)