1 // Copyright (C) 2018-2019 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
5 #include "hetero_plugin.h"
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"
16 using namespace InferenceEngine;
17 using namespace InferenceEngine::PluginConfigParams;
18 using namespace InferenceEngine::HeteroConfigParams;
19 using namespace HeteroPlugin;
22 static Version heteroPluginDescription = {
23 {1, 6}, // plugin API version
25 "dliaPlugin" // plugin description message -
28 void Engine::GetVersion(const Version *&versionInfo)noexcept {
29 versionInfo = &heteroPluginDescription;
34 _config[InferenceEngine::PluginConfigParams::KEY_EXCLUSIVE_ASYNC_REQUESTS] = "YES";
35 _config[KEY_HETERO_DUMP_GRAPH_DOT] = NO;
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;
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;
51 return std::make_shared<HeteroExecutableNetwork>(network, tconfig, _extensions, _deviceLoaders, error_listener);
54 void Engine::SetConfig(const std::map<std::string, std::string> &config) {
55 if (_config.find("TARGET_FALLBACK") == _config.end()) {
56 _config["TARGET_FALLBACK"] = "";
59 for (auto &&i : config) {
60 _config[i.first] = i.second;
64 void Engine::SetDeviceLoader(const std::string &device,
65 IHeteroDeviceLoader::Ptr pLoader) {
66 _deviceLoaders[device] = pLoader;
69 void Engine::AddExtension(InferenceEngine::IExtensionPtr extension) {
70 _extensions.push_back(extension);
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);
82 INFERENCE_PLUGIN_API(StatusCode) CreatePluginEngine(
83 IInferencePlugin *&plugin,
84 ResponseDesc *resp) noexcept {
86 plugin = new HeteroPluginBase<Engine>(
87 {{1, 6}, "heteroPlugin", "heteroPlugin"},
88 std::make_shared<Engine>());
91 catch (std::exception &ex) {
92 return DescriptionBuffer(GENERAL_ERROR, resp) << ex.what();
96 void Engine::SetLogCallback(IErrorListener &listener) {
97 error_listener = &listener;
98 for (auto& device_loader : _deviceLoaders)
99 device_loader.second->SetLogCallback(*error_listener);