1 /*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19 /**
20 * @file
21 * DNN common functions different backends.
22 */
23
24 #ifndef AVFILTER_DNN_DNN_BACKEND_COMMON_H
25 #define AVFILTER_DNN_DNN_BACKEND_COMMON_H
26
28 #include "../dnn_interface.h"
30
31 #define DNN_DEFINE_CLASS_EXT(name, desc, options) \
32 { \
33 .class_name = desc, \
34 .item_name = av_default_item_name, \
35 .option = options, \
36 .version = LIBAVUTIL_VERSION_INT, \
37 .category = AV_CLASS_CATEGORY_FILTER, \
38 }
39 #define DNN_DEFINE_CLASS(fname) \
40 DNN_DEFINE_CLASS_EXT(fname, #fname, fname##_options)
41
42 // one task for one function call from dnn interface
44 void *
model;
// model for the backend
55
56 // one task might have multiple inferences
61
62 /**
63 * Common Async Execution Mechanism for the DNN Backends.
64 */
66 /**
67 * Synchronous inference function for the backend
68 * with corresponding request item as the argument.
69 */
71
72 /**
73 * Completion Callback for the backend.
74 * Expected argument type of callback must match that
75 * of the inference function.
76 */
78
79 /**
80 * Argument for the execution functions.
81 * i.e. Request item for the backend.
82 */
84 #if HAVE_PTHREAD_CANCEL
87 #endif
89
91
92 /**
93 * Fill the Task for Backend Execution. It should be called after
94 * checking execution parameters using ff_check_exec_params.
95 *
96 * @param task pointer to the allocated task
97 * @param exec_param pointer to execution parameters
98 * @param backend_model void pointer to the backend model
99 * @param async flag for async execution. Must be 0 or 1
100 * @param do_ioproc flag for IO processing. Must be 0 or 1
101 *
102 * @returns 0 if successful or error code otherwise.
103 */
105
106 /**
107 * Join the Async Execution thread and set module pointers to NULL.
108 *
109 * @param async_module pointer to DNNAsyncExecModule module
110 *
111 * @returns 0 if successful or error code otherwise.
112 */
114
115 /**
116 * Start asynchronous inference routine for the TensorFlow
117 * model on a detached thread. It calls the completion callback
118 * after the inference completes. Completion callback and inference
119 * function must be set before calling this function.
120 *
121 * If POSIX threads aren't supported, the execution rolls back
122 * to synchronous mode, calling completion callback after inference.
123 *
124 * @param ctx pointer to the backend context
125 * @param async_module pointer to DNNAsyncExecModule module
126 *
127 * @returns 0 on the start of async inference or error code otherwise.
128 */
130
131 /**
132 * Extract input and output frame from the Task Queue after
133 * asynchronous inference.
134 *
135 * @param task_queue pointer to the task queue of the backend
136 * @param in double pointer to the input frame
137 * @param out double pointer to the output frame
138 *
139 * @retval DAST_EMPTY_QUEUE if task queue is empty
140 * @retval DAST_NOT_READY if inference not completed yet.
141 * @retval DAST_SUCCESS if result successfully extracted
142 */
144
145 /**
146 * Allocate input and output frames and fill the Task
147 * with execution parameters.
148 *
149 * @param task pointer to the allocated task
150 * @param exec_params pointer to execution parameters
151 * @param backend_model void pointer to the backend model
152 * @param input_height height of input frame
153 * @param input_width width of input frame
154 * @param ctx pointer to the backend context
155 *
156 * @returns 0 if successful or error code otherwise.
157 */
159
160 #endif