Skip to content

Commit

Permalink
Properties for NPUW (openvinotoolkit#52)
Browse files Browse the repository at this point in the history
* Properties in NPUW

* Fixed review comments
  • Loading branch information
AsyaPronina authored Jun 10, 2024
1 parent afbabdf commit c94ed50
Show file tree
Hide file tree
Showing 20 changed files with 1,165 additions and 468 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,30 @@ template <typename T>
struct OptionParser<std::vector<T>> final {
static std::vector<T> parse(std::string_view val) {
std::vector<T> res;
splitAndApply(val, ',', [&](std::string_view item) {
std::string val_str(val);
splitAndApply(val_str, ',', [&](std::string_view item) {
res.push_back(OptionParser<T>::parse(item));
});
return res;
}
};

template <typename K, typename V>
struct OptionParser<std::map<K, V>> final {
static std::map<K, V> parse(std::string_view val) {
std::map<K, V> res;
std::string val_str(val);
splitAndApply(val_str, ',', [&](std::string_view item) {
auto kv_delim_pos = item.find(":");
OPENVINO_ASSERT(kv_delim_pos != std::string::npos);
K key = OptionParser<K>::parse(std::string_view(item.substr(0, kv_delim_pos)));
V value = OptionParser<V>::parse(std::string_view(item.substr(kv_delim_pos + 1)));
res[key] = value;
});
return res;
}
};

template <typename Rep, typename Period>
struct OptionParser<std::chrono::duration<Rep, Period>> final {
static std::chrono::duration<Rep, Period> parse(std::string_view val) {
Expand Down Expand Up @@ -328,6 +345,7 @@ OptionConcept makeOptionModel() {

class OptionsDesc final {
public:
OptionsDesc(const std::string_view& name);
template <class Opt>
void add();

Expand All @@ -339,6 +357,7 @@ class OptionsDesc final {
private:
std::unordered_map<std::string, details::OptionConcept> _impl;
std::unordered_map<std::string, std::string> _deprecated;
std::string_view _name;
};

template <class Opt>
Expand All @@ -364,7 +383,8 @@ class Config final {
using ConfigMap = std::map<std::string, std::string>;
using ImplMap = std::unordered_map<std::string, std::shared_ptr<details::OptionValue>>;

explicit Config(const std::shared_ptr<const OptionsDesc>& desc);
explicit Config(const std::shared_ptr<const OptionsDesc>& desc,
const std::string_view& name);

void update(const ConfigMap& options, OptionMode mode = OptionMode::Both);

Expand All @@ -384,6 +404,7 @@ class Config final {
private:
std::shared_ptr<const OptionsDesc> _desc;
ImplMap _impl;
std::string_view _name;
};

template <class Opt>
Expand All @@ -395,7 +416,7 @@ template <class Opt>
typename Opt::ValueType Config::get() const {
using ValueType = typename Opt::ValueType;

auto log = Logger::global().clone("Config");
auto log = Logger::global().clone(_name);
log.trace("Get value for the option '%s'", Opt::key().data());

const auto it = _impl.find(Opt::key().data());
Expand Down
Loading

0 comments on commit c94ed50

Please sign in to comment.