HIP: Heterogenous-computing Interface for Portability
host_defines.h
Go to the documentation of this file.
1 /*
2 Copyright (c) 2015 - 2022 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 
28 #ifndef HIP_INCLUDE_HIP_AMD_DETAIL_HOST_DEFINES_H
29 #define HIP_INCLUDE_HIP_AMD_DETAIL_HOST_DEFINES_H
30 
31 // Add guard to Generic Grid Launch method
32 #ifndef GENERIC_GRID_LAUNCH
33 #define GENERIC_GRID_LAUNCH 1
34 #endif
35 
36 #if defined(__clang__) && defined(__HIP__)
37 
38 namespace __hip_internal {
39 typedef unsigned char uint8_t;
40 typedef unsigned short uint16_t;
41 typedef unsigned int uint32_t;
42 typedef unsigned long long uint64_t;
43 typedef signed char int8_t;
44 typedef signed short int16_t;
45 typedef signed int int32_t;
46 typedef signed long long int64_t;
47 
48 template <class _Tp, _Tp __v> struct integral_constant {
49  static constexpr const _Tp value = __v;
50  typedef _Tp value_type;
51  typedef integral_constant type;
52  constexpr operator value_type() const { return value; }
53  constexpr value_type operator()() const { return value; }
54 };
55 template <class _Tp, _Tp __v> constexpr const _Tp integral_constant<_Tp, __v>::value;
56 
57 typedef integral_constant<bool, true> true_type;
58 typedef integral_constant<bool, false> false_type;
59 
60 template <bool B> using bool_constant = integral_constant<bool, B>;
61 typedef bool_constant<true> true_type;
62 typedef bool_constant<false> false_type;
63 
64 template <bool __B, class __T = void> struct enable_if {};
65 template <class __T> struct enable_if<true, __T> { typedef __T type; };
66 
67 template<bool _B> struct true_or_false_type : public false_type {};
68 template<> struct true_or_false_type<true> : public true_type {};
69 
70 template <class _Tp> struct is_integral : public false_type {};
71 template <> struct is_integral<bool> : public true_type {};
72 template <> struct is_integral<char> : public true_type {};
73 template <> struct is_integral<signed char> : public true_type {};
74 template <> struct is_integral<unsigned char> : public true_type {};
75 template <> struct is_integral<wchar_t> : public true_type {};
76 template <> struct is_integral<short> : public true_type {};
77 template <> struct is_integral<unsigned short> : public true_type {};
78 template <> struct is_integral<int> : public true_type {};
79 template <> struct is_integral<unsigned int> : public true_type {};
80 template <> struct is_integral<long> : public true_type {};
81 template <> struct is_integral<unsigned long> : public true_type {};
82 template <> struct is_integral<long long> : public true_type {};
83 template <> struct is_integral<unsigned long long> : public true_type {};
84 
85 template <class _Tp> struct is_arithmetic : public false_type {};
86 template <> struct is_arithmetic<bool> : public true_type {};
87 template <> struct is_arithmetic<char> : public true_type {};
88 template <> struct is_arithmetic<signed char> : public true_type {};
89 template <> struct is_arithmetic<unsigned char> : public true_type {};
90 template <> struct is_arithmetic<wchar_t> : public true_type {};
91 template <> struct is_arithmetic<short> : public true_type {};
92 template <> struct is_arithmetic<unsigned short> : public true_type {};
93 template <> struct is_arithmetic<int> : public true_type {};
94 template <> struct is_arithmetic<unsigned int> : public true_type {};
95 template <> struct is_arithmetic<long> : public true_type {};
96 template <> struct is_arithmetic<unsigned long> : public true_type {};
97 template <> struct is_arithmetic<long long> : public true_type {};
98 template <> struct is_arithmetic<unsigned long long> : public true_type {};
99 template <> struct is_arithmetic<float> : public true_type {};
100 template <> struct is_arithmetic<double> : public true_type {};
101 
102 template<typename _Tp> struct is_floating_point : public false_type {};
103 template<> struct is_floating_point<float> : public true_type {};
104 template<> struct is_floating_point<double> : public true_type {};
105 template<> struct is_floating_point<long double> : public true_type {};
106 
107 template <typename __T, typename __U> struct is_same : public false_type {};
108 template <typename __T> struct is_same<__T, __T> : public true_type {};
109 
110 template<typename _Tp, bool = is_arithmetic<_Tp>::value>
111  struct is_signed : public false_type {};
112 template<typename _Tp>
113  struct is_signed<_Tp, true> : public true_or_false_type<_Tp(-1) < _Tp(0)> {};
114 
115 template<typename _CharT> struct char_traits;
116 template<typename _CharT, typename _Traits = char_traits<_CharT>> class basic_istream;
117 template<typename _CharT, typename _Traits = char_traits<_CharT>> class basic_ostream;
118 typedef basic_istream<char> istream;
119 typedef basic_ostream<char> ostream;
120 
121 template<typename _Tp>
122  struct is_standard_layout
123  : public integral_constant<bool, __is_standard_layout(_Tp)>
124  { };
125 
126 template<typename _Tp>
127  struct is_trivial
128  : public integral_constant<bool, __is_trivial(_Tp)>
129  { };
130 
131 
132 template <bool B, class T, class F> struct conditional { using type = T; };
133 template <class T, class F> struct conditional<false, T, F> { using type = F; };
134 }
135 typedef __hip_internal::uint8_t __hip_uint8_t;
136 typedef __hip_internal::uint16_t __hip_uint16_t;
137 typedef __hip_internal::uint32_t __hip_uint32_t;
138 typedef __hip_internal::uint64_t __hip_uint64_t;
139 typedef __hip_internal::int8_t __hip_int8_t;
140 typedef __hip_internal::int16_t __hip_int16_t;
141 typedef __hip_internal::int32_t __hip_int32_t;
142 typedef __hip_internal::int64_t __hip_int64_t;
143 
144 #if !__CLANG_HIP_RUNTIME_WRAPPER_INCLUDED__
145 #define __host__ __attribute__((host))
146 #define __device__ __attribute__((device))
147 #define __global__ __attribute__((global))
148 #define __shared__ __attribute__((shared))
149 #define __constant__ __attribute__((constant))
150 #endif // !__CLANG_HIP_RUNTIME_WRAPPER_INCLUDED__
151 
152 #if !defined(__has_feature) || !__has_feature(cuda_noinline_keyword)
153 #define __noinline__ __attribute__((noinline))
154 #endif
155 
156 #define __forceinline__ inline __attribute__((always_inline))
157 
158 #if __HIP_NO_IMAGE_SUPPORT
159 #define __hip_img_chk__ __attribute__((unavailable("The image/texture API not supported on the device")))
160 #else
161 #define __hip_img_chk__
162 #endif
163 
164 #else
165 
166 // Non-HCC compiler
170 #define __host__
171 #define __device__
172 
173 #define __global__
174 
175 #define __noinline__
176 #define __forceinline__ inline
177 
178 #define __shared__
179 #define __constant__
180 
181 #define __hip_img_chk__
182 #endif
183 
184 #endif