[FFmpeg-devel] [PATCH 18/23] dnn/dnn_backend_native_layer_conv2d: Avoid separate, unchecked allocations

Guo, Yejun yejun.guo at intel.com
Thu Mar 11 09:05:43 EET 2021



> -----Original Message-----
> From: ffmpeg-devel <ffmpeg-devel-bounces at ffmpeg.org> On Behalf Of
> Andreas Rheinhardt
> Sent: 2021年3月11日 5:55
> To: ffmpeg-devel at ffmpeg.org
> Cc: Andreas Rheinhardt <andreas.rheinhardt at gmail.com>
> Subject: [FFmpeg-devel] [PATCH 18/23]
> dnn/dnn_backend_native_layer_conv2d: Avoid separate, unchecked
> allocations
> 
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at gmail.com>
> ---
>  .../dnn/dnn_backend_native_layer_conv2d.c        | 16 ++++++----------
>  1 file changed, 6 insertions(+), 10 deletions(-)
> 
> diff --git a/libavfilter/dnn/dnn_backend_native_layer_conv2d.c
> b/libavfilter/dnn/dnn_backend_native_layer_conv2d.c
> index c2073a02de..94a07c1fdb 100644
> --- a/libavfilter/dnn/dnn_backend_native_layer_conv2d.c
> +++ b/libavfilter/dnn/dnn_backend_native_layer_conv2d.c
> @@ -191,7 +191,7 @@ int ff_dnn_execute_layer_conv2d(DnnOperand
> *operands, const int32_t *input_opera
>      int thread_num = (ctx->options.conv2d_threads <= 0 ||
> ctx->options.conv2d_threads > av_cpu_count())
>          ? (av_cpu_count() + 1) : (ctx->options.conv2d_threads);
>      int thread_stride;
> -    ThreadParam **thread_param;
> +    ThreadParam *thread_param;
>  #else
>      ThreadParam thread_param = { 0 };
>  #endif
> @@ -231,22 +231,18 @@ int ff_dnn_execute_layer_conv2d(DnnOperand
> *operands, const int32_t *input_opera
>      thread_stride = (height - pad_size * 2) / thread_num;
>      //create threads
>      for (int i = 0; i < thread_num; i++){
> -        thread_param[i] = av_malloc(sizeof(*thread_param[0]));
> -        thread_param[i]->thread_common_param =
> &thread_common_param;
> -        thread_param[i]->thread_start = thread_stride * i + pad_size;
> -        thread_param[i]->thread_end = (i == thread_num - 1) ? (height -
> pad_size) : (thread_param[i]->thread_start + thread_stride);
> -        pthread_create(&thread_param[i]->thread, NULL,
> dnn_execute_layer_conv2d_thread, (void *)thread_param[i]);
> +        thread_param[i].thread_common_param =
> &thread_common_param;
> +        thread_param[i].thread_start = thread_stride * i + pad_size;
> +        thread_param[i].thread_end = (i == thread_num - 1) ? (height -
> pad_size) : (thread_param[i].thread_start + thread_stride);
> +        pthread_create(&thread_param[i].thread, NULL,
> + dnn_execute_layer_conv2d_thread, &thread_param[i]);
>      }
> 
>      //join threads, res gets function return
>      for (int i = 0; i < thread_num; i++){
> -        pthread_join(thread_param[i]->thread, NULL);
> +        pthread_join(thread_param[i].thread, NULL);
>      }
> 
>      //release memory
> -    for (int i = 0; i < thread_num; i++){
> -        av_freep(&thread_param[i]);
> -    }
>      av_free(thread_param);
>  #else
>      thread_param.thread_common_param = &thread_common_param;
> --

LGTM, thanks.



More information about the ffmpeg-devel mailing list