cuda::experimental::mr::async_memory_resource

Defined in /home/runner/work/cccl/cccl/cudax/include/cuda/experimental/__memory_resource/async_memory_resource.cuh

class async_memory_resource

Stream ordered memory resource

async_memory_resource uses cudaMallocFromPoolAsync / cudaFreeAsync for allocation/deallocation. A async_memory_resource is a thin wrapper around a c cudaMemPool_t.

Warning

async_memory_resource does not own the pool and it is the responsibility of the user to ensure that the lifetime of the pool exceeds the lifetime of the async_memory_resource.

Public Functions

inline async_memory_resource()

Default constructs the async_memory_resource using the default cudaMemPool_t of the default device.

Throws

cuda_error – if retrieving the default cudaMemPool_t fails.

inline explicit async_memory_resource(::cuda::experimental::device_ref __device)

Constructs a async_memory_resource using the default cudaMemPool_t of a given device.

Throws

cuda_error – if retrieving the default cudaMemPool_t fails.

async_memory_resource(int) = delete
async_memory_resource(cuda::std::nullptr_t) = delete
inline explicit async_memory_resource(::cudaMemPool_t __pool) noexcept

Constructs the async_memory_resource from a cudaMemPool_t.

Parameters

__pool – The cudaMemPool_t used to allocate memory.

inline explicit async_memory_resource(async_memory_pool &__pool) noexcept

Constructs the async_memory_resource from a async_memory_pool by calling get().

Parameters

__pool – The async_memory_pool used to allocate memory.

inline void *allocate(const size_t __bytes, const size_t __alignment = cuda::mr::default_cuda_malloc_alignment)

Allocate device memory of size at least __bytes via cudaMallocFromPoolAsync.

Parameters
  • __bytes – The size in bytes of the allocation.

  • __alignment – The requested alignment of the allocation.

Throws
  • std::invalid_argument – In case of invalid alignment.

  • cuda::cuda_error – If an error code was return by the CUDA API call.

Returns

Pointer to the newly allocated memory.

inline void deallocate(void *__ptr, const size_t, const size_t __alignment = cuda::mr::default_cuda_malloc_alignment)

Deallocate memory pointed to by __ptr.

Note

The pointer passed to deallocate must not be in use in a stream. It is the caller’s responsibility to properly synchronize all relevant streams before calling deallocate.

Parameters
  • __ptr – Pointer to be deallocated. Must have been allocated through a call to allocate.

  • __bytes – The number of bytes that was passed to the allocate call that returned __ptr.

  • __alignment – The alignment that was passed to the allocate call that returned __ptr.

inline void *allocate_async(const size_t __bytes, const size_t __alignment, const ::cuda::stream_ref __stream)

Allocate device memory of size at least __bytes via cudaMallocFromPoolAsync.

Parameters
  • __bytes – The size in bytes of the allocation.

  • __alignment – The requested alignment of the allocation.

  • __stream – Stream on which to perform allocation.

Throws
  • std::invalid_argument – In case of invalid alignment.

  • cuda::cuda_error – If an error code was return by the cuda api call.

Returns

Pointer to the newly allocated memory.

inline void *allocate_async(const size_t __bytes, const ::cuda::stream_ref __stream)

Allocate device memory of size at least __bytes via cudaMallocFromPoolAsync.

Parameters
  • __bytes – The size in bytes of the allocation.

  • __stream – Stream on which to perform allocation.

Throws

cuda::cuda_error – If an error code was return by the cuda api call.

Returns

Pointer to the newly allocated memory.

inline void deallocate_async(void *__ptr, const size_t __bytes, const size_t __alignment, const ::cuda::stream_ref __stream)

Deallocate memory pointed to by __ptr.

Note

The pointer passed to deallocate_async must not be in use in a stream other than __stream. It is the caller’s responsibility to properly synchronize all relevant streams before calling deallocate_async.

Parameters
  • __ptr – Pointer to be deallocated. Must have been allocated through a call to allocate_async

  • __bytes – The number of bytes that was passed to the allocate_async call that returned __ptr.

  • __alignment – The alignment that was passed to the allocate_async call that returned __ptr.

  • __stream – A stream that has a stream ordering relationship with the stream used in the allocate_async call that returned __ptr.

inline void deallocate_async(void *__ptr, size_t, const ::cuda::stream_ref __stream)

Deallocate memory pointed to by __ptr.

Note

The pointer passed to deallocate_async must not be in use in a stream other than __stream. It is the caller’s responsibility to properly synchronize all relevant streams before calling deallocate_async.

Parameters
  • __ptr – Pointer to be deallocated. Must have been allocated through a call to allocate_async.

  • __bytes – The number of bytes that was passed to the allocate_async call that returned __ptr.

  • __stream – A stream that has a stream ordering relationship with the stream used in the allocate_async call that returned __ptr.

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

Equality comparison with another async_memory_resource.

Returns

true if underlying cudaMemPool_t are equal.

template<class _Resource, ::cuda::std::__enable_if_t<(cuda::mr::__different_resource<async_memory_resource, _Resource>), int> = 0>
inline bool operator==(_Resource const &__rhs) const noexcept

Equality comparison between a async_memory_resource and another resource.

Parameters

__rhs – The resource to compare to.

Returns

If the underlying types are equality comparable, returns the result of equality comparison of both resources. Otherwise, returns false.

inline constexpr cudaMemPool_t get() const noexcept

Returns the underlying handle to the CUDA memory pool.