cl_platform.h

Go to the documentation of this file.
00001 /**********************************************************************************
00002  * Copyright (c) 2008-2009 The Khronos Group Inc.
00003  *
00004  * Permission is hereby granted, free of charge, to any person obtaining a
00005  * copy of this software and/or associated documentation files (the
00006  * "Materials"), to deal in the Materials without restriction, including
00007  * without limitation the rights to use, copy, modify, merge, publish,
00008  * distribute, sublicense, and/or sell copies of the Materials, and to
00009  * permit persons to whom the Materials are furnished to do so, subject to
00010  * the following conditions:
00011  *
00012  * The above copyright notice and this permission notice shall be included
00013  * in all copies or substantial portions of the Materials.
00014  *
00015  * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00016  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00017  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
00018  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
00019  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
00020  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
00021  * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
00022  **********************************************************************************/
00023 
00024 #ifndef __CL_PLATFORM_H
00025 #define __CL_PLATFORM_H
00026 
00027 #define CL_PLATFORM_MINI_CL  0x12345
00028 
00029 struct MiniCLKernelDesc
00030 {
00031         MiniCLKernelDesc(void* pCode, const char* pName);
00032 };
00033 
00034 #define MINICL_REGISTER(__kernel_func) static MiniCLKernelDesc __kernel_func##Desc((void*)__kernel_func, #__kernel_func);
00035 
00036 
00037 #ifdef __APPLE__
00038     /* Contains #defines for AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER below */
00039     #include <AvailabilityMacros.h>
00040 #endif
00041 
00042 #ifdef __cplusplus
00043 extern "C" {
00044 #endif
00045 
00046 #define CL_API_ENTRY
00047 #define CL_API_CALL
00048 #ifdef __APPLE__
00049 #define CL_API_SUFFIX__VERSION_1_0 //  AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER
00050 #define CL_EXTENSION_WEAK_LINK       __attribute__((weak_import))       
00051 #else
00052 #define CL_API_SUFFIX__VERSION_1_0
00053 #define CL_EXTENSION_WEAK_LINK                         
00054 #endif
00055 
00056 #if defined (_WIN32) && ! defined (__MINGW32__)
00057 typedef signed   __int8  int8_t;
00058 typedef unsigned __int8  uint8_t;
00059 typedef signed   __int16 int16_t;
00060 typedef unsigned __int16 uint16_t;
00061 typedef signed   __int32 int32_t;
00062 typedef unsigned __int32 uint32_t;
00063 typedef signed   __int64 int64_t;
00064 typedef unsigned __int64 uint64_t;
00065 
00066 typedef int8_t          cl_char;
00067 typedef uint8_t         cl_uchar;
00068 typedef int16_t         cl_short    ;
00069 typedef uint16_t        cl_ushort   ;
00070 typedef int32_t         cl_int      ;
00071 typedef uint32_t        cl_uint     ;
00072 typedef int64_t         cl_long     ;
00073 typedef uint64_t        cl_ulong    ;
00074 
00075 typedef uint16_t        cl_half     ;
00076 typedef float           cl_float    ;
00077 typedef double          cl_double   ;
00078 
00079 
00080 typedef int8_t          cl_char2[2]     ;
00081 typedef int8_t          cl_char4[4]     ;
00082 typedef int8_t          cl_char8[8]     ;
00083 typedef int8_t          cl_char16[16]   ;
00084 typedef uint8_t         cl_uchar2[2]    ;
00085 typedef uint8_t         cl_uchar4[4]    ;
00086 typedef uint8_t         cl_uchar8[8]    ;
00087 typedef uint8_t         cl_uchar16[16]  ;
00088 
00089 typedef int16_t         cl_short2[2]     ;
00090 typedef int16_t         cl_short4[4]     ;
00091 typedef int16_t         cl_short8[8]     ;
00092 typedef int16_t         cl_short16[16]   ;
00093 typedef uint16_t        cl_ushort2[2]    ;
00094 typedef uint16_t        cl_ushort4[4]    ;
00095 typedef uint16_t        cl_ushort8[8]    ;
00096 typedef uint16_t        cl_ushort16[16]  ;
00097 
00098 typedef int32_t         cl_int2[2]     ;
00099 typedef int32_t         cl_int4[4]     ;
00100 typedef int32_t         cl_int8[8]     ;
00101 typedef int32_t         cl_int16[16]    ;
00102 typedef uint32_t        cl_uint2[2]     ;
00103 typedef uint32_t        cl_uint4[4]     ;
00104 typedef uint32_t        cl_uint8[8]     ;
00105 typedef uint32_t        cl_uint16[16]   ;
00106 
00107 typedef int64_t         cl_long2[2]     ;
00108 typedef int64_t         cl_long4[4]     ;
00109 typedef int64_t         cl_long8[8]     ;
00110 typedef int64_t         cl_long16[16]   ;
00111 typedef uint64_t        cl_ulong2[2]    ;
00112 typedef uint64_t        cl_ulong4[4]    ;
00113 typedef uint64_t        cl_ulong8[8]    ;
00114 typedef uint64_t        cl_ulong16[16]  ;
00115 
00116 typedef float           cl_float2[2]    ;
00117 typedef float           cl_float4[4]    ;
00118 typedef float           cl_float8[8]    ;
00119 typedef float           cl_float16[16]  ;
00120 
00121 typedef double          cl_double2[2]   ;
00122 typedef double          cl_double4[4]   ;
00123 typedef double          cl_double8[8]   ;
00124 typedef double          cl_double16[16] ;
00125 
00126 
00127 #else
00128 #include <stdint.h>
00129 
00130 /* scalar types  */
00131 typedef int8_t          cl_char;
00132 typedef uint8_t         cl_uchar;
00133 typedef int16_t         cl_short    __attribute__((aligned(2)));
00134 typedef uint16_t        cl_ushort   __attribute__((aligned(2)));
00135 typedef int32_t         cl_int      __attribute__((aligned(4)));
00136 typedef uint32_t        cl_uint     __attribute__((aligned(4)));
00137 typedef int64_t         cl_long     __attribute__((aligned(8)));
00138 typedef uint64_t        cl_ulong    __attribute__((aligned(8)));
00139 
00140 typedef uint16_t        cl_half     __attribute__((aligned(2)));
00141 typedef float           cl_float    __attribute__((aligned(4)));
00142 typedef double          cl_double   __attribute__((aligned(8)));
00143 
00144 
00145 /*
00146  * Vector types 
00147  *
00148  *  Note:   OpenCL requires that all types be naturally aligned. 
00149  *          This means that vector types must be naturally aligned.
00150  *          For example, a vector of four floats must be aligned to
00151  *          a 16 byte boundary (calculated as 4 * the natural 4-byte 
00152  *          alignment of the float).  The alignment qualifiers here
00153  *          will only function properly if your compiler supports them
00154  *          and if you don't actively work to defeat them.  For example,
00155  *          in order for a cl_float4 to be 16 byte aligned in a struct,
00156  *          the start of the struct must itself be 16-byte aligned. 
00157  *
00158  *          Maintaining proper alignment is the user's responsibility.
00159  */
00160 typedef int8_t          cl_char2[2]     __attribute__((aligned(2)));
00161 typedef int8_t          cl_char4[4]     __attribute__((aligned(4)));
00162 typedef int8_t          cl_char8[8]     __attribute__((aligned(8)));
00163 typedef int8_t          cl_char16[16]   __attribute__((aligned(16)));
00164 typedef uint8_t         cl_uchar2[2]    __attribute__((aligned(2)));
00165 typedef uint8_t         cl_uchar4[4]    __attribute__((aligned(4)));
00166 typedef uint8_t         cl_uchar8[8]    __attribute__((aligned(8)));
00167 typedef uint8_t         cl_uchar16[16]  __attribute__((aligned(16)));
00168 
00169 typedef int16_t         cl_short2[2]     __attribute__((aligned(4)));
00170 typedef int16_t         cl_short4[4]     __attribute__((aligned(8)));
00171 typedef int16_t         cl_short8[8]     __attribute__((aligned(16)));
00172 typedef int16_t         cl_short16[16]   __attribute__((aligned(32)));
00173 typedef uint16_t        cl_ushort2[2]    __attribute__((aligned(4)));
00174 typedef uint16_t        cl_ushort4[4]    __attribute__((aligned(8)));
00175 typedef uint16_t        cl_ushort8[8]    __attribute__((aligned(16)));
00176 typedef uint16_t        cl_ushort16[16]  __attribute__((aligned(32)));
00177 
00178 typedef int32_t         cl_int2[2]      __attribute__((aligned(8)));
00179 typedef int32_t         cl_int4[4]      __attribute__((aligned(16)));
00180 typedef int32_t         cl_int8[8]      __attribute__((aligned(32)));
00181 typedef int32_t         cl_int16[16]    __attribute__((aligned(64)));
00182 typedef uint32_t        cl_uint2[2]     __attribute__((aligned(8)));
00183 typedef uint32_t        cl_uint4[4]     __attribute__((aligned(16)));
00184 typedef uint32_t        cl_uint8[8]     __attribute__((aligned(32)));
00185 typedef uint32_t        cl_uint16[16]   __attribute__((aligned(64)));
00186 
00187 typedef int64_t         cl_long2[2]     __attribute__((aligned(16)));
00188 typedef int64_t         cl_long4[4]     __attribute__((aligned(32)));
00189 typedef int64_t         cl_long8[8]     __attribute__((aligned(64)));
00190 typedef int64_t         cl_long16[16]   __attribute__((aligned(128)));
00191 typedef uint64_t        cl_ulong2[2]    __attribute__((aligned(16)));
00192 typedef uint64_t        cl_ulong4[4]    __attribute__((aligned(32)));
00193 typedef uint64_t        cl_ulong8[8]    __attribute__((aligned(64)));
00194 typedef uint64_t        cl_ulong16[16]  __attribute__((aligned(128)));
00195 
00196 typedef float           cl_float2[2]    __attribute__((aligned(8)));
00197 typedef float           cl_float4[4]    __attribute__((aligned(16)));
00198 typedef float           cl_float8[8]    __attribute__((aligned(32)));
00199 typedef float           cl_float16[16]  __attribute__((aligned(64)));
00200 
00201 typedef double          cl_double2[2]   __attribute__((aligned(16)));
00202 typedef double          cl_double4[4]   __attribute__((aligned(32)));
00203 typedef double          cl_double8[8]   __attribute__((aligned(64)));
00204 typedef double          cl_double16[16] __attribute__((aligned(128)));
00205 #endif
00206 
00207 #include <stddef.h>
00208 
00209 /* and a few goodies to go with them */
00210 #define CL_CHAR_BIT         8
00211 #define CL_SCHAR_MAX        127
00212 #define CL_SCHAR_MIN        (-127-1)
00213 #define CL_CHAR_MAX         CL_SCHAR_MAX
00214 #define CL_CHAR_MIN         CL_SCHAR_MIN
00215 #define CL_UCHAR_MAX        255
00216 #define CL_SHRT_MAX         32767
00217 #define CL_SHRT_MIN         (-32767-1)
00218 #define CL_USHRT_MAX        65535
00219 #define CL_INT_MAX          2147483647
00220 #define CL_INT_MIN          (-2147483647-1)
00221 #define CL_UINT_MAX         0xffffffffU
00222 #define CL_LONG_MAX         ((cl_long) 0x7FFFFFFFFFFFFFFFLL)
00223 #define CL_LONG_MIN         ((cl_long) -0x7FFFFFFFFFFFFFFFLL - 1LL)
00224 #define CL_ULONG_MAX        ((cl_ulong) 0xFFFFFFFFFFFFFFFFULL)
00225 
00226 #define CL_FLT_DIG          6
00227 #define CL_FLT_MANT_DIG     24
00228 #define CL_FLT_MAX_10_EXP   +38
00229 #define CL_FLT_MAX_EXP      +128
00230 #define CL_FLT_MIN_10_EXP   -37
00231 #define CL_FLT_MIN_EXP      -125
00232 #define CL_FLT_RADIX        2
00233 #define CL_FLT_MAX          0x1.fffffep127f
00234 #define CL_FLT_MIN          0x1.0p-126f
00235 #define CL_FLT_EPSILON      0x1.0p-23f
00236 
00237 #define CL_DBL_DIG          15
00238 #define CL_DBL_MANT_DIG     53
00239 #define CL_DBL_MAX_10_EXP   +308
00240 #define CL_DBL_MAX_EXP      +1024
00241 #define CL_DBL_MIN_10_EXP   -307
00242 #define CL_DBL_MIN_EXP      -1021
00243 #define CL_DBL_RADIX        2
00244 #define CL_DBL_MAX          0x1.fffffffffffffp1023
00245 #define CL_DBL_MIN          0x1.0p-1022
00246 #define CL_DBL_EPSILON      0x1.0p-52
00247 
00248 /* There are no vector types for half */
00249 
00250 #ifdef __cplusplus
00251 }
00252 #endif
00253 
00254 #endif  // __CL_PLATFORM_H