@@ -47,28 +47,9 @@ extern "C" {
47
47
#endif //__cplusplus
48
48
49
49
#if !defined(__HIPCC_RTC__ )
50
- #include <cmath>
51
- #include <cstdlib>
52
- #include <stdlib.h>
53
50
#if __has_include ("hip/hip_version.h" )
54
51
#include "hip/hip_version.h"
55
52
#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__
72
53
#endif // __HIPCC_RTC__
73
54
74
55
typedef __SIZE_TYPE__ __hip_size_t ;
@@ -78,11 +59,13 @@ extern "C" {
78
59
#endif //__cplusplus
79
60
80
61
#if HIP_VERSION_MAJOR * 100 + HIP_VERSION_MINOR >= 405
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 );
62
+ __device__ unsigned long long __ockl_dm_alloc (unsigned long long __size );
63
+ __device__ void __ockl_dm_dealloc (unsigned long long __addr );
83
64
#if __has_feature (address_sanitizer )
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 );
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 );
86
69
__attribute__((noinline , weak )) __device__ void * malloc (__hip_size_t __size ) {
87
70
unsigned long long __pc = (unsigned long long )__builtin_return_address (0 );
88
71
return (void * )__asan_malloc_impl (__size , __pc );
@@ -91,7 +74,7 @@ __attribute__((noinline, weak)) __device__ void free(void *__ptr) {
91
74
unsigned long long __pc = (unsigned long long )__builtin_return_address (0 );
92
75
__asan_free_impl ((unsigned long long )__ptr , __pc );
93
76
}
94
- #else
77
+ #else // __has_feature(address_sanitizer)
95
78
__attribute__((weak )) inline __device__ void * malloc (__hip_size_t __size ) {
96
79
return (void * ) __ockl_dm_alloc (__size );
97
80
}
@@ -109,21 +92,46 @@ __attribute__((weak)) inline __device__ void *malloc(__hip_size_t __size) {
109
92
__attribute__((weak )) inline __device__ void free (void * __ptr ) {
110
93
__hip_free (__ptr );
111
94
}
112
- #else
95
+ #else // __HIP_ENABLE_DEVICE_MALLOC__
113
96
__attribute__((weak )) inline __device__ void * malloc (__hip_size_t __size ) {
114
97
__builtin_trap ();
115
98
return (void * )0 ;
116
99
}
117
100
__attribute__((weak )) inline __device__ void free (void * __ptr ) {
118
101
__builtin_trap ();
119
102
}
120
- #endif
103
+ #endif // __HIP_ENABLE_DEVICE_MALLOC__
121
104
#endif // HIP version check
122
105
123
106
#ifdef __cplusplus
124
107
} // extern "C"
125
108
#endif //__cplusplus
126
109
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
+
127
135
#include <__clang_hip_libdevice_declares.h>
128
136
#include <__clang_hip_math.h>
129
137
#include <__clang_hip_stdlib.h>
0 commit comments