aclrtReserveMemAddress

Description

Reserves virtual 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
  • To use the virtual memory reserved by this API, only aclrtMemcpyAsync can be called to copy data between two devices in the single-process scenario.

Prototype

aclError aclrtReserveMemAddress(void **virPtr, size_t size, size_t alignment, void *expectPtr, uint64_t flags)

Parameters

Parameter

Input/Output

Description

virPtr

Output

Pointer to "pointer to the allocated virtual memory address".

size

Input

Virtual memory size, in bytes.

Must not be 0.

alignment

Input

Alignment value of the virtual address. This parameter is reserved and can only be set to 0.

expectPtr

Input

Start address of the virtual memory to be returned. This parameter is reserved and can only be set to nullptr.

flags

Input

Huge page or common page flag. The flag must be the same as the memory type of aclrtMallocPhysical.

Values:

  • 0: common page
  • 1: huge page

Returns

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