• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2017 Google Inc.
3  *
4  * Use of this source code is governed by a BSD-style license that can
5  * be found in the LICENSE file.
6  *
7  */
8 
9 #ifndef SKC_ONCE_TYPES
10 #define SKC_ONCE_TYPES
11 
12 //
13 //
14 //
15 
16 #if !defined(__OPENCL_C_VERSION__)
17 
18 //
19 // What is going on here is that OpenCL defines both host and device
20 // scalar and vector types.
21 //
22 // Our actual device kernels should try to use native compiler types
23 // for anything that's private to the kernel and the skc_* variant for
24 // types and composites that get pulled into host code.
25 //
26 // I'm not excited about redefining all the basic types but this is a
27 // reasonable solution that allows the code to bridge the host (C/C++)
28 // and device (OpenCL) environments as well as provide vector types.
29 //
30 
31 #ifdef __APPLE__
32 #include "OpenCL/opencl.h"
33 #else
34 #include "CL/opencl.h"
35 #endif
36 
37 //
38 //
39 //
40 
41 #define SKC_TYPE_HELPER(t)  skc_##t
42 #define SKC_TYPE(t)         SKC_TYPE_HELPER(t)
43 
44 typedef cl_bool     skc_bool;
45 
46 typedef cl_char     skc_char;
47 typedef cl_char2    skc_char2;
48 typedef cl_char3    skc_char3;
49 typedef cl_char4    skc_char4;
50 typedef cl_char8    skc_char8;
51 typedef cl_char16   skc_char16;
52 
53 typedef cl_uchar    skc_uchar;
54 typedef cl_uchar2   skc_uchar2;
55 typedef cl_uchar3   skc_uchar3;
56 typedef cl_uchar4   skc_uchar4;
57 typedef cl_uchar8   skc_uchar8;
58 typedef cl_uchar16  skc_uchar16;
59 
60 typedef cl_short    skc_short;
61 typedef cl_short2   skc_short2;
62 typedef cl_short3   skc_short3;
63 typedef cl_short4   skc_short4;
64 typedef cl_short8   skc_short8;
65 typedef cl_short16  skc_short16;
66 
67 typedef cl_ushort   skc_ushort;
68 typedef cl_ushort2  skc_ushort2;
69 typedef cl_ushort3  skc_ushort3;
70 typedef cl_ushort4  skc_ushort4;
71 typedef cl_ushort8  skc_ushort8;
72 typedef cl_ushort16 skc_ushort16;
73 
74 typedef cl_int      skc_int;
75 typedef cl_int2     skc_int2;
76 typedef cl_int3     skc_int3;
77 typedef cl_int4     skc_int4;
78 typedef cl_int8     skc_int8;
79 typedef cl_int16    skc_int16;
80 
81 typedef cl_uint     skc_uint;
82 typedef cl_uint2    skc_uint2;
83 typedef cl_uint3    skc_uint3;
84 typedef cl_uint4    skc_uint4;
85 typedef cl_uint8    skc_uint8;
86 typedef cl_uint16   skc_uint16;
87 
88 typedef cl_ulong    skc_ulong;
89 typedef cl_ulong2   skc_ulong2;
90 typedef cl_ulong3   skc_ulong3;
91 typedef cl_ulong4   skc_ulong4;
92 typedef cl_ulong8   skc_ulong8;
93 typedef cl_ulong16  skc_ulong16;
94 
95 typedef cl_long     skc_long;
96 typedef cl_long2    skc_long2;
97 typedef cl_long3    skc_long3;
98 typedef cl_long4    skc_long4;
99 typedef cl_long8    skc_long8;
100 typedef cl_long16   skc_long16;
101 
102 typedef cl_float    skc_float;
103 typedef cl_float2   skc_float2;
104 typedef cl_float3   skc_float3;
105 typedef cl_float4   skc_float4;
106 typedef cl_float8   skc_float8;
107 typedef cl_float16  skc_float16;
108 
109 typedef cl_half     skc_half;
110 
111 #if defined(__CL_HALF2__)
112 typedef cl_half2    skc_half2;
113 #endif
114 #if defined(__CL_HALF4__)
115 typedef cl_half4    skc_half4;
116 #endif
117 #if defined(__CL_HALF8__)
118 typedef cl_half8    skc_half8;
119 #endif
120 #if defined(__CL_HALF16__)
121 typedef cl_half16   skc_half16;
122 #endif
123 
124 //
125 //
126 //
127 
128 #else
129 
130 //
131 //
132 //
133 
134 #define SKC_TYPE(t) t
135 
136 typedef bool        skc_bool;
137 
138 typedef char        skc_char;
139 typedef char2       skc_char2;
140 typedef char3       skc_char3;
141 typedef char4       skc_char4;
142 typedef char8       skc_char8;
143 typedef char16      skc_char16;
144 
145 typedef uchar       skc_uchar;
146 typedef uchar2      skc_uchar2;
147 typedef uchar3      skc_uchar3;
148 typedef uchar4      skc_uchar4;
149 typedef uchar8      skc_uchar8;
150 typedef uchar16     skc_uchar16;
151 
152 typedef short       skc_short;
153 typedef short2      skc_short2;
154 typedef short3      skc_short3;
155 typedef short4      skc_short4;
156 typedef short8      skc_short8;
157 typedef short16     skc_short16;
158 
159 typedef ushort      skc_ushort;
160 typedef ushort2     skc_ushort2;
161 typedef ushort3     skc_ushort3;
162 typedef ushort4     skc_ushort4;
163 typedef ushort8     skc_ushort8;
164 typedef ushort16    skc_ushort16;
165 
166 typedef int         skc_int;
167 typedef int2        skc_int2;
168 typedef int3        skc_int3;
169 typedef int4        skc_int4;
170 typedef int8        skc_int8;
171 typedef int16       skc_int16;
172 
173 typedef uint        skc_uint;
174 typedef uint2       skc_uint2;
175 typedef uint3       skc_uint3;
176 typedef uint4       skc_uint4;
177 typedef uint8       skc_uint8;
178 typedef uint16      skc_uint16;
179 
180 typedef ulong       skc_ulong;
181 typedef ulong2      skc_ulong2;
182 typedef ulong3      skc_ulong3;
183 typedef ulong4      skc_ulong4;
184 typedef ulong8      skc_ulong8;
185 typedef ulong16     skc_ulong16;
186 
187 typedef long        skc_long;
188 typedef long2       skc_long2;
189 typedef long3       skc_long3;
190 typedef long4       skc_long4;
191 typedef long8       skc_long8;
192 typedef long16      skc_long16;
193 
194 typedef float       skc_float;
195 typedef float2      skc_float2;
196 typedef float3      skc_float3;
197 typedef float4      skc_float4;
198 typedef float8      skc_float8;
199 typedef float16     skc_float16;
200 
201 typedef half        skc_half;
202 
203 #if defined(__CL_HALF2__)
204 typedef half2       skc_half2;
205 #endif
206 #if defined(__CL_HALF4__)
207 typedef half4       skc_half4;
208 #endif
209 #if defined(__CL_HALF8__)
210 typedef half8       skc_half8;
211 #endif
212 #if defined(__CL_HALF16__)
213 typedef half16      skc_half16;
214 #endif
215 
216 //
217 //
218 //
219 
220 #define SKC_AS_HELPER(t)              as_##t
221 #define SKC_AS(t)                     SKC_AS_HELPER(t)
222 
223 #define SKC_CONVERT_HELPER(t)         convert_##t
224 #define SKC_CONVERT(t)                SKC_CONVERT_HELPER(t)
225 
226 // mode is: sat, rte, rtz, rtp, rtn --or-- sat_rte, sat_rtz, etc.
227 #define SKC_CONVERT_MODE_HELPER(t,m)  convert_##t##_##m
228 #define SKC_CONVERT_MODE(t,m)         SKC_CONVERT_HELPER(t)
229 
230 //
231 //
232 //
233 
234 #endif
235 
236 //
237 //
238 //
239 
240 #define SKC_UCHAR_MAX    0xFF
241 
242 #define SKC_SHORT_MAX    0x7FFF
243 #define SKC_SHORT_MIN    (-SKC_SHORT_MAX - 1)
244 #define SKC_USHORT_MAX   0xFFFF
245 
246 #define SKC_INT_MAX      0x7FFFFFFF
247 #define SKC_INT_MIN      (-SKC_INT_MAX - 1)
248 #define SKC_UINT_MAX     0xFFFFFFFF
249 
250 #define SKC_ULONG_MAX    0xFFFFFFFFFFFFFFFFL
251 
252 //
253 //
254 //
255 
256 #endif
257 
258 //
259 //
260 //
261 
262