519210fec9f1f6a682bab38d7d37d95b3cc86ea3
[platform/upstream/dldt.git] / inference-engine / thirdparty / clDNN / api / C / broadcast.h
1 // Copyright (c) 2019 Intel Corporation
2 //
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
6 //
7 //      http://www.apache.org/licenses/LICENSE-2.0
8 //
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.
14
15 ///////////////////////////////////////////////////////////////////////////////////////////////////
16 #pragma once
17 #include "cldnn.h"
18
19 /// @addtogroup c_api C API
20 /// @{
21 /// @addtogroup c_topology Network Topology
22 /// @{
23 /// @addtogroup c_primitives Primitives
24 /// @{
25
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29
30 /// @brief Broadcasts input to defined by @p broadcast_sizes output. @p broadcast_axes are used to
31 ///        reinterpret input (reshape) inside algorithm.
32 ///
33 /// @details Takes input, reinterpret it according to @p broadcast_axes
34 ///          and copies it to output once or multiple times.
35 /// @n
36 /// @n Simple example with empty @p broadcast_axes. Lets assume that:
37 /// @n      <tt>input_sizes = (in_b, in_f, in_y, in_x)</tt>
38 /// @n      <tt>broadcast_sizes = (bs_b, bs_f, bs_y, bs_x)</tt>
39 /// @n      <tt>broadcast_axes = () - empty</tt>
40 /// @n The input is broadcasted on each dimension where <tt>bs_{dim} > in_{dim}</tt> and <tt>bs_{dim}</tt>
41 ///    is dividable by <tt>in_{dim}</tt> (input is copied <tt>bs_{dim} / in_{dim}</tt> times).
42 ///    The dimensions where <tt>bs_{dim}</tt> is equal to <tt>in_{dim}</tt> remain unchanged.
43 /// @n The resulting output will have sizes equal to @p broadcast_sizes and contains values from
44 ///    input that meet following criteria:
45 /// @n      <tt>output[(b, f, y, x)] = input[(b % in_b, f % in_f, y % in_y, x % in_x)]</tt>
46 /// @n where <tt>(b, f, y, x)</tt> is a position of value in a primitive output.
47 /// @n
48 /// @n More complicated example with non empty @p broadcast_axes. Lets assume that:
49 /// @n      <tt>broadcast_sizes = (bs_b, bs_f, bs_y, bs_x)</tt>
50 /// @n      <tt>broadcast_axes = (2)</tt>
51 /// @n Taking into account broadcast_axes size (=1) primitive's input must be (4 - 1 = 3):
52 /// @n      <tt>primitive input = (1, in_b, in_f, in_x)</tt>
53 /// @n Due to broadcast_axes = (2) primitive will interpret input as:
54 /// @n      <tt>primitive input(internal representation) = (in_b, in_f, 1, in_x)</tt>
55 /// @n Now, you can apply broadcast rules from previous example to modified (reinterpreted)
56 ///    input and output:
57 /// @n      <tt>input_sizes = (in_b, in_f, 1, in_x)</tt>
58 /// @n      <tt>output_shape = (bs_b, bs_f, bs_y, bs_x)</tt>
59 /// @n      <tt>broadcast_axes = () - empty</tt>
60 /// @n
61 /// @n@b Requirements:
62 /// @n - @p broadcast_sizes must be positive on all dimensions.
63 /// @n - @p broadcast_axes size (dimensions count) must be within (inclusive) range
64 ///      0 - 4.
65 /// @n - @p broadcast_axes mustn't have duplicate values.
66 /// @n - Values of @p broadcast_axes must be within (inclusive) range 0 - 3
67 /// @n - @p output_shape must be greater (dividable) than or equal to reinterpreted
68 ///      input on all dimensions.
69 /// @n Breaking any of these conditions will raise an exception.
70 CLDNN_BEGIN_PRIMITIVE_DESC(broadcast)
71 /// @brief Sizes of broadcast. Output size of current primitive will match broadcast sizes (layout type
72 ///        will not change).
73 cldnn_tensor broadcast_sizes;
74 /// @brief Array of axes positions from output shape (0-based, from left to right)
75 ///        along which broadcast should happen.
76 cldnn_uint16_t_arr broadcast_axes;
77
78 CLDNN_END_PRIMITIVE_DESC(broadcast)
79
80 CLDNN_DECLARE_PRIMITIVE_TYPE_ID(broadcast);
81
82 #ifdef __cplusplus
83 }
84 #endif
85
86 /// @}
87 /// @}
88 /// @}
89