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