1 /*===- __clang_math_forward_declares.h - Prototypes of __device__ math fns --===
3 * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 * See https://llvm.org/LICENSE.txt for license information.
5 * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 *===-----------------------------------------------------------------------===
9 #ifndef __CLANG__CUDA_MATH_FORWARD_DECLARES_H__
10 #define __CLANG__CUDA_MATH_FORWARD_DECLARES_H__
12 #error "This file is for CUDA compilation only."
15 // This file forward-declares of some math functions we (or the CUDA headers)
16 // will define later. We need to do this, and do it before cmath is included,
17 // because the standard library may have constexpr math functions. In the
18 // absence of a prior __device__ decl, those constexpr functions may become
19 // implicitly host+device. host+device functions can't be overloaded, so that
20 // would preclude the use of our own __device__ overloads for these functions.
22 #pragma push_macro("__DEVICE__")
24 #define __DEVICE__ static __inline__ __attribute__((always_inline))
27 static __inline__ __attribute__((always_inline)) __attribute__((device))
30 // For C++ 17 we need to include noexcept attribute to be compatible
31 // with the header-defined version. This may be removed once
32 // variant is supported.
33 #if defined(_OPENMP) && defined(__cplusplus) && __cplusplus >= 201703L
34 #define __NOEXCEPT noexcept
39 #if !(defined(_OPENMP) && defined(__cplusplus))
40 __DEVICE__ long abs(long);
41 __DEVICE__ long long abs(long long);
42 __DEVICE__ double abs(double);
43 __DEVICE__ float abs(float);
45 // While providing the CUDA declarations and definitions for math functions,
46 // we may manually define additional functions.
47 // TODO: Once variant is supported the additional functions will have
49 #if defined(_OPENMP) && defined(__cplusplus)
50 __DEVICE__ const double abs(const double);
51 __DEVICE__ const float abs(const float);
53 __DEVICE__ int abs(int) __NOEXCEPT;
54 __DEVICE__ double acos(double);
55 __DEVICE__ float acos(float);
56 __DEVICE__ double acosh(double);
57 __DEVICE__ float acosh(float);
58 __DEVICE__ double asin(double);
59 __DEVICE__ float asin(float);
60 __DEVICE__ double asinh(double);
61 __DEVICE__ float asinh(float);
62 __DEVICE__ double atan2(double, double);
63 __DEVICE__ float atan2(float, float);
64 __DEVICE__ double atan(double);
65 __DEVICE__ float atan(float);
66 __DEVICE__ double atanh(double);
67 __DEVICE__ float atanh(float);
68 __DEVICE__ double cbrt(double);
69 __DEVICE__ float cbrt(float);
70 __DEVICE__ double ceil(double);
71 __DEVICE__ float ceil(float);
72 __DEVICE__ double copysign(double, double);
73 __DEVICE__ float copysign(float, float);
74 __DEVICE__ double cos(double);
75 __DEVICE__ float cos(float);
76 __DEVICE__ double cosh(double);
77 __DEVICE__ float cosh(float);
78 __DEVICE__ double erfc(double);
79 __DEVICE__ float erfc(float);
80 __DEVICE__ double erf(double);
81 __DEVICE__ float erf(float);
82 __DEVICE__ double exp2(double);
83 __DEVICE__ float exp2(float);
84 __DEVICE__ double exp(double);
85 __DEVICE__ float exp(float);
86 __DEVICE__ double expm1(double);
87 __DEVICE__ float expm1(float);
88 __DEVICE__ double fabs(double) __NOEXCEPT;
89 __DEVICE__ float fabs(float) __NOEXCEPT;
90 __DEVICE__ double fdim(double, double);
91 __DEVICE__ float fdim(float, float);
92 __DEVICE__ double floor(double);
93 __DEVICE__ float floor(float);
94 __DEVICE__ double fma(double, double, double);
95 __DEVICE__ float fma(float, float, float);
96 __DEVICE__ double fmax(double, double);
97 __DEVICE__ float fmax(float, float);
98 __DEVICE__ double fmin(double, double);
99 __DEVICE__ float fmin(float, float);
100 __DEVICE__ double fmod(double, double);
101 __DEVICE__ float fmod(float, float);
102 __DEVICE__ int fpclassify(double);
103 __DEVICE__ int fpclassify(float);
104 __DEVICE__ double frexp(double, int *);
105 __DEVICE__ float frexp(float, int *);
106 __DEVICE__ double hypot(double, double);
107 __DEVICE__ float hypot(float, float);
108 __DEVICE__ int ilogb(double);
109 __DEVICE__ int ilogb(float);
111 __DEVICE__ bool isfinite(long double);
113 __DEVICE__ bool isfinite(double);
114 __DEVICE__ bool isfinite(float);
115 __DEVICE__ bool isgreater(double, double);
116 __DEVICE__ bool isgreaterequal(double, double);
117 __DEVICE__ bool isgreaterequal(float, float);
118 __DEVICE__ bool isgreater(float, float);
120 __DEVICE__ bool isinf(long double);
122 __DEVICE__ bool isinf(double);
123 __DEVICE__ bool isinf(float);
124 __DEVICE__ bool isless(double, double);
125 __DEVICE__ bool islessequal(double, double);
126 __DEVICE__ bool islessequal(float, float);
127 __DEVICE__ bool isless(float, float);
128 __DEVICE__ bool islessgreater(double, double);
129 __DEVICE__ bool islessgreater(float, float);
131 __DEVICE__ bool isnan(long double);
133 __DEVICE__ bool isnan(double);
134 __DEVICE__ bool isnan(float);
135 __DEVICE__ bool isnormal(double);
136 __DEVICE__ bool isnormal(float);
137 __DEVICE__ bool isunordered(double, double);
138 __DEVICE__ bool isunordered(float, float);
139 __DEVICE__ long labs(long) __NOEXCEPT;
140 __DEVICE__ double ldexp(double, int);
141 __DEVICE__ float ldexp(float, int);
142 __DEVICE__ double lgamma(double);
143 __DEVICE__ float lgamma(float);
144 __DEVICE__ long long llabs(long long) __NOEXCEPT;
145 __DEVICE__ long long llrint(double);
146 __DEVICE__ long long llrint(float);
147 __DEVICE__ double log10(double);
148 __DEVICE__ float log10(float);
149 __DEVICE__ double log1p(double);
150 __DEVICE__ float log1p(float);
151 __DEVICE__ double log2(double);
152 __DEVICE__ float log2(float);
153 __DEVICE__ double logb(double);
154 __DEVICE__ float logb(float);
155 #if defined(_OPENMP) && defined(__cplusplus)
156 __DEVICE__ long double log(long double);
158 __DEVICE__ double log(double);
159 __DEVICE__ float log(float);
160 __DEVICE__ long lrint(double);
161 __DEVICE__ long lrint(float);
162 __DEVICE__ long lround(double);
163 __DEVICE__ long lround(float);
164 __DEVICE__ long long llround(float); // No llround(double).
165 __DEVICE__ double modf(double, double *);
166 __DEVICE__ float modf(float, float *);
167 __DEVICE__ double nan(const char *);
168 __DEVICE__ float nanf(const char *);
169 __DEVICE__ double nearbyint(double);
170 __DEVICE__ float nearbyint(float);
171 __DEVICE__ double nextafter(double, double);
172 __DEVICE__ float nextafter(float, float);
173 __DEVICE__ double pow(double, double);
174 __DEVICE__ double pow(double, int);
175 __DEVICE__ float pow(float, float);
176 __DEVICE__ float pow(float, int);
177 __DEVICE__ double remainder(double, double);
178 __DEVICE__ float remainder(float, float);
179 __DEVICE__ double remquo(double, double, int *);
180 __DEVICE__ float remquo(float, float, int *);
181 __DEVICE__ double rint(double);
182 __DEVICE__ float rint(float);
183 __DEVICE__ double round(double);
184 __DEVICE__ float round(float);
185 __DEVICE__ double scalbln(double, long);
186 __DEVICE__ float scalbln(float, long);
187 __DEVICE__ double scalbn(double, int);
188 __DEVICE__ float scalbn(float, int);
189 __DEVICE__ bool signbit(double);
190 __DEVICE__ bool signbit(float);
191 __DEVICE__ double sin(double);
192 __DEVICE__ float sin(float);
193 __DEVICE__ double sinh(double);
194 __DEVICE__ float sinh(float);
195 __DEVICE__ double sqrt(double);
196 __DEVICE__ float sqrt(float);
197 __DEVICE__ double tan(double);
198 __DEVICE__ float tan(float);
199 __DEVICE__ double tanh(double);
200 __DEVICE__ float tanh(float);
201 __DEVICE__ double tgamma(double);
202 __DEVICE__ float tgamma(float);
203 __DEVICE__ double trunc(double);
204 __DEVICE__ float trunc(float);
206 // Notably missing above is nexttoward, which we don't define on
207 // the device side because libdevice doesn't give us an implementation, and we
208 // don't want to be in the business of writing one ourselves.
210 // We need to define these overloads in exactly the namespace our standard
211 // library uses (including the right inline namespace), otherwise they won't be
212 // picked up by other functions in the standard library (e.g. functions in
213 // <complex>). Thus the ugliness below.
214 #ifdef _LIBCPP_BEGIN_NAMESPACE_STD
215 _LIBCPP_BEGIN_NAMESPACE_STD
218 #ifdef _GLIBCXX_BEGIN_NAMESPACE_VERSION
219 _GLIBCXX_BEGIN_NAMESPACE_VERSION
254 using ::isgreaterequal;
258 using ::islessgreater;
296 #ifdef _LIBCPP_END_NAMESPACE_STD
297 _LIBCPP_END_NAMESPACE_STD
299 #ifdef _GLIBCXX_BEGIN_NAMESPACE_VERSION
300 _GLIBCXX_END_NAMESPACE_VERSION
306 #pragma pop_macro("__DEVICE__")