Move CoreImpl to separate file (#15088)

* Move CoreImpl to separate file

* Added new files

* Small fixes

* Moved ov::Core

* Fixed typo

* Moved DeviceIDParser

* Try to fix build
This commit is contained in:
Ilya Churaev authored and GitHub committed 2023-01-13 17:10:09 +04:00
1 parent 1ea2d679df
commit 2d9a51fa6a
6 files changed
+2174 -1908

No files matched your search

+5
View File
@@ -12,6 +12,7 @@ endif()
file (GLOB LIBRARY_SRC
${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/cpp/*.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/dev/*.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/threading/*.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/cpp/*.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/cpp_interfaces/interface/*.cpp
@@ -113,6 +114,10 @@ file(GLOB_RECURSE plugin_api_src "${CMAKE_CURRENT_SOURCE_DIR}/dev_api/*.hpp"
add_clang_format_target(${TARGET_NAME}_plugin_api_clang FOR_SOURCES ${plugin_api_src})
ov_ncc_naming_style(FOR_TARGET ${TARGET_NAME}_plugin_api
SOURCE_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/dev_api/openvino"
ADDITIONAL_INCLUDE_DIRECTORIES $<TARGET_PROPERTY:ngraph,INTERFACE_INCLUDE_DIRECTORIES>)
# Create object library
add_library(${TARGET_NAME}_obj OBJECT
+283
View File
@@ -0,0 +1,283 @@
// Copyright (C) 2018-2022 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include "openvino/runtime/core.hpp"
#include "any_copy.hpp"
#include "cnn_network_ngraph_impl.hpp"
#include "cpp/ie_plugin.hpp"
#include "dev/core_impl.hpp"
#include "ie_itt.hpp"
#include "so_extension.hpp"
#ifdef OPENVINO_STATIC_LIBRARY
# include "ie_plugins.hpp"
#endif
namespace ov {
#define OV_CORE_CALL_STATEMENT(...) \
try { \
__VA_ARGS__; \
} catch (const std::exception& ex) { \
throw ov::Exception(ex.what()); \
} catch (...) { \
OPENVINO_ASSERT(false, "Unexpected exception"); \
}
class Core::Impl : public CoreImpl {
public:
Impl() : ov::CoreImpl(true) {}
};
Core::Core(const std::string& xmlConfigFile) {
_impl = std::make_shared<Impl>();
#ifdef OPENVINO_STATIC_LIBRARY
_impl->RegisterPluginsInRegistry(::getStaticPluginsRegistry());
#else
register_plugins(findPluginXML(xmlConfigFile));
#endif
}
std::map<std::string, Version> Core::get_versions(const std::string& deviceName) const {
OV_CORE_CALL_STATEMENT({
std::map<std::string, Version> versions;
for (auto&& kvp : _impl->GetVersions(deviceName)) {
versions[kvp.first] = Version{kvp.second.buildNumber, kvp.second.description};
}
return versions;
})
}
#ifdef OPENVINO_ENABLE_UNICODE_PATH_SUPPORT
std::shared_ptr<ov::Model> Core::read_model(const std::wstring& modelPath, const std::wstring& binPath) const {
OV_CORE_CALL_STATEMENT(
return _impl->ReadNetwork(ov::util::wstring_to_string(modelPath), ov::util::wstring_to_string(binPath))
.getFunction(););
}
#endif
std::shared_ptr<ov::Model> Core::read_model(const std::string& modelPath, const std::string& binPath) const {
OV_CORE_CALL_STATEMENT(return _impl->ReadNetwork(modelPath, binPath).getFunction(););
}
std::shared_ptr<ov::Model> Core::read_model(const std::string& model, const ov::Tensor& weights) const {
InferenceEngine::Blob::Ptr blob;
if (weights) {
blob = weights._impl;
}
OV_CORE_CALL_STATEMENT(return _impl->ReadNetwork(model, blob).getFunction(););
}
namespace {
ie::CNNNetwork toCNN(const std::shared_ptr<const ngraph::Function>& model) {
return ie::CNNNetwork(
std::make_shared<ie::details::CNNNetworkNGraphImpl>(std::const_pointer_cast<ngraph::Function>(model),
std::vector<ie::IExtensionPtr>{},
true));
}
} // namespace
CompiledModel Core::compile_model(const std::shared_ptr<const ov::Model>& model, const AnyMap& config) {
return compile_model(model, ov::DEFAULT_DEVICE_NAME, config);
}
CompiledModel Core::compile_model(const std::shared_ptr<const ov::Model>& model,
const std::string& deviceName,
const AnyMap& config) {
OV_CORE_CALL_STATEMENT({
auto exec = _impl->LoadNetwork(toCNN(model), deviceName, any_copy(flatten_sub_properties(deviceName, config)));
return {exec._ptr, exec._so};
});
}
CompiledModel Core::compile_model(const std::string& modelPath, const AnyMap& config) {
return compile_model(modelPath, ov::DEFAULT_DEVICE_NAME, config);
}
CompiledModel Core::compile_model(const std::string& modelPath, const std::string& deviceName, const AnyMap& config) {
OV_CORE_CALL_STATEMENT({
auto exec = _impl->LoadNetwork(modelPath, deviceName, any_copy(flatten_sub_properties(deviceName, config)));
return {exec._ptr, exec._so};
});
}
CompiledModel Core::compile_model(const std::string& model,
const ov::Tensor& weights,
const std::string& deviceName,
const AnyMap& config) {
InferenceEngine::Blob::Ptr blob;
if (weights) {
blob = weights._impl;
}
OV_CORE_CALL_STATEMENT({
auto exec = _impl->LoadNetwork(model, blob, deviceName, any_copy(flatten_sub_properties(deviceName, config)));
return {exec._ptr, exec._so};
});
}
CompiledModel Core::compile_model(const std::shared_ptr<const ov::Model>& model,
const RemoteContext& context,
const AnyMap& config) {
OV_CORE_CALL_STATEMENT({
auto exec = _impl->LoadNetwork(toCNN(model),
context._impl,
any_copy(flatten_sub_properties(context.get_device_name(), config)));
return {exec._ptr, exec._so};
});
}
void Core::add_extension(const ie::IExtensionPtr& extension) {
OV_CORE_CALL_STATEMENT(_impl->AddExtension(extension););
}
void Core::add_extension(const std::string& library_path) {
try {
add_extension(ov::detail::load_extensions(library_path));
} catch (const std::runtime_error&) {
try {
// Try to load legacy extension
const auto extension_ptr = std::make_shared<InferenceEngine::Extension>(library_path);
OPENVINO_SUPPRESS_DEPRECATED_START
add_extension(extension_ptr);
OPENVINO_SUPPRESS_DEPRECATED_END
} catch (const std::runtime_error&) {
throw ov::Exception("Cannot add extension. Cannot find entry point to the extension library");
}
}
}
#ifdef OPENVINO_ENABLE_UNICODE_PATH_SUPPORT
void Core::add_extension(const std::wstring& library_path) {
try {
add_extension(ov::detail::load_extensions(library_path));
} catch (const std::runtime_error&) {
try {
// Try to load legacy extension
const auto extension_ptr = std::make_shared<InferenceEngine::Extension>(library_path);
OPENVINO_SUPPRESS_DEPRECATED_START
add_extension(extension_ptr);
OPENVINO_SUPPRESS_DEPRECATED_END
} catch (const std::runtime_error&) {
throw ov::Exception("Cannot add extension. Cannot find entry point to the extension library");
}
}
}
#endif
void Core::add_extension(const std::shared_ptr<ov::Extension>& extension) {
add_extension(std::vector<std::shared_ptr<ov::Extension>>{extension});
}
void Core::add_extension(const std::vector<std::shared_ptr<ov::Extension>>& extensions) {
OV_CORE_CALL_STATEMENT({ _impl->AddOVExtensions(extensions); });
}
CompiledModel Core::import_model(std::istream& modelStream, const std::string& deviceName, const AnyMap& config) {
OV_ITT_SCOPED_TASK(ov::itt::domains::IE, "Core::import_model");
OV_CORE_CALL_STATEMENT({
auto exec = _impl->ImportNetwork(modelStream, deviceName, any_copy(flatten_sub_properties(deviceName, config)));
return {exec._ptr, exec._so};
});
}
CompiledModel Core::import_model(std::istream& modelStream, const RemoteContext& context, const AnyMap& config) {
OV_ITT_SCOPED_TASK(ov::itt::domains::IE, "Core::import_model");
using ExportMagic = std::array<char, 4>;
constexpr static const ExportMagic exportMagic = {{0x1, 0xE, 0xE, 0x1}};
std::string deviceName;
ExportMagic magic = {};
auto currentPos = modelStream.tellg();
modelStream.read(magic.data(), magic.size());
if (exportMagic == magic) {
std::getline(modelStream, deviceName);
} else {
OPENVINO_ASSERT(false,
"Passed compiled stream does not contain device name. "
"Please, provide device name manually");
}
modelStream.seekg(currentPos, modelStream.beg);
OV_CORE_CALL_STATEMENT({
auto exec = _impl->GetCPPPluginByName(deviceName).import_model(modelStream, {});
return {exec._ptr, exec._so};
});
}
SupportedOpsMap Core::query_model(const std::shared_ptr<const ov::Model>& model,
const std::string& deviceName,
const AnyMap& config) const {
OV_CORE_CALL_STATEMENT({
auto qnResult =
_impl->QueryNetwork(toCNN(model), deviceName, any_copy(flatten_sub_properties(deviceName, config)));
return qnResult.supportedLayersMap;
});
}
void Core::set_property(const AnyMap& properties) {
OV_CORE_CALL_STATEMENT(return _impl->set_property({}, properties););
}
void Core::set_property(const std::string& device_name, const AnyMap& properties) {
OV_CORE_CALL_STATEMENT(return _impl->set_property(device_name, properties););
}
Any Core::get_property(const std::string& deviceName, const std::string& name) const {
OV_CORE_CALL_STATEMENT(return _impl->get_property(deviceName, name, {}););
}
Any Core::get_property(const std::string& deviceName, const std::string& name, const AnyMap& arguments) const {
OV_CORE_CALL_STATEMENT(return _impl->get_property(deviceName, name, arguments););
}
std::vector<std::string> Core::get_available_devices() const {
OV_CORE_CALL_STATEMENT(return _impl->GetAvailableDevices(););
}
void Core::register_plugin(const std::string& pluginName, const std::string& deviceName) {
OV_CORE_CALL_STATEMENT(_impl->RegisterPluginByName(pluginName, deviceName););
}
void Core::unload_plugin(const std::string& deviceName) {
OV_CORE_CALL_STATEMENT({
ie::DeviceIDParser parser(deviceName);
std::string devName = parser.getDeviceName();
_impl->UnloadPluginByName(devName);
});
}
void Core::register_plugins(const std::string& xmlConfigFile) {
OV_CORE_CALL_STATEMENT(_impl->RegisterPluginsInRegistry(xmlConfigFile););
}
RemoteContext Core::create_context(const std::string& deviceName, const AnyMap& params) {
OPENVINO_ASSERT(deviceName.find("HETERO") != 0, "HETERO device does not support remote context");
OPENVINO_ASSERT(deviceName.find("MULTI") != 0, "MULTI device does not support remote context");
OPENVINO_ASSERT(deviceName.find("AUTO") != 0, "AUTO device does not support remote context");
OPENVINO_ASSERT(deviceName.find("BATCH") != 0, "BATCH device does not support remote context");
OV_CORE_CALL_STATEMENT({
auto parsed = parseDeviceNameIntoConfig(deviceName, flatten_sub_properties(deviceName, params));
auto remoteContext = _impl->GetCPPPluginByName(parsed._deviceName).create_context(parsed._config);
return {remoteContext._ptr, {remoteContext._so}};
});
}
RemoteContext Core::get_default_context(const std::string& deviceName) {
OPENVINO_ASSERT(deviceName.find("HETERO") != 0, "HETERO device does not support default remote context");
OPENVINO_ASSERT(deviceName.find("MULTI") != 0, "MULTI device does not support default remote context");
OPENVINO_ASSERT(deviceName.find("AUTO") != 0, "AUTO device does not support default remote context");
OPENVINO_ASSERT(deviceName.find("BATCH") != 0, "BATCH device does not support default remote context");
OV_CORE_CALL_STATEMENT({
auto parsed = parseDeviceNameIntoConfig(deviceName, AnyMap{});
auto remoteContext = _impl->GetCPPPluginByName(parsed._deviceName).get_default_context(parsed._config);
return {remoteContext._ptr, {remoteContext._so}};
});
}
} // namespace ov
File diff suppressed because it is too large. Load diff
+403
View File
@@ -0,0 +1,403 @@
// Copyright (C) 2018-2022 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include <ie_extension.h>
#include "any_copy.hpp"
#include "cpp_interfaces/interface/ie_iplugin_internal.hpp"
#include "ie_cache_guard.hpp"
#include "ie_cache_manager.hpp"
#include "ie_icore.hpp"
#include "multi-device/multi_device_config.hpp"
#include "openvino/core/extension.hpp"
#include "openvino/core/version.hpp"
#include "openvino/runtime/common.hpp"
#include "threading/ie_executor_manager.hpp"
#ifdef OPENVINO_STATIC_LIBRARY
# include "ie_plugins.hpp"
#endif
namespace ov {
const std::string DEFAULT_DEVICE_NAME = "DEFAULT_DEVICE";
template <typename T>
struct Parsed {
std::string _deviceName;
std::map<std::string, T> _config;
};
template <typename T = InferenceEngine::Parameter>
ov::Parsed<T> parseDeviceNameIntoConfig(const std::string& deviceName, const std::map<std::string, T>& config = {}) {
auto config_ = config;
auto deviceName_ = deviceName;
if (deviceName_.find("HETERO:") == 0) {
deviceName_ = "HETERO";
config_["TARGET_FALLBACK"] = deviceName.substr(7);
} else if (deviceName_.find("MULTI:") == 0) {
deviceName_ = "MULTI";
config_[InferenceEngine::MultiDeviceConfigParams::KEY_MULTI_DEVICE_PRIORITIES] = deviceName.substr(6);
} else if (deviceName == "AUTO" || deviceName.find("AUTO:") == 0) {
deviceName_ = "AUTO";
if (deviceName.find("AUTO:") == 0) {
config_[InferenceEngine::MultiDeviceConfigParams::KEY_MULTI_DEVICE_PRIORITIES] =
deviceName.substr(std::string("AUTO:").size());
}
} else if (deviceName_.find("BATCH:") == 0) {
deviceName_ = "BATCH";
config_[CONFIG_KEY(AUTO_BATCH_DEVICE_CONFIG)] = deviceName.substr(6);
} else {
InferenceEngine::DeviceIDParser parser(deviceName_);
deviceName_ = parser.getDeviceName();
std::string deviceIDLocal = parser.getDeviceID();
if (!deviceIDLocal.empty()) {
config_[InferenceEngine::PluginConfigParams::KEY_DEVICE_ID] = deviceIDLocal;
}
}
return {deviceName_, config_};
}
#ifndef OPENVINO_STATIC_LIBRARY
std::string findPluginXML(const std::string& xmlFile);
#endif
ov::AnyMap flatten_sub_properties(const std::string& device, const ov::AnyMap& properties);
class CoreImpl : public InferenceEngine::ICore, public std::enable_shared_from_this<InferenceEngine::ICore> {
private:
mutable std::map<std::string, ov::InferencePlugin> plugins;
// Mutex is needed to prevent changes of dev mutexes map from different threads
mutable std::mutex global_mutex;
// Global mutex "" locks parallel access to pluginRegistry and plugins
// Plugin mutexes "plugin_name" lock access to code which changes configuration of particular plugin
mutable std::unordered_map<std::string, std::mutex> dev_mutexes;
std::mutex& get_mutex(const std::string& dev_name = "") const;
void add_mutex(const std::string& dev_name);
class CoreConfig final {
public:
struct CacheConfig {
std::string _cacheDir;
std::shared_ptr<InferenceEngine::ICacheManager> _cacheManager;
};
bool flag_allow_auto_batching = true;
void setAndUpdate(ov::AnyMap& config);
void setCacheForDevice(const std::string& dir, const std::string& name);
std::string get_cache_dir() const;
// Creating thread-safe copy of config including shared_ptr to ICacheManager
// Passing empty or not-existing name will return global cache config
CacheConfig getCacheConfigForDevice(const std::string& device_name,
bool deviceSupportsCacheDir,
std::map<std::string, std::string>& parsedConfig) const;
CacheConfig getCacheConfigForDevice(const std::string& device_name) const;
private:
static void fillConfig(CacheConfig& config, const std::string& dir);
mutable std::mutex _cacheConfigMutex;
CacheConfig _cacheConfig;
std::map<std::string, CacheConfig> _cacheConfigPerDevice;
};
struct CacheContent {
explicit CacheContent(const std::shared_ptr<InferenceEngine::ICacheManager>& cache_manager,
const std::string model_path = {})
: cacheManager(cache_manager),
modelPath(model_path) {}
std::shared_ptr<InferenceEngine::ICacheManager> cacheManager;
std::string blobId = {};
std::string modelPath = {};
};
// Core settings (cache config, etc)
CoreConfig coreConfig;
InferenceEngine::CacheGuard cacheGuard;
struct PluginDescriptor {
ov::util::FilePath libraryLocation;
ov::AnyMap defaultConfig;
std::vector<ov::util::FilePath> listOfExtentions;
InferenceEngine::CreatePluginEngineFunc* pluginCreateFunc = nullptr;
InferenceEngine::CreateExtensionFunc* extensionCreateFunc = nullptr;
PluginDescriptor() = default;
PluginDescriptor(const ov::util::FilePath& libraryLocation,
const ov::AnyMap& defaultConfig = {},
const std::vector<ov::util::FilePath>& listOfExtentions = {}) {
this->libraryLocation = libraryLocation;
this->defaultConfig = defaultConfig;
this->listOfExtentions = listOfExtentions;
}
PluginDescriptor(InferenceEngine::CreatePluginEngineFunc* pluginCreateFunc,
const ov::AnyMap& defaultConfig = {},
InferenceEngine::CreateExtensionFunc* extensionCreateFunc = nullptr) {
this->pluginCreateFunc = pluginCreateFunc;
this->defaultConfig = defaultConfig;
this->extensionCreateFunc = extensionCreateFunc;
}
};
InferenceEngine::ExecutorManager::Ptr executorManagerPtr;
mutable std::unordered_set<std::string> opsetNames;
// TODO: make extensions to be optional with conditional compilation
mutable std::vector<InferenceEngine::IExtensionPtr> extensions;
std::vector<ov::Extension::Ptr> ov_extensions;
std::map<std::string, PluginDescriptor> pluginRegistry;
const bool newAPI;
void AddExtensionUnsafe(const InferenceEngine::IExtensionPtr& extension) const;
template <typename C, typename = FileUtils::enableIfSupportedChar<C>>
void TryToRegisterLibraryAsExtensionUnsafe(const std::basic_string<C>& path) const {
try {
const auto extension_ptr = std::make_shared<InferenceEngine::Extension>(path);
AddExtensionUnsafe(extension_ptr);
} catch (const InferenceEngine::GeneralError&) {
// in case of shared library is not opened
}
}
public:
CoreImpl(bool _newAPI);
~CoreImpl() override = default;
/**
* @brief Register plugins for devices which are located in .xml configuration file.
* @note The function supports UNICODE path
* @param xmlConfigFile An .xml configuraion with device / plugin information
*/
void RegisterPluginsInRegistry(const std::string& xmlConfigFile);
#ifdef OPENVINO_STATIC_LIBRARY
/**
* @brief Register plugins for devices using statically defined configuration
* @note The function supports UNICODE path
* @param static_registry a statically defined configuration with device / plugin information
*/
void RegisterPluginsInRegistry(const decltype(::getStaticPluginsRegistry())& static_registry) {
std::lock_guard<std::mutex> lock(get_mutex());
for (const auto& plugin : static_registry) {
const auto& deviceName = plugin.first;
if (deviceName.find('.') != std::string::npos) {
IE_THROW() << "Device name must not contain dot '.' symbol";
}
const auto& value = plugin.second;
ov::AnyMap config = any_copy(value.m_default_config);
PluginDescriptor desc{value.m_create_plugin_func, config, value.m_create_extension_func};
pluginRegistry[deviceName] = desc;
add_mutex(deviceName);
}
}
#endif
//
// ICore public API
//
InferenceEngine::CNNNetwork ReadNetwork(const std::string& modelPath, const std::string& binPath) const override;
InferenceEngine::CNNNetwork ReadNetwork(const std::string& model,
const InferenceEngine::Blob::CPtr& weights,
bool frontendMode = false) const override;
bool isNewAPI() const override;
static std::tuple<bool, std::string> CheckStatic(const InferenceEngine::CNNNetwork& network);
InferenceEngine::RemoteContext::Ptr GetDefaultContext(const std::string& deviceName) override;
ov::SoPtr<InferenceEngine::IExecutableNetworkInternal> LoadNetwork(
const InferenceEngine::CNNNetwork& network,
const std::shared_ptr<InferenceEngine::RemoteContext>& context,
const std::map<std::string, std::string>& config) override;
void ApplyAutoBatching(const InferenceEngine::CNNNetwork& network,
std::string& deviceName,
std::map<std::string, std::string>& config);
void CleanUpProperties(std::string& deviceName, std::map<std::string, std::string>& config, ov::Any property);
InferenceEngine::SoExecutableNetworkInternal LoadNetwork(const InferenceEngine::CNNNetwork& network,
const std::string& deviceNameOrig,
const std::map<std::string, std::string>& config) override;
InferenceEngine::SoExecutableNetworkInternal LoadNetwork(
const std::string& modelPath,
const std::string& deviceName,
const std::map<std::string, std::string>& config,
const std::function<void(const InferenceEngine::CNNNetwork&)>& val = nullptr) override;
InferenceEngine::SoExecutableNetworkInternal LoadNetwork(
const std::string& modelStr,
const InferenceEngine::Blob::CPtr& weights,
const std::string& deviceName,
const std::map<std::string, std::string>& config,
const std::function<void(const InferenceEngine::CNNNetwork&)>& val = nullptr) override;
InferenceEngine::SoExecutableNetworkInternal ImportNetwork(
std::istream& networkModel,
const std::string& deviceName,
const std::map<std::string, std::string>& config) override;
InferenceEngine::QueryNetworkResult QueryNetwork(const InferenceEngine::CNNNetwork& network,
const std::string& deviceName,
const std::map<std::string, std::string>& config) const override;
Any GetMetric(const std::string& deviceName, const std::string& name, const AnyMap& options = {}) const override;
void set_property(const std::string& device_name, const AnyMap& properties) override;
Any get_property_for_core(const std::string& name) const;
Any get_property(const std::string& device_name, const std::string& name, const AnyMap& arguments) const override;
Any GetConfig(const std::string& deviceName, const std::string& name) const override;
/**
* @brief Returns devices available for neural networks inference
*
* @return A vector of devices. The devices are returned as { CPU, GPU.0, GPU.1, MYRIAD }
* If there more than one device of specific type, they are enumerated with .# suffix.
*/
std::vector<std::string> GetAvailableDevices() const override;
/**
* @brief Create a new shared context object on specified accelerator device
* using specified plugin-specific low level device API parameters (device handle, pointer, etc.)
* @param deviceName Name of a device to create new shared context on.
* @param params Map of device-specific shared context parameters.
* @return A shared pointer to a created remote context.
*/
InferenceEngine::RemoteContext::Ptr CreateContext(const std::string& deviceName,
const InferenceEngine::ParamMap& params) override;
/**
* @brief Returns reference to CPP plugin wrapper by a device name
* @param deviceName A name of device
* @return Reference to a CPP plugin wrapper
*/
ov::InferencePlugin GetCPPPluginByName(const std::string& pluginName) const;
/**
* @brief Unload plugin for specified device, but plugin meta-data is still in plugin registry
* @param deviceName A name of device
*/
void UnloadPluginByName(const std::string& deviceName);
/**
* @brief Registers plugin meta-data in registry for specified device
* @param deviceName A name of device
*/
void RegisterPluginByName(const std::string& pluginName, const std::string& deviceName);
/**
* @brief Provides a list of plugin names in registry; physically such plugins may not be created
* @return A list of plugin names
*/
std::vector<std::string> GetListOfDevicesInRegistry() const;
/**
* @brief Sets config values for a plugin or set of plugins
* @param deviceName A device name to set config to
* If empty, config is set for all the plugins / plugin's meta-data
* @note `deviceName` is not allowed in form of MULTI:CPU, HETERO:GPU,CPU, AUTO:CPU
* just simple forms like CPU, GPU, MULTI, GPU.0, etc
*/
void SetConfigForPlugins(const ov::AnyMap& configMap, const std::string& deviceName);
/**
* @brief Get device config it is passed as pair of device_name and `AnyMap`
* @param configs All set of configs
* @note `device_name` is not allowed in form of MULTI:CPU, HETERO:GPU,CPU, AUTO:CPU
* just simple forms like CPU, GPU, MULTI, GPU.0, etc
*/
void ExtractAndSetDeviceConfig(const ov::AnyMap& configs);
std::map<std::string, std::string> GetSupportedConfig(const std::string& deviceName,
const std::map<std::string, std::string>& configs) override;
/**
* @brief Registers the extension in a Core object
* Such extensions can be used for both CNNNetwork readers and device plugins
*/
void AddExtension(const InferenceEngine::IExtensionPtr& extension);
void AddOVExtensions(const std::vector<ov::Extension::Ptr>& extensions);
/**
* @brief Provides a list of extensions
* @return A list of registered extensions
*/
const std::vector<InferenceEngine::IExtensionPtr>& GetExtensions() const;
const std::vector<ov::Extension::Ptr>& GetOVExtensions() const;
std::map<std::string, InferenceEngine::Version> GetVersions(const std::string& deviceName) const;
bool DeviceSupportsImportExport(const std::string& deviceName) const override;
bool DeviceSupportsConfigKey(const ov::InferencePlugin& plugin, const std::string& key) const;
bool DeviceSupportsImportExport(const ov::InferencePlugin& plugin) const;
bool DeviceSupportsCacheDir(const ov::InferencePlugin& plugin) const;
ov::SoPtr<InferenceEngine::IExecutableNetworkInternal> compile_model_impl(
const InferenceEngine::CNNNetwork& network,
ov::InferencePlugin& plugin,
const std::map<std::string, std::string>& parsedConfig,
const InferenceEngine::RemoteContext::Ptr& context,
const CacheContent& cacheContent,
bool forceDisableCache = false);
static ov::SoPtr<InferenceEngine::IExecutableNetworkInternal> LoadNetworkFromCache(
const CacheContent& cacheContent,
ov::InferencePlugin& plugin,
const std::map<std::string, std::string>& config,
const std::shared_ptr<InferenceEngine::RemoteContext>& context,
bool& networkIsImported);
std::map<std::string, std::string> CreateCompileConfig(const ov::InferencePlugin& plugin,
const std::string& deviceFamily,
const std::map<std::string, std::string>& origConfig) const;
std::string CalculateNetworkHash(const InferenceEngine::CNNNetwork& network,
const std::string& deviceFamily,
const ov::InferencePlugin& plugin,
const std::map<std::string, std::string>& config) const;
std::string CalculateFileHash(const std::string& modelName,
const std::string& deviceFamily,
const ov::InferencePlugin& plugin,
const std::map<std::string, std::string>& config) const;
std::string CalculateMemoryHash(const std::string& modelStr,
const ov::Tensor& weights,
const std::string& deviceFamily,
const ov::InferencePlugin& plugin,
const std::map<std::string, std::string>& config) const;
};
} // namespace ov
@@ -0,0 +1,89 @@
// Copyright (C) 2018-2022 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include "ie_icore.hpp"
namespace InferenceEngine {
DeviceIDParser::DeviceIDParser(const std::string& deviceNameWithID) {
deviceName = deviceNameWithID;
auto pos = deviceName.find('.');
if (pos != std::string::npos) {
deviceName = deviceNameWithID.substr(0, pos);
deviceID = deviceNameWithID.substr(pos + 1, deviceNameWithID.size());
}
}
std::string DeviceIDParser::getDeviceID() const {
return deviceID;
}
std::string DeviceIDParser::getDeviceName() const {
return deviceName;
}
std::vector<std::string> DeviceIDParser::getHeteroDevices(std::string fallbackDevice) {
std::vector<std::string> deviceNames;
std::string cdevice;
char delimiter = ',';
size_t pos = 0;
while ((pos = fallbackDevice.find(delimiter)) != std::string::npos) {
deviceNames.push_back(fallbackDevice.substr(0, pos));
fallbackDevice.erase(0, pos + 1);
}
if (!fallbackDevice.empty())
deviceNames.push_back(fallbackDevice);
return deviceNames;
}
std::vector<std::string> DeviceIDParser::getMultiDevices(std::string devicesList) {
std::set<std::string> deviceNames;
auto trim_request_info = [](const std::string& device_with_requests) {
auto opening_bracket = device_with_requests.find_first_of('(');
return device_with_requests.substr(0, opening_bracket);
};
std::string device;
char delimiter = ',';
size_t pos = 0;
// in addition to the list of devices, every device can have a #requests in the brackets e.g. "CPU(100)"
// we skip the #requests info here
while ((pos = devicesList.find(delimiter)) != std::string::npos) {
auto d = devicesList.substr(0, pos);
if (d.find("BATCH") == 0) {
deviceNames.insert("BATCH");
auto p = d.find_first_of(":");
if (p != std::string::npos)
deviceNames.insert(DeviceIDParser::getBatchDevice(d.substr(p + 1)));
} else {
deviceNames.insert(trim_request_info(d));
}
devicesList.erase(0, pos + 1);
}
if (!devicesList.empty()) {
if (devicesList.find("BATCH") == 0) {
deviceNames.insert("BATCH");
auto p = devicesList.find_first_of(":");
if (p != std::string::npos)
deviceNames.insert(DeviceIDParser::getBatchDevice(devicesList.substr(p + 1)));
} else {
deviceNames.insert(trim_request_info(devicesList));
}
}
return std::vector<std::string>(deviceNames.begin(), deviceNames.end());
}
std::string DeviceIDParser::getBatchDevice(std::string device) {
auto trim_request_info = [](const std::string& device_with_requests) {
auto opening_bracket = device_with_requests.find_first_of('(');
return device_with_requests.substr(0, opening_bracket);
};
return trim_request_info(device);
}
} // namespace InferenceEngine
File diff suppressed because it is too large. Load diff