cuda::experimental::managed_memory_resource

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

class managed_memory_resource

managed_memory_resource uses cudaMallocManaged / cudaFree for allocation / deallocation.

Public Functions

inline constexpr managed_memory_resource(const unsigned int __flags = cudaMemAttachGlobal) noexcept
inline void *allocate(const size_t __bytes, const size_t __alignment = cuda::mr::default_cuda_malloc_alignment) const

Allocate CUDA unified memory of size at least __bytes.

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 or cuda::cuda_error of the returned error code.

Returns

Pointer to the newly allocated memory

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

Allocate CUDA unified memory of size at least __bytes.

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

  • __alignment – The requested alignment of the allocation.

  • __stream – Stream on which to perform allocation. Currently ignored

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 CUDA unified memory of size at least __bytes.

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(void *__ptr, const size_t, const size_t __alignment = cuda::mr::default_cuda_malloc_alignment) const noexcept

Deallocate memory pointed to by __ptr.

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 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 __bytes, 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==(managed_memory_resource const &__other) const noexcept

Equality comparison with another managed_memory_resource.

Parameters

__other – The other managed_memory_resource.

Returns

Whether both managed_memory_resource were constructed with the same flags.