3 Copyright (c) 2003-2015 HandBrake Team
4 This file is part of the HandBrake source code
5 Homepage: <http://handbrake.fr/>.
6 It may be used under the terms of the GNU General Public License v2.
7 For full terms see the file COPYING file or visit http://www.gnu.org/licenses/gpl-2.0.html
9 Authors: Peng Gao <peng@multicorewareinc.com> <http://www.multicorewareinc.com/>
10 Li Cao <li@multicorewareinc.com> <http://www.multicorewareinc.com/>
14 #ifndef HB_OPENCL_WRAPPER_H
15 #define HB_OPENCL_WRAPPER_H
18 #include "extras/cl.h"
21 #define CL_QUEUE_THREAD_HANDLE_AMD 0x403E
22 #define CL_MAP_WRITE_INVALIDATE_REGION (1 << 2)
24 typedef struct _KernelEnv
27 cl_command_queue command_queue
;
30 char kernel_name
[150];
34 typedef struct _OpenCLEnv
36 cl_platform_id platform
;
39 cl_command_queue command_queue
;
43 //user defined, this is function wrapper which is used to set the input parameters ,
44 //luanch kernel and copy data from GPU to CPU or CPU to GPU.
45 typedef int (*cl_kernel_function
)( void **userdata
, KernelEnv
*kenv
);
47 // registe a wapper for running the kernel specified by the kernel name
48 int hb_register_kernel_wrapper( const char *kernel_name
, cl_kernel_function function
);
50 // run kernel , user call this function to luanch kernel.
51 // kernel_name: this kernel name is used to find the kernel in opencl runtime environment
52 // userdata: this userdata is the all parameters for running the kernel specified by kernel name
53 int hb_run_kernel( const char *kernel_name
, void **userdata
);
55 // init the run time environment , this function must be called befor calling any function related to opencl
56 // the argc must be set zero , argv must be set NULL, build_option is the options for build the kernel.
57 int hb_init_opencl_run_env( int argc
, char **argv
, const char *build_option
);
59 //relase all resource about the opencl , this function must be called after calling any functions related to opencl
60 int hb_release_opencl_run_env();
62 // get the opencl status , 0: not init ; 1, inited; this function is used the check whether or not the opencl run time has been created
63 int hb_opencl_stats();
65 // update opencl run time environments , such as commandqueue , platforme, context. program
66 int hb_init_opencl_attr( OpenCLEnv
* env
);
68 // create kernel object by a kernel name on the specified opencl run time indicated by env parameter
69 int hb_create_kernel( char * kernelname
, KernelEnv
* env
);
71 // release kernel object which is generated by calling the hb_create_kernel api
72 int hb_release_kernel( KernelEnv
* env
);
74 void hb_opencl_init();
76 int hb_get_opencl_env();
78 int hb_create_buffer(cl_mem
*cl_Buf
,int flags
,int size
);
80 int hb_read_opencl_buffer(cl_mem cl_inBuf
,unsigned char *outbuf
,int size
);
82 int hb_cl_create_mapped_buffer(cl_mem
*mem
, unsigned char **addr
, int size
);
84 int hb_cl_free_mapped_buffer(cl_mem mem
, unsigned char *addr
);
88 int hb_confirm_gpu_type();
90 #endif // HB_OPENCL_WRAPPER_H