Class thrust::mr::disjoint_unsynchronized_pool_resource
A memory resource adaptor allowing for pooling and caching allocations from Upstream
, using Bookkeeper
for management of that cached and pooled memory, allowing to cache portions of memory inaccessible from the host.
On a typical memory resource, calls to allocate
and deallocate
actually allocate and deallocate memory. Pooling memory resources only allocate and deallocate memory from an external resource (the upstream memory resource) when there’s no suitable memory currently cached; otherwise, they use memory they have acquired beforehand, to make memory allocation faster and more efficient.
The disjoint version of the pool resources uses a separate upstream memory resource, Bookkeeper
, to allocate memory necessary to manage the cached memory. There may be many reasons to do that; the canonical one is that Upstream
allocates memory that is inaccessible to the code of the pool resource, which means that it cannot embed the necessary information in memory obtained from Upstream
; for instance, Upstream
can be a CUDA non-managed memory resource, or a CUDA managed memory resource whose memory we would prefer to not migrate back and forth between host and device when executing bookkeeping code.
This is not the only case where it makes sense to use a disjoint pool resource, though. In a multi-core environment it may be beneficial to avoid stealing cache lines from other cores by writing over bookkeeping information embedded in an allocated block of memory. In such a case, one can imagine wanting to use a disjoint pool where both the upstream and the bookkeeper are of the same type, to allocate memory consistently, but separately for those two purposes.
Template Parameters:
Upstream
the type of memory resources that will be used for allocating memory blocks to be handed off to the userBookkeeper
the type of memory resources that will be used for allocating bookkeeping memory
Inherits From:
thrust::mr::memory_resource< Upstream::pointer >
thrust::mr::validator2< Upstream, Bookkeeper >
#include <thrust/mr/disjoint_pool.h>
template <typename Upstream, typename Bookkeeper> class thrust::mr::disjoint_unsynchronized_pool_resource { public:
/* Inherited from thrust::mr::memory_resource< Upstream::pointer >
*/ typedef see below pointer;
static pool_options get_default_options();
disjoint_unsynchronized_pool_resource(Upstream * upstream, Bookkeeper * bookkeeper, pool_options options = get_default_options());
disjoint_unsynchronized_pool_resource(pool_options options = get_default_options());
~disjoint_unsynchronized_pool_resource();
void release();
virtual _CCCL_NODISCARD void_ptr do_allocate(std::size_t bytes, std::size_t alignment = alignof(std::max_align_t)) override;
virtual void do_deallocate(void_ptr p, std::size_t bytes, std::size_t alignment = alignof(std::max_align_t)) override;
/* Inherited from thrust::mr::memory_resource< Upstream::pointer >
*/ virtual ~memory_resource() = default;
/* Inherited from thrust::mr::memory_resource< Upstream::pointer >
*/ _CCCL_NODISCARD pointer allocate(std::size_t bytes, std::size_t alignment = alignof(std::max_align_t));
/* Inherited from thrust::mr::memory_resource< Upstream::pointer >
*/ void deallocate(pointer p, std::size_t bytes, std::size_t alignment = alignof(std::max_align_t));
/* Inherited from thrust::mr::memory_resource< Upstream::pointer >
*/ _CCCL_HOST_DEVICE bool is_equal(const memory_resource & other) const;
/* Inherited from thrust::mr::memory_resource< Upstream::pointer >
*/ virtual _CCCL_HOST_DEVICE bool do_is_equal(const memory_resource & other) const; };
Member Functions
Function thrust::mr::disjoint_unsynchronized_pool_resource::get_default_options
static pool_options get_default_options();
Get the default options for a disjoint pool. These are meant to be a sensible set of values for many use cases, and as such, may be tuned in the future. This function is exposed so that creating a set of options that are just a slight departure from the defaults is easy.
Function thrust::mr::disjoint_unsynchronized_pool_resource::disjoint_unsynchronized_pool_resource
disjoint_unsynchronized_pool_resource(Upstream * upstream, Bookkeeper * bookkeeper, pool_options options = get_default_options());
Constructor.
Function Parameters:
upstream
the upstream memory resource for allocationsbookkeeper
the upstream memory resource for bookkeepingoptions
pool options to use
Function thrust::mr::disjoint_unsynchronized_pool_resource::disjoint_unsynchronized_pool_resource
disjoint_unsynchronized_pool_resource(pool_options options = get_default_options());
Constructor. Upstream and bookkeeping resources are obtained by calling get_global_resource
for their types.
Function Parameters: options
: pool options to use
Function thrust::mr::disjoint_unsynchronized_pool_resource::~disjoint_unsynchronized_pool_resource
~disjoint_unsynchronized_pool_resource();
Destructor. Releases all held memory to upstream.
Function thrust::mr::disjoint_unsynchronized_pool_resource::release
void release();
Releases all held memory to upstream.
Function thrust::mr::disjoint_unsynchronized_pool_resource::do_allocate
virtual _CCCL_NODISCARD void_ptr do_allocate(std::size_t bytes, std::size_t alignment = alignof(std::max_align_t)) override;
Allocates memory of size at least bytes
and alignment at least alignment
.
Function Parameters:
bytes
size, in bytes, that is requested from this allocationalignment
alignment that is requested from this allocation
Returns: A pointer to void to the newly allocated memory.
Exceptions: thrust::bad_alloc
: when no memory with requested size and alignment can be allocated.
Implements: do_allocate
Function thrust::mr::disjoint_unsynchronized_pool_resource::do_deallocate
virtual void do_deallocate(void_ptr p, std::size_t bytes, std::size_t alignment = alignof(std::max_align_t)) override;
Deallocates memory pointed to by p
.
Function Parameters:
p
pointer to be deallocatedbytes
the size of the allocation. This must be equivalent to the value ofbytes
that was passed to the allocation function that returnedp
.alignment
the size of the allocation. This must be equivalent to the value ofalignment
that was passed to the allocation function that returnedp
.
Implements: do_deallocate