Memory can be allocated in either of the following ways:
- Allocate memory as required. The memory is not split or re-allocated.
- Allocate a large memory pool at a time and re-allocate the memory from the memory pool as required.
During memory reallocation, the following APIs are used to allocate memory from the memory pool. Pay attention to the restrictions on the address and size of memory allocated by corresponding APIs.
API
|
Function
|
Input/Output Memory
|
acl.rt.memcpy_async
|
Implements asynchronous memory copy within the host, within the device, and between the host and device.
|
For on-chip memory copy within the device, the source and destination address must be 64-byte aligned.
|
acl.rt.malloc
|
Allocates memory on the device. It is a synchronous interface.
|
- If the memory is allocated by using acl.rt.malloc, the memory needs to be released by calling acl.rt.free.
- Performance deterioration will be caused by the frequent calling of acl.rt.malloc to allocate memory and acl.rt.free to free memory. You are advised to allocate or manage memory in advance to avoid frequent memory application and freeing.
- The memory allocated by calling acl.rt.malloc is the least multiple of 32 greater than size plus 32 bytes.
|
acl.media.dvpp_malloc
|
Allocates device memory for media processing. The allocated huge memory page meets the data processing requirements (for example, the start address is 128-byte aligned). It is a synchronous interface. acl.media.dvpp_malloc and acl.media.dvpp_free must be used in pair. Memory allocated using acl.media.dvpp_malloc can only be freed by calling acl.media.dvpp_free.
For details about the media data processing, see Media Data Processing (media).
|
When the VPC function is implemented, the requirements for the input and output memory are as follows: - The start address must be 16-byte aligned. 128-byte alignment provides the highest performance. Allocate memory by calling acl.media.dvpp_malloc and free memory by calling acl.media.dvpp_free.
- Calculate the memory size according to the image format.
YUV400SP and YUV420SP: widthStride x heightStride x 3/2
YUV422SP: widthStride x heightStride x 2
YUV444SP: widthStride x heightStride x 3
YUV422 Packed: widthStride x heightStride
YUV444 Packed and RGB888: widthStride x heightStride
XRGB8888: widthStride x heightStride
|
When the JPEGD function is implemented: - Input memory:
- The size of the input memory is the size of the input image.
- The start address of the input memory must be 128-byte aligned. Allocate memory by calling acl.media.dvpp_malloc and free memory by calling acl.media.dvpp_free.
- Output memory:
- Calculate the output memory size according to the image format.
YUV420SP: widthStride x heightStride x 3/2
YUV422SP: widthStride x heightStride x 2
YUV444SP: widthStride x heightStride x 3
YUV440SP: widthStride*heightStride x 2
- The start address of the output memory must be 128-byte aligned. Allocate memory by calling acl.media.dvpp_malloc and free memory by calling acl.media.dvpp_free. For huge memory: Memory size = Output memory size + (n – 1) x AlignTo128 (Output memory size + 8), where, n indicates the number of images.
|
When the JPEGE function is implemented:
- Input memory:
- Output memory:
- The size of the output memory is the size of the encoded image.
- The start address of the output memory must be 128-byte aligned. Allocate memory by calling acl.media.dvpp_malloc and free memory by calling acl.media.dvpp_free.
|
When the VDEC function is implemented:
|
When the VENC function is implemented:
|
acl.rt.malloc_host
|
Allocates memory on the host. It is a synchronous interface.
|
- The allocated memory cannot be used on the device and needs to be explicitly copied to the device.
- If the memory is allocated by using acl.rt.malloc_host, the memory needs to be released by calling acl.rt.free_host.
|
The typical memory management scenarios during media data processing are as follows:
Figure 3-3 VDEC scenario![]()
Figure 3-4 JPEGD scenario![]()