[FFmpeg-devel] [PATCH] lavu/opencl: add opencl public error API
Stefano Sabatini
stefasab at gmail.com
Sat Apr 27 19:02:54 CEST 2013
On date Saturday 2013-04-27 09:52:45 +0800, Wei Gao encoded:
>
> From 3b8c05135a4e3ef8a131ad7826c01ba3536d5863 Mon Sep 17 00:00:00 2001
> From: highgod0401 <highgod0401 at gmail.com>
> Date: Sat, 27 Apr 2013 09:49:08 +0800
> Subject: [PATCH] lavu/opencl: add opencl public error API
>
> ---
> libavutil/opencl.c | 48 ++++++++++++++++++++++++------------------------
> libavutil/opencl.h | 10 ++++++++++
> 2 files changed, 34 insertions(+), 24 deletions(-)
>
> diff --git a/libavutil/opencl.c b/libavutil/opencl.c
> index 1fdb096..e2d5581 100644
> --- a/libavutil/opencl.c
> +++ b/libavutil/opencl.c
> @@ -162,7 +162,7 @@ static const OpenclErrorMsg opencl_err_msg[] = {
> {CL_INVALID_DEVICE_PARTITION_COUNT, "INVALID DEVICE PARTITION COUNT"},
> };
>
> -static const char *opencl_errstr(cl_int status)
> +const char *av_opencl_errstr(cl_int status)
> {
> int i;
> for (i = 0; i < sizeof(opencl_err_msg); i++) {
> @@ -201,7 +201,7 @@ static int get_device_list(AVOpenCLDeviceList *device_list)
> status = clGetPlatformIDs(0, NULL, &device_list->platform_num);
> if (status != CL_SUCCESS) {
> av_log(&opencl_ctx, AV_LOG_ERROR,
> - "Could not get OpenCL platform ids: %s\n", opencl_errstr(status));
> + "Could not get OpenCL platform ids: %s\n", av_opencl_errstr(status));
> return AVERROR_EXTERNAL;
> }
> platform_ids = av_mallocz(device_list->platform_num * sizeof(cl_platform_id));
> @@ -210,7 +210,7 @@ static int get_device_list(AVOpenCLDeviceList *device_list)
> status = clGetPlatformIDs(device_list->platform_num, platform_ids, NULL);
> if (status != CL_SUCCESS) {
> av_log(&opencl_ctx, AV_LOG_ERROR,
> - "Could not get OpenCL platform ids: %s\n", opencl_errstr(status));
> + "Could not get OpenCL platform ids: %s\n", av_opencl_errstr(status));
> ret = AVERROR_EXTERNAL;
> goto end;
> }
> @@ -256,7 +256,7 @@ static int get_device_list(AVOpenCLDeviceList *device_list)
> devices_num[j], device_ids, NULL);
> if (status != CL_SUCCESS) {
> av_log(&opencl_ctx, AV_LOG_WARNING,
> - "Could not get device ID: %s:\n", opencl_errstr(status));
> + "Could not get device ID: %s:\n", av_opencl_errstr(status));
> av_freep(&device_ids);
> continue;
> }
> @@ -275,7 +275,7 @@ static int get_device_list(AVOpenCLDeviceList *device_list)
> NULL);
> if (status != CL_SUCCESS) {
> av_log(&opencl_ctx, AV_LOG_WARNING,
> - "Could not get device name: %s\n", opencl_errstr(status));
> + "Could not get device name: %s\n", av_opencl_errstr(status));
> continue;
> }
> device_list->platform_node[i]->device_num++;
> @@ -416,7 +416,7 @@ int av_opencl_create_kernel(AVOpenCLKernelEnv *env, const char *kernel_name)
> break;
> }
> if (status != CL_SUCCESS) {
> - av_log(&opencl_ctx, AV_LOG_ERROR, "Could not create OpenCL kernel: %s\n", opencl_errstr(status));
> + av_log(&opencl_ctx, AV_LOG_ERROR, "Could not create OpenCL kernel: %s\n", av_opencl_errstr(status));
> ret = AVERROR_EXTERNAL;
> goto end;
> }
> @@ -438,7 +438,7 @@ void av_opencl_release_kernel(AVOpenCLKernelEnv *env)
> status = clReleaseKernel(env->kernel);
> if (status != CL_SUCCESS) {
> av_log(&opencl_ctx, AV_LOG_ERROR, "Could not release kernel: %s\n",
> - opencl_errstr(status));
> + av_opencl_errstr(status));
> }
> env->kernel = NULL;
> env->command_queue = NULL;
> @@ -526,14 +526,14 @@ static int init_opencl_env(OpenclContext *opencl_ctx, AVOpenCLExternalEnv *ext_o
> NULL, NULL, &status);
> if (status != CL_SUCCESS) {
> av_log(opencl_ctx, AV_LOG_ERROR,
> - "Could not get OpenCL context from device type: %s\n", opencl_errstr(status));
> + "Could not get OpenCL context from device type: %s\n", av_opencl_errstr(status));
> return AVERROR_EXTERNAL;
> }
> opencl_ctx->command_queue = clCreateCommandQueue(opencl_ctx->context, opencl_ctx->device_id,
> 0, &status);
> if (status != CL_SUCCESS) {
> av_log(opencl_ctx, AV_LOG_ERROR,
> - "Could not create OpenCL command queue: %s\n", opencl_errstr(status));
> + "Could not create OpenCL command queue: %s\n", av_opencl_errstr(status));
> return AVERROR_EXTERNAL;
> }
> }
> @@ -566,7 +566,7 @@ static int compile_kernel_file(OpenclContext *opencl_ctx)
> &status);
> if(status != CL_SUCCESS) {
> av_log(opencl_ctx, AV_LOG_ERROR,
> - "Could not create OpenCL program with source code: %s\n", opencl_errstr(status));
> + "Could not create OpenCL program with source code: %s\n", av_opencl_errstr(status));
> return AVERROR_EXTERNAL;
> }
> if (!opencl_ctx->programs[opencl_ctx->program_count]) {
> @@ -577,7 +577,7 @@ static int compile_kernel_file(OpenclContext *opencl_ctx)
> opencl_ctx->build_options, NULL, NULL);
> if (status != CL_SUCCESS) {
> av_log(opencl_ctx, AV_LOG_ERROR,
> - "Could not compile OpenCL kernel: %s\n", opencl_errstr(status));
> + "Could not compile OpenCL kernel: %s\n", av_opencl_errstr(status));
> return AVERROR_EXTERNAL;
> }
> opencl_ctx->program_count++;
> @@ -628,7 +628,7 @@ void av_opencl_uninit(void)
> status = clReleaseProgram(opencl_ctx.programs[i]);
> if (status != CL_SUCCESS) {
> av_log(&opencl_ctx, AV_LOG_ERROR,
> - "Could not release OpenCL program: %s\n", opencl_errstr(status));
> + "Could not release OpenCL program: %s\n", av_opencl_errstr(status));
> }
> opencl_ctx.programs[i] = NULL;
> }
> @@ -637,7 +637,7 @@ void av_opencl_uninit(void)
> status = clReleaseCommandQueue(opencl_ctx.command_queue);
> if (status != CL_SUCCESS) {
> av_log(&opencl_ctx, AV_LOG_ERROR,
> - "Could not release OpenCL command queue: %s\n", opencl_errstr(status));
> + "Could not release OpenCL command queue: %s\n", av_opencl_errstr(status));
> }
> opencl_ctx.command_queue = NULL;
> }
> @@ -645,7 +645,7 @@ void av_opencl_uninit(void)
> status = clReleaseContext(opencl_ctx.context);
> if (status != CL_SUCCESS) {
> av_log(&opencl_ctx, AV_LOG_ERROR,
> - "Could not release OpenCL context: %s\n", opencl_errstr(status));
> + "Could not release OpenCL context: %s\n", av_opencl_errstr(status));
> }
> opencl_ctx.context = NULL;
> }
> @@ -661,7 +661,7 @@ int av_opencl_buffer_create(cl_mem *cl_buf, size_t cl_buf_size, int flags, void
> cl_int status;
> *cl_buf = clCreateBuffer(opencl_ctx.context, flags, cl_buf_size, host_ptr, &status);
> if (status != CL_SUCCESS) {
> - av_log(&opencl_ctx, AV_LOG_ERROR, "Could not create OpenCL buffer: %s\n", opencl_errstr(status));
> + av_log(&opencl_ctx, AV_LOG_ERROR, "Could not create OpenCL buffer: %s\n", av_opencl_errstr(status));
> return AVERROR_EXTERNAL;
> }
> return 0;
> @@ -675,7 +675,7 @@ void av_opencl_buffer_release(cl_mem *cl_buf)
> status = clReleaseMemObject(*cl_buf);
> if (status != CL_SUCCESS) {
> av_log(&opencl_ctx, AV_LOG_ERROR,
> - "Could not release OpenCL buffer: %s\n", opencl_errstr(status));
> + "Could not release OpenCL buffer: %s\n", av_opencl_errstr(status));
> }
> memset(cl_buf, 0, sizeof(*cl_buf));
> }
> @@ -689,7 +689,7 @@ int av_opencl_buffer_write(cl_mem dst_cl_buf, uint8_t *src_buf, size_t buf_size)
>
> if (status != CL_SUCCESS) {
> av_log(&opencl_ctx, AV_LOG_ERROR,
> - "Could not map OpenCL buffer: %s\n", opencl_errstr(status));
> + "Could not map OpenCL buffer: %s\n", av_opencl_errstr(status));
> return AVERROR_EXTERNAL;
> }
> memcpy(mapped, src_buf, buf_size);
> @@ -697,7 +697,7 @@ int av_opencl_buffer_write(cl_mem dst_cl_buf, uint8_t *src_buf, size_t buf_size)
> status = clEnqueueUnmapMemObject(opencl_ctx.command_queue, dst_cl_buf, mapped, 0, NULL, NULL);
> if (status != CL_SUCCESS) {
> av_log(&opencl_ctx, AV_LOG_ERROR,
> - "Could not unmap OpenCL buffer: %s\n", opencl_errstr(status));
> + "Could not unmap OpenCL buffer: %s\n", av_opencl_errstr(status));
> return AVERROR_EXTERNAL;
> }
> return 0;
> @@ -712,7 +712,7 @@ int av_opencl_buffer_read(uint8_t *dst_buf, cl_mem src_cl_buf, size_t buf_size)
>
> if (status != CL_SUCCESS) {
> av_log(&opencl_ctx, AV_LOG_ERROR,
> - "Could not map OpenCL buffer: %s\n", opencl_errstr(status));
> + "Could not map OpenCL buffer: %s\n", av_opencl_errstr(status));
> return AVERROR_EXTERNAL;
> }
> memcpy(dst_buf, mapped, buf_size);
> @@ -720,7 +720,7 @@ int av_opencl_buffer_read(uint8_t *dst_buf, cl_mem src_cl_buf, size_t buf_size)
> status = clEnqueueUnmapMemObject(opencl_ctx.command_queue, src_cl_buf, mapped, 0, NULL, NULL);
> if (status != CL_SUCCESS) {
> av_log(&opencl_ctx, AV_LOG_ERROR,
> - "Could not unmap OpenCL buffer: %s\n", opencl_errstr(status));
> + "Could not unmap OpenCL buffer: %s\n", av_opencl_errstr(status));
> return AVERROR_EXTERNAL;
> }
> return 0;
> @@ -749,7 +749,7 @@ int av_opencl_buffer_write_image(cl_mem dst_cl_buf, size_t cl_buffer_size, int d
> 0, NULL, NULL, &status);
> if (status != CL_SUCCESS) {
> av_log(&opencl_ctx, AV_LOG_ERROR,
> - "Could not map OpenCL buffer: %s\n", opencl_errstr(status));
> + "Could not map OpenCL buffer: %s\n", av_opencl_errstr(status));
> return AVERROR_EXTERNAL;
> }
> temp = mapped;
> @@ -761,7 +761,7 @@ int av_opencl_buffer_write_image(cl_mem dst_cl_buf, size_t cl_buffer_size, int d
> status = clEnqueueUnmapMemObject(opencl_ctx.command_queue, dst_cl_buf, mapped, 0, NULL, NULL);
> if (status != CL_SUCCESS) {
> av_log(&opencl_ctx, AV_LOG_ERROR,
> - "Could not unmap OpenCL buffer: %s\n", opencl_errstr(status));
> + "Could not unmap OpenCL buffer: %s\n", av_opencl_errstr(status));
> return AVERROR_EXTERNAL;
> }
> return 0;
> @@ -791,7 +791,7 @@ int av_opencl_buffer_read_image(uint8_t **dst_data, int *plane_size, int plane_n
>
> if (status != CL_SUCCESS) {
> av_log(&opencl_ctx, AV_LOG_ERROR,
> - "Could not map OpenCL buffer: %s\n", opencl_errstr(status));
> + "Could not map OpenCL buffer: %s\n", av_opencl_errstr(status));
> return AVERROR_EXTERNAL;
> }
> temp = mapped;
> @@ -804,7 +804,7 @@ int av_opencl_buffer_read_image(uint8_t **dst_data, int *plane_size, int plane_n
> status = clEnqueueUnmapMemObject(opencl_ctx.command_queue, src_cl_buf, mapped, 0, NULL, NULL);
> if (status != CL_SUCCESS) {
> av_log(&opencl_ctx, AV_LOG_ERROR,
> - "Could not unmap OpenCL buffer: %s\n", opencl_errstr(status));
> + "Could not unmap OpenCL buffer: %s\n", av_opencl_errstr(status));
> return AVERROR_EXTERNAL;
> }
> return 0;
> diff --git a/libavutil/opencl.h b/libavutil/opencl.h
> index acafe36..8adb5dc 100644
> --- a/libavutil/opencl.h
> +++ b/libavutil/opencl.h
> @@ -151,6 +151,16 @@ AVOpenCLExternalEnv *av_opencl_alloc_external_env(void);
> void av_opencl_free_external_env(AVOpenCLExternalEnv **ext_opencl_env);
>
> /**
> + * Get opencl error string.
opencl -> OpenCL
> + *
> + * Input the OpenCL error code and output the error code string.
You can discard this.
> + *
> + * @param status OpenCL error code
> + * @return opencl error string
> + */
> +const char *av_opencl_errstr(cl_int status);
LGTM otherwise, maybe with a minor bump in libavutil, thanks.
--
FFmpeg = Fiendish Fundamental Mere Portable Energized Genius
More information about the ffmpeg-devel
mailing list