759 lines · c
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-exception6//7//===----------------------------------------------------------------------===//8 9#ifndef _OPENCL_BASE_H_10#define _OPENCL_BASE_H_11 12#if !defined(__opencl_c_generic_address_space)13// Internal feature macro to provide named (global, local, private) address14// space overloads for builtin functions that take a pointer argument.15#define __opencl_c_named_address_space_builtins 116#endif // !defined(__opencl_c_generic_address_space)17 18#if defined(cl_intel_subgroups) || defined(cl_khr_subgroups) || defined(__opencl_c_subgroups)19// Internal feature macro to provide subgroup builtins.20#define __opencl_subgroup_builtins 121#endif22 23// built-in scalar data types:24 25/**26 * An unsigned 8-bit integer.27 */28typedef unsigned char uchar;29 30/**31 * An unsigned 16-bit integer.32 */33typedef unsigned short ushort;34 35/**36 * An unsigned 32-bit integer.37 */38typedef unsigned int uint;39 40/**41 * An unsigned 64-bit integer.42 */43typedef unsigned long ulong;44 45/**46 * The unsigned integer type of the result of the sizeof operator. This47 * is a 32-bit unsigned integer if CL_DEVICE_ADDRESS_BITS48 * defined in table 4.3 is 32-bits and is a 64-bit unsigned integer if49 * CL_DEVICE_ADDRESS_BITS is 64-bits.50 */51typedef __SIZE_TYPE__ size_t;52 53/**54 * A signed integer type that is the result of subtracting two pointers.55 * This is a 32-bit signed integer if CL_DEVICE_ADDRESS_BITS56 * defined in table 4.3 is 32-bits and is a 64-bit signed integer if57 * CL_DEVICE_ADDRESS_BITS is 64-bits.58 */59typedef __PTRDIFF_TYPE__ ptrdiff_t;60 61/**62 * A signed integer type with the property that any valid pointer to63 * void can be converted to this type, then converted back to pointer64 * to void, and the result will compare equal to the original pointer.65 */66typedef __INTPTR_TYPE__ intptr_t;67 68/**69 * An unsigned integer type with the property that any valid pointer to70 * void can be converted to this type, then converted back to pointer71 * to void, and the result will compare equal to the original pointer.72 */73typedef __UINTPTR_TYPE__ uintptr_t;74 75// built-in vector data types:76typedef char char2 __attribute__((ext_vector_type(2)));77typedef char char3 __attribute__((ext_vector_type(3)));78typedef char char4 __attribute__((ext_vector_type(4)));79typedef char char8 __attribute__((ext_vector_type(8)));80typedef char char16 __attribute__((ext_vector_type(16)));81typedef uchar uchar2 __attribute__((ext_vector_type(2)));82typedef uchar uchar3 __attribute__((ext_vector_type(3)));83typedef uchar uchar4 __attribute__((ext_vector_type(4)));84typedef uchar uchar8 __attribute__((ext_vector_type(8)));85typedef uchar uchar16 __attribute__((ext_vector_type(16)));86typedef short short2 __attribute__((ext_vector_type(2)));87typedef short short3 __attribute__((ext_vector_type(3)));88typedef short short4 __attribute__((ext_vector_type(4)));89typedef short short8 __attribute__((ext_vector_type(8)));90typedef short short16 __attribute__((ext_vector_type(16)));91typedef ushort ushort2 __attribute__((ext_vector_type(2)));92typedef ushort ushort3 __attribute__((ext_vector_type(3)));93typedef ushort ushort4 __attribute__((ext_vector_type(4)));94typedef ushort ushort8 __attribute__((ext_vector_type(8)));95typedef ushort ushort16 __attribute__((ext_vector_type(16)));96typedef int int2 __attribute__((ext_vector_type(2)));97typedef int int3 __attribute__((ext_vector_type(3)));98typedef int int4 __attribute__((ext_vector_type(4)));99typedef int int8 __attribute__((ext_vector_type(8)));100typedef int int16 __attribute__((ext_vector_type(16)));101typedef uint uint2 __attribute__((ext_vector_type(2)));102typedef uint uint3 __attribute__((ext_vector_type(3)));103typedef uint uint4 __attribute__((ext_vector_type(4)));104typedef uint uint8 __attribute__((ext_vector_type(8)));105typedef uint uint16 __attribute__((ext_vector_type(16)));106typedef long long2 __attribute__((ext_vector_type(2)));107typedef long long3 __attribute__((ext_vector_type(3)));108typedef long long4 __attribute__((ext_vector_type(4)));109typedef long long8 __attribute__((ext_vector_type(8)));110typedef long long16 __attribute__((ext_vector_type(16)));111typedef ulong ulong2 __attribute__((ext_vector_type(2)));112typedef ulong ulong3 __attribute__((ext_vector_type(3)));113typedef ulong ulong4 __attribute__((ext_vector_type(4)));114typedef ulong ulong8 __attribute__((ext_vector_type(8)));115typedef ulong ulong16 __attribute__((ext_vector_type(16)));116typedef float float2 __attribute__((ext_vector_type(2)));117typedef float float3 __attribute__((ext_vector_type(3)));118typedef float float4 __attribute__((ext_vector_type(4)));119typedef float float8 __attribute__((ext_vector_type(8)));120typedef float float16 __attribute__((ext_vector_type(16)));121#ifdef cl_khr_fp16122#pragma OPENCL EXTENSION cl_khr_fp16 : enable123typedef half half2 __attribute__((ext_vector_type(2)));124typedef half half3 __attribute__((ext_vector_type(3)));125typedef half half4 __attribute__((ext_vector_type(4)));126typedef half half8 __attribute__((ext_vector_type(8)));127typedef half half16 __attribute__((ext_vector_type(16)));128#endif129#ifdef cl_khr_fp64130#if __OPENCL_C_VERSION__ < CL_VERSION_1_2131#pragma OPENCL EXTENSION cl_khr_fp64 : enable132#endif133typedef double double2 __attribute__((ext_vector_type(2)));134typedef double double3 __attribute__((ext_vector_type(3)));135typedef double double4 __attribute__((ext_vector_type(4)));136typedef double double8 __attribute__((ext_vector_type(8)));137typedef double double16 __attribute__((ext_vector_type(16)));138#endif139 140// An internal alias for half, for use by OpenCLBuiltins.td.141#define __half half142 143#if defined(__OPENCL_CPP_VERSION__)144#define NULL nullptr145#elif defined(__OPENCL_C_VERSION__)146#define NULL ((void*)0)147#endif148 149/**150 * Value of maximum non-infinite single-precision floating-point151 * number.152 */153#define MAXFLOAT 0x1.fffffep127f154 155/**156 * A positive float constant expression. HUGE_VALF evaluates157 * to +infinity. Used as an error value returned by the built-in158 * math functions.159 */160#define HUGE_VALF (__builtin_huge_valf())161 162/**163 * A positive double constant expression. HUGE_VAL evaluates164 * to +infinity. Used as an error value returned by the built-in165 * math functions.166 */167#define HUGE_VAL (__builtin_huge_val())168 169/**170 * A constant expression of type float representing positive or171 * unsigned infinity.172 */173#define INFINITY (__builtin_inff())174 175/**176 * A constant expression of type float representing a quiet NaN.177 */178#define NAN as_float(INT_MAX)179 180#define FP_ILOGB0 INT_MIN181#define FP_ILOGBNAN INT_MAX182 183#define FLT_DIG 6184#define FLT_MANT_DIG 24185#define FLT_MAX_10_EXP +38186#define FLT_MAX_EXP +128187#define FLT_MIN_10_EXP -37188#define FLT_MIN_EXP -125189#define FLT_RADIX 2190#define FLT_MAX 0x1.fffffep127f191#define FLT_MIN 0x1.0p-126f192#define FLT_EPSILON 0x1.0p-23f193 194#define M_E_F 2.71828182845904523536028747135266250f195#define M_LOG2E_F 1.44269504088896340735992468100189214f196#define M_LOG10E_F 0.434294481903251827651128918916605082f197#define M_LN2_F 0.693147180559945309417232121458176568f198#define M_LN10_F 2.30258509299404568401799145468436421f199#define M_PI_F 3.14159265358979323846264338327950288f200#define M_PI_2_F 1.57079632679489661923132169163975144f201#define M_PI_4_F 0.785398163397448309615660845819875721f202#define M_1_PI_F 0.318309886183790671537767526745028724f203#define M_2_PI_F 0.636619772367581343075535053490057448f204#define M_2_SQRTPI_F 1.12837916709551257389615890312154517f205#define M_SQRT2_F 1.41421356237309504880168872420969808f206#define M_SQRT1_2_F 0.707106781186547524400844362104849039f207 208#define DBL_DIG 15209#define DBL_MANT_DIG 53210#define DBL_MAX_10_EXP +308211#define DBL_MAX_EXP +1024212#define DBL_MIN_10_EXP -307213#define DBL_MIN_EXP -1021214#define DBL_RADIX 2215#define DBL_MAX 0x1.fffffffffffffp1023216#define DBL_MIN 0x1.0p-1022217#define DBL_EPSILON 0x1.0p-52218 219#define M_E 0x1.5bf0a8b145769p+1220#define M_LOG2E 0x1.71547652b82fep+0221#define M_LOG10E 0x1.bcb7b1526e50ep-2222#define M_LN2 0x1.62e42fefa39efp-1223#define M_LN10 0x1.26bb1bbb55516p+1224#define M_PI 0x1.921fb54442d18p+1225#define M_PI_2 0x1.921fb54442d18p+0226#define M_PI_4 0x1.921fb54442d18p-1227#define M_1_PI 0x1.45f306dc9c883p-2228#define M_2_PI 0x1.45f306dc9c883p-1229#define M_2_SQRTPI 0x1.20dd750429b6dp+0230#define M_SQRT2 0x1.6a09e667f3bcdp+0231#define M_SQRT1_2 0x1.6a09e667f3bcdp-1232 233#ifdef cl_khr_fp16234 235#define HALF_DIG 3236#define HALF_MANT_DIG 11237#define HALF_MAX_10_EXP +4238#define HALF_MAX_EXP +16239#define HALF_MIN_10_EXP -4240#define HALF_MIN_EXP -13241#define HALF_RADIX 2242#define HALF_MAX ((0x1.ffcp15h))243#define HALF_MIN ((0x1.0p-14h))244#define HALF_EPSILON ((0x1.0p-10h))245 246#define M_E_H 2.71828182845904523536028747135266250h247#define M_LOG2E_H 1.44269504088896340735992468100189214h248#define M_LOG10E_H 0.434294481903251827651128918916605082h249#define M_LN2_H 0.693147180559945309417232121458176568h250#define M_LN10_H 2.30258509299404568401799145468436421h251#define M_PI_H 3.14159265358979323846264338327950288h252#define M_PI_2_H 1.57079632679489661923132169163975144h253#define M_PI_4_H 0.785398163397448309615660845819875721h254#define M_1_PI_H 0.318309886183790671537767526745028724h255#define M_2_PI_H 0.636619772367581343075535053490057448h256#define M_2_SQRTPI_H 1.12837916709551257389615890312154517h257#define M_SQRT2_H 1.41421356237309504880168872420969808h258#define M_SQRT1_2_H 0.707106781186547524400844362104849039h259 260#endif //cl_khr_fp16261 262#define CHAR_BIT 8263#define SCHAR_MAX 127264#define SCHAR_MIN (-128)265#define UCHAR_MAX 255266#define CHAR_MAX SCHAR_MAX267#define CHAR_MIN SCHAR_MIN268#define USHRT_MAX 65535269#define SHRT_MAX 32767270#define SHRT_MIN (-32768)271#define UINT_MAX 0xffffffff272#define INT_MAX 2147483647273#define INT_MIN (-2147483647-1)274#define ULONG_MAX 0xffffffffffffffffUL275#define LONG_MAX 0x7fffffffffffffffL276#define LONG_MIN (-0x7fffffffffffffffL-1)277 278// OpenCL v1.1 s6.11.8, v1.2 s6.12.8, v2.0 s6.13.8 - Synchronization Functions279 280// Flag type and values for barrier, mem_fence, read_mem_fence, write_mem_fence281typedef uint cl_mem_fence_flags;282 283/**284 * Queue a memory fence to ensure correct285 * ordering of memory operations to local memory286 */287#define CLK_LOCAL_MEM_FENCE 0x01288 289/**290 * Queue a memory fence to ensure correct291 * ordering of memory operations to global memory292 */293#define CLK_GLOBAL_MEM_FENCE 0x02294 295#if defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= CL_VERSION_2_0)296 297typedef enum memory_scope {298 memory_scope_work_item = __OPENCL_MEMORY_SCOPE_WORK_ITEM,299 memory_scope_work_group = __OPENCL_MEMORY_SCOPE_WORK_GROUP,300 memory_scope_device = __OPENCL_MEMORY_SCOPE_DEVICE,301#if defined(__opencl_c_atomic_scope_all_devices)302 memory_scope_all_svm_devices = __OPENCL_MEMORY_SCOPE_ALL_SVM_DEVICES,303#if (__OPENCL_C_VERSION__ >= CL_VERSION_3_0 || __OPENCL_CPP_VERSION__ >= 202100)304 memory_scope_all_devices = memory_scope_all_svm_devices,305#endif // (__OPENCL_C_VERSION__ >= CL_VERSION_3_0 || __OPENCL_CPP_VERSION__ >= 202100)306#endif // defined(__opencl_c_atomic_scope_all_devices)307/**308 * Subgroups have different requirements on forward progress, so just test309 * all the relevant macros.310 * CL 3.0 sub-groups "they are not guaranteed to make independent forward progress"311 * KHR subgroups "Subgroups within a workgroup are independent, make forward progress with respect to each other"312 */313#if defined(cl_intel_subgroups) || defined(cl_khr_subgroups) || defined(__opencl_c_subgroups)314 memory_scope_sub_group = __OPENCL_MEMORY_SCOPE_SUB_GROUP315#endif316} memory_scope;317 318/**319 * Queue a memory fence to ensure correct ordering of memory320 * operations between work-items of a work-group to321 * image memory.322 */323#define CLK_IMAGE_MEM_FENCE 0x04324 325#ifndef ATOMIC_VAR_INIT326#define ATOMIC_VAR_INIT(x) (x)327#endif //ATOMIC_VAR_INIT328#define ATOMIC_FLAG_INIT 0329 330// enum values aligned with what clang uses in EmitAtomicExpr()331typedef enum memory_order332{333 memory_order_relaxed = __ATOMIC_RELAXED,334 memory_order_acquire = __ATOMIC_ACQUIRE,335 memory_order_release = __ATOMIC_RELEASE,336 memory_order_acq_rel = __ATOMIC_ACQ_REL,337#if defined(__opencl_c_atomic_order_seq_cst)338 memory_order_seq_cst = __ATOMIC_SEQ_CST339#endif340} memory_order;341 342#endif // defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= CL_VERSION_2_0)343 344// OpenCL v1.1 s6.11.3, v1.2 s6.12.14, v2.0 s6.13.14 - Image Read and Write Functions345 346// These values need to match the runtime equivalent347//348// Addressing Mode.349//350#define CLK_ADDRESS_NONE 0351#define CLK_ADDRESS_CLAMP_TO_EDGE 2352#define CLK_ADDRESS_CLAMP 4353#define CLK_ADDRESS_REPEAT 6354#define CLK_ADDRESS_MIRRORED_REPEAT 8355 356//357// Coordination Normalization358//359#define CLK_NORMALIZED_COORDS_FALSE 0360#define CLK_NORMALIZED_COORDS_TRUE 1361 362//363// Filtering Mode.364//365#define CLK_FILTER_NEAREST 0x10366#define CLK_FILTER_LINEAR 0x20367 368#ifdef cl_khr_gl_msaa_sharing369#pragma OPENCL EXTENSION cl_khr_gl_msaa_sharing : enable370#endif //cl_khr_gl_msaa_sharing371 372//373// Channel Datatype.374//375#define CLK_SNORM_INT8 0x10D0376#define CLK_SNORM_INT16 0x10D1377#define CLK_UNORM_INT8 0x10D2378#define CLK_UNORM_INT16 0x10D3379#define CLK_UNORM_SHORT_565 0x10D4380#define CLK_UNORM_SHORT_555 0x10D5381#define CLK_UNORM_INT_101010 0x10D6382#define CLK_SIGNED_INT8 0x10D7383#define CLK_SIGNED_INT16 0x10D8384#define CLK_SIGNED_INT32 0x10D9385#define CLK_UNSIGNED_INT8 0x10DA386#define CLK_UNSIGNED_INT16 0x10DB387#define CLK_UNSIGNED_INT32 0x10DC388#define CLK_HALF_FLOAT 0x10DD389#define CLK_FLOAT 0x10DE390#define CLK_UNORM_INT24 0x10DF391#if __OPENCL_C_VERSION__ >= CL_VERSION_3_0392#define CLK_UNORM_INT_101010_2 0x10E0393#endif // __OPENCL_C_VERSION__ >= CL_VERSION_3_0394#ifdef __opencl_c_ext_image_raw10_raw12395#define CLK_UNSIGNED_INT_RAW10_EXT 0x10E3396#define CLK_UNSIGNED_INT_RAW12_EXT 0x10E4397#endif // __opencl_c_ext_image_raw10_raw12398#ifdef __opencl_c_ext_image_unorm_int_2_101010399#define CLK_UNORM_INT_2_101010_EXT 0x10E5400#endif // __opencl_c_ext_image_unorm_int_2_101010401#ifdef __opencl_c_ext_image_unsigned_10x6_12x4_14x2402#define CLK_UNSIGNED_INT10X6_EXT 0x10E6403#define CLK_UNSIGNED_INT12X4_EXT 0x10E7404#define CLK_UNSIGNED_INT14X2_EXT 0x10E8405#define CLK_UNORM_10X6_EXT 0x10E1406#define CLK_UNORM_12X4_EXT 0x10E9407#define CLK_UNORM_14X2_EXT 0x10EA408#endif // __opencl_c_ext_image_unsigned_10x6_12x4_14x2409 410// Channel order, numbering must be aligned with cl_channel_order in cl.h411//412#define CLK_R 0x10B0413#define CLK_A 0x10B1414#define CLK_RG 0x10B2415#define CLK_RA 0x10B3416#define CLK_RGB 0x10B4417#define CLK_RGBA 0x10B5418#define CLK_BGRA 0x10B6419#define CLK_ARGB 0x10B7420#define CLK_INTENSITY 0x10B8421#define CLK_LUMINANCE 0x10B9422#define CLK_Rx 0x10BA423#define CLK_RGx 0x10BB424#define CLK_RGBx 0x10BC425#define CLK_DEPTH 0x10BD426#define CLK_DEPTH_STENCIL 0x10BE427#if __OPENCL_C_VERSION__ >= CL_VERSION_2_0428#define CLK_sRGB 0x10BF429#define CLK_sRGBx 0x10C0430#define CLK_sRGBA 0x10C1431#define CLK_sBGRA 0x10C2432#define CLK_ABGR 0x10C3433#endif //__OPENCL_C_VERSION__ >= CL_VERSION_2_0434 435// OpenCL v2.0 s6.13.16 - Pipe Functions436#if defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= CL_VERSION_2_0)437#define CLK_NULL_RESERVE_ID (__builtin_astype(((void*)(__SIZE_MAX__)), reserve_id_t))438 439// OpenCL v2.0 s6.13.17 - Enqueue Kernels440#define CL_COMPLETE 0x0441#define CL_RUNNING 0x1442#define CL_SUBMITTED 0x2443#define CL_QUEUED 0x3444 445#define CLK_SUCCESS 0446#define CLK_ENQUEUE_FAILURE -101447#define CLK_INVALID_QUEUE -102448#define CLK_INVALID_NDRANGE -160449#define CLK_INVALID_EVENT_WAIT_LIST -57450#define CLK_DEVICE_QUEUE_FULL -161451#define CLK_INVALID_ARG_SIZE -51452#define CLK_EVENT_ALLOCATION_FAILURE -100453#define CLK_OUT_OF_RESOURCES -5454 455#define CLK_NULL_QUEUE 0456#define CLK_NULL_EVENT (__builtin_astype(((__SIZE_MAX__)), clk_event_t))457 458// execution model related definitions459#define CLK_ENQUEUE_FLAGS_NO_WAIT 0x0460#define CLK_ENQUEUE_FLAGS_WAIT_KERNEL 0x1461#define CLK_ENQUEUE_FLAGS_WAIT_WORK_GROUP 0x2462 463typedef int kernel_enqueue_flags_t;464typedef int clk_profiling_info;465 466// Profiling info name (see capture_event_profiling_info)467#define CLK_PROFILING_COMMAND_EXEC_TIME 0x1468 469#define MAX_WORK_DIM 3470 471#ifdef __opencl_c_device_enqueue472typedef struct {473 unsigned int workDimension;474 size_t globalWorkOffset[MAX_WORK_DIM];475 size_t globalWorkSize[MAX_WORK_DIM];476 size_t localWorkSize[MAX_WORK_DIM];477} ndrange_t;478#endif // __opencl_c_device_enqueue479 480#endif // defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= CL_VERSION_2_0)481 482/**483 * OpenCL v1.1/1.2/2.0 s6.2.4.2 - as_type operators484 * Reinterprets a data type as another data type of the same size485 */486#define as_char(x) __builtin_astype((x), char)487#define as_char2(x) __builtin_astype((x), char2)488#define as_char3(x) __builtin_astype((x), char3)489#define as_char4(x) __builtin_astype((x), char4)490#define as_char8(x) __builtin_astype((x), char8)491#define as_char16(x) __builtin_astype((x), char16)492 493#define as_uchar(x) __builtin_astype((x), uchar)494#define as_uchar2(x) __builtin_astype((x), uchar2)495#define as_uchar3(x) __builtin_astype((x), uchar3)496#define as_uchar4(x) __builtin_astype((x), uchar4)497#define as_uchar8(x) __builtin_astype((x), uchar8)498#define as_uchar16(x) __builtin_astype((x), uchar16)499 500#define as_short(x) __builtin_astype((x), short)501#define as_short2(x) __builtin_astype((x), short2)502#define as_short3(x) __builtin_astype((x), short3)503#define as_short4(x) __builtin_astype((x), short4)504#define as_short8(x) __builtin_astype((x), short8)505#define as_short16(x) __builtin_astype((x), short16)506 507#define as_ushort(x) __builtin_astype((x), ushort)508#define as_ushort2(x) __builtin_astype((x), ushort2)509#define as_ushort3(x) __builtin_astype((x), ushort3)510#define as_ushort4(x) __builtin_astype((x), ushort4)511#define as_ushort8(x) __builtin_astype((x), ushort8)512#define as_ushort16(x) __builtin_astype((x), ushort16)513 514#define as_int(x) __builtin_astype((x), int)515#define as_int2(x) __builtin_astype((x), int2)516#define as_int3(x) __builtin_astype((x), int3)517#define as_int4(x) __builtin_astype((x), int4)518#define as_int8(x) __builtin_astype((x), int8)519#define as_int16(x) __builtin_astype((x), int16)520 521#define as_uint(x) __builtin_astype((x), uint)522#define as_uint2(x) __builtin_astype((x), uint2)523#define as_uint3(x) __builtin_astype((x), uint3)524#define as_uint4(x) __builtin_astype((x), uint4)525#define as_uint8(x) __builtin_astype((x), uint8)526#define as_uint16(x) __builtin_astype((x), uint16)527 528#define as_long(x) __builtin_astype((x), long)529#define as_long2(x) __builtin_astype((x), long2)530#define as_long3(x) __builtin_astype((x), long3)531#define as_long4(x) __builtin_astype((x), long4)532#define as_long8(x) __builtin_astype((x), long8)533#define as_long16(x) __builtin_astype((x), long16)534 535#define as_ulong(x) __builtin_astype((x), ulong)536#define as_ulong2(x) __builtin_astype((x), ulong2)537#define as_ulong3(x) __builtin_astype((x), ulong3)538#define as_ulong4(x) __builtin_astype((x), ulong4)539#define as_ulong8(x) __builtin_astype((x), ulong8)540#define as_ulong16(x) __builtin_astype((x), ulong16)541 542#define as_float(x) __builtin_astype((x), float)543#define as_float2(x) __builtin_astype((x), float2)544#define as_float3(x) __builtin_astype((x), float3)545#define as_float4(x) __builtin_astype((x), float4)546#define as_float8(x) __builtin_astype((x), float8)547#define as_float16(x) __builtin_astype((x), float16)548 549#ifdef cl_khr_fp64550#define as_double(x) __builtin_astype((x), double)551#define as_double2(x) __builtin_astype((x), double2)552#define as_double3(x) __builtin_astype((x), double3)553#define as_double4(x) __builtin_astype((x), double4)554#define as_double8(x) __builtin_astype((x), double8)555#define as_double16(x) __builtin_astype((x), double16)556#endif // cl_khr_fp64557 558#ifdef cl_khr_fp16559#define as_half(x) __builtin_astype((x), half)560#define as_half2(x) __builtin_astype((x), half2)561#define as_half3(x) __builtin_astype((x), half3)562#define as_half4(x) __builtin_astype((x), half4)563#define as_half8(x) __builtin_astype((x), half8)564#define as_half16(x) __builtin_astype((x), half16)565#endif // cl_khr_fp16566 567#define as_size_t(x) __builtin_astype((x), size_t)568#define as_ptrdiff_t(x) __builtin_astype((x), ptrdiff_t)569#define as_intptr_t(x) __builtin_astype((x), intptr_t)570#define as_uintptr_t(x) __builtin_astype((x), uintptr_t)571 572// C++ for OpenCL - __remove_address_space573#if defined(__OPENCL_CPP_VERSION__)574template <typename _Tp> struct __remove_address_space { using type = _Tp; };575#if defined(__opencl_c_generic_address_space)576template <typename _Tp> struct __remove_address_space<__generic _Tp> {577 using type = _Tp;578};579#endif580template <typename _Tp> struct __remove_address_space<__global _Tp> {581 using type = _Tp;582};583template <typename _Tp> struct __remove_address_space<__private _Tp> {584 using type = _Tp;585};586template <typename _Tp> struct __remove_address_space<__local _Tp> {587 using type = _Tp;588};589template <typename _Tp> struct __remove_address_space<__constant _Tp> {590 using type = _Tp;591};592#endif593 594// OpenCL v1.1 s6.9, v1.2/2.0 s6.10 - Function qualifiers595 596#define __kernel_exec(X, typen) __kernel \597 __attribute__((work_group_size_hint(X, 1, 1))) \598 __attribute__((vec_type_hint(typen)))599 600#define kernel_exec(X, typen) __kernel \601 __attribute__((work_group_size_hint(X, 1, 1))) \602 __attribute__((vec_type_hint(typen)))603 604#if defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= CL_VERSION_1_2)605// OpenCL v1.2 s6.12.13, v2.0 s6.13.13 - printf606 607#ifdef __OPENCL_CPP_VERSION__608#define CLINKAGE extern "C"609#else610#define CLINKAGE611#endif612 613CLINKAGE int printf(__constant const char *st, ...)614 __attribute__((format(printf, 1, 2)));615 616#undef CLINKAGE617#endif618 619#ifdef cl_intel_device_side_avc_motion_estimation620 621#define CLK_AVC_ME_MAJOR_16x16_INTEL 0x0622#define CLK_AVC_ME_MAJOR_16x8_INTEL 0x1623#define CLK_AVC_ME_MAJOR_8x16_INTEL 0x2624#define CLK_AVC_ME_MAJOR_8x8_INTEL 0x3625 626#define CLK_AVC_ME_MINOR_8x8_INTEL 0x0627#define CLK_AVC_ME_MINOR_8x4_INTEL 0x1628#define CLK_AVC_ME_MINOR_4x8_INTEL 0x2629#define CLK_AVC_ME_MINOR_4x4_INTEL 0x3630 631#define CLK_AVC_ME_MAJOR_FORWARD_INTEL 0x0632#define CLK_AVC_ME_MAJOR_BACKWARD_INTEL 0x1633#define CLK_AVC_ME_MAJOR_BIDIRECTIONAL_INTEL 0x2634 635#define CLK_AVC_ME_PARTITION_MASK_ALL_INTEL 0x0636#define CLK_AVC_ME_PARTITION_MASK_16x16_INTEL 0x7E637#define CLK_AVC_ME_PARTITION_MASK_16x8_INTEL 0x7D638#define CLK_AVC_ME_PARTITION_MASK_8x16_INTEL 0x7B639#define CLK_AVC_ME_PARTITION_MASK_8x8_INTEL 0x77640#define CLK_AVC_ME_PARTITION_MASK_8x4_INTEL 0x6F641#define CLK_AVC_ME_PARTITION_MASK_4x8_INTEL 0x5F642#define CLK_AVC_ME_PARTITION_MASK_4x4_INTEL 0x3F643 644#define CLK_AVC_ME_SLICE_TYPE_PRED_INTEL 0x0645#define CLK_AVC_ME_SLICE_TYPE_BPRED_INTEL 0x1646#define CLK_AVC_ME_SLICE_TYPE_INTRA_INTEL 0x2647 648#define CLK_AVC_ME_SEARCH_WINDOW_EXHAUSTIVE_INTEL 0x0649#define CLK_AVC_ME_SEARCH_WINDOW_SMALL_INTEL 0x1650#define CLK_AVC_ME_SEARCH_WINDOW_TINY_INTEL 0x2651#define CLK_AVC_ME_SEARCH_WINDOW_EXTRA_TINY_INTEL 0x3652#define CLK_AVC_ME_SEARCH_WINDOW_DIAMOND_INTEL 0x4653#define CLK_AVC_ME_SEARCH_WINDOW_LARGE_DIAMOND_INTEL 0x5654#define CLK_AVC_ME_SEARCH_WINDOW_RESERVED0_INTEL 0x6655#define CLK_AVC_ME_SEARCH_WINDOW_RESERVED1_INTEL 0x7656#define CLK_AVC_ME_SEARCH_WINDOW_CUSTOM_INTEL 0x8657 658#define CLK_AVC_ME_SAD_ADJUST_MODE_NONE_INTEL 0x0659#define CLK_AVC_ME_SAD_ADJUST_MODE_HAAR_INTEL 0x2660 661#define CLK_AVC_ME_SUBPIXEL_MODE_INTEGER_INTEL 0x0662#define CLK_AVC_ME_SUBPIXEL_MODE_HPEL_INTEL 0x1663#define CLK_AVC_ME_SUBPIXEL_MODE_QPEL_INTEL 0x3664 665#define CLK_AVC_ME_COST_PRECISION_QPEL_INTEL 0x0666#define CLK_AVC_ME_COST_PRECISION_HPEL_INTEL 0x1667#define CLK_AVC_ME_COST_PRECISION_PEL_INTEL 0x2668#define CLK_AVC_ME_COST_PRECISION_DPEL_INTEL 0x3669 670#define CLK_AVC_ME_BIDIR_WEIGHT_QUARTER_INTEL 0x10671#define CLK_AVC_ME_BIDIR_WEIGHT_THIRD_INTEL 0x15672#define CLK_AVC_ME_BIDIR_WEIGHT_HALF_INTEL 0x20673#define CLK_AVC_ME_BIDIR_WEIGHT_TWO_THIRD_INTEL 0x2B674#define CLK_AVC_ME_BIDIR_WEIGHT_THREE_QUARTER_INTEL 0x30675 676#define CLK_AVC_ME_BORDER_REACHED_LEFT_INTEL 0x0677#define CLK_AVC_ME_BORDER_REACHED_RIGHT_INTEL 0x2678#define CLK_AVC_ME_BORDER_REACHED_TOP_INTEL 0x4679#define CLK_AVC_ME_BORDER_REACHED_BOTTOM_INTEL 0x8680 681#define CLK_AVC_ME_INTRA_16x16_INTEL 0x0682#define CLK_AVC_ME_INTRA_8x8_INTEL 0x1683#define CLK_AVC_ME_INTRA_4x4_INTEL 0x2684 685#define CLK_AVC_ME_SKIP_BLOCK_PARTITION_16x16_INTEL 0x0686#define CLK_AVC_ME_SKIP_BLOCK_PARTITION_8x8_INTEL 0x4000687 688#define CLK_AVC_ME_SKIP_BLOCK_16x16_FORWARD_ENABLE_INTEL (0x1 << 24)689#define CLK_AVC_ME_SKIP_BLOCK_16x16_BACKWARD_ENABLE_INTEL (0x2 << 24)690#define CLK_AVC_ME_SKIP_BLOCK_16x16_DUAL_ENABLE_INTEL (0x3 << 24)691#define CLK_AVC_ME_SKIP_BLOCK_8x8_FORWARD_ENABLE_INTEL (0x55 << 24)692#define CLK_AVC_ME_SKIP_BLOCK_8x8_BACKWARD_ENABLE_INTEL (0xAA << 24)693#define CLK_AVC_ME_SKIP_BLOCK_8x8_DUAL_ENABLE_INTEL (0xFF << 24)694#define CLK_AVC_ME_SKIP_BLOCK_8x8_0_FORWARD_ENABLE_INTEL (0x1 << 24)695#define CLK_AVC_ME_SKIP_BLOCK_8x8_0_BACKWARD_ENABLE_INTEL (0x2 << 24)696#define CLK_AVC_ME_SKIP_BLOCK_8x8_1_FORWARD_ENABLE_INTEL (0x1 << 26)697#define CLK_AVC_ME_SKIP_BLOCK_8x8_1_BACKWARD_ENABLE_INTEL (0x2 << 26)698#define CLK_AVC_ME_SKIP_BLOCK_8x8_2_FORWARD_ENABLE_INTEL (0x1 << 28)699#define CLK_AVC_ME_SKIP_BLOCK_8x8_2_BACKWARD_ENABLE_INTEL (0x2 << 28)700#define CLK_AVC_ME_SKIP_BLOCK_8x8_3_FORWARD_ENABLE_INTEL (0x1 << 30)701#define CLK_AVC_ME_SKIP_BLOCK_8x8_3_BACKWARD_ENABLE_INTEL (0x2 << 30)702 703#define CLK_AVC_ME_BLOCK_BASED_SKIP_4x4_INTEL 0x00704#define CLK_AVC_ME_BLOCK_BASED_SKIP_8x8_INTEL 0x80705 706#define CLK_AVC_ME_INTRA_LUMA_PARTITION_MASK_ALL_INTEL 0x0707#define CLK_AVC_ME_INTRA_LUMA_PARTITION_MASK_16x16_INTEL 0x6708#define CLK_AVC_ME_INTRA_LUMA_PARTITION_MASK_8x8_INTEL 0x5709#define CLK_AVC_ME_INTRA_LUMA_PARTITION_MASK_4x4_INTEL 0x3710 711#define CLK_AVC_ME_INTRA_NEIGHBOR_LEFT_MASK_ENABLE_INTEL 0x60712#define CLK_AVC_ME_INTRA_NEIGHBOR_UPPER_MASK_ENABLE_INTEL 0x10713#define CLK_AVC_ME_INTRA_NEIGHBOR_UPPER_RIGHT_MASK_ENABLE_INTEL 0x8714#define CLK_AVC_ME_INTRA_NEIGHBOR_UPPER_LEFT_MASK_ENABLE_INTEL 0x4715 716#define CLK_AVC_ME_LUMA_PREDICTOR_MODE_VERTICAL_INTEL 0x0717#define CLK_AVC_ME_LUMA_PREDICTOR_MODE_HORIZONTAL_INTEL 0x1718#define CLK_AVC_ME_LUMA_PREDICTOR_MODE_DC_INTEL 0x2719#define CLK_AVC_ME_LUMA_PREDICTOR_MODE_DIAGONAL_DOWN_LEFT_INTEL 0x3720#define CLK_AVC_ME_LUMA_PREDICTOR_MODE_DIAGONAL_DOWN_RIGHT_INTEL 0x4721#define CLK_AVC_ME_LUMA_PREDICTOR_MODE_PLANE_INTEL 0x4722#define CLK_AVC_ME_LUMA_PREDICTOR_MODE_VERTICAL_RIGHT_INTEL 0x5723#define CLK_AVC_ME_LUMA_PREDICTOR_MODE_HORIZONTAL_DOWN_INTEL 0x6724#define CLK_AVC_ME_LUMA_PREDICTOR_MODE_VERTICAL_LEFT_INTEL 0x7725#define CLK_AVC_ME_LUMA_PREDICTOR_MODE_HORIZONTAL_UP_INTEL 0x8726#define CLK_AVC_ME_CHROMA_PREDICTOR_MODE_DC_INTEL 0x0727#define CLK_AVC_ME_CHROMA_PREDICTOR_MODE_HORIZONTAL_INTEL 0x1728#define CLK_AVC_ME_CHROMA_PREDICTOR_MODE_VERTICAL_INTEL 0x2729#define CLK_AVC_ME_CHROMA_PREDICTOR_MODE_PLANE_INTEL 0x3730 731#define CLK_AVC_ME_FRAME_FORWARD_INTEL 0x1732#define CLK_AVC_ME_FRAME_BACKWARD_INTEL 0x2733#define CLK_AVC_ME_FRAME_DUAL_INTEL 0x3734 735#define CLK_AVC_ME_INTERLACED_SCAN_TOP_FIELD_INTEL 0x0736#define CLK_AVC_ME_INTERLACED_SCAN_BOTTOM_FIELD_INTEL 0x1737 738#define CLK_AVC_ME_INITIALIZE_INTEL 0x0739 740#define CLK_AVC_IME_PAYLOAD_INITIALIZE_INTEL 0x0741#define CLK_AVC_REF_PAYLOAD_INITIALIZE_INTEL 0x0742#define CLK_AVC_SIC_PAYLOAD_INITIALIZE_INTEL 0x0743 744#define CLK_AVC_IME_RESULT_INITIALIZE_INTEL 0x0745#define CLK_AVC_REF_RESULT_INITIALIZE_INTEL 0x0746#define CLK_AVC_SIC_RESULT_INITIALIZE_INTEL 0x0747 748#define CLK_AVC_IME_RESULT_SINGLE_REFERENCE_STREAMOUT_INITIALIZE_INTEL 0x0749#define CLK_AVC_IME_RESULT_SINGLE_REFERENCE_STREAMIN_INITIALIZE_INTEL 0x0750#define CLK_AVC_IME_RESULT_DUAL_REFERENCE_STREAMOUT_INITIALIZE_INTEL 0x0751#define CLK_AVC_IME_RESULT_DUAL_REFERENCE_STREAMIN_INITIALIZE_INTEL 0x0752 753#endif // cl_intel_device_side_avc_motion_estimation754 755// Disable any extensions we may have enabled previously.756#pragma OPENCL EXTENSION all : disable757 758#endif //_OPENCL_BASE_H_759