blob: 05be252fa9fbf045817ec73e2f6b8a3d3ea81222 [file] [log] [blame]
Johannes Doerfertf85ae052020-03-27 20:36:30 -05001/*===-- __clang_openmp_device_functions.h - OpenMP math declares ------ c++ -===
Gheorghe-Teodor Berceae62c6932019-05-08 15:52:33 +00002 *
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
6 *
7 *===-----------------------------------------------------------------------===
8 */
9
Johannes Doerfertf85ae052020-03-27 20:36:30 -050010#ifndef __CLANG_OPENMP_CMATH_H__
11#define __CLANG_OPENMP_CMATH_H__
Gheorghe-Teodor Berceae62c6932019-05-08 15:52:33 +000012
Johannes Doerfertf85ae052020-03-27 20:36:30 -050013#ifndef _OPENMP
14#error "This file is for OpenMP compilation only."
15#endif
16
Gheorghe-Teodor Berceae62c6932019-05-08 15:52:33 +000017#include_next <cmath>
Johannes Doerfertf85ae052020-03-27 20:36:30 -050018
19// Make sure we include our math.h overlay, it probably happend already but we
20// need to be sure.
21#include <math.h>
22
23// We (might) need cstdlib because __clang_cuda_cmath.h below declares `abs`
24// which might live in cstdlib.
25#include <cstdlib>
26
27#pragma omp begin declare variant match( \
28 device = {arch(nvptx, nvptx64)}, implementation = {extension(match_any)})
29
30#define __CUDA__
31#include <__clang_cuda_cmath.h>
32#undef __CUDA__
33
34// Overloads not provided by the CUDA wrappers but by the CUDA system headers.
35// Since we do not include the latter we define them ourselves.
36#define __DEVICE__ static constexpr __attribute__((always_inline, nothrow))
37
38__DEVICE__ float acosh(float __x) { return ::acoshf(__x); }
39__DEVICE__ float asinh(float __x) { return ::asinhf(__x); }
40__DEVICE__ float atanh(float __x) { return ::atanhf(__x); }
41__DEVICE__ float cbrt(float __x) { return ::cbrtf(__x); }
42__DEVICE__ float erf(float __x) { return ::erff(__x); }
43__DEVICE__ float erfc(float __x) { return ::erfcf(__x); }
44__DEVICE__ float exp2(float __x) { return ::exp2f(__x); }
45__DEVICE__ float expm1(float __x) { return ::expm1f(__x); }
46__DEVICE__ float fdim(float __x, float __y) { return ::fdimf(__x, __y); }
47__DEVICE__ float hypot(float __x, float __y) { return ::hypotf(__x, __y); }
48__DEVICE__ int ilogb(float __x) { return ::ilogbf(__x); }
49__DEVICE__ float lgamma(float __x) { return ::lgammaf(__x); }
50__DEVICE__ long long int llrint(float __x) { return ::llrintf(__x); }
51__DEVICE__ long long int llround(float __x) { return ::llroundf(__x); }
52__DEVICE__ float log1p(float __x) { return ::log1pf(__x); }
53__DEVICE__ float log2(float __x) { return ::log2f(__x); }
54__DEVICE__ float logb(float __x) { return ::logbf(__x); }
55__DEVICE__ long int lrint(float __x) { return ::lrintf(__x); }
56__DEVICE__ long int lround(float __x) { return ::lroundf(__x); }
57__DEVICE__ float nextafter(float __x, float __y) {
58 return ::nextafterf(__x, __y);
59}
60__DEVICE__ float remainder(float __x, float __y) {
61 return ::remainderf(__x, __y);
62}
63__DEVICE__ float scalbln(float __x, long int __y) {
64 return ::scalblnf(__x, __y);
65}
66__DEVICE__ float scalbn(float __x, int __y) { return ::scalbnf(__x, __y); }
67__DEVICE__ float tgamma(float __x) { return ::tgammaf(__x); }
68
69#undef __DEVICE__
70
71#pragma omp end declare variant
72
Gheorghe-Teodor Berceae62c6932019-05-08 15:52:33 +000073#endif