cuda::experimental::mr::device_memory_pool

Defined in include/cuda/experimental/__memory_resource/device_memory_pool.cuh

class device_memory_pool

device_memory_pool is an owning wrapper around a cudaMemPool_t.

It handles creation and destruction of the underlying pool utilizing the provided memory_pool_properties.

Public Functions

inline explicit device_memory_pool(const ::cuda::experimental::device_ref __device_id, memory_pool_properties __properties = {})

Constructs a device_memory_pool with the optionally specified initial pool size and release threshold. If the pool size grows beyond the release threshold, unused memory held by the pool will be released at the next synchronization event.

Throws

cuda_error – if the CUDA version does not support cudaMallocAsync.

Parameters
  • __device_id – The device id of the device the stream pool is constructed on.

  • __pool_properties – Optional, additional properties of the pool to be created.

device_memory_pool(::cudaMemPool_t) = delete

Disables construction from a plain cudaMemPool_t. We want to ensure clean ownership semantics.

device_memory_pool(device_memory_pool const&) = delete
device_memory_pool(device_memory_pool&&) = delete
device_memory_pool &operator=(device_memory_pool const&) = delete
device_memory_pool &operator=(device_memory_pool&&) = delete
inline ~device_memory_pool() noexcept

Destroys the device_memory_pool by releasing the internal cudaMemPool_t.

inline void trim_to(const size_t __min_bytes_to_keep)

Tries to release memory.

Note

If the pool has less than __minBytesToKeep reserved, the trim_to operation is a no-op. Otherwise the pool will be guaranteed to have at least __minBytesToKeep bytes reserved after the operation.

Parameters

__min_bytes_to_keep – the minimal guaranteed size of the pool.

inline size_t get_attribute(::cudaMemPoolAttr __attr) const

Gets the value of an attribute of the pool.

Parameters

__attribute – the attribute to be set.

Returns

The value of the attribute. For boolean attributes any value not equal to 0 equates to true.

inline void set_attribute(::cudaMemPoolAttr __attr, size_t __value)

Sets an attribute of the pool to a given value.

Note

For boolean attributes any non-zero value equates to true.

Parameters
  • __attribute – the attribute to be set.

  • __value – the new value of that attribute.

inline void enable_peer_access_from(const ::std::vector<device_ref> &__devices)

Enable peer access to this memory pool from the supplied devices.

Device on which this pool resides can be included in the vector.

Parameters

__devices – A vector of device_refs listing devices to enable access for

inline void enable_peer_access_from(device_ref __device)

Enable peer access to this memory pool from the supplied device.

Parameters

__devicedevice_ref indicating for which device the access should be enabled

inline void disable_peer_access_from(const ::std::vector<device_ref> &__devices)

Disable peer access to this memory pool from the supplied devices.

Device on which this pool resides can be included in the vector.

Parameters

__devices – A vector of device_refs listing devices to disable access for

inline void disable_peer_access_from(device_ref __device)

Disable peer access to this memory pool from the supplied device.

Parameters

__devicedevice_ref indicating for which device the access should be disable

inline bool is_accessible_from(device_ref __device)

Query if memory allocated through this memory resource is accessible by the supplied device.

Parameters

__device – device for which the peer access is queried

inline constexpr bool operator==(device_memory_pool const &__rhs) const noexcept

Equality comparison with another device_memory_pool.

Returns

true if the stored cudaMemPool_t are equal.

inline constexpr bool operator==(device_memory_pool const &__lhs, ::cudaMemPool_t __rhs) noexcept

Equality comparison with a cudaMemPool_t.

Parameters

__rhs – A cudaMemPool_t.

Returns

true if the stored cudaMemPool_t is equal to __rhs.

inline constexpr cudaMemPool_t get() const noexcept

Returns the underlying handle to the CUDA memory pool.

Public Static Functions

static inline device_memory_pool from_native_handle(::cudaMemPool_t __handle) noexcept

Construct an device_memory_pool object from a native cudaMemPool_t handle.

Note

The constructed device_memory_pool object takes ownership of the native handle.

Parameters

__handle – The native handle

Returns

The constructed device_memory_pool object

static device_memory_pool from_native_handle(int) = delete
static device_memory_pool from_native_handle(cuda::std::nullptr_t) = delete