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_plugin.h"
20 #include "ie_plugin_config.hpp"
21 #include "hetero/hetero_plugin_config.hpp"
22 #include <cpp_interfaces/base/ie_plugin_base.hpp>
23 #include "hetero_plugin_base.hpp"
24 #include "inference_engine.hpp"
25 #include "hetero_executable_network.h"
26 #include "fallback_policy.h"
28 using namespace InferenceEngine;
29 using namespace InferenceEngine::PluginConfigParams;
30 using namespace InferenceEngine::HeteroConfigParams;
31 using namespace HeteroPlugin;
34 static Version heteroPluginDescription = {
35 {1, 6}, // plugin API version
37 "dliaPlugin" // plugin description message -
40 void Engine::GetVersion(const Version *&versionInfo)noexcept {
41 versionInfo = &heteroPluginDescription;
46 _config[InferenceEngine::PluginConfigParams::KEY_EXCLUSIVE_ASYNC_REQUESTS] = "YES";
47 _config[KEY_HETERO_DUMP_GRAPH_DOT] = NO;
50 InferenceEngine::ExecutableNetworkInternal::Ptr Engine::LoadExeNetworkImpl(InferenceEngine::ICNNNetwork &network,
51 const std::map<std::string, std::string> &config) {
52 // TODO(amalyshe) do we need here verification of input precisions?
53 std::map<std::string, std::string> tconfig;
56 // we must not override the parameter, but need to copy everything from plugin config
57 for (auto c : _config) {
58 if (tconfig.find(c.first) == tconfig.end()) {
59 tconfig[c.first] = c.second;
63 return std::make_shared<HeteroExecutableNetwork>(network, tconfig, _extensions, _deviceLoaders, error_listener);
66 void Engine::SetConfig(const std::map<std::string, std::string> &config) {
67 if (_config.find("TARGET_FALLBACK") == _config.end()) {
68 _config["TARGET_FALLBACK"] = "";
71 for (auto &&i : config) {
72 _config[i.first] = i.second;
76 void Engine::SetDeviceLoader(const std::string &device,
77 IHeteroDeviceLoader::Ptr pLoader) {
78 _deviceLoaders[device] = pLoader;
81 void Engine::AddExtension(InferenceEngine::IExtensionPtr extension) {
82 _extensions.push_back(extension);
85 void Engine::SetAffinity(InferenceEngine::ICNNNetwork &network,
86 const std::map<std::string, std::string> &config) {
87 // TODO(amalyshe) config is not used here, talk with RAN why it appeared in initial interface
88 FallbackPolicy fbPolicy(_deviceLoaders, _config[KEY_HETERO_DUMP_GRAPH_DOT]== YES);
89 fbPolicy.init(_config["TARGET_FALLBACK"], config, _extensions);
90 fbPolicy.setAffinity(config, network);
94 INFERENCE_PLUGIN_API(StatusCode) CreatePluginEngine(
95 IInferencePlugin *&plugin,
96 ResponseDesc *resp) noexcept {
98 plugin = new HeteroPluginBase<Engine>(
99 {{1, 6}, "heteroPlugin", "heteroPlugin"},
100 std::make_shared<Engine>());
103 catch (std::exception &ex) {
104 return DescriptionBuffer(GENERAL_ERROR, resp) << ex.what();
108 void Engine::SetLogCallback(IErrorListener &listener) {
109 error_listener = &listener;
110 for (auto& device_loader : _deviceLoaders)
111 device_loader.second->SetLogCallback(*error_listener);