Secondary Memory Allocation

Memory can be allocated in either of the following ways:
  1. Allocate memory independently as required without split or second allocation.
  2. Allocate a memory pool in advance and then allocate a memory block from the pool during use as required.

Call the following APIs for memory re-allocation. Pay attention to the restrictions on the memory address and memory size of each API. Otherwise, memory overwriting may occur.

For details about memory management, see Overview.

API

Description

Input/Output Buffer

aclrtMemcpyAsync

Implements asynchronous memory copy within the host, within a device, between devices, or between the host and device.

  • The source address and destination address passed to this call must be 64-byte aligned.

aclrtMalloc

Allocates size bytes of linear memory on the device and returns in *devPtr a pointer to the allocated memory. This API is synchronous.

  • If you use this API to allocate a large memory block, and divide and manage the memory, each memory segment must meet the following requirements:
    • The memory size is rounded up to the nearest multiple of 32 plus 32 bytes (m = ALIGN_UP[len,32] + 32 bytes).
    • The memory start address must be 64-byte aligned (ALIGN_UP[m,64]).
    NOTE:

    len indicates the size of a memory segment. ALIGN_UP[len,k] indicates rounding up to a multiple of k bytes as in this formula: ((len – 1)/k + 1) x k.

acldvppMalloc

Allocates device memory for media processing. The allocated huge page memory meets the data processing requirements (for example, the start address is 128-byte aligned). This API is synchronous.

For details, see Media Data Processing V1.

When the output of media data processing is used as the input of model inference, if you use this API to allocate a large memory block and divide and manage the memory, each memory segment must meet the following requirements:

  • The memory size is rounded up to the nearest multiple of 32 plus 32 bytes (m = ALIGN_UP[len,32] + 32 bytes).
  • The memory start address must be 128-byte aligned (ALIGN_UP[m, 128]).
NOTE:

len indicates the size of a memory segment. ALIGN_UP[len,k] indicates rounding up to a multiple of k bytes as in this formula: ((len – 1)/k + 1) x k.

hi_mpi_dvpp_malloc

Allocates device memory. The requested allocation must meet the media data processing requirements (for example,128-byte alignment of the start address).

For details, see Media Data Processing V2.

When the output of media data processing is used as the input of model inference, if you use this API to allocate a large memory block and divide and manage the memory, each memory segment must meet the following requirements:

  • The memory size is rounded up to the nearest multiple of 32 plus 32 bytes (m = ALIGN_UP[len,32] + 32 bytes).
  • The memory start address must be 128-byte aligned (ALIGN_UP[m,128]).
NOTE:

len indicates the size of a memory segment. ALIGN_UP[len,k] indicates rounding up to a multiple of k bytes as in this formula: ((len – 1)/k + 1) x k.

aclrtMallocHost

If your app runs on the host, this API is called to allocate the host memory, and the system guarantees that the start address of the memory is 64-byte aligned. If your app runs on the device, this API is called to allocate the device memory by normal page. If 64-byte alignment is required for the start address, you need to guarantee the alignment. This API is synchronous.

  • If you use this API to allocate a large memory block, and divide and manage the memory, each memory segment must meet the following requirements:
    • The memory size is rounded up to the nearest multiple of 32 plus 32 bytes (m = ALIGN_UP[len,32] + 32 bytes).
    • The memory start address must be 64-byte aligned (ALIGN_UP[m,64]).
    NOTE:

    len indicates the size of a memory segment. ALIGN_UP[len,k] indicates rounding up to a multiple of k bytes as in this formula: ((len – 1)/k + 1) x k.

aclrtMallocCached

Allocates size bytes of linear memory on the device and returns in *devPtr a pointer to the allocated memory. The allocated memory is cacheable. This API is synchronous.

Other restrictions are the same as those of aclrtMalloc.

In the computer vision field, the media data processing function is often used. Therefore, multiple memory allocation APIs are involved. The memory start address involves 64-byte or 128-byte alignment. To facilitate unified management, you are advised to select a large alignment value, for example, 128-byte alignment.

The following describes the typical scenarios where the memory is managed by the user during media data processing. Media Data Processing V1 details the available media data processing features.
Figure 1 VDEC scenario
Figure 2 JPEGD scenario