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/hip_common.h>
27 #include <hip/hcc_detail/driver_types.h>
29 
30 #ifdef __cplusplus
31 
32 HIP_PUBLIC_API
33 hipChannelFormatDesc hipCreateChannelDesc(int x, int y, int z, int w, hipChannelFormatKind f);
34 
35 static inline hipChannelFormatDesc hipCreateChannelDescHalf() {
36  int e = (int)sizeof(unsigned short) * 8;
37  return hipCreateChannelDesc(e, 0, 0, 0, hipChannelFormatKindFloat);
38 }
39 
40 static inline hipChannelFormatDesc hipCreateChannelDescHalf1() {
41  int e = (int)sizeof(unsigned short) * 8;
42  return hipCreateChannelDesc(e, 0, 0, 0, hipChannelFormatKindFloat);
43 }
44 
45 static inline hipChannelFormatDesc hipCreateChannelDescHalf2() {
46  int e = (int)sizeof(unsigned short) * 8;
47  return hipCreateChannelDesc(e, 0, 0, 0, hipChannelFormatKindFloat);
48 }
49 
50 template <typename T>
51 static inline hipChannelFormatDesc hipCreateChannelDesc() {
52  return hipCreateChannelDesc(0, 0, 0, 0, hipChannelFormatKindNone);
53 }
54 
55 template <>
56 inline hipChannelFormatDesc hipCreateChannelDesc<char>() {
57  int e = (int)sizeof(char) * 8;
58  return hipCreateChannelDesc(e, 0, 0, 0, hipChannelFormatKindSigned);
59 }
60 
61 template <>
62 inline hipChannelFormatDesc hipCreateChannelDesc<signed char>() {
63  int e = (int)sizeof(signed char) * 8;
64  return hipCreateChannelDesc(e, 0, 0, 0, hipChannelFormatKindUnsigned);
65 }
66 
67 template <>
68 inline hipChannelFormatDesc hipCreateChannelDesc<unsigned char>() {
69  int e = (int)sizeof(unsigned char) * 8;
70  return hipCreateChannelDesc(e, 0, 0, 0, hipChannelFormatKindUnsigned);
71 }
72 
73 template <>
74 inline hipChannelFormatDesc hipCreateChannelDesc<uchar1>() {
75  int e = (int)sizeof(unsigned char) * 8;
76  return hipCreateChannelDesc(e, 0, 0, 0, hipChannelFormatKindSigned);
77 }
78 
79 template <>
80 inline hipChannelFormatDesc hipCreateChannelDesc<char1>() {
81  int e = (int)sizeof(signed char) * 8;
82  return hipCreateChannelDesc(e, 0, 0, 0, hipChannelFormatKindSigned);
83 }
84 
85 template <>
86 inline hipChannelFormatDesc hipCreateChannelDesc<uchar2>() {
87  int e = (int)sizeof(unsigned char) * 8;
88  return hipCreateChannelDesc(e, e, 0, 0, hipChannelFormatKindSigned);
89 }
90 
91 template <>
92 inline hipChannelFormatDesc hipCreateChannelDesc<char2>() {
93  int e = (int)sizeof(signed char) * 8;
94  return hipCreateChannelDesc(e, e, 0, 0, hipChannelFormatKindSigned);
95 }
96 
97 #ifndef __GNUC__ // vector3 is the same as vector4
98 template <>
99 inline hipChannelFormatDesc hipCreateChannelDesc<uchar3>() {
100  int e = (int)sizeof(unsigned char) * 8;
101  return hipCreateChannelDesc(e, e, e, 0, hipChannelFormatKindSigned);
102 }
103 
104 template <>
105 inline hipChannelFormatDesc hipCreateChannelDesc<char3>() {
106  int e = (int)sizeof(signed char) * 8;
107  return hipCreateChannelDesc(e, e, e, 0, hipChannelFormatKindSigned);
108 }
109 #endif
110 
111 template <>
112 inline hipChannelFormatDesc hipCreateChannelDesc<uchar4>() {
113  int e = (int)sizeof(unsigned char) * 8;
114  return hipCreateChannelDesc(e, e, e, e, hipChannelFormatKindSigned);
115 }
116 
117 template <>
118 inline hipChannelFormatDesc hipCreateChannelDesc<char4>() {
119  int e = (int)sizeof(signed char) * 8;
120  return hipCreateChannelDesc(e, e, e, e, hipChannelFormatKindSigned);
121 }
122 
123 template <>
124 inline hipChannelFormatDesc hipCreateChannelDesc<unsigned short>() {
125  int e = (int)sizeof(unsigned short) * 8;
126  return hipCreateChannelDesc(e, 0, 0, 0, hipChannelFormatKindUnsigned);
127 }
128 
129 template <>
130 inline hipChannelFormatDesc hipCreateChannelDesc<signed short>() {
131  int e = (int)sizeof(signed short) * 8;
132  return hipCreateChannelDesc(e, 0, 0, 0, hipChannelFormatKindSigned);
133 }
134 
135 template <>
136 inline hipChannelFormatDesc hipCreateChannelDesc<ushort1>() {
137  int e = (int)sizeof(unsigned short) * 8;
138  return hipCreateChannelDesc(e, 0, 0, 0, hipChannelFormatKindUnsigned);
139 }
140 
141 template <>
142 inline hipChannelFormatDesc hipCreateChannelDesc<short1>() {
143  int e = (int)sizeof(signed short) * 8;
144  return hipCreateChannelDesc(e, 0, 0, 0, hipChannelFormatKindSigned);
145 }
146 
147 template <>
148 inline hipChannelFormatDesc hipCreateChannelDesc<ushort2>() {
149  int e = (int)sizeof(unsigned short) * 8;
150  return hipCreateChannelDesc(e, e, 0, 0, hipChannelFormatKindUnsigned);
151 }
152 
153 template <>
154 inline hipChannelFormatDesc hipCreateChannelDesc<short2>() {
155  int e = (int)sizeof(signed short) * 8;
156  return hipCreateChannelDesc(e, e, 0, 0, hipChannelFormatKindSigned);
157 }
158 
159 #ifndef __GNUC__
160 template <>
161 inline hipChannelFormatDesc hipCreateChannelDesc<ushort3>() {
162  int e = (int)sizeof(unsigned short) * 8;
163  return hipCreateChannelDesc(e, e, e, 0, hipChannelFormatKindUnsigned);
164 }
165 
166 template <>
167 inline hipChannelFormatDesc hipCreateChannelDesc<short3>() {
168  int e = (int)sizeof(signed short) * 8;
169  return hipCreateChannelDesc(e, e, e, 0, hipChannelFormatKindSigned);
170 }
171 #endif
172 
173 template <>
174 inline hipChannelFormatDesc hipCreateChannelDesc<ushort4>() {
175  int e = (int)sizeof(unsigned short) * 8;
176  return hipCreateChannelDesc(e, e, e, e, hipChannelFormatKindUnsigned);
177 }
178 
179 template <>
180 inline hipChannelFormatDesc hipCreateChannelDesc<short4>() {
181  int e = (int)sizeof(signed short) * 8;
182  return hipCreateChannelDesc(e, e, e, e, hipChannelFormatKindSigned);
183 }
184 
185 template <>
186 inline hipChannelFormatDesc hipCreateChannelDesc<unsigned int>() {
187  int e = (int)sizeof(unsigned int) * 8;
188  return hipCreateChannelDesc(e, 0, 0, 0, hipChannelFormatKindUnsigned);
189 }
190 
191 template <>
192 inline hipChannelFormatDesc hipCreateChannelDesc<signed int>() {
193  int e = (int)sizeof(signed int) * 8;
194  return hipCreateChannelDesc(e, 0, 0, 0, hipChannelFormatKindSigned);
195 }
196 
197 template <>
198 inline hipChannelFormatDesc hipCreateChannelDesc<uint1>() {
199  int e = (int)sizeof(unsigned int) * 8;
200  return hipCreateChannelDesc(e, 0, 0, 0, hipChannelFormatKindUnsigned);
201 }
202 
203 template <>
204 inline hipChannelFormatDesc hipCreateChannelDesc<int1>() {
205  int e = (int)sizeof(signed int) * 8;
206  return hipCreateChannelDesc(e, 0, 0, 0, hipChannelFormatKindSigned);
207 }
208 
209 template <>
210 inline hipChannelFormatDesc hipCreateChannelDesc<uint2>() {
211  int e = (int)sizeof(unsigned int) * 8;
212  return hipCreateChannelDesc(e, e, 0, 0, hipChannelFormatKindUnsigned);
213 }
214 
215 template <>
216 inline hipChannelFormatDesc hipCreateChannelDesc<int2>() {
217  int e = (int)sizeof(signed int) * 8;
218  return hipCreateChannelDesc(e, e, 0, 0, hipChannelFormatKindSigned);
219 }
220 
221 #ifndef __GNUC__
222 template <>
223 inline hipChannelFormatDesc hipCreateChannelDesc<uint3>() {
224  int e = (int)sizeof(unsigned int) * 8;
225  return hipCreateChannelDesc(e, e, e, 0, hipChannelFormatKindUnsigned);
226 }
227 
228 template <>
229 inline hipChannelFormatDesc hipCreateChannelDesc<int3>() {
230  int e = (int)sizeof(signed int) * 8;
231  return hipCreateChannelDesc(e, e, e, 0, hipChannelFormatKindSigned);
232 }
233 #endif
234 
235 template <>
236 inline hipChannelFormatDesc hipCreateChannelDesc<uint4>() {
237  int e = (int)sizeof(unsigned int) * 8;
238  return hipCreateChannelDesc(e, e, e, e, hipChannelFormatKindUnsigned);
239 }
240 
241 template <>
242 inline hipChannelFormatDesc hipCreateChannelDesc<int4>() {
243  int e = (int)sizeof(signed int) * 8;
244  return hipCreateChannelDesc(e, e, e, e, hipChannelFormatKindSigned);
245 }
246 
247 template <>
248 inline hipChannelFormatDesc hipCreateChannelDesc<float>() {
249  int e = (int)sizeof(float) * 8;
250  return hipCreateChannelDesc(e, 0, 0, 0, hipChannelFormatKindFloat);
251 }
252 
253 template <>
254 inline hipChannelFormatDesc hipCreateChannelDesc<float1>() {
255  int e = (int)sizeof(float) * 8;
256  return hipCreateChannelDesc(e, 0, 0, 0, hipChannelFormatKindFloat);
257 }
258 
259 template <>
260 inline hipChannelFormatDesc hipCreateChannelDesc<float2>() {
261  int e = (int)sizeof(float) * 8;
262  return hipCreateChannelDesc(e, e, 0, 0, hipChannelFormatKindFloat);
263 }
264 
265 #ifndef __GNUC__
266 template <>
267 inline hipChannelFormatDesc hipCreateChannelDesc<float3>() {
268  int e = (int)sizeof(float) * 8;
269  return hipCreateChannelDesc(e, e, e, 0, hipChannelFormatKindFloat);
270 }
271 #endif
272 
273 template <>
274 inline hipChannelFormatDesc hipCreateChannelDesc<float4>() {
275  int e = (int)sizeof(float) * 8;
276  return hipCreateChannelDesc(e, e, e, e, hipChannelFormatKindFloat);
277 }
278 
279 template <>
280 inline hipChannelFormatDesc hipCreateChannelDesc<unsigned long>() {
281  int e = (int)sizeof(unsigned long) * 8;
282  return hipCreateChannelDesc(e, 0, 0, 0, hipChannelFormatKindUnsigned);
283 }
284 
285 template <>
286 inline hipChannelFormatDesc hipCreateChannelDesc<signed long>() {
287  int e = (int)sizeof(signed long) * 8;
288  return hipCreateChannelDesc(e, 0, 0, 0, hipChannelFormatKindSigned);
289 }
290 
291 template <>
292 inline hipChannelFormatDesc hipCreateChannelDesc<ulong1>() {
293  int e = (int)sizeof(unsigned long) * 8;
294  return hipCreateChannelDesc(e, 0, 0, 0, hipChannelFormatKindUnsigned);
295 }
296 
297 template <>
298 inline hipChannelFormatDesc hipCreateChannelDesc<long1>() {
299  int e = (int)sizeof(signed long) * 8;
300  return hipCreateChannelDesc(e, 0, 0, 0, hipChannelFormatKindSigned);
301 }
302 
303 template <>
304 inline hipChannelFormatDesc hipCreateChannelDesc<ulong2>() {
305  int e = (int)sizeof(unsigned long) * 8;
306  return hipCreateChannelDesc(e, e, 0, 0, hipChannelFormatKindUnsigned);
307 }
308 
309 template <>
310 inline hipChannelFormatDesc hipCreateChannelDesc<long2>() {
311  int e = (int)sizeof(signed long) * 8;
312  return hipCreateChannelDesc(e, e, 0, 0, hipChannelFormatKindSigned);
313 }
314 
315 #ifndef __GNUC__
316 template <>
317 inline hipChannelFormatDesc hipCreateChannelDesc<ulong3>() {
318  int e = (int)sizeof(unsigned long) * 8;
319  return hipCreateChannelDesc(e, e, e, 0, hipChannelFormatKindUnsigned);
320 }
321 
322 template <>
323 inline hipChannelFormatDesc hipCreateChannelDesc<long3>() {
324  int e = (int)sizeof(signed long) * 8;
325  return hipCreateChannelDesc(e, e, e, 0, hipChannelFormatKindSigned);
326 }
327 #endif
328 
329 template <>
330 inline hipChannelFormatDesc hipCreateChannelDesc<ulong4>() {
331  int e = (int)sizeof(unsigned long) * 8;
332  return hipCreateChannelDesc(e, e, e, e, hipChannelFormatKindUnsigned);
333 }
334 
335 template <>
336 inline hipChannelFormatDesc hipCreateChannelDesc<long4>() {
337  int e = (int)sizeof(signed long) * 8;
338  return hipCreateChannelDesc(e, e, e, e, hipChannelFormatKindSigned);
339 }
340 
341 #else
342 
343 struct hipChannelFormatDesc hipCreateChannelDesc(int x, int y, int z, int w,
344  enum hipChannelFormatKind f);
345 
346 #endif
347 
348 #endif
Defines the different newt vector types for HIP runtime.
Definition: driver_types.h:38