From: wenbin.chen-at-intel.com@ffmpeg.org To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH] libavfilter/dnn/openvino: Reduce redundant memory allocation Date: Thu, 9 Nov 2023 16:13:10 +0800 Message-ID: <20231109081310.192517-1-wenbin.chen@intel.com> (raw) From: Wenbin Chen <wenbin.chen@intel.com> We can directly get data ptr from tensor, so that extral memory allocation can be removed. Signed-off-by: Wenbin Chen <wenbin.chen@intel.com> --- libavfilter/dnn/dnn_backend_openvino.c | 42 +++++++++++++------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/libavfilter/dnn/dnn_backend_openvino.c b/libavfilter/dnn/dnn_backend_openvino.c index 10520cd765..d3af8c34ce 100644 --- a/libavfilter/dnn/dnn_backend_openvino.c +++ b/libavfilter/dnn/dnn_backend_openvino.c @@ -204,7 +204,6 @@ static int fill_model_input_ov(OVModel *ov_model, OVRequestItem *request) ov_tensor_t* tensor = NULL; ov_shape_t input_shape = {0}; ov_element_type_e precision; - void *input_data_ptr = NULL; #else dimensions_t dims; precision_e precision; @@ -249,12 +248,6 @@ static int fill_model_input_ov(OVModel *ov_model, OVRequestItem *request) input.width = dims[2]; input.channels = dims[3]; input.dt = precision_to_datatype(precision); - input.data = av_malloc(input.height * input.width * input.channels * get_datatype_size(input.dt)); - if (!input.data) { - ov_shape_free(&input_shape); - return AVERROR(ENOMEM); - } - input_data_ptr = input.data; #else status = ie_infer_request_get_blob(request->infer_request, task->input_name, &input_blob); if (status != OK) { @@ -297,6 +290,26 @@ static int fill_model_input_ov(OVModel *ov_model, OVRequestItem *request) request->lltasks[i] = lltask; request->lltask_count = i + 1; task = lltask->task; +#if HAVE_OPENVINO2 + if (tensor) + ov_tensor_free(tensor); + status = ov_tensor_create(precision, input_shape, &tensor); + ov_shape_free(&input_shape); + if (status != OK) { + av_log(ctx, AV_LOG_ERROR, "Failed to create tensor from host prt.\n"); + return ov2_map_error(status, NULL); + } + status = ov_tensor_data(tensor, &input.data); + if (status != OK) { + av_log(ctx, AV_LOG_ERROR, "Failed to get input data.\n"); + return ov2_map_error(status, NULL); + } + status = ov_infer_request_set_input_tensor(request->infer_request, tensor); + if (status != OK) { + av_log(ctx, AV_LOG_ERROR, "Failed to Set an input tensor for the model.\n"); + return ov2_map_error(status, NULL); + } +#endif switch (ov_model->model->func_type) { case DFT_PROCESS_FRAME: if (task->do_ioproc) { @@ -317,24 +330,11 @@ static int fill_model_input_ov(OVModel *ov_model, OVRequestItem *request) av_assert0(!"should not reach here"); break; } -#if HAVE_OPENVINO2 - status = ov_tensor_create_from_host_ptr(precision, input_shape, input.data, &tensor); - ov_shape_free(&input_shape); - if (status != OK) { - av_log(ctx, AV_LOG_ERROR, "Failed to create tensor from host prt.\n"); - return ov2_map_error(status, NULL); - } - status = ov_infer_request_set_input_tensor(request->infer_request, tensor); - if (status != OK) { - av_log(ctx, AV_LOG_ERROR, "Failed to Set an input tensor for the model.\n"); - return ov2_map_error(status, NULL); - } -#endif input.data = (uint8_t *)input.data + input.width * input.height * input.channels * get_datatype_size(input.dt); } #if HAVE_OPENVINO2 - av_freep(&input_data_ptr); + ov_tensor_free(tensor); #else ie_blob_free(&input_blob); #endif -- 2.34.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
next reply other threads:[~2023-11-09 8:13 UTC|newest] Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-11-09 8:13 wenbin.chen-at-intel.com [this message] 2023-11-10 12:31 ` Guo, Yejun
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20231109081310.192517-1-wenbin.chen@intel.com \ --to=wenbin.chen-at-intel.com@ffmpeg.org \ --cc=ffmpeg-devel@ffmpeg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git