aclrtMemAllocManaged
Function
Allocates unified virtual memory (UVM). The pointer to the allocated memory is returned through *ptr. The size of the allocated memory is rounded up to the nearest multiple of 2 MB based on the specified size. The memory allocated by this API can only be freed by calling aclrtFree.
This is an encapsulated API that applies only to C++ programs. It internally calls the C API aclrtMemAllocManaged.
Prototype
1 2 | template <typename T> aclError aclrtMemAllocManaged(T **devPtr, size_t size, uint32_t flags = ACL_RT_MEM_ATTACH_GLOBAL) |
Parameters
Parameter |
Input/Output |
Description |
|---|---|---|
ptr |
Output |
Pointer to the allocated memory. Because the virtual addresses of the host and device are uniformly addressed, this parameter does not distinguish the allocation location. |
size |
Input |
Memory size, in bytes. The value of size cannot be 0. A single application process can request a maximum of 3 TB of UVM. |
flag |
Input |
Memory flag. Currently, the flag can only be set to ACL_RT_MEM_ATTACH_GLOBAL, which corresponds to the value 1. After this parameter is set to ACL_RT_MEM_ATTACH_GLOBAL, the memory allocated by this API can be accessed on both the device and host sides. The macro is defined as follows: #define ACL_RT_MEM_ATTACH_GLOBAL (0x01U) |
Returns
0 on success; otherwise, failure. For details, see aclError.
Restrictions
The memory allocated by this API is not initialized. Before using the memory, call aclrtMemset to initialize it and clear unpredictable contents.