HIP managed memory allocation API#
-
hipError_t hipMallocManaged(void **dev_ptr, size_t size, unsigned int flags)#
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:
dev_ptr – [out] - pointer to allocated device memory
size – [in] - requested allocation size in bytes, it should be granularity of 4KB
flags – [in] - must be either hipMemAttachGlobal or hipMemAttachHost (defaults to hipMemAttachGlobal)
- Returns:
hipSuccess, hipErrorMemoryAllocation, hipErrorNotSupported, hipErrorInvalidValue
-
hipError_t hipMemPrefetchAsync(const void *dev_ptr, size_t count, int device, hipStream_t stream)#
Prefetches memory to the specified destination device using HIP.
Note
This API is implemented on Linux and is under development on Microsoft Windows.
- Parameters:
dev_ptr – [in] pointer to be prefetched
count – [in] size in bytes for prefetching
device – [in] destination device to prefetch to
stream – [in] stream to enqueue prefetch operation
- Returns:
hipSuccess, hipErrorInvalidValue
-
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.
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 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 corresponding CUDA API behaves in CUDA version 8.0 and afterwards.
Note
This API is implemented on Linux and is under development on Microsoft Windows.
- Parameters:
dev_ptr – [in] pointer to memory to set the advice for
count – [in] size in bytes of the memory range, it should be CPU page size alligned.
advice – [in] advice to be applied for the specified memory range
device – [in] device to apply the advice for
- Returns:
hipSuccess, hipErrorInvalidValue
-
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.
Note
This API is implemented on Linux and is under development on Microsoft Windows.
- Parameters:
data – [inout] a pointer to a memory location where the result of each attribute query will be written to
data_size – [in] the size of data
attribute – [in] the attribute to query
dev_ptr – [in] start of the range to query
count – [in] size of the range to query
- Returns:
hipSuccess, hipErrorInvalidValue
-
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.
Note
This API is implemented on Linux and is under development on Microsoft Windows.
- Parameters:
data – [inout] a two-dimensional array containing pointers to memory locations where the result of each attribute query will be written to
data_sizes – [in] an array, containing the sizes of each result
attributes – [in] the attribute to query
num_attributes – [in] an array of attributes to query (numAttributes and the number of attributes in this array should match)
dev_ptr – [in] start of the range to query
count – [in] size of the range to query
- Returns:
hipSuccess, hipErrorInvalidValue
-
hipError_t hipStreamAttachMemAsync(hipStream_t stream, void *dev_ptr, size_t length, unsigned int flags)#
Attach memory to a stream asynchronously in HIP.
Warning
This API is under development. Currently it is a no-operation (NOP) function on AMD GPUs and returns hipSuccess.
- Parameters:
stream – [in] - stream in which to enqueue the attach operation
dev_ptr – [in] - pointer to memory (must be a pointer to managed memory or to a valid host-accessible region of system-allocated memory)
length – [in] - length of memory (defaults to zero)
flags – [in] - must be one of hipMemAttachGlobal, hipMemAttachHost or hipMemAttachSingle (defaults to hipMemAttachSingle)
- Returns:
hipSuccess, hipErrorInvalidValue
-
template<class T>
static inline hipError_t hipMallocManaged(T **devPtr, size_t size, unsigned int flags = hipMemAttachGlobal)# : C++ wrapper for hipMallocManaged
Provide an override to automatically typecast the pointer type from void**, and also provide a default for the flags.
HIP_DISABLE_CPP_FUNCTIONS macro can be defined to suppress these wrappers. It is useful for applications which need to obtain decltypes of HIP runtime APIs.
See also