7082be18a0cac7f866b548d83d4c2746a1e31302
[platform/upstream/dldt.git] / inference-engine / thirdparty / clDNN / api / CPP / embed.hpp
1 /*
2 // Copyright (c) 2018 Intel Corporation
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //      http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 */
16
17 ///////////////////////////////////////////////////////////////////////////////////////////////////
18 #pragma once
19 #include "../C/embed.h"
20 #include "primitive.hpp"
21 #include <vector>
22
23 namespace cldnn {
24 /// @addtogroup cpp_api C++ API
25 /// @{
26 /// @addtogroup cpp_topology Network Topology
27 /// @{
28 /// @addtogroup cpp_primitives Primitives
29 /// @{
30
31 /// @brief
32 /// @details Performs embedding upon input.
33 /// @n\b Example:
34 /// @n input_size = { 8, 1, 1, 75 };
35 /// @n weights_size = {15, 1, 62, 1 };
36 /// @n output_size = { 8, 75, 15, 1 };
37 /// @par Algorithm:
38 /// @par Where:
39 struct embed : public primitive_base<embed, CLDNN_PRIMITIVE_DESC(embed)> {
40     CLDNN_DECLARE_PRIMITIVE(embed)
41
42     /// @brief Constructs embed primitive.
43     /// @param id This primitive id.
44     /// @param input Input primitive id.
45     /// @param weights Primitive id containing weights data.
46     /// @param bias Primitive id containing bias data.
47     embed(
48         const primitive_id& id,
49         const primitive_id& input,
50         const primitive_id& weights,
51         const primitive_id& bias)
52         : primitive_base(id, {input}), weights(weights), bias(bias) {}
53
54     /// @brief Constructs embed primitive.
55     /// @param id This primitive id.
56     /// @param input Input primitive id.
57     embed(
58         const primitive_id& id,
59         const primitive_id& input,
60         const primitive_id& weights)
61         : primitive_base(id, {input}), weights(weights), bias("") {}
62
63     /// @brief Constructs a copy from C API @CLDNN_PRIMITIVE_DESC{embed}
64     embed(const dto* dto)
65         : primitive_base(dto), weights(dto->weights), bias(dto->bias) {
66     }
67
68     /// @brief Primitive id containing weights data.
69     primitive_id weights;
70     /// @brief Primitive id containing bias data.
71     primitive_id bias;
72
73 protected:
74     std::vector<std::reference_wrapper<const primitive_id>> get_dependencies() const override {
75         if (bias.empty())
76             return {weights};
77         else
78             return {weights, bias};
79     }
80
81     void update_dto(dto& dto) const override {
82         dto.weights = weights.c_str();
83         dto.bias = bias.c_str();
84     }
85 };
86 /// @}
87 /// @}
88 /// @}
89 }  // namespace cldnn
90 #pragma once