1*bed243d3SAndroid Build Coastguard Worker/*===---- new - CUDA wrapper for <new> -------------------------------------=== 2*bed243d3SAndroid Build Coastguard Worker * 3*bed243d3SAndroid Build Coastguard Worker * Permission is hereby granted, free of charge, to any person obtaining a copy 4*bed243d3SAndroid Build Coastguard Worker * of this software and associated documentation files (the "Software"), to deal 5*bed243d3SAndroid Build Coastguard Worker * in the Software without restriction, including without limitation the rights 6*bed243d3SAndroid Build Coastguard Worker * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7*bed243d3SAndroid Build Coastguard Worker * copies of the Software, and to permit persons to whom the Software is 8*bed243d3SAndroid Build Coastguard Worker * furnished to do so, subject to the following conditions: 9*bed243d3SAndroid Build Coastguard Worker * 10*bed243d3SAndroid Build Coastguard Worker * The above copyright notice and this permission notice shall be included in 11*bed243d3SAndroid Build Coastguard Worker * all copies or substantial portions of the Software. 12*bed243d3SAndroid Build Coastguard Worker * 13*bed243d3SAndroid Build Coastguard Worker * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14*bed243d3SAndroid Build Coastguard Worker * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15*bed243d3SAndroid Build Coastguard Worker * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16*bed243d3SAndroid Build Coastguard Worker * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17*bed243d3SAndroid Build Coastguard Worker * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18*bed243d3SAndroid Build Coastguard Worker * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19*bed243d3SAndroid Build Coastguard Worker * THE SOFTWARE. 20*bed243d3SAndroid Build Coastguard Worker * 21*bed243d3SAndroid Build Coastguard Worker *===-----------------------------------------------------------------------=== 22*bed243d3SAndroid Build Coastguard Worker */ 23*bed243d3SAndroid Build Coastguard Worker 24*bed243d3SAndroid Build Coastguard Worker#ifndef __CLANG_CUDA_WRAPPERS_NEW 25*bed243d3SAndroid Build Coastguard Worker#define __CLANG_CUDA_WRAPPERS_NEW 26*bed243d3SAndroid Build Coastguard Worker 27*bed243d3SAndroid Build Coastguard Worker#include_next <new> 28*bed243d3SAndroid Build Coastguard Worker 29*bed243d3SAndroid Build Coastguard Worker#if !defined(__device__) 30*bed243d3SAndroid Build Coastguard Worker// The header has been included too early from the standard C++ library 31*bed243d3SAndroid Build Coastguard Worker// and CUDA-specific macros are not available yet. 32*bed243d3SAndroid Build Coastguard Worker// Undo the include guard and try again later. 33*bed243d3SAndroid Build Coastguard Worker#undef __CLANG_CUDA_WRAPPERS_NEW 34*bed243d3SAndroid Build Coastguard Worker#else 35*bed243d3SAndroid Build Coastguard Worker 36*bed243d3SAndroid Build Coastguard Worker#pragma push_macro("CUDA_NOEXCEPT") 37*bed243d3SAndroid Build Coastguard Worker#if __cplusplus >= 201103L 38*bed243d3SAndroid Build Coastguard Worker#define CUDA_NOEXCEPT noexcept 39*bed243d3SAndroid Build Coastguard Worker#else 40*bed243d3SAndroid Build Coastguard Worker#define CUDA_NOEXCEPT 41*bed243d3SAndroid Build Coastguard Worker#endif 42*bed243d3SAndroid Build Coastguard Worker 43*bed243d3SAndroid Build Coastguard Worker// Device overrides for non-placement new and delete. 44*bed243d3SAndroid Build Coastguard Worker__device__ inline void *operator new(__SIZE_TYPE__ size) { 45*bed243d3SAndroid Build Coastguard Worker if (size == 0) { 46*bed243d3SAndroid Build Coastguard Worker size = 1; 47*bed243d3SAndroid Build Coastguard Worker } 48*bed243d3SAndroid Build Coastguard Worker return ::malloc(size); 49*bed243d3SAndroid Build Coastguard Worker} 50*bed243d3SAndroid Build Coastguard Worker__device__ inline void *operator new(__SIZE_TYPE__ size, 51*bed243d3SAndroid Build Coastguard Worker const std::nothrow_t &) CUDA_NOEXCEPT { 52*bed243d3SAndroid Build Coastguard Worker return ::operator new(size); 53*bed243d3SAndroid Build Coastguard Worker} 54*bed243d3SAndroid Build Coastguard Worker 55*bed243d3SAndroid Build Coastguard Worker__device__ inline void *operator new[](__SIZE_TYPE__ size) { 56*bed243d3SAndroid Build Coastguard Worker return ::operator new(size); 57*bed243d3SAndroid Build Coastguard Worker} 58*bed243d3SAndroid Build Coastguard Worker__device__ inline void *operator new[](__SIZE_TYPE__ size, 59*bed243d3SAndroid Build Coastguard Worker const std::nothrow_t &) { 60*bed243d3SAndroid Build Coastguard Worker return ::operator new(size); 61*bed243d3SAndroid Build Coastguard Worker} 62*bed243d3SAndroid Build Coastguard Worker 63*bed243d3SAndroid Build Coastguard Worker__device__ inline void operator delete(void* ptr) CUDA_NOEXCEPT { 64*bed243d3SAndroid Build Coastguard Worker if (ptr) { 65*bed243d3SAndroid Build Coastguard Worker ::free(ptr); 66*bed243d3SAndroid Build Coastguard Worker } 67*bed243d3SAndroid Build Coastguard Worker} 68*bed243d3SAndroid Build Coastguard Worker__device__ inline void operator delete(void *ptr, 69*bed243d3SAndroid Build Coastguard Worker const std::nothrow_t &) CUDA_NOEXCEPT { 70*bed243d3SAndroid Build Coastguard Worker ::operator delete(ptr); 71*bed243d3SAndroid Build Coastguard Worker} 72*bed243d3SAndroid Build Coastguard Worker 73*bed243d3SAndroid Build Coastguard Worker__device__ inline void operator delete[](void* ptr) CUDA_NOEXCEPT { 74*bed243d3SAndroid Build Coastguard Worker ::operator delete(ptr); 75*bed243d3SAndroid Build Coastguard Worker} 76*bed243d3SAndroid Build Coastguard Worker__device__ inline void operator delete[](void *ptr, 77*bed243d3SAndroid Build Coastguard Worker const std::nothrow_t &) CUDA_NOEXCEPT { 78*bed243d3SAndroid Build Coastguard Worker ::operator delete(ptr); 79*bed243d3SAndroid Build Coastguard Worker} 80*bed243d3SAndroid Build Coastguard Worker 81*bed243d3SAndroid Build Coastguard Worker// Sized delete, C++14 only. 82*bed243d3SAndroid Build Coastguard Worker#if __cplusplus >= 201402L 83*bed243d3SAndroid Build Coastguard Worker__device__ inline void operator delete(void *ptr, 84*bed243d3SAndroid Build Coastguard Worker __SIZE_TYPE__ size) CUDA_NOEXCEPT { 85*bed243d3SAndroid Build Coastguard Worker ::operator delete(ptr); 86*bed243d3SAndroid Build Coastguard Worker} 87*bed243d3SAndroid Build Coastguard Worker__device__ inline void operator delete[](void *ptr, 88*bed243d3SAndroid Build Coastguard Worker __SIZE_TYPE__ size) CUDA_NOEXCEPT { 89*bed243d3SAndroid Build Coastguard Worker ::operator delete(ptr); 90*bed243d3SAndroid Build Coastguard Worker} 91*bed243d3SAndroid Build Coastguard Worker#endif 92*bed243d3SAndroid Build Coastguard Worker 93*bed243d3SAndroid Build Coastguard Worker// Device overrides for placement new and delete. 94*bed243d3SAndroid Build Coastguard Worker__device__ inline void *operator new(__SIZE_TYPE__, void *__ptr) CUDA_NOEXCEPT { 95*bed243d3SAndroid Build Coastguard Worker return __ptr; 96*bed243d3SAndroid Build Coastguard Worker} 97*bed243d3SAndroid Build Coastguard Worker__device__ inline void *operator new[](__SIZE_TYPE__, void *__ptr) CUDA_NOEXCEPT { 98*bed243d3SAndroid Build Coastguard Worker return __ptr; 99*bed243d3SAndroid Build Coastguard Worker} 100*bed243d3SAndroid Build Coastguard Worker__device__ inline void operator delete(void *, void *) CUDA_NOEXCEPT {} 101*bed243d3SAndroid Build Coastguard Worker__device__ inline void operator delete[](void *, void *) CUDA_NOEXCEPT {} 102*bed243d3SAndroid Build Coastguard Worker 103*bed243d3SAndroid Build Coastguard Worker#pragma pop_macro("CUDA_NOEXCEPT") 104*bed243d3SAndroid Build Coastguard Worker 105*bed243d3SAndroid Build Coastguard Worker#endif // __device__ 106*bed243d3SAndroid Build Coastguard Worker#endif // include guard 107