aclrtMapMem

Description

Maps virtual memory to physical memory.

This API needs to 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.

Restrictions

This API is not supported in the Ascend RC form.

Currently, the following models support the Ascend RC form:

  • Atlas 200/300/500 Inference Product

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.

The virtual memory address must be 2-MB aligned.

size

Input

Size of the memory to be mapped, in bytes.

The size must be 2-MB aligned.

offset

Input

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

handle

Input

Handle to the physical memory information.

A virtual address segment reserved by using the aclrtReserveMemAddress interface. When the virtual address segment is managed and allocated by the user, it cannot be bound to the physical addresses applied for on two devices at the same time.

An entire virtual address segment reserved by using the aclrtReserveMemAddress interface cannot be bound to the handle output by the aclrtMallocPhysical and aclrtMemImportFromShareableHandle interfaces at the same time when the virtual address segment is managed and divided by the user.

flags

Input

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

Returns

The value 0 indicates success, and other values indicate failure. For details, see aclError.