Skip to content

Commit 4c5c8a7

Browse files
committed
[DT] Collapse MaterializeEncodingIntoPaddingPass into the generic pass.
Signed-off-by: hanhanW <[email protected]>
1 parent bf3fa4d commit 4c5c8a7

14 files changed

+68
-184
lines changed

compiler/src/iree/compiler/Codegen/Common/BUILD.bazel

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ iree_compiler_cc_library(
127127
"LoweringConfigInterpreter.cpp",
128128
"MaterializeEncoding.cpp",
129129
"MaterializeEncodingIntoNop.cpp",
130-
"MaterializeEncodingIntoPadding.cpp",
131130
"MaterializeEncodingPatterns.cpp",
132131
"MaterializeTuningSpecsPass.cpp",
133132
"MathTransformPass.cpp",

compiler/src/iree/compiler/Codegen/Common/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ iree_cc_library(
120120
"LoweringConfigInterpreter.cpp"
121121
"MaterializeEncoding.cpp"
122122
"MaterializeEncodingIntoNop.cpp"
123-
"MaterializeEncodingIntoPadding.cpp"
124123
"MaterializeEncodingPatterns.cpp"
125124
"MaterializeTuningSpecsPass.cpp"
126125
"MathTransformPass.cpp"

compiler/src/iree/compiler/Codegen/Common/EncodingUtils.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,23 @@
1010
#include "iree/compiler/Codegen/Dialect/Codegen/Utils/Utils.h"
1111
#include "iree/compiler/Dialect/Encoding/IR/EncodingOps.h"
1212
#include "iree/compiler/Dialect/TensorExt/IR/TensorExtTypes.h"
13-
#include "mlir/Dialect/Tensor/IR/Tensor.h"
1413
#include "mlir/Transforms/DialectConversion.h"
1514

1615
namespace mlir::iree_compiler {
1716

17+
//===---------------------------------------------------------------------===//
18+
// Utilities for testing purpose.
19+
//===---------------------------------------------------------------------===//
20+
21+
namespace detail {
22+
/// Kinds of testing resolvers for MaterializeDeviceEncodingPass.
23+
enum class TestingResolverKind {
24+
kGPUDataTiling, // iree_gpu.gpu_encoding_resolver<>
25+
kGPUPadding, // iree_gpu.gpu_padding_resolver<>
26+
kNone // Do not create any specific resolver.
27+
};
28+
} // namespace detail
29+
1830
//===---------------------------------------------------------------------===//
1931
// TypeConverter
2032
//===---------------------------------------------------------------------===//

compiler/src/iree/compiler/Codegen/Common/MaterializeEncoding.cpp

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "iree/compiler/Codegen/Dialect/Codegen/IR/IREECodegenDialect.h"
1111
#include "iree/compiler/Codegen/Dialect/GPU/IR/IREEGPUAttrs.h"
1212
#include "iree/compiler/Codegen/Dialect/GPU/IR/IREEGPUDialect.h"
13+
#include "iree/compiler/Codegen/Dialect/GPU/TargetUtils/KnownTargets.h"
1314
#include "iree/compiler/Codegen/Utils/GPUUtils.h"
1415
#include "iree/compiler/Dialect/Encoding/IR/EncodingTypes.h"
1516
#include "iree/compiler/Dialect/HAL/Analysis/DeviceAnalysis.h"
@@ -59,43 +60,43 @@ updateFuncSignature(FunctionOpInterface funcOp,
5960
}
6061
}
6162

62-
static LogicalResult
63-
materializeFuncOpEncodings(FunctionOpInterface funcOp,
64-
IREE::HAL::ExecutableTargetAttr targetAttr,
65-
bool testCLGPUTarget = false) {
63+
static LogicalResult materializeFuncOpEncodings(
64+
FunctionOpInterface funcOp, IREE::HAL::ExecutableTargetAttr targetAttr,
65+
::mlir::iree_compiler::detail::TestingResolverKind resolverSource =
66+
::mlir::iree_compiler::detail::TestingResolverKind::kNone) {
6667
MLIRContext *ctx = funcOp.getContext();
6768
{
6869
RewritePatternSet patterns(ctx);
6970
DictionaryAttr targetConfig =
7071
targetAttr ? targetAttr.getConfiguration() : nullptr;
71-
// Check if the encoding resolver is a GPUPaddingResolverAttr. For padding
72-
// encoding materialization, we use a separate pass, so skip materialization
73-
// here.
74-
// TODO(#20160): Support GPUPaddingResolverAttr materialization through this
75-
// pass, and remove the ad-hoc materialization pass for padding.
76-
if (targetConfig && targetConfig.getAs<IREE::GPU::GPUPaddingResolverAttr>(
77-
IREE::Encoding::kEncodingResolverAttrName)) {
78-
LDBG()
79-
<< "Found GPUPaddingResolverAttr encoding resolver. Materialization "
80-
"will be handled later.";
81-
return success();
82-
}
83-
8472
auto getTestTargetOrNopLayout =
8573
[&]() -> IREE::Encoding::LayoutMaterializerAttr {
86-
if (testCLGPUTarget) {
74+
LDBG() << "Select GPUEncodingResolverAttr attribute as the layout "
75+
"attribute. (testCLGPUTarget)";
76+
SmallVector<NamedAttribute> configItems;
77+
IREE::GPU::TargetAttr targetAttr =
78+
getGPUTargetAttr(ctx, /*target=*/nullptr);
79+
addConfigGPUTarget(ctx, targetAttr, configItems);
80+
switch (resolverSource) {
81+
case ::mlir::iree_compiler::detail::TestingResolverKind::kGPUDataTiling: {
8782
LDBG() << "Select GPUEncodingResolverAttr attribute as the layout "
88-
"attribute. (testCLGPUTarget)";
89-
SmallVector<NamedAttribute> configItems;
90-
// Setting a nullptr to `target` below returns the target from command
91-
// line.
92-
IREE::GPU::TargetAttr targetAttr =
93-
getGPUTargetAttr(ctx, /*target=*/nullptr);
94-
addConfigGPUTarget(ctx, targetAttr, configItems);
83+
"attribute. (kGPUDataTiling)";
9584
return cast<IREE::Encoding::LayoutMaterializerAttr>(
9685
IREE::GPU::GPUEncodingResolverAttr::get(
9786
ctx, DictionaryAttr::get(ctx, configItems)));
9887
}
88+
case ::mlir::iree_compiler::detail::TestingResolverKind::kGPUPadding: {
89+
LDBG() << "Select GPUPaddingResolverAttr attribute as the layout "
90+
"attribute. (kGPUPadding)";
91+
std::optional<IREE::GPU::L1CacheInfo> cache =
92+
IREE::GPU::getL1CacheInfo(targetAttr);
93+
return cast<IREE::Encoding::LayoutMaterializerAttr>(
94+
IREE::GPU::GPUPaddingResolverAttr::get(ctx, cache->cacheLineBytes,
95+
cache->cacheSets));
96+
}
97+
case ::mlir::iree_compiler::detail::TestingResolverKind::kNone:
98+
break;
99+
}
99100
LDBG() << "Select IdentityResolverAttr attribute as the layout "
100101
"attribute (Encoding resolver unknown or unsupported).";
101102
return cast<IREE::Encoding::LayoutMaterializerAttr>(
@@ -132,10 +133,10 @@ materializeFuncOpEncodings(FunctionOpInterface funcOp,
132133
populateMaterializeEncodingPatterns(patterns, target, typeConverter);
133134

134135
// Replace any unrealized conversions to tensor.cast ops if they come from
135-
// block arguments. The function signature is updated to match the converted
136-
// types after the partial conversion. This is used in testing, where
137-
// function arguments have encodings to reduce the amount of IR, but we do
138-
// not expect function arguments to have encodings in practice.
136+
// block arguments. The function signature is updated to match the
137+
// converted types after the partial conversion. This is used in testing,
138+
// where function arguments have encodings to reduce the amount of IR, but
139+
// we do not expect function arguments to have encodings in practice.
139140
auto castFnArguments = [](OpBuilder &builder, Type resultTy,
140141
ValueRange inputs, Location loc) -> Value {
141142
if (inputs.size() != 1) {
@@ -174,11 +175,11 @@ materializeFuncOpEncodings(FunctionOpInterface funcOp,
174175
patterns, [](OpOperand *opOperand) {
175176
Operation *producer = opOperand->get().getDefiningOp();
176177
Operation *consumer = opOperand->getOwner();
177-
// If we have a pack/unpack consumer and a producer that has multiple
178-
// uses, this _probably_ means the producer won't get dce'd. If that
179-
// is the case, by folding the consumer pack/unpack, we break the
180-
// producer consumer chain between them and inhibit fusion later in
181-
// the pipeline.
178+
// If we have a pack/unpack consumer and a producer that has
179+
// multiple uses, this _probably_ means the producer won't get
180+
// dce'd. If that is the case, by folding the consumer pack/unpack,
181+
// we break the producer consumer chain between them and inhibit
182+
// fusion later in the pipeline.
182183
if (isa<linalg::PackOp, linalg::UnPackOp>(consumer) &&
183184
isa_and_nonnull<TilingInterface>(producer) &&
184185
!producer->hasOneUse())
@@ -301,7 +302,7 @@ struct MaterializeDeviceEncodingPass final
301302
FunctionOpInterface funcOp = getOperation();
302303
auto executableTargetAttr = IREE::HAL::ExecutableTargetAttr::lookup(funcOp);
303304
if (failed(materializeFuncOpEncodings(funcOp, executableTargetAttr,
304-
testCLGPUTarget))) {
305+
testGPUEncodingResolver))) {
305306
return signalPassFailure();
306307
}
307308
}

compiler/src/iree/compiler/Codegen/Common/MaterializeEncodingIntoPadding.cpp

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

compiler/src/iree/compiler/Codegen/Common/Passes.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#define IREE_COMPILER_CODEGEN_COMMON_PASSES_H_
1414

1515
#include "iree/compiler/Codegen/Common/CombineLayoutTransformation.h"
16+
#include "iree/compiler/Codegen/Common/EncodingUtils.h"
1617
#include "iree/compiler/Codegen/Common/PassUtils.h"
1718
#include "iree/compiler/Codegen/Dialect/Codegen/IR/IREECodegenAttrs.h"
1819
#include "iree/compiler/Codegen/Utils/Utils.h"
@@ -49,9 +50,6 @@ void addIREEComprehensiveBufferizePasses(
4950
/// Populate Encoding to Nop pass and canonicalizer pass to the pipeline.
5051
void addEncodingToNopPasses(FunctionLikeNest &passManager);
5152

52-
/// Populate Encoding to padding pass and canonicalizer pass to the pipeline.
53-
void addEncodingToPaddingPasses(FunctionLikeNest &passManager);
54-
5553
/// Links nested transform dialect tuning specs named sequences into a single
5654
/// entry point. Returns the new named sequence op (inserted into the `module`)
5755
/// that includes the nested tuning specs, or a null op when no nested named

compiler/src/iree/compiler/Codegen/Common/Passes.td

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -616,8 +616,18 @@ def MaterializeDeviceEncodingPass :
616616
InterfacePass<"iree-codegen-materialize-device-encoding", "mlir::FunctionOpInterface"> {
617617
let summary = "Materialize the encoding for tensor as specified by the backend.";
618618
let options = [
619-
Option<"testCLGPUTarget", "test-cl-gpu-target", "bool", /*default=*/"false",
620-
"Flag used for lit-testing GPU target only. Not for general usage">,
619+
Option<"testGPUEncodingResolver", "test-gpu-encoding-resolver", "::mlir::iree_compiler::detail::TestingResolverKind",
620+
/*default=*/"detail::TestingResolverKind::kNone",
621+
"Flag used for lit-testing GPU target only. Not for general usage",
622+
[{llvm::cl::values(
623+
clEnumValN(::mlir::iree_compiler::detail::TestingResolverKind::kGPUDataTiling, "gpu_data_tiling",
624+
"Use iree_gpu.gpu_encoding_resolver<>."),
625+
clEnumValN(::mlir::iree_compiler::detail::TestingResolverKind::kGPUPadding, "gpu_padding",
626+
"Use iree_gpu.gpu_padding_resolver<>."),
627+
clEnumValN(::mlir::iree_compiler::detail::TestingResolverKind::kNone, "none",
628+
"Ignore testing resolvers.")
629+
)}]>,
630+
621631
];
622632
}
623633

@@ -627,17 +637,6 @@ def MaterializeEncodingIntoNopPass :
627637
let summary = "Drop the encodings from tensor types with encodings.";
628638
}
629639

630-
def MaterializeEncodingIntoPaddingPass :
631-
InterfacePass<"iree-codegen-materialize-encoding-into-padding", "mlir::FunctionOpInterface"> {
632-
let summary = "Materialize `#iree_encoding.padding` attributes.";
633-
let description = [{
634-
Handles padding introduced by `padding` encoding layouts, which
635-
requires `iree_tensor_ext.dispatch.tensor.load`/`.store` to be adjusted to account for
636-
padding regions.
637-
Materializes any other encoding layouts into nop.
638-
}];
639-
}
640-
641640
def MaterializeTuningSpecsPass : Pass<"iree-codegen-materialize-tuning-specs", "ModuleOp"> {
642641
let summary =
643642
"Load tuning spec transform dialect libraries and encode them in the module";

compiler/src/iree/compiler/Codegen/Common/test/materialize_encoding_gfx1100.mlir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: iree-opt --pass-pipeline="builtin.module(func.func(iree-codegen-materialize-device-encoding{test-cl-gpu-target}))" \
1+
// RUN: iree-opt --pass-pipeline="builtin.module(func.func(iree-codegen-materialize-device-encoding{test-gpu-encoding-resolver=gpu_data_tiling}))" \
22
// RUN: --iree-gpu-test-target=gfx1100 \
33
// RUN: --split-input-file %s | FileCheck %s
44

compiler/src/iree/compiler/Codegen/Common/test/materialize_encoding_gfx908.mlir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: iree-opt --pass-pipeline="builtin.module(func.func(iree-codegen-materialize-device-encoding{test-cl-gpu-target}))" \
1+
// RUN: iree-opt --pass-pipeline="builtin.module(func.func(iree-codegen-materialize-device-encoding{test-gpu-encoding-resolver=gpu_data_tiling}))" \
22
// RUN: --iree-gpu-test-target=gfx908 \
33
// RUN: --split-input-file %s | FileCheck %s
44

compiler/src/iree/compiler/Codegen/Common/test/materialize_encoding_gfx90a.mlir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: iree-opt --pass-pipeline="builtin.module(func.func(iree-codegen-materialize-device-encoding{test-cl-gpu-target}))" \
1+
// RUN: iree-opt --pass-pipeline="builtin.module(func.func(iree-codegen-materialize-device-encoding{test-gpu-encoding-resolver=gpu_data_tiling}))" \
22
// RUN: --iree-gpu-test-target=gfx90a \
33
// RUN: --split-input-file %s | FileCheck %s
44

0 commit comments

Comments
 (0)