//===----------------------------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// #ifndef ALLOCATORS_H #define ALLOCATORS_H #include #include #include "test_macros.h" template class A1 { int id_; public: __device__ __host__ explicit A1(int id = 0) noexcept : id_(id) {} typedef T value_type; __device__ __host__ int id() const { return id_; } STATIC_MEMBER_VAR(copy_called, bool); STATIC_MEMBER_VAR(move_called, bool); STATIC_MEMBER_VAR(allocate_called, bool); __device__ __host__ static cuda::std::pair& deallocate_called() { NV_IF_ELSE_TARGET(NV_IS_DEVICE, (__shared__ cuda::std::pair v; return v;), (static cuda::std::pair v = 0; return v;)) } __device__ __host__ A1(const A1& a) noexcept : id_(a.id()) { copy_called() = true; } __device__ __host__ A1(A1&& a) noexcept : id_(a.id()) { move_called() = true; } __device__ __host__ A1& operator=(const A1& a) noexcept { id_ = a.id(); copy_called() = true; return *this; } __device__ __host__ A1& operator=(A1&& a) noexcept { id_ = a.id(); move_called() = true; return *this; } template __device__ __host__ A1(const A1& a) noexcept : id_(a.id()) { copy_called() = true; } template __device__ __host__ A1(A1&& a) noexcept : id_(a.id()) { move_called() = true; } __device__ __host__ T* allocate(cuda::std::size_t n) { allocate_called() = true; return (T*) n; } __device__ __host__ void deallocate(T* p, cuda::std::size_t n) noexcept { deallocate_called() = cuda::std::pair(p, n); } __device__ __host__ cuda::std::size_t max_size() const { return id_; } }; template inline __device__ __host__ bool operator==(const A1& x, const A1& y) { return x.id() == y.id(); } template inline __device__ __host__ bool operator!=(const A1& x, const A1& y) { return !(x == y); } template class A2 { int id_; public: __device__ __host__ explicit A2(int id = 0) noexcept : id_(id) {} typedef T value_type; typedef unsigned size_type; typedef int difference_type; typedef cuda::std::true_type propagate_on_container_move_assignment; __device__ __host__ int id() const { return id_; } STATIC_MEMBER_VAR(copy_called, bool); STATIC_MEMBER_VAR(move_called, bool); STATIC_MEMBER_VAR(allocate_called, bool); __device__ __host__ A2(const A2& a) noexcept : id_(a.id()) { copy_called() = true; } __device__ __host__ A2(A2&& a) noexcept : id_(a.id()) { move_called() = true; } __device__ __host__ A2& operator=(const A2& a) noexcept { id_ = a.id(); copy_called() = true; return *this; } __device__ __host__ A2& operator=(A2&& a) noexcept { id_ = a.id(); move_called() = true; return *this; } __device__ __host__ T* allocate(cuda::std::size_t, const void* hint) { allocate_called() = true; return (T*) const_cast(hint); } }; template inline __device__ __host__ bool operator==(const A2& x, const A2& y) { return x.id() == y.id(); } template inline __device__ __host__ bool operator!=(const A2& x, const A2& y) { return !(x == y); } template class A3 { int id_; public: __device__ __host__ explicit A3(int id = 0) noexcept : id_(id) {} typedef T value_type; typedef cuda::std::true_type propagate_on_container_copy_assignment; typedef cuda::std::true_type propagate_on_container_swap; __device__ __host__ int id() const { return id_; } STATIC_MEMBER_VAR(copy_called, bool); STATIC_MEMBER_VAR(move_called, bool); STATIC_MEMBER_VAR(constructed, bool); STATIC_MEMBER_VAR(destroy_called, bool); __device__ __host__ A3(const A3& a) noexcept : id_(a.id()) { copy_called() = true; } __device__ __host__ A3(A3&& a) noexcept : id_(a.id()) { move_called() = true; } __device__ __host__ A3& operator=(const A3& a) noexcept { id_ = a.id(); copy_called() = true; return *this; } __device__ __host__ A3& operator=(A3&& a) noexcept { id_ = a.id(); move_called() = true; return *this; } template __device__ __host__ void construct(U* p, Args&&... args) { ::new (p) U(cuda::std::forward(args)...); constructed() = true; } template __device__ __host__ void destroy(U* p) noexcept { p->~U(); destroy_called() = true; } __device__ __host__ A3 select_on_container_copy_construction() const { return A3(-1); } }; template inline __device__ __host__ bool operator==(const A3& x, const A3& y) { return x.id() == y.id(); } template inline __device__ __host__ bool operator!=(const A3& x, const A3& y) { return !(x == y); } #endif // ALLOCATORS_H