Skip to content

Commit 344c5e0

Browse files
committed
Addressing review comments
Mainly as follows: - removing custom attribute parser/printer - renaming SystemDescSpec to SystemSpec and TargetDeviceDescSpec to TargetDeviceSpec - using DeviceID as a type insted of uint32_t - grammatical errors
1 parent 1c7be2f commit 344c5e0

File tree

14 files changed

+289
-388
lines changed

14 files changed

+289
-388
lines changed

mlir/include/mlir/Dialect/DLTI/DLTIAttrs.td

Lines changed: 52 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def DataLayoutEntryTrait
2828
def DLTI_DataLayoutEntryAttr :
2929
DLTIAttr<"DataLayoutEntry", [DataLayoutEntryTrait]> {
3030
let summary = [{
31-
An attribute to represent an entry of a data layout specification
31+
An attribute to represent an entry of a data layout specification.
3232
}];
3333
let description = [{
3434
A data layout entry attribute is a key-value pair where the key is a type or
@@ -38,7 +38,7 @@ def DLTI_DataLayoutEntryAttr :
3838
let parameters = (ins
3939
"DataLayoutEntryKey":$key, "Attribute":$value
4040
);
41-
// We do not generate storage class because llvm::PointerUnion
41+
// TODO: We do not generate storage class because llvm::PointerUnion
4242
// does not work with hash_key method.
4343
let genStorageClass = 0;
4444
let mnemonic = "dl_entry";
@@ -62,7 +62,9 @@ def DataLayoutSpecTrait
6262

6363
def DLTI_DataLayoutSpecAttr :
6464
DLTIAttr<"DataLayoutSpec", [DataLayoutSpecTrait]> {
65-
let summary = [{An attribute to represent a data layout specification}];
65+
let summary = [{
66+
An attribute to represent a data layout specification.
67+
}];
6668
let description = [{
6769
A data layout specification is a list of entries that specify (partial) data
6870
layout information. It is expected to be attached to operations that serve
@@ -96,84 +98,57 @@ def DLTI_DataLayoutSpecAttr :
9698
/// Returns the stack alignment identifier.
9799
StringAttr getStackAlignmentIdentifier(MLIRContext *context) const;
98100
}];
99-
let extraClassDefinition = [{
100-
StringAttr
101-
$cppClass::getEndiannessIdentifier(MLIRContext *context) const {
102-
return Builder(context).getStringAttr(DLTIDialect::kDataLayoutEndiannessKey);
103-
}
104-
105-
StringAttr
106-
$cppClass::getAllocaMemorySpaceIdentifier(MLIRContext *context) const {
107-
return Builder(context).getStringAttr(
108-
DLTIDialect::kDataLayoutAllocaMemorySpaceKey);
109-
}
110-
111-
StringAttr $cppClass::getProgramMemorySpaceIdentifier(
112-
MLIRContext *context) const {
113-
return Builder(context).getStringAttr(
114-
DLTIDialect::kDataLayoutProgramMemorySpaceKey);
115-
}
116-
117-
StringAttr
118-
$cppClass::getGlobalMemorySpaceIdentifier(MLIRContext *context) const {
119-
return Builder(context).getStringAttr(
120-
DLTIDialect::kDataLayoutGlobalMemorySpaceKey);
121-
}
122-
123-
StringAttr
124-
$cppClass::getStackAlignmentIdentifier(MLIRContext *context) const {
125-
return Builder(context).getStringAttr(
126-
DLTIDialect::kDataLayoutStackAlignmentKey);
127-
}
128-
}];
129101
}
130102

131103
//===----------------------------------------------------------------------===//
132-
// TargetSystemDescSpecAttr
104+
// TargetSystemSpecAttr
133105
//===----------------------------------------------------------------------===//
134106

135-
def TargetSystemDescSpecTrait
136-
: NativeAttrTrait<"TargetSystemDescSpecInterface::Trait"> {
107+
def TargetSystemSpecTrait
108+
: NativeAttrTrait<"TargetSystemSpecInterface::Trait"> {
137109
let cppNamespace = "::mlir";
138110
}
139111

140-
def DLTI_TargetSystemDescSpecAttr :
141-
DLTIAttr<"TargetSystemDescSpec", [TargetSystemDescSpecTrait]> {
142-
let summary = [{An attribute to represent target system description}];
112+
def DLTI_TargetSystemSpecAttr :
113+
DLTIAttr<"TargetSystemSpec", [TargetSystemSpecTrait]> {
114+
let summary = [{
115+
An attribute to represent target system specification.
116+
}];
143117
let description = [{
144-
A system description specification describes the overall system
145-
containing multiple devices, with each device having a unique ID
146-
and its corresponding TargetDeviceDescSpec object.
118+
A system specification describes the overall system containing
119+
multiple devices, with each device having a unique ID
120+
and its corresponding TargetDeviceSpec object.
147121

148122
Example:
149-
dlti.target_system_desc_spec =
150-
#dlti.target_device_desc_spec<
123+
dlti.target_system_spec =
124+
#dlti.target_device_spec<
151125
#dlti.dl_entry<"dlti.device_id", 0: ui32>,
152126
#dlti.dl_entry<"dlti.device_type", "CPU">>,
153-
#dlti.target_device_desc_spec <
127+
#dlti.target_device_spec<
154128
#dlti.dl_entry<"dlti.device_id", 1: ui32>,
155129
#dlti.dl_entry<"dlti.device_type", "GPU">,
156130
#dlti.dl_entry<"dlti.max_vector_op_width", 64 : ui32>>,
157-
#dlti.target_device_desc_spec <
131+
#dlti.target_device_spec<
158132
#dlti.dl_entry<"dlti.device_id", 2: ui32>,
159133
#dlti.dl_entry<"dlti.device_type", "XPU">>>
160134
}];
161135
let parameters = (ins
162-
ArrayRefParameter<"TargetDeviceDescSpecInterface", "">:$entries
136+
ArrayRefParameter<"TargetDeviceSpecInterface", "">:$entries
163137
);
164-
let mnemonic = "target_system_desc_spec";
138+
let mnemonic = "target_system_spec";
165139
let genVerifyDecl = 1;
166-
let hasCustomAssemblyFormat = 1;
140+
let assemblyFormat = "`<` $entries `>`";
167141
let extraClassDeclaration = [{
168-
/// Return the device descriptor that matches the given device ID
169-
std::optional<TargetDeviceDescSpecInterface>
170-
getDeviceDescForDeviceID(uint32_t deviceID);
142+
/// Return the device specification that matches the given device ID
143+
std::optional<TargetDeviceSpecInterface>
144+
getDeviceSpecForDeviceID(
145+
TargetDeviceSpecInterface::DeviceID deviceID);
171146
}];
172147
let extraClassDefinition = [{
173-
std::optional<TargetDeviceDescSpecInterface>
174-
$cppClass::getDeviceDescForDeviceID(
175-
TargetDeviceDescSpecInterface::DeviceID deviceID) {
176-
for (TargetDeviceDescSpecInterface entry : getEntries()) {
148+
std::optional<TargetDeviceSpecInterface>
149+
$cppClass::getDeviceSpecForDeviceID(
150+
TargetDeviceSpecInterface::DeviceID deviceID) {
151+
for (TargetDeviceSpecInterface entry : getEntries()) {
177152
if (entry.getDeviceID() == deviceID)
178153
return entry;
179154
}
@@ -183,35 +158,37 @@ def DLTI_TargetSystemDescSpecAttr :
183158
}
184159

185160
//===----------------------------------------------------------------------===//
186-
// TargetDeviceDescSpecAttr
161+
// TargetDeviceSpecAttr
187162
//===----------------------------------------------------------------------===//
188163

189-
def TargetDeviceDescSpecTrait
190-
: NativeAttrTrait<"TargetDeviceDescSpecInterface::Trait"> {
164+
def TargetDeviceSpecTrait
165+
: NativeAttrTrait<"TargetDeviceSpecInterface::Trait"> {
191166
let cppNamespace = "::mlir";
192167
}
193168

194-
def DLTI_TargetDeviceDescSpecAttr :
195-
DLTIAttr<"TargetDeviceDescSpec", [TargetDeviceDescSpecTrait]> {
196-
let summary = [{An attribute to represent target device description}];
169+
def DLTI_TargetDeviceSpecAttr :
170+
DLTIAttr<"TargetDeviceSpec", [TargetDeviceSpecTrait]> {
171+
let summary = [{
172+
An attribute to represent target device specification.
173+
}];
197174
let description = [{
198-
Each device description specification describes a single device and
199-
its hardware properties. Each device description must have a device_id
200-
and a device_type. In addition, the description can contain any number
201-
of optional hardware properties (e.g., max_vector_op_width below).
175+
Each device specification describes a single device and its
176+
hardware properties. Each device specification must have a device_id
177+
and a device_type. In addition, the specification can contain any number
178+
of optional hardware properties (e.g., max_vector_op_width below).
202179

203-
Example:
204-
#dlti.target_device_desc_spec <
205-
#dlti.dl_entry<"dlti.device_id", 1: ui32>,
206-
#dlti.dl_entry<"dlti.device_type", "GPU">,
207-
#dlti.dl_entry<"dlti.max_vector_op_width", 64 : ui32>>
208-
}];
180+
Example:
181+
#dlti.target_device_spec<
182+
#dlti.dl_entry<"dlti.device_id", 1: ui32>,
183+
#dlti.dl_entry<"dlti.device_type", "GPU">,
184+
#dlti.dl_entry<"dlti.max_vector_op_width", 64 : ui32>>
185+
}];
209186
let parameters = (ins
210187
ArrayRefParameter<"DataLayoutEntryInterface", "">:$entries
211188
);
212-
let mnemonic = "target_device_desc_spec";
189+
let mnemonic = "target_device_spec";
213190
let genVerifyDecl = 1;
214-
let hasCustomAssemblyFormat = 1;
191+
let assemblyFormat = "`<` $entries `>`";
215192
let extraClassDeclaration = [{
216193
/// Returns the device ID identifier.
217194
StringAttr getDeviceIDIdentifier();
@@ -248,55 +225,7 @@ def DLTI_TargetDeviceDescSpecAttr :
248225
DataLayoutEntryInterface getSpecForL1CacheSizeInBytes();
249226

250227
/// Return the value of device ID
251-
uint32_t getDeviceID();
252-
}];
253-
254-
let extraClassDefinition = [{
255-
StringAttr
256-
$cppClass::getDeviceIDIdentifier() {
257-
return Builder(getContext()).getStringAttr(DLTIDialect::kTargetDeviceIDKey);
258-
}
259-
260-
StringAttr
261-
$cppClass::getDeviceTypeIdentifier() {
262-
return Builder(getContext()).getStringAttr(DLTIDialect::kTargetDeviceTypeKey);
263-
}
264-
265-
StringAttr
266-
$cppClass::getMaxVectorOpWidthIdentifier() {
267-
return Builder(getContext()).getStringAttr(
268-
DLTIDialect::kTargetDeviceMaxVectorOpWidthKey);
269-
}
270-
271-
StringAttr $cppClass::getL1CacheSizeInBytesIdentifier() {
272-
return Builder(getContext()).getStringAttr(
273-
DLTIDialect::kTargetDeviceL1CacheSizeInBytesKey);
274-
}
275-
276-
DataLayoutEntryInterface
277-
$cppClass::getSpecForDeviceID() {
278-
return getSpecForIdentifier(getDeviceIDIdentifier());
279-
}
280-
281-
DataLayoutEntryInterface
282-
$cppClass::getSpecForDeviceType() {
283-
return getSpecForIdentifier(getDeviceTypeIdentifier());
284-
}
285-
286-
DataLayoutEntryInterface
287-
$cppClass::getSpecForMaxVectorOpWidth() {
288-
return getSpecForIdentifier(getMaxVectorOpWidthIdentifier());
289-
}
290-
291-
DataLayoutEntryInterface
292-
$cppClass::getSpecForL1CacheSizeInBytes() {
293-
return getSpecForIdentifier(getL1CacheSizeInBytesIdentifier());
294-
}
295-
296-
uint32_t $cppClass::getDeviceID() {
297-
DataLayoutEntryInterface entry = getSpecForDeviceID();
298-
return llvm::cast<IntegerAttr>(entry.getValue()).getValue().getZExtValue();
299-
}
228+
TargetDeviceSpecInterface::DeviceID getDeviceID();
300229
}];
301230
}
302231

mlir/include/mlir/Dialect/DLTI/DLTIBase.td

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ def DLTI_Dialect : Dialect {
2929

3030
// Top level attribute name for target system description
3131
constexpr const static ::llvm::StringLiteral
32-
kTargetSystemDescAttrName = "dlti.target_system_desc_spec";
32+
kTargetSystemDescAttrName = "dlti.target_system_spec";
3333

3434
constexpr const static ::llvm::StringLiteral
35-
kTargetDeviceDescAttrName = "dlti.target_device_desc_spec";
35+
kTargetDeviceDescAttrName = "dlti.target_device_spec";
3636

3737
// Constants used in entries.
3838
constexpr const static ::llvm::StringLiteral
@@ -56,7 +56,7 @@ def DLTI_Dialect : Dialect {
5656
constexpr const static ::llvm::StringLiteral
5757
kDataLayoutStackAlignmentKey = "dlti.stack_alignment";
5858

59-
// Constants used in target description part of DLTI
59+
// Constants used in target description part of DLTI.
6060
constexpr const static ::llvm::StringLiteral
6161
kTargetDeviceIDKey = "dlti.device_id";
6262

mlir/include/mlir/Dialect/DLTI/Traits.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class DataLayoutSpecAttr;
1818
namespace impl {
1919
LogicalResult verifyHasDefaultDLTIDataLayoutTrait(Operation *op);
2020
DataLayoutSpecInterface getDataLayoutSpec(Operation *op);
21-
TargetSystemDescSpecInterface getTargetSystemDescSpec(Operation *op);
21+
TargetSystemSpecInterface getTargetSystemSpec(Operation *op);
2222
} // namespace impl
2323

2424
/// Trait to be used by operations willing to use the implementation of the
@@ -41,8 +41,8 @@ class HasDefaultDLTIDataLayout
4141

4242
/// Returns the target system description specification as provided by DLTI
4343
/// dialect
44-
TargetSystemDescSpecInterface getTargetSystemDescSpec() {
45-
return impl::getTargetSystemDescSpec(this->getOperation());
44+
TargetSystemSpecInterface getTargetSystemSpec() {
45+
return impl::getTargetSystemSpec(this->getOperation());
4646
}
4747
};
4848
} // namespace mlir

mlir/include/mlir/IR/BuiltinOps.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def ModuleOp : Builtin_Op<"module", [
7878
//===------------------------------------------------------------------===//
7979

8080
DataLayoutSpecInterface getDataLayoutSpec();
81-
TargetSystemDescSpecInterface getTargetSystemDescSpec();
81+
TargetSystemSpecInterface getTargetSystemSpec();
8282

8383
//===------------------------------------------------------------------===//
8484
// OpAsmOpInterface Methods

mlir/include/mlir/Interfaces/DataLayoutInterfaces.h

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,14 @@
2323
namespace mlir {
2424
class DataLayout;
2525
class DataLayoutEntryInterface;
26-
class TargetDeviceDescSpecInterface;
27-
class TargetSystemDescSpecInterface;
26+
class TargetDeviceSpecInterface;
27+
class TargetSystemSpecInterface;
2828
using DataLayoutEntryKey = llvm::PointerUnion<Type, StringAttr>;
2929
// Using explicit SmallVector size because we cannot infer the size from the
3030
// forward declaration, and we need the typedef in the actual declaration.
3131
using DataLayoutEntryList = llvm::SmallVector<DataLayoutEntryInterface, 4>;
3232
using DataLayoutEntryListRef = llvm::ArrayRef<DataLayoutEntryInterface>;
33-
using TargetDeviceDescSpecListRef =
34-
llvm::ArrayRef<TargetDeviceDescSpecInterface>;
33+
using TargetDeviceSpecListRef = llvm::ArrayRef<TargetDeviceSpecInterface>;
3534
class DataLayoutOpInterface;
3635
class DataLayoutSpecInterface;
3736
class ModuleOp;
@@ -109,8 +108,8 @@ filterEntryForIdentifier(DataLayoutEntryListRef entries, StringAttr id);
109108

110109
/// Given a list of target device entries, returns the entry that has the given
111110
/// identifier as key, if such an entry exists in the list.
112-
TargetDeviceDescSpecInterface
113-
filterEntryForIdentifier(TargetDeviceDescSpecListRef entries, StringAttr id);
111+
TargetDeviceSpecInterface
112+
filterEntryForIdentifier(TargetDeviceSpecListRef entries, StringAttr id);
114113

115114
/// Verifies that the operation implementing the data layout interface, or a
116115
/// module operation, is valid. This calls the verifier of the spec attribute
@@ -126,8 +125,8 @@ LogicalResult verifyDataLayoutSpec(DataLayoutSpecInterface spec, Location loc);
126125
/// Verifies that a target system desc spec is valid. This dispatches to
127126
/// individual entry verifiers, and then to the verifiers implemented by the
128127
/// relevant dialect interfaces for identifier keys.
129-
LogicalResult verifyTargetSystemDescSpec(TargetSystemDescSpecInterface spec,
130-
Location loc);
128+
LogicalResult verifyTargetSystemSpec(TargetSystemSpecInterface spec,
129+
Location loc);
131130

132131
/// Divides the known min value of the numerator by the denominator and rounds
133132
/// the result up to the next integer. Preserves the scalable flag.
@@ -162,7 +161,7 @@ class DataLayoutDialectInterface
162161

163162
/// Checks whether the given data layout entry is valid and reports any errors
164163
/// at the provided location. Derived classes should override this.
165-
virtual LogicalResult verifyEntry(TargetDeviceDescSpecInterface entry,
164+
virtual LogicalResult verifyEntry(TargetDeviceSpecInterface entry,
166165
Location loc) const {
167166
return success();
168167
}
@@ -247,19 +246,19 @@ class DataLayout {
247246
/// Returns for max vector op width if the property is defined for the given
248247
/// device ID, otherwise return std::nullopt.
249248
std::optional<uint32_t>
250-
getMaxVectorOpWidth(TargetDeviceDescSpecInterface::DeviceID) const;
249+
getMaxVectorOpWidth(TargetDeviceSpecInterface::DeviceID) const;
251250

252251
/// Returns for L1 cache size if the property is defined for the given
253252
/// device ID, otherwise return std::nullopt.
254253
std::optional<uint32_t>
255-
getL1CacheSizeInBytes(TargetDeviceDescSpecInterface::DeviceID) const;
254+
getL1CacheSizeInBytes(TargetDeviceSpecInterface::DeviceID) const;
256255

257256
private:
258257
/// Combined layout spec at the given scope.
259258
const DataLayoutSpecInterface originalLayout;
260259

261260
/// Combined target system desc spec at the given scope.
262-
const TargetSystemDescSpecInterface originalTargetSystemDesc;
261+
const TargetSystemSpecInterface originalTargetSystemDesc;
263262

264263
#if LLVM_ENABLE_ABI_BREAKING_CHECKS
265264
/// List of enclosing layout specs.

0 commit comments

Comments
 (0)