[FFmpeg-devel] [PATCH]opencl: compile kernels separately
Wei Gao
highgod0401 at gmail.com
Mon Nov 4 02:57:36 CET 2013
2013/11/4 Wei Gao <highgod0401 at gmail.com>
>
>
>
> 2013/11/2 Lenny Wang <lenny at multicorewareinc.com>
>
>>
>>
>> Newly adjusted patch based on Michael's comments. Please review, thanks.
>>
>
>
> diff --git a/libavfilter/deshake.h b/libavfilter/deshake.h
> index c24090e..5792973 100644
>
> @@ -108,11 +108,21 @@ int ff_opencl_deshake_init(AVFilterContext *ctx)
> deshake->opencl_ctx.matrix_size*sizeof(cl_float),
> CL_MEM_READ_ONLY, NULL);
> if (ret < 0)
> return ret;
> - if (!deshake->opencl_ctx.kernel_env.kernel) {
> - ret = av_opencl_create_kernel(&deshake->opencl_ctx.kernel_env,
> "avfilter_transform");
> - if (ret < 0) {
> - av_log(ctx, AV_LOG_ERROR, "OpenCL failed to create kernel for
> name 'avfilter_transform'\n");
> - return ret;
> + deshake->opencl_ctx.command_queue = av_opencl_get_command_queue();
> + if (!deshake->opencl_ctx.command_queue) {
> + av_log(ctx, AV_LOG_ERROR, "Unable to get OpenCL command queue in
> filter 'deshake'\n");
> + return -1;
> It should return a meaningful value, return AVERROR(EINVAL) should be OK.
>
> + }
> + deshake->opencl_ctx.program = av_opencl_compile("avfilter_transform",
> NULL);
> + if (!deshake->opencl_ctx.program) {
> + av_log(ctx, AV_LOG_ERROR, "OpenCL failed to compile program
> 'avfilter_transform'\n");
> + return -1;
> + }
> + if (!deshake->opencl_ctx.kernel) {
> + deshake->opencl_ctx.kernel =
> clCreateKernel(deshake->opencl_ctx.program, "avfilter_transform", &ret);
> + if (ret != CL_SUCCESS) {
> + av_log(ctx, AV_LOG_ERROR, "OpenCL failed to create kernel
> 'avfilter_transform'\n");
> + return -1;
> It should return a meaningful value, return AVERROR(EINVAL) should be OK.
>
>
> int ff_opencl_deshake_process_inout_buf(AVFilterContext *ctx, AVFrame
> *in, AVFrame *out)
> {
> int ret = 0;
> diff --git a/libavfilter/unsharp.h b/libavfilter/unsharp.h
> index c225929..2738243 100644
> --- a/libavfilter/unsharp.h
> +++ b/libavfilter/unsharp.h
> @@ -33,6 +33,9 @@
> #if CONFIG_OPENCL
>
> #endif
> diff --git a/libavfilter/unsharp_opencl.c b/libavfilter/unsharp_opencl.c
> index b373b66..3dd0527 100644
> --- a/libavfilter/unsharp_opencl.c
> +++ b/libavfilter/unsharp_opencl.c
> @@ -159,7 +159,7 @@ int ff_opencl_apply_unsharp(AVFilterContext *ctx,
> AVFrame *in, AVFrame *out)
> FFOpenclParam opencl_param = {0};
>
> opencl_param.ctx = ctx;
> - opencl_param.kernel = unsharp->opencl_ctx.kernel_env.kernel;
> + opencl_param.kernel = unsharp->opencl_ctx.kernel;
> ret = ff_opencl_set_parameter(&opencl_param,
>
> FF_OPENCL_PARAM_INFO(unsharp->opencl_ctx.cl_inbuf),
>
> FF_OPENCL_PARAM_INFO(unsharp->opencl_ctx.cl_outbuf),
> @@ -186,14 +186,14 @@ int ff_opencl_apply_unsharp(AVFilterContext *ctx,
> AVFrame *in, AVFrame *out)
> NULL);
> if (ret < 0)
>
> @@ -220,11 +220,21 @@ int ff_opencl_unsharp_init(AVFilterContext *ctx)
> if (ret < 0)
> return ret;
> unsharp->opencl_ctx.plane_num = PLANE_NUM;
> - if (!unsharp->opencl_ctx.kernel_env.kernel) {
> - ret = av_opencl_create_kernel(&unsharp->opencl_ctx.kernel_env,
> "unsharp");
> - if (ret < 0) {
> - av_log(ctx, AV_LOG_ERROR, "OpenCL failed to create kernel
> with name 'unsharp'\n");
> - return ret;
> + unsharp->opencl_ctx.command_queue = av_opencl_get_command_queue();
> + if (!unsharp->opencl_ctx.command_queue) {
> + av_log(ctx, AV_LOG_ERROR, "Unable to get OpenCL command queue in
> filter 'unsharp'\n");
> + return -1;
> It should return a meaningful value, return AVERROR(EINVAL) should be OK.
>
> + }
> + unsharp->opencl_ctx.program = av_opencl_compile("unsharp", NULL);
> + if (!unsharp->opencl_ctx.program) {
> + av_log(ctx, AV_LOG_ERROR, "OpenCL failed to compile program
> 'unsharp'\n");
> + return -1;
> It should return a meaningful value, return AVERROR(EINVAL) should be OK.
>
> + }
> + if (!unsharp->opencl_ctx.kernel) {
> + unsharp->opencl_ctx.kernel =
> clCreateKernel(unsharp->opencl_ctx.program, "unsharp", &ret);
> + if (ret != CL_SUCCESS) {
> + av_log(ctx, AV_LOG_ERROR, "OpenCL failed to create kernel
> 'unsharp'\n");
> + return -1;
> It should return a meaningful value, return AVERROR(EINVAL) should be OK.
>
> Looks good to me thanks
>
+cl_program av_opencl_compile(const char *program_name, const char
*build_opts)
{
+ int i;
cl_int status;
- int i, ret = 0;
+ int kernel_code_idx = 0;
+ const char *kernel_source;
+ size_t kernel_code_len;
+ char* ptr = NULL;
a trailing whitespace after char* ptr = NULL;
+cl_program av_opencl_compile(const char *program_name, const char*
build_opts);
+
+/**
+ * get OpenCL command queue
+ *
+ * @return a cl_command_queue object
a trailing whitespace after eturn a cl_command_queue object
+ */
+cl_command_queue av_opencl_get_command_queue(void);
+ cl_program program = NULL;
+
>
>
>>
>> _______________________________________________
>> ffmpeg-devel mailing list
>> ffmpeg-devel at ffmpeg.org
>> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>>
>>
>
More information about the ffmpeg-devel
mailing list