Publishing 2019 R1 content
[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
22 namespace cldnn
23 {
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         {
41                 CLDNN_DECLARE_PRIMITIVE(embed)
42
43                         /// @brief Constructs embed primitive.
44                         /// @param id This primitive id.
45                         /// @param input Input primitive id.
46             /// @param weights Primitive id containing weights data.
47             /// @param bias Primitive id containing bias data.
48                 embed(
49                         const primitive_id& id,
50                         const primitive_id& input,
51                         const primitive_id& weights,
52                         const primitive_id& bias
53                         )
54                         : primitive_base(id, { input })
55                         , weights(weights)
56                         , bias(bias)
57                 {}
58
59         /// @brief Constructs embed primitive.
60         /// @param id This primitive id.
61         /// @param input Input primitive id.
62         embed(
63             const primitive_id& id,
64             const primitive_id& input,
65             const primitive_id& weights
66         )
67             : primitive_base(id, { input })
68             , weights(weights)
69             , bias("")
70         {}
71
72                 /// @brief Constructs a copy from C API @CLDNN_PRIMITIVE_DESC{embed}
73                 embed(const dto* dto)
74                         :primitive_base(dto)
75                         , weights(dto->weights)
76                         , bias(dto->bias)
77                 {
78                 }
79
80                 /// @brief Primitive id containing weights data.
81                 primitive_id weights;
82                 /// @brief Primitive id containing bias data.
83                 primitive_id bias;
84
85         protected:
86                 std::vector<std::reference_wrapper<const primitive_id>> get_dependencies() const override
87                 {
88                         if (bias.empty())
89                                 return{ weights };
90                         else
91                                 return{ weights, bias };
92                 }
93
94                 void update_dto(dto& dto) const override
95                 {
96                         dto.weights = weights.c_str();
97                         dto.bias = bias.c_str();
98                 }
99
100         };
101         /// @}
102         /// @}
103         /// @}
104 }
105 #pragma once