Streams executor configured using OV2.0 configuration API (#9587)

* Streams executor config OV2.0

* Fixed error

* Reverted CPU tests
This commit is contained in:
Anton Pankratov 2022-02-01 13:08:32 +03:00 committed by GitHub
parent 8ca6aeae83
commit b8a4b0742b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 69 additions and 21 deletions

View File

@ -40,7 +40,11 @@ Configuration::Configuration(const ConfigMap& config, const Configuration& defau
} }
InferenceEngine::Parameter Configuration::Get(const std::string& name) const { InferenceEngine::Parameter Configuration::Get(const std::string& name) const {
if (name == CONFIG_KEY(DEVICE_ID)) { auto streamExecutorConfigKeys = _streamsExecutorConfig.SupportedKeys();
if ((streamExecutorConfigKeys.end() !=
std::find(std::begin(streamExecutorConfigKeys), std::end(streamExecutorConfigKeys), name))) {
return _streamsExecutorConfig.GetConfig(name);
} else if (name == CONFIG_KEY(DEVICE_ID)) {
return {std::to_string(deviceId)}; return {std::to_string(deviceId)};
} else if (name == CONFIG_KEY(PERF_COUNT)) { } else if (name == CONFIG_KEY(PERF_COUNT)) {
return {perfCount}; return {perfCount};

View File

@ -56,7 +56,7 @@ public:
* @brief Supported Configuration keys * @brief Supported Configuration keys
* @return vector of supported configuration keys * @return vector of supported configuration keys
*/ */
std::vector<std::string> SupportedKeys(); std::vector<std::string> SupportedKeys() const;
/** /**
* @brief Parses configuration key/value pair * @brief Parses configuration key/value pair
@ -70,7 +70,7 @@ public:
* @param key configuration key * @param key configuration key
* @return configuration value wrapped into Parameter * @return configuration value wrapped into Parameter
*/ */
Parameter GetConfig(const std::string& key); Parameter GetConfig(const std::string& key) const;
/** /**
* @brief Create appropriate multithreaded configuration * @brief Create appropriate multithreaded configuration

View File

@ -15,16 +15,20 @@
#include "ie_parameter.hpp" #include "ie_parameter.hpp"
#include "ie_plugin_config.hpp" #include "ie_plugin_config.hpp"
#include "ie_system_conf.h" #include "ie_system_conf.h"
#include "openvino/runtime/properties.hpp"
namespace InferenceEngine { namespace InferenceEngine {
IStreamsExecutor::~IStreamsExecutor() {} IStreamsExecutor::~IStreamsExecutor() {}
std::vector<std::string> IStreamsExecutor::Config::SupportedKeys() { std::vector<std::string> IStreamsExecutor::Config::SupportedKeys() const {
return { return {
CONFIG_KEY(CPU_THROUGHPUT_STREAMS), CONFIG_KEY(CPU_THROUGHPUT_STREAMS),
CONFIG_KEY(CPU_BIND_THREAD), CONFIG_KEY(CPU_BIND_THREAD),
CONFIG_KEY(CPU_THREADS_NUM), CONFIG_KEY(CPU_THREADS_NUM),
CONFIG_KEY_INTERNAL(CPU_THREADS_PER_STREAM), CONFIG_KEY_INTERNAL(CPU_THREADS_PER_STREAM),
ov::streams::num.name(),
ov::inference_num_threads.name(),
ov::affinity.name(),
}; };
} }
int IStreamsExecutor::Config::GetDefaultNumStreams() { int IStreamsExecutor::Config::GetDefaultNumStreams() {
@ -59,6 +63,29 @@ void IStreamsExecutor::Config::SetConfig(const std::string& key, const std::stri
<< ". Expected only YES(binds to cores) / NO(no binding) / NUMA(binds to NUMA nodes) / " << ". Expected only YES(binds to cores) / NO(no binding) / NUMA(binds to NUMA nodes) / "
"HYBRID_AWARE (let the runtime recognize and use the hybrid cores)"; "HYBRID_AWARE (let the runtime recognize and use the hybrid cores)";
} }
} else if (key == ov::affinity) {
ov::Affinity affinity;
std::stringstream{value} >> affinity;
switch (affinity) {
case ov::Affinity::NONE:
_threadBindingType = ThreadBindingType::NONE;
break;
case ov::Affinity::CORE: {
#if (defined(__APPLE__) || defined(_WIN32))
_threadBindingType = ThreadBindingType::NUMA;
#else
_threadBindingType = ThreadBindingType::CORES;
#endif
} break;
case ov::Affinity::NUMA:
_threadBindingType = ThreadBindingType::NUMA;
break;
case ov::Affinity::HYBRID_AWARE:
_threadBindingType = ThreadBindingType::HYBRID_AWARE;
break;
default:
OPENVINO_UNREACHABLE("Unsupported affinity type");
}
} else if (key == CONFIG_KEY(CPU_THROUGHPUT_STREAMS)) { } else if (key == CONFIG_KEY(CPU_THROUGHPUT_STREAMS)) {
if (value == CONFIG_VALUE(CPU_THROUGHPUT_NUMA)) { if (value == CONFIG_VALUE(CPU_THROUGHPUT_NUMA)) {
_streams = static_cast<int>(getAvailableNUMANodes().size()); _streams = static_cast<int>(getAvailableNUMANodes().size());
@ -80,7 +107,23 @@ void IStreamsExecutor::Config::SetConfig(const std::string& key, const std::stri
} }
_streams = val_i; _streams = val_i;
} }
} else if (key == CONFIG_KEY(CPU_THREADS_NUM)) { } else if (key == ov::streams::num) {
int32_t streams = std::stoi(value);
if (streams == ov::streams::NUMA) {
_streams = static_cast<int32_t>(getAvailableNUMANodes().size());
} else if (streams == ov::streams::AUTO) {
// bare minimum of streams (that evenly divides available number of cores)
_streams = GetDefaultNumStreams();
} else if (streams >= 0) {
_streams = streams;
} else {
OPENVINO_UNREACHABLE("Wrong value for property key ",
ov::streams::num.name(),
". Expected non negative numbers (#streams) or ",
"ov::streams::NUMA|ov::streams::AUTO, Got: ",
streams);
}
} else if (key == CONFIG_KEY(CPU_THREADS_NUM) || key == ov::inference_num_threads) {
int val_i; int val_i;
try { try {
val_i = std::stoi(value); val_i = std::stoi(value);
@ -111,26 +154,37 @@ void IStreamsExecutor::Config::SetConfig(const std::string& key, const std::stri
} }
} }
Parameter IStreamsExecutor::Config::GetConfig(const std::string& key) { Parameter IStreamsExecutor::Config::GetConfig(const std::string& key) const {
if (key == CONFIG_KEY(CPU_BIND_THREAD)) { if (key == ov::affinity) {
switch (_threadBindingType) {
case IStreamsExecutor::ThreadBindingType::NONE:
return ov::Affinity::NONE;
case IStreamsExecutor::ThreadBindingType::CORES:
return ov::Affinity::CORE;
case IStreamsExecutor::ThreadBindingType::NUMA:
return ov::Affinity::NUMA;
case IStreamsExecutor::ThreadBindingType::HYBRID_AWARE:
return ov::Affinity::HYBRID_AWARE;
}
} else if (key == CONFIG_KEY(CPU_BIND_THREAD)) {
switch (_threadBindingType) { switch (_threadBindingType) {
case IStreamsExecutor::ThreadBindingType::NONE: case IStreamsExecutor::ThreadBindingType::NONE:
return {CONFIG_VALUE(NO)}; return {CONFIG_VALUE(NO)};
break;
case IStreamsExecutor::ThreadBindingType::CORES: case IStreamsExecutor::ThreadBindingType::CORES:
return {CONFIG_VALUE(YES)}; return {CONFIG_VALUE(YES)};
break;
case IStreamsExecutor::ThreadBindingType::NUMA: case IStreamsExecutor::ThreadBindingType::NUMA:
return {CONFIG_VALUE(NUMA)}; return {CONFIG_VALUE(NUMA)};
break;
case IStreamsExecutor::ThreadBindingType::HYBRID_AWARE: case IStreamsExecutor::ThreadBindingType::HYBRID_AWARE:
return {CONFIG_VALUE(HYBRID_AWARE)}; return {CONFIG_VALUE(HYBRID_AWARE)};
break;
} }
} else if (key == CONFIG_KEY(CPU_THROUGHPUT_STREAMS)) { } else if (key == CONFIG_KEY(CPU_THROUGHPUT_STREAMS)) {
return {std::to_string(_streams)}; return {std::to_string(_streams)};
} else if (key == ov::streams::num) {
return decltype(ov::streams::num)::value_type{_streams};
} else if (key == CONFIG_KEY(CPU_THREADS_NUM)) { } else if (key == CONFIG_KEY(CPU_THREADS_NUM)) {
return {std::to_string(_threads)}; return {std::to_string(_threads)};
} else if (key == ov::inference_num_threads) {
return decltype(ov::inference_num_threads)::value_type{_threads};
} else if (key == CONFIG_KEY_INTERNAL(CPU_THREADS_PER_STREAM)) { } else if (key == CONFIG_KEY_INTERNAL(CPU_THREADS_PER_STREAM)) {
return {std::to_string(_threadsPerStream)}; return {std::to_string(_threadsPerStream)};
} else { } else {

View File

@ -189,16 +189,6 @@ TEST_P(ASyncTaskExecutorTests, runAndWaitDoesNotOwnTasks) {
class StreamsExecutorConfigTest : public ::testing::Test {}; class StreamsExecutorConfigTest : public ::testing::Test {};
TEST_F(StreamsExecutorConfigTest, streamsExecutorConfigReturnStrings) {
auto streams = getNumberOfCPUCores();
auto threads = parallel_get_max_threads();
auto config = IStreamsExecutor::Config::MakeDefaultMultiThreaded({"TestCPUStreamsExecutor",
streams, threads/streams, IStreamsExecutor::ThreadBindingType::NONE});
for (auto&& key : config.SupportedKeys()) {
ASSERT_NO_THROW(config.GetConfig(key).as<std::string>());
}
}
static auto Executors = ::testing::Values( static auto Executors = ::testing::Values(
[] { [] {
auto streams = getNumberOfCPUCores(); auto streams = getNumberOfCPUCores();