Function: map_mem
Applicable Products
- Ascend 950PR&950DT products: Supported
- Atlas A3 products: Supported
- Atlas A2 products: Supported
- Atlas 200I/500 A2 inference products: Supported
- Atlas inference products: Supported
- Atlas training products: Supported
Function
Maps virtual memory to physical memory.
This API needs to work with other APIs to allocate virtual memory with consecutive addresses and maximize the use of physical memory.
- Call acl.rt.reserve_mem_address to allocate virtual memory.
- Call acl.rt.malloc_physical to allocate physical memory.
- Call acl.rt.map_mem to map the virtual memory to the physical memory.
- Call specific task APIs to execute tasks.
- Call acl.rt.unmap_mem to cancel the mapping between the virtual memory and the physical memory.
- Call acl.rt.free_physical to free the physical memory.
- Call acl.rt.release_mem_address to free the virtual memory.
Prototype
-
C Prototype
aclError aclrtMapMem(void *virPtr, size_t size, size_t offset, aclrtDrvMemHandle handle, uint64_t flags) -
Python Function
ret = acl.rt.map_mem(vir_ptr, size, offset, handle, flags)
Parameters
| Parameter | Description |
|---|---|
| vir_ptr | Int, virtual address to be mapped. The address may not be the start address. You can also offset the address based on the start address and then map the address. |
| size | Int, size of the memory to be mapped, in bytes. The value of size must be the same as that of the size parameter of the acl.rt.malloc_physical API. The value of size must be aligned with the value of ACL_RT_MEM_ALLOC_GRANULARITY_MINIMUM obtained by the acl.rt.mem_get_allocation_granularity API. |
| offset | Int, physical memory offset. It can only be set to 0 currently. |
| handle | Int, physical memory pointer address. A virtual address segment reserved by using acl.rt.reserve_mem_address is managed and allocated by the user and cannot be bound to the physical addresses allocated on two devices at the same time. A virtual address segment reserved by using acl.rt.reserve_mem_address is managed and allocated by the user and cannot be bound to the handles output by acl.rt.malloc_physical and acl.rt.mem_import_from_shareable_handle at the same time. |
| flags | Int, reserved. Currently, this parameter can only be set to 0. |
Return Values
| Return Value | Description |
|---|---|
| ret | Int, error code. If 0 is returned, the operation is successful. If other values are returned, the operation fails. |
Constraints
On Atlas 200I/500 A2 inference products, this API cannot be called in Ascend RC mode.