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 #if !defined(__HIPCC_RTC__) 22 #include <cmath> 23 #include <cstdlib> 24 #include <stdlib.h> 25 #else 26 typedef __SIZE_TYPE__ size_t; 27 // Define macros which are needed to declare HIP device API's without standard 28 // C/C++ headers. This is for readability so that these API's can be written 29 // the same way as non-hipRTC use case. These macros need to be popped so that 30 // they do not pollute users' name space. 31 #pragma push_macro("NULL") 32 #pragma push_macro("uint32_t") 33 #pragma push_macro("uint64_t") 34 #pragma push_macro("CHAR_BIT") 35 #pragma push_macro("INT_MAX") 36 #define NULL (void *)0 37 #define uint32_t __UINT32_TYPE__ 38 #define uint64_t __UINT64_TYPE__ 39 #define CHAR_BIT __CHAR_BIT__ 40 #define INT_MAX __INTMAX_MAX__ 41 #endif // __HIPCC_RTC__ 42 43 #define __host__ __attribute__((host)) 44 #define __device__ __attribute__((device)) 45 #define __global__ __attribute__((global)) 46 #define __shared__ __attribute__((shared)) 47 #define __constant__ __attribute__((constant)) 48 #define __managed__ __attribute__((managed)) 49 50 #if !defined(__cplusplus) || __cplusplus < 201103L 51 #define nullptr NULL; 52 #endif 53 54 #if __HIP_ENABLE_DEVICE_MALLOC__ 55 extern "C" __device__ void *__hip_malloc(size_t __size); 56 extern "C" __device__ void *__hip_free(void *__ptr); malloc(size_t __size)57static inline __device__ void *malloc(size_t __size) { 58 return __hip_malloc(__size); 59 } free(void * __ptr)60static inline __device__ void *free(void *__ptr) { return __hip_free(__ptr); } 61 #else malloc(size_t __size)62static inline __device__ void *malloc(size_t __size) { 63 __builtin_trap(); 64 return nullptr; 65 } free(void * __ptr)66static inline __device__ void *free(void *__ptr) { 67 __builtin_trap(); 68 return nullptr; 69 } 70 #endif 71 72 #include <__clang_hip_libdevice_declares.h> 73 #include <__clang_hip_math.h> 74 75 #if !_OPENMP || __HIP_ENABLE_CUDA_WRAPPER_FOR_OPENMP__ 76 #if defined(__HIPCC_RTC__) 77 #include <__clang_hip_cmath.h> 78 #else 79 #include <__clang_cuda_math_forward_declares.h> 80 #include <__clang_hip_cmath.h> 81 #include <__clang_cuda_complex_builtins.h> 82 #include <algorithm> 83 #include <complex> 84 #include <new> 85 #endif // __HIPCC_RTC__ 86 #endif // !_OPENMP || __HIP_ENABLE_CUDA_WRAPPER_FOR_OPENMP__ 87 88 #define __CLANG_HIP_RUNTIME_WRAPPER_INCLUDED__ 1 89 #if defined(__HIPCC_RTC__) 90 #pragma pop_macro("NULL") 91 #pragma pop_macro("uint32_t") 92 #pragma pop_macro("uint64_t") 93 #pragma pop_macro("CHAR_BIT") 94 #pragma pop_macro("INT_MAX") 95 #endif // __HIPCC_RTC__ 96 #endif // __HIP__ 97 #endif // __CLANG_HIP_RUNTIME_WRAPPER_H__ 98