[Mlir-commits] [mlir] [mlir] Target Description and Cost Model in MLIR (PR #85141)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Fri Mar 15 15:43:32 PDT 2024
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff b966b224b32aada3d83fb6d58abe413b5c59f3c1 a93107d014e81131586d0d01e10319a5aeaf29c7 -- mlir/include/mlir/Support/SystemDesc.h mlir/lib/Support/SystemDesc.cpp mlir/include/mlir/IR/MLIRContext.h mlir/include/mlir/Tools/mlir-opt/MlirOptMain.h mlir/lib/Conversion/AMDGPUToROCDL/AMDGPUToROCDL.cpp mlir/lib/IR/MLIRContext.cpp mlir/lib/Tools/mlir-opt/MlirOptMain.cpp mlir/lib/Transforms/Canonicalizer.cpp
``````````
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/mlir/include/mlir/IR/MLIRContext.h b/mlir/include/mlir/IR/MLIRContext.h
index f94e223ba5..76de6b11f9 100644
--- a/mlir/include/mlir/IR/MLIRContext.h
+++ b/mlir/include/mlir/IR/MLIRContext.h
@@ -245,7 +245,7 @@ public:
SystemDesc &getSystemDesc();
/// Set context-specific system descriptor
- void setSystemDesc(const SystemDesc& desc);
+ void setSystemDesc(const SystemDesc &desc);
//===--------------------------------------------------------------------===//
// Action API
diff --git a/mlir/include/mlir/Support/SystemDesc.h b/mlir/include/mlir/Support/SystemDesc.h
index 926569eddd..2c03edb118 100644
--- a/mlir/include/mlir/Support/SystemDesc.h
+++ b/mlir/include/mlir/Support/SystemDesc.h
@@ -88,7 +88,8 @@ public:
}
/// Set property
- DeviceDesc &setProperty(MLIRContext *context, llvm::StringRef name, int64_t iv) {
+ DeviceDesc &setProperty(MLIRContext *context, llvm::StringRef name,
+ int64_t iv) {
std::optional<NamedAttribute> attr = deviceProperties.getNamed(name);
if (!attr.has_value()) {
IntegerType int64Ty = IntegerType::get(context, 64);
@@ -99,7 +100,8 @@ public:
return *this;
}
- DeviceDesc &setProperty(MLIRContext *context, llvm::StringRef name, double dv) {
+ DeviceDesc &setProperty(MLIRContext *context, llvm::StringRef name,
+ double dv) {
std::optional<NamedAttribute> attr = deviceProperties.getNamed(name);
if (!attr.has_value()) {
FloatType floatType = FloatType::getF64(context);
@@ -115,8 +117,10 @@ public:
std::optional<NamedAttribute> attr = deviceProperties.getNamed(name);
if (!attr.has_value()) {
IntegerType int64Ty = IntegerType::get(context, 64);
- RankedTensorType shape = RankedTensorType::get({static_cast<long>(ivv.size()), 1}, int64Ty);
- DenseElementsAttr value = DenseElementsAttr::get(shape, llvm::ArrayRef(ivv));
+ RankedTensorType shape =
+ RankedTensorType::get({static_cast<long>(ivv.size()), 1}, int64Ty);
+ DenseElementsAttr value =
+ DenseElementsAttr::get(shape, llvm::ArrayRef(ivv));
deviceProperties.append(name, value);
} else
llvm::report_fatal_error("Duplicate device property name found:" + name);
@@ -128,8 +132,10 @@ public:
std::optional<NamedAttribute> attr = deviceProperties.getNamed(name);
if (!attr.has_value()) {
FloatType float64Ty = FloatType::getF64(context);
- RankedTensorType shape = RankedTensorType::get({static_cast<long>(idv.size()), 1}, float64Ty);
- DenseElementsAttr value = DenseElementsAttr::get(shape, llvm::ArrayRef(idv));
+ RankedTensorType shape =
+ RankedTensorType::get({static_cast<long>(idv.size()), 1}, float64Ty);
+ DenseElementsAttr value =
+ DenseElementsAttr::get(shape, llvm::ArrayRef(idv));
deviceProperties.append(name, value);
} else
llvm::report_fatal_error("Duplicate device property name found:" + name);
@@ -137,7 +143,8 @@ public:
}
// We provide convenience interface to handle int/float value as string
- DeviceDesc &setProperty(MLIRContext *context, llvm::StringRef name, const std::string &json_value) {
+ DeviceDesc &setProperty(MLIRContext *context, llvm::StringRef name,
+ const std::string &json_value) {
if (json_value.length() > 0 && json_value[0] == '[') {
// Parse as an array
llvm::Expected<std::vector<int64_t>> ivv =
@@ -245,7 +252,8 @@ public:
}
void setL1CacheSizeInBytes(MLIRContext *context, int64_t value) {
// Temporarily use int override until we support size_t
- this->setProperty(context, DeviceDesc::getCPUL1CacheSizeInBytesKeyName(), value);
+ this->setProperty(context, DeviceDesc::getCPUL1CacheSizeInBytesKeyName(),
+ value);
}
std::optional<int64_t> getConvAndMatMulBlockingFactor() const {
if (std::optional<int64_t> v = this->getPropertyValueAsInt(
@@ -256,8 +264,8 @@ public:
}
void setConvAndMatMulBlockingFactor(MLIRContext *context, int64_t value) {
// Temporarily use int override until we support size_t
- this->setProperty(context, DeviceDesc::getConvAndMatMulBlockingFactorKeyName(),
- value);
+ this->setProperty(
+ context, DeviceDesc::getConvAndMatMulBlockingFactorKeyName(), value);
}
std::optional<int64_t> getMatMulTileSizeInBytes() const {
if (std::optional<int64_t> v = this->getPropertyValueAsInt(
@@ -268,7 +276,8 @@ public:
}
void setMatMulTileSizeInBytes(MLIRContext *context, int64_t value) {
// Temporarily use int override until we support size_t
- this->setProperty(context, DeviceDesc::getMatMulTileSizeInBytesKeyName(), value);
+ this->setProperty(context, DeviceDesc::getMatMulTileSizeInBytesKeyName(),
+ value);
}
std::optional<int64_t> getCanonicalizerMaxNumRewrites() const {
if (std::optional<int64_t> v = this->getPropertyValueAsInt(
@@ -278,8 +287,8 @@ public:
return std::nullopt;
}
void setCanonicalizerMaxNumRewrites(MLIRContext *context, int64_t value) {
- this->setProperty(context, DeviceDesc::getCanonicalizerMaxNumRewritesKeyName(),
- value);
+ this->setProperty(
+ context, DeviceDesc::getCanonicalizerMaxNumRewritesKeyName(), value);
}
std::optional<int64_t> getCanonicalizerMaxIterations() const {
if (std::optional<int64_t> v = this->getPropertyValueAsInt(
@@ -289,8 +298,8 @@ public:
return std::nullopt;
}
void setCanonicalizerMaxIterations(MLIRContext *context, int64_t value) {
- this->setProperty(context, DeviceDesc::getCanonicalizerMaxIterationsKeyName(),
- value);
+ this->setProperty(
+ context, DeviceDesc::getCanonicalizerMaxIterationsKeyName(), value);
}
std::optional<int64_t> getMaxVectorWidth() const {
if (std::optional<int64_t> v = this->getPropertyValueAsInt(
@@ -321,12 +330,8 @@ private:
class SystemDesc {
public:
SystemDesc() = default;
- SystemDesc(const SystemDesc &desc) {
- this->deviceDescs = desc.deviceDescs;
- }
- void operator=(const SystemDesc &rhs) {
- this->deviceDescs = rhs.deviceDescs;
- }
+ SystemDesc(const SystemDesc &desc) { this->deviceDescs = desc.deviceDescs; }
+ void operator=(const SystemDesc &rhs) { this->deviceDescs = rhs.deviceDescs; }
/// Insert a new device description
SystemDesc &addDeviceDesc(const DeviceDesc &desc) {
@@ -475,34 +480,37 @@ private:
// Config file readers
// ---------------------------------------------------------------------------
namespace impl {
- class SystemDescJSONConfigParser {
- public:
- /// Build SystemDesc by parsing input config file in JSON format.
- /// Returns a valid SystemDesc if parsing is successful; otherwise
- /// returns std::nullopt.
- static std::optional<SystemDesc> buildSystemDescFromConfigFile(
- MLIRContext *context, llvm::StringRef filename);
-
- private:
- /// We represent DeviceDesc in JSON as a key-value pairs of strings.
- using DeviceDescJSONTy = std::map<std::string, std::string>;
-
- /// A utility function to parse device description entry in JSON format
- /// Returns valid DeviceDesc if parsing is successful; otherwise returns
- /// std::nullopt.
- static std::optional<DeviceDesc> buildDeviceDescFromConfigFile(MLIRContext *context,
- const DeviceDescJSONTy &device_desc_in_json);
- };
-}
+class SystemDescJSONConfigParser {
+public:
+ /// Build SystemDesc by parsing input config file in JSON format.
+ /// Returns a valid SystemDesc if parsing is successful; otherwise
+ /// returns std::nullopt.
+ static std::optional<SystemDesc>
+ buildSystemDescFromConfigFile(MLIRContext *context, llvm::StringRef filename);
+
+private:
+ /// We represent DeviceDesc in JSON as a key-value pairs of strings.
+ using DeviceDescJSONTy = std::map<std::string, std::string>;
+
+ /// A utility function to parse device description entry in JSON format
+ /// Returns valid DeviceDesc if parsing is successful; otherwise returns
+ /// std::nullopt.
+ static std::optional<DeviceDesc>
+ buildDeviceDescFromConfigFile(MLIRContext *context,
+ const DeviceDescJSONTy &device_desc_in_json);
+};
+} // namespace impl
class SystemDescConfigFileParser {
public:
/// Build SystemDesc by parsing input config file. Returns valid SystemDesc
/// if parsing is successful; otherwise returns std::nullopt.
- static std::optional<SystemDesc> buildSystemDescFromConfigFile(
- MLIRContext *context, llvm::StringRef filename) {
- // Once we support more formats, we can accept format as the input argument.
- return impl::SystemDescJSONConfigParser::buildSystemDescFromConfigFile(context, filename);
+ static std::optional<SystemDesc>
+ buildSystemDescFromConfigFile(MLIRContext *context,
+ llvm::StringRef filename) {
+ // Once we support more formats, we can accept format as the input argument.
+ return impl::SystemDescJSONConfigParser::buildSystemDescFromConfigFile(
+ context, filename);
}
};
diff --git a/mlir/lib/IR/MLIRContext.cpp b/mlir/lib/IR/MLIRContext.cpp
index f656ab6994..d695cd50c3 100644
--- a/mlir/lib/IR/MLIRContext.cpp
+++ b/mlir/lib/IR/MLIRContext.cpp
@@ -708,7 +708,9 @@ bool MLIRContext::isOperationRegistered(StringRef name) {
SystemDesc &MLIRContext::getSystemDesc() { return impl->system_desc; }
-void MLIRContext::setSystemDesc(const SystemDesc& desc) { impl->system_desc = desc; }
+void MLIRContext::setSystemDesc(const SystemDesc &desc) {
+ impl->system_desc = desc;
+}
void Dialect::addType(TypeID typeID, AbstractType &&typeInfo) {
auto &impl = context->getImpl();
diff --git a/mlir/lib/Support/SystemDesc.cpp b/mlir/lib/Support/SystemDesc.cpp
index 356ec13287..0527490fd0 100644
--- a/mlir/lib/Support/SystemDesc.cpp
+++ b/mlir/lib/Support/SystemDesc.cpp
@@ -20,19 +20,22 @@
using namespace llvm;
using namespace mlir;
-std::optional<DeviceDesc> impl::SystemDescJSONConfigParser::buildDeviceDescFromConfigFile(
+std::optional<DeviceDesc>
+impl::SystemDescJSONConfigParser::buildDeviceDescFromConfigFile(
MLIRContext *context, const DeviceDescJSONTy &device_desc_in_json) {
// ID and Type are mandatory fields.
auto iter = device_desc_in_json.find("ID");
if (iter == device_desc_in_json.end()) {
- llvm::errs() << "\"ID\" key missing in Device Description" << "\n";
+ llvm::errs() << "\"ID\" key missing in Device Description"
+ << "\n";
return std::nullopt;
}
DeviceDesc::DeviceID id = DeviceDesc::strToDeviceID(iter->second);
iter = device_desc_in_json.find("Type");
if (iter == device_desc_in_json.end()) {
- llvm::errs() << "\"Type\" key missing in Device Description" << "\n";
+ llvm::errs() << "\"Type\" key missing in Device Description"
+ << "\n";
return std::nullopt;
}
DeviceDesc::DeviceType type = DeviceDesc::strToDeviceType(iter->second);
@@ -51,7 +54,8 @@ std::optional<DeviceDesc> impl::SystemDescJSONConfigParser::buildDeviceDescFromC
return std::optional<DeviceDesc>(device_desc);
}
-std::optional<SystemDesc> impl::SystemDescJSONConfigParser::buildSystemDescFromConfigFile(
+std::optional<SystemDesc>
+impl::SystemDescJSONConfigParser::buildSystemDescFromConfigFile(
MLIRContext *context, llvm::StringRef filename) {
std::string errorMessage;
std::unique_ptr<llvm::MemoryBuffer> file =
@@ -73,14 +77,16 @@ std::optional<SystemDesc> impl::SystemDescJSONConfigParser::buildSystemDescFromC
using SystemDescJSONTy = std::vector<DeviceDescJSONTy>;
SystemDescJSONTy system_desc_in_json;
if (!json::fromJSON(*parsed, system_desc_in_json, NullRoot)) {
- llvm::errs() << "Invalid System Description in JSON" << "\n";
+ llvm::errs() << "Invalid System Description in JSON"
+ << "\n";
return std::nullopt;
}
SystemDesc system_desc;
for (auto device_desc_in_json : system_desc_in_json) {
- std::optional<DeviceDesc> device_desc = impl::SystemDescJSONConfigParser::buildDeviceDescFromConfigFile(
- context, device_desc_in_json);
+ std::optional<DeviceDesc> device_desc =
+ impl::SystemDescJSONConfigParser::buildDeviceDescFromConfigFile(
+ context, device_desc_in_json);
if (device_desc)
system_desc.addDeviceDesc(*device_desc);
else
diff --git a/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp b/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp
index fd2db58e5b..0b2b368249 100644
--- a/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp
+++ b/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp
@@ -391,8 +391,8 @@ performActions(raw_ostream &os,
bool setDefaultSystemDesc = true;
if (!config.getSystemDescriptionFileName().empty()) {
std::optional<SystemDesc> desc =
- SystemDescConfigFileParser::buildSystemDescFromConfigFile(context,
- config.getSystemDescriptionFileName());
+ SystemDescConfigFileParser::buildSystemDescFromConfigFile(
+ context, config.getSystemDescriptionFileName());
if (desc) {
context->setSystemDesc(*desc);
setDefaultSystemDesc = false;
``````````
</details>
https://github.com/llvm/llvm-project/pull/85141
More information about the Mlir-commits
mailing list