ie_ihetero_plugin.hpp
Go to the documentation of this file.
1 // Copyright (C) 2018-2019 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
3 //
4 
5 /**
6  * @brief A header file that provides interface to register custom hetero functionality
7  * @file ie_ihetero_plugin.hpp
8  */
9 #pragma once
10 #include <map>
11 #include <string>
12 #include <memory>
13 #include <ie_icnn_network.hpp>
15 #include <ie_plugin.hpp>
16 
17 namespace InferenceEngine {
18 
19 /**
20  * This interface describes a mechanism of custom loaders to be used in heterogeneous
21  * plugin during setting of affinity and loading of split sub-network to the plugins
22  * The custom loader can define addition settings for the plugins or network loading
23  * Examples of cases when this interface should be implemented in the application:
24  * 1. add custom layers to existing plugins if it is not pointed to the heterogeneous plugin
25  * or registration of custom layer is different than supported in available public plugins
26  * 2. set affinity manually for the same plugin being initialized by different parameters,
27  * e.g different device id
28  * In this case there will be mapping of
29  * Device1 > HeteroDeviceLoaderImpl1
30  * Device2 > HeteroDeviceLoaderImpl2
31  * the affinity should be pointed manually, the implementation of HeteroDeviceLoaderImpl1 and
32  * HeteroDeviceLoaderImpl2 should be in the application, and these device loaders should be registered
33  * through calling of
34  * IHeteroInferencePlugin::SetDeviceLoader("Device1", HeteroDeviceLoaderImpl1)
35  * IHeteroInferencePlugin::SetDeviceLoader("Device2", HeteroDeviceLoaderImpl2)
36 */
38 public:
39  using Ptr = std::shared_ptr<IHeteroDeviceLoader>;
40  virtual ~IHeteroDeviceLoader() = default;
41 
42  /**
43  * Loads network to the device. The instantiation of plugin should be in the implementation
44  * of the IHeteroDeviceLoader. As well setting of special config option should happen in the
45  * implementation as well
46  * @param device Loading of network should happen for this device
47  * @param ret Reference to a shared ptr of the returned executable network instance
48  * @param network Network object acquired from CNNNetReader
49  * @param config Map of configuration settings relevant only for current load operation
50  * @param resp Pointer to the response message that holds a description of an error if any occurred
51  * @return Status code of the operation. OK if succeeded
52  */
53  virtual StatusCode LoadNetwork(
54  const std::string& device,
56  ICNNNetwork &network,
57  const std::map<std::string, std::string> &config,
58  ResponseDesc *resp) noexcept = 0;
59 
60  /**
61  * @depricated Use the version with config parameter
62  * This function calls plugin function QueryNetwork for the plugin being instantiated
63  * in the implementation of IHeteroDeviceLoader
64  * @param device QueryNetwork will be executed for this device
65  * @param network Network object acquired from CNNNetReader
66  * @param res
67  */
68  virtual void QueryNetwork(const std::string &device,
69  const ICNNNetwork &network,
70  QueryNetworkResult &res) noexcept = 0;
71 
72  /**
73  * This function calls plugin function QueryNetwork for the plugin being instantiated
74  * in the implementation of IHeteroDeviceLoader
75  * @param device QueryNetwork will be executed for this device
76  * @param network Network object acquired from CNNNetReader
77  * @param config Network configuration parameters
78  * @param res
79  */
80  virtual void QueryNetwork(const std::string &device,
81  const ICNNNetwork &network,
82  const std::map<std::string, std::string>& /*config*/,
83  QueryNetworkResult &res) noexcept {
84  QueryNetwork(device, network, res);
85  };
86 
87  virtual void SetLogCallback(IErrorListener &listener) = 0;
88 };
89 
90 using MapDeviceLoaders = std::map<std::string, InferenceEngine::IHeteroDeviceLoader::Ptr>;
91 
92 /**
93  * This interface extends regular plugin interface for heterogeneous case. Not all plugins
94  * implements it. The main purpose of this interface - to register loaders and have an ability
95  * to get default settings for affinity on certain devices.
96  */
98 public:
99  /**
100  * Registers device loader for the device
101  * @param device - the device name being used in CNNNLayer::affinity
102  * @param loader - helper class allowing to analyze if layers are supported and allow
103  * to load network to the plugin being defined in the IHeteroDeviceLoader implementation
104  */
105  virtual void SetDeviceLoader(const std::string &device, IHeteroDeviceLoader::Ptr loader) noexcept = 0;
106 
107  /**
108  * The main goal of this function to set affinity according to the options set for the plugin\
109  * implementing IHeteroInferencePlugin.
110  * This function works only if all affinity in the network are empty.
111  * @param network Network object acquired from CNNNetReader
112  * @param config Map of configuration settings
113  * @param resp Pointer to the response message that holds a description of an error if any occurred
114  * @return Status code of the operation. OK if succeeded
115  */
116  virtual StatusCode SetAffinity(
117  ICNNNetwork& network,
118  const std::map<std::string, std::string> &config,
119  ResponseDesc *resp) noexcept = 0;
120 };
121 
122 } // namespace InferenceEngine
Definition: ie_argmax_layer.hpp:11
a header file for IExecutableNetwork interface
A header file for Main Inference Engine API.
StatusCode
This enum contains codes for all possible return values of the interface functions.
Definition: ie_common.h:175
This is a header file for the ICNNNetwork class.
virtual void QueryNetwork(const std::string &device, const ICNNNetwork &network, QueryNetworkResult &res) noexcept=0
virtual void QueryNetwork(const std::string &device, const ICNNNetwork &network, const std::map< std::string, std::string > &, QueryNetworkResult &res) noexcept
Definition: ie_ihetero_plugin.hpp:80
Definition: ie_ihetero_plugin.hpp:37
Definition: ie_ihetero_plugin.hpp:97
Represents detailed information for an error.
Definition: ie_common.h:198
virtual StatusCode LoadNetwork(const std::string &device, IExecutableNetwork::Ptr &ret, ICNNNetwork &network, const std::map< std::string, std::string > &config, ResponseDesc *resp) noexcept=0
This class is a main plugin interface.
Definition: ie_plugin.hpp:55
This is the main interface to describe the NN topology.
Definition: ie_icnn_network.hpp:35
This class represents a custom error listener. Plugin consumers can provide it via InferenceEngine::S...
Definition: ie_error.hpp:16
std::shared_ptr< IExecutableNetwork > Ptr
A smart pointer to the current IExecutableNetwork object.
Definition: ie_iexecutable_network.hpp:37
Responce structure encapsulating information about supported layer.
Definition: ie_plugin.hpp:46