@@ -88,7 +88,8 @@ class DeviceDesc {
88
88
}
89
89
90
90
// / 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) {
92
93
std::optional<NamedAttribute> attr = deviceProperties.getNamed (name);
93
94
if (!attr.has_value ()) {
94
95
IntegerType int64Ty = IntegerType::get (context, 64 );
@@ -99,7 +100,8 @@ class DeviceDesc {
99
100
return *this ;
100
101
}
101
102
102
- DeviceDesc &setProperty (MLIRContext *context, llvm::StringRef name, double dv) {
103
+ DeviceDesc &setProperty (MLIRContext *context, llvm::StringRef name,
104
+ double dv) {
103
105
std::optional<NamedAttribute> attr = deviceProperties.getNamed (name);
104
106
if (!attr.has_value ()) {
105
107
FloatType floatType = FloatType::getF64 (context);
@@ -115,8 +117,10 @@ class DeviceDesc {
115
117
std::optional<NamedAttribute> attr = deviceProperties.getNamed (name);
116
118
if (!attr.has_value ()) {
117
119
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));
120
124
deviceProperties.append (name, value);
121
125
} else
122
126
llvm::report_fatal_error (" Duplicate device property name found:" + name);
@@ -128,16 +132,19 @@ class DeviceDesc {
128
132
std::optional<NamedAttribute> attr = deviceProperties.getNamed (name);
129
133
if (!attr.has_value ()) {
130
134
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));
133
139
deviceProperties.append (name, value);
134
140
} else
135
141
llvm::report_fatal_error (" Duplicate device property name found:" + name);
136
142
return *this ;
137
143
}
138
144
139
145
// 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) {
141
148
if (json_value.length () > 0 && json_value[0 ] == ' [' ) {
142
149
// Parse as an array
143
150
llvm::Expected<std::vector<int64_t >> ivv =
@@ -245,7 +252,8 @@ class DeviceDesc {
245
252
}
246
253
void setL1CacheSizeInBytes (MLIRContext *context, int64_t value) {
247
254
// Temporarily use int override until we support size_t
248
- this ->setProperty (context, DeviceDesc::getCPUL1CacheSizeInBytesKeyName (), value);
255
+ this ->setProperty (context, DeviceDesc::getCPUL1CacheSizeInBytesKeyName (),
256
+ value);
249
257
}
250
258
std::optional<int64_t > getConvAndMatMulBlockingFactor () const {
251
259
if (std::optional<int64_t > v = this ->getPropertyValueAsInt (
@@ -256,8 +264,8 @@ class DeviceDesc {
256
264
}
257
265
void setConvAndMatMulBlockingFactor (MLIRContext *context, int64_t value) {
258
266
// 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);
261
269
}
262
270
std::optional<int64_t > getMatMulTileSizeInBytes () const {
263
271
if (std::optional<int64_t > v = this ->getPropertyValueAsInt (
@@ -268,7 +276,8 @@ class DeviceDesc {
268
276
}
269
277
void setMatMulTileSizeInBytes (MLIRContext *context, int64_t value) {
270
278
// Temporarily use int override until we support size_t
271
- this ->setProperty (context, DeviceDesc::getMatMulTileSizeInBytesKeyName (), value);
279
+ this ->setProperty (context, DeviceDesc::getMatMulTileSizeInBytesKeyName (),
280
+ value);
272
281
}
273
282
std::optional<int64_t > getCanonicalizerMaxNumRewrites () const {
274
283
if (std::optional<int64_t > v = this ->getPropertyValueAsInt (
@@ -278,8 +287,8 @@ class DeviceDesc {
278
287
return std::nullopt;
279
288
}
280
289
void setCanonicalizerMaxNumRewrites (MLIRContext *context, int64_t value) {
281
- this ->setProperty (context, DeviceDesc::getCanonicalizerMaxNumRewritesKeyName (),
282
- value);
290
+ this ->setProperty (
291
+ context, DeviceDesc::getCanonicalizerMaxNumRewritesKeyName (), value);
283
292
}
284
293
std::optional<int64_t > getCanonicalizerMaxIterations () const {
285
294
if (std::optional<int64_t > v = this ->getPropertyValueAsInt (
@@ -289,8 +298,8 @@ class DeviceDesc {
289
298
return std::nullopt;
290
299
}
291
300
void setCanonicalizerMaxIterations (MLIRContext *context, int64_t value) {
292
- this ->setProperty (context, DeviceDesc::getCanonicalizerMaxIterationsKeyName (),
293
- value);
301
+ this ->setProperty (
302
+ context, DeviceDesc::getCanonicalizerMaxIterationsKeyName (), value);
294
303
}
295
304
std::optional<int64_t > getMaxVectorWidth () const {
296
305
if (std::optional<int64_t > v = this ->getPropertyValueAsInt (
@@ -321,12 +330,8 @@ class DeviceDesc {
321
330
class SystemDesc {
322
331
public:
323
332
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 ; }
330
335
331
336
// / Insert a new device description
332
337
SystemDesc &addDeviceDesc (const DeviceDesc &desc) {
@@ -475,34 +480,37 @@ class DefaultGPUDeviceDesc : public DefaultBaseDeviceDesc {
475
480
// Config file readers
476
481
// ---------------------------------------------------------------------------
477
482
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
497
503
498
504
class SystemDescConfigFileParser {
499
505
public:
500
506
// / Build SystemDesc by parsing input config file. Returns valid SystemDesc
501
507
// / 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);
506
514
}
507
515
};
508
516
0 commit comments