1 // Copyright (C) 2018-2019 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
7 #include <details/caseless.hpp>
8 #include <ie_parameter.hpp>
9 #include <ie_network.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 std::shared_ptr<const Layer>&, bool)>> validators;
32 * @brief This class implements a builder for IE Layer
34 class INFERENCE_ENGINE_API_CLASS(Layer): public ILayer,
35 public std::enable_shared_from_this<Layer> {
38 * @brief A shared pointer to the Layer builder
40 using Ptr = std::shared_ptr<Layer>;
42 * @brief A shared pointer to the constant Layer builder
44 using CPtr = std::shared_ptr<const Layer>;
47 * @brief The constructor creates a Layer builder with layer type and layer name
48 * @param type Layer type
49 * @param name Layer name
51 explicit Layer(const std::string& type, const std::string& name = "");
53 * @brief The constructor creates a Layer builder from shared pointer to constant ILayer
54 * @param layer shared pointer to constant ILayer
56 explicit Layer(const ILayer::CPtr& layer);
58 * @brief The constructor creates a Layer builder with layer ID and layer builder
60 * @param layer layer builder
62 Layer(idx_t id, const Layer& layer);
65 * @brief Compares the given Layer builder with the current one
66 * @param rhs Layer builder to compare with
67 * @return true if the given Layer builder is equal to the current one, false - otherwise
69 bool operator==(const Layer& rhs) const {
70 return params == rhs.params;
74 * @brief Returns layer ID
77 idx_t getId() const noexcept override;
80 * @brief Returns a constant reference to layer name
83 const std::string& getName() const noexcept override;
85 * @brief Sets layer name
86 * @param name Layer name
87 * @return Reference to Layer builder
89 Layer& setName(const std::string& name);
92 * @brief Returns a constant reference to layer type
95 const std::string& getType() const noexcept override;
97 * @brief Sets layer type
98 * @param type Layer type
99 * @return Reference to Layer builder
101 Layer& setType(const std::string& type);
104 * @brief Returns map of parameters
105 * @return map of parameters
107 const std::map<std::string, Parameter>& getParameters() const noexcept override;
109 * @brief Returns map of parameters
110 * @return map of parameters
112 std::map<std::string, Parameter>& getParameters();
114 * @brief Sets parameters for layer
115 * @param params constant map of parameters
116 * @return Reference to Layer builder
118 Layer& setParameters(const std::map<std::string, Parameter>& params);
121 * @brief Returns vector of input ports
122 * @return Vector of input ports
124 const std::vector<Port>& getInputPorts() const noexcept override;
126 * @brief Returns vector of input ports
127 * @return Vector of input ports
129 std::vector<Port>& getInputPorts();
131 * @brief Sets input ports
132 * @param ports vector of ports
133 * @return Reference to Layer builder
135 Layer& setInputPorts(const std::vector<Port> &ports);
138 * @brief Returns vector of output ports
139 * @return Vector of output ports
141 const std::vector<Port>& getOutputPorts() const noexcept override;
143 * @brief Returns vector of output ports
144 * @return Vector of output ports
146 std::vector<Port>& getOutputPorts();
148 * @brief Sets output ports
149 * @param ports vector of ports
150 * @return Reference to Layer builder
152 Layer& setOutputPorts(const std::vector<Port> &ports);
155 * @brief Validates the current builder and generates ILayer object
156 * @return constant shared pointer to ILayer
158 const ILayer::CPtr build() const;
161 * @brief Validates layer builder
163 void validate(bool partial = false) const;
166 * @brief Registers a new validator for type
167 * @param type Layer type
168 * @param validator Layer validator
170 static void addValidator(const std::string& type, const std::function<void(const Layer::CPtr&, bool)>& validator);
176 std::vector<Port> inPorts;
177 std::vector<Port> outPorts;
178 std::map<std::string, Parameter> params;
179 static std::shared_ptr<ValidatorsHolder> getValidatorsHolder();
183 * @brief This class registers layer validators
185 class ValidatorRegisterBase {
188 * @brief The constructor registers new layer validator
189 * @param type Layer type
190 * @param validator Layer validator
192 explicit ValidatorRegisterBase(const std::string& type, const std::function<void(const Layer::CPtr&, bool)>& validator) {
193 InferenceEngine::Builder::Layer::addValidator(type, validator);
197 #define REG_VALIDATOR_FOR(__type, __validator) \
198 static InferenceEngine::Builder::ValidatorRegisterBase _reg_##__type(#__type, __validator)
200 } // namespace Builder
201 } // namespace InferenceEngine