Managed Memory#
Functions | |
hipError_t | hipMallocManaged (void **dev_ptr, size_t size, unsigned int flags __dparm(hipMemAttachGlobal)) |
Allocates memory that will be automatically managed by HIP. More... | |
hipError_t | hipMemPrefetchAsync (const void *dev_ptr, size_t count, int device, hipStream_t stream __dparm(0)) |
Prefetches memory to the specified destination device using HIP. More... | |
hipError_t | hipMemAdvise (const void *dev_ptr, size_t count, hipMemoryAdvise advice, int device) |
Advise about the usage of a given memory range to HIP. More... | |
hipError_t | hipMemRangeGetAttribute (void *data, size_t data_size, hipMemRangeAttribute attribute, const void *dev_ptr, size_t count) |
Query an attribute of a given memory range in HIP. More... | |
hipError_t | hipMemRangeGetAttributes (void **data, size_t *data_sizes, hipMemRangeAttribute *attributes, size_t num_attributes, const void *dev_ptr, size_t count) |
Query attributes of a given memory range in HIP. More... | |
hipError_t | hipStreamAttachMemAsync (hipStream_t stream, void *dev_ptr, size_t length __dparm(0), unsigned int flags __dparm(hipMemAttachSingle)) |
Attach memory to a stream asynchronously in HIP. More... | |
Detailed Description
This section describes the managed memory management functions of HIP runtime API.
- Note
- The managed memory management APIs are implemented on Linux, under developement on Windows.
Function Documentation
◆ hipMallocManaged()
hipError_t hipMallocManaged | ( | void ** | dev_ptr, |
size_t | size, | ||
unsigned int flags | __dparmhipMemAttachGlobal | ||
) |
Allocates memory that will be automatically managed by HIP.
This API is used for managed memory, allows data be shared and accessible to both CPU and GPU using a single pointer.
The API returns the allocation pointer, managed by HMM, can be used further to execute kernels on device and fetch data between the host and device as needed.
- Note
- It is recommend to do the capability check before call this API.
- Parameters
-
[out] dev_ptr - pointer to allocated device memory [in] size - requested allocation size in bytes, it should be granularity of 4KB [in] flags - must be either hipMemAttachGlobal or hipMemAttachHost (defaults to hipMemAttachGlobal)
◆ hipMemAdvise()
hipError_t hipMemAdvise | ( | const void * | dev_ptr, |
size_t | count, | ||
hipMemoryAdvise | advice, | ||
int | device | ||
) |
Advise about the usage of a given memory range to HIP.
- Parameters
-
[in] dev_ptr Pointer to memory to set the advice for [in] count Size in bytes of the memory range, it should be CPU page size alligned. [in] advice Advice to be applied for the specified memory range [in] device Device to apply the advice for
- Returns
- hipSuccess, hipErrorInvalidValue
This HIP API advises about the usage to be applied on unified memory allocation in the range starting from the pointer address devPtr, with the size of count bytes. The advice can be one of enumeration value as defined in hipMemoryAdvise. The memory range must refer to managed memory allocated via the API hipMallocManaged. And the range will be handled with proper round down and round up respectively in the driver to be aligned to CPU page size, the same way as coresponding CUDA API behaves.
- Note
- This API is implemented on Linux, under development on Windows.
◆ hipMemPrefetchAsync()
hipError_t hipMemPrefetchAsync | ( | const void * | dev_ptr, |
size_t | count, | ||
int | device, | ||
hipStream_t stream | __dparm0 | ||
) |
Prefetches memory to the specified destination device using HIP.
- Parameters
-
[in] dev_ptr pointer to be prefetched [in] count size in bytes for prefetching [in] device destination device to prefetch to [in] stream stream to enqueue prefetch operation
- Returns
- hipSuccess, hipErrorInvalidValue
- Note
- This API is implemented on Linux, under development on Windows.
◆ hipMemRangeGetAttribute()
hipError_t hipMemRangeGetAttribute | ( | void * | data, |
size_t | data_size, | ||
hipMemRangeAttribute | attribute, | ||
const void * | dev_ptr, | ||
size_t | count | ||
) |
Query an attribute of a given memory range in HIP.
- Parameters
-
[in,out] data a pointer to a memory location where the result of each attribute query will be written to [in] data_size the size of data [in] attribute the attribute to query [in] dev_ptr start of the range to query [in] count size of the range to query
- Returns
- hipSuccess, hipErrorInvalidValue
- Note
- This API is implemented on Linux, under development on Windows.
◆ hipMemRangeGetAttributes()
hipError_t hipMemRangeGetAttributes | ( | void ** | data, |
size_t * | data_sizes, | ||
hipMemRangeAttribute * | attributes, | ||
size_t | num_attributes, | ||
const void * | dev_ptr, | ||
size_t | count | ||
) |
Query attributes of a given memory range in HIP.
- Parameters
-
[in,out] data a two-dimensional array containing pointers to memory locations where the result of each attribute query will be written to [in] data_sizes an array, containing the sizes of each result [in] attributes the attribute to query [in] num_attributes an array of attributes to query (numAttributes and the number of attributes in this array should match) [in] dev_ptr start of the range to query [in] count size of the range to query
- Returns
- hipSuccess, hipErrorInvalidValue
- Note
- This API is implemented on Linux, under development on Windows.
◆ hipStreamAttachMemAsync()
hipError_t hipStreamAttachMemAsync | ( | hipStream_t | stream, |
void * | dev_ptr, | ||
size_t length | __dparm0, | ||
unsigned int flags | __dparmhipMemAttachSingle | ||
) |
Attach memory to a stream asynchronously in HIP.
- Parameters
-
[in] stream - stream in which to enqueue the attach operation [in] dev_ptr - pointer to memory (must be a pointer to managed memory or to a valid host-accessible region of system-allocated memory) [in] length - length of memory (defaults to zero) [in] flags - must be one of hipMemAttachGlobal, hipMemAttachHost or hipMemAttachSingle (defaults to hipMemAttachSingle)
- Returns
- hipSuccess, hipErrorInvalidValue
- Note
- This API is implemented on Linux, under development on Windows.