Skip to content

Commit 48a46e4

Browse files
committed
Missed style check
1 parent 2c2eb29 commit 48a46e4

File tree

4 files changed

+69
-53
lines changed

4 files changed

+69
-53
lines changed

mlir/include/mlir/IR/MLIRContext.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ class MLIRContext {
245245
SystemDesc &getSystemDesc();
246246

247247
/// Set context-specific system descriptor
248-
void setSystemDesc(const SystemDesc& desc);
248+
void setSystemDesc(const SystemDesc &desc);
249249

250250
//===--------------------------------------------------------------------===//
251251
// Action API

mlir/include/mlir/Support/SystemDesc.h

Lines changed: 52 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ class DeviceDesc {
8888
}
8989

9090
/// Set property
91-
DeviceDesc &setProperty(MLIRContext *context, llvm::StringRef name, int64_t iv) {
91+
DeviceDesc &setProperty(MLIRContext *context, llvm::StringRef name,
92+
int64_t iv) {
9293
std::optional<NamedAttribute> attr = deviceProperties.getNamed(name);
9394
if (!attr.has_value()) {
9495
IntegerType int64Ty = IntegerType::get(context, 64);
@@ -99,7 +100,8 @@ class DeviceDesc {
99100
return *this;
100101
}
101102

102-
DeviceDesc &setProperty(MLIRContext *context, llvm::StringRef name, double dv) {
103+
DeviceDesc &setProperty(MLIRContext *context, llvm::StringRef name,
104+
double dv) {
103105
std::optional<NamedAttribute> attr = deviceProperties.getNamed(name);
104106
if (!attr.has_value()) {
105107
FloatType floatType = FloatType::getF64(context);
@@ -115,8 +117,10 @@ class DeviceDesc {
115117
std::optional<NamedAttribute> attr = deviceProperties.getNamed(name);
116118
if (!attr.has_value()) {
117119
IntegerType int64Ty = IntegerType::get(context, 64);
118-
RankedTensorType shape = RankedTensorType::get({static_cast<long>(ivv.size()), 1}, int64Ty);
119-
DenseElementsAttr value = DenseElementsAttr::get(shape, llvm::ArrayRef(ivv));
120+
RankedTensorType shape =
121+
RankedTensorType::get({static_cast<long>(ivv.size()), 1}, int64Ty);
122+
DenseElementsAttr value =
123+
DenseElementsAttr::get(shape, llvm::ArrayRef(ivv));
120124
deviceProperties.append(name, value);
121125
} else
122126
llvm::report_fatal_error("Duplicate device property name found:" + name);
@@ -128,16 +132,19 @@ class DeviceDesc {
128132
std::optional<NamedAttribute> attr = deviceProperties.getNamed(name);
129133
if (!attr.has_value()) {
130134
FloatType float64Ty = FloatType::getF64(context);
131-
RankedTensorType shape = RankedTensorType::get({static_cast<long>(idv.size()), 1}, float64Ty);
132-
DenseElementsAttr value = DenseElementsAttr::get(shape, llvm::ArrayRef(idv));
135+
RankedTensorType shape =
136+
RankedTensorType::get({static_cast<long>(idv.size()), 1}, float64Ty);
137+
DenseElementsAttr value =
138+
DenseElementsAttr::get(shape, llvm::ArrayRef(idv));
133139
deviceProperties.append(name, value);
134140
} else
135141
llvm::report_fatal_error("Duplicate device property name found:" + name);
136142
return *this;
137143
}
138144

139145
// We provide convenience interface to handle int/float value as string
140-
DeviceDesc &setProperty(MLIRContext *context, llvm::StringRef name, const std::string &json_value) {
146+
DeviceDesc &setProperty(MLIRContext *context, llvm::StringRef name,
147+
const std::string &json_value) {
141148
if (json_value.length() > 0 && json_value[0] == '[') {
142149
// Parse as an array
143150
llvm::Expected<std::vector<int64_t>> ivv =
@@ -245,7 +252,8 @@ class DeviceDesc {
245252
}
246253
void setL1CacheSizeInBytes(MLIRContext *context, int64_t value) {
247254
// Temporarily use int override until we support size_t
248-
this->setProperty(context, DeviceDesc::getCPUL1CacheSizeInBytesKeyName(), value);
255+
this->setProperty(context, DeviceDesc::getCPUL1CacheSizeInBytesKeyName(),
256+
value);
249257
}
250258
std::optional<int64_t> getConvAndMatMulBlockingFactor() const {
251259
if (std::optional<int64_t> v = this->getPropertyValueAsInt(
@@ -256,8 +264,8 @@ class DeviceDesc {
256264
}
257265
void setConvAndMatMulBlockingFactor(MLIRContext *context, int64_t value) {
258266
// Temporarily use int override until we support size_t
259-
this->setProperty(context, DeviceDesc::getConvAndMatMulBlockingFactorKeyName(),
260-
value);
267+
this->setProperty(
268+
context, DeviceDesc::getConvAndMatMulBlockingFactorKeyName(), value);
261269
}
262270
std::optional<int64_t> getMatMulTileSizeInBytes() const {
263271
if (std::optional<int64_t> v = this->getPropertyValueAsInt(
@@ -268,7 +276,8 @@ class DeviceDesc {
268276
}
269277
void setMatMulTileSizeInBytes(MLIRContext *context, int64_t value) {
270278
// Temporarily use int override until we support size_t
271-
this->setProperty(context, DeviceDesc::getMatMulTileSizeInBytesKeyName(), value);
279+
this->setProperty(context, DeviceDesc::getMatMulTileSizeInBytesKeyName(),
280+
value);
272281
}
273282
std::optional<int64_t> getCanonicalizerMaxNumRewrites() const {
274283
if (std::optional<int64_t> v = this->getPropertyValueAsInt(
@@ -278,8 +287,8 @@ class DeviceDesc {
278287
return std::nullopt;
279288
}
280289
void setCanonicalizerMaxNumRewrites(MLIRContext *context, int64_t value) {
281-
this->setProperty(context, DeviceDesc::getCanonicalizerMaxNumRewritesKeyName(),
282-
value);
290+
this->setProperty(
291+
context, DeviceDesc::getCanonicalizerMaxNumRewritesKeyName(), value);
283292
}
284293
std::optional<int64_t> getCanonicalizerMaxIterations() const {
285294
if (std::optional<int64_t> v = this->getPropertyValueAsInt(
@@ -289,8 +298,8 @@ class DeviceDesc {
289298
return std::nullopt;
290299
}
291300
void setCanonicalizerMaxIterations(MLIRContext *context, int64_t value) {
292-
this->setProperty(context, DeviceDesc::getCanonicalizerMaxIterationsKeyName(),
293-
value);
301+
this->setProperty(
302+
context, DeviceDesc::getCanonicalizerMaxIterationsKeyName(), value);
294303
}
295304
std::optional<int64_t> getMaxVectorWidth() const {
296305
if (std::optional<int64_t> v = this->getPropertyValueAsInt(
@@ -321,12 +330,8 @@ class DeviceDesc {
321330
class SystemDesc {
322331
public:
323332
SystemDesc() = default;
324-
SystemDesc(const SystemDesc &desc) {
325-
this->deviceDescs = desc.deviceDescs;
326-
}
327-
void operator=(const SystemDesc &rhs) {
328-
this->deviceDescs = rhs.deviceDescs;
329-
}
333+
SystemDesc(const SystemDesc &desc) { this->deviceDescs = desc.deviceDescs; }
334+
void operator=(const SystemDesc &rhs) { this->deviceDescs = rhs.deviceDescs; }
330335

331336
/// Insert a new device description
332337
SystemDesc &addDeviceDesc(const DeviceDesc &desc) {
@@ -475,34 +480,37 @@ class DefaultGPUDeviceDesc : public DefaultBaseDeviceDesc {
475480
// Config file readers
476481
// ---------------------------------------------------------------------------
477482
namespace impl {
478-
class SystemDescJSONConfigParser {
479-
public:
480-
/// Build SystemDesc by parsing input config file in JSON format.
481-
/// Returns a valid SystemDesc if parsing is successful; otherwise
482-
/// returns std::nullopt.
483-
static std::optional<SystemDesc> buildSystemDescFromConfigFile(
484-
MLIRContext *context, llvm::StringRef filename);
485-
486-
private:
487-
/// We represent DeviceDesc in JSON as a key-value pairs of strings.
488-
using DeviceDescJSONTy = std::map<std::string, std::string>;
489-
490-
/// A utility function to parse device description entry in JSON format
491-
/// Returns valid DeviceDesc if parsing is successful; otherwise returns
492-
/// std::nullopt.
493-
static std::optional<DeviceDesc> buildDeviceDescFromConfigFile(MLIRContext *context,
494-
const DeviceDescJSONTy &device_desc_in_json);
495-
};
496-
}
483+
class SystemDescJSONConfigParser {
484+
public:
485+
/// Build SystemDesc by parsing input config file in JSON format.
486+
/// Returns a valid SystemDesc if parsing is successful; otherwise
487+
/// returns std::nullopt.
488+
static std::optional<SystemDesc>
489+
buildSystemDescFromConfigFile(MLIRContext *context, llvm::StringRef filename);
490+
491+
private:
492+
/// We represent DeviceDesc in JSON as a key-value pairs of strings.
493+
using DeviceDescJSONTy = std::map<std::string, std::string>;
494+
495+
/// A utility function to parse device description entry in JSON format
496+
/// Returns valid DeviceDesc if parsing is successful; otherwise returns
497+
/// std::nullopt.
498+
static std::optional<DeviceDesc>
499+
buildDeviceDescFromConfigFile(MLIRContext *context,
500+
const DeviceDescJSONTy &device_desc_in_json);
501+
};
502+
} // namespace impl
497503

498504
class SystemDescConfigFileParser {
499505
public:
500506
/// Build SystemDesc by parsing input config file. Returns valid SystemDesc
501507
/// if parsing is successful; otherwise returns std::nullopt.
502-
static std::optional<SystemDesc> buildSystemDescFromConfigFile(
503-
MLIRContext *context, llvm::StringRef filename) {
504-
// Once we support more formats, we can accept format as the input argument.
505-
return impl::SystemDescJSONConfigParser::buildSystemDescFromConfigFile(context, filename);
508+
static std::optional<SystemDesc>
509+
buildSystemDescFromConfigFile(MLIRContext *context,
510+
llvm::StringRef filename) {
511+
// Once we support more formats, we can accept format as the input argument.
512+
return impl::SystemDescJSONConfigParser::buildSystemDescFromConfigFile(
513+
context, filename);
506514
}
507515
};
508516

mlir/lib/IR/MLIRContext.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,9 @@ bool MLIRContext::isOperationRegistered(StringRef name) {
709709

710710
SystemDesc &MLIRContext::getSystemDesc() { return impl->system_desc; }
711711

712-
void MLIRContext::setSystemDesc(const SystemDesc& desc) { impl->system_desc = desc; }
712+
void MLIRContext::setSystemDesc(const SystemDesc &desc) {
713+
impl->system_desc = desc;
714+
}
713715

714716
void Dialect::addType(TypeID typeID, AbstractType &&typeInfo) {
715717
auto &impl = context->getImpl();

mlir/lib/Support/SystemDesc.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,22 @@
2020
using namespace llvm;
2121
using namespace mlir;
2222

23-
std::optional<DeviceDesc> impl::SystemDescJSONConfigParser::buildDeviceDescFromConfigFile(
23+
std::optional<DeviceDesc>
24+
impl::SystemDescJSONConfigParser::buildDeviceDescFromConfigFile(
2425
MLIRContext *context, const DeviceDescJSONTy &device_desc_in_json) {
2526
// ID and Type are mandatory fields.
2627
auto iter = device_desc_in_json.find("ID");
2728
if (iter == device_desc_in_json.end()) {
28-
llvm::errs() << "\"ID\" key missing in Device Description" << "\n";
29+
llvm::errs() << "\"ID\" key missing in Device Description"
30+
<< "\n";
2931
return std::nullopt;
3032
}
3133
DeviceDesc::DeviceID id = DeviceDesc::strToDeviceID(iter->second);
3234

3335
iter = device_desc_in_json.find("Type");
3436
if (iter == device_desc_in_json.end()) {
35-
llvm::errs() << "\"Type\" key missing in Device Description" << "\n";
37+
llvm::errs() << "\"Type\" key missing in Device Description"
38+
<< "\n";
3639
return std::nullopt;
3740
}
3841
DeviceDesc::DeviceType type = DeviceDesc::strToDeviceType(iter->second);
@@ -51,7 +54,8 @@ std::optional<DeviceDesc> impl::SystemDescJSONConfigParser::buildDeviceDescFromC
5154
return std::optional<DeviceDesc>(device_desc);
5255
}
5356

54-
std::optional<SystemDesc> impl::SystemDescJSONConfigParser::buildSystemDescFromConfigFile(
57+
std::optional<SystemDesc>
58+
impl::SystemDescJSONConfigParser::buildSystemDescFromConfigFile(
5559
MLIRContext *context, llvm::StringRef filename) {
5660
std::string errorMessage;
5761
std::unique_ptr<llvm::MemoryBuffer> file =
@@ -73,14 +77,16 @@ std::optional<SystemDesc> impl::SystemDescJSONConfigParser::buildSystemDescFromC
7377
using SystemDescJSONTy = std::vector<DeviceDescJSONTy>;
7478
SystemDescJSONTy system_desc_in_json;
7579
if (!json::fromJSON(*parsed, system_desc_in_json, NullRoot)) {
76-
llvm::errs() << "Invalid System Description in JSON" << "\n";
80+
llvm::errs() << "Invalid System Description in JSON"
81+
<< "\n";
7782
return std::nullopt;
7883
}
7984

8085
SystemDesc system_desc;
8186
for (auto device_desc_in_json : system_desc_in_json) {
82-
std::optional<DeviceDesc> device_desc = impl::SystemDescJSONConfigParser::buildDeviceDescFromConfigFile(
83-
context, device_desc_in_json);
87+
std::optional<DeviceDesc> device_desc =
88+
impl::SystemDescJSONConfigParser::buildDeviceDescFromConfigFile(
89+
context, device_desc_in_json);
8490
if (device_desc)
8591
system_desc.addDeviceDesc(*device_desc);
8692
else

0 commit comments

Comments
 (0)