aclrtMapMem

Applicability

Product

Supported

Atlas A3 training products/Atlas A3 inference products

Atlas A2 training products/Atlas A2 inference products

Atlas 200I/500 A2 inference products

Atlas inference products

Atlas training products

Description

Maps virtual memory to physical memory.

This API must be used with other APIs to allocate virtual memory with consecutive addresses and maximize the use of physical memory.
  1. Call aclrtReserveMemAddress to allocate virtual memory.
  2. Call aclrtMallocPhysical to allocate physical memory.
  3. Call aclrtMapMem to map the virtual memory to the physical memory.
  4. Call specific task APIs to execute tasks.
  5. Call aclrtUnmapMem to unmap the virtual memory from the physical memory.
  6. Call aclrtFreePhysical to free the physical memory.
  7. Call aclrtReleaseMemAddress to free the virtual memory.

Prototype

aclError aclrtMapMem(void *virPtr, size_t size, size_t offset, aclrtDrvMemHandle handle, uint64_t flags)

Parameters

Parameter

Input/Output

Description

virPtr

Input

Pointer to the virtual memory 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

Input

Size of the memory to be mapped, in bytes.

This size must be the same as that of the size parameter of aclrtMallocPhysical. It must also be aligned with ACL_RT_MEM_ALLOC_GRANULARITY_MINIMUM obtained by aclrtMemGetAllocationGranularity.

offset

Input

Offset of the physical memory. This parameter can only be set to 0.

handle

Input

Handle for storing physical memory information.

A virtual address segment reserved by using the aclrtReserveMemAddress API is managed and divided by users. It cannot be bound to the physical addresses allocated on two devices at the same time.

A virtual address segment reserved by using the aclrtReserveMemAddress API is managed and divided by users. It cannot be bound to the handles output by the aclrtMallocPhysical and aclrtMemImportFromShareableHandle APIs.

flags

Input

This parameter is reserved and can only be set to 0.

Returns

0 on success; else, failure. For details, see aclError.

Restrictions

This API is not supported in the Ascend RC form of the Atlas 200I/500 A2 inference products.