1 /*===---- __clang_hip_runtime_wrapper.h - HIP runtime support ---------------===
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 /*
11  * WARNING: This header is intended to be directly -include'd by
12  * the compiler and is not supposed to be included by users.
13  *
14  */
15 
16 #ifndef __CLANG_HIP_RUNTIME_WRAPPER_H__
17 #define __CLANG_HIP_RUNTIME_WRAPPER_H__
18 
19 #if __HIP__
20 
21 #include <cmath>
22 #include <cstdlib>
23 #include <stdlib.h>
24 
25 #define __host__ __attribute__((host))
26 #define __device__ __attribute__((device))
27 #define __global__ __attribute__((global))
28 #define __shared__ __attribute__((shared))
29 #define __constant__ __attribute__((constant))
30 
31 #if !defined(__cplusplus) || __cplusplus < 201103L
32   #define nullptr NULL;
33 #endif
34 
35 #if __HIP_ENABLE_DEVICE_MALLOC__
36 extern "C" __device__ void *__hip_malloc(size_t __size);
37 extern "C" __device__ void *__hip_free(void *__ptr);
malloc(size_t __size)38 static inline __device__ void *malloc(size_t __size) {
39   return __hip_malloc(__size);
40 }
free(void * __ptr)41 static inline __device__ void *free(void *__ptr) { return __hip_free(__ptr); }
42 #else
malloc(size_t __size)43 static inline __device__ void *malloc(size_t __size) {
44   __builtin_trap();
45   return nullptr;
46 }
free(void * __ptr)47 static inline __device__ void *free(void *__ptr) {
48   __builtin_trap();
49   return nullptr;
50 }
51 #endif
52 
53 #include <__clang_hip_libdevice_declares.h>
54 #include <__clang_hip_math.h>
55 
56 #if !_OPENMP || __HIP_ENABLE_CUDA_WRAPPER_FOR_OPENMP__
57 #include <__clang_cuda_math_forward_declares.h>
58 #include <__clang_hip_cmath.h>
59 #include <__clang_cuda_complex_builtins.h>
60 
61 #include <algorithm>
62 #include <complex>
63 #include <new>
64 #endif // !_OPENMP || __HIP_ENABLE_CUDA_WRAPPER_FOR_OPENMP__
65 
66 #define __CLANG_HIP_RUNTIME_WRAPPER_INCLUDED__ 1
67 
68 #endif // __HIP__
69 #endif // __CLANG_HIP_RUNTIME_WRAPPER_H__
70