From patchwork Fri Sep 4 13:59:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xu Jun X-Patchwork-Id: 22092 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id B141444B7E2 for ; Fri, 4 Sep 2020 17:02:11 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 8FBC568A9AA; Fri, 4 Sep 2020 17:02:11 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from smtp181.sjtu.edu.cn (smtp181.sjtu.edu.cn [202.120.2.181]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A72F26805A5 for ; Fri, 4 Sep 2020 17:02:04 +0300 (EEST) Received: from proxy02.sjtu.edu.cn (smtp188.sjtu.edu.cn [202.120.2.188]) by smtp181.sjtu.edu.cn (Postfix) with ESMTPS id 2874E1008CBC1 for ; Fri, 4 Sep 2020 22:01:59 +0800 (CST) Received: from localhost (localhost.localdomain [127.0.0.1]) by proxy02.sjtu.edu.cn (Postfix) with ESMTP id 1E98C200B4497; Fri, 4 Sep 2020 22:01:59 +0800 (CST) X-Virus-Scanned: amavisd-new at Received: from proxy02.sjtu.edu.cn ([127.0.0.1]) by localhost (proxy02.sjtu.edu.cn [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id e968R2j7ZuPO; Fri, 4 Sep 2020 22:01:58 +0800 (CST) Received: from localhost.localdomain (unknown [202.120.39.204]) (Authenticated sender: xujunzz@sjtu.edu.cn) by proxy02.sjtu.edu.cn (Postfix) with ESMTPSA id 0D99B200B4496; Fri, 4 Sep 2020 22:01:57 +0800 (CST) From: xujunzz@sjtu.edu.cn To: ffmpeg-devel@ffmpeg.org Date: Fri, 4 Sep 2020 21:59:14 +0800 Message-Id: <20200904135913.4934-1-xujunzz@sjtu.edu.cn> X-Mailer: git-send-email 2.28.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3 1/2] dnn_backend_native.c: parse options in native backend X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: xujunzz@sjtu.edu.cn Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Xu Jun Signed-off-by: Xu Jun --- v2: use av_opt_set_from_string instead of function dnn_parse_option(). v3: make all the options supported, not just conv2d_threads libavfilter/dnn/dnn_backend_native.c | 19 ++++++++++--------- libavfilter/dnn/dnn_backend_native.h | 21 +++++++++++++++++++++ 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/libavfilter/dnn/dnn_backend_native.c b/libavfilter/dnn/dnn_backend_native.c index a8fe6b94eb..031fb8c7df 100644 --- a/libavfilter/dnn/dnn_backend_native.c +++ b/libavfilter/dnn/dnn_backend_native.c @@ -28,14 +28,6 @@ #include "dnn_backend_native_layer_conv2d.h" #include "dnn_backend_native_layers.h" -static const AVClass dnn_native_class = { - .class_name = "dnn_native", - .item_name = av_default_item_name, - .option = NULL, - .version = LIBAVUTIL_VERSION_INT, - .category = AV_CLASS_CATEGORY_FILTER, -}; - static DNNReturnType get_input_native(void *model, DNNData *input, const char *input_name) { NativeModel *native_model = (NativeModel *)model; @@ -174,8 +166,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 +250,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; diff --git a/libavfilter/dnn/dnn_backend_native.h b/libavfilter/dnn/dnn_backend_native.h index 197f557dee..3954fee199 100644 --- a/libavfilter/dnn/dnn_backend_native.h +++ b/libavfilter/dnn/dnn_backend_native.h @@ -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,10 +107,30 @@ 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; +#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 }, +}; + +static const AVClass dnn_native_class = { + .class_name = "dnn_native", + .item_name = av_default_item_name, + .option = dnn_native_options, + .version = LIBAVUTIL_VERSION_INT, + .category = AV_CLASS_CATEGORY_FILTER, +}; + // Represents simple feed-forward convolutional network. typedef struct NativeModel{ NativeContext ctx;