62 lines · c
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-exception6 *7 *===-----------------------------------------------------------------------===8 */9 10// If we are in C++ mode and include <math.h> (not <cmath>) first, we still need11// to make sure <cmath> is read first. The problem otherwise is that we haven't12// seen the declarations of the math.h functions when the system math.h includes13// our cmath overlay. However, our cmath overlay, or better the underlying14// overlay, e.g. CUDA, uses the math.h functions. Since we haven't declared them15// yet we get errors. CUDA avoids this by eagerly declaring all math functions16// (in the __device__ space) but we cannot do this. Instead we break the17// dependence by forcing cmath to go first. While our cmath will in turn include18// this file, the cmath guards will prevent recursion.19#ifdef __cplusplus20#include <cmath>21#endif22 23#ifndef __CLANG_OPENMP_MATH_H__24#define __CLANG_OPENMP_MATH_H__25 26#ifndef _OPENMP27#error "This file is for OpenMP compilation only."28#endif29 30#include_next <math.h>31 32// We need limits.h for __clang_cuda_math.h below and because it should not hurt33// 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 variant50 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 variant59#endif60 61#endif62