summaryrefslogtreecommitdiff
path: root/inference-engine/thirdparty/clDNN/api/CPP/border.hpp
blob: 79c0777fbb424ca7c5ad40aed40c0173e8b1400c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
// Copyright (c) 2018 Intel Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

///////////////////////////////////////////////////////////////////////////////////////////////////
#pragma once

#include "../C/border.h"
#include "primitive.hpp"


namespace cldnn
{
/// @addtogroup cpp_api C++ API
/// @{
/// @addtogroup cpp_topology Network Topology
/// @{
/// @addtogroup cpp_primitives Primitives
/// @{

/// @brief Type of border that will be added to the input by border layer / primitive.
enum class border_type : std::int32_t
{
    /// @brief All points in the border are set to zero.
    zero = cldnn_border_zero,
    /// @brief Border is constructed as an mirror of image (edge is also mirrored).
    /// @details Size of border in any dimension cannot be larger than size of
    ///          input in the same dimension.
    mirror = cldnn_border_mirror,
    /// @brief Border is constructed as an mirror of image (edge is NOT mirrored).
    /// @details Size of border in any dimension cannot be larger than size of
    ///          input in the same dimension decreased by @c 1.
    mirror_101 = cldnn_border_mirror_101
};


/// @brief Adds border around input.
///
/// @details Applies border of specified type around input data. The size of output data is increased
///          by @c left_top_sizes and by @right_bottom_sizes.
/// @n
/// @n@b Requirements:
/// @n - @c left_top_sizes and @c right_bottom_sizes must be non-negative on all dimensions and compatible
///      with size of input (describe the same dimensions).
/// @n - For @c border_type equal to @c cldnn_border_mirror, @c left_top_sizes and @c right_bottom_sizes
///      must be lower than or equal to size of input on corresponding dimension (for all dimensions)
/// @n - For @c border_type equal to @c cldnn_border_mirror_101, @c left_top_sizes and @c right_bottom_sizes
///      must be lower than size of input on corresponding dimension (for all dimensions)
/// @n Breaking any of this conditions will cause exeption throw.
struct border : public primitive_base<border, CLDNN_PRIMITIVE_DESC(border)>
{
    CLDNN_DECLARE_PRIMITIVE(border)

    /// @brief Constructs border primitive / layer.
    ///
    /// @param id                 An identifier of new primitive.
    /// @param input              An identifier of primitive which is an input for newly created
    ///                           border primitive.
    /// @param left_top_sizes     Sizes of border that needs to be added from left
    ///                           (in X dimension) and from top (in Y dimension).
    /// @param right_bottom_sizes Sizes of border that needs to be added from right
    ///                           (in X dimension) and from bottom (in Y dimension).
    /// @param type               Type of added border.
    /// @param output_padding     Optional padding for output from primitive.
    border(
        const primitive_id& id,
        const primitive_id& input,
        const tensor& left_top_sizes     = {0, 0, 0, 0},
        const tensor& right_bottom_sizes = {0, 0, 0, 0},
        const border_type type           = border_type::zero,
        const padding& output_padding    = padding()
    )
        : primitive_base(id, {input}, output_padding),
          left_top_sizes(left_top_sizes),
          right_bottom_sizes(right_bottom_sizes),
          type(type)
    {
    }

    /// @brief Constructs border primitive / layer.
    ///
    /// @param id                 An identifier of new primitive.
    /// @param input              An identifier of primitive which is an input for newly created
    ///                           border primitive.
    /// @param x_y_sizes          Sizes of border that needs to be added from left and right
    ///                           (in X dimension) and from top and bottom (in Y dimension).
    ///                           Created border is simmetric (the same size of border applied
    ///                           from both sides of input).
    /// @param type               Type of added border.
    /// @param output_padding     Optional padding for output from primitive.
    border(
        const primitive_id& id,
        const primitive_id& input,
        const tensor& x_y_sizes,
        const border_type type        = border_type::zero,
        const padding& output_padding = padding()
    )
        : border(id, input, x_y_sizes, x_y_sizes, type, output_padding)
    {
    }

    /// @brief Constructs a copy from C API @CLDNN_PRIMITIVE_DESC{border}
    border(const dto* dto)
        : primitive_base(dto),
          left_top_sizes(dto->left_top_sizes),
          right_bottom_sizes(dto->right_bottom_sizes),
          type(static_cast<border_type>(dto->border_type))
    {
    }

    /// @brief Sizes of border that needs to be added from left (in X dimension) and from top (in Y dimension).
    tensor left_top_sizes;
    /// @brief Sizes of border that needs to be added from right (in X dimension) and from bottom (in Y dimension).
    tensor right_bottom_sizes;
    /// @brief Type of border that needs to be added to the input.
    border_type type;

protected:
    void update_dto(dto& dto) const override
    {
        dto.left_top_sizes     = left_top_sizes;
        dto.right_bottom_sizes = right_bottom_sizes;
        dto.border_type        = static_cast<cldnn_border_type>(type);
    }
};
/// @}
/// @}
/// @}
}