]> git.sesse.net Git - ffmpeg/commitdiff
dnn_backend_native.c: parse options in native backend
authorXu Jun <xujunzz@sjtu.edu.cn>
Sun, 6 Sep 2020 12:28:51 +0000 (20:28 +0800)
committerGuo, Yejun <yejun.guo@intel.com>
Wed, 9 Sep 2020 06:24:36 +0000 (14:24 +0800)
Signed-off-by: Xu Jun <xujunzz@sjtu.edu.cn>
Signed-off-by: Guo, Yejun <yejun.guo@intel.com>
libavfilter/dnn/dnn_backend_native.c
libavfilter/dnn/dnn_backend_native.h

index a8fe6b94eb3345efba644d66d3a2e84d298e1001..a9ecbdc88b52adbd2678da30aa9c742771568fb1 100644 (file)
 #include "dnn_backend_native_layer_conv2d.h"
 #include "dnn_backend_native_layers.h"
 
-static const AVClass dnn_native_class = {
+#define OFFSET(x) offsetof(NativeContext, x)
+#define FLAGS AV_OPT_FLAG_FILTERING_PARAM
+static const AVOption dnn_native_options[] = {
+    { "conv2d_threads", "threads num for conv2d layer", OFFSET(options.conv2d_threads), AV_OPT_TYPE_INT,  { .i64 = 0 }, INT_MIN, INT_MAX, FLAGS },
+    { NULL },
+};
+
+const AVClass dnn_native_class = {
     .class_name = "dnn_native",
     .item_name  = av_default_item_name,
-    .option     = NULL,
+    .option     = dnn_native_options,
     .version    = LIBAVUTIL_VERSION_INT,
     .category   = AV_CLASS_CATEGORY_FILTER,
 };
@@ -174,8 +181,18 @@ DNNModel *ff_dnn_load_model_native(const char *model_filename, const char *optio
     }
 
     native_model->ctx.class = &dnn_native_class;
+    model->options = options;
+    if (av_opt_set_from_string(&native_model->ctx, model->options, NULL, "=", "&") < 0)
+        goto fail;
     model->model = (void *)native_model;
 
+#if !HAVE_PTHREAD_CANCEL
+    if (native_model->ctx.options.conv2d_threads > 1){
+        av_log(&native_model->ctx, AV_LOG_WARNING, "'conv2d_threads' option was set but it is not supported "
+                       "on this build (pthread support is required)\n");
+    }
+#endif
+
     avio_seek(model_file_context, file_size - 8, SEEK_SET);
     native_model->layers_num = (int32_t)avio_rl32(model_file_context);
     native_model->operands_num = (int32_t)avio_rl32(model_file_context);
@@ -248,7 +265,6 @@ DNNModel *ff_dnn_load_model_native(const char *model_filename, const char *optio
 
     model->set_input = &set_input_native;
     model->get_input = &get_input_native;
-    model->options = options;
 
     return model;
 
index 197f557deeabb7d90224f02452b5a6a58c2e9ba0..b1f8f3d6bf03eb91a716f160978160b7b156b23b 100644 (file)
@@ -29,6 +29,7 @@
 
 #include "../dnn_interface.h"
 #include "libavformat/avio.h"
+#include "libavutil/opt.h"
 
 /**
  * the enum value of DNNLayerType should not be changed,
@@ -106,8 +107,13 @@ typedef struct InputParams{
     int height, width, channels;
 } InputParams;
 
+typedef struct NativeOptions{
+    uint32_t conv2d_threads;
+} NativeOptions;
+
 typedef struct NativeContext {
     const AVClass *class;
+    NativeOptions options;
 } NativeContext;
 
 // Represents simple feed-forward convolutional network.