1*bed243d3SAndroid Build Coastguard Worker /*===---- openmp_wrapper/math.h -------- OpenMP math.h intercept ------ c++ -=== 2*bed243d3SAndroid Build Coastguard Worker * 3*bed243d3SAndroid Build Coastguard Worker * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4*bed243d3SAndroid Build Coastguard Worker * See https://llvm.org/LICENSE.txt for license information. 5*bed243d3SAndroid Build Coastguard Worker * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6*bed243d3SAndroid Build Coastguard Worker * 7*bed243d3SAndroid Build Coastguard Worker *===-----------------------------------------------------------------------=== 8*bed243d3SAndroid Build Coastguard Worker */ 9*bed243d3SAndroid Build Coastguard Worker 10*bed243d3SAndroid Build Coastguard Worker // If we are in C++ mode and include <math.h> (not <cmath>) first, we still need 11*bed243d3SAndroid Build Coastguard Worker // to make sure <cmath> is read first. The problem otherwise is that we haven't 12*bed243d3SAndroid Build Coastguard Worker // seen the declarations of the math.h functions when the system math.h includes 13*bed243d3SAndroid Build Coastguard Worker // our cmath overlay. However, our cmath overlay, or better the underlying 14*bed243d3SAndroid Build Coastguard Worker // overlay, e.g. CUDA, uses the math.h functions. Since we haven't declared them 15*bed243d3SAndroid Build Coastguard Worker // yet we get errors. CUDA avoids this by eagerly declaring all math functions 16*bed243d3SAndroid Build Coastguard Worker // (in the __device__ space) but we cannot do this. Instead we break the 17*bed243d3SAndroid Build Coastguard Worker // dependence by forcing cmath to go first. While our cmath will in turn include 18*bed243d3SAndroid Build Coastguard Worker // this file, the cmath guards will prevent recursion. 19*bed243d3SAndroid Build Coastguard Worker #ifdef __cplusplus 20*bed243d3SAndroid Build Coastguard Worker #include <cmath> 21*bed243d3SAndroid Build Coastguard Worker #endif 22*bed243d3SAndroid Build Coastguard Worker 23*bed243d3SAndroid Build Coastguard Worker #ifndef __CLANG_OPENMP_MATH_H__ 24*bed243d3SAndroid Build Coastguard Worker #define __CLANG_OPENMP_MATH_H__ 25*bed243d3SAndroid Build Coastguard Worker 26*bed243d3SAndroid Build Coastguard Worker #ifndef _OPENMP 27*bed243d3SAndroid Build Coastguard Worker #error "This file is for OpenMP compilation only." 28*bed243d3SAndroid Build Coastguard Worker #endif 29*bed243d3SAndroid Build Coastguard Worker 30*bed243d3SAndroid Build Coastguard Worker #include_next <math.h> 31*bed243d3SAndroid Build Coastguard Worker 32*bed243d3SAndroid Build Coastguard Worker // We need limits.h for __clang_cuda_math.h below and because it should not hurt 33*bed243d3SAndroid Build Coastguard Worker // we include it eagerly here. 34*bed243d3SAndroid Build Coastguard Worker #include <limits.h> 35*bed243d3SAndroid Build Coastguard Worker 36*bed243d3SAndroid Build Coastguard Worker // We need stdlib.h because (for now) __clang_cuda_math.h below declares `abs` 37*bed243d3SAndroid Build Coastguard Worker // which should live in stdlib.h. 38*bed243d3SAndroid Build Coastguard Worker #include <stdlib.h> 39*bed243d3SAndroid Build Coastguard Worker 40*bed243d3SAndroid Build Coastguard Worker #pragma omp begin declare variant match( \ 41*bed243d3SAndroid Build Coastguard Worker device = {arch(nvptx, nvptx64)}, implementation = {extension(match_any)}) 42*bed243d3SAndroid Build Coastguard Worker 43*bed243d3SAndroid Build Coastguard Worker #define __CUDA__ 44*bed243d3SAndroid Build Coastguard Worker #define __OPENMP_NVPTX__ 45*bed243d3SAndroid Build Coastguard Worker #include <__clang_cuda_math.h> 46*bed243d3SAndroid Build Coastguard Worker #undef __OPENMP_NVPTX__ 47*bed243d3SAndroid Build Coastguard Worker #undef __CUDA__ 48*bed243d3SAndroid Build Coastguard Worker 49*bed243d3SAndroid Build Coastguard Worker #pragma omp end declare variant 50*bed243d3SAndroid Build Coastguard Worker 51*bed243d3SAndroid Build Coastguard Worker #ifdef __AMDGCN__ 52*bed243d3SAndroid Build Coastguard Worker #pragma omp begin declare variant match(device = {arch(amdgcn)}) 53*bed243d3SAndroid Build Coastguard Worker 54*bed243d3SAndroid Build Coastguard Worker #define __OPENMP_AMDGCN__ 55*bed243d3SAndroid Build Coastguard Worker #include <__clang_hip_math.h> 56*bed243d3SAndroid Build Coastguard Worker #undef __OPENMP_AMDGCN__ 57*bed243d3SAndroid Build Coastguard Worker 58*bed243d3SAndroid Build Coastguard Worker #pragma omp end declare variant 59*bed243d3SAndroid Build Coastguard Worker #endif 60*bed243d3SAndroid Build Coastguard Worker 61*bed243d3SAndroid Build Coastguard Worker #endif 62