Skip to content

Commit

Permalink
[Encoding] Introduce EncodingLayoutAttrInterface. (iree-org#19216)
Browse files Browse the repository at this point in the history
The revisions introduces a new attribute interface in the Encoding
dialect. The interface is used to query layout information needed to
materialize encoding attributes.

Any backend can implement the interface to interpret an encoding layout
based on their needs.

The current expectation of the interface is to propagate layout
information from backends to the host compilation or other targets. The
expectation can be adjusted as long as we identify additional needs for
encodings/layouts.

It is a step towards iree-org#17924

---------

Signed-off-by: hanhanW <[email protected]>
  • Loading branch information
hanhanW authored Nov 21, 2024
1 parent b9d73cf commit 16a22e2
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 0 deletions.
21 changes: 21 additions & 0 deletions compiler/src/iree/compiler/Dialect/Encoding/IR/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ iree_td_library(
[
"EncodingAttrs.td",
"EncodingBase.td",
"EncodingInterfaces.td",
"EncodingOps.td",
],
include = ["*.td"],
Expand All @@ -45,6 +46,7 @@ iree_compiler_cc_library(
"EncodingDialect.cpp",
"EncodingDialect.cpp.inc",
"EncodingEnums.cpp.inc",
"EncodingInterfaces.cpp.inc",
"EncodingOps.cpp",
"EncodingOps.cpp.inc",
"EncodingTypes.cpp.inc",
Expand All @@ -54,13 +56,15 @@ iree_compiler_cc_library(
"EncodingDialect.h",
"EncodingDialect.h.inc",
"EncodingEnums.h.inc",
"EncodingInterfaces.h.inc",
"EncodingOps.h",
"EncodingOps.h.inc",
"EncodingTypes.h",
"EncodingTypes.h.inc",
],
deps = [
":EncodingEnumsGen",
":EncodingInterfacesGen",
":EncodingOpsIncGen",
":EncodingTypesGen",
"@llvm-project//llvm:Support",
Expand Down Expand Up @@ -139,6 +143,23 @@ iree_gentbl_cc_library(
deps = [":td_files"],
)

iree_gentbl_cc_library(
name = "EncodingInterfacesGen",
tbl_outs = [
(
["--gen-attr-interface-decls"],
"EncodingInterfaces.h.inc",
),
(
["--gen-attr-interface-defs"],
"EncodingInterfaces.cpp.inc",
),
],
tblgen = "@llvm-project//mlir:mlir-tblgen",
td_file = "EncodingInterfaces.td",
deps = [":td_files"],
)

iree_gentbl_cc_library(
name = "EncodingTypesGen",
tbl_outs = [
Expand Down
13 changes: 13 additions & 0 deletions compiler/src/iree/compiler/Dialect/Encoding/IR/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ iree_cc_library(
"EncodingDialect.h"
"EncodingDialect.h.inc"
"EncodingEnums.h.inc"
"EncodingInterfaces.h.inc"
"EncodingOps.h"
"EncodingOps.h.inc"
"EncodingTypes.h"
Expand All @@ -28,11 +29,13 @@ iree_cc_library(
"EncodingDialect.cpp"
"EncodingDialect.cpp.inc"
"EncodingEnums.cpp.inc"
"EncodingInterfaces.cpp.inc"
"EncodingOps.cpp"
"EncodingOps.cpp.inc"
"EncodingTypes.cpp.inc"
DEPS
::EncodingEnumsGen
::EncodingInterfacesGen
::EncodingOpsIncGen
::EncodingTypesGen
LLVMSupport
Expand Down Expand Up @@ -83,6 +86,16 @@ iree_tablegen_library(
--dialect=iree_encoding --gen-dialect-defs EncodingDialect.cpp.inc
)

iree_tablegen_library(
NAME
EncodingInterfacesGen
TD_FILE
"EncodingInterfaces.td"
OUTS
--gen-attr-interface-decls EncodingInterfaces.h.inc
--gen-attr-interface-defs EncodingInterfaces.cpp.inc
)

iree_tablegen_library(
NAME
EncodingTypesGen
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#define GET_ATTRDEF_CLASSES
#include "iree/compiler/Dialect/Encoding/IR/EncodingAttrs.cpp.inc"
#include "iree/compiler/Dialect/Encoding/IR/EncodingEnums.cpp.inc"
#include "iree/compiler/Dialect/Encoding/IR/EncodingInterfaces.cpp.inc"
#undef GET_ATTRDEF_CLASSES

namespace mlir::iree_compiler::IREE::Encoding {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright 2024 The IREE Authors
//
// Licensed 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

#ifndef IREE_DIALECT_ENCODING_INTERFACES
#define IREE_DIALECT_ENCODING_INTERFACES

include "iree/compiler/Dialect/Encoding/IR/EncodingBase.td"
include "mlir/IR/BuiltinAttributeInterfaces.td"

def IREEEncoding_EncodingLayoutAttrInterface :
AttrInterface<"EncodingLayoutAttrInterface"> {
let cppNamespace = "::mlir::iree_compiler::IREE::Encoding";
let description = [{
Interface used to query layout information needed to materialize encoding
attributes.

Any backend can implement the interface to interpret an encoding layout
based on their needs.

TBD. The current expectation of the interface is to propagate layout
information from backends to the host compliation or other targets.
}];

let methods = [
InterfaceMethod<
/*desc=*/[{
Returns the storage size (in bytes) for the tensor types with an
optional encoding.
}],
/*retTy=*/"::mlir::OpFoldResult",
/*methodName=*/"calculateStorageSizeInBytes",
/*args=*/(ins
"::mlir::OpBuilder &":$builder,
"RankedTensorType":$type,
"ValueRange":$dynamicDims
),
/*methodBody=*/"",
/*defaultImplementation=*/[{
assert(false && "unimplemented interface method");
return {};
}]
>
];
}

#endif // IREE_DIALECT_ENCODING_INTERFACES
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

// clang-format off
#include "iree/compiler/Dialect/Encoding/IR/EncodingEnums.h.inc" // IWYU pragma: export
#include "iree/compiler/Dialect/Encoding/IR/EncodingInterfaces.h.inc" // IWYU pragma: export
#define GET_ATTRDEF_CLASSES
#include "iree/compiler/Dialect/Encoding/IR/EncodingAttrs.h.inc" // IWYU pragma: export
#undef GET_ATTRDEF_CLASSES
Expand Down

0 comments on commit 16a22e2

Please sign in to comment.