Skip to content

Commit c33d260

Browse files
authored
[Codegen][NFC] Make namespace usage follow IREE::[Encoding|Codegen]. (#20894)
In the core dialect, we prefer fully specify type name. This makes it easier to do large scale replacements, avoids conflicts with mlir upstream types, and makes it easier to port passes between dialects. The revision also removes the using-directives (e.g., using namespace foo), because we don't want to pollute the codebase. --------- Signed-off-by: hanhanW <[email protected]>
1 parent bd1a7ec commit c33d260

File tree

4 files changed

+32
-34
lines changed

4 files changed

+32
-34
lines changed

compiler/src/iree/compiler/Codegen/ExternalInterfaces/CPUEncodingExternalModels.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@
5353

5454
namespace mlir::iree_compiler::IREE::CPU {
5555

56-
using Codegen::MaterializeEncodingInfo;
57-
using Codegen::TileMxNxK;
56+
using IREE::Codegen::MaterializeEncodingInfo;
57+
using IREE::Codegen::TileMxNxK;
5858

5959
namespace {
6060

@@ -606,7 +606,7 @@ struct CPUDeviceEncodingPackedLayoutAttrInterface
606606
return info;
607607
}
608608
info = std::move(maybeEncodingInfo.value());
609-
if (Encoding::isNarrowNResult(encoding)) {
609+
if (IREE::Encoding::isNarrowNResult(encoding)) {
610610
transposeInPlace(info);
611611
}
612612
return info;
@@ -742,7 +742,7 @@ struct VMVXDeviceEncodingPackedLayoutAttrInterface final
742742
return info;
743743
}
744744
info = std::move(maybeEncodingInfo.value());
745-
if (Encoding::isNarrowNResult(encoding)) {
745+
if (IREE::Encoding::isNarrowNResult(encoding)) {
746746
transposeInPlace(info);
747747
}
748748
return info;

compiler/src/iree/compiler/Codegen/ExternalInterfaces/GPUEncodingExternalModels.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@
5252

5353
namespace mlir::iree_compiler::IREE::GPU {
5454

55-
using Codegen::MaterializeEncodingInfo;
56-
using Codegen::TileMxNxK;
55+
using IREE::Codegen::MaterializeEncodingInfo;
56+
using IREE::Codegen::TileMxNxK;
5757

5858
namespace {
5959

@@ -82,7 +82,7 @@ static MMAAttr chooseIntrinsicMMAAttr(TypeRange eTypes, TargetWgpAttr wgp) {
8282

8383
static DataTiledMMAAttr
8484
chooseDataTiledMMAAttr(TypeRange eTypes, TargetAttr target,
85-
Encoding::EncodingAttr encoding) {
85+
IREE::Encoding::EncodingAttr encoding) {
8686
if (!target) {
8787
return {};
8888
}
@@ -349,7 +349,7 @@ struct GPUDeviceEncodingPackedLayoutAttrInterface
349349
info = std::move(maybeEncodingInfo.value());
350350
auto fragment = static_cast<IREE::GPU::MMAFragment>(
351351
encoding.getOperandIndex().getInt());
352-
FailureOr<Codegen::TileSwizzle> maybeSwizzle =
352+
FailureOr<IREE::Codegen::TileSwizzle> maybeSwizzle =
353353
getEncodingSwizzle(encoding, mma, fragment);
354354
if (failed(maybeSwizzle)) {
355355
return info;
@@ -417,7 +417,7 @@ struct GPUHostEncodingLayoutResolverAttrInterface final
417417
};
418418

419419
struct GPUPadDeviceEncodingLayoutAttrInterface final
420-
: Encoding::LayoutAttrInterface::ExternalModel<
420+
: IREE::Encoding::LayoutAttrInterface::ExternalModel<
421421
GPUPadDeviceEncodingLayoutAttrInterface, GPUPadLayoutAttr> {
422422
Operation *lowerOp(Attribute attr, OpBuilder &b, Operation *op,
423423
TypeRange convertedResTypes,
@@ -427,7 +427,7 @@ struct GPUPadDeviceEncodingLayoutAttrInterface final
427427
};
428428

429429
struct GPUPadEncodingLayoutResolverAttrInterface final
430-
: Encoding::EncodingLayoutResolverAttrInterface::ExternalModel<
430+
: IREE::Encoding::EncodingLayoutResolverAttrInterface::ExternalModel<
431431
GPUPadEncodingLayoutResolverAttrInterface, GPUPadLayoutAttr> {
432432
Attribute cloneWithSimplifiedConfig(Attribute attr,
433433
DictionaryAttr config) const {
@@ -445,12 +445,12 @@ struct GPUPadEncodingLayoutResolverAttrInterface final
445445
MLIRContext *ctx = attr.getContext();
446446
auto padLayoutAttr = cast<GPUPadLayoutAttr>(attr);
447447
auto contractionEncodingAttr =
448-
dyn_cast_or_null<Encoding::ContractionEncodingAttrInterface>(
448+
dyn_cast_or_null<IREE::Encoding::ContractionEncodingAttrInterface>(
449449
type.getEncoding());
450450

451451
const int64_t rank = type.getRank();
452452
auto noPaddingAttr =
453-
Encoding::PadEncodingLayoutAttr::getIdentityAttr(ctx, rank);
453+
IREE::Encoding::PadEncodingLayoutAttr::getIdentityAttr(ctx, rank);
454454
if (!padLayoutAttr.getCacheLineBytes() || !padLayoutAttr.getCacheSets()) {
455455
return noPaddingAttr;
456456
}
@@ -540,7 +540,7 @@ struct GPUPadEncodingLayoutResolverAttrInterface final
540540
const int64_t numPadElements = (padBytes * 8) / elementBits;
541541
SmallVector<int64_t> padValues(rank, 0);
542542
padValues[padDimensionIndex] = numPadElements;
543-
auto padLayout = Encoding::PadEncodingLayoutAttr::get(ctx, padValues);
543+
auto padLayout = IREE::Encoding::PadEncodingLayoutAttr::get(ctx, padValues);
544544
return padLayout;
545545
}
546546
};

compiler/src/iree/compiler/Codegen/ExternalInterfaces/Utils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#include "mlir/IR/MLIRContext.h"
2020

2121
namespace mlir::iree_compiler::IREE {
22-
using Codegen::MaterializeEncodingInfo;
22+
using IREE::Codegen::MaterializeEncodingInfo;
2323

2424
Value calculatePackedStorageSizeInBytesImpl(Attribute attr, Location loc,
2525
OpBuilder &builder,

compiler/src/iree/compiler/Codegen/ExternalInterfaces/Utils.h

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@
2020

2121
namespace mlir::iree_compiler::IREE {
2222

23-
using IREE::Codegen::MaterializeEncodingInfo;
24-
using IREE::TensorExt::DispatchTensorType;
25-
2623
static const char kEncodingInfoAttrName[] = "encoding_info";
2724

2825
// This class is the base class for the external model of different packed
@@ -33,18 +30,18 @@ static const char kEncodingInfoAttrName[] = "encoding_info";
3330
template <typename DeviceEncodingPackedLayoutAttrInterface,
3431
typename EncodingLayoutAttr>
3532
struct DevicePackedLayoutAttrExternalModelBase
36-
: public Codegen::PackedLayoutAttrInterface::ExternalModel<
33+
: public IREE::Codegen::PackedLayoutAttrInterface::ExternalModel<
3734
DeviceEncodingPackedLayoutAttrInterface, EncodingLayoutAttr> {
3835
public:
39-
Codegen::MaterializeEncodingInfo
36+
IREE::Codegen::MaterializeEncodingInfo
4037
getEncodingInfo(Attribute attr, RankedTensorType type) const {
4138
const DeviceEncodingPackedLayoutAttrInterface *impl =
4239
static_cast<const DeviceEncodingPackedLayoutAttrInterface *>(this);
4340
// If the layout is already resolved, use it directly.
4441
if (auto config = impl->getConfiguration(attr)) {
4542
if (auto namedAttr = config.getNamed(kEncodingInfoAttrName)) {
46-
std::optional<Codegen::MaterializeEncodingInfo> info =
47-
Codegen::deserializeEncodingInfo(
43+
std::optional<IREE::Codegen::MaterializeEncodingInfo> info =
44+
IREE::Codegen::deserializeEncodingInfo(
4845
cast<DictionaryAttr>(namedAttr->getValue()));
4946
assert(info && "encoding_info is invalid");
5047
return info.value();
@@ -60,8 +57,8 @@ struct DeviceEncodingLayoutAttrInterfaceExternalModelBase
6057
: public IREE::Encoding::LayoutAttrInterface::ExternalModel<
6158
DeviceEncodingLayoutAttrInterface, EncodingLayoutAttr> {
6259
public:
63-
MaterializeEncodingInfo getEncodingInfo(EncodingLayoutAttr layoutAttr,
64-
RankedTensorType type) const {
60+
IREE::Codegen::MaterializeEncodingInfo
61+
getEncodingInfo(EncodingLayoutAttr layoutAttr, RankedTensorType type) const {
6562
return getEncodingInfoFromLayout(
6663
type, cast<IREE::Encoding::LayoutAttrInterface>(layoutAttr));
6764
}
@@ -73,7 +70,7 @@ struct DeviceEncodingLayoutAttrInterfaceExternalModelBase
7370
// For a given tensor type with an encoding, return the materialized
7471
// type to use for it. If no encoding is set, then return the tensor
7572
// type itself.
76-
MaterializeEncodingInfo encodingInfo =
73+
IREE::Codegen::MaterializeEncodingInfo encodingInfo =
7774
getEncodingInfo(layoutAttr, type);
7875
if (IREE::Codegen::isIdentityLayout(encodingInfo)) {
7976
return type.dropEncoding();
@@ -100,15 +97,16 @@ struct DeviceEncodingLayoutAttrInterfaceExternalModelBase
10097
newShape.append(swizzledTileShape);
10198
return RankedTensorType::get(newShape, packedType.getElementType());
10299
})
103-
.template Case<DispatchTensorType>([&](auto dispatchTensorType) {
104-
Type boundType = dispatchTensorType.getBoundType();
105-
Type convertedBoundType = convertType(attr, boundType);
106-
if (convertedBoundType == boundType) {
107-
return dispatchTensorType;
108-
}
109-
return DispatchTensorType::get(dispatchTensorType.getAccess(),
110-
convertedBoundType);
111-
})
100+
.template Case<IREE::TensorExt::DispatchTensorType>(
101+
[&](auto dispatchTensorType) {
102+
Type boundType = dispatchTensorType.getBoundType();
103+
Type convertedBoundType = convertType(attr, boundType);
104+
if (convertedBoundType == boundType) {
105+
return dispatchTensorType;
106+
}
107+
return IREE::TensorExt::DispatchTensorType::get(
108+
dispatchTensorType.getAccess(), convertedBoundType);
109+
})
112110
.Default([&](auto concreteType) { return concreteType; });
113111
}
114112

@@ -127,7 +125,7 @@ struct DeviceEncodingLayoutAttrInterfaceExternalModelBase
127125
return failure();
128126
}
129127
auto boundTensorType = cast<RankedTensorType>(type.getBoundType());
130-
MaterializeEncodingInfo encodingInfo =
128+
IREE::Codegen::MaterializeEncodingInfo encodingInfo =
131129
getEncodingInfoFromLayout(boundTensorType, layoutAttr);
132130
newSizes = getMixedValues(boundTensorType.getShape(), dynamicDims, builder);
133131
FailureOr<SmallVector<OpFoldResult>> convertedMixedSizes =

0 commit comments

Comments
 (0)