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())) {
// Use API 2.0 key for streams
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 device
namespace streams {
/**
* @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
/**
@ -642,9 +643,9 @@ struct NumStreams {
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() {
return num;
@ -657,28 +658,37 @@ struct NumStreams {
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 */
inline std::ostream& operator<<(std::ostream& os, const NumStreams& num_streams) {
switch (num_streams.num) {
case NumStreams::AUTO:
inline std::ostream& operator<<(std::ostream& os, const Num& num) {
switch (num.num) {
case Num::AUTO:
return os << "AUTO";
case NumStreams::NUMA:
case Num::NUMA:
return os << "NUMA";
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;
is >> str;
if (str == "AUTO") {
num_streams = {NumStreams::AUTO};
num = AUTO;
} else if (str == "NUMA") {
num_streams = {NumStreams::NUMA};
num = NUMA;
} else {
try {
num_streams = {std::stoi(str)};
num = {std::stoi(str)};
} catch (const std::exception& e) {
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;
}
/** @endcond */
} // namespace streams
/**
* @brief Class to represent number of streams in streams executor
*/
using NumStreams = streams::Num;
/**
* @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

View File

@ -16,6 +16,7 @@
#include "ie_plugin_config.hpp"
#include "ie_system_conf.h"
#include "openvino/runtime/properties.hpp"
#include "openvino/util/common_util.hpp"
namespace InferenceEngine {
IStreamsExecutor::~IStreamsExecutor() {}
@ -108,12 +109,10 @@ void IStreamsExecutor::Config::SetConfig(const std::string& key, const std::stri
_streams = val_i;
}
} else if (key == ov::num_streams) {
ov::NumStreams streams;
std::stringstream strm{value};
strm >> streams;
if (streams.num == ov::NumStreams::NUMA) {
auto streams = ov::util::from_string(value, ov::streams::num);
if (streams == ov::streams::NUMA) {
_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)
_streams = GetDefaultNumStreams();
} 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 ",
ov::num_streams.name(),
". Expected non negative numbers (#streams) or ",
"ov::NumStreams(ov::NumStreams::NUMA|ov::NumStreams::AUTO), Got: ",
"ov::streams::NUMA|ov::streams::AUTO, Got: ",
streams);
}
} 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) {
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();
} else {
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);
} else if (mode_name == CONFIG_VALUE(THROUGHPUT)) {
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
//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() ||
@ -913,7 +913,7 @@ Parameter Plugin::GetMetric(const std::string& name, const std::map<std::string,
} else if (it_streams->second.is<std::string>()) {
std::string n_streams_str = it_streams->second.as<std::string>();
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\"";
}
n_streams = config.GetDefaultNStreamsForThroughputMode();

View File

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

View File

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