From patchwork Mon Jun 11 21:38:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danil Iashchenko X-Patchwork-Id: 9368 Delivered-To: ffmpegpatchwork@gmail.com Received: by 2002:a02:11c:0:0:0:0:0 with SMTP id c28-v6csp4649699jad; Mon, 11 Jun 2018 14:47:07 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLWckTKmX6oTFtTCwVldXCHxCxEj4CrSun27+pZpaRGtVHrZZf8xHNBSZQ6i6udi/685llG X-Received: by 2002:a1c:14cc:: with SMTP id 195-v6mr381119wmu.48.1528753627400; Mon, 11 Jun 2018 14:47:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528753627; cv=none; d=google.com; s=arc-20160816; b=D+eavZ5CPIjSwBmE8pgJ6QJWQzKo4HV9v8MQlfsqY7mxzZD8Yph98IXNlNie7cvA+t 4QMVR7Y5se8Ra+/3zBoxrM0CHuQMks/CGo1yWboHAk42kaHTXL/w2QRovToGtrjOe+gi qx/cq2odnGIN29jI+y29ckmgaIF0xR+AD+mYOdWj2e4Lw97QbKxc5AtVOT2ePp8RU+27 TEKujShB89V8Iuqkf2RMyN9Xv/DQ1yPXuhVW3AumHm55OZ+8oN4RwfQBQ59LYGO9atmg 3xpES8CU8Lwbstc39d8iurE/jpnM5+BHpemoByiSxWsPre0rKNTyFm3NcYN+l8IPSy6Q /T/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:dkim-signature:delivered-to:arc-authentication-results; bh=xve2VOWtrhozUtP81zYnCv0Jzu+qfp63SikKk8Vxyoc=; b=yRNh0ZjLdb+TYIU7xDd9pHZstWSopU4UU19Kp34h9XKIA7ecSv968o+uyqVUwA9VpW z4+qcBtIcKZuZY4fudbDlkjbtOEbr02Wd0FnpFph733vuzL3hMv7JPN+VUX7Qo8YlaOY WAujZbaL5oF2mrrCviUgbW84B9CwTf3ffmxAnbYV6dEQXUpwvGnE2nUsXQ5rr38tkI+D Ci//iFNOqqfHr+v6JrSR7rfhRcbKwqa7/1KzGyjL1i++0sSzxgwo+9DyCZYU06snLeFF 5VdBI7sbVtkk/ZuttpeNUnhmwHWPXQM8rMNhqw7PLR6NkGbhZXjzzdAbBSK+ddAQPCrh eVvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=ZqUuZvLq; 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 e9-v6si42929278wrg.249.2018.06.11.14.47.07; Mon, 11 Jun 2018 14:47:07 -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=ZqUuZvLq; 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 5650768AD8B; Tue, 12 Jun 2018 00:46:16 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf0-f65.google.com (mail-lf0-f65.google.com [209.85.215.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id ABF4168A986 for ; Tue, 12 Jun 2018 00:46:09 +0300 (EEST) Received: by mail-lf0-f65.google.com with SMTP id y20-v6so32887008lfy.0 for ; Mon, 11 Jun 2018 14:46:59 -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; bh=HE7Ad3wtkYxSDfAc5sn7tEV6mpnnjoL4ooUXuK3lM0k=; b=ZqUuZvLqxM8Qr+vAY3hyq4vLX9DTeiJkGOBuF9Y2Wm1g773YG1kPbM0b0RzDla48Bk A8odXdvw+JL6NMFH3YHIN56iEWlbZ5In+t/UCGasnTFCQkq+hbkfyyOvb7hmAgqUhPHb i5m90v6kN1YANDhyVkq0F1jMbbjsCz6RIZDozdo/7WAKsNmWET39HVpX1HLc5bYYRydO c0epB0BqKB71C40x3Tk881OGhHLkRIKy1zuuM4ebleygZ1y7e2KVBU6GrvBPbu4rt+Cu ZmtIrQRpgWgbLm+O61kg916T4NzZd16rL4+k1XvHkUlVJSAoMZh7RYVQ8oHkhEsqgOI5 w1lA== 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; bh=HE7Ad3wtkYxSDfAc5sn7tEV6mpnnjoL4ooUXuK3lM0k=; b=DzMa7aBdLHVQP83RDIpPtFx+FNFl7rkgCjn8wDscMNmBuxsAGet3EDU7MD1sWZ0seb viDW8+KKL5P/fVs8mFftQbUzoMdG1lsqzggTxaRsabssD8LdET4XKV8EM34liJiogVpv FhCqHZ0D+jf6JI3AkmnvZ/xyUlg1RjbJoKa7xQ3CdUzp8TxgcXPKxn95St1E42ymkhvq wLliz3Jn6RnRUmOGuJayG1w/XDVh8STfR1Z/4k7mJOgsvi9VTBSM2EFRw8yf5r/1WFjH 9Bsh08ChbFC+b5Fsa0AxmBqv2n1lSC8HabPhXjLTzvE5YkVbcrbPTmPRiBseSfQkjYEC +1dg== X-Gm-Message-State: APt69E175K9vPSQdI9iN5bj6Fhw04uQYQsMvWK4F5SlGRpTJHOtYai2n gElRzBQ6klo9kv9kO2hY6V9Lc7U= X-Received: by 2002:a19:1714:: with SMTP id n20-v6mr483724lfi.54.1528753163222; Mon, 11 Jun 2018 14:39:23 -0700 (PDT) Received: from dan-acer.lan (campus.ifmo.ru. [194.85.161.2]) by smtp.gmail.com with ESMTPSA id j7-v6sm5662297ljg.48.2018.06.11.14.39.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 11 Jun 2018 14:39:22 -0700 (PDT) From: Danil Iashchenko To: ffmpeg-devel@ffmpeg.org Date: Tue, 12 Jun 2018 00:38:47 +0300 Message-Id: <1528753127-910-1-git-send-email-danyaschenko@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: References: Subject: [FFmpeg-devel] [PATCH] libavfilter/opencl.h: Add macro for setting opencl kernel X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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: Danil Iashchenko MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" --- 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; \ + } + /** * 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) diff --git a/libavfilter/vf_overlay_opencl.c b/libavfilter/vf_overlay_opencl.c index b43050d..556ce35 100644 --- a/libavfilter/vf_overlay_opencl.c +++ b/libavfilter/vf_overlay_opencl.c @@ -167,47 +167,39 @@ static int overlay_opencl_blend(FFFrameSync *fs) kernel_arg = 0; mem = (cl_mem)output->data[plane]; - cle = clSetKernelArg(ctx->kernel, kernel_arg++, sizeof(cl_mem), &mem); - if (cle != CL_SUCCESS) - goto fail_kernel_arg; + CL_SET_KERNEL_ARG(ctx->kernel, kernel_arg, cl_mem, &mem); + kernel_arg++; mem = (cl_mem)input_main->data[plane]; - cle = clSetKernelArg(ctx->kernel, kernel_arg++, sizeof(cl_mem), &mem); - if (cle != CL_SUCCESS) - goto fail_kernel_arg; + CL_SET_KERNEL_ARG(ctx->kernel, kernel_arg, cl_mem, &mem); + kernel_arg++; mem = (cl_mem)input_overlay->data[plane]; - cle = clSetKernelArg(ctx->kernel, kernel_arg++, sizeof(cl_mem), &mem); - if (cle != CL_SUCCESS) - goto fail_kernel_arg; + CL_SET_KERNEL_ARG(ctx->kernel, kernel_arg, cl_mem, &mem); + kernel_arg++; if (ctx->alpha_separate) { mem = (cl_mem)input_overlay->data[ctx->nb_planes]; - cle = clSetKernelArg(ctx->kernel, kernel_arg++, sizeof(cl_mem), &mem); - if (cle != CL_SUCCESS) - goto fail_kernel_arg; + CL_SET_KERNEL_ARG(ctx->kernel, kernel_arg, cl_mem, &mem); + kernel_arg++; } x = ctx->x_position / (plane == 0 ? 1 : ctx->x_subsample); y = ctx->y_position / (plane == 0 ? 1 : ctx->y_subsample); - cle = clSetKernelArg(ctx->kernel, kernel_arg++, sizeof(cl_int), &x); - if (cle != CL_SUCCESS) - goto fail_kernel_arg; - cle = clSetKernelArg(ctx->kernel, kernel_arg++, sizeof(cl_int), &y); - if (cle != CL_SUCCESS) - goto fail_kernel_arg; + CL_SET_KERNEL_ARG(ctx->kernel, kernel_arg, cl_int, &x); + kernel_arg++; + CL_SET_KERNEL_ARG(ctx->kernel, kernel_arg, cl_int, &y); + kernel_arg++; if (ctx->alpha_separate) { cl_int alpha_adj_x = plane == 0 ? 1 : ctx->x_subsample; cl_int alpha_adj_y = plane == 0 ? 1 : ctx->y_subsample; - cle = clSetKernelArg(ctx->kernel, kernel_arg++, sizeof(cl_int), &alpha_adj_x); - if (cle != CL_SUCCESS) - goto fail_kernel_arg; - cle = clSetKernelArg(ctx->kernel, kernel_arg++, sizeof(cl_int), &alpha_adj_y); - 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++; } err = ff_opencl_filter_work_size_from_image(avctx, global_work, @@ -241,10 +233,6 @@ static int overlay_opencl_blend(FFFrameSync *fs) return ff_filter_frame(outlink, output); -fail_kernel_arg: - av_log(avctx, AV_LOG_ERROR, "Failed to set kernel arg %d: %d.\n", - kernel_arg, cle); - err = AVERROR(EIO); fail: av_frame_free(&output); return err; diff --git a/libavfilter/vf_unsharp_opencl.c b/libavfilter/vf_unsharp_opencl.c index 19c9185..385d851 100644 --- a/libavfilter/vf_unsharp_opencl.c +++ b/libavfilter/vf_unsharp_opencl.c @@ -268,56 +268,17 @@ static int unsharp_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->plane[p].size_x); - 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_int), &ctx->plane[p].size_y); - 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, 4, sizeof(cl_float), &ctx->plane[p].amount); - if (cle != CL_SUCCESS) { - av_log(avctx, AV_LOG_ERROR, "Failed to set kernel " - "amount 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->plane[p].size_x); + CL_SET_KERNEL_ARG(ctx->kernel, 3, cl_int, &ctx->plane[p].size_y); + CL_SET_KERNEL_ARG(ctx->kernel, 4, cl_float, &ctx->plane[p].amount); + if (ctx->global) { - cle = clSetKernelArg(ctx->kernel, 5, sizeof(cl_mem), &ctx->plane[p].matrix); - if (cle != CL_SUCCESS) { - av_log(avctx, AV_LOG_ERROR, "Failed to set kernel " - "matrix argument: %d.\n", cle); - goto fail; - } + CL_SET_KERNEL_ARG(ctx->kernel, 5, cl_mem, &ctx->plane[p].matrix); } else { - cle = clSetKernelArg(ctx->kernel, 5, sizeof(cl_mem), &ctx->plane[p].coef_x); - if (cle != CL_SUCCESS) { - av_log(avctx, AV_LOG_ERROR, "Failed to set kernel " - "x-coef argument: %d.\n", cle); - goto fail; - } - cle = clSetKernelArg(ctx->kernel, 6, sizeof(cl_mem), &ctx->plane[p].coef_y); - if (cle != CL_SUCCESS) { - av_log(avctx, AV_LOG_ERROR, "Failed to set kernel " - "y-coef argument: %d.\n", cle); - goto fail; - } + CL_SET_KERNEL_ARG(ctx->kernel, 5, cl_mem, &ctx->plane[p].coef_x); + CL_SET_KERNEL_ARG(ctx->kernel, 6, cl_mem, &ctx->plane[p].coef_y); } err = ff_opencl_filter_work_size_from_image(avctx, global_work, output, p,