49 using const_pointer =
const T*;
51 using const_reference =
const T&;
52 using size_type = std::size_t;
53 using difference_type = std::ptrdiff_t;
66 XGBOOST_DEVICE inline pinned_allocator(pinned_allocator<U>
const&) {}
69 XGBOOST_DEVICE inline const_pointer address(const_reference r) {
return &r; }
71 inline pointer allocate(size_type cnt, const_pointer =
nullptr) {
72 if (cnt > this->max_size()) {
throw std::bad_alloc(); }
74 pointer result(
nullptr);
75 dh::safe_cuda(cudaMallocHost(
reinterpret_cast<void**
>(&result), cnt *
sizeof(value_type)));
79 inline void deallocate(pointer p, size_type) { dh::safe_cuda(cudaFreeHost(p)); }
81 inline size_type max_size()
const {
return (std::numeric_limits<size_type>::max)() /
sizeof(T); }
83 XGBOOST_DEVICE inline bool operator==(pinned_allocator
const& x)
const {
return true; }
85 XGBOOST_DEVICE inline bool operator!=(pinned_allocator
const& x)
const {
86 return !operator==(x);