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