Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / thirdparty / clDNN / api / CPP / reshape.hpp
1 /*
2 // Copyright (c) 2017 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/reshape.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 Changes information about inputs's layout effectively creating new memory which share underlaying buffer
32 /// but is interpreted in a different way (different shape).
33 /// @note reshape primitive is supposed only to reinterpret shape of the memory therefore it's not possible to change
34 /// neither data type nor format of the input buffer and total number of elements in input and output (excluding paddings) must match.
35 /// Please note that there is no guarantee that underlying data will be in proper format if primitive was explicitly added to output list.
36 struct reshape : public primitive_base<reshape, CLDNN_PRIMITIVE_DESC(reshape)>
37 {
38     CLDNN_DECLARE_PRIMITIVE(reshape)
39
40     /// @brief Constructs reshape primitive.
41     /// @param id This primitive id.
42     /// @param input Input primitive id.
43     /// @param output_shape Requested memory shape (excluding padding).
44     /// A dimension could be 0, in this case,  the value is taken from the input tensor.
45     /// At most one dimension of the new shape can be -1. In this case, the value is inferred from the size of the tensor and the remaining dimensions.
46     /// @param output_padding Requested memory padding.
47     reshape(
48         const primitive_id& id,
49         const primitive_id& input,
50         const tensor& output_shape,
51         const padding& output_padding = padding()
52     )
53         : primitive_base(id, { input }, output_padding)
54         , output_shape(output_shape)
55     {
56     }
57
58     /// @brief Constructs a copy from basic C API @CLDNN_PRIMITIVE_DESC{reshape}
59     reshape(const dto* dto)
60         : primitive_base(dto)
61         , output_shape(dto->output_shape)
62     {
63     }
64
65     /// @brief Requested memory shape.
66     tensor output_shape;
67
68 protected:
69     void update_dto(dto& dto) const override
70     {
71         dto.output_shape = output_shape;
72     }
73 };
74
75 /// @}
76 /// @}
77 /// @}
78 }