OpenVX Neural Network Extension  7505566
 All Functions Typedefs Enumerations Enumerator Groups Pages
vx_khr_cnn.h
1 /*
2  * Copyright (c) 2012-2016 The Khronos Group Inc.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and/or associated documentation files (the
6  * "Materials"), to deal in the Materials without restriction, including
7  * without limitation the rights to use, copy, modify, merge, publish,
8  * distribute, sublicense, and/or sell copies of the Materials, and to
9  * permit persons to whom the Materials are furnished to do so, subject to
10  * the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included
13  * in all copies or substantial portions of the Materials.
14  *
15  * MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS
16  * KHRONOS STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS
17  * SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT
18  * https://www.khronos.org/registry/
19  *
20  * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
24  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
25  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
26  * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
27  */
28 
29 #ifndef _VX_KHR_CNN_H_
30 #define _VX_KHR_CNN_H_
31 
32 /*!
33  * \file
34  * \brief The Khronos Extension for Deep Convolutional Networks Functions.
35  *
36  * \defgroup group_cnn Extension: Deep Convolutional Networks API
37  * \brief Convolutional Network Nodes.
38  * \defgroup group_tensor Tensor API
39  * \brief The Tensor API for Deep Convolutional Networks Functions.
40  * \details The tensor is a multidimensional opaque object.Since the object have no visibility to the programmer. Vendors can introduce many optimization possibilities.
41  * An example of such optimization can be found in the following article.http://arxiv.org/abs/1510.00149
42 */
43 
44 #define OPENVX_KHR_CNN "vx_khr_cnn"
45 
46 #if defined(OPENVX_CNN_1_0)
47 #undef OPENVX_CNN_1_1
48 #endif
49 
50 #include <VX/vx.h>
51 
52 /*! \brief tensor Data attributes.
53  * \ingroup group_tensor
54  */
56 {
57  /*! \brief Number of dimensions. */
58  VX_TENSOR_NUM_OF_DIMS = VX_ATTRIBUTE_BASE( VX_ID_KHRONOS, VX_TYPE_TENSOR ) + 0x0,
59  /*! \brief Dimension sizes. */
60  VX_TENSOR_DIMS = VX_ATTRIBUTE_BASE( VX_ID_KHRONOS, VX_TYPE_TENSOR ) + 0x1,
61  /*! \brief tensor Data element data type. <tt>vx_type_e</tt> */
62  VX_TENSOR_DATA_TYPE = VX_ATTRIBUTE_BASE( VX_ID_KHRONOS, VX_TYPE_TENSOR ) + 0x2,
63  /*! \brief fixed point position when the input element type is int16. */
64  VX_TENSOR_FIXED_POINT_POS = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_TENSOR) + 0x4
65 };
66 
67 
68 /*! \brief A list of context attributes.
69 * \ingroup group_tensor
70 */
72  /*! \brief tensor Data max num of dimensions supported by HW. */
73  VX_CONTEXT_MAX_TENSOR_DIMENSIONS = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_CONTEXT) + 0x0
74  /*! \brief max accumulation bits supported */
75  VX_CONTEXT_MAX_CONVOLUTIONAL_NETWORK_ACCUMULATION_BITS = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_CONTEXT) + 0x1
76  /*! \brief min accumulation bits supported */
77  VX_CONTEXT_MIN_CONVOLUTIONAL_NETWORK_ACCUMULATION_BITS = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_CONTEXT) + 0x2
78 };
79 
80 
81 /*==============================================================================
82 CONVOLUTIONAL_NETWORK structs and enums
83 =============================================================================*/
84 /*! \brief The multidimensional data object (Tensor).
85  * \see vxCreateTensor
86  * \ingroup group_tensor
87  * \extends vx_reference
88  */
89 typedef struct _vx_tensor_t * vx_tensor;
90 
91 /*! \brief The multi dimensional view data structure.
92 * \details Used to split tensors into several views. Or concatenate several view into one tensor.
93 * \see vxCreateTensorFromView
94 * \ingroup group_tensor
95 */
96 typedef struct _vx_tensor_view_t * vx_tensor_view;
97 
98 /*! \brief The addressing of a tensor view patch structure is used by the Host only
99 * to address elements in a tensor view patch.
100 * \see <tt>\ref vxCopyTensorPatch</tt>
101 * \ingroup group_tensor
102 */
103 typedef struct _vx_tensor_addressing_t * vx_tensor_addressing;
104 
105 /*! \brief The Convolutional Network down scaling size rounding type list.
106 * \details rounding done downscaling, In convolution and pooling functions.
107 * Relevant when input size is even.
108 * \ingroup group_cnn
109 */
111 {
112  /*! \brief floor rounding */
113  VX_CONVOLUTIONAL_NETWORK_DS_SIZE_ROUNDING_FLOOR = VX_ENUM_BASE(VX_ID_KHRONOS, VX_ENUM_CONVOLUTIONAL_NETWORK_ROUNDING_TYPE) + 0x0,
114  /*! \brief ceil rounding */
115  VX_CONVOLUTIONAL_NETWORK_DS_SIZE_ROUNDING_CEILING = VX_ENUM_BASE(VX_ID_KHRONOS, VX_ENUM_CONVOLUTIONAL_NETWORK_ROUNDING_TYPE) + 0x1
116 };
117 
118 
119 /*! \brief The Convolutional Network pooling type list.
120 * \details kind of pooling done in pooling function
121 * \ingroup group_cnn
122 */
124 {
125  /*! \brief max pooling*/
126  VX_CONVOLUTIONAL_NETWORK_POOLING_MAX = VX_ENUM_BASE(VX_ID_KHRONOS, VX_ENUM_CONVOLUTIONAL_NETWORK_POOL_TYPE) + 0x0,
127  /*! \brief average pooling*/
128  VX_CONVOLUTIONAL_NETWORK_POOLING_AVG = VX_ENUM_BASE(VX_ID_KHRONOS, VX_ENUM_CONVOLUTIONAL_NETWORK_POOL_TYPE) + 0x1
129 };
130 
131 
132 /*! \brief The Convolutional Network normalization type list.
133 * \ingroup group_cnn
134 */
136 {
137  /*! \brief normalization is done on same IFM*/
138  VX_CONVOLUTIONAL_NETWORK_NORM_SAME_MAP = VX_ENUM_BASE(VX_ID_KHRONOS, VX_ENUM_CONVOLUTIONAL_NETWORK_NORM_TYPE) + 0x0,
139  /*! \brief Normalization is done across different IFMs*/
140  VX_CONVOLUTIONAL_NETWORK_NORM_ACROSS_MAPS = VX_ENUM_BASE(VX_ID_KHRONOS, VX_ENUM_CONVOLUTIONAL_NETWORK_NORM_TYPE) + 0x1,
141 };
142 
143 
144 
145 /*! \brief The Convolutional Network activation functions list.
146 * \details
147 * <table>
148 * <tr><td> <B>Function name </B> <td> <B>Mathematical definition</B> <td> <B>Parameters</B> <td> <B>Parameters type</B>
149 * <tr><td>logistic <td> \f$f(x)=1/(1+e^{-x}) \f$ <td> <td>
150 * <tr><td>hyperbolic tangent <td> \f$f(x)=a\cdot tanh(b\cdot x) \f$ <td> a,b <td> VX_INT32
151 * <tr><td>relu <td> \f$f(x)=max(0,x)\f$ <td> <td>
152 * <tr><td>bounded relu <td> \f$f(x)=min(a,max(0,x)) \f$ <td> a <td> VX_INT32
153 * <tr><td>soft relu <td> \f$f(x)=log(1+e^{x}) \f$ <td> <td>
154 * <tr><td>abs <td> \f$f(x)=\mid x\mid \f$ <td> <td>
155 * <tr><td>square <td> \f$f(x)= x^2 \f$ <td> <td>
156 * <tr><td>square root <td> \f$f(x)=\sqrt{x} \f$ <td> <td>
157 * <tr><td>linear <td> \f$f(x)=ax+b \f$ <td> a,b <td> VX_INT32
158 * </table>
159 * \ingroup group_cnn
160 */
162 {
163  VX_CONVOLUTIONAL_NETWORK_ACTIVATION_LOGISTIC = VX_ENUM_BASE(VX_ID_KHRONOS, VX_ENUM_CONVOLUTIONAL_NETWORK_ACTIVATION_FUNC) + 0x0,
164  VX_CONVOLUTIONAL_NETWORK_ACTIVATION_HYPERBOLIC_TAN = VX_ENUM_BASE(VX_ID_KHRONOS, VX_ENUM_CONVOLUTIONAL_NETWORK_ACTIVATION_FUNC) + 0x1,
165  VX_CONVOLUTIONAL_NETWORK_ACTIVATION_RELU = VX_ENUM_BASE(VX_ID_KHRONOS, VX_ENUM_CONVOLUTIONAL_NETWORK_ACTIVATION_FUNC) + 0x2,
166  VX_CONVOLUTIONAL_NETWORK_ACTIVATION_BRELU = VX_ENUM_BASE(VX_ID_KHRONOS, VX_ENUM_CONVOLUTIONAL_NETWORK_ACTIVATION_FUNC) + 0x3,
167  VX_CONVOLUTIONAL_NETWORK_ACTIVATION_SOFTRELU = VX_ENUM_BASE(VX_ID_KHRONOS, VX_ENUM_CONVOLUTIONAL_NETWORK_ACTIVATION_FUNC) + 0x4,
168  VX_CONVOLUTIONAL_NETWORK_ACTIVATION_ABS = VX_ENUM_BASE(VX_ID_KHRONOS, VX_ENUM_CONVOLUTIONAL_NETWORK_ACTIVATION_FUNC) + 0x5,
169  VX_CONVOLUTIONAL_NETWORK_ACTIVATION_SQUARE = VX_ENUM_BASE(VX_ID_KHRONOS, VX_ENUM_CONVOLUTIONAL_NETWORK_ACTIVATION_FUNC) + 0x6,
170  VX_CONVOLUTIONAL_NETWORK_ACTIVATION_SQRT = VX_ENUM_BASE(VX_ID_KHRONOS, VX_ENUM_CONVOLUTIONAL_NETWORK_ACTIVATION_FUNC) + 0x7,
171  VX_CONVOLUTIONAL_NETWORK_ACTIVATION_LINEAR = VX_ENUM_BASE(VX_ID_KHRONOS, VX_ENUM_CONVOLUTIONAL_NETWORK_ACTIVATION_FUNC) + 0x8,
172 };
173 
174 /* END CNN types*/
175 
176 /*==============================================================================
177  TENSOR DATA FUNCTIONS
178 =============================================================================*/
179 /*! \brief Creates an opaque reference to a tensor data buffer.
180  * \details Not guaranteed to exist until the <tt>vx_graph</tt> containing it has been verified.
181  * \param [in] context The reference to the implementation context.
182  * \param [in] num_of_dims The number of dimensions.
183  * \param [in] sizes Dimensions sizes in elements.
184  * \param [in] data_format The <tt>vx_type_t</tt> that represents the data type of the tensor data elements.
185  * \param [in] fixed_point_pos Specifies the fixed point position when the input element type is int16, if 0 calculations are performed in integer math
186  * \return A tensor data reference or zero when an error is encountered.
187  * \ingroup group_tensor
188  */
189 VX_API_ENTRY vx_tensor VX_API_CALL vxCreateTensor(vx_context context, vx_uint32 num_of_dims, vx_uint32 *sizes, vx_enum data_format,vx_uint8 fixed_point_pos);
190 
191 /*! \brief Creates an array of images into the multi-dimension data, this can be a adjacent 2D images or not depending on the stride value.
192  * The stride value is representing bytes in the third dimension.
193  * The OpenVX image object that points to a three dimension data and access it as an array of images.
194  * This has to be portion of the third lowest dimension, and the stride correspond to that third dimension.
195  * The returned Object array is an array of images. Where the image data is pointing to a specific memory in the input tensor.
196  * \param [in] tensor The tensor data from which to extract the images. Has to be a 3d tensor.
197  * \param [in] rect Image coordinates within tensor data.
198  * \param [in] array_size Number of images to extract.
199  * \param [in] stride Delta between two images in the array.
200  * \param [in] image_format The requested image format. Should match the tensor data's data type.
201  * \return An array of images pointing to the tensor data's data.
202  * \ingroup group_tensor
203  */
204 VX_API_ENTRY vx_object_array VX_API_CALL vxCreateImageObjectArrayFromTensor(vx_tensor tensor, vx_rectangle_t rect, vx_uint32 array_size, vx_uint32 stride, vx_df_image image_format);
205 
206 /*! \brief Creates a tensor data from another tensor data given a view. This second
207  * reference refers to the data in the original tensor data. Updates to this tensor data
208  * updates the parent tensor data. The view must be defined within the dimensions
209  * of the parent tensor data.
210  * \param [in] tensor The reference to the parent tensor data.
211  * \param [in] view The region of interest of a tensor view. Must contain points
212  * within the parent tensor data dimensions. <tt>\ref vx_tensor_view</tt>
213  * \return The reference to the sub-tensor or zero if the view is invalid.
214  * \ingroup group_tensor
215  */
216 VX_API_ENTRY vx_tensor VX_API_CALL vxCreateTensorFromView(vx_tensor tensor, vx_tensor_view view);
217 
218 /*! \brief Creates an opaque reference to a tensor data buffer with no direct
219  * user access. This function allows setting the tensor data dimensions or data format.
220  * \details Virtual data objects allow users to connect various nodes within a
221  * graph via data references without access to that data, but they also permit the
222  * implementation to take maximum advantage of possible optimizations. Use this
223  * API to create a data reference to link two or more nodes together when the
224  * intermediate data are not required to be accessed by outside entities. This API
225  * in particular allows the user to define the tensor data format of the data without
226  * requiring the exact dimensions. Virtual objects are scoped within the graph
227  * they are declared a part of, and can't be shared outside of this scope.
228  * \param [in] graph The reference to the parent graph.
229  * \param [in] num_of_dims The number of dimensions.
230  * \param [in] sizes Dimensions sizes in elements.
231  * \param [in] data_format The <tt>vx_type_t</tt> that represents the data type of the tensor data elements.
232  * \param [in] fixed_point_pos Specifies the fixed point position when the input element type is int16, if 0 calculations are performed in integer math
233  * \return A tensor data reference or zero when an error is encountered.
234  * \note Passing this reference to <tt>\ref vxCopyTensorPatch</tt> will return an error.
235  * \ingroup group_tensor
236  */
237 VX_API_ENTRY vx_tensor VX_API_CALL vxCreateVirtualTensor(vx_graph graph, vx_uint32 num_of_dims, vx_uint32 *sizes, vx_enum data_format, vx_uint8 fixed_point_pos);
238 
239 
240 /*! \brief Allows the application to copy a view patch from/into an tensor object .
241 * \param [in] tensor The reference to the tensor object that is the source or the
242 * destination of the copy.
243 * \param [in] view Optional parameter of type <tt>\ref vx_tensor_view</tt>. The coordinates of the view patch. The patch must be within
244 * the bounds of the tensor. (start[index],end[index]) gives the coordinates of the view
245 * element out of the patch. Must be 0 <= start < end <= number of elements in the tensor dimension.
246 * see <tt>\ref vxCreateTensorView</tt>. If NULL is given instead of the object. Then the function behaves as if view was the size of the full tensor.
247 * \param [in] user_addr The address of a structure describing the layout of the
248 * user memory location pointed by user_ptr. In the structure, dim[index],
249 * stride[index] fields must be provided, other fields are ignored by the function.
250 * The layout of the user memory must follow a row major order. see <tt>\ref vxCreateTensorAddressing</tt>
251 * \param [in] user_ptr The address of the memory location where to store the requested data
252 * if the copy was requested in read mode, or from where to get the data to store into the tensor
253 * object if the copy was requested in write mode. The accessible memory must be large enough
254 * to contain the specified patch with the specified layout:\n
255 * accessible memory in bytes >= (end[last_dimension] - start[last_dimension]) * stride[last_dimension].\m
256 * see <tt>\ref vxCreateTensorAddressing</tt> and <tt>\ref vxCreateTensorView</tt>.
257 * \param [in] usage This declares the effect of the copy with regard to the tensor object
258 * using the <tt>vx_accessor_e</tt> enumeration. Only VX_READ_ONLY and VX_WRITE_ONLY are supported:
259 * \arg VX_READ_ONLY means that data is copied from the tensor object into the application memory
260 * \arg VX_WRITE_ONLY means that data is copied into the tensor object from the application memory
261 * \param [in] user_mem_type A <tt>vx_memory_type_e</tt> enumeration that specifies
262 * the memory type of the memory referenced by the user_addr.
263 * \return A <tt>vx_status_e</tt> enumeration.
264 * \retval VX_ERROR_OPTIMIZED_AWAY This is a reference to a virtual tensor that cannot be
265 * accessed by the application.
266 * \retval VX_ERROR_INVALID_REFERENCE The tensor reference is not actually an tensor reference.
267 * \retval VX_ERROR_INVALID_PARAMETERS An other parameter is incorrect.
268  * \ingroup group_tensor
269  */
270 VX_API_ENTRY vx_status VX_API_CALL vxCopyTensorPatch(vx_tensor tensor, vx_tensor_view view, vx_tensor_addressing user_addr, void *user_ptr, vx_enum usage, vx_enum user_mem_type);
271 
272 /*! \brief Retrieves various attributes of a tensor data.
273  * \param [in] tensor The reference to the tensor data to query.
274  * \param [in] attribute The attribute to query. Use a <tt>\ref vx_tensor_attribute_e</tt>.
275  * \param [out] ptr The location at which to store the resulting value.
276  * \param [in] size The size of the container to which \a ptr points.
277  * \return A <tt>vx_status_e</tt> enumeration.
278  * \retval VX_SUCCESS No errors.
279  * \retval VX_ERROR_INVALID_REFERENCE If data is not a <tt>\ref vx_tensor</tt>.
280  * \retval VX_ERROR_INVALID_PARAMETERS If any of the other parameters are incorrect.
281  * \ingroup group_tensor
282  */
283 VX_API_ENTRY vx_status VX_API_CALL vxQueryTensor(vx_tensor tensor, vx_enum attribute, void *ptr, vx_size size);
284 
285 /*! \brief Releases a reference to a tensor data object.
286  * The object may not be garbage collected until its total reference count is zero.
287  * \param [in] tensor The pointer to the tensor data to release.
288  * \post After returning from this function the reference is zeroed.
289  * \return A <tt>vx_status_e</tt> enumeration.
290  * \retval VX_SUCCESS No errors.
291  * \retval VX_SUCCESS Success
292  * \retval * An error occurred. See <tt>vx_status_e</tt>.
293  * \ingroup group_tensor
294  */
295 VX_API_ENTRY vx_status VX_API_CALL vxReleaseTensor(vx_tensor *tensor);
296 
297 
298 /*! \brief Create an opaque reference to a tensor view object.
299  * \details Not guaranteed to exist until the <tt>vx_graph</tt> containing it has been verified.
300  * \param [in] context The reference to the implementation context.
301  * \param [in] view_array_start a vx_uint32 array of start values of the view.
302  * \param [in] view_array_end a vx_uint32 array of end values of the view.
303  * \param [in] numViewDimensions number of dimensions of view_array_start and view_array_end.
304  * \return A tensor data view reference or zero when an error is encountered.
305  * \ingroup group_tensor
306  */
307 VX_API_ENTRY vx_tensor_view VX_API_CALL vxCreateTensorView(vx_context context, vx_uint32 *view_array_start, vx_uint32 * view_array_end, vx_uint8 numViewDimensions);
308 
309 /*! \brief Releases a reference to a tensor data view object.
310 * The object may not be garbage collected until its total reference count is zero.
311 * \param [in] tensor_view The pointer to the tensor data view to release.
312 * \post After returning from this function the reference is zeroed.
313 * \return A <tt>vx_status_e</tt> enumeration.
314 * \retval VX_SUCCESS No errors.
315 * \retval VX_SUCCESS Success
316 * \retval * An error occurred. See <tt>vx_status_e</tt>.
317 * \ingroup group_tensor
318 */
319 VX_API_ENTRY vx_status VX_API_CALL vxReleaseTensorView(vx_tensor_view *tensor_view);
320 
321 /*! \brief Create an opaque reference to a tensor addressing object.
322 * \details Not guaranteed to exist until the <tt>vx_graph</tt> containing it has been verified.
323 * \param [in] context The reference to the implementation context.
324 * \param [in] addressing_array_dimension a vx_uint32 array of sLength of patch in all dimensions in elements.
325 * \param [in] addressing_array_stride a vx_uint32 arrayStride in all dimensions in bytes.
326 * \param [in] numViewDimensions number of dimensions of view_array_start and view_array_end.
327 * \return A tensor data view reference or zero when an error is encountered.
328 * \ingroup group_tensor
329 */
330 VX_API_ENTRY vx_tensor_addressing VX_API_CALL vxCreateTensorAddressing(vx_context context, vx_uint32 *addressing_array_dimension, vx_uint32 * addressing_array_stride, vx_uint8 numViewDimensions);
331 
332 /*! \brief Releases a reference to a tensor data addressing object.
333 * The object may not be garbage collected until its total reference count is zero.
334 * \param [in] tensor_addr The pointer to the tensor data addressing to release.
335 * \post After returning from this function the reference is zeroed.
336 * \return A <tt>vx_status_e</tt> enumeration.
337 * \retval VX_SUCCESS No errors.
338 * \retval VX_SUCCESS Success
339 * \retval * An error occurred. See <tt>vx_status_e</tt>.
340 * \ingroup group_tensor
341 */
342 VX_API_ENTRY vx_status VX_API_CALL vxReleaseTensorAddressing(vx_tensor_addressing *tensor_addr);
343 
344 /*==============================================================================
345  NN Nodes
346 =============================================================================*/
347 /*! \brief [Graph] Creates a Convolutional Network Convolution Layer Node.
348 * \details This function implement Convolutional Network Convolution layer.
349 * In case the input and output <tt>\ref vx_tensor</tt> are signed 16. A fixed point calculation is performed with round and saturate according to the number of accumulator bits. \n
350 * round: rounding according the <tt>vx_round_policy_e</tt> enumeration. \n
351 * saturate: A saturation according the <tt>vx_convert_policy_e</tt> enumeration.
352 * The saturation is done based on the accumulator_bits parameter.
353 * According the accumulator_bits, the saturation might not be performed every operation.
354 * But every a specified amount of operations,
355 * that are suspected to saturate the accumulation bits\n
356 * The following equation is implemented: \n
357 * \f$ outputs[j,k,i] = (\sum_{l} \sum_{m,n} saturate(round(inputs[j-m,k-n,l] \times weights[m,n,l,i])))+biasses[j,k,i] \f$\n
358 * Where \f$m,n\f$ are indexes on the convolution matrices. \f$ l\f$ is an index on all the convolutions per input.\f$ i\f$ is an index per output.
359 * \f$ j,k \f$ are the inputs/outputs spatial indexes.
360 * Convolution is done on the first 2 dimensions of the <tt>\ref vx_tensor</tt>. Therefore, we use here the term x for the first dimension and y for the second.\n
361 * before the Convolution is done, a padding of the first 2D with zeros is performed.
362 * Then down scale is done by picking the results according to a skip jump. The skip in the x and y dimension is determined by the output size dimensions.
363 * The relation between input to output is as follows: \n
364 * \f$ width_{output} = round(\frac{(width + 2 * pad_x - kernel_x)}{skip_x} + 1) \f$\n
365 * and \n
366 * \f$ height_{output} = round(\frac{(height + 2 * pad_y - kernel_y)}{skip_y} + 1) \f$\n
367 * where \f$width\f$ is the size of the first input dimension. \f$height\f$ is the size of the second input dimension.
368 * \f$width_{output}\f$ is the size of the first output dimension. \f$height_{output}\f$ is the size of the second output dimension.
369 * \f$kernel_x\f$ and \f$kernel_y\f$ are the convolution sizes in x and y.
370 * skip is calculated by the relation between input and output.
371 * rounding is done according to <tt>\ref vx_convolutional_network_rounding_type_e</tt>.
372 * \param [in] graph The handle to the graph.
373 * \param [in] inputs The input tensor data. 3 lower dims represent a single input, and an optional 4th dimension for batch of inputs.\n
374 * \param [in] weights Weights are 4d tensor with dimensions [kernel_x, kernel_y, #IFM, #OFM].\n
375 * \param [in] biases The biases, which may be shared (one per ofm) or unshared (one per ofm * output location).
376 * \param [in] pad_x Number of elements added at each side in the x dimension of the input.
377 * \param [in] pad_y Number of elements added at each side in the y dimension of the input. In fully connected layers this input is ignored.
378 * \param [in] accumulator_bits Is the total number of bits used during intermediate accumulation.
379 * \param [in] overflow_policy A <tt> VX_TYPE_ENUM</tt> of the <tt> vx_convert_policy_e</tt> enumeration.
380 * \param [in] rounding_policy A <tt> VX_TYPE_ENUM</tt> of the <tt> vx_round_policy_e</tt> enumeration.
381 * \param [in] down_scale_size_rounding Rounding method for calculating output dimensions. See <tt>\ref vx_convolutional_network_rounding_type_e</tt>
382 * \param [out] outputs The output tensor data. Output will have the same number of dimensions as input.
383 * \return <tt> vx_node</tt>.
384 * \retval 0 Node could not be created.
385 * \retval * Node handle.
386 * \ingroup group_cnn
387 */
388 VX_API_ENTRY vx_node VX_API_CALL vxConvolutionLayer(vx_graph graph, vx_tensor inputs, vx_tensor weights, vx_tensor biases,
389  vx_uint32 pad_x,
390  vx_uint32 pad_y,
391  vx_uint8 accumulator_bits,
392  vx_enum overflow_policy,
393  vx_enum rounding_policy,
394  vx_enum down_scale_size_rounding,
395  vx_tensor outputs);
396 
397 /*! \brief [Graph] Creates a Fully connected Convolutional Network Layer Node.
398 * \details This function implement Fully connected Convolutional Network layers.
399 * In case the input and output <tt>\ref vx_tensor</tt> are signed 16. A fixed point calculation is performed with round and saturate according to the number of accumulator bits. \n
400 * round: rounding according the <tt>vx_round_policy_e</tt> enumeration. \n
401 * saturate: A saturation according the <tt>vx_convert_policy_e</tt> enumeration.
402 * The saturation is done based on the accumulator_bits parameter.
403 * According the accumulator_bits, the saturation might not be performed every operation.
404 * But every a specified amount of operations,
405 * that are suspected to saturate the accumulation bits\n
406 * The equation for Fully connected layer:\n
407 * \f$ outputs[i] = ( \sum_{j} saturate(round(inputs[j] \times weights[j,i])))+biasses[i] \f$\n
408 * Where \f$j\f$ is a index on the input feature and \f$i\f$ is a index on the output.
409 * before the fully connected is done, a padding of the input is performed.
410 * Then down scale is done by picking the results according to a skip jump. The skip is determined by the output size dimensions.
411 * The relation between input to output is as follows:
412 * \f$ size_{output} = round(\frac{(size_{input} + 2 * pad)}{skip} + 1) \f$\n
413 * where \f$size_{input}\f$ is the size of the input dimension.
414 * \f$size_{output}\f$ is the size of the output dimension.
415 * skip is calculated by the relation between input and output.
416 * rounding is done according to <tt>\ref vx_convolutional_network_rounding_type_e</tt>.
417 * \param [in] graph The handle to the graph.
418 * \param [in] inputs The input tensor data. 1-3 lower dims represent a single input, and all dims above dim(weights)-1 are optional for batch of inputs. Note that batch may be multidimensional.
419 * \param [in] weights Number of dimensions equals dim(single input)+1. Single input dims are [width, height, #IFM], with height and #IFM being optional.\n
420 * \param [in] biases The biases, which may be shared (one per ofm) or unshared (one per ofm * output location).
421 * \param [in] pad Number of elements added at each side in the input.
422 * \param [in] accumulator_bits Is the total number of bits used during intermediate accumulation.
423 * \param [in] overflow_policy A <tt> VX_TYPE_ENUM</tt> of the <tt> vx_convert_policy_e</tt> enumeration.
424 * \param [in] rounding_policy A <tt> VX_TYPE_ENUM</tt> of the <tt> vx_round_policy_e</tt> enumeration.
425 * \param [in] down_scale_size_rounding Rounding method for calculating output dimensions. See <tt>\ref vx_convolutional_network_rounding_type_e</tt>
426 * \param [out] outputs The output tensor data. Output will have the same number of dimensions as input.
427 * \return <tt> vx_node</tt>.
428 * \retval 0 Node could not be created.
429 * \retval * Node handle.
430 * \ingroup group_cnn
431 */
432 VX_API_ENTRY vx_node VX_API_CALL vxFullyConnectedLayer(vx_graph graph, vx_tensor inputs, vx_tensor weights, vx_tensor biases,
433  vx_uint32 pad,
434  vx_uint8 accumulator_bits,
435  vx_enum overflow_policy,
436  vx_enum rounding_policy,
437  vx_enum down_scale_size_rounding,
438  vx_tensor outputs);
439 
440 
441 /*! \brief [Graph] Creates a Convolutional Network Pooling Layer Node.
442  * \details Pooling is done on the first 2 dimensions or the <tt>\ref vx_tensor</tt>. Therefore, we use here the term x for the first dimension and y for the second.\n
443  * Pooling operation is a function operation over a rectangle size and then a nearest neighbour down scale.
444  * Here we use pool_size_x and pool_size_y to specify the rectangle size on which the operation
445  * is performed. \n
446  * before the operation is done (average or maximum value). the data is padded in the first 2D with zeros.
447  * The down scale is done by picking the results according to a skip jump. The skip in the x and y dimension is determined by the output size dimensions.
448 * \param [in] graph The handle to the graph.
449 * \param [in] inputs The input tensor data. 3 lower dims represent a single input with dimensions [width, height, IFM], and an optional 4th dimension for batch of inputs.
450 * \param [in] pool_type Either max pooling or average pooling (see <tt>\ref vx_convolutional_network_pooling_type_e</tt>).
451 * \param [in] pool_size_x Size of the pooling region in the x dimension
452 * \param [in] pool_size_y Size of the pooling region in the y dimension.
453 * \param [in] pool_pad_x Padding size in the x dimension.
454 * \param [in] pool_pad_y Padding size in the y dimension.
455 * \param [in] rounding, Rounding method for calculating output dimensions. See <tt>\ref vx_convolutional_network_rounding_type_e</tt>
456 * \param [out] outputs The output tensor data. Output will have the same number of dimensions as input.
457 * \return <tt> vx_node</tt>.
458 * \retval 0 Node could not be created.
459 * \retval * Node handle.
460 * \ingroup group_cnn
461 */
462 VX_API_ENTRY vx_node VX_API_CALL vxPoolingLayer(vx_graph graph, vx_tensor inputs, vx_enum pool_type,
463  vx_uint32 pool_size_x,
464  vx_uint32 pool_size_y,
465  vx_uint32 pool_pad_x,
466  vx_uint32 pool_pad_y,
467  vx_enum rounding,
468  vx_tensor outputs);
469 
470 /*! \brief [Graph] Creates a Convolutional Network Softmax Layer Node.
471 * \param [in] graph The handle to the graph.
472 * \param [in] inputs The input tensor data, with number of dimensions equals dim(input batch) + 1. Softmax will be calculated per IFM.
473 * \param [out] outputs The output tensor data. Output will have the same number of dimensions as input.
474 * \ingroup group_cnn
475 * \return <tt> vx_node</tt>.
476 * \retval 0 Node could not be created.
477 * \retval * Node handle.
478 */
479 VX_API_ENTRY vx_node VX_API_CALL vxSoftmaxLayer(vx_graph graph, vx_tensor inputs, vx_tensor outputs);
480 
481 /*! \brief [Graph] Creates a Convolutional Network Normalization Layer Node.
482 * \details Normalizing over local input regions. Each input value is divided by \f$ (1+\frac{\alpha}{n}\sum_i x^2_i)^\beta \f$ , where n is the number of elements to normalize across.
483 * and the sum is taken over the region centred at that value (zero padding is added where necessary).
484 * \param [in] graph The handle to the graph.
485 * \param [in] inputs The input tensor data. 3 lower dims represent a single input with dimensions [width, height, IFM], and an optional 4th dimension for batch of inputs.
486 * \param [in] type Either same map or across maps (see vx_convolutional_network_norm_type_e).
487 * \param [in] norm_size Number of elements to normalize across.
488 * \param [in] alpha Alpha parameter in the normalization equation.
489 * \param [in] beta Beta parameter in the normalization equation.
490 * \param [out] outputs The output tensor data. Output will have the same number of dimensions as input.
491 * \ingroup group_cnn
492 * \return <tt> vx_node</tt>.
493 * \retval 0 Node could not be created.
494 * \retval * Node handle.
495 */
496 VX_API_ENTRY vx_node VX_API_CALL vxNormalizationLayer(vx_graph graph, vx_tensor inputs, vx_enum type,
497  vx_uint32 norm_size,
498  vx_float32 alpha,
499  vx_float32 beta,
500  vx_tensor outputs);
501 
502 /*! \brief [Graph] Creates a Convolutional Network Activation Layer Node.
503 * \param [in] graph The handle to the graph.
504 * \param [in] inputs The input tensor data.
505 * \param [in] func Non-linear function (see <tt>\ref vx_convolutional_network_activation_func_e</tt>).
506 * \param [in] a Function parameters a. (see <tt>\ref vx_convolutional_network_activation_func_e</tt>).
507 * \param [in] b Function parameters b. (see <tt>\ref vx_convolutional_network_activation_func_e</tt>).
508 * \param [out] outputs The output tensor data. Output will have the same number of dimensions as input.
509 * \ingroup group_cnn
510 * \return <tt> vx_node</tt>.
511 * \retval 0 Node could not be created.
512 * \retval * Node handle.
513 */
514 VX_API_ENTRY vx_node VX_API_CALL vxActivationLayer(vx_graph graph, vx_tensor inputs, vx_enum func, vx_int32 a,vx_int32 b, vx_tensor outputs);
515 
516 
517 
518 
519 /*! \brief [Graph] Performs element wise multiplications on element values in the input tensor data's with a scale.
520 * \param [in] graph The handle to the graph.
521 * \param [in] in1 input tensor data.
522 * \param [in] in2 input tensor data, inputs must be of equal in dimensions.
523 * else, If in one of the vx_mddata dimension is 1.
524 * That dimension is considered as a const on all the dimension terms.
525 * And will perform as if the values are duplicated on all terms in that dimensions.
526 * After the expansion. The dimensions are equal.
527 * \param [in] scale The scale value.
528 * \param [in] overflow_policy A <tt>vx_convert_policy_e</tt> enumeration.
529 * \param [in] rounding_policy A <tt>vx_round_policy_e</tt> enumeration.
530 * \param [out] out The output tensor data with the same dimensions as the input tensor data's.
531 * \ingroup group_tensor
532 * \return <tt> vx_node</tt>.
533 * \retval 0 Node could not be created.
534 * \retval * Node handle.
535 */
536 VX_API_ENTRY vx_node VX_API_CALL vxTensorMultiplyNode(vx_graph graph, vx_tensor in1, vx_tensor in2, vx_scalar scale, vx_enum overflow_policy, vx_enum rounding_policy, vx_tensor out);
537 
538 /*! \brief [Graph] Performs arithmetic addition on element values in the input tensor data's.
539  * \param [in] graph The handle to the graph.
540  * \param [in] in1 input tensor data,.
541  * \param [in] in2 input tensor data, inputs must be of equal in dimensions.
542  * else, If in one of the vx_mddata dimension is 1.
543  * That dimension is considered as a const on all the dimension terms.
544  * And will perform as if the values are duplicated on all terms in that dimensions.
545  * After the expansion. The dimensions are equal.
546  * \param [in] policy A vx_convert_policy_e enumeration.
547  * \param [out] out The output tensor data with the same dimensions as the input tensor data's.
548  * \ingroup group_tensor
549  * \return <tt> vx_node</tt>.
550  * \retval 0 Node could not be created.
551  * \retval * Node handle.
552  */
553 VX_API_ENTRY vx_node VX_API_CALL vxTensorAddNode(vx_graph graph, vx_tensor in1, vx_tensor in2, vx_enum policy, vx_tensor out);
554 
555 /*! \brief [Graph] Performs arithmetic subtraction on element values in the input tensor data's.
556 * \param [in] graph The handle to the graph.
557 * \param [in] in1 input tensor data.
558 * \param [in] in2 input tensor data, inputs must be of equal in dimensions.
559 * else, If in one of the vx_mddata dimension is 1.
560 * That dimension is considered as a const on all the dimension terms.
561 * And will perform as if the values are duplicated on all terms in that dimensions.
562 * After the expansion. The dimensions are equal.
563 * \param [in] policy A vx_convert_policy_e enumeration.
564 * \param [out] out The output tensor data with the same dimensions as the input tensor data's.
565 * \ingroup group_tensor
566 * \return <tt> vx_node</tt>.
567 * \retval 0 Node could not be created.
568 * \retval * Node handle.
569 */
570 VX_API_ENTRY vx_node VX_API_CALL vxTensorSubtractNode(vx_graph graph, vx_tensor in1, vx_tensor in2, vx_enum policy, vx_tensor out);
571 
572 /*! \brief [Graph] Performs LUT on element values in the input tensor data's.
573 * \param [in] graph The handle to the graph.
574 * \param [in] in1 input tensor data.
575 * \param [in] lut of type <tt>vx_lut</tt>
576 * \param [out] out The output tensor data with the same dimensions as the input tensor data's.
577 * \ingroup group_tensor
578 * \return <tt> vx_node</tt>.
579 * \retval 0 Node could not be created.
580 * \retval * Node handle.
581 */
582 VX_API_ENTRY vx_node VX_API_CALL vxTensorTableLookupNode(vx_graph graph, vx_tensor in1, vx_lut lut, vx_tensor out);
583 
584 
585 /*! \brief [Graph] Performs transpose on the input tensor.
586 * The node transpose the tensor according to a specified 2 indexes in the tensor (0-based indexing)
587 * \param [in] graph The handle to the graph.
588 * \param [in] in input tensor data,
589 * \param [out] out output tensor data,
590 * \param [in] dim1 that is transposed with dim 2.
591 * \param [in] dim2 that is transposed with dim 1.
592 * \ingroup group_tensor
593 * \return <tt> vx_node</tt>.
594 * \retval 0 Node could not be created.
595 * \retval * Node handle.
596 */
597 VX_API_ENTRY vx_node VX_API_CALL vxTensorTransposeNode(vx_graph graph, vx_tensor in, vx_tensor out, vx_uint32 dim1, vx_uint32 dim2);
598 
599 
600 
601 
602 #endif
Number of dimensions.
Definition: vx_khr_cnn.h:58
vx_node vxPoolingLayer(vx_graph graph, vx_tensor inputs, vx_enum pool_type, vx_uint32 pool_size_x, vx_uint32 pool_size_y, vx_uint32 pool_pad_x, vx_uint32 pool_pad_y, vx_enum rounding, vx_tensor outputs)
[Graph] Creates a Convolutional Network Pooling Layer Node.
vx_node vxFullyConnectedLayer(vx_graph graph, vx_tensor inputs, vx_tensor weights, vx_tensor biases, vx_uint32 pad, vx_uint8 accumulator_bits, vx_enum overflow_policy, vx_enum rounding_policy, vx_enum down_scale_size_rounding, vx_tensor outputs)
[Graph] Creates a Fully connected Convolutional Network Layer Node.
vx_node vxSoftmaxLayer(vx_graph graph, vx_tensor inputs, vx_tensor outputs)
[Graph] Creates a Convolutional Network Softmax Layer Node.
Dimension sizes.
Definition: vx_khr_cnn.h:60
vx_tensor_view vxCreateTensorView(vx_context context, vx_uint32 *view_array_start, vx_uint32 *view_array_end, vx_uint8 numViewDimensions)
Create an opaque reference to a tensor view object.
vx_tensor_addressing vxCreateTensorAddressing(vx_context context, vx_uint32 *addressing_array_dimension, vx_uint32 *addressing_array_stride, vx_uint8 numViewDimensions)
Create an opaque reference to a tensor addressing object.
normalization is done on same IFM
Definition: vx_khr_cnn.h:138
vx_object_array vxCreateImageObjectArrayFromTensor(vx_tensor tensor, vx_rectangle_t rect, vx_uint32 array_size, vx_uint32 stride, vx_df_image image_format)
Creates an array of images into the multi-dimension data, this can be a adjacent 2D images or not dep...
vx_status vxReleaseTensorView(vx_tensor_view *tensor_view)
Releases a reference to a tensor data view object. The object may not be garbage collected until its ...
vx_convolutional_network_pooling_type_e
The Convolutional Network pooling type list.
Definition: vx_khr_cnn.h:123
vx_convolutional_network_activation_func_e
The Convolutional Network activation functions list.
Definition: vx_khr_cnn.h:161
vx_convolutional_network_norm_type_e
The Convolutional Network normalization type list.
Definition: vx_khr_cnn.h:135
vx_tensor_attribute_e
tensor Data attributes.
Definition: vx_khr_cnn.h:55
vx_status vxQueryTensor(vx_tensor tensor, vx_enum attribute, void *ptr, vx_size size)
Retrieves various attributes of a tensor data.
vx_convolutional_networks_rounding_type_e
The Convolutional Network down scaling size rounding type list.
Definition: vx_khr_cnn.h:110
fixed point position when the input element type is int16.
Definition: vx_khr_cnn.h:64
vx_node vxTensorAddNode(vx_graph graph, vx_tensor in1, vx_tensor in2, vx_enum policy, vx_tensor out)
[Graph] Performs arithmetic addition on element values in the input tensor data's.
vx_status vxReleaseTensor(vx_tensor *tensor)
Releases a reference to a tensor data object. The object may not be garbage collected until its total...
vx_tensor vxCreateTensorFromView(vx_tensor tensor, vx_tensor_view view)
Creates a tensor data from another tensor data given a view. This second reference refers to the data...
vx_tensor vxCreateTensor(vx_context context, vx_uint32 num_of_dims, vx_uint32 *sizes, vx_enum data_format, vx_uint8 fixed_point_pos)
Creates an opaque reference to a tensor data buffer.
struct _vx_tensor_addressing_t * vx_tensor_addressing
The addressing of a tensor view patch structure is used by the Host only to address elements in a ten...
Definition: vx_khr_cnn.h:103
vx_node vxTensorTableLookupNode(vx_graph graph, vx_tensor in1, vx_lut lut, vx_tensor out)
[Graph] Performs LUT on element values in the input tensor data's.
Normalization is done across different IFMs.
Definition: vx_khr_cnn.h:140
struct _vx_tensor_view_t * vx_tensor_view
The multi dimensional view data structure.
Definition: vx_khr_cnn.h:96
tensor Data max num of dimensions supported by HW.
Definition: vx_khr_cnn.h:73
vx_node vxTensorTransposeNode(vx_graph graph, vx_tensor in, vx_tensor out, vx_uint32 dim1, vx_uint32 dim2)
[Graph] Performs transpose on the input tensor. The node transpose the tensor according to a specifie...
vx_status vxCopyTensorPatch(vx_tensor tensor, vx_tensor_view view, vx_tensor_addressing user_addr, void *user_ptr, vx_enum usage, vx_enum user_mem_type)
Allows the application to copy a view patch from/into an tensor object .
vx_node vxTensorMultiplyNode(vx_graph graph, vx_tensor in1, vx_tensor in2, vx_scalar scale, vx_enum overflow_policy, vx_enum rounding_policy, vx_tensor out)
[Graph] Performs element wise multiplications on element values in the input tensor data's with a sca...
vx_node vxConvolutionLayer(vx_graph graph, vx_tensor inputs, vx_tensor weights, vx_tensor biases, vx_uint32 pad_x, vx_uint32 pad_y, vx_uint8 accumulator_bits, vx_enum overflow_policy, vx_enum rounding_policy, vx_enum down_scale_size_rounding, vx_tensor outputs)
[Graph] Creates a Convolutional Network Convolution Layer Node.
vx_node vxActivationLayer(vx_graph graph, vx_tensor inputs, vx_enum func, vx_int32 a, vx_int32 b, vx_tensor outputs)
[Graph] Creates a Convolutional Network Activation Layer Node.
vx_node vxTensorSubtractNode(vx_graph graph, vx_tensor in1, vx_tensor in2, vx_enum policy, vx_tensor out)
[Graph] Performs arithmetic subtraction on element values in the input tensor data's.
struct _vx_tensor_t * vx_tensor
The multidimensional data object (Tensor).
Definition: vx_khr_cnn.h:89
vx_node vxNormalizationLayer(vx_graph graph, vx_tensor inputs, vx_enum type, vx_uint32 norm_size, vx_float32 alpha, vx_float32 beta, vx_tensor outputs)
[Graph] Creates a Convolutional Network Normalization Layer Node.
vx_status vxReleaseTensorAddressing(vx_tensor_addressing *tensor_addr)
Releases a reference to a tensor data addressing object. The object may not be garbage collected unti...
vx_context_attribute_e
A list of context attributes.
Definition: vx_khr_cnn.h:71
tensor Data element data type. vx_type_e
Definition: vx_khr_cnn.h:62
vx_tensor vxCreateVirtualTensor(vx_graph graph, vx_uint32 num_of_dims, vx_uint32 *sizes, vx_enum data_format, vx_uint8 fixed_point_pos)
Creates an opaque reference to a tensor data buffer with no direct user access. This function allows ...