From patchwork Mon Jul 5 10:30:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shubhanshu Saxena X-Patchwork-Id: 28784 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a5d:965a:0:0:0:0:0 with SMTP id d26csp4031721ios; Mon, 5 Jul 2021 03:39:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwL1bnRRCgTjJJpXvmd7t5TEiC9qoidFWIIYL6YdCrGO+QoFPihBdpqyUzKMf8Zf5eCvrTU X-Received: by 2002:a05:6402:88b:: with SMTP id e11mr15370287edy.21.1625481589689; Mon, 05 Jul 2021 03:39:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625481589; cv=none; d=google.com; s=arc-20160816; b=Mw7LOCVS5x60x7+u72SpXKtktI1LtnvdVLVl9+F1o7PjB4TtrNJ53SBo4HbErLhK9d RrMz09t7y6fbQlz/MSJE/22Axu1W6Zsc6lwm2Rza1O2SeT3dOy2OhXBNHsxD6iG+n6Zq VZIatZdVFHac9JMznokcV1dbugpqEmOM27B9fbhycVoa7Za1Es6FSYoHMWa89NsVWnTm 4iHkjsCuQjCAkppGG6IFb7RlbcB9sH3MLjLybU0nIcjBzZ6zn6dazMXTnEnQoX/+zZi4 uzEEdXTEIky00PqIR00eH5Sjx7Lgz7KRFxnyEWUoiOE4iarvCpIy3l4TNN7L117qaZpN Qn6A== 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=RpB6P6ODI9OWTQu78a/MBC8TvuDjm15fBCP1ESXLPak=; b=hwSjg1QWn2PGX8ZVQ+PuKLWH6yGLxoJP9PNMahMT/KPAIU3SqvTlUkThsN0ofWCxg2 Vro/XdgDod4sICjNZlFpW6O1xY+oO4Ezk5uHibI75l1D0f108bRYeoMS0WANITyfMCQa BJieYp5ZDNUuiBgMjsSU3iFYWHuDqJKRAhrS5epD0MRud6qmTJoaP9hAjGYtKrGXENuW MTslwU8C9CcCv9fgRg6dxGMi+MFEZpN9whYipxkMdBSwBBo/j1CLfQzmihPYgiGQsJAr fJ8J2/UpK4dTb36by95ruxYDSgm5kWzuuJvkSTZFPNTc/UnXrcFh8hCFBtJc2jySlxCQ lbMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=uAiZiric; 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 hs13si4639665ejc.150.2021.07.05.03.39.49; Mon, 05 Jul 2021 03:39:49 -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=uAiZiric; 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 82C1068A6B5; Mon, 5 Jul 2021 13:39:47 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 4897D68A5D7 for ; Mon, 5 Jul 2021 13:39:41 +0300 (EEST) Received: by mail-pf1-f179.google.com with SMTP id x16so16304574pfa.13 for ; Mon, 05 Jul 2021 03:39:41 -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=Y73bDz8K09pPg7xhjEErY122Ikc8CnH1/Z6WXm/Ad68=; b=uAiZiric4FlaTLdgAKP1J3bHFDgq4uaXuJnN7HQaIYpXoyoxg97o8oU3xeZN9P5yEk PtfnS+5sVkzv4MF6Z4Y9UPhplew8lSgWOZIRy12o0psQQfg179xAbzXKWeUBWlcBejDU lz12X1csLKvZsx4vyOMdnQ/pBbUj9fdZQFAw5kELmeyMR/o+DI2UEpAKqM1j5BYrOV/O 1CaknmQETrKY7jrKmbG8I2kNtv8/4y+Ude+KtK59iXVAzyG15fbJA9GVSqmlRxqfXSDK XbA0FjS9g9dxJKpId8EcpcBXR7ykQw+BrX3xM7zHWkPh1O6IShJcMwB3ahbxoW+3RrnA fc2g== 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=Y73bDz8K09pPg7xhjEErY122Ikc8CnH1/Z6WXm/Ad68=; b=Rm3Pzh9dv/W1THSV5iiPMZ4CWgqj0+svcSpyOvlTo6ol7ecN7nKangcuJqTDZrn3sI lKk0y2VYHAoVGHTw/pUMjWUuQvAN+C9a+FV5NSi8XtLecCooELEsfIZALh4fGf1B+84e RWlLdnwLVhMdT4VkZ5HuTTWirDVvoKkn62gkHpHCqh5ni1G6GyXNPRpAKgtc96kXZDKk WtOfLa3YwDTP1ChFep5IxhqKY+QQBqyoiSUb14u+Ax/TFTyIhLXzcom7XkygIzF1LWGK /GI6hihmFMkVnc6cAi2C76g8xWFQ06wQGR/kaIw42f1saICfkU9k2vlyBTu6bM2/qqwf zZqQ== X-Gm-Message-State: AOAM530mUqa0DsDP5EPsKmYt+464+GMNjpu56v8cPOSX+VCbgpyYFSya ZpH2CMjWETrZvc4+N7201b2VAKZ00QIcPw== X-Received: by 2002:a17:903:2452:b029:129:33a0:399d with SMTP id l18-20020a1709032452b029012933a0399dmr12163988pls.31.1625481089095; Mon, 05 Jul 2021 03:31:29 -0700 (PDT) Received: from Pavilion-x360.bbrouter ([103.133.121.113]) by smtp.googlemail.com with ESMTPSA id cx5sm13174242pjb.1.2021.07.05.03.31.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Jul 2021 03:31:28 -0700 (PDT) From: Shubhanshu Saxena To: ffmpeg-devel@ffmpeg.org Date: Mon, 5 Jul 2021 16:00:54 +0530 Message-Id: <20210705103057.42309-2-shubhanshu.e01@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210705103057.42309-1-shubhanshu.e01@gmail.com> References: <20210705103057.42309-1-shubhanshu.e01@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH V2 2/6] lavfi/dnn_backend_tf: Add TFInferRequest and TFRequestItem 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: m9ystMfelAFj This commit introduces a typedef TFInferRequest to store execution parameters for a single call to the TensorFlow C API. This typedef is used in the TFRequestItem. Signed-off-by: Shubhanshu Saxena --- libavfilter/dnn/dnn_backend_tf.c | 49 ++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/libavfilter/dnn/dnn_backend_tf.c b/libavfilter/dnn/dnn_backend_tf.c index 8762211ebc..578748eb35 100644 --- a/libavfilter/dnn/dnn_backend_tf.c +++ b/libavfilter/dnn/dnn_backend_tf.c @@ -56,6 +56,23 @@ typedef struct TFModel{ Queue *inference_queue; } TFModel; +/** + * Stores execution parameters for single + * call to the TensorFlow C API + */ +typedef struct TFInferRequest { + TF_Output *tf_outputs; + TF_Tensor **output_tensors; + TF_Output *tf_input; + TF_Tensor *input_tensor; +} TFInferRequest; + +typedef struct TFRequestItem { + TFInferRequest *infer_request; + InferenceItem *inference; + // further properties will be added later for async +} TFRequestItem; + #define OFFSET(x) offsetof(TFContext, x) #define FLAGS AV_OPT_FLAG_FILTERING_PARAM static const AVOption dnn_tensorflow_options[] = { @@ -72,6 +89,38 @@ static void free_buffer(void *data, size_t length) av_freep(&data); } +static void tf_free_request(TFInferRequest *request) +{ + if (!request) + return; + if (request->input_tensor) { + TF_DeleteTensor(request->input_tensor); + request->input_tensor = NULL; + } + av_freep(&request->tf_input); + av_freep(&request->tf_outputs); + if (request->output_tensors) { + int nb_output = sizeof(*request->output_tensors)/sizeof(request->output_tensors[0]); + for (uint32_t i = 0; i < nb_output; ++i) { + if (request->output_tensors[i]) { + TF_DeleteTensor(request->output_tensors[i]); + request->output_tensors[i] = NULL; + } + } + av_freep(&request->output_tensors); + } +} + +static TFInferRequest *tf_create_inference_request(void) +{ + TFInferRequest *infer_request = av_malloc(sizeof(TFInferRequest)); + infer_request->tf_outputs = NULL; + infer_request->tf_input = NULL; + infer_request->input_tensor = NULL; + infer_request->output_tensors = NULL; + return infer_request; +} + static DNNReturnType extract_inference_from_task(TaskItem *task, Queue *inference_queue) { InferenceItem *inference = av_malloc(sizeof(*inference));