From patchwork Sun Apr 18 10:07:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Guo, Yejun" X-Patchwork-Id: 26964 Delivered-To: andriy.gelman@gmail.com Received: by 2002:a25:49c5:0:0:0:0:0 with SMTP id w188csp228738yba; Sun, 18 Apr 2021 03:20:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw7yRDw1AllnGyPjVLY97I5qmm6ILbBSwVjUKCfnPQuTZC9L7Rv+7RWBjj/hXrY9JD9keQu X-Received: by 2002:a17:906:3945:: with SMTP id g5mr16544756eje.427.1618741204824; Sun, 18 Apr 2021 03:20:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618741204; cv=none; d=google.com; s=arc-20160816; b=GkiIzs/oUa5hZaEe6NIUTFVyJqc81EwBVLofaxSiupvwzgyiYaQK/1EKHNkraQrHHw eMy0Of07LJFgvGBZIgXKMY8ymD24ZbP17E59Oclh3cKns+cym+5mF70ACP4zt3krpUHj qgWbS5By8t/LHiidBP7/+DkyVxAPLovkL4jqjjwOu8Pp8PsB4l5AScVrmXkf1Jf/QYSr XYJ/w4EVGafpXBneDwt/IPFQ9Vi1PxSGXyTrqc52Jcm/IJ+ZChTgrx0DhNTjfTnQMTLC sFL+QKnlXtESutwEjfC5H+bEQ84T7zFPTAZPXvHmTcBmXhOBa3HMG4CuiZZjTSBvVXag KlbQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:message-id:date:to:from:ironport-sdr :ironport-sdr:delivered-to; bh=q7Q5i5jieDCVmIcIV1X5qNU6Ty+JvqODDUa+cvV7rFU=; b=o+ppN9R/9lyP2ocXJx6eqs2pEeSRlUif6TVhJZy5zTk00f2w32MVSE+9EiVAGlCahb KVbSHlmr3Mw32B42hn0e2vR0+CMBHjCFWvVcx2j7U1/rRtZWeIvnv1H4PHl/80rOri3D /ybDyOk4kb5LUp9mIOVG0sB+kOth96h70bD4HKzo7PxedOYmH7+EMzGIAixizdEXTarN Vq5bXHF/v6IXxJAz+VQzGUCzAGobAZjRL85djDxirrTFmv74/LUvEoU+rFeAFdGXFkE+ OOFiPwHKKf5wPhgxe9KD9fqiGwxTIUSVHelMZRmBhq2Nlxt1OEamdBAN5GItnb3BrX++ ZlSg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id ds10si10976242ejc.709.2021.04.18.03.20.04; Sun, 18 Apr 2021 03:20:04 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 5F50E680998; Sun, 18 Apr 2021 13:20:02 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 57A01680577 for ; Sun, 18 Apr 2021 13:19:55 +0300 (EEST) IronPort-SDR: yJq9IwsOsLUcw/PaEQuZPHub51paBDjvhFHrUxc2+5tQTM5XozPU/yJjAlQPM5EP+0hWzDfkYI uavlheXtApXg== X-IronPort-AV: E=McAfee;i="6200,9189,9957"; a="256523543" X-IronPort-AV: E=Sophos;i="5.82,231,1613462400"; d="scan'208";a="256523543" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Apr 2021 03:19:52 -0700 IronPort-SDR: QCBAnqJ5+2wzO0Ldr9yfDJVYj4nqb5HGmjqahSN5oBszUlEBFhcoBHXba866lBZ3wvZz/fi8w9 MhFS43b2ZBxw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.82,231,1613462400"; d="scan'208";a="453918908" Received: from yguo18-skl-u1604.sh.intel.com ([10.239.159.53]) by fmsmga002.fm.intel.com with ESMTP; 18 Apr 2021 03:19:50 -0700 From: "Guo, Yejun" To: ffmpeg-devel@ffmpeg.org Date: Sun, 18 Apr 2021 18:07:57 +0800 Message-Id: <20210418100802.19017-1-yejun.guo@intel.com> X-Mailer: git-send-email 2.17.1 Subject: [FFmpeg-devel] [PATCH 1/6] lavfi/dnn_backend_openvino.c: unify code for infer request for sync/async X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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: yejun.guo@intel.com MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: 6NUzfpGiTZMJ Content-Length: 4508 --- libavfilter/dnn/dnn_backend_openvino.c | 49 +++++++++++--------------- 1 file changed, 21 insertions(+), 28 deletions(-) diff --git a/libavfilter/dnn/dnn_backend_openvino.c b/libavfilter/dnn/dnn_backend_openvino.c index 0757727a9c..874354ecef 100644 --- a/libavfilter/dnn/dnn_backend_openvino.c +++ b/libavfilter/dnn/dnn_backend_openvino.c @@ -52,9 +52,6 @@ typedef struct OVModel{ ie_core_t *core; ie_network_t *network; ie_executable_network_t *exe_network; - ie_infer_request_t *infer_request; - - /* for async execution */ SafeQueue *request_queue; // holds RequestItem Queue *task_queue; // holds TaskItem } OVModel; @@ -269,12 +266,9 @@ static void infer_completion_callback(void *args) ie_blob_free(&output_blob); request->task_count = 0; - - if (task->async) { - if (ff_safe_queue_push_back(requestq, request) < 0) { - av_log(ctx, AV_LOG_ERROR, "Failed to push back request_queue.\n"); - return; - } + if (ff_safe_queue_push_back(requestq, request) < 0) { + av_log(ctx, AV_LOG_ERROR, "Failed to push back request_queue.\n"); + return; } } @@ -347,11 +341,6 @@ static DNNReturnType init_model_ov(OVModel *ov_model, const char *input_name, co goto err; } - // create infer_request for sync execution - status = ie_exec_network_create_infer_request(ov_model->exe_network, &ov_model->infer_request); - if (status != OK) - goto err; - // create infer_requests for async execution if (ctx->options.nireq <= 0) { // the default value is a rough estimation @@ -502,10 +491,9 @@ static DNNReturnType get_output_ov(void *model, const char *input_name, int inpu OVModel *ov_model = model; OVContext *ctx = &ov_model->ctx; TaskItem task; - RequestItem request; + RequestItem *request; AVFrame *in_frame = NULL; AVFrame *out_frame = NULL; - TaskItem *ptask = &task; IEStatusCode status; input_shapes_t input_shapes; @@ -557,11 +545,16 @@ static DNNReturnType get_output_ov(void *model, const char *input_name, int inpu task.out_frame = out_frame; task.ov_model = ov_model; - request.infer_request = ov_model->infer_request; - request.task_count = 1; - request.tasks = &ptask; + request = ff_safe_queue_pop_front(ov_model->request_queue); + if (!request) { + av_frame_free(&out_frame); + av_frame_free(&in_frame); + av_log(ctx, AV_LOG_ERROR, "unable to get infer request.\n"); + return DNN_ERROR; + } + request->tasks[request->task_count++] = &task; - ret = execute_model_ov(&request); + ret = execute_model_ov(request); *output_width = out_frame->width; *output_height = out_frame->height; @@ -633,8 +626,7 @@ DNNReturnType ff_dnn_execute_model_ov(const DNNModel *model, const char *input_n OVModel *ov_model = model->model; OVContext *ctx = &ov_model->ctx; TaskItem task; - RequestItem request; - TaskItem *ptask = &task; + RequestItem *request; if (!in_frame) { av_log(ctx, AV_LOG_ERROR, "in frame is NULL when execute model.\n"); @@ -674,11 +666,14 @@ DNNReturnType ff_dnn_execute_model_ov(const DNNModel *model, const char *input_n task.out_frame = out_frame; task.ov_model = ov_model; - request.infer_request = ov_model->infer_request; - request.task_count = 1; - request.tasks = &ptask; + request = ff_safe_queue_pop_front(ov_model->request_queue); + if (!request) { + av_log(ctx, AV_LOG_ERROR, "unable to get infer request.\n"); + return DNN_ERROR; + } + request->tasks[request->task_count++] = &task; - return execute_model_ov(&request); + return execute_model_ov(request); } DNNReturnType ff_dnn_execute_model_async_ov(const DNNModel *model, const char *input_name, AVFrame *in_frame, @@ -821,8 +816,6 @@ void ff_dnn_free_model_ov(DNNModel **model) } ff_queue_destroy(ov_model->task_queue); - if (ov_model->infer_request) - ie_infer_request_free(&ov_model->infer_request); if (ov_model->exe_network) ie_exec_network_free(&ov_model->exe_network); if (ov_model->network)