annotate ffmpeg/libavutil/opencl.h @ 13:844d341cf643 tip

Back up before ISMIR
author Yading Song <yading.song@eecs.qmul.ac.uk>
date Thu, 31 Oct 2013 13:17:06 +0000
parents f445c3017523
children
rev   line source
yading@11 1 /*
yading@11 2 * Copyright (C) 2012 Peng Gao <peng@multicorewareinc.com>
yading@11 3 * Copyright (C) 2012 Li Cao <li@multicorewareinc.com>
yading@11 4 * Copyright (C) 2012 Wei Gao <weigao@multicorewareinc.com>
yading@11 5 *
yading@11 6 * This file is part of FFmpeg.
yading@11 7 *
yading@11 8 * FFmpeg is free software; you can redistribute it and/or
yading@11 9 * modify it under the terms of the GNU Lesser General Public
yading@11 10 * License as published by the Free Software Foundation; either
yading@11 11 * version 2.1 of the License, or (at your option) any later version.
yading@11 12 *
yading@11 13 * FFmpeg is distributed in the hope that it will be useful,
yading@11 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
yading@11 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
yading@11 16 * Lesser General Public License for more details.
yading@11 17 *
yading@11 18 * You should have received a copy of the GNU Lesser General Public
yading@11 19 * License along with FFmpeg; if not, write to the Free Software
yading@11 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
yading@11 21 */
yading@11 22
yading@11 23 /**
yading@11 24 * @file
yading@11 25 * OpenCL wrapper
yading@11 26 *
yading@11 27 * This interface is considered still experimental and its API and ABI may
yading@11 28 * change without prior notice.
yading@11 29 */
yading@11 30
yading@11 31 #ifndef LIBAVUTIL_OPENCL_H
yading@11 32 #define LIBAVUTIL_OPENCL_H
yading@11 33
yading@11 34 #include <CL/cl.h>
yading@11 35 #include "config.h"
yading@11 36 #include "dict.h"
yading@11 37
yading@11 38 #define AV_OPENCL_KERNEL( ... )# __VA_ARGS__
yading@11 39
yading@11 40 #define AV_OPENCL_MAX_KERNEL_NAME_SIZE 150
yading@11 41
yading@11 42 #define AV_OPENCL_MAX_DEVICE_NAME_SIZE 100
yading@11 43
yading@11 44 #define AV_OPENCL_MAX_PLATFORM_NAME_SIZE 100
yading@11 45
yading@11 46 typedef struct {
yading@11 47 int device_type;
yading@11 48 char device_name[AV_OPENCL_MAX_DEVICE_NAME_SIZE];
yading@11 49 cl_device_id device_id;
yading@11 50 } AVOpenCLDeviceNode;
yading@11 51
yading@11 52 typedef struct {
yading@11 53 cl_platform_id platform_id;
yading@11 54 char platform_name[AV_OPENCL_MAX_PLATFORM_NAME_SIZE];
yading@11 55 int device_num;
yading@11 56 AVOpenCLDeviceNode **device_node;
yading@11 57 } AVOpenCLPlatformNode;
yading@11 58
yading@11 59 typedef struct {
yading@11 60 int platform_num;
yading@11 61 AVOpenCLPlatformNode **platform_node;
yading@11 62 } AVOpenCLDeviceList;
yading@11 63
yading@11 64 typedef struct {
yading@11 65 cl_command_queue command_queue;
yading@11 66 cl_kernel kernel;
yading@11 67 char kernel_name[AV_OPENCL_MAX_KERNEL_NAME_SIZE];
yading@11 68 } AVOpenCLKernelEnv;
yading@11 69
yading@11 70 typedef struct {
yading@11 71 cl_platform_id platform_id;
yading@11 72 cl_device_type device_type;
yading@11 73 cl_context context;
yading@11 74 cl_device_id device_id;
yading@11 75 cl_command_queue command_queue;
yading@11 76 char *platform_name;
yading@11 77 } AVOpenCLExternalEnv;
yading@11 78
yading@11 79 /**
yading@11 80 * Get OpenCL device list.
yading@11 81 *
yading@11 82 * It must be freed with av_opencl_free_device_list().
yading@11 83 *
yading@11 84 * @param device_list pointer to OpenCL environment device list,
yading@11 85 * should be released by av_opencl_free_device_list()
yading@11 86 *
yading@11 87 * @return >=0 on success, a negative error code in case of failure
yading@11 88 */
yading@11 89 int av_opencl_get_device_list(AVOpenCLDeviceList **device_list);
yading@11 90
yading@11 91 /**
yading@11 92 * Free OpenCL device list.
yading@11 93 *
yading@11 94 * @param device_list pointer to OpenCL environment device list
yading@11 95 * created by av_opencl_get_device_list()
yading@11 96 */
yading@11 97 void av_opencl_free_device_list(AVOpenCLDeviceList **device_list);
yading@11 98
yading@11 99 /**
yading@11 100 * Set option in the global OpenCL context.
yading@11 101 *
yading@11 102 * This options affect the operation performed by the next
yading@11 103 * av_opencl_init() operation.
yading@11 104 *
yading@11 105 * The currently accepted options are:
yading@11 106 * - build_options: set options to compile registered kernels code
yading@11 107 * - platform: set index of platform in device list
yading@11 108 * - device: set index of device in device list
yading@11 109 *
yading@11 110 * See reference "OpenCL Specification Version: 1.2 chapter 5.6.4".
yading@11 111 *
yading@11 112 * @param key option key
yading@11 113 * @param val option value
yading@11 114 * @return >=0 on success, a negative error code in case of failure
yading@11 115 * @see av_opencl_get_option()
yading@11 116 */
yading@11 117 int av_opencl_set_option(const char *key, const char *val);
yading@11 118
yading@11 119 /**
yading@11 120 * Get option value from the global OpenCL context.
yading@11 121 *
yading@11 122 * @param key option key
yading@11 123 * @param out_val pointer to location where option value will be
yading@11 124 * written, must be freed with av_freep()
yading@11 125 * @return >=0 on success, a negative error code in case of failure
yading@11 126 * @see av_opencl_set_option()
yading@11 127 */
yading@11 128 int av_opencl_get_option(const char *key, uint8_t **out_val);
yading@11 129
yading@11 130 /**
yading@11 131 * Free option values of the global OpenCL context.
yading@11 132 *
yading@11 133 */
yading@11 134 void av_opencl_free_option(void);
yading@11 135
yading@11 136 /**
yading@11 137 * Allocate OpenCL external environment.
yading@11 138 *
yading@11 139 * It must be freed with av_opencl_free_external_env().
yading@11 140 *
yading@11 141 * @return pointer to allocated OpenCL external environment
yading@11 142 */
yading@11 143 AVOpenCLExternalEnv *av_opencl_alloc_external_env(void);
yading@11 144
yading@11 145 /**
yading@11 146 * Free OpenCL external environment.
yading@11 147 *
yading@11 148 * @param ext_opencl_env pointer to OpenCL external environment
yading@11 149 * created by av_opencl_alloc_external_env()
yading@11 150 */
yading@11 151 void av_opencl_free_external_env(AVOpenCLExternalEnv **ext_opencl_env);
yading@11 152
yading@11 153 /**
yading@11 154 * Register kernel code.
yading@11 155 *
yading@11 156 * The registered kernel code is stored in a global context, and compiled
yading@11 157 * in the runtime environment when av_opencl_init() is called.
yading@11 158 *
yading@11 159 * @param kernel_code kernel code to be compiled in the OpenCL runtime environment
yading@11 160 * @return >=0 on success, a negative error code in case of failure
yading@11 161 */
yading@11 162 int av_opencl_register_kernel_code(const char *kernel_code);
yading@11 163
yading@11 164 /**
yading@11 165 * Initialize the run time OpenCL environment and compile the kernel
yading@11 166 * code registered with av_opencl_register_kernel_code().
yading@11 167 *
yading@11 168 * @param ext_opencl_env external OpenCL environment, created by an
yading@11 169 * application program, ignored if set to NULL
yading@11 170 * @return >=0 on success, a negative error code in case of failure
yading@11 171 */
yading@11 172 int av_opencl_init(AVOpenCLExternalEnv *ext_opencl_env);
yading@11 173
yading@11 174 /**
yading@11 175 * Create kernel object in the specified kernel environment.
yading@11 176 *
yading@11 177 * @param env pointer to kernel environment which is filled with
yading@11 178 * the environment used to run the kernel
yading@11 179 * @param kernel_name kernel function name
yading@11 180 * @return >=0 on success, a negative error code in case of failure
yading@11 181 */
yading@11 182 int av_opencl_create_kernel(AVOpenCLKernelEnv *env, const char *kernel_name);
yading@11 183
yading@11 184 /**
yading@11 185 * Create OpenCL buffer.
yading@11 186 *
yading@11 187 * The buffer is used to save the data used or created by an OpenCL
yading@11 188 * kernel.
yading@11 189 * The created buffer must be released with av_opencl_buffer_release().
yading@11 190 *
yading@11 191 * See clCreateBuffer() function reference for more information about
yading@11 192 * the parameters.
yading@11 193 *
yading@11 194 * @param cl_buf pointer to OpenCL buffer
yading@11 195 * @param cl_buf_size size in bytes of the OpenCL buffer to create
yading@11 196 * @param flags flags used to control buffer attributes
yading@11 197 * @param host_ptr host pointer of the OpenCL buffer
yading@11 198 * @return >=0 on success, a negative error code in case of failure
yading@11 199 */
yading@11 200 int av_opencl_buffer_create(cl_mem *cl_buf, size_t cl_buf_size, int flags, void *host_ptr);
yading@11 201
yading@11 202 /**
yading@11 203 * Write OpenCL buffer with data from src_buf.
yading@11 204 *
yading@11 205 * @param dst_cl_buf pointer to OpenCL destination buffer
yading@11 206 * @param src_buf pointer to source buffer
yading@11 207 * @param buf_size size in bytes of the source and destination buffers
yading@11 208 * @return >=0 on success, a negative error code in case of failure
yading@11 209 */
yading@11 210 int av_opencl_buffer_write(cl_mem dst_cl_buf, uint8_t *src_buf, size_t buf_size);
yading@11 211
yading@11 212 /**
yading@11 213 * Read data from OpenCL buffer to memory buffer.
yading@11 214 *
yading@11 215 * @param dst_buf pointer to destination buffer (CPU memory)
yading@11 216 * @param src_cl_buf pointer to source OpenCL buffer
yading@11 217 * @param buf_size size in bytes of the source and destination buffers
yading@11 218 * @return >=0 on success, a negative error code in case of failure
yading@11 219 */
yading@11 220 int av_opencl_buffer_read(uint8_t *dst_buf, cl_mem src_cl_buf, size_t buf_size);
yading@11 221
yading@11 222 /**
yading@11 223 * Write image data from memory to OpenCL buffer.
yading@11 224 *
yading@11 225 * The source must be an array of pointers to image plane buffers.
yading@11 226 *
yading@11 227 * @param dst_cl_buf pointer to destination OpenCL buffer
yading@11 228 * @param dst_cl_buf_size size in bytes of OpenCL buffer
yading@11 229 * @param dst_cl_buf_offset the offset of the OpenCL buffer start position
yading@11 230 * @param src_data array of pointers to source plane buffers
yading@11 231 * @param src_plane_sizes array of sizes in bytes of the source plane buffers
yading@11 232 * @param src_plane_num number of source image planes
yading@11 233 * @return >=0 on success, a negative error code in case of failure
yading@11 234 */
yading@11 235 int av_opencl_buffer_write_image(cl_mem dst_cl_buf, size_t cl_buffer_size, int dst_cl_offset,
yading@11 236 uint8_t **src_data, int *plane_size, int plane_num);
yading@11 237
yading@11 238 /**
yading@11 239 * Read image data from OpenCL buffer.
yading@11 240 *
yading@11 241 * @param dst_data array of pointers to destination plane buffers
yading@11 242 * @param dst_plane_sizes array of pointers to destination plane buffers
yading@11 243 * @param dst_plane_num number of destination image planes
yading@11 244 * @param src_cl_buf pointer to source OpenCL buffer
yading@11 245 * @param src_cl_buf_size size in bytes of OpenCL buffer
yading@11 246 * @return >=0 on success, a negative error code in case of failure
yading@11 247 */
yading@11 248 int av_opencl_buffer_read_image(uint8_t **dst_data, int *plane_size, int plane_num,
yading@11 249 cl_mem src_cl_buf, size_t cl_buffer_size);
yading@11 250
yading@11 251 /**
yading@11 252 * Release OpenCL buffer.
yading@11 253 *
yading@11 254 * @param cl_buf pointer to OpenCL buffer to release, which was
yading@11 255 * previously filled with av_opencl_buffer_create()
yading@11 256 */
yading@11 257 void av_opencl_buffer_release(cl_mem *cl_buf);
yading@11 258
yading@11 259 /**
yading@11 260 * Release kernel object.
yading@11 261 *
yading@11 262 * @param env kernel environment where the kernel object was created
yading@11 263 * with av_opencl_create_kernel()
yading@11 264 */
yading@11 265 void av_opencl_release_kernel(AVOpenCLKernelEnv *env);
yading@11 266
yading@11 267 /**
yading@11 268 * Release OpenCL environment.
yading@11 269 *
yading@11 270 * The OpenCL environment is effectively released only if all the created
yading@11 271 * kernels had been released with av_opencl_release_kernel().
yading@11 272 */
yading@11 273 void av_opencl_uninit(void);
yading@11 274
yading@11 275 #endif /* LIBAVUTIL_OPENCL_H */