1 // Copyright (c) 2018 Intel Corporation
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 ///////////////////////////////////////////////////////////////////////////////////////////////////
18 #include "../C/border.h"
19 #include "primitive.hpp"
24 /// @addtogroup cpp_api C++ API
26 /// @addtogroup cpp_topology Network Topology
28 /// @addtogroup cpp_primitives Primitives
31 /// @brief Type of border that will be added to the input by border layer / primitive.
32 enum class border_type : std::int32_t
34 /// @brief All points in the border are set to constant value.
35 constant = cldnn_border_constant,
36 zero = cldnn_border_zero,
37 /// @brief Border is constructed as an mirror of image (edge is also mirrored).
38 /// @details Size of border in any dimension cannot be larger than size of
39 /// input in the same dimension.
40 mirror = cldnn_border_mirror,
41 /// @brief Border is constructed as an mirror of image (edge is NOT mirrored).
42 /// @details Size of border in any dimension cannot be larger than size of
43 /// input in the same dimension decreased by @c 1.
44 mirror_101 = cldnn_border_mirror_101,
45 /// @brief Border is constructed as an replication of edge.
46 /// @details Size of border in any dimension cannot be larger than size of
47 /// input in the same dimension.
48 edge = cldnn_border_edge
52 /// @brief Adds border around input.
54 /// @details Applies border of specified type around input data. The size of output data is increased
55 /// by @c left_top_sizes and by @right_bottom_sizes.
57 /// @n@b Requirements:
58 /// @n - @c left_top_sizes and @c right_bottom_sizes must be non-negative on all dimensions and compatible
59 /// with size of input (describe the same dimensions).
60 /// @n - For @c border_type equal to @c cldnn_border_mirror, @c left_top_sizes and @c right_bottom_sizes
61 /// must be lower than or equal to size of input on corresponding dimension (for all dimensions)
62 /// @n - For @c border_type equal to @c cldnn_border_mirror_101, @c left_top_sizes and @c right_bottom_sizes
63 /// must be lower than size of input on corresponding dimension (for all dimensions)
64 /// @n Breaking any of this conditions will cause exeption throw.
65 struct border : public primitive_base<border, CLDNN_PRIMITIVE_DESC(border)>
67 CLDNN_DECLARE_PRIMITIVE(border)
69 /// @brief Constructs border primitive / layer.
71 /// @param id An identifier of new primitive.
72 /// @param input An identifier of primitive which is an input for newly created
74 /// @param left_top_sizes Sizes of border that needs to be added from left
75 /// (in X dimension) and from top (in Y dimension).
76 /// @param right_bottom_sizes Sizes of border that needs to be added from right
77 /// (in X dimension) and from bottom (in Y dimension).
78 /// @param type Type of added border.
79 /// @param border_value Value of elements which is used for paddings
80 /// @param output_padding Optional padding for output from primitive.
82 const primitive_id& id,
83 const primitive_id& input,
84 const tensor& left_top_sizes = { 0, 0, 0, 0 },
85 const tensor& right_bottom_sizes = { 0, 0, 0, 0 },
86 const border_type type = border_type::constant,
87 const float border_value = 0.0f,
88 const padding& output_padding = padding()
90 : primitive_base(id, {input}, output_padding),
91 left_top_sizes(left_top_sizes),
92 right_bottom_sizes(right_bottom_sizes),
94 border_value(border_value)
98 /// @brief Constructs border primitive / layer.
100 /// @param id An identifier of new primitive.
101 /// @param input An identifier of primitive which is an input for newly created
102 /// border primitive.
103 /// @param x_y_sizes Sizes of border that needs to be added from left and right
104 /// (in X dimension) and from top and bottom (in Y dimension).
105 /// Created border is simmetric (the same size of border applied
106 /// from both sides of input).
107 /// @param type Type of added border.
108 /// @param output_padding Optional padding for output from primitive.
110 const primitive_id& id,
111 const primitive_id& input,
112 const tensor& x_y_sizes,
113 const border_type type = border_type::constant,
114 const padding& output_padding = padding()
116 : border(id, input, x_y_sizes, x_y_sizes, type, 0.0f, output_padding)
120 /// @brief Constructs a copy from C API @CLDNN_PRIMITIVE_DESC{border}
121 border(const dto* dto)
122 : primitive_base(dto),
123 left_top_sizes(dto->left_top_sizes),
124 right_bottom_sizes(dto->right_bottom_sizes),
125 type(static_cast<border_type>(dto->border_type)),
126 border_value(dto->border_value)
130 /// @brief Sizes of border that needs to be added from left (in X dimension) and from top (in Y dimension).
131 tensor left_top_sizes;
132 /// @brief Sizes of border that needs to be added from right (in X dimension) and from bottom (in Y dimension).
133 tensor right_bottom_sizes;
134 /// @brief Type of border that needs to be added to the input.
136 /// @brief Border value that is used in constant mode.
139 void update_dto(dto& dto) const override
141 dto.left_top_sizes = left_top_sizes;
142 dto.right_bottom_sizes = right_bottom_sizes;
143 dto.border_type = static_cast<cldnn_border_type>(type);
144 dto.border_value = border_value;