cl_platform.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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. #ifndef __CL_PLATFORM_H
  24. #define __CL_PLATFORM_H
  25. #define CL_PLATFORM_MINI_CL 0x12345
  26. struct MiniCLKernelDesc
  27. {
  28. MiniCLKernelDesc(void* pCode, const char* pName);
  29. };
  30. #define MINICL_REGISTER(__kernel_func) static MiniCLKernelDesc __kernel_func##Desc((void*)__kernel_func, #__kernel_func);
  31. #ifdef __APPLE__
  32. /* Contains #defines for AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER below */
  33. #include <AvailabilityMacros.h>
  34. #endif
  35. #ifdef __cplusplus
  36. extern "C" {
  37. #endif
  38. #define CL_API_ENTRY
  39. #define CL_API_CALL
  40. #ifdef __APPLE__
  41. #define CL_API_SUFFIX__VERSION_1_0 // AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER
  42. #define CL_EXTENSION_WEAK_LINK __attribute__((weak_import))
  43. #else
  44. #define CL_API_SUFFIX__VERSION_1_0
  45. #define CL_EXTENSION_WEAK_LINK
  46. #endif
  47. #if defined (_WIN32) && ! defined (__MINGW32__)
  48. typedef signed __int8 int8_t;
  49. typedef unsigned __int8 uint8_t;
  50. typedef signed __int16 int16_t;
  51. typedef unsigned __int16 uint16_t;
  52. typedef signed __int32 int32_t;
  53. typedef unsigned __int32 uint32_t;
  54. typedef signed __int64 int64_t;
  55. typedef unsigned __int64 uint64_t;
  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. typedef uint16_t cl_half ;
  65. typedef float cl_float ;
  66. typedef double cl_double ;
  67. typedef int8_t cl_char2[2] ;
  68. typedef int8_t cl_char4[4] ;
  69. typedef int8_t cl_char8[8] ;
  70. typedef int8_t cl_char16[16] ;
  71. typedef uint8_t cl_uchar2[2] ;
  72. typedef uint8_t cl_uchar4[4] ;
  73. typedef uint8_t cl_uchar8[8] ;
  74. typedef uint8_t cl_uchar16[16] ;
  75. typedef int16_t cl_short2[2] ;
  76. typedef int16_t cl_short4[4] ;
  77. typedef int16_t cl_short8[8] ;
  78. typedef int16_t cl_short16[16] ;
  79. typedef uint16_t cl_ushort2[2] ;
  80. typedef uint16_t cl_ushort4[4] ;
  81. typedef uint16_t cl_ushort8[8] ;
  82. typedef uint16_t cl_ushort16[16] ;
  83. typedef int32_t cl_int2[2] ;
  84. typedef int32_t cl_int4[4] ;
  85. typedef int32_t cl_int8[8] ;
  86. typedef int32_t cl_int16[16] ;
  87. typedef uint32_t cl_uint2[2] ;
  88. typedef uint32_t cl_uint4[4] ;
  89. typedef uint32_t cl_uint8[8] ;
  90. typedef uint32_t cl_uint16[16] ;
  91. typedef int64_t cl_long2[2] ;
  92. typedef int64_t cl_long4[4] ;
  93. typedef int64_t cl_long8[8] ;
  94. typedef int64_t cl_long16[16] ;
  95. typedef uint64_t cl_ulong2[2] ;
  96. typedef uint64_t cl_ulong4[4] ;
  97. typedef uint64_t cl_ulong8[8] ;
  98. typedef uint64_t cl_ulong16[16] ;
  99. typedef float cl_float2[2] ;
  100. typedef float cl_float4[4] ;
  101. typedef float cl_float8[8] ;
  102. typedef float cl_float16[16] ;
  103. typedef double cl_double2[2] ;
  104. typedef double cl_double4[4] ;
  105. typedef double cl_double8[8] ;
  106. typedef double cl_double16[16] ;
  107. #else
  108. #include <stdint.h>
  109. /* scalar types */
  110. typedef int8_t cl_char;
  111. typedef uint8_t cl_uchar;
  112. typedef int16_t cl_short __attribute__((aligned(2)));
  113. typedef uint16_t cl_ushort __attribute__((aligned(2)));
  114. typedef int32_t cl_int __attribute__((aligned(4)));
  115. typedef uint32_t cl_uint __attribute__((aligned(4)));
  116. typedef int64_t cl_long __attribute__((aligned(8)));
  117. typedef uint64_t cl_ulong __attribute__((aligned(8)));
  118. typedef uint16_t cl_half __attribute__((aligned(2)));
  119. typedef float cl_float __attribute__((aligned(4)));
  120. typedef double cl_double __attribute__((aligned(8)));
  121. /*
  122. * Vector types
  123. *
  124. * Note: OpenCL requires that all types be naturally aligned.
  125. * This means that vector types must be naturally aligned.
  126. * For example, a vector of four floats must be aligned to
  127. * a 16 byte boundary (calculated as 4 * the natural 4-byte
  128. * alignment of the float). The alignment qualifiers here
  129. * will only function properly if your compiler supports them
  130. * and if you don't actively work to defeat them. For example,
  131. * in order for a cl_float4 to be 16 byte aligned in a struct,
  132. * the start of the struct must itself be 16-byte aligned.
  133. *
  134. * Maintaining proper alignment is the user's responsibility.
  135. */
  136. typedef int8_t cl_char2[2] __attribute__((aligned(2)));
  137. typedef int8_t cl_char4[4] __attribute__((aligned(4)));
  138. typedef int8_t cl_char8[8] __attribute__((aligned(8)));
  139. typedef int8_t cl_char16[16] __attribute__((aligned(16)));
  140. typedef uint8_t cl_uchar2[2] __attribute__((aligned(2)));
  141. typedef uint8_t cl_uchar4[4] __attribute__((aligned(4)));
  142. typedef uint8_t cl_uchar8[8] __attribute__((aligned(8)));
  143. typedef uint8_t cl_uchar16[16] __attribute__((aligned(16)));
  144. typedef int16_t cl_short2[2] __attribute__((aligned(4)));
  145. typedef int16_t cl_short4[4] __attribute__((aligned(8)));
  146. typedef int16_t cl_short8[8] __attribute__((aligned(16)));
  147. typedef int16_t cl_short16[16] __attribute__((aligned(32)));
  148. typedef uint16_t cl_ushort2[2] __attribute__((aligned(4)));
  149. typedef uint16_t cl_ushort4[4] __attribute__((aligned(8)));
  150. typedef uint16_t cl_ushort8[8] __attribute__((aligned(16)));
  151. typedef uint16_t cl_ushort16[16] __attribute__((aligned(32)));
  152. typedef int32_t cl_int2[2] __attribute__((aligned(8)));
  153. typedef int32_t cl_int4[4] __attribute__((aligned(16)));
  154. typedef int32_t cl_int8[8] __attribute__((aligned(32)));
  155. typedef int32_t cl_int16[16] __attribute__((aligned(64)));
  156. typedef uint32_t cl_uint2[2] __attribute__((aligned(8)));
  157. typedef uint32_t cl_uint4[4] __attribute__((aligned(16)));
  158. typedef uint32_t cl_uint8[8] __attribute__((aligned(32)));
  159. typedef uint32_t cl_uint16[16] __attribute__((aligned(64)));
  160. typedef int64_t cl_long2[2] __attribute__((aligned(16)));
  161. typedef int64_t cl_long4[4] __attribute__((aligned(32)));
  162. typedef int64_t cl_long8[8] __attribute__((aligned(64)));
  163. typedef int64_t cl_long16[16] __attribute__((aligned(128)));
  164. typedef uint64_t cl_ulong2[2] __attribute__((aligned(16)));
  165. typedef uint64_t cl_ulong4[4] __attribute__((aligned(32)));
  166. typedef uint64_t cl_ulong8[8] __attribute__((aligned(64)));
  167. typedef uint64_t cl_ulong16[16] __attribute__((aligned(128)));
  168. typedef float cl_float2[2] __attribute__((aligned(8)));
  169. typedef float cl_float4[4] __attribute__((aligned(16)));
  170. typedef float cl_float8[8] __attribute__((aligned(32)));
  171. typedef float cl_float16[16] __attribute__((aligned(64)));
  172. typedef double cl_double2[2] __attribute__((aligned(16)));
  173. typedef double cl_double4[4] __attribute__((aligned(32)));
  174. typedef double cl_double8[8] __attribute__((aligned(64)));
  175. typedef double cl_double16[16] __attribute__((aligned(128)));
  176. #endif
  177. #include <stddef.h>
  178. /* and a few goodies to go with them */
  179. #define CL_CHAR_BIT 8
  180. #define CL_SCHAR_MAX 127
  181. #define CL_SCHAR_MIN (-127-1)
  182. #define CL_CHAR_MAX CL_SCHAR_MAX
  183. #define CL_CHAR_MIN CL_SCHAR_MIN
  184. #define CL_UCHAR_MAX 255
  185. #define CL_SHRT_MAX 32767
  186. #define CL_SHRT_MIN (-32767-1)
  187. #define CL_USHRT_MAX 65535
  188. #define CL_INT_MAX 2147483647
  189. #define CL_INT_MIN (-2147483647-1)
  190. #define CL_UINT_MAX 0xffffffffU
  191. #define CL_LONG_MAX ((cl_long) 0x7FFFFFFFFFFFFFFFLL)
  192. #define CL_LONG_MIN ((cl_long) -0x7FFFFFFFFFFFFFFFLL - 1LL)
  193. #define CL_ULONG_MAX ((cl_ulong) 0xFFFFFFFFFFFFFFFFULL)
  194. #define CL_FLT_DIG 6
  195. #define CL_FLT_MANT_DIG 24
  196. #define CL_FLT_MAX_10_EXP +38
  197. #define CL_FLT_MAX_EXP +128
  198. #define CL_FLT_MIN_10_EXP -37
  199. #define CL_FLT_MIN_EXP -125
  200. #define CL_FLT_RADIX 2
  201. #define CL_FLT_MAX 0x1.fffffep127f
  202. #define CL_FLT_MIN 0x1.0p-126f
  203. #define CL_FLT_EPSILON 0x1.0p-23f
  204. #define CL_DBL_DIG 15
  205. #define CL_DBL_MANT_DIG 53
  206. #define CL_DBL_MAX_10_EXP +308
  207. #define CL_DBL_MAX_EXP +1024
  208. #define CL_DBL_MIN_10_EXP -307
  209. #define CL_DBL_MIN_EXP -1021
  210. #define CL_DBL_RADIX 2
  211. #define CL_DBL_MAX 0x1.fffffffffffffp1023
  212. #define CL_DBL_MIN 0x1.0p-1022
  213. #define CL_DBL_EPSILON 0x1.0p-52
  214. /* There are no vector types for half */
  215. #ifdef __cplusplus
  216. }
  217. #endif
  218. #endif // __CL_PLATFORM_H