thrust::per_device_allocator

Defined in thrust/per_device_resource.h

template<typename T, typename Upstream, typename ExecutionPolicy>
class per_device_allocator : public thrust::mr::allocator<T, Upstream>

A helper allocator class that uses global per device instances of a given upstream memory resource. Requires the memory resource to be default constructible.

Template Parameters
  • T – the type that will be allocated by this allocator.

  • MR – the upstream memory resource to use for memory allocation. Must derive from thrust::mr::memory_resource and must be final.

  • ExecutionPolicy – the execution policy of the system to be used to retrieve the resource for the current device.

Public Types

using void_pointer = typename MR::pointer

The pointer to void type of this allocator.

using value_type = T

The value type allocated by this allocator. Equivalent to T.

using pointer = typename thrust::detail::pointer_traits<void_pointer>::template rebind<T>::other

The pointer type allocated by this allocator. Equivaled to the pointer type of MR rebound to T.

using const_pointer = typename thrust::detail::pointer_traits<void_pointer>::template rebind<const T>::other

The pointer to const type. Equivalent to a pointer type of MR rebound to const T.

using reference = typename thrust::detail::pointer_traits<pointer>::reference

The reference to the type allocated by this allocator. Supports smart references.

using const_reference = typename thrust::detail::pointer_traits<const_pointer>::reference

The const reference to the type allocated by this allocator. Supports smart references.

using size_type = std::size_t

The size type of this allocator. Always std::size_t.

using difference_type = typename thrust::detail::pointer_traits<pointer>::difference_type

The difference type between pointers allocated by this allocator.

using propagate_on_container_copy_assignment = detail::true_type

Specifies that the allocator shall be propagated on container copy assignment.

using propagate_on_container_move_assignment = detail::true_type

Specifies that the allocator shall be propagated on container move assignment.

using propagate_on_container_swap = detail::true_type

Specifies that the allocator shall be propagated on container swap.

Public Functions

inline per_device_allocator()

Default constructor. Uses get_global_resource to get the global instance of Upstream and initializes the allocator base subobject with that resource.

inline per_device_allocator(const per_device_allocator &other)

Copy constructor. Copies the memory resource pointer.

template<typename U>
inline per_device_allocator(const per_device_allocator<U, Upstream, ExecutionPolicy> &other)

Conversion constructor from an allocator of a different type. Copies the memory resource pointer.

inline ~per_device_allocator()

Destructor.

inline size_type max_size() const

Calculates the maximum number of elements allocated by this allocator.

Returns

the maximum value of std::size_t, divided by the size of T.

inline pointer allocate(size_type n)

Allocates objects of type T.

Parameters

n – number of elements to allocate

Returns

a pointer to the newly allocated storage.

inline void deallocate(pointer p, size_type n) noexcept

Deallocates objects of type T.

Parameters
  • p – pointer returned by a previous call to allocate

  • n – number of elements, passed as an argument to the allocate call that produced p

inline Upstream *resource() const

Extracts the memory resource used by this allocator.

Returns

the memory resource used by this allocator.

template<typename U>
struct rebind

The rebind metafunction provides the type of an per_device_allocator instantiated with another type.

Template Parameters

U – the other type to use for instantiation.

Public Types

using other = per_device_allocator<U, Upstream, ExecutionPolicy>

The alias other gives the type of the rebound per_device_allocator.