Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[mlir][tensor][linalg] Move RelayoutOpInterface from linalg back to tensor #127533

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions mlir/include/mlir/Dialect/Linalg/IR/Linalg.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
10 changes: 0 additions & 10 deletions mlir/include/mlir/Dialect/Linalg/IR/LinalgInterfaces.td
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion mlir/include/mlir/Dialect/Linalg/IR/LinalgRelayoutOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -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"

//===----------------------------------------------------------------------===//
Expand All @@ -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",
Expand Down
6 changes: 6 additions & 0 deletions mlir/include/mlir/Dialect/Tensor/IR/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
6 changes: 6 additions & 0 deletions mlir/include/mlir/Dialect/Tensor/IR/Tensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
//===----------------------------------------------------------------------===//
Expand Down
30 changes: 30 additions & 0 deletions mlir/include/mlir/Dialect/Tensor/IR/TensorInterfaces.td
Original file line number Diff line number Diff line change
@@ -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

1 change: 1 addition & 0 deletions mlir/lib/Dialect/Tensor/IR/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ add_mlir_dialect_library(MLIRTensorDialect

DEPENDS
MLIRTensorOpsIncGen
MLIRTensorInterfacesIncGen

LINK_LIBS PUBLIC
MLIRAffineDialect
Expand Down
4 changes: 1 addition & 3 deletions mlir/lib/Dialect/Tensor/IR/TensorOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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());
Expand Down
21 changes: 21 additions & 0 deletions utils/bazel/llvm-project-overlay/mlir/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand All @@ -11150,6 +11151,7 @@ td_library(
":LoopLikeInterfaceTdFiles",
":OpBaseTdFiles",
":SideEffectInterfacesTdFiles",
":TensorOpsTdFiles",
":TilingInterfaceTdFiles",
":ViewLikeInterfaceTdFiles",
],
Expand Down Expand Up @@ -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 = [
Expand Down Expand Up @@ -11557,6 +11576,7 @@ cc_library(
":LinalgInterfacesIncGen",
":LinalgNamedStructuredOpsYamlIncGen",
":LinalgOpsIncGen",
":LinalgRelayoutOpsIncGen",
":LinalgStructuredOpsIncGen",
":MathDialect",
":MemRefDialect",
Expand All @@ -11568,6 +11588,7 @@ cc_library(
":SubsetOpInterface",
":Support",
":TensorDialect",
":TensorUtils",
":TilingInterface",
":ValueBoundsOpInterface",
":ViewLikeInterface",
Expand Down