HIP: Heterogenous-computing Interface for Portability
channel_descriptor.h
1 /*
2 Copyright (c) 2015 - present Advanced Micro Devices, Inc. All rights reserved.
3 
4 Permission is hereby granted, free of charge, to any person obtaining a copy
5 of this software and associated documentation files (the "Software"), to deal
6 in the Software without restriction, including without limitation the rights
7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 copies of the Software, and to permit persons to whom the Software is
9 furnished to do so, subject to the following conditions:
10 
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
13 
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 THE SOFTWARE.
21 */
22 
23 #ifndef HIP_INCLUDE_HIP_HCC_DETAIL_CHANNEL_DESCRIPTOR_H
24 #define HIP_INCLUDE_HIP_HCC_DETAIL_CHANNEL_DESCRIPTOR_H
25 
26 #include <hip/hcc_detail/driver_types.h>
28 
29 #ifdef __cplusplus
30 
31 hipChannelFormatDesc hipCreateChannelDesc(int x, int y, int z, int w, hipChannelFormatKind f);
32 
33 static inline hipChannelFormatDesc hipCreateChannelDescHalf() {
34  int e = (int)sizeof(unsigned short) * 8;
35  return hipCreateChannelDesc(e, 0, 0, 0, hipChannelFormatKindFloat);
36 }
37 
38 static inline hipChannelFormatDesc hipCreateChannelDescHalf1() {
39  int e = (int)sizeof(unsigned short) * 8;
40  return hipCreateChannelDesc(e, 0, 0, 0, hipChannelFormatKindFloat);
41 }
42 
43 static inline hipChannelFormatDesc hipCreateChannelDescHalf2() {
44  int e = (int)sizeof(unsigned short) * 8;
45  return hipCreateChannelDesc(e, 0, 0, 0, hipChannelFormatKindFloat);
46 }
47 
48 template <typename T>
49 static inline hipChannelFormatDesc hipCreateChannelDesc() {
50  return hipCreateChannelDesc(0, 0, 0, 0, hipChannelFormatKindNone);
51 }
52 
53 template <>
54 inline hipChannelFormatDesc hipCreateChannelDesc<char>() {
55  int e = (int)sizeof(char) * 8;
56  return hipCreateChannelDesc(e, 0, 0, 0, hipChannelFormatKindSigned);
57 }
58 
59 template <>
60 inline hipChannelFormatDesc hipCreateChannelDesc<signed char>() {
61  int e = (int)sizeof(signed char) * 8;
62  return hipCreateChannelDesc(e, 0, 0, 0, hipChannelFormatKindUnsigned);
63 }
64 
65 template <>
66 inline hipChannelFormatDesc hipCreateChannelDesc<unsigned char>() {
67  int e = (int)sizeof(unsigned char) * 8;
68  return hipCreateChannelDesc(e, 0, 0, 0, hipChannelFormatKindUnsigned);
69 }
70 
71 template <>
72 inline hipChannelFormatDesc hipCreateChannelDesc<uchar1>() {
73  int e = (int)sizeof(unsigned char) * 8;
74  return hipCreateChannelDesc(e, 0, 0, 0, hipChannelFormatKindSigned);
75 }
76 
77 template <>
78 inline hipChannelFormatDesc hipCreateChannelDesc<char1>() {
79  int e = (int)sizeof(signed char) * 8;
80  return hipCreateChannelDesc(e, 0, 0, 0, hipChannelFormatKindSigned);
81 }
82 
83 template <>
84 inline hipChannelFormatDesc hipCreateChannelDesc<uchar2>() {
85  int e = (int)sizeof(unsigned char) * 8;
86  return hipCreateChannelDesc(e, e, 0, 0, hipChannelFormatKindSigned);
87 }
88 
89 template <>
90 inline hipChannelFormatDesc hipCreateChannelDesc<char2>() {
91  int e = (int)sizeof(signed char) * 8;
92  return hipCreateChannelDesc(e, e, 0, 0, hipChannelFormatKindSigned);
93 }
94 
95 #ifndef __GNUC__ // vector3 is the same as vector4
96 template <>
97 inline hipChannelFormatDesc hipCreateChannelDesc<uchar3>() {
98  int e = (int)sizeof(unsigned char) * 8;
99  return hipCreateChannelDesc(e, e, e, 0, hipChannelFormatKindSigned);
100 }
101 
102 template <>
103 inline hipChannelFormatDesc hipCreateChannelDesc<char3>() {
104  int e = (int)sizeof(signed char) * 8;
105  return hipCreateChannelDesc(e, e, e, 0, hipChannelFormatKindSigned);
106 }
107 #endif
108 
109 template <>
110 inline hipChannelFormatDesc hipCreateChannelDesc<uchar4>() {
111  int e = (int)sizeof(unsigned char) * 8;
112  return hipCreateChannelDesc(e, e, e, e, hipChannelFormatKindSigned);
113 }
114 
115 template <>
116 inline hipChannelFormatDesc hipCreateChannelDesc<char4>() {
117  int e = (int)sizeof(signed char) * 8;
118  return hipCreateChannelDesc(e, e, e, e, hipChannelFormatKindSigned);
119 }
120 
121 template <>
122 inline hipChannelFormatDesc hipCreateChannelDesc<unsigned short>() {
123  int e = (int)sizeof(unsigned short) * 8;
124  return hipCreateChannelDesc(e, 0, 0, 0, hipChannelFormatKindUnsigned);
125 }
126 
127 template <>
128 inline hipChannelFormatDesc hipCreateChannelDesc<signed short>() {
129  int e = (int)sizeof(signed short) * 8;
130  return hipCreateChannelDesc(e, 0, 0, 0, hipChannelFormatKindSigned);
131 }
132 
133 template <>
134 inline hipChannelFormatDesc hipCreateChannelDesc<ushort1>() {
135  int e = (int)sizeof(unsigned short) * 8;
136  return hipCreateChannelDesc(e, 0, 0, 0, hipChannelFormatKindUnsigned);
137 }
138 
139 template <>
140 inline hipChannelFormatDesc hipCreateChannelDesc<short1>() {
141  int e = (int)sizeof(signed short) * 8;
142  return hipCreateChannelDesc(e, 0, 0, 0, hipChannelFormatKindSigned);
143 }
144 
145 template <>
146 inline hipChannelFormatDesc hipCreateChannelDesc<ushort2>() {
147  int e = (int)sizeof(unsigned short) * 8;
148  return hipCreateChannelDesc(e, e, 0, 0, hipChannelFormatKindUnsigned);
149 }
150 
151 template <>
152 inline hipChannelFormatDesc hipCreateChannelDesc<short2>() {
153  int e = (int)sizeof(signed short) * 8;
154  return hipCreateChannelDesc(e, e, 0, 0, hipChannelFormatKindSigned);
155 }
156 
157 #ifndef __GNUC__
158 template <>
159 inline hipChannelFormatDesc hipCreateChannelDesc<ushort3>() {
160  int e = (int)sizeof(unsigned short) * 8;
161  return hipCreateChannelDesc(e, e, e, 0, hipChannelFormatKindUnsigned);
162 }
163 
164 template <>
165 inline hipChannelFormatDesc hipCreateChannelDesc<short3>() {
166  int e = (int)sizeof(signed short) * 8;
167  return hipCreateChannelDesc(e, e, e, 0, hipChannelFormatKindSigned);
168 }
169 #endif
170 
171 template <>
172 inline hipChannelFormatDesc hipCreateChannelDesc<ushort4>() {
173  int e = (int)sizeof(unsigned short) * 8;
174  return hipCreateChannelDesc(e, e, e, e, hipChannelFormatKindUnsigned);
175 }
176 
177 template <>
178 inline hipChannelFormatDesc hipCreateChannelDesc<short4>() {
179  int e = (int)sizeof(signed short) * 8;
180  return hipCreateChannelDesc(e, e, e, e, hipChannelFormatKindSigned);
181 }
182 
183 template <>
184 inline hipChannelFormatDesc hipCreateChannelDesc<unsigned int>() {
185  int e = (int)sizeof(unsigned int) * 8;
186  return hipCreateChannelDesc(e, 0, 0, 0, hipChannelFormatKindUnsigned);
187 }
188 
189 template <>
190 inline hipChannelFormatDesc hipCreateChannelDesc<signed int>() {
191  int e = (int)sizeof(signed int) * 8;
192  return hipCreateChannelDesc(e, 0, 0, 0, hipChannelFormatKindSigned);
193 }
194 
195 template <>
196 inline hipChannelFormatDesc hipCreateChannelDesc<uint1>() {
197  int e = (int)sizeof(unsigned int) * 8;
198  return hipCreateChannelDesc(e, 0, 0, 0, hipChannelFormatKindUnsigned);
199 }
200 
201 template <>
202 inline hipChannelFormatDesc hipCreateChannelDesc<int1>() {
203  int e = (int)sizeof(signed int) * 8;
204  return hipCreateChannelDesc(e, 0, 0, 0, hipChannelFormatKindSigned);
205 }
206 
207 template <>
208 inline hipChannelFormatDesc hipCreateChannelDesc<uint2>() {
209  int e = (int)sizeof(unsigned int) * 8;
210  return hipCreateChannelDesc(e, e, 0, 0, hipChannelFormatKindUnsigned);
211 }
212 
213 template <>
214 inline hipChannelFormatDesc hipCreateChannelDesc<int2>() {
215  int e = (int)sizeof(signed int) * 8;
216  return hipCreateChannelDesc(e, e, 0, 0, hipChannelFormatKindSigned);
217 }
218 
219 #ifndef __GNUC__
220 template <>
221 inline hipChannelFormatDesc hipCreateChannelDesc<uint3>() {
222  int e = (int)sizeof(unsigned int) * 8;
223  return hipCreateChannelDesc(e, e, e, 0, hipChannelFormatKindUnsigned);
224 }
225 
226 template <>
227 inline hipChannelFormatDesc hipCreateChannelDesc<int3>() {
228  int e = (int)sizeof(signed int) * 8;
229  return hipCreateChannelDesc(e, e, e, 0, hipChannelFormatKindSigned);
230 }
231 #endif
232 
233 template <>
234 inline hipChannelFormatDesc hipCreateChannelDesc<uint4>() {
235  int e = (int)sizeof(unsigned int) * 8;
236  return hipCreateChannelDesc(e, e, e, e, hipChannelFormatKindUnsigned);
237 }
238 
239 template <>
240 inline hipChannelFormatDesc hipCreateChannelDesc<int4>() {
241  int e = (int)sizeof(signed int) * 8;
242  return hipCreateChannelDesc(e, e, e, e, hipChannelFormatKindSigned);
243 }
244 
245 template <>
246 inline hipChannelFormatDesc hipCreateChannelDesc<float>() {
247  int e = (int)sizeof(float) * 8;
248  return hipCreateChannelDesc(e, 0, 0, 0, hipChannelFormatKindFloat);
249 }
250 
251 template <>
252 inline hipChannelFormatDesc hipCreateChannelDesc<float1>() {
253  int e = (int)sizeof(float) * 8;
254  return hipCreateChannelDesc(e, 0, 0, 0, hipChannelFormatKindFloat);
255 }
256 
257 template <>
258 inline hipChannelFormatDesc hipCreateChannelDesc<float2>() {
259  int e = (int)sizeof(float) * 8;
260  return hipCreateChannelDesc(e, e, 0, 0, hipChannelFormatKindFloat);
261 }
262 
263 #ifndef __GNUC__
264 template <>
265 inline hipChannelFormatDesc hipCreateChannelDesc<float3>() {
266  int e = (int)sizeof(float) * 8;
267  return hipCreateChannelDesc(e, e, e, 0, hipChannelFormatKindFloat);
268 }
269 #endif
270 
271 template <>
272 inline hipChannelFormatDesc hipCreateChannelDesc<float4>() {
273  int e = (int)sizeof(float) * 8;
274  return hipCreateChannelDesc(e, e, e, e, hipChannelFormatKindFloat);
275 }
276 
277 template <>
278 inline hipChannelFormatDesc hipCreateChannelDesc<unsigned long>() {
279  int e = (int)sizeof(unsigned long) * 8;
280  return hipCreateChannelDesc(e, 0, 0, 0, hipChannelFormatKindUnsigned);
281 }
282 
283 template <>
284 inline hipChannelFormatDesc hipCreateChannelDesc<signed long>() {
285  int e = (int)sizeof(signed long) * 8;
286  return hipCreateChannelDesc(e, 0, 0, 0, hipChannelFormatKindSigned);
287 }
288 
289 template <>
290 inline hipChannelFormatDesc hipCreateChannelDesc<ulong1>() {
291  int e = (int)sizeof(unsigned long) * 8;
292  return hipCreateChannelDesc(e, 0, 0, 0, hipChannelFormatKindUnsigned);
293 }
294 
295 template <>
296 inline hipChannelFormatDesc hipCreateChannelDesc<long1>() {
297  int e = (int)sizeof(signed long) * 8;
298  return hipCreateChannelDesc(e, 0, 0, 0, hipChannelFormatKindSigned);
299 }
300 
301 template <>
302 inline hipChannelFormatDesc hipCreateChannelDesc<ulong2>() {
303  int e = (int)sizeof(unsigned long) * 8;
304  return hipCreateChannelDesc(e, e, 0, 0, hipChannelFormatKindUnsigned);
305 }
306 
307 template <>
308 inline hipChannelFormatDesc hipCreateChannelDesc<long2>() {
309  int e = (int)sizeof(signed long) * 8;
310  return hipCreateChannelDesc(e, e, 0, 0, hipChannelFormatKindSigned);
311 }
312 
313 #ifndef __GNUC__
314 template <>
315 inline hipChannelFormatDesc hipCreateChannelDesc<ulong3>() {
316  int e = (int)sizeof(unsigned long) * 8;
317  return hipCreateChannelDesc(e, e, e, 0, hipChannelFormatKindUnsigned);
318 }
319 
320 template <>
321 inline hipChannelFormatDesc hipCreateChannelDesc<long3>() {
322  int e = (int)sizeof(signed long) * 8;
323  return hipCreateChannelDesc(e, e, e, 0, hipChannelFormatKindSigned);
324 }
325 #endif
326 
327 template <>
328 inline hipChannelFormatDesc hipCreateChannelDesc<ulong4>() {
329  int e = (int)sizeof(unsigned long) * 8;
330  return hipCreateChannelDesc(e, e, e, e, hipChannelFormatKindUnsigned);
331 }
332 
333 template <>
334 inline hipChannelFormatDesc hipCreateChannelDesc<long4>() {
335  int e = (int)sizeof(signed long) * 8;
336  return hipCreateChannelDesc(e, e, e, e, hipChannelFormatKindSigned);
337 }
338 
339 #else
340 
341 struct hipChannelFormatDesc hipCreateChannelDesc(int x, int y, int z, int w,
342  enum hipChannelFormatKind f);
343 
344 #endif
345 
346 #endif
Defines the different newt vector types for HIP runtime.
Definition: driver_types.h:38