Publishing 2019 R1.1 content and Myriad plugin sources (#162)
[platform/upstream/dldt.git] / inference-engine / src / hetero_plugin / hetero_plugin.cpp
1 // Copyright (C) 2018-2019 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
3 //
4
5 #include "hetero_plugin.h"
6 #include <memory>
7 #include <vector>
8 #include "ie_plugin_config.hpp"
9 #include "hetero/hetero_plugin_config.hpp"
10 #include <cpp_interfaces/base/ie_plugin_base.hpp>
11 #include "hetero_plugin_base.hpp"
12 #include "inference_engine.hpp"
13 #include "hetero_executable_network.h"
14 #include "fallback_policy.h"
15
16 using namespace InferenceEngine;
17 using namespace InferenceEngine::PluginConfigParams;
18 using namespace InferenceEngine::HeteroConfigParams;
19 using namespace HeteroPlugin;
20 using namespace std;
21
22 static Version heteroPluginDescription = {
23         {1, 6},  // plugin API version
24         CI_BUILD_NUMBER,
25         "dliaPlugin"  // plugin description message -
26 };
27
28 void Engine::GetVersion(const Version *&versionInfo)noexcept {
29     versionInfo = &heteroPluginDescription;
30 }
31
32
33 Engine::Engine() {
34     _config[InferenceEngine::PluginConfigParams::KEY_EXCLUSIVE_ASYNC_REQUESTS] = "YES";
35     _config[KEY_HETERO_DUMP_GRAPH_DOT] = NO;
36 }
37
38 InferenceEngine::ExecutableNetworkInternal::Ptr Engine::LoadExeNetworkImpl(InferenceEngine::ICNNNetwork &network,
39                                                                            const std::map<std::string, std::string> &config) {
40     // TODO(amalyshe) do we need here verification of input precisions?
41     std::map<std::string, std::string> tconfig;
42     tconfig = config;
43
44     // we must not override the parameter, but need to copy everything from plugin config
45     for (auto c : _config) {
46         if (tconfig.find(c.first) == tconfig.end()) {
47             tconfig[c.first] = c.second;
48         }
49     }
50
51     return std::make_shared<HeteroExecutableNetwork>(network, tconfig, _extensions, _deviceLoaders, error_listener);
52 }
53
54 void Engine::SetConfig(const std::map<std::string, std::string> &config) {
55     if (_config.find("TARGET_FALLBACK") == _config.end()) {
56         _config["TARGET_FALLBACK"] = "";
57     }
58
59     for (auto &&i : config) {
60         _config[i.first] = i.second;
61     }
62 }
63
64 void Engine::SetDeviceLoader(const std::string &device,
65                              IHeteroDeviceLoader::Ptr pLoader) {
66     _deviceLoaders[device] = pLoader;
67 }
68
69 void Engine::AddExtension(InferenceEngine::IExtensionPtr extension) {
70     _extensions.push_back(extension);
71 }
72
73 void Engine::SetAffinity(InferenceEngine::ICNNNetwork &network,
74                          const std::map<std::string, std::string> &config) {
75     // TODO(amalyshe) config is not used here, talk with RAN why it appeared in initial interface
76     FallbackPolicy fbPolicy(_deviceLoaders, _config[KEY_HETERO_DUMP_GRAPH_DOT]== YES);
77     fbPolicy.init(_config["TARGET_FALLBACK"], config, _extensions);
78     fbPolicy.setAffinity(config, network);
79 }
80
81
82 INFERENCE_PLUGIN_API(StatusCode) CreatePluginEngine(
83         IInferencePlugin *&plugin,
84         ResponseDesc *resp) noexcept {
85     try {
86         plugin = new HeteroPluginBase<Engine>(
87                 {{1, 6}, "heteroPlugin", "heteroPlugin"},
88                 std::make_shared<Engine>());
89         return OK;
90     }
91     catch (std::exception &ex) {
92         return DescriptionBuffer(GENERAL_ERROR, resp) << ex.what();
93     }
94 }
95
96 void Engine::SetLogCallback(IErrorListener &listener) {
97     error_listener = &listener;
98     for (auto& device_loader : _deviceLoaders)
99         device_loader.second->SetLogCallback(*error_listener);
100 }