1 // Copyright (C) 2018-2019 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
5 // avoiding clash of the "max" macro with std::max
9 #include "ie_plugin_config.hpp"
10 #include "ie_common.h"
18 #include <cpp_interfaces/exception2status.hpp>
20 #include "mkldnn/omp_manager.h"
22 namespace MKLDNNPlugin {
24 using namespace InferenceEngine;
26 void Config::readProperties(const std::map<std::string, std::string> &prop) {
27 for (auto& kvp : prop) {
28 std::string key = kvp.first;
29 std::string val = kvp.second;
31 if (key == PluginConfigParams::KEY_CPU_BIND_THREAD) {
32 if (val == PluginConfigParams::YES) useThreadBinding = true;
33 else if (val == PluginConfigParams::NO) useThreadBinding = false;
35 THROW_IE_EXCEPTION << "Wrong value for property key " << PluginConfigParams::KEY_CPU_BIND_THREAD
36 << ". Expected only YES/NO";
37 } else if (key == PluginConfigParams::KEY_DYN_BATCH_LIMIT) {
38 int val_i = std::stoi(val);
39 // zero and any negative value will be treated
40 // as default batch size
41 batchLimit = std::max(val_i, 0);
42 } else if (key == PluginConfigParams::KEY_PERF_COUNT) {
43 if (val == PluginConfigParams::YES) collectPerfCounters = true;
44 else if (val == PluginConfigParams::NO) collectPerfCounters = false;
46 THROW_IE_EXCEPTION << "Wrong value for property key " << PluginConfigParams::KEY_PERF_COUNT
47 << ". Expected only YES/NO";
48 } else if (key == PluginConfigParams::KEY_EXCLUSIVE_ASYNC_REQUESTS) {
49 if (val == PluginConfigParams::YES) exclusiveAsyncRequests = true;
50 else if (val == PluginConfigParams::NO) exclusiveAsyncRequests = false;
52 THROW_IE_EXCEPTION << "Wrong value for property key " << PluginConfigParams::KEY_EXCLUSIVE_ASYNC_REQUESTS
53 << ". Expected only YES/NO";
54 } else if (key == PluginConfigParams::KEY_CPU_THROUGHPUT_STREAMS) {
55 if (val == PluginConfigParams::CPU_THROUGHPUT_NUMA) {
56 throughputStreams = MKLDNNPlugin::cpu::getNumberOfCPUSockets();
57 } else if (val == PluginConfigParams::CPU_THROUGHPUT_AUTO) {
58 // bare minimum of streams (that evenly divides available number of core)
59 const int num_cores = std::thread::hardware_concurrency();
60 if (0 == num_cores % 4)
61 throughputStreams = std::max(4, num_cores / 4);
62 else if (0 == num_cores % 5)
63 throughputStreams = std::max(5, num_cores / 5);
64 else if (0 == num_cores % 3)
65 throughputStreams = std::max(3, num_cores / 3);
66 else // if user disables some cores say in BIOS, so we got weird #cores which is not easy to divide
67 throughputStreams = 1;
71 val_i = std::stoi(val);
72 } catch (const std::exception&) {
73 THROW_IE_EXCEPTION << "Wrong value for property key " << PluginConfigParams::KEY_CPU_THROUGHPUT_STREAMS
74 << ". Expected only positive numbers (#streams) or "
75 << "PluginConfigParams::CPU_THROUGHPUT_NUMA/CPU_THROUGHPUT_AUTO";
78 throughputStreams = val_i;
80 } else if (key == PluginConfigParams::KEY_CPU_THREADS_NUM) {
83 val_i = std::stoi(val);
84 } catch (const std::exception&) {
85 THROW_IE_EXCEPTION << "Wrong value for property key " << PluginConfigParams::KEY_CPU_THREADS_NUM
86 << ". Expected only positive numbers (#threads)";
90 } else if (key.compare(PluginConfigParams::KEY_DYN_BATCH_ENABLED) == 0) {
91 if (val.compare(PluginConfigParams::YES) == 0)
92 enableDynamicBatch = true;
93 else if (val.compare(PluginConfigParams::NO) == 0)
94 enableDynamicBatch = false;
96 THROW_IE_EXCEPTION << "Wrong value for property key " << PluginConfigParams::KEY_DYN_BATCH_ENABLED
97 << ". Expected only YES/NO";
98 } else if (key.compare(PluginConfigParams::KEY_DUMP_EXEC_GRAPH_AS_DOT) == 0) {
99 // empty string means that dumping is switched off
102 THROW_IE_EXCEPTION << NOT_FOUND_str << "Unsupported property " << key << " by CPU plugin";
105 if (exclusiveAsyncRequests) // Exclusive request feature disables the streams
106 throughputStreams = 1;
109 } // namespace MKLDNNPlugin