HIP: Heterogenous-computing Interface for Portability
Loading...
Searching...
No Matches
host_defines.h
Go to the documentation of this file.
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
28#ifndef HIP_INCLUDE_HIP_AMD_DETAIL_HOST_DEFINES_H
29#define HIP_INCLUDE_HIP_AMD_DETAIL_HOST_DEFINES_H
30
31// The follow macro should be removed after upstream updation.
32// It's defined here for workarround of rocThrust building failure.
33#define HIP_INCLUDE_HIP_HCC_DETAIL_HOST_DEFINES_H
34
35// Add guard to Generic Grid Launch method
36#ifndef GENERIC_GRID_LAUNCH
37#define GENERIC_GRID_LAUNCH 1
38#endif
39
40#if defined(__clang__) && defined(__HIP__)
41
42namespace __hip_internal {
43typedef unsigned char uint8_t;
44typedef unsigned short uint16_t;
45typedef unsigned int uint32_t;
46typedef unsigned long long uint64_t;
47typedef signed char int8_t;
48typedef signed short int16_t;
49typedef signed int int32_t;
50typedef signed long long int64_t;
51
52template <class _Tp, _Tp __v> struct integral_constant {
53 static constexpr const _Tp value = __v;
54 typedef _Tp value_type;
55 typedef integral_constant type;
56 constexpr operator value_type() const { return value; }
57 constexpr value_type operator()() const { return value; }
58};
59template <class _Tp, _Tp __v> constexpr const _Tp integral_constant<_Tp, __v>::value;
60
61typedef integral_constant<bool, true> true_type;
62typedef integral_constant<bool, false> false_type;
63
64template <bool B> using bool_constant = integral_constant<bool, B>;
65typedef bool_constant<true> true_type;
66typedef bool_constant<false> false_type;
67
68template <bool __B, class __T = void> struct enable_if {};
69template <class __T> struct enable_if<true, __T> { typedef __T type; };
70
71template<bool _B> struct true_or_false_type : public false_type {};
72template<> struct true_or_false_type<true> : public true_type {};
73
74template <class _Tp> struct is_integral : public false_type {};
75template <> struct is_integral<bool> : public true_type {};
76template <> struct is_integral<char> : public true_type {};
77template <> struct is_integral<signed char> : public true_type {};
78template <> struct is_integral<unsigned char> : public true_type {};
79template <> struct is_integral<wchar_t> : public true_type {};
80template <> struct is_integral<short> : public true_type {};
81template <> struct is_integral<unsigned short> : public true_type {};
82template <> struct is_integral<int> : public true_type {};
83template <> struct is_integral<unsigned int> : public true_type {};
84template <> struct is_integral<long> : public true_type {};
85template <> struct is_integral<unsigned long> : public true_type {};
86template <> struct is_integral<long long> : public true_type {};
87template <> struct is_integral<unsigned long long> : public true_type {};
88
89template <class _Tp> struct is_arithmetic : public false_type {};
90template <> struct is_arithmetic<bool> : public true_type {};
91template <> struct is_arithmetic<char> : public true_type {};
92template <> struct is_arithmetic<signed char> : public true_type {};
93template <> struct is_arithmetic<unsigned char> : public true_type {};
94template <> struct is_arithmetic<wchar_t> : public true_type {};
95template <> struct is_arithmetic<short> : public true_type {};
96template <> struct is_arithmetic<unsigned short> : public true_type {};
97template <> struct is_arithmetic<int> : public true_type {};
98template <> struct is_arithmetic<unsigned int> : public true_type {};
99template <> struct is_arithmetic<long> : public true_type {};
100template <> struct is_arithmetic<unsigned long> : public true_type {};
101template <> struct is_arithmetic<long long> : public true_type {};
102template <> struct is_arithmetic<unsigned long long> : public true_type {};
103template <> struct is_arithmetic<float> : public true_type {};
104template <> struct is_arithmetic<double> : public true_type {};
105
106template<typename _Tp> struct is_floating_point : public false_type {};
107template<> struct is_floating_point<float> : public true_type {};
108template<> struct is_floating_point<double> : public true_type {};
109template<> struct is_floating_point<long double> : public true_type {};
110
111template <typename __T, typename __U> struct is_same : public false_type {};
112template <typename __T> struct is_same<__T, __T> : public true_type {};
113
114template<typename _Tp, bool = is_arithmetic<_Tp>::value>
115 struct is_signed : public false_type {};
116template<typename _Tp>
117 struct is_signed<_Tp, true> : public true_or_false_type<_Tp(-1) < _Tp(0)> {};
118
119template<typename _CharT> struct char_traits;
120template<typename _CharT, typename _Traits = char_traits<_CharT>> class basic_istream;
121template<typename _CharT, typename _Traits = char_traits<_CharT>> class basic_ostream;
122typedef basic_istream<char> istream;
123typedef basic_ostream<char> ostream;
124
125template<typename _Tp>
126 struct is_standard_layout
127 : public integral_constant<bool, __is_standard_layout(_Tp)>
128 { };
129
130template<typename _Tp>
131 struct is_trivial
132 : public integral_constant<bool, __is_trivial(_Tp)>
133 { };
134}
135typedef __hip_internal::uint8_t __hip_uint8_t;
136typedef __hip_internal::uint16_t __hip_uint16_t;
137typedef __hip_internal::uint32_t __hip_uint32_t;
138typedef __hip_internal::uint64_t __hip_uint64_t;
139typedef __hip_internal::int8_t __hip_int8_t;
140typedef __hip_internal::int16_t __hip_int16_t;
141typedef __hip_internal::int32_t __hip_int32_t;
142typedef __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