[FFmpeg-devel] [PATCH] libavfilter/opencl.h: Add macro for setting opencl kernel arguments
Danil Iashchenko
danyaschenko at gmail.com
Sat Jun 2 19:58:22 EEST 2018
---
libavfilter/opencl.h | 13 +++++++++++
libavfilter/vf_convolution_opencl.c | 43 ++++++-------------------------------
2 files changed, 19 insertions(+), 37 deletions(-)
diff --git a/libavfilter/opencl.h b/libavfilter/opencl.h
index c0a4519..16cdfbe 100644
--- a/libavfilter/opencl.h
+++ b/libavfilter/opencl.h
@@ -46,6 +46,19 @@ typedef struct OpenCLFilterContext {
int output_height;
} OpenCLFilterContext;
+
+/**
+ * set argument to specific Kernel.
+ * This macro relies on usage of local label "fail" and variable avctx.
+ */
+#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' " \
+ "%d argument. Error code:%d.\n", arg_num, cle); \
+ goto fail; \
+ } \
+
/**
* Return that all inputs and outputs support only AV_PIX_FMT_OPENCL.
*/
diff --git a/libavfilter/vf_convolution_opencl.c b/libavfilter/vf_convolution_opencl.c
index 2df51e0..4d0ecf8 100644
--- a/libavfilter/vf_convolution_opencl.c
+++ b/libavfilter/vf_convolution_opencl.c
@@ -204,43 +204,12 @@ static int convolution_opencl_filter_frame(AVFilterLink *inlink, AVFrame *input)
if (!dst)
break;
- cle = clSetKernelArg(ctx->kernel, 0, sizeof(cl_mem), &dst);
- if (cle != CL_SUCCESS) {
- av_log(avctx, AV_LOG_ERROR, "Failed to set kernel "
- "destination image argument: %d.\n", cle);
- goto fail;
- }
- cle = clSetKernelArg(ctx->kernel, 1, sizeof(cl_mem), &src);
- if (cle != CL_SUCCESS) {
- av_log(avctx, AV_LOG_ERROR, "Failed to set kernel "
- "source image argument: %d.\n", cle);
- goto fail;
- }
- cle = clSetKernelArg(ctx->kernel, 2, sizeof(cl_int), &ctx->dims[p]);
- if (cle != CL_SUCCESS) {
- av_log(avctx, AV_LOG_ERROR, "Failed to set kernel "
- "matrix size argument: %d.\n", cle);
- goto fail;
- }
- cle = clSetKernelArg(ctx->kernel, 3, sizeof(cl_mem), &ctx->matrix[p]);
- if (cle != CL_SUCCESS) {
- av_log(avctx, AV_LOG_ERROR, "Failed to set kernel "
- "matrix argument: %d.\n", cle);
- goto fail;
- }
- cle = clSetKernelArg(ctx->kernel, 4, sizeof(cl_float), &ctx->rdivs[p]);
- if (cle != CL_SUCCESS) {
- av_log(avctx, AV_LOG_ERROR, "Failed to set kernel "
- "rdiv argument: %d.\n", cle);
- goto fail;
- }
- cle = clSetKernelArg(ctx->kernel, 5, sizeof(cl_float), &ctx->biases[p]);
- if (cle != CL_SUCCESS) {
- av_log(avctx, AV_LOG_ERROR, "Failed to set kernel "
- "bias argument: %d.\n", cle);
- goto fail;
- }
-
+ CL_SET_KERNEL_ARG(ctx->kernel, 0, cl_mem, &dst);
+ CL_SET_KERNEL_ARG(ctx->kernel, 1, cl_mem, &src);
+ CL_SET_KERNEL_ARG(ctx->kernel, 2, cl_int, &ctx->dims[p]);
+ CL_SET_KERNEL_ARG(ctx->kernel, 3, cl_mem, &ctx->matrix[p]);
+ CL_SET_KERNEL_ARG(ctx->kernel, 4, cl_float, &ctx->rdivs[p]);
+ CL_SET_KERNEL_ARG(ctx->kernel, 5, cl_float, &ctx->biases[p]);
err = ff_opencl_filter_work_size_from_image(avctx, global_work, output, p, 0);
if (err < 0)
--
2.7.4
More information about the ffmpeg-devel
mailing list