Pirama Arumuga Nainar | 494f645 | 2021-12-02 10:42:14 -0800 | [diff] [blame] | 1 | /*===-- __clang_openmp_device_functions.h - OpenMP math declares ------ c++ -=== |
| 2 | * |
| 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 | |
| 10 | #ifndef __CLANG_OPENMP_CMATH_H__ |
| 11 | #define __CLANG_OPENMP_CMATH_H__ |
| 12 | |
| 13 | #ifndef _OPENMP |
| 14 | #error "This file is for OpenMP compilation only." |
| 15 | #endif |
| 16 | |
| 17 | #include_next <cmath> |
| 18 | |
| 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 | // We need limits because __clang_cuda_cmath.h below uses `std::numeric_limit`. |
| 28 | #include <limits> |
| 29 | |
| 30 | #pragma omp begin declare variant match( \ |
| 31 | device = {arch(nvptx, nvptx64)}, implementation = {extension(match_any, allow_templates)}) |
| 32 | |
| 33 | #define __CUDA__ |
| 34 | #define __OPENMP_NVPTX__ |
| 35 | #include <__clang_cuda_cmath.h> |
| 36 | #undef __OPENMP_NVPTX__ |
| 37 | #undef __CUDA__ |
| 38 | |
| 39 | // Overloads not provided by the CUDA wrappers but by the CUDA system headers. |
| 40 | // Since we do not include the latter we define them ourselves. |
| 41 | #define __DEVICE__ static constexpr __attribute__((always_inline, nothrow)) |
| 42 | |
| 43 | __DEVICE__ float acosh(float __x) { return ::acoshf(__x); } |
| 44 | __DEVICE__ float asinh(float __x) { return ::asinhf(__x); } |
| 45 | __DEVICE__ float atanh(float __x) { return ::atanhf(__x); } |
| 46 | __DEVICE__ float cbrt(float __x) { return ::cbrtf(__x); } |
| 47 | __DEVICE__ float erf(float __x) { return ::erff(__x); } |
| 48 | __DEVICE__ float erfc(float __x) { return ::erfcf(__x); } |
| 49 | __DEVICE__ float exp2(float __x) { return ::exp2f(__x); } |
| 50 | __DEVICE__ float expm1(float __x) { return ::expm1f(__x); } |
| 51 | __DEVICE__ float fdim(float __x, float __y) { return ::fdimf(__x, __y); } |
| 52 | __DEVICE__ float hypot(float __x, float __y) { return ::hypotf(__x, __y); } |
| 53 | __DEVICE__ int ilogb(float __x) { return ::ilogbf(__x); } |
| 54 | __DEVICE__ float lgamma(float __x) { return ::lgammaf(__x); } |
| 55 | __DEVICE__ long long int llrint(float __x) { return ::llrintf(__x); } |
| 56 | __DEVICE__ long long int llround(float __x) { return ::llroundf(__x); } |
| 57 | __DEVICE__ float log1p(float __x) { return ::log1pf(__x); } |
| 58 | __DEVICE__ float log2(float __x) { return ::log2f(__x); } |
| 59 | __DEVICE__ float logb(float __x) { return ::logbf(__x); } |
| 60 | __DEVICE__ long int lrint(float __x) { return ::lrintf(__x); } |
| 61 | __DEVICE__ long int lround(float __x) { return ::lroundf(__x); } |
| 62 | __DEVICE__ float nextafter(float __x, float __y) { |
| 63 | return ::nextafterf(__x, __y); |
| 64 | } |
| 65 | __DEVICE__ float remainder(float __x, float __y) { |
| 66 | return ::remainderf(__x, __y); |
| 67 | } |
| 68 | __DEVICE__ float scalbln(float __x, long int __y) { |
| 69 | return ::scalblnf(__x, __y); |
| 70 | } |
| 71 | __DEVICE__ float scalbn(float __x, int __y) { return ::scalbnf(__x, __y); } |
| 72 | __DEVICE__ float tgamma(float __x) { return ::tgammaf(__x); } |
| 73 | |
| 74 | #undef __DEVICE__ |
| 75 | |
| 76 | #pragma omp end declare variant |
| 77 | |
| 78 | #ifdef __AMDGCN__ |
| 79 | #pragma omp begin declare variant match(device = {arch(amdgcn)}) |
| 80 | |
| 81 | #pragma push_macro("__constant__") |
| 82 | #define __constant__ __attribute__((constant)) |
| 83 | #define __OPENMP_AMDGCN__ |
| 84 | |
| 85 | #include <__clang_hip_cmath.h> |
| 86 | |
| 87 | #pragma pop_macro("__constant__") |
| 88 | #undef __OPENMP_AMDGCN__ |
| 89 | |
| 90 | // Define overloads otherwise which are absent |
| 91 | #define __DEVICE__ static constexpr __attribute__((always_inline, nothrow)) |
| 92 | |
| 93 | __DEVICE__ float acos(float __x) { return ::acosf(__x); } |
| 94 | __DEVICE__ float acosh(float __x) { return ::acoshf(__x); } |
| 95 | __DEVICE__ float asin(float __x) { return ::asinf(__x); } |
| 96 | __DEVICE__ float asinh(float __x) { return ::asinhf(__x); } |
| 97 | __DEVICE__ float atan(float __x) { return ::atanf(__x); } |
| 98 | __DEVICE__ float atan2(float __x, float __y) { return ::atan2f(__x, __y); } |
| 99 | __DEVICE__ float atanh(float __x) { return ::atanhf(__x); } |
| 100 | __DEVICE__ float cbrt(float __x) { return ::cbrtf(__x); } |
| 101 | __DEVICE__ float cosh(float __x) { return ::coshf(__x); } |
| 102 | __DEVICE__ float erf(float __x) { return ::erff(__x); } |
| 103 | __DEVICE__ float erfc(float __x) { return ::erfcf(__x); } |
| 104 | __DEVICE__ float exp2(float __x) { return ::exp2f(__x); } |
| 105 | __DEVICE__ float expm1(float __x) { return ::expm1f(__x); } |
| 106 | __DEVICE__ float fdim(float __x, float __y) { return ::fdimf(__x, __y); } |
| 107 | __DEVICE__ float hypot(float __x, float __y) { return ::hypotf(__x, __y); } |
| 108 | __DEVICE__ int ilogb(float __x) { return ::ilogbf(__x); } |
| 109 | __DEVICE__ float ldexp(float __arg, int __exp) { |
| 110 | return ::ldexpf(__arg, __exp); |
| 111 | } |
| 112 | __DEVICE__ float lgamma(float __x) { return ::lgammaf(__x); } |
| 113 | __DEVICE__ float log1p(float __x) { return ::log1pf(__x); } |
| 114 | __DEVICE__ float logb(float __x) { return ::logbf(__x); } |
| 115 | __DEVICE__ float nextafter(float __x, float __y) { |
| 116 | return ::nextafterf(__x, __y); |
| 117 | } |
| 118 | __DEVICE__ float remainder(float __x, float __y) { |
| 119 | return ::remainderf(__x, __y); |
| 120 | } |
| 121 | __DEVICE__ float scalbn(float __x, int __y) { return ::scalbnf(__x, __y); } |
| 122 | __DEVICE__ float sinh(float __x) { return ::sinhf(__x); } |
| 123 | __DEVICE__ float tan(float __x) { return ::tanf(__x); } |
| 124 | __DEVICE__ float tanh(float __x) { return ::tanhf(__x); } |
| 125 | __DEVICE__ float tgamma(float __x) { return ::tgammaf(__x); } |
| 126 | |
| 127 | #undef __DEVICE__ |
| 128 | |
| 129 | #pragma omp end declare variant |
| 130 | #endif // __AMDGCN__ |
| 131 | |
| 132 | #endif |