@@ -47,9 +47,28 @@ extern "C" {
47
47
#endif //__cplusplus
48
48
49
49
#if !defined(__HIPCC_RTC__ )
50
+ #include <cmath>
51
+ #include <cstdlib>
52
+ #include <stdlib.h>
50
53
#if __has_include ("hip/hip_version.h" )
51
54
#include "hip/hip_version.h"
52
55
#endif // __has_include("hip/hip_version.h")
56
+ #else
57
+ typedef __SIZE_TYPE__ size_t ;
58
+ // Define macros which are needed to declare HIP device API's without standard
59
+ // C/C++ headers. This is for readability so that these API's can be written
60
+ // the same way as non-hipRTC use case. These macros need to be popped so that
61
+ // they do not pollute users' name space.
62
+ #pragma push_macro("NULL")
63
+ #pragma push_macro("uint32_t")
64
+ #pragma push_macro("uint64_t")
65
+ #pragma push_macro("CHAR_BIT")
66
+ #pragma push_macro("INT_MAX")
67
+ #define NULL (void *)0
68
+ #define uint32_t __UINT32_TYPE__
69
+ #define uint64_t __UINT64_TYPE__
70
+ #define CHAR_BIT __CHAR_BIT__
71
+ #define INT_MAX __INTMAX_MAX__
53
72
#endif // __HIPCC_RTC__
54
73
55
74
typedef __SIZE_TYPE__ __hip_size_t ;
@@ -59,13 +78,11 @@ extern "C" {
59
78
#endif //__cplusplus
60
79
61
80
#if HIP_VERSION_MAJOR * 100 + HIP_VERSION_MINOR >= 405
62
- __device__ unsigned long long __ockl_dm_alloc (unsigned long long __size );
63
- __device__ void __ockl_dm_dealloc (unsigned long long __addr );
81
+ extern "C" __device__ unsigned long long __ockl_dm_alloc (unsigned long long __size );
82
+ extern "C" __device__ void __ockl_dm_dealloc (unsigned long long __addr );
64
83
#if __has_feature (address_sanitizer )
65
- __device__ unsigned long long __asan_malloc_impl (unsigned long long __size ,
66
- unsigned long long __pc );
67
- __device__ void __asan_free_impl (unsigned long long __addr ,
68
- unsigned long long __pc );
84
+ extern "C" __device__ unsigned long long __asan_malloc_impl (unsigned long long __size , unsigned long long __pc );
85
+ extern "C" __device__ void __asan_free_impl (unsigned long long __addr , unsigned long long __pc );
69
86
__attribute__((noinline , weak )) __device__ void * malloc (__hip_size_t __size ) {
70
87
unsigned long long __pc = (unsigned long long )__builtin_return_address (0 );
71
88
return (void * )__asan_malloc_impl (__size , __pc );
@@ -74,7 +91,7 @@ __attribute__((noinline, weak)) __device__ void free(void *__ptr) {
74
91
unsigned long long __pc = (unsigned long long )__builtin_return_address (0 );
75
92
__asan_free_impl ((unsigned long long )__ptr , __pc );
76
93
}
77
- #else // __has_feature(address_sanitizer)
94
+ #else
78
95
__attribute__((weak )) inline __device__ void * malloc (__hip_size_t __size ) {
79
96
return (void * ) __ockl_dm_alloc (__size );
80
97
}
@@ -92,46 +109,21 @@ __attribute__((weak)) inline __device__ void *malloc(__hip_size_t __size) {
92
109
__attribute__((weak )) inline __device__ void free (void * __ptr ) {
93
110
__hip_free (__ptr );
94
111
}
95
- #else // __HIP_ENABLE_DEVICE_MALLOC__
112
+ #else
96
113
__attribute__((weak )) inline __device__ void * malloc (__hip_size_t __size ) {
97
114
__builtin_trap ();
98
115
return (void * )0 ;
99
116
}
100
117
__attribute__((weak )) inline __device__ void free (void * __ptr ) {
101
118
__builtin_trap ();
102
119
}
103
- #endif // __HIP_ENABLE_DEVICE_MALLOC__
120
+ #endif
104
121
#endif // HIP version check
105
122
106
123
#ifdef __cplusplus
107
124
} // extern "C"
108
125
#endif //__cplusplus
109
126
110
- #if !defined(__HIPCC_RTC__ )
111
- #include <cmath>
112
- #include <cstdlib>
113
- #include <stdlib.h>
114
- #if __has_include ("hip/hip_version.h" )
115
- #include "hip/hip_version.h"
116
- #endif // __has_include("hip/hip_version.h")
117
- #else
118
- typedef __SIZE_TYPE__ size_t ;
119
- // Define macros which are needed to declare HIP device API's without standard
120
- // C/C++ headers. This is for readability so that these API's can be written
121
- // the same way as non-hipRTC use case. These macros need to be popped so that
122
- // they do not pollute users' name space.
123
- #pragma push_macro("NULL")
124
- #pragma push_macro("uint32_t")
125
- #pragma push_macro("uint64_t")
126
- #pragma push_macro("CHAR_BIT")
127
- #pragma push_macro("INT_MAX")
128
- #define NULL (void *)0
129
- #define uint32_t __UINT32_TYPE__
130
- #define uint64_t __UINT64_TYPE__
131
- #define CHAR_BIT __CHAR_BIT__
132
- #define INT_MAX __INTMAX_MAX__
133
- #endif // __HIPCC_RTC__
134
-
135
127
#include <__clang_hip_libdevice_declares.h>
136
128
#include <__clang_hip_math.h>
137
129
#include <__clang_hip_stdlib.h>
0 commit comments