1 /********************************************************************************** 2 * Copyright (c) 2008-2009 The Khronos Group Inc. 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a 5 * copy of this software and/or associated documentation files (the 6 * "Materials"), to deal in the Materials without restriction, including 7 * without limitation the rights to use, copy, modify, merge, publish, 8 * distribute, sublicense, and/or sell copies of the Materials, and to 9 * permit persons to whom the Materials are furnished to do so, subject to 10 * the following conditions: 11 * 12 * The above copyright notice and this permission notice shall be included 13 * in all copies or substantial portions of the Materials. 14 * 15 * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. 22 **********************************************************************************/ 23 24 #ifndef __CL_PLATFORM_H 25 #define __CL_PLATFORM_H 26 27 #ifdef __APPLE__ 28 /* Contains #defines for AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER below */ 29 #include <AvailabilityMacros.h> 30 #endif 31 32 #ifdef __cplusplus 33 extern "C" { 34 #endif 35 36 #define CL_API_ENTRY 37 #define CL_API_CALL 38 #ifdef __APPLE__ 39 #define CL_API_SUFFIX__VERSION_1_0 // AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER 40 #define CL_EXTENSION_WEAK_LINK __attribute__((weak_import)) 41 #else 42 #define CL_API_SUFFIX__VERSION_1_0 43 #define CL_EXTENSION_WEAK_LINK 44 #endif 45 46 #ifdef WIN32 47 typedef signed __int8 int8_t; 48 typedef unsigned __int8 uint8_t; 49 typedef signed __int16 int16_t; 50 typedef unsigned __int16 uint16_t; 51 typedef signed __int32 int32_t; 52 typedef unsigned __int32 uint32_t; 53 typedef signed __int64 int64_t; 54 typedef unsigned __int64 uint64_t; 55 56 typedef int8_t cl_char; 57 typedef uint8_t cl_uchar; 58 typedef int16_t cl_short ; 59 typedef uint16_t cl_ushort ; 60 typedef int32_t cl_int ; 61 typedef uint32_t cl_uint ; 62 typedef int64_t cl_long ; 63 typedef uint64_t cl_ulong ; 64 65 typedef uint16_t cl_half ; 66 typedef float cl_float ; 67 typedef double cl_double ; 68 69 70 typedef int8_t cl_char2[2] ; 71 typedef int8_t cl_char4[4] ; 72 typedef int8_t cl_char8[8] ; 73 typedef int8_t cl_char16[16] ; 74 typedef uint8_t cl_uchar2[2] ; 75 typedef uint8_t cl_uchar4[4] ; 76 typedef uint8_t cl_uchar8[8] ; 77 typedef uint8_t cl_uchar16[16] ; 78 79 typedef int16_t cl_short2[2] ; 80 typedef int16_t cl_short4[4] ; 81 typedef int16_t cl_short8[8] ; 82 typedef int16_t cl_short16[16] ; 83 typedef uint16_t cl_ushort2[2] ; 84 typedef uint16_t cl_ushort4[4] ; 85 typedef uint16_t cl_ushort8[8] ; 86 typedef uint16_t cl_ushort16[16] ; 87 88 typedef int32_t cl_int2[2] ; 89 typedef int32_t cl_int4[4] ; 90 typedef int32_t cl_int8[8] ; 91 typedef int32_t cl_int16[16] ; 92 typedef uint32_t cl_uint2[2] ; 93 typedef uint32_t cl_uint4[4] ; 94 typedef uint32_t cl_uint8[8] ; 95 typedef uint32_t cl_uint16[16] ; 96 97 typedef int64_t cl_long2[2] ; 98 typedef int64_t cl_long4[4] ; 99 typedef int64_t cl_long8[8] ; 100 typedef int64_t cl_long16[16] ; 101 typedef uint64_t cl_ulong2[2] ; 102 typedef uint64_t cl_ulong4[4] ; 103 typedef uint64_t cl_ulong8[8] ; 104 typedef uint64_t cl_ulong16[16] ; 105 106 typedef float cl_float2[2] ; 107 typedef float cl_float4[4] ; 108 typedef float cl_float8[8] ; 109 typedef float cl_float16[16] ; 110 111 typedef double cl_double2[2] ; 112 typedef double cl_double4[4] ; 113 typedef double cl_double8[8] ; 114 typedef double cl_double16[16] ; 115 116 117 #else 118 #include <stdint.h> 119 120 /* scalar types */ 121 typedef int8_t cl_char; 122 typedef uint8_t cl_uchar; 123 typedef int16_t cl_short __attribute__((aligned(2))); 124 typedef uint16_t cl_ushort __attribute__((aligned(2))); 125 typedef int32_t cl_int __attribute__((aligned(4))); 126 typedef uint32_t cl_uint __attribute__((aligned(4))); 127 typedef int64_t cl_long __attribute__((aligned(8))); 128 typedef uint64_t cl_ulong __attribute__((aligned(8))); 129 130 typedef uint16_t cl_half __attribute__((aligned(2))); 131 typedef float cl_float __attribute__((aligned(4))); 132 typedef double cl_double __attribute__((aligned(8))); 133 134 135 /* 136 * Vector types 137 * 138 * Note: OpenCL requires that all types be naturally aligned. 139 * This means that vector types must be naturally aligned. 140 * For example, a vector of four floats must be aligned to 141 * a 16 byte boundary (calculated as 4 * the natural 4-byte 142 * alignment of the float). The alignment qualifiers here 143 * will only function properly if your compiler supports them 144 * and if you don't actively work to defeat them. For example, 145 * in order for a cl_float4 to be 16 byte aligned in a struct, 146 * the start of the struct must itself be 16-byte aligned. 147 * 148 * Maintaining proper alignment is the user's responsibility. 149 */ 150 typedef int8_t cl_char2[2] __attribute__((aligned(2))); 151 typedef int8_t cl_char4[4] __attribute__((aligned(4))); 152 typedef int8_t cl_char8[8] __attribute__((aligned(8))); 153 typedef int8_t cl_char16[16] __attribute__((aligned(16))); 154 typedef uint8_t cl_uchar2[2] __attribute__((aligned(2))); 155 typedef uint8_t cl_uchar4[4] __attribute__((aligned(4))); 156 typedef uint8_t cl_uchar8[8] __attribute__((aligned(8))); 157 typedef uint8_t cl_uchar16[16] __attribute__((aligned(16))); 158 159 typedef int16_t cl_short2[2] __attribute__((aligned(4))); 160 typedef int16_t cl_short4[4] __attribute__((aligned(8))); 161 typedef int16_t cl_short8[8] __attribute__((aligned(16))); 162 typedef int16_t cl_short16[16] __attribute__((aligned(32))); 163 typedef uint16_t cl_ushort2[2] __attribute__((aligned(4))); 164 typedef uint16_t cl_ushort4[4] __attribute__((aligned(8))); 165 typedef uint16_t cl_ushort8[8] __attribute__((aligned(16))); 166 typedef uint16_t cl_ushort16[16] __attribute__((aligned(32))); 167 168 typedef int32_t cl_int2[2] __attribute__((aligned(8))); 169 typedef int32_t cl_int4[4] __attribute__((aligned(16))); 170 typedef int32_t cl_int8[8] __attribute__((aligned(32))); 171 typedef int32_t cl_int16[16] __attribute__((aligned(64))); 172 typedef uint32_t cl_uint2[2] __attribute__((aligned(8))); 173 typedef uint32_t cl_uint4[4] __attribute__((aligned(16))); 174 typedef uint32_t cl_uint8[8] __attribute__((aligned(32))); 175 typedef uint32_t cl_uint16[16] __attribute__((aligned(64))); 176 177 typedef int64_t cl_long2[2] __attribute__((aligned(16))); 178 typedef int64_t cl_long4[4] __attribute__((aligned(32))); 179 typedef int64_t cl_long8[8] __attribute__((aligned(64))); 180 typedef int64_t cl_long16[16] __attribute__((aligned(128))); 181 typedef uint64_t cl_ulong2[2] __attribute__((aligned(16))); 182 typedef uint64_t cl_ulong4[4] __attribute__((aligned(32))); 183 typedef uint64_t cl_ulong8[8] __attribute__((aligned(64))); 184 typedef uint64_t cl_ulong16[16] __attribute__((aligned(128))); 185 186 typedef float cl_float2[2] __attribute__((aligned(8))); 187 typedef float cl_float4[4] __attribute__((aligned(16))); 188 typedef float cl_float8[8] __attribute__((aligned(32))); 189 typedef float cl_float16[16] __attribute__((aligned(64))); 190 191 typedef double cl_double2[2] __attribute__((aligned(16))); 192 typedef double cl_double4[4] __attribute__((aligned(32))); 193 typedef double cl_double8[8] __attribute__((aligned(64))); 194 typedef double cl_double16[16] __attribute__((aligned(128))); 195 #endif 196 197 #include <stddef.h> 198 199 /* and a few goodies to go with them */ 200 #define CL_CHAR_BIT 8 201 #define CL_SCHAR_MAX 127 202 #define CL_SCHAR_MIN (-127-1) 203 #define CL_CHAR_MAX CL_SCHAR_MAX 204 #define CL_CHAR_MIN CL_SCHAR_MIN 205 #define CL_UCHAR_MAX 255 206 #define CL_SHRT_MAX 32767 207 #define CL_SHRT_MIN (-32767-1) 208 #define CL_USHRT_MAX 65535 209 #define CL_INT_MAX 2147483647 210 #define CL_INT_MIN (-2147483647-1) 211 #define CL_UINT_MAX 0xffffffffU 212 #define CL_LONG_MAX ((cl_long) 0x7FFFFFFFFFFFFFFFLL) 213 #define CL_LONG_MIN ((cl_long) -0x7FFFFFFFFFFFFFFFLL - 1LL) 214 #define CL_ULONG_MAX ((cl_ulong) 0xFFFFFFFFFFFFFFFFULL) 215 216 #define CL_FLT_DIG 6 217 #define CL_FLT_MANT_DIG 24 218 #define CL_FLT_MAX_10_EXP +38 219 #define CL_FLT_MAX_EXP +128 220 #define CL_FLT_MIN_10_EXP -37 221 #define CL_FLT_MIN_EXP -125 222 #define CL_FLT_RADIX 2 223 #define CL_FLT_MAX 0x1.fffffep127f 224 #define CL_FLT_MIN 0x1.0p-126f 225 #define CL_FLT_EPSILON 0x1.0p-23f 226 227 #define CL_DBL_DIG 15 228 #define CL_DBL_MANT_DIG 53 229 #define CL_DBL_MAX_10_EXP +308 230 #define CL_DBL_MAX_EXP +1024 231 #define CL_DBL_MIN_10_EXP -307 232 #define CL_DBL_MIN_EXP -1021 233 #define CL_DBL_RADIX 2 234 #define CL_DBL_MAX 0x1.fffffffffffffp1023 235 #define CL_DBL_MIN 0x1.0p-1022 236 #define CL_DBL_EPSILON 0x1.0p-52 237 238 /* There are no vector types for half */ 239 240 #ifdef __cplusplus 241 } 242 #endif 243 244 #endif // __CL_PLATFORM_H 245