1 // Copyright (C) 2018 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
7 #include <details/caseless.hpp>
8 #include <ie_parameter.hpp>
9 #include <ie_inetwork.hpp>
16 namespace InferenceEngine {
22 * @brief This structure implements a holder for validators
24 struct ValidatorsHolder {
26 * @brief Caseless map connects type with validator
28 details::caseless_map<std::string, std::function<void(const Layer&)>> validators;
32 * @brief This class implements a builder for IE Layer
34 class INFERENCE_ENGINE_API_CLASS(Layer) {
37 * @brief The constructor creates a Layer builder with layer type and layer name
38 * @param type Layer type
39 * @param name Layer name
41 explicit Layer(const std::string& type, const std::string& name = "");
43 * @brief The constructor creates a Layer builder from shared pointer to ILayer
44 * @param layer shared pointer to ILayer
46 explicit Layer(const ILayer::Ptr& layer);
48 * @brief The constructor creates a Layer builder from shared pointer to constant ILayer
49 * @param layer shared pointer to constant ILayer
51 explicit Layer(const ILayer::CPtr& layer);
53 * @brief The constructor creates a Layer builder with layer ID and layer builder
55 * @param layer layer builder
57 Layer(idx_t id, const Layer& layer);
60 * @brief Returns layer builder ID
66 * @brief Returns a reference to layer type
69 std::string& getType();
71 * @brief Returns a reference to constant layer type
72 * @return constant layer type
74 const std::string& getType() const;
76 * @brief Sets layer type
77 * @param type Layer type
78 * @return Reference to Layer builder
80 Layer& setType(const std::string& type);
83 * @brief Returns a reference to layer name
86 std::string& getName();
88 * @brief Returns a reference to constant layer name
89 * @return constant layer name
91 const std::string& getName() const;
93 * @brief Sets layer name
94 * @param name Layer name
95 * @return Reference to Layer builder
97 Layer& setName(const std::string& name);
100 * @brief Returns layer subgraph
101 * @return shared pointer to INetwork
103 INetwork::Ptr& getGraph();
105 * @brief Returns constant layer subgraph
106 * @return constant shared pointer to INetwork
108 const INetwork::Ptr& getGraph() const;
110 * @brief Sets layer subgraph
111 * @param graph constant shared pointer to INetwork
112 * @return Reference to Layer builder
114 Layer& setGraph(const INetwork::Ptr& graph);
117 * @brief Returns map of parameters
118 * @return map of parameters
120 std::map<std::string, Parameter>& getParameters();
122 * @brief Returns constant map of parameters
123 * @return constant map of parameters
125 const std::map<std::string, Parameter>& getParameters() const;
127 * @brief Sets parameters for layer
128 * @param params constant map of parameters
129 * @return Reference to Layer builder
131 Layer& setParameters(const std::map<std::string, Parameter>& params);
134 * @brief Returns map of internal blobs
135 * @return map of internal blobs
137 std::map<std::string, Blob::CPtr>& getConstantData();
139 * @brief Returns constant map of internal blobs
140 * @return constant map of internal blobs
142 const std::map<std::string, Blob::CPtr>& getConstantData() const;
144 * @brief Sets constant data for layer
145 * @param constData constant map of shared pointers to blobs
146 * @return Reference to Layer builder
148 Layer& setConstantData(const std::map<std::string, Blob::Ptr>& constData);
150 * @brief Sets constant data for layer
151 * @param constData constant map of shared pointers to constant blobs
152 * @return Reference to Layer builder
154 Layer& setConstantData(const std::map<std::string, Blob::CPtr>& constData);
156 * @brief Adds constant data for layer by name
157 * @param name Name of constant data
158 * @param data shared pointer to constant blob
159 * @return Reference to Layer builder
161 Layer& addConstantData(const std::string& name, const Blob::CPtr& data);
164 * @brief Returns vector of input ports
165 * @return Vector of input ports
167 std::vector<Port>& getInputPorts();
169 * @brief Returns constant vector of input ports
170 * @return constant vector of input ports
172 const std::vector<Port>& getInputPorts() const;
174 * @brief Sets input ports
175 * @param ports vector of ports
176 * @return Reference to Layer builder
178 Layer& setInputPorts(const std::vector<Port> &ports);
181 * @brief Returns vector of output ports
182 * @return Vector of output ports
184 std::vector<Port>& getOutputPorts();
186 * @brief Returns constant vector of output ports
187 * @return constant vector of output ports
189 const std::vector<Port>& getOutputPorts() const;
191 * @brief Sets output ports
192 * @param ports vector of ports
193 * @return Reference to Layer builder
195 Layer& setOutputPorts(const std::vector<Port> &ports);
198 * @brief Validates the current builder and generates ILayer object
199 * @return constant shared pointer to ILayer
201 const ILayer::Ptr build() const;
204 * @brief Validates layer builder
206 void validate() const;
209 * @brief Registers a new validator for type
210 * @param type Layer type
211 * @param validator Layer validator
213 static void addValidator(const std::string& type, const std::function<void(const Layer&)>& validator);
220 std::vector<Port> inPorts;
221 std::vector<Port> outPorts;
222 std::map<std::string, Parameter> params;
223 std::map<std::string, Blob::CPtr> constData;
225 static std::shared_ptr<ValidatorsHolder> getValidatorsHolder();
229 * @brief This class registers layer validators
231 class ValidatorRegisterBase {
234 * @brief The constructor registers new layer validator
235 * @param type Layer type
236 * @param validator Layer validator
238 explicit ValidatorRegisterBase(const std::string& type, const std::function<void(const Layer&)>& validator) {
239 InferenceEngine::Builder::Layer::addValidator(type, validator);
243 #define REG_VALIDATOR_FOR(__type, __validator) \
244 static InferenceEngine::Builder::ValidatorRegisterBase _reg_##__type(#__type, __validator)
246 } // namespace Builder
247 } // namespace InferenceEngine