EdgeAI TIOVX Apps Guide
tiovx_modules_types.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright (c) 2024 Texas Instruments Incorporated
4  *
5  * All rights reserved not granted herein.
6  *
7  * Limited License.
8  *
9  * Texas Instruments Incorporated grants a world-wide, royalty-free, non-exclusive
10  * license under copyrights and patents it now or hereafter owns or controls to make,
11  * have made, use, import, offer to sell and sell ("Utilize") this software subject to the
12  * terms herein. With respect to the foregoing patent license, such license is granted
13  * solely to the extent that any such patent is necessary to Utilize the software alone.
14  * The patent license shall not apply to any combinations which include this software,
15  * other than combinations with devices manufactured by or for TI ("TI Devices").
16  * No hardware patent is licensed hereunder.
17  *
18  * Redistributions must preserve existing copyright notices and reproduce this license
19  * (including the above copyright notice and the disclaimer and (if applicable) source
20  * code license limitations below) in the documentation and/or other materials provided
21  * with the distribution
22  *
23  * Redistribution and use in binary form, without modification, are permitted provided
24  * that the following conditions are met:
25  *
26  * * No reverse engineering, decompilation, or disassembly of this software is
27  * permitted with respect to any software provided in binary form.
28  *
29  * * any redistribution and use are licensed by TI for use only with TI Devices.
30  *
31  * * Nothing shall obligate TI to provide you with source code for the software
32  * licensed and provided to you in object code.
33  *
34  * If software source code is provided to you, modification and redistribution of the
35  * source code are permitted provided that the following conditions are met:
36  *
37  * * any redistribution and use of the source code, including any resulting derivative
38  * works, are licensed by TI for use only with TI Devices.
39  *
40  * * any redistribution and use of any object code compiled from the source code
41  * and any resulting derivative works, are licensed by TI for use only with TI Devices.
42  *
43  * Neither the name of Texas Instruments Incorporated nor the names of its suppliers
44  *
45  * may be used to endorse or promote products derived from this software without
46  * specific prior written permission.
47  *
48  * DISCLAIMER.
49  *
50  * THIS SOFTWARE IS PROVIDED BY TI AND TI'S LICENSORS "AS IS" AND ANY EXPRESS
51  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
52  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
53  * IN NO EVENT SHALL TI AND TI'S LICENSORS BE LIABLE FOR ANY DIRECT, INDIRECT,
54  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
55  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
56  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
57  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
58  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
59  * OF THE POSSIBILITY OF SUCH DAMAGE.
60  *
61  */
62 #ifndef _TIOVX_MODULES_TYPES
63 #define _TIOVX_MODULES_TYPES
64 
65 #include <TI/tivx.h>
66 #include <TI/tivx_fileio.h>
67 #include <TI/tivx_obj_desc.h>
68 
69 #ifdef __cplusplus
70 extern "C" {
71 #endif
72 
73 //#define TIOVX_MODULE_DEBUG
74 
75 #include <stdio.h>
76 #include <string.h>
77 #include <pthread.h>
78 
79 #ifdef TIOVX_MODULE_DEBUG
80 #define TIOVX_MODULE_PRINTF(f_, ...) printf("[TIOVX_MODULES][DEBUG] %d: %s: "f_, __LINE__, __func__, ##__VA_ARGS__)
81 #else
82 #define TIOVX_MODULE_PRINTF(f_, ...)
83 #endif
84 
85 #define TIOVX_MODULE_ERROR(f_, ...) printf("[TIOVX_MODULES][ERROR] %d: %s: "f_, __LINE__, __func__, ##__VA_ARGS__)
86 
87 #define CLR(o) memset(o, 0, sizeof(*o))
88 
89 #define TIOVX_MODULES_MAX_BUFQ_DEPTH (16u)
90 #define TIOVX_MODULES_MAX_NODE_INPUTS (16u)
91 #define TIOVX_MODULES_MAX_NODE_OUTPUTS (8u)
92 #define TIOVX_MODULES_MAX_NODES (128u)
93 #define TIOVX_MODULES_MAX_NUM_CHANNELS (16u)
94 #define TIOVX_MODULES_MAX_GRAPH_PARAMS (16u)
95 
96 #define TIOVX_MODULES_MAX_TENSOR_DIMS (4u)
97 #define TIOVX_MODULES_MAX_TENSORS (8u)
98 #define TIOVX_MODULES_MAX_PARAMS (16u)
99 
100 #define TIOVX_MODULES_DEFAULT_IMAGE_WIDTH (640)
101 #define TIOVX_MODULES_DEFAULT_IMAGE_HEIGHT (480)
102 #define TIOVX_MODULES_DEFAULT_COLOR_FORMAT (VX_DF_IMAGE_NV12)
103 
104 #define TIOVX_MODULES_DEFAULT_BUFQ_DEPTH (2u)
105 #define TIOVX_MODULES_DEFAULT_NUM_CHANNELS (1u)
106 #define TIOVX_MODULES_MAX_REF_HANDLES (16u)
107 
111 typedef enum {
112  SRC = 0,
114 } PAD_DIRECTION;
115 
116 typedef struct _Pad Pad;
117 typedef struct _NodeObj NodeObj;
118 typedef struct _GraphObj GraphObj;
119 typedef struct _Buf Buf;
120 typedef struct _BufPool BufPool;
121 
125 struct _Buf {
127  BufPool *pool;
128 
130  vx_int32 buf_index;
131 
133  vx_object_array arr;
134 
136  vx_reference handle;
137 
139  vx_int32 num_channels;
140 };
141 
145 struct _BufPool {
147  Pad *pad;
148 
151 
153  vx_int32 bufq_depth;
154 
157 
159  vx_int32 free_count;
160 
163 
165  vx_int32 enqueue_head;
166 
168  vx_int32 enqueue_tail;
169 
172 
174  pthread_mutex_t lock;
175 };
176 
180 struct _Pad {
182  NodeObj *node;
183 
185  Pad *peer_pad;
186 
189 
191  vx_int32 pad_index;
192 
195 
198 
200  vx_int32 num_channels;
201 
202 
204  vx_int32 bufq_depth;
205 
207  BufPool *buf_pool;
208 
210  vx_reference exemplar;
211  vx_object_array exemplar_arr;
212 };
213 
217 typedef struct {
218  vx_status (*init_node)(NodeObj *node);
219  vx_status (*create_node)(NodeObj *node);
220  vx_status (*post_verify_graph)(NodeObj *node);
221  vx_status (*delete_node)(NodeObj *node);
222  vx_uint32 (*get_cfg_size)();
223  vx_uint32 (*get_priv_size)();
224 } NodeCbs;
225 
229 struct _NodeObj {
231  vx_char name[VX_MAX_REFERENCE_NAME];
232 
234  vx_int32 node_type;
235 
237  GraphObj *graph;
238 
240  void *node_cfg;
241 
243  vx_int32 node_index;
244 
246  vx_node tiovx_node;
247 
249  vx_int32 num_inputs;
250 
252  vx_int32 num_outputs;
253 
256 
259 
262 
264  void *node_priv;
265 };
266 
267 struct _GraphObj {
269  vx_context tiovx_context;
270 
272  vx_graph tiovx_graph;
273 
275  vx_graph_parameter_queue_params_t graph_params_list[TIOVX_MODULES_MAX_GRAPH_PARAMS];
276 
279 
281  vx_int32 num_nodes;
282 
285 
286  /* \brief Schedule mode (AUTO or MANUAL) */
287  vx_enum schedule_mode;
288  pthread_mutex_t lock;
289 };
290 
291 typedef struct {
292  tivx_raw_image_create_params_t params;
293 } RawImgCfg;
294 
295 typedef struct {
296  vx_int32 width;
297  vx_int32 height;
298  vx_int32 color_format;
299 } ImgCfg;
300 
301 typedef struct {
302  vx_int32 num_dims;
303  vx_int32 dim_sizes[TIVX_CONTEXT_MAX_TENSOR_DIMS];
304  vx_int32 datatype;
305 } TensorCfg;
306 
307 typedef struct {
308  vx_int32 width;
309  vx_int32 height;
310  vx_int32 color_format;
311  vx_int32 levels;
312  vx_float32 scale;
313 } PyramidCfg;
314 
315 typedef struct {
316  vx_size num_bins;
317  vx_int32 offset;
318  vx_uint32 range;
319 } DstCfg;
320 
321 vx_status tiovx_module_create_pad_exemplar(Pad *pad, vx_reference exemplar);
322 
330 vx_status tiovx_modules_link_pads(Pad *src_pad, Pad *sink_pad);
331 
332 #ifdef __cplusplus
333 }
334 #endif
335 
336 #endif //_TIOVX_MODULES_TYPES
vx_float32 scale
Definition: tiovx_modules_types.h:312
NodeCbs * cbs
Module call backs NodeCbs.
Definition: tiovx_modules_types.h:261
Buf * freeQ[TIOVX_MODULES_MAX_BUFQ_DEPTH]
Array that contains all free buffers _Buf.
Definition: tiovx_modules_types.h:156
vx_int32 datatype
Definition: tiovx_modules_types.h:304
vx_reference handle
0th handle of the object array
Definition: tiovx_modules_types.h:136
#define TIOVX_MODULES_MAX_BUFQ_DEPTH
Definition: tiovx_modules_types.h:89
#define TIOVX_MODULES_MAX_GRAPH_PARAMS
Definition: tiovx_modules_types.h:94
Definition: tiovx_modules_types.h:267
Definition: tiovx_modules_types.h:112
Structure describing a Buffer object.
Definition: tiovx_modules_types.h:125
vx_object_array arr
Object array for the buffer.
Definition: tiovx_modules_types.h:133
Definition: tiovx_modules_types.h:295
vx_int32 width
Definition: tiovx_modules_types.h:296
vx_int32 num_inputs
Number of inputs to the Node.
Definition: tiovx_modules_types.h:249
vx_int32 height
Definition: tiovx_modules_types.h:297
vx_int32 num_nodes
Number of nodes in the graph.
Definition: tiovx_modules_types.h:281
BufPool * pool
Bufferpool to which the buffer belongs to _BufPool.
Definition: tiovx_modules_types.h:127
vx_uint32 range
Definition: tiovx_modules_types.h:318
vx_graph_parameter_queue_params_t graph_params_list[TIOVX_MODULES_MAX_GRAPH_PARAMS]
Graph params list.
Definition: tiovx_modules_types.h:275
vx_int32 node_index
Index among all nodes in the graph.
Definition: tiovx_modules_types.h:243
vx_int32 enqueue_head
Head pointer for queue management.
Definition: tiovx_modules_types.h:165
vx_node tiovx_node
Actual OpenVx node.
Definition: tiovx_modules_types.h:246
vx_char name[VX_MAX_REFERENCE_NAME]
Name of the node.
Definition: tiovx_modules_types.h:231
Pad srcs[TIOVX_MODULES_MAX_NODE_OUTPUTS]
List of output pads _Pad.
Definition: tiovx_modules_types.h:258
vx_int32 color_format
Definition: tiovx_modules_types.h:310
vx_int32 num_dims
Definition: tiovx_modules_types.h:302
pthread_mutex_t lock
Definition: tiovx_modules_types.h:288
vx_int32 node_parameter_index
Node parameter index.
Definition: tiovx_modules_types.h:194
Definition: tiovx_modules_types.h:307
vx_size num_bins
Definition: tiovx_modules_types.h:316
void * node_priv
Pointer to private data managed by modules.
Definition: tiovx_modules_types.h:264
Structure describing a Pad.
Definition: tiovx_modules_types.h:180
vx_int32 num_outputs
Number of outputs to the Node.
Definition: tiovx_modules_types.h:252
Structure of function prototypes to be implemented by each module.
Definition: tiovx_modules_types.h:217
Definition: tiovx_modules_types.h:113
Buf bufs[TIOVX_MODULES_MAX_BUFQ_DEPTH]
List of buffers in the pool _Buf.
Definition: tiovx_modules_types.h:150
vx_int32 bufq_depth
Number of buffers in the pool.
Definition: tiovx_modules_types.h:153
pthread_mutex_t lock
Mutex for queue management.
Definition: tiovx_modules_types.h:174
vx_int32 levels
Definition: tiovx_modules_types.h:311
Pad * peer_pad
Peer pad to which the pad is connected to.
Definition: tiovx_modules_types.h:185
vx_int32 bufq_depth
Buffer queue depth.
Definition: tiovx_modules_types.h:204
vx_int32 free_count
Number of buffers that are free.
Definition: tiovx_modules_types.h:159
NodeObj node_list[TIOVX_MODULES_MAX_NODES]
List of nodes in the graph.
Definition: tiovx_modules_types.h:284
vx_int32 height
Definition: tiovx_modules_types.h:309
Definition: tiovx_modules_types.h:301
vx_int32 offset
Definition: tiovx_modules_types.h:317
tivx_raw_image_create_params_t params
Definition: tiovx_modules_types.h:292
vx_int32 buf_index
Index of the buffer with respect to all the buffers in the pool.
Definition: tiovx_modules_types.h:130
#define TIOVX_MODULES_MAX_NODES
Definition: tiovx_modules_types.h:92
#define TIOVX_MODULES_MAX_NODE_INPUTS
Definition: tiovx_modules_types.h:90
vx_int32 color_format
Definition: tiovx_modules_types.h:298
vx_int32 pad_index
Index among all the pads in the node with same direction.
Definition: tiovx_modules_types.h:191
Definition: tiovx_modules_types.h:315
Structure describing a Node.
Definition: tiovx_modules_types.h:229
vx_object_array exemplar_arr
Definition: tiovx_modules_types.h:211
vx_graph tiovx_graph
Actual OpenVX graph.
Definition: tiovx_modules_types.h:272
vx_reference exemplar
vx_reference that defines the data that this pad handles
Definition: tiovx_modules_types.h:210
vx_status tiovx_module_create_pad_exemplar(Pad *pad, vx_reference exemplar)
Definition: tiovx_modules.c:893
PAD_DIRECTION direction
Pad direction PAD_DIRECTION.
Definition: tiovx_modules_types.h:188
vx_enum schedule_mode
Definition: tiovx_modules_types.h:287
vx_int32 num_graph_params
Number of graph params.
Definition: tiovx_modules_types.h:278
Pad * pad
Pad with which the buffer pool is allocated for _Pad.
Definition: tiovx_modules_types.h:147
Structure describing a Buffer pool.
Definition: tiovx_modules_types.h:145
GraphObj * graph
Pointer to the parent Graph _GraphObj.
Definition: tiovx_modules_types.h:237
vx_context tiovx_context
OpenVX context used for creating all OpenVX references.
Definition: tiovx_modules_types.h:269
BufPool * buf_pool
Buffer pool allocated for this pad.
Definition: tiovx_modules_types.h:207
NodeObj * node
Node to which the pad belongs to _NodeObj.
Definition: tiovx_modules_types.h:182
vx_int32 num_channels
Number of channels.
Definition: tiovx_modules_types.h:139
vx_status tiovx_modules_link_pads(Pad *src_pad, Pad *sink_pad)
Function to link two pads.
Definition: tiovx_modules.c:553
vx_reference ref_list[TIOVX_MODULES_MAX_BUFQ_DEPTH]
Ref list for graph param.
Definition: tiovx_modules_types.h:171
vx_int32 graph_parameter_index
Graph parameter index.
Definition: tiovx_modules_types.h:197
vx_int32 node_type
Name type NODE_TYPES.
Definition: tiovx_modules_types.h:234
vx_int32 width
Definition: tiovx_modules_types.h:308
vx_int32 enqueue_tail
Tail pointer for queue management.
Definition: tiovx_modules_types.h:168
Pad sinks[TIOVX_MODULES_MAX_NODE_INPUTS]
List of input pads _Pad.
Definition: tiovx_modules_types.h:255
void * node_cfg
Copy of node cfg supplied during add node.
Definition: tiovx_modules_types.h:240
Definition: tiovx_modules_types.h:291
PAD_DIRECTION
Enum for pad directions.
Definition: tiovx_modules_types.h:111
vx_int32 num_channels
Number of channels.
Definition: tiovx_modules_types.h:200
#define TIOVX_MODULES_MAX_NODE_OUTPUTS
Definition: tiovx_modules_types.h:91
Buf * enqueuedQ[TIOVX_MODULES_MAX_BUFQ_DEPTH]
List of buffers that are enqueued _Buf.
Definition: tiovx_modules_types.h:162