aclrtReserveMemAddress

Applicable Products

Product

Supported

Ascend 950PR / Ascend 950DT

√

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

√

Function

Reserves virtual memory.

This API must be used together 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 virtual memory to physical memory.
  4. Call specific task APIs to execute tasks.
  5. Call aclrtUnmapMem to cancel the mapping between virtual memory and physical memory.
  6. Call aclrtFreePhysical to free physical memory.
  7. Call aclrtReleaseMemAddress to free virtual memory.

Prototype

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

Parameters

Parameter

Input/Output

Description

virPtr

Output

Pointer to the pointer to the allocated virtual memory address.

size

Input

Virtual memory size, in bytes.

size cannot 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.

The value can be:
  • nullptr: The system automatically allocates a virtual address that meets the alignment requirements.

    For the Atlas 350 Accelerator Card, only nullptr is supported.

  • Non-nullptr: Specify a start address within the range of 8 TB (16–24 TB). Ensure that the specified address is not occupied and meets the alignment requirements. Otherwise, the virtual memory cannot be reserved and an error will be returned. The alignment rule is as follows: If size is less than 1 GB, expectPtr must be aligned to a power (n) of 2. If size is greater than 1 GB, expectPtr must be aligned to 1 GB.

    Note: The function of specifying a start address is for trial use and may be changed in later versions. It is not available in the production environment.

flags

Input

Reserved. The value 0 is recommended.

Returns

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

Restrictions

  • Atlas 200I/500 A2 inference products in Ascend RC form: This API is not supported.
  • 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.

API Call Example

For the API call example, see Virtual Memory Management.