Publishing R3
[platform/upstream/dldt.git] / inference-engine / thirdparty / clDNN / api / CPP / concatenation.hpp
1 /*
2 // Copyright (c) 2016 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/concatenation.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 /// @details Concatenation is used to concatenate multiple sources into one destination along specified dimension.
32 /// @notes 
33 /// - all other dimensions (except the one along which concatenation take place) must have the same value in each source.
34 /// - order of arguments in primitive creation has impact on order of feature maps in output primitive. 
35 /// 
36 /// @par Alogrithm:
37 /// \code
38 ///     int outputIdx = 0
39 ///     for(i : input)
40 ///     {
41 ///         for(f : i.features)
42 ///         {
43 ///             output[outputIdx] = f
44 ///             outputIdx += 1
45 ///         }
46 ///     }
47 /// \endcode
48 /// @par Where: 
49 ///   @li input : data structure holding all source inputs for this primitive
50 ///   @li output : data structure holding output data for this primitive
51 ///   @li i.features : number of features in currently processed input
52 ///   @li outputIdx : index of destination feature 
53 struct concatenation : public primitive_base<concatenation, CLDNN_PRIMITIVE_DESC(concatenation)>
54 {
55     CLDNN_DECLARE_PRIMITIVE(concatenation)
56
57     enum concatenation_axis
58     {
59         along_b = cldnn_concatenation_along_b,
60         along_f = cldnn_concatenation_along_f,
61         along_x = cldnn_concatenation_along_x,
62         along_y = cldnn_concatenation_along_y
63     };
64
65     /// @li Constructs concatenation primitive.
66     /// @param id This primitive id.
67     /// @param input Vector of input primitives ids.
68     /// @param axis Selected dimension for concatenation.
69     concatenation(
70         const primitive_id& id,
71         const std::vector<primitive_id>& input,
72         const concatenation_axis axis,
73         const padding& output_padding = padding()
74     )
75         :primitive_base(id, { input }, output_padding)
76         , axis(axis)
77     {}
78
79     /// @brief Constructs a copy from C API @CLDNN_PRIMITIVE_DESC(depth_concatenate)
80     concatenation(const dto* dto)
81         :primitive_base(dto)
82         , axis(static_cast<concatenation_axis>(dto->axis))
83     {}
84
85     /// @brief Dimension along which concatenation should take place
86     concatenation_axis axis;
87
88 private:
89     void update_dto(dto& dto) const override
90     {
91         dto.axis = static_cast<cldnn_concatenation_axis>(axis);
92     }
93 };
94 /// @}
95 /// @}
96 /// @}
97 }