Johannes Doerfert | f85ae05 | 2020-03-27 20:36:30 -0500 | [diff] [blame] | 1 | /*===---- openmp_wrapper/math.h -------- OpenMP math.h intercept ------ c++ -=== |
Gheorghe-Teodor Bercea | e62c693 | 2019-05-08 15:52:33 +0000 | [diff] [blame] | 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 | |
Johannes Doerfert | 17d8334 | 2020-04-09 22:10:16 -0500 | [diff] [blame] | 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 | |
Johannes Doerfert | f85ae05 | 2020-03-27 20:36:30 -0500 | [diff] [blame] | 23 | #ifndef __CLANG_OPENMP_MATH_H__ |
| 24 | #define __CLANG_OPENMP_MATH_H__ |
Gheorghe-Teodor Bercea | e62c693 | 2019-05-08 15:52:33 +0000 | [diff] [blame] | 25 | |
Johannes Doerfert | f85ae05 | 2020-03-27 20:36:30 -0500 | [diff] [blame] | 26 | #ifndef _OPENMP |
| 27 | #error "This file is for OpenMP compilation only." |
Gheorghe-Teodor Bercea | e62c693 | 2019-05-08 15:52:33 +0000 | [diff] [blame] | 28 | #endif |
| 29 | |
Johannes Doerfert | f85ae05 | 2020-03-27 20:36:30 -0500 | [diff] [blame] | 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 | #include <__clang_cuda_math.h> |
| 45 | #undef __CUDA__ |
| 46 | |
| 47 | #pragma omp end declare variant |
| 48 | |
| 49 | #endif |