1 /*===---- openmp_wrapper/math.h -------- OpenMP math.h intercept ------ c++ -===
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
7 *===-----------------------------------------------------------------------===
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.
23 #ifndef __CLANG_OPENMP_MATH_H__
24 #define __CLANG_OPENMP_MATH_H__
27 #error "This file is for OpenMP compilation only."
30 #include_next <math.h>
32 // We need limits.h for __clang_cuda_math.h below and because it should not hurt
33 // we include it eagerly here.
36 // We need stdlib.h because (for now) __clang_cuda_math.h below declares `abs`
37 // which should live in stdlib.h.
40 #pragma omp begin declare variant match( \
41 device = {arch(nvptx, nvptx64)}, implementation = {extension(match_any)})
44 #define __OPENMP_NVPTX__
45 #include <__clang_cuda_math.h>
46 #undef __OPENMP_NVPTX__
49 #pragma omp end declare variant
52 #pragma omp begin declare variant match(device = {arch(amdgcn)})
54 #define __OPENMP_AMDGCN__
55 #include <__clang_hip_math.h>
56 #undef __OPENMP_AMDGCN__
58 #pragma omp end declare variant