1*e038c9c4Sjoerg/*===-- __clang_openmp_device_functions.h - OpenMP math declares ------ c++ -=== 27330f729Sjoerg * 37330f729Sjoerg * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 47330f729Sjoerg * See https://llvm.org/LICENSE.txt for license information. 57330f729Sjoerg * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 67330f729Sjoerg * 77330f729Sjoerg *===-----------------------------------------------------------------------=== 87330f729Sjoerg */ 97330f729Sjoerg 10*e038c9c4Sjoerg#ifndef __CLANG_OPENMP_CMATH_H__ 11*e038c9c4Sjoerg#define __CLANG_OPENMP_CMATH_H__ 127330f729Sjoerg 13*e038c9c4Sjoerg#ifndef _OPENMP 14*e038c9c4Sjoerg#error "This file is for OpenMP compilation only." 15*e038c9c4Sjoerg#endif 16*e038c9c4Sjoerg 177330f729Sjoerg#include_next <cmath> 18*e038c9c4Sjoerg 19*e038c9c4Sjoerg// Make sure we include our math.h overlay, it probably happend already but we 20*e038c9c4Sjoerg// need to be sure. 21*e038c9c4Sjoerg#include <math.h> 22*e038c9c4Sjoerg 23*e038c9c4Sjoerg// We (might) need cstdlib because __clang_cuda_cmath.h below declares `abs` 24*e038c9c4Sjoerg// which might live in cstdlib. 25*e038c9c4Sjoerg#include <cstdlib> 26*e038c9c4Sjoerg 27*e038c9c4Sjoerg// We need limits because __clang_cuda_cmath.h below uses `std::numeric_limit`. 28*e038c9c4Sjoerg#include <limits> 29*e038c9c4Sjoerg 30*e038c9c4Sjoerg#pragma omp begin declare variant match( \ 31*e038c9c4Sjoerg device = {arch(nvptx, nvptx64)}, implementation = {extension(match_any, allow_templates)}) 32*e038c9c4Sjoerg 33*e038c9c4Sjoerg#define __CUDA__ 34*e038c9c4Sjoerg#define __OPENMP_NVPTX__ 35*e038c9c4Sjoerg#include <__clang_cuda_cmath.h> 36*e038c9c4Sjoerg#undef __OPENMP_NVPTX__ 37*e038c9c4Sjoerg#undef __CUDA__ 38*e038c9c4Sjoerg 39*e038c9c4Sjoerg// Overloads not provided by the CUDA wrappers but by the CUDA system headers. 40*e038c9c4Sjoerg// Since we do not include the latter we define them ourselves. 41*e038c9c4Sjoerg#define __DEVICE__ static constexpr __attribute__((always_inline, nothrow)) 42*e038c9c4Sjoerg 43*e038c9c4Sjoerg__DEVICE__ float acosh(float __x) { return ::acoshf(__x); } 44*e038c9c4Sjoerg__DEVICE__ float asinh(float __x) { return ::asinhf(__x); } 45*e038c9c4Sjoerg__DEVICE__ float atanh(float __x) { return ::atanhf(__x); } 46*e038c9c4Sjoerg__DEVICE__ float cbrt(float __x) { return ::cbrtf(__x); } 47*e038c9c4Sjoerg__DEVICE__ float erf(float __x) { return ::erff(__x); } 48*e038c9c4Sjoerg__DEVICE__ float erfc(float __x) { return ::erfcf(__x); } 49*e038c9c4Sjoerg__DEVICE__ float exp2(float __x) { return ::exp2f(__x); } 50*e038c9c4Sjoerg__DEVICE__ float expm1(float __x) { return ::expm1f(__x); } 51*e038c9c4Sjoerg__DEVICE__ float fdim(float __x, float __y) { return ::fdimf(__x, __y); } 52*e038c9c4Sjoerg__DEVICE__ float hypot(float __x, float __y) { return ::hypotf(__x, __y); } 53*e038c9c4Sjoerg__DEVICE__ int ilogb(float __x) { return ::ilogbf(__x); } 54*e038c9c4Sjoerg__DEVICE__ float lgamma(float __x) { return ::lgammaf(__x); } 55*e038c9c4Sjoerg__DEVICE__ long long int llrint(float __x) { return ::llrintf(__x); } 56*e038c9c4Sjoerg__DEVICE__ long long int llround(float __x) { return ::llroundf(__x); } 57*e038c9c4Sjoerg__DEVICE__ float log1p(float __x) { return ::log1pf(__x); } 58*e038c9c4Sjoerg__DEVICE__ float log2(float __x) { return ::log2f(__x); } 59*e038c9c4Sjoerg__DEVICE__ float logb(float __x) { return ::logbf(__x); } 60*e038c9c4Sjoerg__DEVICE__ long int lrint(float __x) { return ::lrintf(__x); } 61*e038c9c4Sjoerg__DEVICE__ long int lround(float __x) { return ::lroundf(__x); } 62*e038c9c4Sjoerg__DEVICE__ float nextafter(float __x, float __y) { 63*e038c9c4Sjoerg return ::nextafterf(__x, __y); 64*e038c9c4Sjoerg} 65*e038c9c4Sjoerg__DEVICE__ float remainder(float __x, float __y) { 66*e038c9c4Sjoerg return ::remainderf(__x, __y); 67*e038c9c4Sjoerg} 68*e038c9c4Sjoerg__DEVICE__ float scalbln(float __x, long int __y) { 69*e038c9c4Sjoerg return ::scalblnf(__x, __y); 70*e038c9c4Sjoerg} 71*e038c9c4Sjoerg__DEVICE__ float scalbn(float __x, int __y) { return ::scalbnf(__x, __y); } 72*e038c9c4Sjoerg__DEVICE__ float tgamma(float __x) { return ::tgammaf(__x); } 73*e038c9c4Sjoerg 74*e038c9c4Sjoerg#undef __DEVICE__ 75*e038c9c4Sjoerg 76*e038c9c4Sjoerg#pragma omp end declare variant 77*e038c9c4Sjoerg 787330f729Sjoerg#endif 79