cuda::experimental::pinned_memory_resource
Defined in include/cuda/experimental/__memory_resource/pinned_memory_resource.cuh
-
class pinned_memory_resource
pinned_memory_resource uses
cudaMallocHost
/cudaFreeHost
for allocation / deallocation.Public Functions
-
inline constexpr pinned_memory_resource(const unsigned int __flags = cudaHostAllocDefault) noexcept
-
inline void *allocate(const size_t __bytes, const size_t __alignment = cuda::mr::default_cuda_malloc_host_alignment) const
Allocate host 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 host 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 host 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_host_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 callingdeallocate_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 callingdeallocate_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==(pinned_memory_resource const &__other) const noexcept
Equality comparison with another
pinned_memory_resource
.- Parameters
__other – The other
pinned_memory_resource
.- Returns
Whether both
pinned_memory_resource
were constructed with the same flags.
-
inline constexpr pinned_memory_resource(const unsigned int __flags = cudaHostAllocDefault) noexcept