|
33 | 33 | #define CUDA_NOEXCEPT
|
34 | 34 | #endif
|
35 | 35 |
|
| 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 | + |
36 | 45 | // Device overrides for non-placement new and delete.
|
37 |
| -__device__ inline void *operator new(__SIZE_TYPE__ size) { |
| 46 | +__DEVICE__ inline void *operator new(__SIZE_TYPE__ size) { |
38 | 47 | if (size == 0) {
|
39 | 48 | size = 1;
|
40 | 49 | }
|
41 | 50 | return ::malloc(size);
|
42 | 51 | }
|
43 |
| -__device__ inline void *operator new(__SIZE_TYPE__ size, |
| 52 | +__DEVICE__ inline void *operator new(__SIZE_TYPE__ size, |
44 | 53 | const std::nothrow_t &) CUDA_NOEXCEPT {
|
45 | 54 | return ::operator new(size);
|
46 | 55 | }
|
47 | 56 |
|
48 |
| -__device__ inline void *operator new[](__SIZE_TYPE__ size) { |
| 57 | +__DEVICE__ inline void *operator new[](__SIZE_TYPE__ size) { |
49 | 58 | return ::operator new(size);
|
50 | 59 | }
|
51 |
| -__device__ inline void *operator new[](__SIZE_TYPE__ size, |
| 60 | +__DEVICE__ inline void *operator new[](__SIZE_TYPE__ size, |
52 | 61 | const std::nothrow_t &) {
|
53 | 62 | return ::operator new(size);
|
54 | 63 | }
|
55 | 64 |
|
56 |
| -__device__ inline void operator delete(void* ptr) CUDA_NOEXCEPT { |
| 65 | +__DEVICE__ inline void operator delete(void* ptr) CUDA_NOEXCEPT { |
57 | 66 | if (ptr) {
|
58 | 67 | ::free(ptr);
|
59 | 68 | }
|
60 | 69 | }
|
61 |
| -__device__ inline void operator delete(void *ptr, |
| 70 | +__DEVICE__ inline void operator delete(void *ptr, |
62 | 71 | const std::nothrow_t &) CUDA_NOEXCEPT {
|
63 | 72 | ::operator delete(ptr);
|
64 | 73 | }
|
65 | 74 |
|
66 |
| -__device__ inline void operator delete[](void* ptr) CUDA_NOEXCEPT { |
| 75 | +__DEVICE__ inline void operator delete[](void* ptr) CUDA_NOEXCEPT { |
67 | 76 | ::operator delete(ptr);
|
68 | 77 | }
|
69 |
| -__device__ inline void operator delete[](void *ptr, |
| 78 | +__DEVICE__ inline void operator delete[](void *ptr, |
70 | 79 | const std::nothrow_t &) CUDA_NOEXCEPT {
|
71 | 80 | ::operator delete(ptr);
|
72 | 81 | }
|
73 | 82 |
|
74 | 83 | // Sized delete, C++14 only.
|
75 | 84 | #if __cplusplus >= 201402L
|
76 |
| -__device__ inline void operator delete(void *ptr, |
| 85 | +__DEVICE__ inline void operator delete(void *ptr, |
77 | 86 | __SIZE_TYPE__ size) CUDA_NOEXCEPT {
|
78 | 87 | ::operator delete(ptr);
|
79 | 88 | }
|
80 |
| -__device__ inline void operator delete[](void *ptr, |
| 89 | +__DEVICE__ inline void operator delete[](void *ptr, |
81 | 90 | __SIZE_TYPE__ size) CUDA_NOEXCEPT {
|
82 | 91 | ::operator delete(ptr);
|
83 | 92 | }
|
84 | 93 | #endif
|
85 | 94 |
|
86 | 95 | // Device overrides for placement new and delete.
|
87 |
| -__device__ inline void *operator new(__SIZE_TYPE__, void *__ptr) CUDA_NOEXCEPT { |
| 96 | +__DEVICE__ inline void *operator new(__SIZE_TYPE__, void *__ptr) CUDA_NOEXCEPT { |
88 | 97 | return __ptr;
|
89 | 98 | }
|
90 |
| -__device__ inline void *operator new[](__SIZE_TYPE__, void *__ptr) CUDA_NOEXCEPT { |
| 99 | +__DEVICE__ inline void *operator new[](__SIZE_TYPE__, void *__ptr) CUDA_NOEXCEPT { |
91 | 100 | return __ptr;
|
92 | 101 | }
|
93 |
| -__device__ inline void operator delete(void *, void *) CUDA_NOEXCEPT {} |
94 |
| -__device__ inline void operator delete[](void *, void *) CUDA_NOEXCEPT {} |
| 102 | +__DEVICE__ inline void operator delete(void *, void *) CUDA_NOEXCEPT {} |
| 103 | +__DEVICE__ inline void operator delete[](void *, void *) CUDA_NOEXCEPT {} |
95 | 104 |
|
| 105 | +#pragma pop_macro("__DEVICE__") |
96 | 106 | #pragma pop_macro("CUDA_NOEXCEPT")
|
97 | 107 |
|
98 | 108 | #endif // include guard
|
0 commit comments