Function: malloc_align32
Applicable Products
|
Product |
Supported (√/x) |
|---|---|
|
|
√ |
|
|
√ |
|
|
√ |
|
|
√ |
|
|
√ |
|
|
√ |
Description
Allocates size bytes of linear memory on the device and returns in dev_ptr a pointer to the allocated memory. The allocation size is the input size rounded up to the nearest multiple of 32 bytes. Memory allocated by this call needs to be freed by the acl.rt.free call.
For the
For the product models below, compared with the aclrtMalloc API, this API only rounds the input size up to the nearest multiple of 32 bytes, but does not add an extra 32 bytes.
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
Prototype
- C Prototype
1aclError aclrtMallocAlign32(void **devPtr, size_t size, aclrtMemMallocPolicy policy)
- Python Function
1dev_ptr, ret = acl.rt.malloc_align32(size, policy)
Parameters
|
Parameter |
Description |
|---|---|
|
size |
Int, allocated memory size, in bytes. Must not be 0. |
|
policy |
|
Return Values
|
Return Value |
Description |
|---|---|
|
dev_ptr |
Int, address of the pointer to the allocated device memory. |
|
ret |
Int, error code. 0 on success; else, failure. |
Restrictions
- Media data processing has higher requirements on the memory for storing the input and output data (for example, the start address of the memory must be 128-byte aligned). Therefore, the following dedicated memory allocation APIs are required:
- When the media data processing V1 API is called to perform operations such as cropping and resizing on images, the acl.media.dvpp_malloc API is called to allocate memory.
- When the media data processing V2 API is called to perform operations such as cropping and resizing on images, the acl.himpi.dvpp_malloc API is called to allocate memory.
- The memory allocated by this API does not initialize the content.
- This API does not perform implicit device synchronization or stream synchronization. The memory allocation result, either success or failure, is returned immediately.
- The value of policy can only be a single enumeration item and cannot be multiple enumeration items combined with bitwise OR.
- For the ACL_MEM_MALLOC_HUGE_FIRST_P2P and ACL_MEM_MALLOC_HUGE_ONLY_P2P policies, you are advised to use the acl.rt.malloc_with_cfg API. Otherwise, performance issues may occur or memory may fail to be allocated.
- If the memory is allocated by using acl.rt.malloc_align32, the memory needs to be released by calling acl.rt.free.
- Performance deterioration will be caused by the frequent calling of acl.rt.malloc_align32 to allocate memory and acl.rt.free to free memory. You are advised to allocate or manage memory in advance to avoid frequent memory allocation and release.
- 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]).
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.