|
26 | 26 |
|
27 | 27 | #include_next <new>
|
28 | 28 |
|
| 29 | +#if !defined(__device__) |
| 30 | +// The header has been included too early from the standard C++ library |
| 31 | +// and CUDA-specific macros are not available yet. |
| 32 | +// Undo the include guard and try again later. |
| 33 | +#undef __CLANG_CUDA_WRAPPERS_NEW |
| 34 | +#else |
| 35 | + |
29 | 36 | #pragma push_macro("CUDA_NOEXCEPT")
|
30 | 37 | #if __cplusplus >= 201103L
|
31 | 38 | #define CUDA_NOEXCEPT noexcept
|
32 | 39 | #else
|
33 | 40 | #define CUDA_NOEXCEPT
|
34 | 41 | #endif
|
35 | 42 |
|
36 |
| -#pragma push_macro("__DEVICE__") |
37 |
| -#if defined __device__ |
38 |
| -#define __DEVICE__ __device__ |
39 |
| -#else |
40 |
| -// <new> has been included too early from the standard libc++ headers and the |
41 |
| -// standard CUDA macros are not available yet. We have to define our own. |
42 |
| -#define __DEVICE__ __attribute__((device)) |
43 |
| -#endif |
44 |
| - |
45 | 43 | // Device overrides for non-placement new and delete.
|
46 |
| -__DEVICE__ inline void *operator new(__SIZE_TYPE__ size) { |
| 44 | +__device__ inline void *operator new(__SIZE_TYPE__ size) { |
47 | 45 | if (size == 0) {
|
48 | 46 | size = 1;
|
49 | 47 | }
|
50 | 48 | return ::malloc(size);
|
51 | 49 | }
|
52 |
| -__DEVICE__ inline void *operator new(__SIZE_TYPE__ size, |
| 50 | +__device__ inline void *operator new(__SIZE_TYPE__ size, |
53 | 51 | const std::nothrow_t &) CUDA_NOEXCEPT {
|
54 | 52 | return ::operator new(size);
|
55 | 53 | }
|
56 | 54 |
|
57 |
| -__DEVICE__ inline void *operator new[](__SIZE_TYPE__ size) { |
| 55 | +__device__ inline void *operator new[](__SIZE_TYPE__ size) { |
58 | 56 | return ::operator new(size);
|
59 | 57 | }
|
60 |
| -__DEVICE__ inline void *operator new[](__SIZE_TYPE__ size, |
| 58 | +__device__ inline void *operator new[](__SIZE_TYPE__ size, |
61 | 59 | const std::nothrow_t &) {
|
62 | 60 | return ::operator new(size);
|
63 | 61 | }
|
64 | 62 |
|
65 |
| -__DEVICE__ inline void operator delete(void* ptr) CUDA_NOEXCEPT { |
| 63 | +__device__ inline void operator delete(void* ptr) CUDA_NOEXCEPT { |
66 | 64 | if (ptr) {
|
67 | 65 | ::free(ptr);
|
68 | 66 | }
|
69 | 67 | }
|
70 |
| -__DEVICE__ inline void operator delete(void *ptr, |
| 68 | +__device__ inline void operator delete(void *ptr, |
71 | 69 | const std::nothrow_t &) CUDA_NOEXCEPT {
|
72 | 70 | ::operator delete(ptr);
|
73 | 71 | }
|
74 | 72 |
|
75 |
| -__DEVICE__ inline void operator delete[](void* ptr) CUDA_NOEXCEPT { |
| 73 | +__device__ inline void operator delete[](void* ptr) CUDA_NOEXCEPT { |
76 | 74 | ::operator delete(ptr);
|
77 | 75 | }
|
78 |
| -__DEVICE__ inline void operator delete[](void *ptr, |
| 76 | +__device__ inline void operator delete[](void *ptr, |
79 | 77 | const std::nothrow_t &) CUDA_NOEXCEPT {
|
80 | 78 | ::operator delete(ptr);
|
81 | 79 | }
|
82 | 80 |
|
83 | 81 | // Sized delete, C++14 only.
|
84 | 82 | #if __cplusplus >= 201402L
|
85 |
| -__DEVICE__ inline void operator delete(void *ptr, |
| 83 | +__device__ inline void operator delete(void *ptr, |
86 | 84 | __SIZE_TYPE__ size) CUDA_NOEXCEPT {
|
87 | 85 | ::operator delete(ptr);
|
88 | 86 | }
|
89 |
| -__DEVICE__ inline void operator delete[](void *ptr, |
| 87 | +__device__ inline void operator delete[](void *ptr, |
90 | 88 | __SIZE_TYPE__ size) CUDA_NOEXCEPT {
|
91 | 89 | ::operator delete(ptr);
|
92 | 90 | }
|
93 | 91 | #endif
|
94 | 92 |
|
95 | 93 | // Device overrides for placement new and delete.
|
96 |
| -__DEVICE__ inline void *operator new(__SIZE_TYPE__, void *__ptr) CUDA_NOEXCEPT { |
| 94 | +__device__ inline void *operator new(__SIZE_TYPE__, void *__ptr) CUDA_NOEXCEPT { |
97 | 95 | return __ptr;
|
98 | 96 | }
|
99 |
| -__DEVICE__ inline void *operator new[](__SIZE_TYPE__, void *__ptr) CUDA_NOEXCEPT { |
| 97 | +__device__ inline void *operator new[](__SIZE_TYPE__, void *__ptr) CUDA_NOEXCEPT { |
100 | 98 | return __ptr;
|
101 | 99 | }
|
102 |
| -__DEVICE__ inline void operator delete(void *, void *) CUDA_NOEXCEPT {} |
103 |
| -__DEVICE__ inline void operator delete[](void *, void *) CUDA_NOEXCEPT {} |
| 100 | +__device__ inline void operator delete(void *, void *) CUDA_NOEXCEPT {} |
| 101 | +__device__ inline void operator delete[](void *, void *) CUDA_NOEXCEPT {} |
104 | 102 |
|
105 |
| -#pragma pop_macro("__DEVICE__") |
106 | 103 | #pragma pop_macro("CUDA_NOEXCEPT")
|
107 | 104 |
|
| 105 | +#endif // __device__ |
108 | 106 | #endif // include guard
|
0 commit comments