1 //===----- opencl-c-base.h - OpenCL C language base definitions -----------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef _OPENCL_BASE_H_
10 #define _OPENCL_BASE_H_
11 
12 // Define extension macros
13 
14 #if (defined(__OPENCL_CPP_VERSION__) || __OPENCL_C_VERSION__ >= 200)
15 // For SPIR all extensions are supported.
16 #if defined(__SPIR__)
17 #define cl_khr_subgroup_extended_types 1
18 #define cl_khr_subgroup_non_uniform_vote 1
19 #define cl_khr_subgroup_ballot 1
20 #define cl_khr_subgroup_non_uniform_arithmetic 1
21 #define cl_khr_subgroup_shuffle 1
22 #define cl_khr_subgroup_shuffle_relative 1
23 #define cl_khr_subgroup_clustered_reduce 1
24 #endif // defined(__SPIR__)
25 #endif // (defined(__OPENCL_CPP_VERSION__) || __OPENCL_C_VERSION__ >= 200)
26 
27 // Define feature macros for OpenCL C 2.0
28 #if (defined(__OPENCL_CPP_VERSION__) || __OPENCL_C_VERSION__ == 200)
29 #define __opencl_c_pipes 1
30 #define __opencl_c_generic_address_space 1
31 #define __opencl_c_work_group_collective_functions 1
32 #define __opencl_c_atomic_order_acq_rel 1
33 #define __opencl_c_atomic_order_seq_cst 1
34 #define __opencl_c_atomic_scope_device 1
35 #define __opencl_c_atomic_scope_all_devices 1
36 #define __opencl_c_device_enqueue 1
37 #define __opencl_c_read_write_images 1
38 #define __opencl_c_program_scope_global_variables 1
39 #define __opencl_c_images 1
40 #endif
41 
42 // built-in scalar data types:
43 
44 /**
45  * An unsigned 8-bit integer.
46  */
47 typedef unsigned char uchar;
48 
49 /**
50  * An unsigned 16-bit integer.
51  */
52 typedef unsigned short ushort;
53 
54 /**
55  * An unsigned 32-bit integer.
56  */
57 typedef unsigned int uint;
58 
59 /**
60  * An unsigned 64-bit integer.
61  */
62 typedef unsigned long ulong;
63 
64 /**
65  * The unsigned integer type of the result of the sizeof operator. This
66  * is a 32-bit unsigned integer if CL_DEVICE_ADDRESS_BITS
67  * defined in table 4.3 is 32-bits and is a 64-bit unsigned integer if
68  * CL_DEVICE_ADDRESS_BITS is 64-bits.
69  */
70 typedef __SIZE_TYPE__ size_t;
71 
72 /**
73  * A signed integer type that is the result of subtracting two pointers.
74  * This is a 32-bit signed integer if CL_DEVICE_ADDRESS_BITS
75  * defined in table 4.3 is 32-bits and is a 64-bit signed integer if
76  * CL_DEVICE_ADDRESS_BITS is 64-bits.
77  */
78 typedef __PTRDIFF_TYPE__ ptrdiff_t;
79 
80 /**
81  * A signed integer type with the property that any valid pointer to
82  * void can be converted to this type, then converted back to pointer
83  * to void, and the result will compare equal to the original pointer.
84  */
85 typedef __INTPTR_TYPE__ intptr_t;
86 
87 /**
88  * An unsigned integer type with the property that any valid pointer to
89  * void can be converted to this type, then converted back to pointer
90  * to void, and the result will compare equal to the original pointer.
91  */
92 typedef __UINTPTR_TYPE__ uintptr_t;
93 
94 // built-in vector data types:
95 typedef char char2 __attribute__((ext_vector_type(2)));
96 typedef char char3 __attribute__((ext_vector_type(3)));
97 typedef char char4 __attribute__((ext_vector_type(4)));
98 typedef char char8 __attribute__((ext_vector_type(8)));
99 typedef char char16 __attribute__((ext_vector_type(16)));
100 typedef uchar uchar2 __attribute__((ext_vector_type(2)));
101 typedef uchar uchar3 __attribute__((ext_vector_type(3)));
102 typedef uchar uchar4 __attribute__((ext_vector_type(4)));
103 typedef uchar uchar8 __attribute__((ext_vector_type(8)));
104 typedef uchar uchar16 __attribute__((ext_vector_type(16)));
105 typedef short short2 __attribute__((ext_vector_type(2)));
106 typedef short short3 __attribute__((ext_vector_type(3)));
107 typedef short short4 __attribute__((ext_vector_type(4)));
108 typedef short short8 __attribute__((ext_vector_type(8)));
109 typedef short short16 __attribute__((ext_vector_type(16)));
110 typedef ushort ushort2 __attribute__((ext_vector_type(2)));
111 typedef ushort ushort3 __attribute__((ext_vector_type(3)));
112 typedef ushort ushort4 __attribute__((ext_vector_type(4)));
113 typedef ushort ushort8 __attribute__((ext_vector_type(8)));
114 typedef ushort ushort16 __attribute__((ext_vector_type(16)));
115 typedef int int2 __attribute__((ext_vector_type(2)));
116 typedef int int3 __attribute__((ext_vector_type(3)));
117 typedef int int4 __attribute__((ext_vector_type(4)));
118 typedef int int8 __attribute__((ext_vector_type(8)));
119 typedef int int16 __attribute__((ext_vector_type(16)));
120 typedef uint uint2 __attribute__((ext_vector_type(2)));
121 typedef uint uint3 __attribute__((ext_vector_type(3)));
122 typedef uint uint4 __attribute__((ext_vector_type(4)));
123 typedef uint uint8 __attribute__((ext_vector_type(8)));
124 typedef uint uint16 __attribute__((ext_vector_type(16)));
125 typedef long long2 __attribute__((ext_vector_type(2)));
126 typedef long long3 __attribute__((ext_vector_type(3)));
127 typedef long long4 __attribute__((ext_vector_type(4)));
128 typedef long long8 __attribute__((ext_vector_type(8)));
129 typedef long long16 __attribute__((ext_vector_type(16)));
130 typedef ulong ulong2 __attribute__((ext_vector_type(2)));
131 typedef ulong ulong3 __attribute__((ext_vector_type(3)));
132 typedef ulong ulong4 __attribute__((ext_vector_type(4)));
133 typedef ulong ulong8 __attribute__((ext_vector_type(8)));
134 typedef ulong ulong16 __attribute__((ext_vector_type(16)));
135 typedef float float2 __attribute__((ext_vector_type(2)));
136 typedef float float3 __attribute__((ext_vector_type(3)));
137 typedef float float4 __attribute__((ext_vector_type(4)));
138 typedef float float8 __attribute__((ext_vector_type(8)));
139 typedef float float16 __attribute__((ext_vector_type(16)));
140 #ifdef cl_khr_fp16
141 #pragma OPENCL EXTENSION cl_khr_fp16 : enable
142 typedef half half2 __attribute__((ext_vector_type(2)));
143 typedef half half3 __attribute__((ext_vector_type(3)));
144 typedef half half4 __attribute__((ext_vector_type(4)));
145 typedef half half8 __attribute__((ext_vector_type(8)));
146 typedef half half16 __attribute__((ext_vector_type(16)));
147 #endif
148 #ifdef cl_khr_fp64
149 #if __OPENCL_C_VERSION__ < CL_VERSION_1_2
150 #pragma OPENCL EXTENSION cl_khr_fp64 : enable
151 #endif
152 typedef double double2 __attribute__((ext_vector_type(2)));
153 typedef double double3 __attribute__((ext_vector_type(3)));
154 typedef double double4 __attribute__((ext_vector_type(4)));
155 typedef double double8 __attribute__((ext_vector_type(8)));
156 typedef double double16 __attribute__((ext_vector_type(16)));
157 #endif
158 
159 #if defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= CL_VERSION_2_0)
160 #define NULL ((void*)0)
161 #endif
162 
163 /**
164  * Value of maximum non-infinite single-precision floating-point
165  * number.
166  */
167 #define MAXFLOAT 0x1.fffffep127f
168 
169 /**
170  * A positive float constant expression. HUGE_VALF evaluates
171  * to +infinity. Used as an error value returned by the built-in
172  * math functions.
173  */
174 #define HUGE_VALF (__builtin_huge_valf())
175 
176 /**
177  * A positive double constant expression. HUGE_VAL evaluates
178  * to +infinity. Used as an error value returned by the built-in
179  * math functions.
180  */
181 #define HUGE_VAL (__builtin_huge_val())
182 
183 /**
184  * A constant expression of type float representing positive or
185  * unsigned infinity.
186  */
187 #define INFINITY (__builtin_inff())
188 
189 /**
190  * A constant expression of type float representing a quiet NaN.
191  */
192 #define NAN as_float(INT_MAX)
193 
194 #define FP_ILOGB0    INT_MIN
195 #define FP_ILOGBNAN  INT_MAX
196 
197 #define FLT_DIG 6
198 #define FLT_MANT_DIG 24
199 #define FLT_MAX_10_EXP +38
200 #define FLT_MAX_EXP +128
201 #define FLT_MIN_10_EXP -37
202 #define FLT_MIN_EXP -125
203 #define FLT_RADIX 2
204 #define FLT_MAX 0x1.fffffep127f
205 #define FLT_MIN 0x1.0p-126f
206 #define FLT_EPSILON 0x1.0p-23f
207 
208 #define M_E_F         2.71828182845904523536028747135266250f
209 #define M_LOG2E_F     1.44269504088896340735992468100189214f
210 #define M_LOG10E_F    0.434294481903251827651128918916605082f
211 #define M_LN2_F       0.693147180559945309417232121458176568f
212 #define M_LN10_F      2.30258509299404568401799145468436421f
213 #define M_PI_F        3.14159265358979323846264338327950288f
214 #define M_PI_2_F      1.57079632679489661923132169163975144f
215 #define M_PI_4_F      0.785398163397448309615660845819875721f
216 #define M_1_PI_F      0.318309886183790671537767526745028724f
217 #define M_2_PI_F      0.636619772367581343075535053490057448f
218 #define M_2_SQRTPI_F  1.12837916709551257389615890312154517f
219 #define M_SQRT2_F     1.41421356237309504880168872420969808f
220 #define M_SQRT1_2_F   0.707106781186547524400844362104849039f
221 
222 #define DBL_DIG 15
223 #define DBL_MANT_DIG 53
224 #define DBL_MAX_10_EXP +308
225 #define DBL_MAX_EXP +1024
226 #define DBL_MIN_10_EXP -307
227 #define DBL_MIN_EXP -1021
228 #define DBL_RADIX 2
229 #define DBL_MAX 0x1.fffffffffffffp1023
230 #define DBL_MIN 0x1.0p-1022
231 #define DBL_EPSILON 0x1.0p-52
232 
233 #define M_E           0x1.5bf0a8b145769p+1
234 #define M_LOG2E       0x1.71547652b82fep+0
235 #define M_LOG10E      0x1.bcb7b1526e50ep-2
236 #define M_LN2         0x1.62e42fefa39efp-1
237 #define M_LN10        0x1.26bb1bbb55516p+1
238 #define M_PI          0x1.921fb54442d18p+1
239 #define M_PI_2        0x1.921fb54442d18p+0
240 #define M_PI_4        0x1.921fb54442d18p-1
241 #define M_1_PI        0x1.45f306dc9c883p-2
242 #define M_2_PI        0x1.45f306dc9c883p-1
243 #define M_2_SQRTPI    0x1.20dd750429b6dp+0
244 #define M_SQRT2       0x1.6a09e667f3bcdp+0
245 #define M_SQRT1_2     0x1.6a09e667f3bcdp-1
246 
247 #ifdef cl_khr_fp16
248 
249 #define HALF_DIG 3
250 #define HALF_MANT_DIG 11
251 #define HALF_MAX_10_EXP +4
252 #define HALF_MAX_EXP +16
253 #define HALF_MIN_10_EXP -4
254 #define HALF_MIN_EXP -13
255 #define HALF_RADIX 2
256 #define HALF_MAX ((0x1.ffcp15h))
257 #define HALF_MIN ((0x1.0p-14h))
258 #define HALF_EPSILON ((0x1.0p-10h))
259 
260 #define M_E_H         2.71828182845904523536028747135266250h
261 #define M_LOG2E_H     1.44269504088896340735992468100189214h
262 #define M_LOG10E_H    0.434294481903251827651128918916605082h
263 #define M_LN2_H       0.693147180559945309417232121458176568h
264 #define M_LN10_H      2.30258509299404568401799145468436421h
265 #define M_PI_H        3.14159265358979323846264338327950288h
266 #define M_PI_2_H      1.57079632679489661923132169163975144h
267 #define M_PI_4_H      0.785398163397448309615660845819875721h
268 #define M_1_PI_H      0.318309886183790671537767526745028724h
269 #define M_2_PI_H      0.636619772367581343075535053490057448h
270 #define M_2_SQRTPI_H  1.12837916709551257389615890312154517h
271 #define M_SQRT2_H     1.41421356237309504880168872420969808h
272 #define M_SQRT1_2_H   0.707106781186547524400844362104849039h
273 
274 #endif //cl_khr_fp16
275 
276 #define CHAR_BIT  8
277 #define SCHAR_MAX 127
278 #define SCHAR_MIN (-128)
279 #define UCHAR_MAX 255
280 #define CHAR_MAX  SCHAR_MAX
281 #define CHAR_MIN  SCHAR_MIN
282 #define USHRT_MAX 65535
283 #define SHRT_MAX  32767
284 #define SHRT_MIN  (-32768)
285 #define UINT_MAX  0xffffffff
286 #define INT_MAX   2147483647
287 #define INT_MIN   (-2147483647-1)
288 #define ULONG_MAX 0xffffffffffffffffUL
289 #define LONG_MAX  0x7fffffffffffffffL
290 #define LONG_MIN  (-0x7fffffffffffffffL-1)
291 
292 // OpenCL v1.1 s6.11.8, v1.2 s6.12.8, v2.0 s6.13.8 - Synchronization Functions
293 
294 // Flag type and values for barrier, mem_fence, read_mem_fence, write_mem_fence
295 typedef uint cl_mem_fence_flags;
296 
297 /**
298  * Queue a memory fence to ensure correct
299  * ordering of memory operations to local memory
300  */
301 #define CLK_LOCAL_MEM_FENCE    0x01
302 
303 /**
304  * Queue a memory fence to ensure correct
305  * ordering of memory operations to global memory
306  */
307 #define CLK_GLOBAL_MEM_FENCE   0x02
308 
309 #if defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= CL_VERSION_2_0)
310 
311 typedef enum memory_scope {
312   memory_scope_work_item = __OPENCL_MEMORY_SCOPE_WORK_ITEM,
313   memory_scope_work_group = __OPENCL_MEMORY_SCOPE_WORK_GROUP,
314   memory_scope_device = __OPENCL_MEMORY_SCOPE_DEVICE,
315   memory_scope_all_svm_devices = __OPENCL_MEMORY_SCOPE_ALL_SVM_DEVICES,
316 #if defined(cl_intel_subgroups) || defined(cl_khr_subgroups)
317   memory_scope_sub_group = __OPENCL_MEMORY_SCOPE_SUB_GROUP
318 #endif
319 } memory_scope;
320 
321 /**
322  * Queue a memory fence to ensure correct ordering of memory
323  * operations between work-items of a work-group to
324  * image memory.
325  */
326 #define CLK_IMAGE_MEM_FENCE  0x04
327 
328 #ifndef ATOMIC_VAR_INIT
329 #define ATOMIC_VAR_INIT(x) (x)
330 #endif //ATOMIC_VAR_INIT
331 #define ATOMIC_FLAG_INIT 0
332 
333 // enum values aligned with what clang uses in EmitAtomicExpr()
334 typedef enum memory_order
335 {
336   memory_order_relaxed = __ATOMIC_RELAXED,
337   memory_order_acquire = __ATOMIC_ACQUIRE,
338   memory_order_release = __ATOMIC_RELEASE,
339   memory_order_acq_rel = __ATOMIC_ACQ_REL,
340   memory_order_seq_cst = __ATOMIC_SEQ_CST
341 } memory_order;
342 
343 #endif // defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= CL_VERSION_2_0)
344 
345 // OpenCL v1.1 s6.11.3, v1.2 s6.12.14, v2.0 s6.13.14 - Image Read and Write Functions
346 
347 // These values need to match the runtime equivalent
348 //
349 // Addressing Mode.
350 //
351 #define CLK_ADDRESS_NONE                0
352 #define CLK_ADDRESS_CLAMP_TO_EDGE       2
353 #define CLK_ADDRESS_CLAMP               4
354 #define CLK_ADDRESS_REPEAT              6
355 #define CLK_ADDRESS_MIRRORED_REPEAT     8
356 
357 //
358 // Coordination Normalization
359 //
360 #define CLK_NORMALIZED_COORDS_FALSE     0
361 #define CLK_NORMALIZED_COORDS_TRUE      1
362 
363 //
364 // Filtering Mode.
365 //
366 #define CLK_FILTER_NEAREST              0x10
367 #define CLK_FILTER_LINEAR               0x20
368 
369 #ifdef cl_khr_gl_msaa_sharing
370 #pragma OPENCL EXTENSION cl_khr_gl_msaa_sharing : enable
371 #endif //cl_khr_gl_msaa_sharing
372 
373 //
374 // Channel Datatype.
375 //
376 #define CLK_SNORM_INT8        0x10D0
377 #define CLK_SNORM_INT16       0x10D1
378 #define CLK_UNORM_INT8        0x10D2
379 #define CLK_UNORM_INT16       0x10D3
380 #define CLK_UNORM_SHORT_565   0x10D4
381 #define CLK_UNORM_SHORT_555   0x10D5
382 #define CLK_UNORM_INT_101010  0x10D6
383 #define CLK_SIGNED_INT8       0x10D7
384 #define CLK_SIGNED_INT16      0x10D8
385 #define CLK_SIGNED_INT32      0x10D9
386 #define CLK_UNSIGNED_INT8     0x10DA
387 #define CLK_UNSIGNED_INT16    0x10DB
388 #define CLK_UNSIGNED_INT32    0x10DC
389 #define CLK_HALF_FLOAT        0x10DD
390 #define CLK_FLOAT             0x10DE
391 #define CLK_UNORM_INT24       0x10DF
392 
393 // Channel order, numbering must be aligned with cl_channel_order in cl.h
394 //
395 #define CLK_R         0x10B0
396 #define CLK_A         0x10B1
397 #define CLK_RG        0x10B2
398 #define CLK_RA        0x10B3
399 #define CLK_RGB       0x10B4
400 #define CLK_RGBA      0x10B5
401 #define CLK_BGRA      0x10B6
402 #define CLK_ARGB      0x10B7
403 #define CLK_INTENSITY 0x10B8
404 #define CLK_LUMINANCE 0x10B9
405 #define CLK_Rx                0x10BA
406 #define CLK_RGx               0x10BB
407 #define CLK_RGBx              0x10BC
408 #define CLK_DEPTH             0x10BD
409 #define CLK_DEPTH_STENCIL     0x10BE
410 #if __OPENCL_C_VERSION__ >= CL_VERSION_2_0
411 #define CLK_sRGB              0x10BF
412 #define CLK_sRGBx             0x10C0
413 #define CLK_sRGBA             0x10C1
414 #define CLK_sBGRA             0x10C2
415 #define CLK_ABGR              0x10C3
416 #endif //__OPENCL_C_VERSION__ >= CL_VERSION_2_0
417 
418 // OpenCL v2.0 s6.13.16 - Pipe Functions
419 #if defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= CL_VERSION_2_0)
420 #define CLK_NULL_RESERVE_ID (__builtin_astype(((void*)(__SIZE_MAX__)), reserve_id_t))
421 
422 // OpenCL v2.0 s6.13.17 - Enqueue Kernels
423 #define CL_COMPLETE                                 0x0
424 #define CL_RUNNING                                  0x1
425 #define CL_SUBMITTED                                0x2
426 #define CL_QUEUED                                   0x3
427 
428 #define CLK_SUCCESS                                 0
429 #define CLK_ENQUEUE_FAILURE                         -101
430 #define CLK_INVALID_QUEUE                           -102
431 #define CLK_INVALID_NDRANGE                         -160
432 #define CLK_INVALID_EVENT_WAIT_LIST                 -57
433 #define CLK_DEVICE_QUEUE_FULL                       -161
434 #define CLK_INVALID_ARG_SIZE                        -51
435 #define CLK_EVENT_ALLOCATION_FAILURE                -100
436 #define CLK_OUT_OF_RESOURCES                        -5
437 
438 #define CLK_NULL_QUEUE                              0
439 #define CLK_NULL_EVENT (__builtin_astype(((__SIZE_MAX__)), clk_event_t))
440 
441 // execution model related definitions
442 #define CLK_ENQUEUE_FLAGS_NO_WAIT                   0x0
443 #define CLK_ENQUEUE_FLAGS_WAIT_KERNEL               0x1
444 #define CLK_ENQUEUE_FLAGS_WAIT_WORK_GROUP           0x2
445 
446 typedef int kernel_enqueue_flags_t;
447 typedef int clk_profiling_info;
448 
449 // Profiling info name (see capture_event_profiling_info)
450 #define CLK_PROFILING_COMMAND_EXEC_TIME 0x1
451 
452 #define MAX_WORK_DIM 3
453 
454 typedef struct {
455   unsigned int workDimension;
456   size_t globalWorkOffset[MAX_WORK_DIM];
457   size_t globalWorkSize[MAX_WORK_DIM];
458   size_t localWorkSize[MAX_WORK_DIM];
459 } ndrange_t;
460 
461 #endif // defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= CL_VERSION_2_0)
462 
463 /**
464  * OpenCL v1.1/1.2/2.0 s6.2.4.2 - as_type operators
465  * Reinterprets a data type as another data type of the same size
466  */
467 #define as_char(x) __builtin_astype((x), char)
468 #define as_char2(x) __builtin_astype((x), char2)
469 #define as_char3(x) __builtin_astype((x), char3)
470 #define as_char4(x) __builtin_astype((x), char4)
471 #define as_char8(x) __builtin_astype((x), char8)
472 #define as_char16(x) __builtin_astype((x), char16)
473 
474 #define as_uchar(x) __builtin_astype((x), uchar)
475 #define as_uchar2(x) __builtin_astype((x), uchar2)
476 #define as_uchar3(x) __builtin_astype((x), uchar3)
477 #define as_uchar4(x) __builtin_astype((x), uchar4)
478 #define as_uchar8(x) __builtin_astype((x), uchar8)
479 #define as_uchar16(x) __builtin_astype((x), uchar16)
480 
481 #define as_short(x) __builtin_astype((x), short)
482 #define as_short2(x) __builtin_astype((x), short2)
483 #define as_short3(x) __builtin_astype((x), short3)
484 #define as_short4(x) __builtin_astype((x), short4)
485 #define as_short8(x) __builtin_astype((x), short8)
486 #define as_short16(x) __builtin_astype((x), short16)
487 
488 #define as_ushort(x) __builtin_astype((x), ushort)
489 #define as_ushort2(x) __builtin_astype((x), ushort2)
490 #define as_ushort3(x) __builtin_astype((x), ushort3)
491 #define as_ushort4(x) __builtin_astype((x), ushort4)
492 #define as_ushort8(x) __builtin_astype((x), ushort8)
493 #define as_ushort16(x) __builtin_astype((x), ushort16)
494 
495 #define as_int(x) __builtin_astype((x), int)
496 #define as_int2(x) __builtin_astype((x), int2)
497 #define as_int3(x) __builtin_astype((x), int3)
498 #define as_int4(x) __builtin_astype((x), int4)
499 #define as_int8(x) __builtin_astype((x), int8)
500 #define as_int16(x) __builtin_astype((x), int16)
501 
502 #define as_uint(x) __builtin_astype((x), uint)
503 #define as_uint2(x) __builtin_astype((x), uint2)
504 #define as_uint3(x) __builtin_astype((x), uint3)
505 #define as_uint4(x) __builtin_astype((x), uint4)
506 #define as_uint8(x) __builtin_astype((x), uint8)
507 #define as_uint16(x) __builtin_astype((x), uint16)
508 
509 #define as_long(x) __builtin_astype((x), long)
510 #define as_long2(x) __builtin_astype((x), long2)
511 #define as_long3(x) __builtin_astype((x), long3)
512 #define as_long4(x) __builtin_astype((x), long4)
513 #define as_long8(x) __builtin_astype((x), long8)
514 #define as_long16(x) __builtin_astype((x), long16)
515 
516 #define as_ulong(x) __builtin_astype((x), ulong)
517 #define as_ulong2(x) __builtin_astype((x), ulong2)
518 #define as_ulong3(x) __builtin_astype((x), ulong3)
519 #define as_ulong4(x) __builtin_astype((x), ulong4)
520 #define as_ulong8(x) __builtin_astype((x), ulong8)
521 #define as_ulong16(x) __builtin_astype((x), ulong16)
522 
523 #define as_float(x) __builtin_astype((x), float)
524 #define as_float2(x) __builtin_astype((x), float2)
525 #define as_float3(x) __builtin_astype((x), float3)
526 #define as_float4(x) __builtin_astype((x), float4)
527 #define as_float8(x) __builtin_astype((x), float8)
528 #define as_float16(x) __builtin_astype((x), float16)
529 
530 #ifdef cl_khr_fp64
531 #define as_double(x) __builtin_astype((x), double)
532 #define as_double2(x) __builtin_astype((x), double2)
533 #define as_double3(x) __builtin_astype((x), double3)
534 #define as_double4(x) __builtin_astype((x), double4)
535 #define as_double8(x) __builtin_astype((x), double8)
536 #define as_double16(x) __builtin_astype((x), double16)
537 #endif // cl_khr_fp64
538 
539 #ifdef cl_khr_fp16
540 #define as_half(x) __builtin_astype((x), half)
541 #define as_half2(x) __builtin_astype((x), half2)
542 #define as_half3(x) __builtin_astype((x), half3)
543 #define as_half4(x) __builtin_astype((x), half4)
544 #define as_half8(x) __builtin_astype((x), half8)
545 #define as_half16(x) __builtin_astype((x), half16)
546 #endif // cl_khr_fp16
547 
548 #define as_size_t(x) __builtin_astype((x), size_t)
549 #define as_ptrdiff_t(x) __builtin_astype((x), ptrdiff_t)
550 #define as_intptr_t(x) __builtin_astype((x), intptr_t)
551 #define as_uintptr_t(x) __builtin_astype((x), uintptr_t)
552 
553 // OpenCL v1.1 s6.9, v1.2/2.0 s6.10 - Function qualifiers
554 
555 #define __kernel_exec(X, typen) __kernel \
556 	__attribute__((work_group_size_hint(X, 1, 1))) \
557 	__attribute__((vec_type_hint(typen)))
558 
559 #define kernel_exec(X, typen) __kernel \
560 	__attribute__((work_group_size_hint(X, 1, 1))) \
561 	__attribute__((vec_type_hint(typen)))
562 
563 #if defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= CL_VERSION_1_2)
564 // OpenCL v1.2 s6.12.13, v2.0 s6.13.13 - printf
565 
566 int printf(__constant const char* st, ...) __attribute__((format(printf, 1, 2)));
567 #endif
568 
569 #ifdef cl_intel_device_side_avc_motion_estimation
570 
571 #define CLK_AVC_ME_MAJOR_16x16_INTEL 0x0
572 #define CLK_AVC_ME_MAJOR_16x8_INTEL 0x1
573 #define CLK_AVC_ME_MAJOR_8x16_INTEL 0x2
574 #define CLK_AVC_ME_MAJOR_8x8_INTEL 0x3
575 
576 #define CLK_AVC_ME_MINOR_8x8_INTEL 0x0
577 #define CLK_AVC_ME_MINOR_8x4_INTEL 0x1
578 #define CLK_AVC_ME_MINOR_4x8_INTEL 0x2
579 #define CLK_AVC_ME_MINOR_4x4_INTEL 0x3
580 
581 #define CLK_AVC_ME_MAJOR_FORWARD_INTEL 0x0
582 #define CLK_AVC_ME_MAJOR_BACKWARD_INTEL 0x1
583 #define CLK_AVC_ME_MAJOR_BIDIRECTIONAL_INTEL 0x2
584 
585 #define CLK_AVC_ME_PARTITION_MASK_ALL_INTEL 0x0
586 #define CLK_AVC_ME_PARTITION_MASK_16x16_INTEL 0x7E
587 #define CLK_AVC_ME_PARTITION_MASK_16x8_INTEL 0x7D
588 #define CLK_AVC_ME_PARTITION_MASK_8x16_INTEL 0x7B
589 #define CLK_AVC_ME_PARTITION_MASK_8x8_INTEL 0x77
590 #define CLK_AVC_ME_PARTITION_MASK_8x4_INTEL 0x6F
591 #define CLK_AVC_ME_PARTITION_MASK_4x8_INTEL 0x5F
592 #define CLK_AVC_ME_PARTITION_MASK_4x4_INTEL 0x3F
593 
594 #define CLK_AVC_ME_SLICE_TYPE_PRED_INTEL 0x0
595 #define CLK_AVC_ME_SLICE_TYPE_BPRED_INTEL 0x1
596 #define CLK_AVC_ME_SLICE_TYPE_INTRA_INTEL 0x2
597 
598 #define CLK_AVC_ME_SEARCH_WINDOW_EXHAUSTIVE_INTEL 0x0
599 #define CLK_AVC_ME_SEARCH_WINDOW_SMALL_INTEL 0x1
600 #define CLK_AVC_ME_SEARCH_WINDOW_TINY_INTEL 0x2
601 #define CLK_AVC_ME_SEARCH_WINDOW_EXTRA_TINY_INTEL 0x3
602 #define CLK_AVC_ME_SEARCH_WINDOW_DIAMOND_INTEL 0x4
603 #define CLK_AVC_ME_SEARCH_WINDOW_LARGE_DIAMOND_INTEL 0x5
604 #define CLK_AVC_ME_SEARCH_WINDOW_RESERVED0_INTEL 0x6
605 #define CLK_AVC_ME_SEARCH_WINDOW_RESERVED1_INTEL 0x7
606 #define CLK_AVC_ME_SEARCH_WINDOW_CUSTOM_INTEL 0x8
607 
608 #define CLK_AVC_ME_SAD_ADJUST_MODE_NONE_INTEL 0x0
609 #define CLK_AVC_ME_SAD_ADJUST_MODE_HAAR_INTEL 0x2
610 
611 #define CLK_AVC_ME_SUBPIXEL_MODE_INTEGER_INTEL 0x0
612 #define CLK_AVC_ME_SUBPIXEL_MODE_HPEL_INTEL 0x1
613 #define CLK_AVC_ME_SUBPIXEL_MODE_QPEL_INTEL 0x3
614 
615 #define CLK_AVC_ME_COST_PRECISION_QPEL_INTEL 0x0
616 #define CLK_AVC_ME_COST_PRECISION_HPEL_INTEL 0x1
617 #define CLK_AVC_ME_COST_PRECISION_PEL_INTEL 0x2
618 #define CLK_AVC_ME_COST_PRECISION_DPEL_INTEL 0x3
619 
620 #define CLK_AVC_ME_BIDIR_WEIGHT_QUARTER_INTEL 0x10
621 #define CLK_AVC_ME_BIDIR_WEIGHT_THIRD_INTEL 0x15
622 #define CLK_AVC_ME_BIDIR_WEIGHT_HALF_INTEL 0x20
623 #define CLK_AVC_ME_BIDIR_WEIGHT_TWO_THIRD_INTEL 0x2B
624 #define CLK_AVC_ME_BIDIR_WEIGHT_THREE_QUARTER_INTEL 0x30
625 
626 #define CLK_AVC_ME_BORDER_REACHED_LEFT_INTEL 0x0
627 #define CLK_AVC_ME_BORDER_REACHED_RIGHT_INTEL 0x2
628 #define CLK_AVC_ME_BORDER_REACHED_TOP_INTEL 0x4
629 #define CLK_AVC_ME_BORDER_REACHED_BOTTOM_INTEL 0x8
630 
631 #define CLK_AVC_ME_INTRA_16x16_INTEL 0x0
632 #define CLK_AVC_ME_INTRA_8x8_INTEL 0x1
633 #define CLK_AVC_ME_INTRA_4x4_INTEL 0x2
634 
635 #define CLK_AVC_ME_SKIP_BLOCK_PARTITION_16x16_INTEL 0x0
636 #define CLK_AVC_ME_SKIP_BLOCK_PARTITION_8x8_INTEL 0x4000
637 
638 #define CLK_AVC_ME_SKIP_BLOCK_16x16_FORWARD_ENABLE_INTEL (0x1 << 24)
639 #define CLK_AVC_ME_SKIP_BLOCK_16x16_BACKWARD_ENABLE_INTEL (0x2 << 24)
640 #define CLK_AVC_ME_SKIP_BLOCK_16x16_DUAL_ENABLE_INTEL (0x3 << 24)
641 #define CLK_AVC_ME_SKIP_BLOCK_8x8_FORWARD_ENABLE_INTEL (0x55 << 24)
642 #define CLK_AVC_ME_SKIP_BLOCK_8x8_BACKWARD_ENABLE_INTEL (0xAA << 24)
643 #define CLK_AVC_ME_SKIP_BLOCK_8x8_DUAL_ENABLE_INTEL (0xFF << 24)
644 #define CLK_AVC_ME_SKIP_BLOCK_8x8_0_FORWARD_ENABLE_INTEL (0x1 << 24)
645 #define CLK_AVC_ME_SKIP_BLOCK_8x8_0_BACKWARD_ENABLE_INTEL (0x2 << 24)
646 #define CLK_AVC_ME_SKIP_BLOCK_8x8_1_FORWARD_ENABLE_INTEL (0x1 << 26)
647 #define CLK_AVC_ME_SKIP_BLOCK_8x8_1_BACKWARD_ENABLE_INTEL (0x2 << 26)
648 #define CLK_AVC_ME_SKIP_BLOCK_8x8_2_FORWARD_ENABLE_INTEL (0x1 << 28)
649 #define CLK_AVC_ME_SKIP_BLOCK_8x8_2_BACKWARD_ENABLE_INTEL (0x2 << 28)
650 #define CLK_AVC_ME_SKIP_BLOCK_8x8_3_FORWARD_ENABLE_INTEL (0x1 << 30)
651 #define CLK_AVC_ME_SKIP_BLOCK_8x8_3_BACKWARD_ENABLE_INTEL (0x2 << 30)
652 
653 #define CLK_AVC_ME_BLOCK_BASED_SKIP_4x4_INTEL 0x00
654 #define CLK_AVC_ME_BLOCK_BASED_SKIP_8x8_INTEL 0x80
655 
656 #define CLK_AVC_ME_INTRA_LUMA_PARTITION_MASK_ALL_INTEL 0x0
657 #define CLK_AVC_ME_INTRA_LUMA_PARTITION_MASK_16x16_INTEL 0x6
658 #define CLK_AVC_ME_INTRA_LUMA_PARTITION_MASK_8x8_INTEL 0x5
659 #define CLK_AVC_ME_INTRA_LUMA_PARTITION_MASK_4x4_INTEL 0x3
660 
661 #define CLK_AVC_ME_INTRA_NEIGHBOR_LEFT_MASK_ENABLE_INTEL 0x60
662 #define CLK_AVC_ME_INTRA_NEIGHBOR_UPPER_MASK_ENABLE_INTEL 0x10
663 #define CLK_AVC_ME_INTRA_NEIGHBOR_UPPER_RIGHT_MASK_ENABLE_INTEL 0x8
664 #define CLK_AVC_ME_INTRA_NEIGHBOR_UPPER_LEFT_MASK_ENABLE_INTEL 0x4
665 
666 #define CLK_AVC_ME_LUMA_PREDICTOR_MODE_VERTICAL_INTEL 0x0
667 #define CLK_AVC_ME_LUMA_PREDICTOR_MODE_HORIZONTAL_INTEL 0x1
668 #define CLK_AVC_ME_LUMA_PREDICTOR_MODE_DC_INTEL 0x2
669 #define CLK_AVC_ME_LUMA_PREDICTOR_MODE_DIAGONAL_DOWN_LEFT_INTEL 0x3
670 #define CLK_AVC_ME_LUMA_PREDICTOR_MODE_DIAGONAL_DOWN_RIGHT_INTEL 0x4
671 #define CLK_AVC_ME_LUMA_PREDICTOR_MODE_PLANE_INTEL 0x4
672 #define CLK_AVC_ME_LUMA_PREDICTOR_MODE_VERTICAL_RIGHT_INTEL 0x5
673 #define CLK_AVC_ME_LUMA_PREDICTOR_MODE_HORIZONTAL_DOWN_INTEL 0x6
674 #define CLK_AVC_ME_LUMA_PREDICTOR_MODE_VERTICAL_LEFT_INTEL 0x7
675 #define CLK_AVC_ME_LUMA_PREDICTOR_MODE_HORIZONTAL_UP_INTEL 0x8
676 #define CLK_AVC_ME_CHROMA_PREDICTOR_MODE_DC_INTEL 0x0
677 #define CLK_AVC_ME_CHROMA_PREDICTOR_MODE_HORIZONTAL_INTEL 0x1
678 #define CLK_AVC_ME_CHROMA_PREDICTOR_MODE_VERTICAL_INTEL 0x2
679 #define CLK_AVC_ME_CHROMA_PREDICTOR_MODE_PLANE_INTEL 0x3
680 
681 #define CLK_AVC_ME_FRAME_FORWARD_INTEL 0x1
682 #define CLK_AVC_ME_FRAME_BACKWARD_INTEL 0x2
683 #define CLK_AVC_ME_FRAME_DUAL_INTEL 0x3
684 
685 #define CLK_AVC_ME_INTERLACED_SCAN_TOP_FIELD_INTEL 0x0
686 #define CLK_AVC_ME_INTERLACED_SCAN_BOTTOM_FIELD_INTEL 0x1
687 
688 #define CLK_AVC_ME_INITIALIZE_INTEL 0x0
689 
690 #define CLK_AVC_IME_PAYLOAD_INITIALIZE_INTEL 0x0
691 #define CLK_AVC_REF_PAYLOAD_INITIALIZE_INTEL 0x0
692 #define CLK_AVC_SIC_PAYLOAD_INITIALIZE_INTEL 0x0
693 
694 #define CLK_AVC_IME_RESULT_INITIALIZE_INTEL 0x0
695 #define CLK_AVC_REF_RESULT_INITIALIZE_INTEL 0x0
696 #define CLK_AVC_SIC_RESULT_INITIALIZE_INTEL 0x0
697 
698 #define CLK_AVC_IME_RESULT_SINGLE_REFERENCE_STREAMOUT_INITIALIZE_INTEL 0x0
699 #define CLK_AVC_IME_RESULT_SINGLE_REFERENCE_STREAMIN_INITIALIZE_INTEL 0x0
700 #define CLK_AVC_IME_RESULT_DUAL_REFERENCE_STREAMOUT_INITIALIZE_INTEL 0x0
701 #define CLK_AVC_IME_RESULT_DUAL_REFERENCE_STREAMIN_INITIALIZE_INTEL 0x0
702 
703 #endif // cl_intel_device_side_avc_motion_estimation
704 
705 // Disable any extensions we may have enabled previously.
706 #pragma OPENCL EXTENSION all : disable
707 
708 #endif //_OPENCL_BASE_H_
709