new 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*===---- complex - CUDA wrapper for <new> ------------------------------===
  2. *
  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:
  9. *
  10. * The above copyright notice and this permission notice shall be included in
  11. * all copies or substantial portions of the Software.
  12. *
  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
  19. * THE SOFTWARE.
  20. *
  21. *===-----------------------------------------------------------------------===
  22. */
  23. #ifndef __CLANG_CUDA_WRAPPERS_NEW
  24. #define __CLANG_CUDA_WRAPPERS_NEW
  25. #include_next <new>
  26. #pragma push_macro("CUDA_NOEXCEPT")
  27. #if __cplusplus >= 201103L
  28. #define CUDA_NOEXCEPT noexcept
  29. #else
  30. #define CUDA_NOEXCEPT
  31. #endif
  32. // Device overrides for non-placement new and delete.
  33. __device__ inline void *operator new(__SIZE_TYPE__ size) {
  34. if (size == 0) {
  35. size = 1;
  36. }
  37. return ::malloc(size);
  38. }
  39. __device__ inline void *operator new(__SIZE_TYPE__ size,
  40. const std::nothrow_t &) CUDA_NOEXCEPT {
  41. return ::operator new(size);
  42. }
  43. __device__ inline void *operator new[](__SIZE_TYPE__ size) {
  44. return ::operator new(size);
  45. }
  46. __device__ inline void *operator new[](__SIZE_TYPE__ size,
  47. const std::nothrow_t &) {
  48. return ::operator new(size);
  49. }
  50. __device__ inline void operator delete(void* ptr) CUDA_NOEXCEPT {
  51. if (ptr) {
  52. ::free(ptr);
  53. }
  54. }
  55. __device__ inline void operator delete(void *ptr,
  56. const std::nothrow_t &) CUDA_NOEXCEPT {
  57. ::operator delete(ptr);
  58. }
  59. __device__ inline void operator delete[](void* ptr) CUDA_NOEXCEPT {
  60. ::operator delete(ptr);
  61. }
  62. __device__ inline void operator delete[](void *ptr,
  63. const std::nothrow_t &) CUDA_NOEXCEPT {
  64. ::operator delete(ptr);
  65. }
  66. // Sized delete, C++14 only.
  67. #if __cplusplus >= 201402L
  68. __device__ void operator delete(void *ptr, __SIZE_TYPE__ size) CUDA_NOEXCEPT {
  69. ::operator delete(ptr);
  70. }
  71. __device__ void operator delete[](void *ptr, __SIZE_TYPE__ size) CUDA_NOEXCEPT {
  72. ::operator delete(ptr);
  73. }
  74. #endif
  75. // Device overrides for placement new and delete.
  76. __device__ inline void *operator new(__SIZE_TYPE__, void *__ptr) CUDA_NOEXCEPT {
  77. return __ptr;
  78. }
  79. __device__ inline void *operator new[](__SIZE_TYPE__, void *__ptr) CUDA_NOEXCEPT {
  80. return __ptr;
  81. }
  82. __device__ inline void operator delete(void *, void *) CUDA_NOEXCEPT {}
  83. __device__ inline void operator delete[](void *, void *) CUDA_NOEXCEPT {}
  84. #pragma pop_macro("CUDA_NOEXCEPT")
  85. #endif // include guard