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