2 // Copyright (C) 2018-2019 Intel Corporation.
4 // This software and the related documents are Intel copyrighted materials,
5 // and your use of them is governed by the express license under which they
6 // were provided to you (End User License Agreement for the Intel(R) Software
7 // Development Products (Version May 2017)). Unless the License provides
8 // otherwise, you may not use, modify, copy, publish, distribute, disclose or
9 // transmit this software or the related documents without Intel's prior
10 // written permission.
12 // This software and the related documents are provided as is, with no
13 // express or implied warranties, other than those that are expressly
14 // stated in the License.
17 #include "hetero_device_loader.h"
18 #include "ie_plugin_dispatcher.hpp"
23 #include <ie_plugin_config.hpp>
25 using namespace InferenceEngine;
27 StatusCode HeteroDeviceLoader::LoadNetwork(
28 const std::string &device,
29 IExecutableNetwork::Ptr &ret,
31 const std::map<std::string, std::string> &config,
32 ResponseDesc *resp) noexcept {
33 if (device != _deviceId) {
35 std::string msg("Current HeteroDeviceLoader doesn't support device passed to LoadNetwork");
36 snprintf(resp->msg, msg.size(), "%s", msg.c_str());
38 return NETWORK_NOT_LOADED;
41 return NETWORK_NOT_LOADED;
43 // preparing local version of configs which are supported by plugins
44 std::map<std::string, std::string> tconfig;
46 for (auto c : config) {
47 std::map<std::string, std::string> oneconfig;
48 oneconfig[c.first] = c.second;
49 InferenceEngine::ResponseDesc response;
50 if (_plugin->SetConfig(oneconfig, &response) == OK) {
51 tconfig[c.first] = c.second;
55 return _plugin->LoadNetwork(ret, network, tconfig, resp);
58 void HeteroDeviceLoader::QueryNetwork(const std::string &device,
59 const ICNNNetwork &network,
60 QueryNetworkResult &res) noexcept {
61 QueryNetwork(device, network, {}, res);
64 void HeteroDeviceLoader::QueryNetwork(const std::string &device,
65 const ICNNNetwork &network,
66 const std::map<std::string, std::string>& config,
67 QueryNetworkResult &res) noexcept {
68 if (device != _deviceId) {
69 res.rc = GENERAL_ERROR;
70 std::string msg("Current HeteroDeviceLoader doesn't support device passed to QueryNetwork");
71 snprintf(res.resp.msg, msg.size(), "%s", msg.c_str());
75 res.rc = GENERAL_ERROR;
76 std::string msg("No plugin, cannot execute QueryNetwork");
77 snprintf(res.resp.msg, msg.size(), "%s", msg.c_str());
80 _plugin->QueryNetwork(network, config, res);
83 HeteroDeviceLoader::HeteroDeviceLoader(const std::string& deviceId) {
85 // try to create plugin
86 PluginDispatcher dispatcher({ "" });
87 _plugin = dispatcher.getPluginByDevice(_deviceId);
90 void HeteroDeviceLoader::initConfigs(const std::map<std::string, std::string> &config,
91 const std::vector<InferenceEngine::IExtensionPtr> &extensions) {
93 if (_deviceId == "CPU") {
94 for (auto &&ext : extensions) {
95 _plugin->AddExtension(ext, nullptr);
98 auto copyConfig = config;
99 // preparing local version of configs which are supported by plugins
100 for (auto c : copyConfig) {
101 std::map<std::string, std::string> oneconfig;
102 oneconfig[c.first] = c.second;
104 _plugin->SetConfig(oneconfig, nullptr);
105 } catch (InferenceEngine::details::InferenceEngineException &e) {
111 void HeteroDeviceLoader::SetLogCallback(IErrorListener &listener) {
112 _plugin->SetLogCallback(listener);