Skip to content

Commit

Permalink
Added SetExeNetworkInfo to Plugin API level (openvinotoolkit#5715)
Browse files Browse the repository at this point in the history
  • Loading branch information
ilya-lavrenov authored and rnugmanx committed Aug 26, 2021
1 parent 4835bea commit 416c910
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 41 deletions.
9 changes: 8 additions & 1 deletion inference-engine/include/ie_input_info.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,20 @@ class InputInfo {

/**
* @brief Gets pre-process info for the input
*
* @return A reference to the PreProcessInfo instance that contains pre-process info for this input
*/
PreProcessInfo& getPreProcess() {
return _preProcessInfo;
}

/**
* @brief Gets pre-process info for the input
* @return A reference to the PreProcessInfo instance that contains pre-process info for this input
*/
const PreProcessInfo& getPreProcess() const {
return _preProcessInfo;
}

protected:
/**
* @brief Pre-process info for the input
Expand Down
10 changes: 9 additions & 1 deletion inference-engine/src/auto_plugin/auto_plugin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <vector>
#include <string>
#include <unordered_set>
#include <type_traits>

#include <cpp_interfaces/impl/ie_plugin_internal.hpp>
#include <cpp_interfaces/interface/ie_internal_plugin_config.hpp>
Expand Down Expand Up @@ -62,7 +63,14 @@ class AutoInferencePlugin : public IE::InferencePluginInternal {
if (!executableNetwork) {
IE_THROW() << "Failed to load network by AUTO plugin";
}
return std::make_shared<AutoExecutableNetwork>(executableNetwork);
auto impl = std::make_shared<AutoExecutableNetwork>(executableNetwork);

if (std::is_same<std::string, T>::value) {
SetExeNetworkInfo(impl, executableNetwork->GetInputsInfo(),
executableNetwork->GetOutputsInfo());
}

return impl;
}
};

Expand Down
25 changes: 1 addition & 24 deletions inference-engine/src/multi_device/multi_device_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,33 +142,10 @@ InferenceEngine::Parameter MultiDeviceInferencePlugin::GetMetric(const std::stri
}
}

void MultiDeviceInferencePlugin::SetExeNetworkInfo(InferenceEngine::ExecutableNetworkInternal::Ptr exeNetwork,
const InferenceEngine::ConstInputsDataMap& devInputs,
const InferenceEngine::ConstOutputsDataMap& devOutputs) {
// Set inputs/outputs and pointer to plugin manually here
InputsDataMap _inputs, clonedInputs;
OutputsDataMap _outputs, clonedOutputs;
for (auto& it : devInputs) {
InputInfo::CPtr devData = it.second;
InputInfo::Ptr data = std::make_shared<InputInfo>(*devData);
_inputs[it.first] = data;
}
for (auto& it : devOutputs) {
CDataPtr devData = it.second;
DataPtr data = std::make_shared<Data>(*devData);
_outputs[it.first] = data;
}
copyInputOutputInfo(_inputs, _outputs, clonedInputs, clonedOutputs);
exeNetwork->setNetworkInputs(clonedInputs);
exeNetwork->setNetworkOutputs(clonedOutputs);
exeNetwork->SetPointerToPlugin(shared_from_this());
}

// Is called only when caching is enabled
IExecutableNetworkInternal::Ptr MultiDeviceInferencePlugin::LoadNetwork(const std::string& modelPath,
const std::map<std::string, std::string>& config) {
CNNNetwork network;
return LoadExeNetworkImpl(modelPath, network, config);
return LoadExeNetworkImpl(modelPath, {}, config);
}

ExecutableNetworkInternal::Ptr MultiDeviceInferencePlugin::LoadExeNetworkImpl(const CNNNetwork &network,
Expand Down
4 changes: 0 additions & 4 deletions inference-engine/src/multi_device/multi_device_plugin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@ class MultiDeviceInferencePlugin : public InferenceEngine::InferencePluginIntern
InferenceEngine::ExecutableNetworkInternal::Ptr LoadExeNetworkImpl(const std::string& modelPath,
InferenceEngine::CNNNetwork network,
const std::map<std::string, std::string>& config);

void SetExeNetworkInfo(InferenceEngine::ExecutableNetworkInternal::Ptr exeNetwork,
const InferenceEngine::ConstInputsDataMap& inputs,
const InferenceEngine::ConstOutputsDataMap& outputs);
};

} // namespace MultiDevicePlugin
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class ExecutableNetworkInternal : public IExecutableNetworkInternal {
* @param[in] plugin The plugin
* @note Needed to correctly handle ownership between objects.
*/
void SetPointerToPlugin(const IInferencePlugin::Ptr& plugin) {
virtual void SetPointerToPlugin(const IInferencePlugin::Ptr& plugin) {
_plugin = plugin;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,14 @@ class InferencePluginInternal : public IInferencePlugin {

IExecutableNetworkInternal::Ptr LoadNetwork(const CNNNetwork& network, const std::map<std::string, std::string>& config,
RemoteContext::Ptr context) override {
InputsDataMap networkInputs = network.getInputsInfo(), networkInputsCloned;
OutputsDataMap networkOutputs = network.getOutputsInfo(), networkOutputsCloned;
copyInputOutputInfo(networkInputs, networkOutputs, networkInputsCloned, networkOutputsCloned);

ExecutableNetworkInternal::Ptr impl;
if (nullptr == context) {
impl = LoadExeNetworkImpl(network, config);
} else {
impl = LoadExeNetworkImpl(network, context, config);
}

impl->setNetworkInputs(networkInputsCloned);
impl->setNetworkOutputs(networkOutputsCloned);
impl->SetPointerToPlugin(shared_from_this());
SetExeNetworkInfo(impl, network.getInputsInfo(), network.getOutputsInfo());

return impl;
}
Expand Down Expand Up @@ -216,6 +210,20 @@ class InferencePluginInternal : public IInferencePlugin {
IE_THROW(NotImplemented);
}

template <typename Tinput, typename Toutput>
void SetExeNetworkInfo(const InferenceEngine::ExecutableNetworkInternal::Ptr& exeNetwork,
const std::map<std::string, std::shared_ptr<Tinput> >& inputs,
const std::map<std::string, std::shared_ptr<Toutput> >& outputs) {
// Set inputs/outputs and pointer to plugin manually here
InferenceEngine::InputsDataMap clonedInputs;
InferenceEngine::OutputsDataMap clonedOutputs;
copyInputOutputInfo(inputs, outputs, clonedInputs, clonedOutputs);

exeNetwork->setNetworkInputs(clonedInputs);
exeNetwork->setNetworkOutputs(clonedOutputs);
exeNetwork->SetPointerToPlugin(shared_from_this());
}

std::string _pluginName; //!< A device name that plugins enables
std::map<std::string, std::string> _config; //!< A map config keys -> values
ICore* _core = nullptr; //!< A pointer to ICore interface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class IExecutableNetworkInternal;
* @param[in] from PreProcessInfo to copy from
* @param to PreProcessInfo to copy to
*/
static void copyPreProcess(const PreProcessInfo& from, PreProcessInfo& to) {
inline void copyPreProcess(const PreProcessInfo& from, PreProcessInfo& to) {
to = from;
if (from.getMeanVariant() == MEAN_IMAGE) {
for (size_t i = 0; i < from.getNumberOfChannels(); i++) {
Expand All @@ -54,7 +54,9 @@ static void copyPreProcess(const PreProcessInfo& from, PreProcessInfo& to) {
* @param _networkInputs The network inputs to copy to
* @param _networkOutputs The network outputs to copy to
*/
inline void copyInputOutputInfo(const InputsDataMap & networkInputs, const OutputsDataMap & networkOutputs,
template <typename Tinput, typename Toutput>
inline void copyInputOutputInfo(const std::map<std::string, std::shared_ptr<Tinput> > & networkInputs,
const std::map<std::string, std::shared_ptr<Toutput> > & networkOutputs,
InputsDataMap & _networkInputs, OutputsDataMap & _networkOutputs) {
_networkInputs.clear();
_networkOutputs.clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class MockExecutableNetwork : public ExecutableNetworkInternal {
ExecutableNetworkInternal::Export(networkModel);
}

void SetPointerToPlugin(IInferencePlugin::Ptr plugin) override {
void SetPointerToPlugin(const IInferencePlugin::Ptr& plugin) override {
std::lock_guard<std::mutex> guard(m_pluginMutex);
ExecutableNetworkInternal::SetPointerToPlugin(plugin);
}
Expand Down

0 comments on commit 416c910

Please sign in to comment.