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