From patchwork Sun Jul 11 16:15:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shubhanshu Saxena X-Patchwork-Id: 28883 Delivered-To: andriy.gelman@gmail.com Received: by 2002:a25:bbc9:0:0:0:0:0 with SMTP id c9csp2220099ybk; Sun, 11 Jul 2021 09:15:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzOnWEVC8LhnqlbU0hP7mRo2U8odhLJ7mlMD278DzK5R8dZKo530my2f1BQ/qvCDz0oXevu X-Received: by 2002:a17:906:2752:: with SMTP id a18mr50836128ejd.458.1626020126439; Sun, 11 Jul 2021 09:15:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626020126; cv=none; d=google.com; s=arc-20160816; b=mYaizBz37RoQJeBoLvWumhh3Wdmngp+6U4iZLmLhJPQhZBUFZV7SyTVYadECpmMCiM iLVK+VqEiM5gyCT7xjAC5aVOu3na/ZeP7zHhw1Wtv9KHHedOfJ8j8PPQYgDSqFKBxdOx c1T3MgDtnI/ELRrcS5v0+XjjsQPRPy8frZvz1iYaG9CyGJU30BOzQLd8gsxFITUe3KHC Il9fspV088MpMa1PWZvPLXhxSMZi/4lJmJszk4gLXN0M2oSrKjh9vf13tcc7lAno6KUc InOX9YHPTXIa7af3yLasFhe3kJQcfmzlWnSzGMf8ulcP/T5/KMi8ximb8qCQxkZesgtZ X+BQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:message-id:date:to:from :dkim-signature:delivered-to; bh=IYFiZl98s5npkm7il5aKORcNGVgrwfK47+yH1LDMBro=; b=ADSdzSx6RhANfuNFJbv7ADAU2OFGbIcUswikG/f/qsgd82hWIHgzQ9/ADGd1imsR1L HSh/p+gpyo6Qp5w4l1JcFWs7cPsU57GJj/4Uv6b5WGwM8mP+a/EGH2Ltt9bbam47OKRb /YhFOp8fW9jFIsOEYqmU4LLZTvyWwpM2Q4Tau+XIkE2W8mAkuhkM+uabNNcWs3td1AXy hrPYU6JGGdRMseJujGgbdshrrAz6xedooTA5g+agV2lfhl2DosJsp0XN/T3MnAZAsT94 JTh5GacbytbPB881pEXtHwlt1r/xLUW04IIaSGzfPCayzeKCGCkr0kLZO76fYtxhbbW7 Mu1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=Bkw+riub; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id gv16si3864033ejb.111.2021.07.11.09.15.25; Sun, 11 Jul 2021 09:15:26 -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; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=Bkw+riub; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 631CD6802C0; Sun, 11 Jul 2021 19:15:24 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pg1-f175.google.com (mail-pg1-f175.google.com [209.85.215.175]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E32BE6802C0 for ; Sun, 11 Jul 2021 19:15:17 +0300 (EEST) Received: by mail-pg1-f175.google.com with SMTP id s18so219658pgq.3 for ; Sun, 11 Jul 2021 09:15:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=hLvqZZIOx2Ei3MHlczTeSaVFUMYHC6k4syik8Gfr2ko=; b=Bkw+riubdI3ZbGYgieKChil8OfibC4yungm3QGqmoOkYj5aHxddRwBw08xH3aHEf+n tcm618+mB8vBMqGUx+/Ww5uAD3yn6eJWXrFYdBxqW+JxB1H2erMQ+TMezTVFX/LBuLQ9 AzAS9UzURqq/Ib3cCT6IV98UhGXUrILjfD8GZ+i5TSJ2kpcDUyaEr7OOxILcZh7EKMO2 xYfdJVyl6ipDO0DvxlUBKOmQhXWM9QCd2fZRIu4vi/O2Vh1u+Eh8NuWHV8/bOstt4VBy bjoNUSZMxnPkVfCJK5+577PydJWarwOXNKshysZ3HwB3meAtbSbgQ4L8X9lV4gWv8IBr fPYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=hLvqZZIOx2Ei3MHlczTeSaVFUMYHC6k4syik8Gfr2ko=; b=Sw4Y/3E0wHjL9PqQpOOYh2D4bmSM/xRaZAb9LO4I5mPqQDCQ7gmx6gE908oTycZT7o fGn1van6qpbxwbPx5bmGBi3oMeykk0tunfs+YB5DqipfQTt8BTit0whXixfl3LcD0dde tJM6YH2OESszyiMQWWk3SARgpH1OZSWswFxwPDBWkh875izdUaFBpFQ4rjeeQyB8Ym6y RRpgLoKd4aV8gnQvE2ro4YGMU9+fgFxsXFvPpQiYqVp2J/dTU9XqvFY9CGjTzi+Mx9GZ +hzSBXXvJiij3rx6B9uKb3RBrdTsXQM1vQyjsfGYoo701AtKihAlzVGIvOqkxtOkObm3 QJfA== X-Gm-Message-State: AOAM531uN+vOeC2SxsefjB/sX8myiYBRbnSQrV6r95HqNlqa1+dDuEtI XIc0oYJ10qppnkmk+xMEx1I9aRIjADKUtw== X-Received: by 2002:a63:e211:: with SMTP id q17mr26923763pgh.363.1626020116011; Sun, 11 Jul 2021 09:15:16 -0700 (PDT) Received: from localhost.localdomain ([103.157.221.209]) by smtp.googlemail.com with ESMTPSA id j13sm9982617pjl.1.2021.07.11.09.15.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 11 Jul 2021 09:15:15 -0700 (PDT) From: Shubhanshu Saxena To: ffmpeg-devel@ffmpeg.org Date: Sun, 11 Jul 2021 21:45:01 +0530 Message-Id: <20210711161502.53155-1-shubhanshu.e01@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/2] lavfi/dnn_backend_openvino.c: Fix Memory Leak in execute_model_ov 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: Shubhanshu Saxena Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: ZR9o1N3YNReJ Content-Length: 1912 In cases where the execution inside the function execute_model_ov fails, the OVRequestItem must be pushed back to the request_queue before returning the error. In case pushing back fails, release the allocated memory. Signed-off-by: Shubhanshu Saxena --- libavfilter/dnn/dnn_backend_openvino.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libavfilter/dnn/dnn_backend_openvino.c b/libavfilter/dnn/dnn_backend_openvino.c index f34b8150f5..b340859c12 100644 --- a/libavfilter/dnn/dnn_backend_openvino.c +++ b/libavfilter/dnn/dnn_backend_openvino.c @@ -432,6 +432,8 @@ static DNNReturnType execute_model_ov(RequestItem *request, Queue *inferenceq) OVModel *ov_model; if (ff_queue_size(inferenceq) == 0) { + ie_infer_request_free(&request->infer_request); + av_freep(&request); return DNN_SUCCESS; } @@ -443,7 +445,7 @@ static DNNReturnType execute_model_ov(RequestItem *request, Queue *inferenceq) if (task->async) { ret = fill_model_input_ov(ov_model, request); if (ret != DNN_SUCCESS) { - return ret; + goto err; } status = ie_infer_set_completion_callback(request->infer_request, &request->callback); if (status != OK) { @@ -459,7 +461,7 @@ static DNNReturnType execute_model_ov(RequestItem *request, Queue *inferenceq) } else { ret = fill_model_input_ov(ov_model, request); if (ret != DNN_SUCCESS) { - return ret; + goto err; } status = ie_infer_request_infer(request->infer_request); if (status != OK) { From patchwork Sun Jul 11 16:15:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shubhanshu Saxena X-Patchwork-Id: 28888 Delivered-To: andriy.gelman@gmail.com Received: by 2002:a25:bbc9:0:0:0:0:0 with SMTP id c9csp2220216ybk; Sun, 11 Jul 2021 09:15:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzAkaZVR2iJ2rUnWoAn4INYFtrh+fJDeClOfXK2J2YbqfFQSt5CczfPBc/Ss6+rPFhUHZr+ X-Received: by 2002:a50:9b06:: with SMTP id o6mr61271584edi.284.1626020137922; Sun, 11 Jul 2021 09:15:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626020137; cv=none; d=google.com; s=arc-20160816; b=sE29drb2egruzdI0yGeN5C/O7zXb85al+QWBH5CTh3uKrtXq9CK0vH4rwMm32mt0NK XOJmCq2v41QowMZRDRP2a7K8dwhhUBTsnXJKd9U32/7IzyJ+D2MJq2ziyEG4RW08PxpV B752JqQydzWNIsT5QBxhwEZ6AQuMwZJNPT9iV5F+IdKelD0pFw9d38/rT+CFl0uYJNjX 0G7vkfZz4MzaEaBN9Dcw4Bepy3867tC9WI8lK13lKlziHnu41Jk0wd0mi7jWv8Lgk1iL Wt2Av8+rXNx5OcUeTD86y6DgvDuWUjMS5R3XQ5/pbInDlZ/35OBRcFCXt58H3fjXjvYH XIuw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to; bh=a610SdCRKfORtoocVaW1z0Qy2GiiDYHkbIoez7WnyvY=; b=XxPRlIBZsU5ynBNzGpNhFBpgQs2CRVchNsjeeQPzc3pQ9dwCi6ts0UJfQo/43OJaIP iQDdFDnuQWiE1TztEUIW4TyN48bVPH5lQZWvWKd6pKKk8OG4piPO60Jb2HfT4N1D0pek JjWcpQ6HUGS9EMhxGORR4rCjpEDrzKYljPLRvZBC173gX8MzB9TRegwZzpmYmbXkmLgY x/VVOVyj5yIHoAO64z1coaJS9Z5ahuRHeqxDBeIfXrRW9MIYzH2uE08m7L4JOlFTZ6FY uE6I+34+B/2DbSxfivW/rHM5rlvplS+P98oBee79EkHBaHJzc5SLqD45HJCD+KtC0M9a 5+gg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=TIB8XQ5S; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id ho14si13879300ejc.252.2021.07.11.09.15.37; Sun, 11 Jul 2021 09:15:37 -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; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=TIB8XQ5S; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9514368A7C2; Sun, 11 Jul 2021 19:15:36 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pg1-f179.google.com (mail-pg1-f179.google.com [209.85.215.179]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1F96568A791 for ; Sun, 11 Jul 2021 19:15:30 +0300 (EEST) Received: by mail-pg1-f179.google.com with SMTP id a2so15508371pgi.6 for ; Sun, 11 Jul 2021 09:15:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=YQg1V51LNjf7a0jjUPA3TGJQauV8wqQcCV7gkpC9f3Q=; b=TIB8XQ5SQ6yaeanS9rEtYXC35uObOI9TL4E9Jk7tz8lixX2D5kkxeFJABobV6fswwa NBssRY+QRG6S9tffKICcFDBnQqGoOHn1icI4rexw4Hx0hkGp9XCKxPvRed/M4mn9UWd6 5GIRf7OoQYBw9Dmx2OyZZKZmWLxa8PGkaNaozwm/UMO/dmXCz2ijjed89uGC/mvkj6/i B5J99XG8lBYlMODgCKmRnXf2TzxGugvktMZ4VpCJdOXexqnrI/I5rMrIhTM9PI9hhR5G DseTuxA/rE2mfxzVqdKN5SyhMfnGpF7pHSvxaW+s7kSi8H/6jY8J/tn0N+L1ffYDYL14 Q+5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=YQg1V51LNjf7a0jjUPA3TGJQauV8wqQcCV7gkpC9f3Q=; b=hw80tLz4VYLqaLeizvGnd4qJOGiOC50485iRcjI+AoPSA3XiCPDiAcuPIF9H2+yOAo BEwfPYHYCTvfmYaDVC1qCZL5M2fHrFNy+i/OXr+pNklb3F207Aa81h0yymPpH+p6lTaC kBDl3PYrSia+s0dt+MvBJjm+M5uMkk1cZE2B5nSjSGIkltxsM8XNBbI9t15ZiXEq+CIf kKQ58VHiEb4dCcU4LEBHTdI6rtj7xK6xrVZY7csuQXJr/EaZ7wnaUlAR6yNFYu7s/Rg9 r6fvVW+ldShqA92GZaY3lm9kLKJkLF1QOsbDxkktwFu+kG+gpj1FFBYeiYvxj4KAYf6j ipzg== X-Gm-Message-State: AOAM5333ecU/ltfiXa9NFHCKUaeHyD/gEd3MzuuA1JrheYmIcHxExBCF Jn8rAqfUYR81k5Q5qcVO2OECL6myiOLxUw== X-Received: by 2002:a62:7545:0:b029:327:90e9:d4b4 with SMTP id q66-20020a6275450000b029032790e9d4b4mr20788421pfc.39.1626020128414; Sun, 11 Jul 2021 09:15:28 -0700 (PDT) Received: from localhost.localdomain ([103.157.221.209]) by smtp.googlemail.com with ESMTPSA id j13sm9982617pjl.1.2021.07.11.09.15.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 11 Jul 2021 09:15:28 -0700 (PDT) From: Shubhanshu Saxena To: ffmpeg-devel@ffmpeg.org Date: Sun, 11 Jul 2021 21:45:02 +0530 Message-Id: <20210711161502.53155-2-shubhanshu.e01@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210711161502.53155-1-shubhanshu.e01@gmail.com> References: <20210711161502.53155-1-shubhanshu.e01@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/2] lavfi/dnn_backend_ov: Rename RequestItem to OVRequestItem 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: Shubhanshu Saxena Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: N8Yq7cxzPuSQ Content-Length: 4589 Rename RequestItem to OVRequestItem in the OpenVINO backend to avoid confusion. Signed-off-by: Shubhanshu Saxena --- libavfilter/dnn/dnn_backend_openvino.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/libavfilter/dnn/dnn_backend_openvino.c b/libavfilter/dnn/dnn_backend_openvino.c index b340859c12..f8d548feaf 100644 --- a/libavfilter/dnn/dnn_backend_openvino.c +++ b/libavfilter/dnn/dnn_backend_openvino.c @@ -54,18 +54,18 @@ typedef struct OVModel{ ie_core_t *core; ie_network_t *network; ie_executable_network_t *exe_network; - SafeQueue *request_queue; // holds RequestItem + SafeQueue *request_queue; // holds OVRequestItem Queue *task_queue; // holds TaskItem Queue *inference_queue; // holds InferenceItem } OVModel; // one request for one call to openvino -typedef struct RequestItem { +typedef struct OVRequestItem { ie_infer_request_t *infer_request; InferenceItem **inferences; uint32_t inference_count; ie_complete_call_back_t callback; -} RequestItem; +} OVRequestItem; #define APPEND_STRING(generated_string, iterate_string) \ generated_string = generated_string ? av_asprintf("%s %s", generated_string, iterate_string) : \ @@ -111,7 +111,7 @@ static int get_datatype_size(DNNDataType dt) } } -static DNNReturnType fill_model_input_ov(OVModel *ov_model, RequestItem *request) +static DNNReturnType fill_model_input_ov(OVModel *ov_model, OVRequestItem *request) { dimensions_t dims; precision_e precision; @@ -198,7 +198,7 @@ static void infer_completion_callback(void *args) dimensions_t dims; precision_e precision; IEStatusCode status; - RequestItem *request = args; + OVRequestItem *request = args; InferenceItem *inference = request->inferences[0]; TaskItem *task = inference->task; OVModel *ov_model = task->model; @@ -381,7 +381,7 @@ static DNNReturnType init_model_ov(OVModel *ov_model, const char *input_name, co } for (int i = 0; i < ctx->options.nireq; i++) { - RequestItem *item = av_mallocz(sizeof(*item)); + OVRequestItem *item = av_mallocz(sizeof(*item)); if (!item) { goto err; } @@ -422,7 +422,7 @@ err: return DNN_ERROR; } -static DNNReturnType execute_model_ov(RequestItem *request, Queue *inferenceq) +static DNNReturnType execute_model_ov(OVRequestItem *request, Queue *inferenceq) { IEStatusCode status; DNNReturnType ret; @@ -639,7 +639,7 @@ 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; + OVRequestItem *request; AVFrame *in_frame = NULL; AVFrame *out_frame = NULL; IEStatusCode status; @@ -779,7 +779,7 @@ DNNReturnType ff_dnn_execute_model_ov(const DNNModel *model, DNNExecBaseParams * OVModel *ov_model = model->model; OVContext *ctx = &ov_model->ctx; TaskItem task; - RequestItem *request; + OVRequestItem *request; if (ff_check_exec_params(ctx, DNN_OV, model->func_type, exec_params) != 0) { return DNN_ERROR; @@ -827,7 +827,7 @@ DNNReturnType ff_dnn_execute_model_async_ov(const DNNModel *model, DNNExecBasePa { OVModel *ov_model = model->model; OVContext *ctx = &ov_model->ctx; - RequestItem *request; + OVRequestItem *request; TaskItem *task; DNNReturnType ret; @@ -904,7 +904,7 @@ DNNReturnType ff_dnn_flush_ov(const DNNModel *model) { OVModel *ov_model = model->model; OVContext *ctx = &ov_model->ctx; - RequestItem *request; + OVRequestItem *request; IEStatusCode status; DNNReturnType ret; @@ -943,7 +943,7 @@ void ff_dnn_free_model_ov(DNNModel **model) if (*model){ OVModel *ov_model = (*model)->model; while (ff_safe_queue_size(ov_model->request_queue) != 0) { - RequestItem *item = ff_safe_queue_pop_front(ov_model->request_queue); + OVRequestItem *item = ff_safe_queue_pop_front(ov_model->request_queue); if (item && item->infer_request) { ie_infer_request_free(&item->infer_request); }