Streams property with special values (#10411)

* Streams  property with special values

* Fixed clang
This commit is contained in:
Anton Pankratov 2022-02-17 16:39:06 +03:00 committed by GitHub
parent 198f44fdc7
commit 61f657795c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 42 additions and 28 deletions

View File

@ -329,7 +329,7 @@ int main(int argc, char* argv[]) {
} else if (supported(ov::num_streams.name())) { } else if (supported(ov::num_streams.name())) {
// Use API 2.0 key for streams // Use API 2.0 key for streams
key = ov::num_streams.name(); key = ov::num_streams.name();
device_config[key] = ov::NumStreams::AUTO; device_config[key] = ov::streams::AUTO;
} }
} }
} }

View File

@ -628,10 +628,11 @@ constexpr static const auto EXPORT_IMPORT = "EXPORT_IMPORT"; //!< Device suppor
} // namespace capability } // namespace capability
} // namespace device } // namespace device
namespace streams {
/** /**
* @brief Class to represent number of streams in streams executor * @brief Class to represent number of streams in streams executor
*/ */
struct NumStreams { struct Num {
using Base = std::tuple<int32_t>; //!< NumStreams is representable as int32_t using Base = std::tuple<int32_t>; //!< NumStreams is representable as int32_t
/** /**
@ -642,9 +643,9 @@ struct NumStreams {
NUMA = -2, //!< Creates as many streams as needed to accommodate NUMA and avoid associated penalties NUMA = -2, //!< Creates as many streams as needed to accommodate NUMA and avoid associated penalties
}; };
NumStreams() : num{AUTO} {}; constexpr Num() : num{AUTO} {};
NumStreams(const int32_t num_) : num{num_} {} constexpr Num(const int32_t num_) : num{num_} {}
operator int32_t() { operator int32_t() {
return num; return num;
@ -657,28 +658,37 @@ struct NumStreams {
int32_t num = 0; int32_t num = 0;
}; };
/**
* @brief The number of executor logical partitions
*/
static constexpr Property<Num, PropertyMutability::RW> num{"NUM_STREAMS"};
static constexpr Num AUTO{Num::AUTO}; //!< Creates bare minimum of streams to improve the performance
static constexpr Num NUMA{
Num::NUMA}; //!< Creates as many streams as needed to accommodate NUMA and avoid associated penalties
/** @cond INTERNAL */ /** @cond INTERNAL */
inline std::ostream& operator<<(std::ostream& os, const NumStreams& num_streams) { inline std::ostream& operator<<(std::ostream& os, const Num& num) {
switch (num_streams.num) { switch (num.num) {
case NumStreams::AUTO: case Num::AUTO:
return os << "AUTO"; return os << "AUTO";
case NumStreams::NUMA: case Num::NUMA:
return os << "NUMA"; return os << "NUMA";
default: default:
return os << num_streams.num; return os << num.num;
} }
} }
inline std::istream& operator>>(std::istream& is, NumStreams& num_streams) { inline std::istream& operator>>(std::istream& is, Num& num) {
std::string str; std::string str;
is >> str; is >> str;
if (str == "AUTO") { if (str == "AUTO") {
num_streams = {NumStreams::AUTO}; num = AUTO;
} else if (str == "NUMA") { } else if (str == "NUMA") {
num_streams = {NumStreams::NUMA}; num = NUMA;
} else { } else {
try { try {
num_streams = {std::stoi(str)}; num = {std::stoi(str)};
} catch (const std::exception& e) { } catch (const std::exception& e) {
throw ov::Exception{std::string{"Could not read number of streams from str: "} + str + "; " + e.what()}; throw ov::Exception{std::string{"Could not read number of streams from str: "} + str + "; " + e.what()};
} }
@ -686,11 +696,17 @@ inline std::istream& operator>>(std::istream& is, NumStreams& num_streams) {
return is; return is;
} }
/** @endcond */ /** @endcond */
} // namespace streams
/**
* @brief Class to represent number of streams in streams executor
*/
using NumStreams = streams::Num;
/** /**
* @brief The number of executor logical partitions * @brief The number of executor logical partitions
*/ */
static constexpr Property<NumStreams, PropertyMutability::RW> num_streams{"NUM_STREAMS"}; static constexpr Property<streams::Num, PropertyMutability::RW> num_streams{"NUM_STREAMS"};
/** /**
* @brief Maximum number of threads that can be used for inference tasks * @brief Maximum number of threads that can be used for inference tasks

View File

@ -16,6 +16,7 @@
#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" #include "openvino/runtime/properties.hpp"
#include "openvino/util/common_util.hpp"
namespace InferenceEngine { namespace InferenceEngine {
IStreamsExecutor::~IStreamsExecutor() {} IStreamsExecutor::~IStreamsExecutor() {}
@ -108,12 +109,10 @@ void IStreamsExecutor::Config::SetConfig(const std::string& key, const std::stri
_streams = val_i; _streams = val_i;
} }
} else if (key == ov::num_streams) { } else if (key == ov::num_streams) {
ov::NumStreams streams; auto streams = ov::util::from_string(value, ov::streams::num);
std::stringstream strm{value}; if (streams == ov::streams::NUMA) {
strm >> streams;
if (streams.num == ov::NumStreams::NUMA) {
_streams = static_cast<int32_t>(getAvailableNUMANodes().size()); _streams = static_cast<int32_t>(getAvailableNUMANodes().size());
} else if (streams.num == ov::NumStreams::AUTO) { } else if (streams == ov::streams::AUTO) {
// bare minimum of streams (that evenly divides available number of cores) // bare minimum of streams (that evenly divides available number of cores)
_streams = GetDefaultNumStreams(); _streams = GetDefaultNumStreams();
} else if (streams.num >= 0) { } else if (streams.num >= 0) {
@ -122,7 +121,7 @@ void IStreamsExecutor::Config::SetConfig(const std::string& key, const std::stri
OPENVINO_UNREACHABLE("Wrong value for property key ", OPENVINO_UNREACHABLE("Wrong value for property key ",
ov::num_streams.name(), ov::num_streams.name(),
". Expected non negative numbers (#streams) or ", ". Expected non negative numbers (#streams) or ",
"ov::NumStreams(ov::NumStreams::NUMA|ov::NumStreams::AUTO), Got: ", "ov::streams::NUMA|ov::streams::AUTO, Got: ",
streams); streams);
} }
} else if (key == CONFIG_KEY(CPU_THREADS_NUM) || key == ov::inference_num_threads) { } else if (key == CONFIG_KEY(CPU_THREADS_NUM) || key == ov::inference_num_threads) {

View File

@ -243,7 +243,7 @@ void Config::UpdateFromMap(const std::map<std::string, std::string>& configMap)
} }
} else if (key.compare(PluginConfigParams::KEY_GPU_THROUGHPUT_STREAMS) == 0 || key == ov::num_streams) { } else if (key.compare(PluginConfigParams::KEY_GPU_THROUGHPUT_STREAMS) == 0 || key == ov::num_streams) {
if (val.compare(PluginConfigParams::GPU_THROUGHPUT_AUTO) == 0 || if (val.compare(PluginConfigParams::GPU_THROUGHPUT_AUTO) == 0 ||
val.compare(ov::num_streams(ov::NumStreams::AUTO).second.as<std::string>()) == 0) { val.compare(ov::util::to_string(ov::streams::AUTO)) == 0) {
throughput_streams = GetDefaultNStreamsForThroughputMode(); throughput_streams = GetDefaultNStreamsForThroughputMode();
} else { } else {
int val_i; int val_i;

View File

@ -225,7 +225,7 @@ std::map<std::string, std::string> Plugin::ConvertPerfHintsToConfig(
config[ov::num_streams.name()] = std::to_string(1); config[ov::num_streams.name()] = std::to_string(1);
} else if (mode_name == CONFIG_VALUE(THROUGHPUT)) { } else if (mode_name == CONFIG_VALUE(THROUGHPUT)) {
config[PluginConfigParams::KEY_GPU_THROUGHPUT_STREAMS] = CONFIG_VALUE(GPU_THROUGHPUT_AUTO); config[PluginConfigParams::KEY_GPU_THROUGHPUT_STREAMS] = CONFIG_VALUE(GPU_THROUGHPUT_AUTO);
config[ov::num_streams.name()] = ov::util::to_string(ov::NumStreams(ov::NumStreams::AUTO)); config[ov::num_streams.name()] = ov::util::to_string(ov::streams::AUTO);
//disabling the throttling temporarily to set the validation (that is switching to the hints) perf baseline //disabling the throttling temporarily to set the validation (that is switching to the hints) perf baseline
//checking throttling (to avoid overriding what user might explicitly set in the incoming config or previously via SetConfig) //checking throttling (to avoid overriding what user might explicitly set in the incoming config or previously via SetConfig)
// const auto bInConfig = config.find(GPUConfigParams::KEY_GPU_PLUGIN_THROTTLE) != config.end() || // const auto bInConfig = config.find(GPUConfigParams::KEY_GPU_PLUGIN_THROTTLE) != config.end() ||
@ -913,7 +913,7 @@ Parameter Plugin::GetMetric(const std::string& name, const std::map<std::string,
} else if (it_streams->second.is<std::string>()) { } else if (it_streams->second.is<std::string>()) {
std::string n_streams_str = it_streams->second.as<std::string>(); std::string n_streams_str = it_streams->second.as<std::string>();
if (n_streams_str != CONFIG_VALUE(GPU_THROUGHPUT_AUTO) && if (n_streams_str != CONFIG_VALUE(GPU_THROUGHPUT_AUTO) &&
n_streams_str != util::to_string(ov::NumStreams(ov::NumStreams::AUTO))) { n_streams_str != util::to_string(ov::streams::AUTO)) {
IE_THROW() << "[GPU_MAX_BATCH_SIZE] bad casting: GPU_THROUGHPUT_STREAMS should be either of uint32_t type or \"GPU_THROUGHPUT_AUTO\""; IE_THROW() << "[GPU_MAX_BATCH_SIZE] bad casting: GPU_THROUGHPUT_STREAMS should be either of uint32_t type or \"GPU_THROUGHPUT_AUTO\"";
} }
n_streams = config.GetDefaultNStreamsForThroughputMode(); n_streams = config.GetDefaultNStreamsForThroughputMode();

View File

@ -9,6 +9,7 @@
#include <openvino/runtime/properties.hpp> #include <openvino/runtime/properties.hpp>
#include <sstream> #include <sstream>
#include <vpu/myriad_config.hpp> #include <vpu/myriad_config.hpp>
#include <openvino/util/common_util.hpp>
namespace vpu { namespace vpu {
@ -45,9 +46,7 @@ details::Category OvThroughputStreamsOption::category() {
} }
std::string OvThroughputStreamsOption::defaultValue() { std::string OvThroughputStreamsOption::defaultValue() {
std::stringstream ss; return ov::util::to_string(ov::streams::AUTO);
ss << ov::NumStreams(ov::NumStreams::AUTO);
return ss.str();
} }
OvThroughputStreamsOption::value_type OvThroughputStreamsOption::parse(const std::string& value) { OvThroughputStreamsOption::value_type OvThroughputStreamsOption::parse(const std::string& value) {

View File

@ -126,12 +126,12 @@ TEST(OVClassBasicTest, smoke_SetConfigStreamsNum) {
setGetProperty(value, num_streams); setGetProperty(value, num_streams);
ASSERT_EQ(num_streams, value); ASSERT_EQ(num_streams, value);
num_streams = ov::NumStreams::NUMA; num_streams = ov::streams::NUMA;
setGetProperty(value, num_streams); setGetProperty(value, num_streams);
ASSERT_GT(value, 0); // value has been configured automatically ASSERT_GT(value, 0); // value has been configured automatically
num_streams = ov::NumStreams::AUTO; num_streams = ov::streams::AUTO;
setGetProperty(value, num_streams); setGetProperty(value, num_streams);
ASSERT_GT(value, 0); // value has been configured automatically ASSERT_GT(value, 0); // value has been configured automatically