[FFmpeg-devel] [PATCH] libavfilter/opencl.h: Add macro for setting opencl kernel

Song, Ruiling ruiling.song at intel.com
Wed Jun 13 05:14:36 EEST 2018



> -----Original Message-----
> From: ffmpeg-devel [mailto:ffmpeg-devel-bounces at ffmpeg.org] On Behalf Of
> Danil Iashchenko
> Sent: Tuesday, June 12, 2018 5:39 AM
> To: ffmpeg-devel at ffmpeg.org
> Cc: Danil Iashchenko <danyaschenko at gmail.com>
> Subject: [FFmpeg-devel] [PATCH] libavfilter/opencl.h: Add macro for setting
> opencl kernel
> 
> ---
>  libavfilter/opencl.h                | 15 ++++++++++
>  libavfilter/vf_convolution_opencl.c | 43 ++++------------------------
>  libavfilter/vf_overlay_opencl.c     | 44 +++++++++++-----------------
>  libavfilter/vf_unsharp_opencl.c     | 57 ++++++-------------------------------
>  4 files changed, 46 insertions(+), 113 deletions(-)
> 
> diff --git a/libavfilter/opencl.h b/libavfilter/opencl.h
> index c0a4519..7441b11 100644
> --- a/libavfilter/opencl.h
> +++ b/libavfilter/opencl.h
> @@ -46,6 +46,21 @@ typedef struct OpenCLFilterContext {
>      int                output_height;
>  } OpenCLFilterContext;
> 
> +
> +/**
> + * set argument to specific Kernel.
> + * This macro relies on usage of local label "fail" and variables:
> + * avctx, cle and err.
> + */
> +#define CL_SET_KERNEL_ARG(kernel, arg_num, type, arg)          \
> +    cle = clSetKernelArg(kernel, arg_num, sizeof(type), arg);  \
> +    if (cle != CL_SUCCESS) {                                   \
> +        av_log(avctx, AV_LOG_ERROR, "Failed to set kernel "    \
> +               "argument %d: error %d.\n", arg_num, cle);      \
> +        err = AVERROR(EIO);                                    \
> +        goto fail;                                             \
> +    }

> -            if (cle != CL_SUCCESS)
> -                goto fail_kernel_arg;
> +            CL_SET_KERNEL_ARG(ctx->kernel, kernel_arg, cl_int, &alpha_adj_x);
> +            kernel_arg++;
> +            CL_SET_KERNEL_ARG(ctx->kernel, kernel_arg, cl_int, &alpha_adj_y);
> +            kernel_arg++;
>          }
Hi Danil,

I think about this for some while. Instead of totally wrap the clSetKernelArg() together with the error handling.
I would rather provide a simple macro for OpenCL error handling, which may not reduce code complexity as much as this patch.
But people can still use clSetKernelArg(kernel, argIdx++,...) without explicitly separate the self-increment to a new line.
And also an dedicated OpenCL macro for error handling could benefit other OpenCL functions like clFinish() or clEnqueueNDRange() etc.
So I post a patch as: "[PATCH] lavfi: add helper macro for OpenCL error handling." Welcome your comment!

Ruiling
 



More information about the ffmpeg-devel mailing list