cl.h 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924
  1. /*
  2. * Copyright 2010-2013 Branimir Karadzic. All rights reserved.
  3. * License: http://www.opensource.org/licenses/BSD-2-Clause
  4. */
  5. #ifndef BX_CL_H_HEADER_GUARD
  6. #define BX_CL_H_HEADER_GUARD
  7. /// To implement OpenCL dynamic loading, define BX_CL_IMPLEMENTATION and
  8. /// #include <bx/cl.h> into .cpp file.
  9. ///
  10. /// To use it, just #include <bx/cl.h> without defining BX_CL_IMPLEMENTATION.
  11. /// To load dynamic library call bx::clLoad(), to unload it call bx::clUnload.
  12. namespace bx
  13. {
  14. /// Load OpenCL dynamic library.
  15. ///
  16. /// Returns internal reference count. If library is not available
  17. /// returns 0.
  18. ///
  19. int32_t clLoad();
  20. /// Unload OpenCL dynamic library.
  21. ///
  22. /// Returns internal reference count. When reference count reaches 0
  23. /// library is fully unloaded.
  24. ///
  25. int32_t clUnload();
  26. } // namespace bx
  27. #if defined(BX_CL_IMPLEMENTATION) && defined(__OPENCL_CL_H)
  28. # error message("CL/cl.h is already included, it cannot be included before bx/cl.h header when BX_CL_IMPLEMENTATION is defined!")
  29. #endif // defined(BX_CL_IMPLEMENTATION) && defined(__OPENCL_CL_H)
  30. #ifndef __OPENCL_CL_H
  31. #define __OPENCL_CL_H
  32. // BK - CL/cl.h header begin ------------------------------------------------->8
  33. /*******************************************************************************
  34. * Copyright (c) 2008 - 2012 The Khronos Group Inc.
  35. *
  36. * Permission is hereby granted, free of charge, to any person obtaining a
  37. * copy of this software and/or associated documentation files (the
  38. * "Materials"), to deal in the Materials without restriction, including
  39. * without limitation the rights to use, copy, modify, merge, publish,
  40. * distribute, sublicense, and/or sell copies of the Materials, and to
  41. * permit persons to whom the Materials are furnished to do so, subject to
  42. * the following conditions:
  43. *
  44. * The above copyright notice and this permission notice shall be included
  45. * in all copies or substantial portions of the Materials.
  46. *
  47. * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  48. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  49. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  50. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  51. * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  52. * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  53. * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
  54. ******************************************************************************/
  55. #ifdef __APPLE__
  56. #include <OpenCL/cl_platform.h>
  57. #else
  58. #include <CL/cl_platform.h>
  59. #endif
  60. #ifdef __cplusplus
  61. extern "C" {
  62. #endif
  63. /******************************************************************************/
  64. typedef struct _cl_platform_id * cl_platform_id;
  65. typedef struct _cl_device_id * cl_device_id;
  66. typedef struct _cl_context * cl_context;
  67. typedef struct _cl_command_queue * cl_command_queue;
  68. typedef struct _cl_mem * cl_mem;
  69. typedef struct _cl_program * cl_program;
  70. typedef struct _cl_kernel * cl_kernel;
  71. typedef struct _cl_event * cl_event;
  72. typedef struct _cl_sampler * cl_sampler;
  73. typedef cl_uint cl_bool; /* WARNING! Unlike cl_ types in cl_platform.h, cl_bool is not guaranteed to be the same size as the bool in kernels. */
  74. typedef cl_ulong cl_bitfield;
  75. typedef cl_bitfield cl_device_type;
  76. typedef cl_uint cl_platform_info;
  77. typedef cl_uint cl_device_info;
  78. typedef cl_bitfield cl_device_fp_config;
  79. typedef cl_uint cl_device_mem_cache_type;
  80. typedef cl_uint cl_device_local_mem_type;
  81. typedef cl_bitfield cl_device_exec_capabilities;
  82. typedef cl_bitfield cl_command_queue_properties;
  83. typedef intptr_t cl_device_partition_property;
  84. typedef cl_bitfield cl_device_affinity_domain;
  85. typedef intptr_t cl_context_properties;
  86. typedef cl_uint cl_context_info;
  87. typedef cl_uint cl_command_queue_info;
  88. typedef cl_uint cl_channel_order;
  89. typedef cl_uint cl_channel_type;
  90. typedef cl_bitfield cl_mem_flags;
  91. typedef cl_uint cl_mem_object_type;
  92. typedef cl_uint cl_mem_info;
  93. typedef cl_bitfield cl_mem_migration_flags;
  94. typedef cl_uint cl_image_info;
  95. typedef cl_uint cl_buffer_create_type;
  96. typedef cl_uint cl_addressing_mode;
  97. typedef cl_uint cl_filter_mode;
  98. typedef cl_uint cl_sampler_info;
  99. typedef cl_bitfield cl_map_flags;
  100. typedef cl_uint cl_program_info;
  101. typedef cl_uint cl_program_build_info;
  102. typedef cl_uint cl_program_binary_type;
  103. typedef cl_int cl_build_status;
  104. typedef cl_uint cl_kernel_info;
  105. typedef cl_uint cl_kernel_arg_info;
  106. typedef cl_uint cl_kernel_arg_address_qualifier;
  107. typedef cl_uint cl_kernel_arg_access_qualifier;
  108. typedef cl_bitfield cl_kernel_arg_type_qualifier;
  109. typedef cl_uint cl_kernel_work_group_info;
  110. typedef cl_uint cl_event_info;
  111. typedef cl_uint cl_command_type;
  112. typedef cl_uint cl_profiling_info;
  113. typedef struct _cl_image_format {
  114. cl_channel_order image_channel_order;
  115. cl_channel_type image_channel_data_type;
  116. } cl_image_format;
  117. typedef struct _cl_image_desc {
  118. cl_mem_object_type image_type;
  119. size_t image_width;
  120. size_t image_height;
  121. size_t image_depth;
  122. size_t image_array_size;
  123. size_t image_row_pitch;
  124. size_t image_slice_pitch;
  125. cl_uint num_mip_levels;
  126. cl_uint num_samples;
  127. cl_mem buffer;
  128. } cl_image_desc;
  129. typedef struct _cl_buffer_region {
  130. size_t origin;
  131. size_t size;
  132. } cl_buffer_region;
  133. /******************************************************************************/
  134. /* Error Codes */
  135. #define CL_SUCCESS 0
  136. #define CL_DEVICE_NOT_FOUND -1
  137. #define CL_DEVICE_NOT_AVAILABLE -2
  138. #define CL_COMPILER_NOT_AVAILABLE -3
  139. #define CL_MEM_OBJECT_ALLOCATION_FAILURE -4
  140. #define CL_OUT_OF_RESOURCES -5
  141. #define CL_OUT_OF_HOST_MEMORY -6
  142. #define CL_PROFILING_INFO_NOT_AVAILABLE -7
  143. #define CL_MEM_COPY_OVERLAP -8
  144. #define CL_IMAGE_FORMAT_MISMATCH -9
  145. #define CL_IMAGE_FORMAT_NOT_SUPPORTED -10
  146. #define CL_BUILD_PROGRAM_FAILURE -11
  147. #define CL_MAP_FAILURE -12
  148. #define CL_MISALIGNED_SUB_BUFFER_OFFSET -13
  149. #define CL_EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LIST -14
  150. #define CL_COMPILE_PROGRAM_FAILURE -15
  151. #define CL_LINKER_NOT_AVAILABLE -16
  152. #define CL_LINK_PROGRAM_FAILURE -17
  153. #define CL_DEVICE_PARTITION_FAILED -18
  154. #define CL_KERNEL_ARG_INFO_NOT_AVAILABLE -19
  155. #define CL_INVALID_VALUE -30
  156. #define CL_INVALID_DEVICE_TYPE -31
  157. #define CL_INVALID_PLATFORM -32
  158. #define CL_INVALID_DEVICE -33
  159. #define CL_INVALID_CONTEXT -34
  160. #define CL_INVALID_QUEUE_PROPERTIES -35
  161. #define CL_INVALID_COMMAND_QUEUE -36
  162. #define CL_INVALID_HOST_PTR -37
  163. #define CL_INVALID_MEM_OBJECT -38
  164. #define CL_INVALID_IMAGE_FORMAT_DESCRIPTOR -39
  165. #define CL_INVALID_IMAGE_SIZE -40
  166. #define CL_INVALID_SAMPLER -41
  167. #define CL_INVALID_BINARY -42
  168. #define CL_INVALID_BUILD_OPTIONS -43
  169. #define CL_INVALID_PROGRAM -44
  170. #define CL_INVALID_PROGRAM_EXECUTABLE -45
  171. #define CL_INVALID_KERNEL_NAME -46
  172. #define CL_INVALID_KERNEL_DEFINITION -47
  173. #define CL_INVALID_KERNEL -48
  174. #define CL_INVALID_ARG_INDEX -49
  175. #define CL_INVALID_ARG_VALUE -50
  176. #define CL_INVALID_ARG_SIZE -51
  177. #define CL_INVALID_KERNEL_ARGS -52
  178. #define CL_INVALID_WORK_DIMENSION -53
  179. #define CL_INVALID_WORK_GROUP_SIZE -54
  180. #define CL_INVALID_WORK_ITEM_SIZE -55
  181. #define CL_INVALID_GLOBAL_OFFSET -56
  182. #define CL_INVALID_EVENT_WAIT_LIST -57
  183. #define CL_INVALID_EVENT -58
  184. #define CL_INVALID_OPERATION -59
  185. #define CL_INVALID_GL_OBJECT -60
  186. #define CL_INVALID_BUFFER_SIZE -61
  187. #define CL_INVALID_MIP_LEVEL -62
  188. #define CL_INVALID_GLOBAL_WORK_SIZE -63
  189. #define CL_INVALID_PROPERTY -64
  190. #define CL_INVALID_IMAGE_DESCRIPTOR -65
  191. #define CL_INVALID_COMPILER_OPTIONS -66
  192. #define CL_INVALID_LINKER_OPTIONS -67
  193. #define CL_INVALID_DEVICE_PARTITION_COUNT -68
  194. /* OpenCL Version */
  195. #define CL_VERSION_1_0 1
  196. #define CL_VERSION_1_1 1
  197. #define CL_VERSION_1_2 1
  198. /* cl_bool */
  199. #define CL_FALSE 0
  200. #define CL_TRUE 1
  201. #define CL_BLOCKING CL_TRUE
  202. #define CL_NON_BLOCKING CL_FALSE
  203. /* cl_platform_info */
  204. #define CL_PLATFORM_PROFILE 0x0900
  205. #define CL_PLATFORM_VERSION 0x0901
  206. #define CL_PLATFORM_NAME 0x0902
  207. #define CL_PLATFORM_VENDOR 0x0903
  208. #define CL_PLATFORM_EXTENSIONS 0x0904
  209. /* cl_device_type - bitfield */
  210. #define CL_DEVICE_TYPE_DEFAULT (1 << 0)
  211. #define CL_DEVICE_TYPE_CPU (1 << 1)
  212. #define CL_DEVICE_TYPE_GPU (1 << 2)
  213. #define CL_DEVICE_TYPE_ACCELERATOR (1 << 3)
  214. #define CL_DEVICE_TYPE_CUSTOM (1 << 4)
  215. #define CL_DEVICE_TYPE_ALL 0xFFFFFFFF
  216. /* cl_device_info */
  217. #define CL_DEVICE_TYPE 0x1000
  218. #define CL_DEVICE_VENDOR_ID 0x1001
  219. #define CL_DEVICE_MAX_COMPUTE_UNITS 0x1002
  220. #define CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS 0x1003
  221. #define CL_DEVICE_MAX_WORK_GROUP_SIZE 0x1004
  222. #define CL_DEVICE_MAX_WORK_ITEM_SIZES 0x1005
  223. #define CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR 0x1006
  224. #define CL_DEVICE_PREFERRED_VECTOR_WIDTH_SHORT 0x1007
  225. #define CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT 0x1008
  226. #define CL_DEVICE_PREFERRED_VECTOR_WIDTH_LONG 0x1009
  227. #define CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT 0x100A
  228. #define CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE 0x100B
  229. #define CL_DEVICE_MAX_CLOCK_FREQUENCY 0x100C
  230. #define CL_DEVICE_ADDRESS_BITS 0x100D
  231. #define CL_DEVICE_MAX_READ_IMAGE_ARGS 0x100E
  232. #define CL_DEVICE_MAX_WRITE_IMAGE_ARGS 0x100F
  233. #define CL_DEVICE_MAX_MEM_ALLOC_SIZE 0x1010
  234. #define CL_DEVICE_IMAGE2D_MAX_WIDTH 0x1011
  235. #define CL_DEVICE_IMAGE2D_MAX_HEIGHT 0x1012
  236. #define CL_DEVICE_IMAGE3D_MAX_WIDTH 0x1013
  237. #define CL_DEVICE_IMAGE3D_MAX_HEIGHT 0x1014
  238. #define CL_DEVICE_IMAGE3D_MAX_DEPTH 0x1015
  239. #define CL_DEVICE_IMAGE_SUPPORT 0x1016
  240. #define CL_DEVICE_MAX_PARAMETER_SIZE 0x1017
  241. #define CL_DEVICE_MAX_SAMPLERS 0x1018
  242. #define CL_DEVICE_MEM_BASE_ADDR_ALIGN 0x1019
  243. #define CL_DEVICE_MIN_DATA_TYPE_ALIGN_SIZE 0x101A
  244. #define CL_DEVICE_SINGLE_FP_CONFIG 0x101B
  245. #define CL_DEVICE_GLOBAL_MEM_CACHE_TYPE 0x101C
  246. #define CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE 0x101D
  247. #define CL_DEVICE_GLOBAL_MEM_CACHE_SIZE 0x101E
  248. #define CL_DEVICE_GLOBAL_MEM_SIZE 0x101F
  249. #define CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE 0x1020
  250. #define CL_DEVICE_MAX_CONSTANT_ARGS 0x1021
  251. #define CL_DEVICE_LOCAL_MEM_TYPE 0x1022
  252. #define CL_DEVICE_LOCAL_MEM_SIZE 0x1023
  253. #define CL_DEVICE_ERROR_CORRECTION_SUPPORT 0x1024
  254. #define CL_DEVICE_PROFILING_TIMER_RESOLUTION 0x1025
  255. #define CL_DEVICE_ENDIAN_LITTLE 0x1026
  256. #define CL_DEVICE_AVAILABLE 0x1027
  257. #define CL_DEVICE_COMPILER_AVAILABLE 0x1028
  258. #define CL_DEVICE_EXECUTION_CAPABILITIES 0x1029
  259. #define CL_DEVICE_QUEUE_PROPERTIES 0x102A
  260. #define CL_DEVICE_NAME 0x102B
  261. #define CL_DEVICE_VENDOR 0x102C
  262. #define CL_DRIVER_VERSION 0x102D
  263. #define CL_DEVICE_PROFILE 0x102E
  264. #define CL_DEVICE_VERSION 0x102F
  265. #define CL_DEVICE_EXTENSIONS 0x1030
  266. #define CL_DEVICE_PLATFORM 0x1031
  267. #define CL_DEVICE_DOUBLE_FP_CONFIG 0x1032
  268. /* 0x1033 reserved for CL_DEVICE_HALF_FP_CONFIG */
  269. #define CL_DEVICE_PREFERRED_VECTOR_WIDTH_HALF 0x1034
  270. #define CL_DEVICE_HOST_UNIFIED_MEMORY 0x1035
  271. #define CL_DEVICE_NATIVE_VECTOR_WIDTH_CHAR 0x1036
  272. #define CL_DEVICE_NATIVE_VECTOR_WIDTH_SHORT 0x1037
  273. #define CL_DEVICE_NATIVE_VECTOR_WIDTH_INT 0x1038
  274. #define CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG 0x1039
  275. #define CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT 0x103A
  276. #define CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE 0x103B
  277. #define CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF 0x103C
  278. #define CL_DEVICE_OPENCL_C_VERSION 0x103D
  279. #define CL_DEVICE_LINKER_AVAILABLE 0x103E
  280. #define CL_DEVICE_BUILT_IN_KERNELS 0x103F
  281. #define CL_DEVICE_IMAGE_MAX_BUFFER_SIZE 0x1040
  282. #define CL_DEVICE_IMAGE_MAX_ARRAY_SIZE 0x1041
  283. #define CL_DEVICE_PARENT_DEVICE 0x1042
  284. #define CL_DEVICE_PARTITION_MAX_SUB_DEVICES 0x1043
  285. #define CL_DEVICE_PARTITION_PROPERTIES 0x1044
  286. #define CL_DEVICE_PARTITION_AFFINITY_DOMAIN 0x1045
  287. #define CL_DEVICE_PARTITION_TYPE 0x1046
  288. #define CL_DEVICE_REFERENCE_COUNT 0x1047
  289. #define CL_DEVICE_PREFERRED_INTEROP_USER_SYNC 0x1048
  290. #define CL_DEVICE_PRINTF_BUFFER_SIZE 0x1049
  291. #define CL_DEVICE_IMAGE_PITCH_ALIGNMENT 0x104A
  292. #define CL_DEVICE_IMAGE_BASE_ADDRESS_ALIGNMENT 0x104B
  293. /* cl_device_fp_config - bitfield */
  294. #define CL_FP_DENORM (1 << 0)
  295. #define CL_FP_INF_NAN (1 << 1)
  296. #define CL_FP_ROUND_TO_NEAREST (1 << 2)
  297. #define CL_FP_ROUND_TO_ZERO (1 << 3)
  298. #define CL_FP_ROUND_TO_INF (1 << 4)
  299. #define CL_FP_FMA (1 << 5)
  300. #define CL_FP_SOFT_FLOAT (1 << 6)
  301. #define CL_FP_CORRECTLY_ROUNDED_DIVIDE_SQRT (1 << 7)
  302. /* cl_device_mem_cache_type */
  303. #define CL_NONE 0x0
  304. #define CL_READ_ONLY_CACHE 0x1
  305. #define CL_READ_WRITE_CACHE 0x2
  306. /* cl_device_local_mem_type */
  307. #define CL_LOCAL 0x1
  308. #define CL_GLOBAL 0x2
  309. /* cl_device_exec_capabilities - bitfield */
  310. #define CL_EXEC_KERNEL (1 << 0)
  311. #define CL_EXEC_NATIVE_KERNEL (1 << 1)
  312. /* cl_command_queue_properties - bitfield */
  313. #define CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE (1 << 0)
  314. #define CL_QUEUE_PROFILING_ENABLE (1 << 1)
  315. /* cl_context_info */
  316. #define CL_CONTEXT_REFERENCE_COUNT 0x1080
  317. #define CL_CONTEXT_DEVICES 0x1081
  318. #define CL_CONTEXT_PROPERTIES 0x1082
  319. #define CL_CONTEXT_NUM_DEVICES 0x1083
  320. /* cl_context_properties */
  321. #define CL_CONTEXT_PLATFORM 0x1084
  322. #define CL_CONTEXT_INTEROP_USER_SYNC 0x1085
  323. /* cl_device_partition_property */
  324. #define CL_DEVICE_PARTITION_EQUALLY 0x1086
  325. #define CL_DEVICE_PARTITION_BY_COUNTS 0x1087
  326. #define CL_DEVICE_PARTITION_BY_COUNTS_LIST_END 0x0
  327. #define CL_DEVICE_PARTITION_BY_AFFINITY_DOMAIN 0x1088
  328. /* cl_device_affinity_domain */
  329. #define CL_DEVICE_AFFINITY_DOMAIN_NUMA (1 << 0)
  330. #define CL_DEVICE_AFFINITY_DOMAIN_L4_CACHE (1 << 1)
  331. #define CL_DEVICE_AFFINITY_DOMAIN_L3_CACHE (1 << 2)
  332. #define CL_DEVICE_AFFINITY_DOMAIN_L2_CACHE (1 << 3)
  333. #define CL_DEVICE_AFFINITY_DOMAIN_L1_CACHE (1 << 4)
  334. #define CL_DEVICE_AFFINITY_DOMAIN_NEXT_PARTITIONABLE (1 << 5)
  335. /* cl_command_queue_info */
  336. #define CL_QUEUE_CONTEXT 0x1090
  337. #define CL_QUEUE_DEVICE 0x1091
  338. #define CL_QUEUE_REFERENCE_COUNT 0x1092
  339. #define CL_QUEUE_PROPERTIES 0x1093
  340. /* cl_mem_flags - bitfield */
  341. #define CL_MEM_READ_WRITE (1 << 0)
  342. #define CL_MEM_WRITE_ONLY (1 << 1)
  343. #define CL_MEM_READ_ONLY (1 << 2)
  344. #define CL_MEM_USE_HOST_PTR (1 << 3)
  345. #define CL_MEM_ALLOC_HOST_PTR (1 << 4)
  346. #define CL_MEM_COPY_HOST_PTR (1 << 5)
  347. // reserved (1 << 6)
  348. #define CL_MEM_HOST_WRITE_ONLY (1 << 7)
  349. #define CL_MEM_HOST_READ_ONLY (1 << 8)
  350. #define CL_MEM_HOST_NO_ACCESS (1 << 9)
  351. /* cl_mem_migration_flags - bitfield */
  352. #define CL_MIGRATE_MEM_OBJECT_HOST (1 << 0)
  353. #define CL_MIGRATE_MEM_OBJECT_CONTENT_UNDEFINED (1 << 1)
  354. /* cl_channel_order */
  355. #define CL_R 0x10B0
  356. #define CL_A 0x10B1
  357. #define CL_RG 0x10B2
  358. #define CL_RA 0x10B3
  359. #define CL_RGB 0x10B4
  360. #define CL_RGBA 0x10B5
  361. #define CL_BGRA 0x10B6
  362. #define CL_ARGB 0x10B7
  363. #define CL_INTENSITY 0x10B8
  364. #define CL_LUMINANCE 0x10B9
  365. #define CL_Rx 0x10BA
  366. #define CL_RGx 0x10BB
  367. #define CL_RGBx 0x10BC
  368. #define CL_DEPTH 0x10BD
  369. #define CL_DEPTH_STENCIL 0x10BE
  370. /* cl_channel_type */
  371. #define CL_SNORM_INT8 0x10D0
  372. #define CL_SNORM_INT16 0x10D1
  373. #define CL_UNORM_INT8 0x10D2
  374. #define CL_UNORM_INT16 0x10D3
  375. #define CL_UNORM_SHORT_565 0x10D4
  376. #define CL_UNORM_SHORT_555 0x10D5
  377. #define CL_UNORM_INT_101010 0x10D6
  378. #define CL_SIGNED_INT8 0x10D7
  379. #define CL_SIGNED_INT16 0x10D8
  380. #define CL_SIGNED_INT32 0x10D9
  381. #define CL_UNSIGNED_INT8 0x10DA
  382. #define CL_UNSIGNED_INT16 0x10DB
  383. #define CL_UNSIGNED_INT32 0x10DC
  384. #define CL_HALF_FLOAT 0x10DD
  385. #define CL_FLOAT 0x10DE
  386. #define CL_UNORM_INT24 0x10DF
  387. /* cl_mem_object_type */
  388. #define CL_MEM_OBJECT_BUFFER 0x10F0
  389. #define CL_MEM_OBJECT_IMAGE2D 0x10F1
  390. #define CL_MEM_OBJECT_IMAGE3D 0x10F2
  391. #define CL_MEM_OBJECT_IMAGE2D_ARRAY 0x10F3
  392. #define CL_MEM_OBJECT_IMAGE1D 0x10F4
  393. #define CL_MEM_OBJECT_IMAGE1D_ARRAY 0x10F5
  394. #define CL_MEM_OBJECT_IMAGE1D_BUFFER 0x10F6
  395. /* cl_mem_info */
  396. #define CL_MEM_TYPE 0x1100
  397. #define CL_MEM_FLAGS 0x1101
  398. #define CL_MEM_SIZE 0x1102
  399. #define CL_MEM_HOST_PTR 0x1103
  400. #define CL_MEM_MAP_COUNT 0x1104
  401. #define CL_MEM_REFERENCE_COUNT 0x1105
  402. #define CL_MEM_CONTEXT 0x1106
  403. #define CL_MEM_ASSOCIATED_MEMOBJECT 0x1107
  404. #define CL_MEM_OFFSET 0x1108
  405. /* cl_image_info */
  406. #define CL_IMAGE_FORMAT 0x1110
  407. #define CL_IMAGE_ELEMENT_SIZE 0x1111
  408. #define CL_IMAGE_ROW_PITCH 0x1112
  409. #define CL_IMAGE_SLICE_PITCH 0x1113
  410. #define CL_IMAGE_WIDTH 0x1114
  411. #define CL_IMAGE_HEIGHT 0x1115
  412. #define CL_IMAGE_DEPTH 0x1116
  413. #define CL_IMAGE_ARRAY_SIZE 0x1117
  414. #define CL_IMAGE_BUFFER 0x1118
  415. #define CL_IMAGE_NUM_MIP_LEVELS 0x1119
  416. #define CL_IMAGE_NUM_SAMPLES 0x111A
  417. /* cl_addressing_mode */
  418. #define CL_ADDRESS_NONE 0x1130
  419. #define CL_ADDRESS_CLAMP_TO_EDGE 0x1131
  420. #define CL_ADDRESS_CLAMP 0x1132
  421. #define CL_ADDRESS_REPEAT 0x1133
  422. #define CL_ADDRESS_MIRRORED_REPEAT 0x1134
  423. /* cl_filter_mode */
  424. #define CL_FILTER_NEAREST 0x1140
  425. #define CL_FILTER_LINEAR 0x1141
  426. /* cl_sampler_info */
  427. #define CL_SAMPLER_REFERENCE_COUNT 0x1150
  428. #define CL_SAMPLER_CONTEXT 0x1151
  429. #define CL_SAMPLER_NORMALIZED_COORDS 0x1152
  430. #define CL_SAMPLER_ADDRESSING_MODE 0x1153
  431. #define CL_SAMPLER_FILTER_MODE 0x1154
  432. /* cl_map_flags - bitfield */
  433. #define CL_MAP_READ (1 << 0)
  434. #define CL_MAP_WRITE (1 << 1)
  435. #define CL_MAP_WRITE_INVALIDATE_REGION (1 << 2)
  436. /* cl_program_info */
  437. #define CL_PROGRAM_REFERENCE_COUNT 0x1160
  438. #define CL_PROGRAM_CONTEXT 0x1161
  439. #define CL_PROGRAM_NUM_DEVICES 0x1162
  440. #define CL_PROGRAM_DEVICES 0x1163
  441. #define CL_PROGRAM_SOURCE 0x1164
  442. #define CL_PROGRAM_BINARY_SIZES 0x1165
  443. #define CL_PROGRAM_BINARIES 0x1166
  444. #define CL_PROGRAM_NUM_KERNELS 0x1167
  445. #define CL_PROGRAM_KERNEL_NAMES 0x1168
  446. /* cl_program_build_info */
  447. #define CL_PROGRAM_BUILD_STATUS 0x1181
  448. #define CL_PROGRAM_BUILD_OPTIONS 0x1182
  449. #define CL_PROGRAM_BUILD_LOG 0x1183
  450. #define CL_PROGRAM_BINARY_TYPE 0x1184
  451. /* cl_program_binary_type */
  452. #define CL_PROGRAM_BINARY_TYPE_NONE 0x0
  453. #define CL_PROGRAM_BINARY_TYPE_COMPILED_OBJECT 0x1
  454. #define CL_PROGRAM_BINARY_TYPE_LIBRARY 0x2
  455. #define CL_PROGRAM_BINARY_TYPE_EXECUTABLE 0x4
  456. /* cl_build_status */
  457. #define CL_BUILD_SUCCESS 0
  458. #define CL_BUILD_NONE -1
  459. #define CL_BUILD_ERROR -2
  460. #define CL_BUILD_IN_PROGRESS -3
  461. /* cl_kernel_info */
  462. #define CL_KERNEL_FUNCTION_NAME 0x1190
  463. #define CL_KERNEL_NUM_ARGS 0x1191
  464. #define CL_KERNEL_REFERENCE_COUNT 0x1192
  465. #define CL_KERNEL_CONTEXT 0x1193
  466. #define CL_KERNEL_PROGRAM 0x1194
  467. #define CL_KERNEL_ATTRIBUTES 0x1195
  468. /* cl_kernel_arg_info */
  469. #define CL_KERNEL_ARG_ADDRESS_QUALIFIER 0x1196
  470. #define CL_KERNEL_ARG_ACCESS_QUALIFIER 0x1197
  471. #define CL_KERNEL_ARG_TYPE_NAME 0x1198
  472. #define CL_KERNEL_ARG_TYPE_QUALIFIER 0x1199
  473. #define CL_KERNEL_ARG_NAME 0x119A
  474. /* cl_kernel_arg_address_qualifier */
  475. #define CL_KERNEL_ARG_ADDRESS_GLOBAL 0x119B
  476. #define CL_KERNEL_ARG_ADDRESS_LOCAL 0x119C
  477. #define CL_KERNEL_ARG_ADDRESS_CONSTANT 0x119D
  478. #define CL_KERNEL_ARG_ADDRESS_PRIVATE 0x119E
  479. /* cl_kernel_arg_access_qualifier */
  480. #define CL_KERNEL_ARG_ACCESS_READ_ONLY 0x11A0
  481. #define CL_KERNEL_ARG_ACCESS_WRITE_ONLY 0x11A1
  482. #define CL_KERNEL_ARG_ACCESS_READ_WRITE 0x11A2
  483. #define CL_KERNEL_ARG_ACCESS_NONE 0x11A3
  484. /* cl_kernel_arg_type_qualifer */
  485. #define CL_KERNEL_ARG_TYPE_NONE 0
  486. #define CL_KERNEL_ARG_TYPE_CONST (1 << 0)
  487. #define CL_KERNEL_ARG_TYPE_RESTRICT (1 << 1)
  488. #define CL_KERNEL_ARG_TYPE_VOLATILE (1 << 2)
  489. /* cl_kernel_work_group_info */
  490. #define CL_KERNEL_WORK_GROUP_SIZE 0x11B0
  491. #define CL_KERNEL_COMPILE_WORK_GROUP_SIZE 0x11B1
  492. #define CL_KERNEL_LOCAL_MEM_SIZE 0x11B2
  493. #define CL_KERNEL_PREFERRED_WORK_GROUP_SIZE_MULTIPLE 0x11B3
  494. #define CL_KERNEL_PRIVATE_MEM_SIZE 0x11B4
  495. #define CL_KERNEL_GLOBAL_WORK_SIZE 0x11B5
  496. /* cl_event_info */
  497. #define CL_EVENT_COMMAND_QUEUE 0x11D0
  498. #define CL_EVENT_COMMAND_TYPE 0x11D1
  499. #define CL_EVENT_REFERENCE_COUNT 0x11D2
  500. #define CL_EVENT_COMMAND_EXECUTION_STATUS 0x11D3
  501. #define CL_EVENT_CONTEXT 0x11D4
  502. /* cl_command_type */
  503. #define CL_COMMAND_NDRANGE_KERNEL 0x11F0
  504. #define CL_COMMAND_TASK 0x11F1
  505. #define CL_COMMAND_NATIVE_KERNEL 0x11F2
  506. #define CL_COMMAND_READ_BUFFER 0x11F3
  507. #define CL_COMMAND_WRITE_BUFFER 0x11F4
  508. #define CL_COMMAND_COPY_BUFFER 0x11F5
  509. #define CL_COMMAND_READ_IMAGE 0x11F6
  510. #define CL_COMMAND_WRITE_IMAGE 0x11F7
  511. #define CL_COMMAND_COPY_IMAGE 0x11F8
  512. #define CL_COMMAND_COPY_IMAGE_TO_BUFFER 0x11F9
  513. #define CL_COMMAND_COPY_BUFFER_TO_IMAGE 0x11FA
  514. #define CL_COMMAND_MAP_BUFFER 0x11FB
  515. #define CL_COMMAND_MAP_IMAGE 0x11FC
  516. #define CL_COMMAND_UNMAP_MEM_OBJECT 0x11FD
  517. #define CL_COMMAND_MARKER 0x11FE
  518. #define CL_COMMAND_ACQUIRE_GL_OBJECTS 0x11FF
  519. #define CL_COMMAND_RELEASE_GL_OBJECTS 0x1200
  520. #define CL_COMMAND_READ_BUFFER_RECT 0x1201
  521. #define CL_COMMAND_WRITE_BUFFER_RECT 0x1202
  522. #define CL_COMMAND_COPY_BUFFER_RECT 0x1203
  523. #define CL_COMMAND_USER 0x1204
  524. #define CL_COMMAND_BARRIER 0x1205
  525. #define CL_COMMAND_MIGRATE_MEM_OBJECTS 0x1206
  526. #define CL_COMMAND_FILL_BUFFER 0x1207
  527. #define CL_COMMAND_FILL_IMAGE 0x1208
  528. /* command execution status */
  529. #define CL_COMPLETE 0x0
  530. #define CL_RUNNING 0x1
  531. #define CL_SUBMITTED 0x2
  532. #define CL_QUEUED 0x3
  533. /* cl_buffer_create_type */
  534. #define CL_BUFFER_CREATE_TYPE_REGION 0x1220
  535. /* cl_profiling_info */
  536. #define CL_PROFILING_COMMAND_QUEUED 0x1280
  537. #define CL_PROFILING_COMMAND_SUBMIT 0x1281
  538. #define CL_PROFILING_COMMAND_START 0x1282
  539. #define CL_PROFILING_COMMAND_END 0x1283
  540. #ifdef __cplusplus
  541. } //extern "C"
  542. #endif
  543. // BK - CL/cl.h header end --------------------------------------------------->8
  544. // 1.1
  545. typedef cl_int (CL_API_CALL* PFNCLGETPLATFORMIDSPROC)(cl_uint, cl_platform_id*, cl_uint*);
  546. typedef cl_int (CL_API_CALL* PFNCLGETPLATFORMINFOPROC)(cl_platform_id, cl_platform_info, size_t, void*, size_t*);
  547. typedef cl_int (CL_API_CALL* PFNCLGETDEVICEINFOPROC)(cl_device_id, cl_device_info, size_t, void*, size_t*);
  548. typedef cl_int (CL_API_CALL* PFNCLGETDEVICEIDSPROC)(cl_platform_id, cl_device_type, cl_uint, cl_device_id*, cl_uint*);
  549. typedef cl_context (CL_API_CALL* PFNCLCREATECONTEXTPROC)(const cl_context_properties*, cl_uint, const cl_device_id*, void (CL_CALLBACK*)(const char*, const void*, size_t, void*), void*, cl_int*);
  550. typedef cl_context (CL_API_CALL* PFNCLCREATECONTEXTFROMTYPEPROC)(const cl_context_properties *, cl_device_type, void (CL_CALLBACK*)(const char*, const void*, size_t, void*), void*, cl_int*);
  551. typedef cl_int (CL_API_CALL* PFNCLRETAINCONTEXTPROC)(cl_context);
  552. typedef cl_int (CL_API_CALL* PFNCLRELEASECONTEXTPROC)(cl_context);
  553. typedef cl_int (CL_API_CALL* PFNCLGETCONTEXTINFOPROC)(cl_context, cl_context_info, size_t, void*, size_t*);
  554. typedef cl_command_queue (CL_API_CALL* PFNCLCREATECOMMANDQUEUEPROC)(cl_context, cl_device_id, cl_command_queue_properties, cl_int*);
  555. typedef cl_int (CL_API_CALL* PFNCLRETAINCOMMANDQUEUEPROC)(cl_command_queue);
  556. typedef cl_int (CL_API_CALL* PFNCLRELEASECOMMANDQUEUEPROC)(cl_command_queue);
  557. typedef cl_int (CL_API_CALL* PFNCLGETCOMMANDQUEUEINFOPROC)(cl_command_queue, cl_command_queue_info, size_t, void*, size_t*);
  558. typedef cl_mem (CL_API_CALL* PFNCLCREATEBUFFERPROC)(cl_context, cl_mem_flags, size_t, void*, cl_int*);
  559. typedef cl_int (CL_API_CALL* PFNCLRETAINMEMOBJECTPROC)(cl_mem);
  560. typedef cl_int (CL_API_CALL* PFNCLRELEASEMEMOBJECTPROC)(cl_mem);
  561. typedef cl_int (CL_API_CALL* PFNCLGETSUPPORTEDIMAGEFORMATSPROC)(cl_context, cl_mem_flags, cl_mem_object_type, cl_uint, cl_image_format*, cl_uint*);
  562. typedef cl_int (CL_API_CALL* PFNCLGETMEMOBJECTINFOPROC)(cl_mem, cl_mem_info, size_t, void*, size_t*);
  563. typedef cl_int (CL_API_CALL* PFNCLGETIMAGEINFOPROC)(cl_mem, cl_image_info, size_t, void*, size_t*);
  564. typedef cl_sampler (CL_API_CALL* PFNCLCREATESAMPLERPROC)(cl_context, cl_bool, cl_addressing_mode, cl_filter_mode, cl_int*);
  565. typedef cl_int (CL_API_CALL* PFNCLRETAINSAMPLERPROC)(cl_sampler);
  566. typedef cl_int (CL_API_CALL* PFNCLRELEASESAMPLERPROC)(cl_sampler);
  567. typedef cl_int (CL_API_CALL* PFNCLGETSAMPLERINFOPROC)(cl_sampler, cl_sampler_info, size_t, void*, size_t*);
  568. typedef cl_program (CL_API_CALL* PFNCLCREATEPROGRAMWITHSOURCEPROC)(cl_context, cl_uint, const char**, const size_t*, cl_int*);
  569. typedef cl_program (CL_API_CALL* PFNCLCREATEPROGRAMWITHBINARYPROC)(cl_context, cl_uint, const cl_device_id*, const size_t*, const unsigned char**, cl_int*, cl_int*);
  570. typedef cl_int (CL_API_CALL* PFNCLRETAINPROGRAMPROC)(cl_program);
  571. typedef cl_int (CL_API_CALL* PFNCLRELEASEPROGRAMPROC)(cl_program);
  572. typedef cl_int (CL_API_CALL* PFNCLBUILDPROGRAMPROC)(cl_program, cl_uint, const cl_device_id *, const char *, void (CL_CALLBACK*)(cl_program, void*), void*);
  573. typedef cl_int (CL_API_CALL* PFNCLGETPROGRAMINFOPROC)(cl_program, cl_program_info, size_t, void*, size_t*);
  574. typedef cl_int (CL_API_CALL* PFNCLGETPROGRAMBUILDINFOPROC)(cl_program, cl_device_id, cl_program_build_info, size_t, void*, size_t*);
  575. typedef cl_kernel (CL_API_CALL* PFNCLCREATEKERNELPROC)(cl_program, const char*, cl_int*);
  576. typedef cl_int (CL_API_CALL* PFNCLCREATEKERNELSINPROGRAMPROC)(cl_program, cl_uint, cl_kernel*, cl_uint*);
  577. typedef cl_int (CL_API_CALL* PFNCLRETAINKERNELPROC)(cl_kernel);
  578. typedef cl_int (CL_API_CALL* PFNCLRELEASEKERNELPROC)(cl_kernel);
  579. typedef cl_int (CL_API_CALL* PFNCLSETKERNELARGPROC)(cl_kernel, cl_uint, size_t, const void*);
  580. typedef cl_int (CL_API_CALL* PFNCLGETKERNELINFOPROC)(cl_kernel, cl_kernel_info, size_t, void*, size_t*);
  581. typedef cl_int (CL_API_CALL* PFNCLGETKERNELWORKGROUPINFOPROC)(cl_kernel, cl_device_id, cl_kernel_work_group_info, size_t, void*, size_t*);
  582. typedef cl_int (CL_API_CALL* PFNCLWAITFOREVENTSPROC)(cl_uint, const cl_event*);
  583. typedef cl_int (CL_API_CALL* PFNCLGETEVENTINFOPROC)(cl_event, cl_event_info, size_t, void*, size_t*);
  584. typedef cl_int (CL_API_CALL* PFNCLRETAINEVENTPROC)(cl_event);
  585. typedef cl_int (CL_API_CALL* PFNCLRELEASEEVENTPROC)(cl_event);
  586. typedef cl_int (CL_API_CALL* PFNCLGETEVENTPROFILINGINFOPROC)(cl_event, cl_profiling_info, size_t, void*, size_t*);
  587. typedef cl_int (CL_API_CALL* PFNCLFLUSHPROC)(cl_command_queue);
  588. typedef cl_int (CL_API_CALL* PFNCLFINISHPROC)(cl_command_queue);
  589. typedef cl_int (CL_API_CALL* PFNCLENQUEUEREADBUFFERPROC)(cl_command_queue, cl_mem, cl_bool, size_t, size_t, void*, cl_uint, const cl_event*, cl_event*);
  590. typedef cl_int (CL_API_CALL* PFNCLENQUEUEWRITEBUFFERPROC)(cl_command_queue, cl_mem, cl_bool, size_t, size_t, const void*, cl_uint, const cl_event*, cl_event*);
  591. typedef cl_int (CL_API_CALL* PFNCLENQUEUECOPYBUFFERPROC)(cl_command_queue, cl_mem, cl_mem, size_t, size_t, size_t, cl_uint, const cl_event*, cl_event*);
  592. typedef cl_int (CL_API_CALL* PFNCLENQUEUEREADIMAGEPROC)(cl_command_queue, cl_mem, cl_bool, const size_t*, const size_t*, size_t, size_t, void*, cl_uint, const cl_event*, cl_event*);
  593. typedef cl_int (CL_API_CALL* PFNCLENQUEUEWRITEIMAGEPROC)(cl_command_queue, cl_mem, cl_bool, const size_t*, const size_t*, size_t, size_t, const void*, cl_uint, const cl_event*, cl_event*);
  594. typedef cl_int (CL_API_CALL* PFNCLENQUEUECOPYIMAGEPROC)(cl_command_queue, cl_mem, cl_mem, const size_t*, const size_t*, const size_t*, cl_uint, const cl_event*, cl_event*);
  595. typedef cl_int (CL_API_CALL* PFNCLENQUEUECOPYIMAGETOBUFFERPROC)(cl_command_queue, cl_mem, cl_mem, const size_t*, const size_t*, size_t, cl_uint, const cl_event*, cl_event*);
  596. typedef cl_int (CL_API_CALL* PFNCLENQUEUECOPYBUFFERTOIMAGEPROC)(cl_command_queue, cl_mem, cl_mem, size_t, const size_t*, const size_t*, cl_uint, const cl_event*, cl_event*);
  597. typedef void (CL_API_CALL* PFNCLENQUEUEMAPBUFFERPROC)(cl_command_queue, cl_mem, cl_bool, cl_map_flags, size_t, size_t, cl_uint, const cl_event*, cl_event*, cl_int*);
  598. typedef void (CL_API_CALL* PFNCLENQUEUEMAPIMAGEPROC)(cl_command_queue, cl_mem, cl_bool, cl_map_flags, const size_t *, const size_t *, size_t *, size_t *, cl_uint, const cl_event *, cl_event *, cl_int*);
  599. typedef cl_int (CL_API_CALL* PFNCLENQUEUEUNMAPMEMOBJECTPROC)(cl_command_queue, cl_mem, void*, cl_uint, const cl_event*, cl_event*);
  600. typedef cl_int (CL_API_CALL* PFNCLENQUEUENDRANGEKERNELPROC)(cl_command_queue, cl_kernel, cl_uint, const size_t*, const size_t*, const size_t*, cl_uint, const cl_event*, cl_event*);
  601. typedef cl_int (CL_API_CALL* PFNCLENQUEUETASKPROC)(cl_command_queue, cl_kernel, cl_uint, const cl_event*, cl_event*);
  602. typedef cl_int (CL_API_CALL* PFNCLENQUEUENATIVEKERNELPROC)(cl_command_queue, void (CL_CALLBACK*)(void*), void*, size_t, cl_uint, const cl_mem*, const void**, cl_uint, const cl_event*, cl_event*);
  603. // 1.1
  604. typedef cl_mem (CL_API_CALL* PFNCLCREATEIMAGE2DPROC)(cl_context, cl_mem_flags, const cl_image_format*, size_t, size_t, size_t, void*, cl_int*);
  605. typedef cl_mem (CL_API_CALL* PFNCLCREATEIMAGE3DPROC)(cl_context, cl_mem_flags, const cl_image_format*, size_t, size_t, size_t, size_t, size_t, void*, cl_int*);
  606. typedef cl_mem (CL_API_CALL* PFNCLCREATESUBBUFFERPROC)(cl_mem, cl_mem_flags, cl_buffer_create_type, const void*, cl_int*);
  607. typedef cl_int (CL_API_CALL* PFNCLSETMEMOBJECTDESTRUCTORCALLBACKPROC)(cl_mem, void (CL_CALLBACK*)(cl_mem, void*), void*);
  608. typedef cl_event (CL_API_CALL* PFNCLCREATEUSEREVENTPROC)(cl_context, cl_int*);
  609. typedef cl_int (CL_API_CALL* PFNCLSETUSEREVENTSTATUSPROC)(cl_event, cl_int);
  610. typedef cl_int (CL_API_CALL* PFNCLSETEVENTCALLBACKPROC)(cl_event, cl_int, void (CL_CALLBACK*)(cl_event, cl_int, void*), void*);
  611. typedef cl_int (CL_API_CALL* PFNCLENQUEUEREADBUFFERRECTPROC)(cl_command_queue, cl_mem, cl_bool, const size_t *, const size_t *, const size_t *, size_t, size_t, size_t, size_t, void*, cl_uint, const cl_event*, cl_event*);
  612. typedef cl_int (CL_API_CALL* PFNCLENQUEUEWRITEBUFFERRECTPROC)(cl_command_queue, cl_mem, cl_bool, const size_t *, const size_t *, const size_t *, size_t, size_t, size_t, size_t, const void*, cl_uint, const cl_event*, cl_event*);
  613. typedef cl_int (CL_API_CALL* PFNCLENQUEUECOPYBUFFERRECTPROC)(cl_command_queue, cl_mem, cl_mem, const size_t*, const size_t*, const size_t*, size_t, size_t, size_t, size_t, cl_uint, const cl_event*, cl_event*);
  614. // 1.2
  615. typedef cl_int (CL_API_CALL* PFNCLCREATESUBDEVICESPROC)(cl_device_id, const cl_device_partition_property*, cl_uint, cl_device_id*, cl_uint*);
  616. typedef cl_int (CL_API_CALL* PFNCLRETAINDEVICEPROC)(cl_device_id);
  617. typedef cl_int (CL_API_CALL* PFNCLRELEASEDEVICEPROC)(cl_device_id);
  618. typedef cl_mem (CL_API_CALL* PFNCLCREATEIMAGEPROC)(cl_context, cl_mem_flags, const cl_image_format*, const cl_image_desc*, void*, cl_int*);
  619. typedef cl_program (CL_API_CALL* PFNCLCREATEPROGRAMWITHBUILTINKERNELSPROC)(cl_context, cl_uint, const cl_device_id*, const char*, cl_int*);
  620. typedef cl_int (CL_API_CALL* PFNCLCOMPILEPROGRAMPROC)(cl_program, cl_uint, const cl_device_id*, const char*, cl_uint, const cl_program*, const char**, void (CL_CALLBACK*)(cl_program, void*), void*);
  621. typedef cl_program (CL_API_CALL* PFNCLLINKPROGRAMPROC)(cl_context, cl_uint, const cl_device_id*, const char*, cl_uint, const cl_program*, void (CL_CALLBACK*)(cl_program, void*), void*, cl_int*);
  622. typedef cl_int (CL_API_CALL* PFNCLUNLOADPLATFORMCOMPILERPROC)(cl_platform_id);
  623. typedef cl_int (CL_API_CALL* PFNCLGETKERNELARGINFOPROC)(cl_kernel, cl_uint, cl_kernel_arg_info, size_t, void*, size_t*);
  624. typedef cl_int (CL_API_CALL* PFNCLENQUEUEFILLBUFFERPROC)(cl_command_queue, cl_mem, const void*, size_t, size_t, size_t, cl_uint, const cl_event*, cl_event *);
  625. typedef cl_int (CL_API_CALL* PFNCLENQUEUEFILLIMAGEPROC)(cl_command_queue, cl_mem, const void*, const size_t*, const size_t*, cl_uint, const cl_event*, cl_event*);
  626. typedef cl_int (CL_API_CALL* PFNCLENQUEUEMIGRATEMEMOBJECTSPROC)(cl_command_queue, cl_uint, const cl_mem*, cl_mem_migration_flags, cl_uint, const cl_event *, cl_event*);
  627. typedef cl_int (CL_API_CALL* PFNCLENQUEUEMARKERWITHWAITLISTPROC)(cl_command_queue, cl_uint, const cl_event*, cl_event*);
  628. typedef cl_int (CL_API_CALL* PFNCLENQUEUEBARRIERWITHWAITLISTPROC)(cl_command_queue, cl_uint, const cl_event *, cl_event*);
  629. #define BX_CL_IMPORT_ALL_10 \
  630. /* Platform API */ \
  631. BX_CL_IMPORT_10(false, PFNCLGETPLATFORMIDSPROC, clGetPlatformIDs); \
  632. BX_CL_IMPORT_10(false, PFNCLGETPLATFORMINFOPROC, clGetPlatformInfo); \
  633. /* Device APIs */ \
  634. BX_CL_IMPORT_10(false, PFNCLGETDEVICEIDSPROC, clGetDeviceIDs); \
  635. BX_CL_IMPORT_10(false, PFNCLGETDEVICEINFOPROC, clGetDeviceInfo); \
  636. /* Context APIs */ \
  637. BX_CL_IMPORT_10(false, PFNCLCREATECONTEXTPROC, clCreateContext); \
  638. BX_CL_IMPORT_10(false, PFNCLCREATECONTEXTFROMTYPEPROC, clCreateContextFromType); \
  639. BX_CL_IMPORT_10(false, PFNCLRETAINCONTEXTPROC, clRetainContext); \
  640. BX_CL_IMPORT_10(false, PFNCLRELEASECONTEXTPROC, clReleaseContext); \
  641. BX_CL_IMPORT_10(false, PFNCLGETCONTEXTINFOPROC, clGetContextInfo); \
  642. /* Command Queue APIs */ \
  643. BX_CL_IMPORT_10(false, PFNCLCREATECOMMANDQUEUEPROC, clCreateCommandQueue); \
  644. BX_CL_IMPORT_10(false, PFNCLRETAINCOMMANDQUEUEPROC, clRetainCommandQueue); \
  645. BX_CL_IMPORT_10(false, PFNCLRELEASECOMMANDQUEUEPROC, clReleaseCommandQueue); \
  646. BX_CL_IMPORT_10(false, PFNCLGETCOMMANDQUEUEINFOPROC, clGetCommandQueueInfo); \
  647. /* Memory Object APIs */ \
  648. BX_CL_IMPORT_10(false, PFNCLCREATEBUFFERPROC, clCreateBuffer); \
  649. BX_CL_IMPORT_10(false, PFNCLRETAINMEMOBJECTPROC, clRetainMemObject); \
  650. BX_CL_IMPORT_10(false, PFNCLRELEASEMEMOBJECTPROC, clReleaseMemObject); \
  651. BX_CL_IMPORT_10(false, PFNCLGETSUPPORTEDIMAGEFORMATSPROC, clGetSupportedImageFormats); \
  652. BX_CL_IMPORT_10(false, PFNCLGETMEMOBJECTINFOPROC, clGetMemObjectInfo); \
  653. BX_CL_IMPORT_10(false, PFNCLGETIMAGEINFOPROC, clGetImageInfo); \
  654. /* Sampler APIs */ \
  655. BX_CL_IMPORT_10(false, PFNCLCREATESAMPLERPROC, clCreateSampler); \
  656. BX_CL_IMPORT_10(false, PFNCLRETAINSAMPLERPROC, clRetainSampler); \
  657. BX_CL_IMPORT_10(false, PFNCLRELEASESAMPLERPROC, clReleaseSampler); \
  658. BX_CL_IMPORT_10(false, PFNCLGETSAMPLERINFOPROC, clGetSamplerInfo); \
  659. /* Program Object APIs */ \
  660. BX_CL_IMPORT_10(false, PFNCLCREATEPROGRAMWITHSOURCEPROC, clCreateProgramWithSource); \
  661. BX_CL_IMPORT_10(false, PFNCLCREATEPROGRAMWITHBINARYPROC, clCreateProgramWithBinary); \
  662. BX_CL_IMPORT_10(false, PFNCLRETAINPROGRAMPROC, clRetainProgram); \
  663. BX_CL_IMPORT_10(false, PFNCLRELEASEPROGRAMPROC, clReleaseProgram); \
  664. BX_CL_IMPORT_10(false, PFNCLBUILDPROGRAMPROC, clBuildProgram); \
  665. BX_CL_IMPORT_10(false, PFNCLGETPROGRAMINFOPROC, clGetProgramInfo); \
  666. BX_CL_IMPORT_10(false, PFNCLGETPROGRAMBUILDINFOPROC, clGetProgramBuildInfo); \
  667. /* Kernel Object APIs */ \
  668. BX_CL_IMPORT_10(false, PFNCLCREATEKERNELPROC, clCreateKernel); \
  669. BX_CL_IMPORT_10(false, PFNCLCREATEKERNELSINPROGRAMPROC, clCreateKernelsInProgram); \
  670. BX_CL_IMPORT_10(false, PFNCLRETAINKERNELPROC, clRetainKernel); \
  671. BX_CL_IMPORT_10(false, PFNCLRELEASEKERNELPROC, clReleaseKernel); \
  672. BX_CL_IMPORT_10(false, PFNCLSETKERNELARGPROC, clSetKernelArg); \
  673. BX_CL_IMPORT_10(false, PFNCLGETKERNELINFOPROC, clGetKernelInfo); \
  674. BX_CL_IMPORT_10(false, PFNCLGETKERNELWORKGROUPINFOPROC, clGetKernelWorkGroupInfo); \
  675. /* Event Object APIs */ \
  676. BX_CL_IMPORT_10(false, PFNCLWAITFOREVENTSPROC, clWaitForEvents); \
  677. BX_CL_IMPORT_10(false, PFNCLGETEVENTINFOPROC, clGetEventInfo); \
  678. BX_CL_IMPORT_10(false, PFNCLRETAINEVENTPROC, clRetainEvent); \
  679. BX_CL_IMPORT_10(false, PFNCLRELEASEEVENTPROC, clReleaseEvent); \
  680. /* Profiling APIs */ \
  681. BX_CL_IMPORT_10(false, PFNCLGETEVENTPROFILINGINFOPROC, clGetEventProfilingInfo); \
  682. /* Flush and Finish APIs */ \
  683. BX_CL_IMPORT_10(false, PFNCLFLUSHPROC, clFlush); \
  684. BX_CL_IMPORT_10(false, PFNCLFINISHPROC, clFinish); \
  685. /* Enqueued Commands APIs */ \
  686. BX_CL_IMPORT_10(false, PFNCLENQUEUEREADBUFFERPROC, clEnqueueReadBuffer); \
  687. BX_CL_IMPORT_10(false, PFNCLENQUEUEWRITEBUFFERPROC, clEnqueueWriteBuffer); \
  688. BX_CL_IMPORT_10(false, PFNCLENQUEUECOPYBUFFERPROC, clEnqueueCopyBuffer); \
  689. BX_CL_IMPORT_10(false, PFNCLENQUEUEREADIMAGEPROC, clEnqueueReadImage); \
  690. BX_CL_IMPORT_10(false, PFNCLENQUEUEWRITEIMAGEPROC, clEnqueueWriteImage); \
  691. BX_CL_IMPORT_10(false, PFNCLENQUEUECOPYIMAGEPROC, clEnqueueCopyImage); \
  692. BX_CL_IMPORT_10(false, PFNCLENQUEUECOPYIMAGETOBUFFERPROC, clEnqueueCopyImageToBuffer); \
  693. BX_CL_IMPORT_10(false, PFNCLENQUEUEMAPBUFFERPROC, clEnqueueMapBuffer); \
  694. BX_CL_IMPORT_10(false, PFNCLENQUEUEMAPIMAGEPROC, clEnqueueMapImage); \
  695. BX_CL_IMPORT_10(false, PFNCLENQUEUEUNMAPMEMOBJECTPROC, clEnqueueUnmapMemObject); \
  696. BX_CL_IMPORT_10(false, PFNCLENQUEUENDRANGEKERNELPROC, clEnqueueNDRangeKernel); \
  697. BX_CL_IMPORT_10(false, PFNCLENQUEUETASKPROC, clEnqueueTask); \
  698. BX_CL_IMPORT_10(false, PFNCLENQUEUENATIVEKERNELPROC, clEnqueueNativeKernel); \
  699. \
  700. BX_CL_IMPORT_END
  701. #define BX_CL_IMPORT_ALL_11 \
  702. /* Memory Object APIs */ \
  703. BX_CL_IMPORT_11(false, PFNCLCREATEIMAGE2DPROC, clCreateImage2D); \
  704. BX_CL_IMPORT_11(false, PFNCLCREATEIMAGE3DPROC, clCreateImage3D); \
  705. BX_CL_IMPORT_11(false, PFNCLCREATESUBBUFFERPROC, clCreateSubBuffer); \
  706. BX_CL_IMPORT_11(false, PFNCLSETMEMOBJECTDESTRUCTORCALLBACKPROC, clSetMemObjectDestructorCallback); \
  707. /* Event Object APIs */ \
  708. BX_CL_IMPORT_11(false, PFNCLCREATEUSEREVENTPROC, clCreateUserEvent); \
  709. BX_CL_IMPORT_11(false, PFNCLSETUSEREVENTSTATUSPROC, clSetUserEventStatus); \
  710. BX_CL_IMPORT_11(false, PFNCLSETEVENTCALLBACKPROC, clSetEventCallback); \
  711. /* Enqueued Commands APIs */ \
  712. BX_CL_IMPORT_11(false, PFNCLENQUEUEREADBUFFERRECTPROC, clEnqueueReadBufferRect); \
  713. BX_CL_IMPORT_11(false, PFNCLENQUEUEWRITEBUFFERRECTPROC, clEnqueueWriteBufferRect); \
  714. BX_CL_IMPORT_11(false, PFNCLENQUEUECOPYBUFFERRECTPROC, clEnqueueCopyBufferRect); \
  715. \
  716. BX_CL_IMPORT_END
  717. #define BX_CL_IMPORT_ALL_12 \
  718. /* Device APIs */ \
  719. BX_CL_IMPORT_12(false, PFNCLCREATESUBDEVICESPROC, clCreateSubDevices); \
  720. BX_CL_IMPORT_12(false, PFNCLRETAINDEVICEPROC, clRetainDevice); \
  721. BX_CL_IMPORT_12(false, PFNCLRELEASEDEVICEPROC, clReleaseDevice); \
  722. BX_CL_IMPORT_12(false, PFNCLCREATEIMAGEPROC, clCreateImage); \
  723. /* Program Object APIs */ \
  724. BX_CL_IMPORT_12(false, PFNCLCREATEPROGRAMWITHBUILTINKERNELSPROC, clCreateProgramWithBuiltInKernels); \
  725. BX_CL_IMPORT_12(false, PFNCLCOMPILEPROGRAMPROC, clCompileProgram); \
  726. BX_CL_IMPORT_12(false, PFNCLLINKPROGRAMPROC, clLinkProgram); \
  727. BX_CL_IMPORT_12(false, PFNCLUNLOADPLATFORMCOMPILERPROC, clUnloadPlatformCompiler); \
  728. /* Kernel Object APIs */ \
  729. BX_CL_IMPORT_12(false, PFNCLGETKERNELARGINFOPROC, clGetKernelArgInfo); \
  730. /* Enqueued Commands APIs */ \
  731. BX_CL_IMPORT_12(false, PFNCLENQUEUEFILLBUFFERPROC, clEnqueueFillBuffer); \
  732. BX_CL_IMPORT_12(false, PFNCLENQUEUEFILLIMAGEPROC, clEnqueueFillImage); \
  733. BX_CL_IMPORT_12(false, PFNCLENQUEUEMIGRATEMEMOBJECTSPROC, clEnqueueMigrateMemObjects); \
  734. BX_CL_IMPORT_12(false, PFNCLENQUEUEMARKERWITHWAITLISTPROC, clEnqueueMarkerWithWaitList); \
  735. BX_CL_IMPORT_12(false, PFNCLENQUEUEBARRIERWITHWAITLISTPROC, clEnqueueBarrierWithWaitList); \
  736. \
  737. BX_CL_IMPORT_END
  738. #define BX_CL_IMPORT_ALL \
  739. BX_CL_IMPORT_ALL_10 \
  740. BX_CL_IMPORT_ALL_11 \
  741. BX_CL_IMPORT_ALL_12 \
  742. \
  743. BX_CL_IMPORT_END
  744. #define BX_CL_IMPORT_10(_optional, _proto, _func) BX_CL_IMPORT(10, _optional, _proto, _func)
  745. #define BX_CL_IMPORT_11(_optional, _proto, _func) BX_CL_IMPORT(11, _optional, _proto, _func)
  746. #define BX_CL_IMPORT_12(_optional, _proto, _func) BX_CL_IMPORT(12, _optional, _proto, _func)
  747. #define BX_CL_IMPORT_END
  748. #define BX_CL_IMPORT(_version, _optional, _proto, _func) extern "C" _proto _func
  749. BX_CL_IMPORT_ALL
  750. #undef BX_CL_IMPORT
  751. #if defined(BX_CL_IMPLEMENTATION)
  752. extern "C"
  753. {
  754. #define BX_CL_IMPORT(_version, _optional, _proto, _func) _proto _func
  755. BX_CL_IMPORT_ALL
  756. #undef BX_CL_IMPORT
  757. };
  758. #include "os.h"
  759. namespace bx
  760. {
  761. struct OpenCLContext
  762. {
  763. OpenCLContext()
  764. : m_handle(NULL)
  765. , m_refCount(0)
  766. {
  767. }
  768. int32_t load()
  769. {
  770. if (NULL != m_handle)
  771. {
  772. int32_t ref = ++m_refCount;
  773. return ref;
  774. }
  775. const char* filePath =
  776. #if BX_PLATFORM_LINUX
  777. "libOpenCL.so"
  778. #elif BX_PLATFORM_OSX
  779. "/Library/Frameworks/OpenCL.framework/OpenCL"
  780. #elif BX_PLATFORM_WINDOWS
  781. "opencl.dll"
  782. #else
  783. "??? unknown OpenCL platform ???"
  784. #endif // BX_PLATFORM_
  785. ;
  786. m_handle = bx::dlopen(filePath);
  787. if (NULL == m_handle)
  788. {
  789. BX_TRACE("Unable to find OpenCL '%s' dynamic library.", filePath);
  790. return 0;
  791. }
  792. m_refCount = 1;
  793. #define BX_CL_IMPORT(_version, _optional, _proto, _func) _func = (_proto)bx::dlsym(m_handle, #_func)
  794. BX_CL_IMPORT_ALL
  795. #undef BX_CL_IMPORT
  796. return 1;
  797. }
  798. int32_t unload()
  799. {
  800. BX_CHECK(m_refCount > 0 && NULL != m_handle, "OpenCL is not loaded.");
  801. int32_t ref = --m_refCount;
  802. if (0 == ref)
  803. {
  804. dlclose(m_handle);
  805. }
  806. return ref;
  807. }
  808. void* m_handle;
  809. int32_t m_refCount;
  810. };
  811. static OpenCLContext s_ctx;
  812. int32_t clLoad()
  813. {
  814. return s_ctx.load();
  815. }
  816. int32_t clUnload()
  817. {
  818. return s_ctx.unload();
  819. }
  820. } // namespace bx
  821. #undef BX_CL_IMPORT_ALL
  822. #undef BX_CL_IMPORT_ALL_10
  823. #undef BX_CL_IMPORT_ALL_11
  824. #undef BX_CL_IMPORT_ALL_12
  825. #undef BX_CL_IMPORT_END
  826. #endif // defined(BX_CL_IMPLEMENTATION)
  827. #endif // __OPENCL_CL_H
  828. #endif // BX_CL_H_HEADER_GUARD