Managed Memory

Managed Memory#

HIP Runtime API Reference: Managed Memory
Collaboration diagram for 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.
 
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.
 
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.
 
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.
 
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.
 
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.
 

Detailed Description



This section describes the managed memory management functions of HIP runtime API.

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.

Parameters
[out]dev_ptr- pointer to allocated device memory
[in]size- requested allocation size in bytes
[in]flags- must be either hipMemAttachGlobal or hipMemAttachHost (defaults to hipMemAttachGlobal)
Returns
hipSuccess, hipErrorMemoryAllocation, hipErrorNotSupported, hipErrorInvalidValue

◆ 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_ptrpointer to memory to set the advice for
[in]countsize in bytes of the memory range
[in]adviceadvice to be applied for the specified memory range
[in]devicedevice to apply the advice for
Returns
hipSuccess, hipErrorInvalidValue

◆ hipMemPrefetchAsync()

hipError_t hipMemPrefetchAsync ( const void *  dev_ptr,
size_t  count,
int  device,
hipStream_t stream   __dparm
)

Prefetches memory to the specified destination device using HIP.

Parameters
[in]dev_ptrpointer to be prefetched
[in]countsize in bytes for prefetching
[in]devicedestination device to prefetch to
[in]streamstream to enqueue prefetch operation
Returns
hipSuccess, hipErrorInvalidValue

◆ 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]dataa pointer to a memory location where the result of each attribute query will be written to
[in]data_sizethe size of data
[in]attributethe attribute to query
[in]dev_ptrstart of the range to query
[in]countsize of the range to query
Returns
hipSuccess, hipErrorInvalidValue

◆ 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]dataa two-dimensional array containing pointers to memory locations where the result of each attribute query will be written to
[in]data_sizesan array, containing the sizes of each result
[in]attributesthe attribute to query
[in]num_attributesan array of attributes to query (numAttributes and the number of attributes in this array should match)
[in]dev_ptrstart of the range to query
[in]countsize of the range to query
Returns
hipSuccess, hipErrorInvalidValue

◆ 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