Commit 189cbc1a authored by highgod0401's avatar highgod0401 Committed by Michael Niedermayer

opencl wrapper based on comments on 20130401

Signed-off-by: 's avatarMichael Niedermayer <michaelni@gmx.at>
parent 24f822c3
......@@ -234,6 +234,7 @@ External library support:
--enable-libxvid enable Xvid encoding via xvidcore,
native MPEG-4/Xvid encoder exists [no]
--enable-openal enable OpenAL 1.1 capture support [no]
--enable-opencl enable OpenCL code
--enable-openssl enable openssl [no]
--enable-x11grab enable X11 grabbing [no]
--enable-zlib enable zlib [autodetect]
......@@ -1179,6 +1180,7 @@ EXTERNAL_LIBRARY_LIST="
libxavs
libxvid
openal
opencl
openssl
x11grab
zlib
......@@ -3987,6 +3989,7 @@ enabled openal && { { for al_libs in "${OPENAL_LIBS}" "-lopenal" "-lOpenAL32
die "ERROR: openal not found"; } &&
{ check_cpp_condition "AL/al.h" "defined(AL_VERSION_1_1)" ||
die "ERROR: openal must be installed and version must be 1.1 or compatible"; }
enabled opencl && require2 opencl CL/cl.h clEnqueueNDRangeKernel -lOpenCL
enabled openssl && { check_lib openssl/ssl.h SSL_library_init -lssl -lcrypto ||
check_lib openssl/ssl.h SSL_library_init -lssl32 -leay32 ||
check_lib openssl/ssl.h SSL_library_init -lssl -lcrypto -lws2_32 -lgdi32 ||
......@@ -4355,6 +4358,7 @@ echo "network support ${network-no}"
echo "threading support ${thread_type-no}"
echo "safe bitstream reader ${safe_bitstream_reader-no}"
echo "SDL support ${sdl-no}"
echo "opencl enabled ${opencl-no}"
echo "texi2html enabled ${texi2html-no}"
echo "perl enabled ${perl-no}"
echo "pod2man enabled ${pod2man-no}"
......
......@@ -52,6 +52,8 @@ HEADERS = adler32.h \
HEADERS-$(CONFIG_LZO) += lzo.h
HEADERS-$(CONFIG_OPENCL) += opencl.h
ARCH_HEADERS = bswap.h \
intmath.h \
intreadwrite.h \
......@@ -106,6 +108,7 @@ OBJS = adler32.o \
xtea.o \
OBJS-$(CONFIG_LZO) += lzo.o
OBJS-$(CONFIG_OPENCL) += opencl.o
OBJS += $(COMPAT_OBJS:%=../compat/%)
......
This diff is collapsed.
/*
* Copyright (C) 2012 Peng Gao <peng@multicorewareinc.com>
* Copyright (C) 2012 Li Cao <li@multicorewareinc.com>
* Copyright (C) 2012 Wei Gao <weigao@multicorewareinc.com>
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @file
* OpenCL wrapper
*
* This interface is considered still experimental and its API and ABI may
* change without prior notice.
*/
#ifndef LIBAVUTIL_OPENCLWRAPPER_H
#define LIBAVUTIL_OPENCLWRAPPER_H
#include <CL/cl.h>
#include "config.h"
#include "dict.h"
#define AV_OPENCL_KERNEL( ... )# __VA_ARGS__
#define AV_OPENCL_MAX_KERNEL_NAME_SIZE 150
typedef struct {
cl_command_queue command_queue;
cl_kernel kernel;
char kernel_name[AV_OPENCL_MAX_KERNEL_NAME_SIZE];
} AVOpenCLKernelEnv;
typedef struct {
cl_platform_id platform_id;
cl_device_type device_type;
cl_context context;
cl_device_id *device_ids;
cl_device_id device_id;
cl_command_queue command_queue;
char *platform_name;
} AVOpenCLExternalEnv;
/**
* Allocate OpenCL external environment.
*
* It must be freed with av_opencl_free_external_env().
*
* @return pointer to allocated OpenCL external environment
*/
AVOpenCLExternalEnv *av_opencl_alloc_external_env(void);
/**
* Free OpenCL external environment.
*
* @param ext_opencl_env pointer to OpenCL external environment created by av_opencl_alloc_external_env()
*/
void av_opencl_free_external_env(AVOpenCLExternalEnv **ext_opencl_env);
/**
* Register kernel code.
*
* The registered kernel code is stored in a global context, and compiled
* in the runtime environment when av_opencl_init() is called.
*
* @param kernel_code kernel code to be compiled in the OpenCL runtime environment
* @return >=0 on success, a negative error code in case of failure
*/
int av_opencl_register_kernel_code(const char *kernel_code);
/**
* Initialize the run time OpenCL environment and compile the kernel code registered with
* av_opencl_register_kernel_code().
*
* Currently, the only accepted option is "build_options", used to set
* options to compile registered kernels code. See reference "OpenCL
* Specification Version: 1.2 chapter 5.6.4".
*
* @param options dictionary of key/value options
* @param ext_opencl_env external OpenCL environment, created by an
* application program, ignored if set to NULL
* @return >=0 on success, a negative error code in case of failure
*/
int av_opencl_init(AVDictionary *options, AVOpenCLExternalEnv *ext_opencl_env);
/**
* Create kernel object in the specified kernel environment.
*
* @param env pointer to kernel environment which is filled with the environment,
* used to run the kernel
* @param kernel_name kernel function name
* @return >=0 on success, a negative error code in case of failure
*/
int av_opencl_create_kernel(AVOpenCLKernelEnv *env, const char *kernel_name);
/**
* Create OpenCL buffer.
*
* The buffer is used to save the data used or created by an OpenCL
* kernel.
* The created buffer must be released with av_opencl_buffer_release().
*
* See clCreateBuffer() function reference for more information about
* the parameters.
*
* @param cl_buf pointer to OpenCL buffer
* @param cl_buf_size size in bytes of the OpenCL buffer to create
* @param flags flags used to control buffer attributes
* @param host_ptr host pointer of the OpenCL buffer
* @return >=0 on success, a negative error code in case of failure
*/
int av_opencl_buffer_create(cl_mem *cl_buf, size_t cl_buf_size, int flags, void *host_ptr);
/**
* Write OpenCL buffer with data from src_buf.
*
* @param dst_cl_buf pointer to OpenCL destination buffer
* @param src_buf pointer to source buffer
* @param buf_size size in bytes of the source and destination buffers
* @return >=0 on success, a negative error code in case of failure
*/
int av_opencl_buffer_write(cl_mem dst_cl_buf, uint8_t *src_buf, size_t buf_size);
/**
* Read data from OpenCL buffer to memory buffer.
*
* @param dst_buf pointer to destination buffer (CPU memory)
* @param src_cl_buf pointer to source OpenCL buffer
* @param buf_size size in bytes of the source and destination buffers
* @return >=0 on success, a negative error code in case of failure
*/
int av_opencl_buffer_read(uint8_t *dst_buf, cl_mem src_cl_buf, size_t buf_size);
/**
* Write image data from memory to OpenCL buffer.
*
* The source must be an array of pointers to image plane buffers.
*
* @param dst_cl_buf pointer to destination OpenCL buffer
* @param dst_cl_buf_size size in bytes of OpenCL buffer
* @param dst_cl_buf_offset the offset of the OpenCL buffer start position
* @param src_data array of pointers to source plane buffers
* @param src_plane_sizes array of sizes in bytes of the source plane buffers
* @param src_plane_num number of source image planes
* @return >=0 on success, a negative error code in case of failure
*/
int av_opencl_buffer_write_image(cl_mem dst_cl_buf, size_t cl_buffer_size, int dst_cl_offset,
uint8_t **src_data, int *plane_size, int plane_num);
/**
* Read image data from OpenCL buffer.
*
* src buffer is OpenCL buffer, dst buffer is frame buffer(data[0],data[1]....).
*
* @param dst_data array of pointers to destination plane buffers
* @param dst_plane_sizes array of pointers to destination plane buffers
* @param dst_plane_num number of destination image planes
* @param src_cl_buf pointer to source OpenCL buffer
* @param src_cl_buf_size size in bytes of OpenCL buffer
* @return >=0 on success, a negative error code in case of failure
*/
int av_opencl_buffer_read_image(uint8_t **dst_data, int *plane_size, int plane_num,
cl_mem src_cl_buf, size_t cl_buffer_size);
/**
* Release OpenCL buffer.
*
* @param cl_buf pointer to OpenCL buffer to release, which was previously filled with av_opencl_buffer_create()
*/
void av_opencl_buffer_release(cl_mem *cl_buf);
/**
* Release kernel object.
*
* @param env kernel environment where the kernel object was created with av_opencl_create_kernel
*/
void av_opencl_release_kernel(AVOpenCLKernelEnv *env);
/**
* Release OpenCL environment.
*
* The OpenCL environment is effectively released only if all the created
* kernels had been released with av_opencl_release_kernel().
*/
void av_opencl_uninit(void);
#endif/*LIBAVUTIL_OPENCL_H*/
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment