[Mlir-commits] [llvm] [mlir] [mlir][tensor][linalg] Move RelayoutOpInterface from linalg back to tensor (PR #127533)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Mon Feb 17 10:29:45 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir-linalg
Author: Christian Sigg (chsigg)
<details>
<summary>Changes</summary>
RelayoutOpInterface is used only to identify tensor.pack/tensor.unpack ops.
This CL moves this interface back to the tensor dialect, to allow the removal of the linalg dialect dependency from the tensor dialect.
This is a partial revert of https://github.com/llvm/llvm-project/pull/125823.
---
Full diff: https://github.com/llvm/llvm-project/pull/127533.diff
9 Files Affected:
- (modified) mlir/include/mlir/Dialect/Linalg/IR/Linalg.h (+1)
- (modified) mlir/include/mlir/Dialect/Linalg/IR/LinalgInterfaces.td (-10)
- (modified) mlir/include/mlir/Dialect/Linalg/IR/LinalgRelayoutOps.td (+2-1)
- (modified) mlir/include/mlir/Dialect/Tensor/IR/CMakeLists.txt (+6)
- (modified) mlir/include/mlir/Dialect/Tensor/IR/Tensor.h (+6)
- (added) mlir/include/mlir/Dialect/Tensor/IR/TensorInterfaces.td (+30)
- (modified) mlir/lib/Dialect/Tensor/IR/CMakeLists.txt (+1)
- (modified) mlir/lib/Dialect/Tensor/IR/TensorOps.cpp (+1-3)
- (modified) utils/bazel/llvm-project-overlay/mlir/BUILD.bazel (+21)
``````````diff
diff --git a/mlir/include/mlir/Dialect/Linalg/IR/Linalg.h b/mlir/include/mlir/Dialect/Linalg/IR/Linalg.h
index 57bf6305a469d..38a8d18e56b05 100644
--- a/mlir/include/mlir/Dialect/Linalg/IR/Linalg.h
+++ b/mlir/include/mlir/Dialect/Linalg/IR/Linalg.h
@@ -10,6 +10,7 @@
#define MLIR_DIALECT_LINALG_IR_LINALG_H
#include "mlir/Bytecode/BytecodeOpInterface.h"
+#include "mlir/Dialect/Tensor/IR/Tensor.h"
#include "mlir/Dialect/Utils/ReshapeOpsUtils.h"
#include "mlir/Dialect/Utils/StructuredOpsUtils.h"
#include "mlir/IR/AffineExpr.h"
diff --git a/mlir/include/mlir/Dialect/Linalg/IR/LinalgInterfaces.td b/mlir/include/mlir/Dialect/Linalg/IR/LinalgInterfaces.td
index 247afc141c180..dbc1ac60e0973 100644
--- a/mlir/include/mlir/Dialect/Linalg/IR/LinalgInterfaces.td
+++ b/mlir/include/mlir/Dialect/Linalg/IR/LinalgInterfaces.td
@@ -178,16 +178,6 @@ def LinalgConvolutionOpInterface : OpInterface<"ConvolutionOpInterface"> {
];
}
-def LinalgRelayoutOpInterface : OpInterface<"RelayoutOpInterface"> {
- let description = [{
- A Linalg relayout-op is either linalg.pack or linalg.unpack.
-
- While we could extend this interface with methods from Linalg_RelayoutOp,
- this is currently not needed and left as a TODO.
- }];
- let cppNamespace = "::mlir::linalg";
-}
-
def LinalgFillOpInterface : OpInterface<"FillOpInterface"> {
let description = [{
A fill operation is defined in general terms:
diff --git a/mlir/include/mlir/Dialect/Linalg/IR/LinalgRelayoutOps.td b/mlir/include/mlir/Dialect/Linalg/IR/LinalgRelayoutOps.td
index a08a778fc25e1..2b27f2c908c64 100644
--- a/mlir/include/mlir/Dialect/Linalg/IR/LinalgRelayoutOps.td
+++ b/mlir/include/mlir/Dialect/Linalg/IR/LinalgRelayoutOps.td
@@ -23,6 +23,7 @@ include "mlir/Interfaces/DestinationStyleOpInterface.td"
include "mlir/Interfaces/SideEffectInterfaces.td"
include "mlir/Interfaces/InferTypeOpInterface.td"
include "mlir/Dialect/Linalg/IR/LinalgInterfaces.td"
+include "mlir/Dialect/Tensor/IR/TensorInterfaces.td"
include "mlir/IR/OpAsmInterface.td"
//===----------------------------------------------------------------------===//
@@ -32,7 +33,7 @@ include "mlir/IR/OpAsmInterface.td"
class Linalg_RelayoutOp<string mnemonic, list<Trait> traits = []> :
Op<Linalg_Dialect, mnemonic, !listconcat(traits, [
DeclareOpInterfaceMethods<OpAsmOpInterface, ["getAsmResultNames"]>,
- DestinationStyleOpInterface, LinalgRelayoutOpInterface,
+ DestinationStyleOpInterface, TensorRelayoutOpInterface,
ConditionallySpeculatable, NoMemoryEffect,
DeclareOpInterfaceMethods<ReifyRankedShapedTypeOpInterface>,
TypesMatchWith<"result type matches type of dest",
diff --git a/mlir/include/mlir/Dialect/Tensor/IR/CMakeLists.txt b/mlir/include/mlir/Dialect/Tensor/IR/CMakeLists.txt
index cd14fe5c04561..74a05291376b3 100644
--- a/mlir/include/mlir/Dialect/Tensor/IR/CMakeLists.txt
+++ b/mlir/include/mlir/Dialect/Tensor/IR/CMakeLists.txt
@@ -1,2 +1,8 @@
add_mlir_dialect(TensorOps tensor)
add_mlir_doc(TensorOps TensorOps Dialects/ -gen-dialect-doc)
+
+set(LLVM_TARGET_DEFINITIONS TensorInterfaces.td)
+mlir_tablegen(TensorInterfaces.h.inc -gen-op-interface-decls)
+mlir_tablegen(TensorInterfaces.cpp.inc -gen-op-interface-defs)
+add_public_tablegen_target(MLIRTensorInterfacesIncGen)
+add_dependencies(mlir-headers MLIRTensorInterfacesIncGen)
diff --git a/mlir/include/mlir/Dialect/Tensor/IR/Tensor.h b/mlir/include/mlir/Dialect/Tensor/IR/Tensor.h
index eb550bb469b9f..b3ec796a72337 100644
--- a/mlir/include/mlir/Dialect/Tensor/IR/Tensor.h
+++ b/mlir/include/mlir/Dialect/Tensor/IR/Tensor.h
@@ -46,6 +46,12 @@ SmallVector<Range, 8> getOrCreateRanges(OffsetSizeAndStrideOpInterface op,
#include "mlir/Dialect/Tensor/IR/TensorOpsDialect.h.inc"
+//===----------------------------------------------------------------------===//
+// Tensor Interfaces
+//===----------------------------------------------------------------------===//
+
+#include "mlir/Dialect/Tensor/IR/TensorInterfaces.h.inc"
+
//===----------------------------------------------------------------------===//
// Tensor Dialect Operations
//===----------------------------------------------------------------------===//
diff --git a/mlir/include/mlir/Dialect/Tensor/IR/TensorInterfaces.td b/mlir/include/mlir/Dialect/Tensor/IR/TensorInterfaces.td
new file mode 100644
index 0000000000000..83c173b182664
--- /dev/null
+++ b/mlir/include/mlir/Dialect/Tensor/IR/TensorInterfaces.td
@@ -0,0 +1,30 @@
+//===- TensorInterfaces.td - Tensor Interfaces Declaration -*- 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 is the definition file for the structured interface sfor Tensor ops.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef TENSOR_IR_TENSORINTERFACES
+#define TENSOR_IR_TENSORINTERFACES
+
+include "mlir/Interfaces/DestinationStyleOpInterface.td"
+include "mlir/IR/OpBase.td"
+
+def TensorRelayoutOpInterface : OpInterface<"RelayoutOpInterface"> {
+ let description = [{
+ A Tensor relayout-op is either linalg.pack or linalg.unpack.
+
+ While we could extend this interface with methods from Linalg_RelayoutOp,
+ this is currently not needed and left as a TODO.
+ }];
+ let cppNamespace = "::mlir::tensor";
+}
+
+#endif // TENSOR_IR_TENSORINTERFACES
+
diff --git a/mlir/lib/Dialect/Tensor/IR/CMakeLists.txt b/mlir/lib/Dialect/Tensor/IR/CMakeLists.txt
index 5425615dac393..d9d09d6361a2f 100644
--- a/mlir/lib/Dialect/Tensor/IR/CMakeLists.txt
+++ b/mlir/lib/Dialect/Tensor/IR/CMakeLists.txt
@@ -16,6 +16,7 @@ add_mlir_dialect_library(MLIRTensorDialect
DEPENDS
MLIRTensorOpsIncGen
+ MLIRTensorInterfacesIncGen
LINK_LIBS PUBLIC
MLIRAffineDialect
diff --git a/mlir/lib/Dialect/Tensor/IR/TensorOps.cpp b/mlir/lib/Dialect/Tensor/IR/TensorOps.cpp
index e741144647043..eeef383ac531a 100644
--- a/mlir/lib/Dialect/Tensor/IR/TensorOps.cpp
+++ b/mlir/lib/Dialect/Tensor/IR/TensorOps.cpp
@@ -10,9 +10,7 @@
#include "mlir/Dialect/Arith/IR/Arith.h"
#include "mlir/Dialect/Arith/Utils/Utils.h"
#include "mlir/Dialect/Complex/IR/Complex.h"
-#include "mlir/Dialect/Linalg/IR/Linalg.h"
#include "mlir/Dialect/Tensor/IR/Tensor.h"
-#include "mlir/Dialect/Tensor/Utils/Utils.h"
#include "mlir/Dialect/Utils/IndexingUtils.h"
#include "mlir/Dialect/Utils/ReshapeOpsUtils.h"
#include "mlir/Dialect/Utils/StaticValueUtils.h"
@@ -3914,7 +3912,7 @@ struct FoldTensorCastProducerOp
// Reject PackOp/UnpackOp (i.e. RelayoutOps) - there are dedicated patterns
// for that instead.
if (!foldTensorCastPrecondition(op) ||
- isa<linalg::RelayoutOpInterface>(*op))
+ isa<tensor::RelayoutOpInterface>(*op))
return failure();
SmallVector<Type> newResultTypes(op->getResultTypes());
diff --git a/utils/bazel/llvm-project-overlay/mlir/BUILD.bazel b/utils/bazel/llvm-project-overlay/mlir/BUILD.bazel
index 92aedac837197..2569847ab6efe 100644
--- a/utils/bazel/llvm-project-overlay/mlir/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/mlir/BUILD.bazel
@@ -11140,6 +11140,7 @@ td_library(
"include/mlir/Dialect/Linalg/IR/LinalgEnums.td",
"include/mlir/Dialect/Linalg/IR/LinalgInterfaces.td",
"include/mlir/Dialect/Linalg/IR/LinalgOps.td",
+ "include/mlir/Dialect/Linalg/IR/LinalgRelayoutOps.td",
],
includes = ["include"],
deps = [
@@ -11150,6 +11151,7 @@ td_library(
":LoopLikeInterfaceTdFiles",
":OpBaseTdFiles",
":SideEffectInterfacesTdFiles",
+ ":TensorOpsTdFiles",
":TilingInterfaceTdFiles",
":ViewLikeInterfaceTdFiles",
],
@@ -11206,6 +11208,23 @@ gentbl_cc_library(
deps = [":LinalgOpsTdFiles"],
)
+gentbl_cc_library(
+ name = "LinalgRelayoutOpsIncGen",
+ tbl_outs = [
+ (
+ ["-gen-op-decls"],
+ "include/mlir/Dialect/Linalg/IR/LinalgRelayoutOps.h.inc",
+ ),
+ (
+ ["-gen-op-defs"],
+ "include/mlir/Dialect/Linalg/IR/LinalgRelayoutOps.cpp.inc",
+ ),
+ ],
+ tblgen = ":mlir-tblgen",
+ td_file = "include/mlir/Dialect/Linalg/IR/LinalgRelayoutOps.td",
+ deps = [":LinalgOpsTdFiles"],
+)
+
gentbl_cc_library(
name = "LinalgEnumsIncGen",
tbl_outs = [
@@ -11557,6 +11576,7 @@ cc_library(
":LinalgInterfacesIncGen",
":LinalgNamedStructuredOpsYamlIncGen",
":LinalgOpsIncGen",
+ ":LinalgRelayoutOpsIncGen",
":LinalgStructuredOpsIncGen",
":MathDialect",
":MemRefDialect",
@@ -11568,6 +11588,7 @@ cc_library(
":SubsetOpInterface",
":Support",
":TensorDialect",
+ ":TensorUtils",
":TilingInterface",
":ValueBoundsOpInterface",
":ViewLikeInterface",
``````````
</details>
https://github.com/llvm/llvm-project/pull/127533
More information about the Mlir-commits
mailing list