1 /*===---- new - CUDA wrapper for <new> -------------------------------------===
3 * Permission is hereby granted, free of charge, to any person obtaining a copy
4 * of this software and associated documentation files (the "Software"), to deal
5 * in the Software without restriction, including without limitation the rights
6 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 * copies of the Software, and to permit persons to whom the Software is
8 * furnished to do so, subject to the following conditions:
10 * The above copyright notice and this permission notice shall be included in
11 * all copies or substantial portions of the Software.
13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 *===-----------------------------------------------------------------------===
24 #ifndef __CLANG_CUDA_WRAPPERS_NEW
25 #define __CLANG_CUDA_WRAPPERS_NEW
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
36 #pragma push_macro("CUDA_NOEXCEPT")
37 #if __cplusplus >= 201103L
38 #define CUDA_NOEXCEPT noexcept
43 // Device overrides for non-placement new and delete.
44 __device__ inline void *operator new(__SIZE_TYPE__ size) {
48 return ::malloc(size);
50 __device__ inline void *operator new(__SIZE_TYPE__ size,
51 const std::nothrow_t &) CUDA_NOEXCEPT {
52 return ::operator new(size);
55 __device__ inline void *operator new[](__SIZE_TYPE__ size) {
56 return ::operator new(size);
58 __device__ inline void *operator new[](__SIZE_TYPE__ size,
59 const std::nothrow_t &) {
60 return ::operator new(size);
63 __device__ inline void operator delete(void* ptr) CUDA_NOEXCEPT {
68 __device__ inline void operator delete(void *ptr,
69 const std::nothrow_t &) CUDA_NOEXCEPT {
70 ::operator delete(ptr);
73 __device__ inline void operator delete[](void* ptr) CUDA_NOEXCEPT {
74 ::operator delete(ptr);
76 __device__ inline void operator delete[](void *ptr,
77 const std::nothrow_t &) CUDA_NOEXCEPT {
78 ::operator delete(ptr);
81 // Sized delete, C++14 only.
82 #if __cplusplus >= 201402L
83 __device__ inline void operator delete(void *ptr,
84 __SIZE_TYPE__ size) CUDA_NOEXCEPT {
85 ::operator delete(ptr);
87 __device__ inline void operator delete[](void *ptr,
88 __SIZE_TYPE__ size) CUDA_NOEXCEPT {
89 ::operator delete(ptr);
93 // Device overrides for placement new and delete.
94 #if !(_LIBCPP_STD_VER >= 26 || __cpp_lib_constexpr_new >= 202406L)
95 __device__ inline void *operator new(__SIZE_TYPE__, void *__ptr) CUDA_NOEXCEPT {
98 __device__ inline void *operator new[](__SIZE_TYPE__, void *__ptr) CUDA_NOEXCEPT {
102 __device__ inline void operator delete(void *, void *) CUDA_NOEXCEPT {}
103 __device__ inline void operator delete[](void *, void *) CUDA_NOEXCEPT {}
105 #pragma pop_macro("CUDA_NOEXCEPT")
108 #endif // include guard