aclrtMallocAlign32
Applicable Products
Product |
Supported |
|---|---|
√ |
|
√ |
|
√ |
|
√ |
|
√ |
|
√ |
Function
Allocates size bytes of linear memory on the device and returns the pointer to the allocated memory through *devPtr. The memory allocated by this API is byte-aligned. The size bytes requested by users are rounded up to the nearest multiple of 32 bytes. The memory allocated by this API can only be freed by calling aclrtFree or aclrtFreeWithDevSync.
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
1 | aclError aclrtMallocAlign32(void **devPtr, size_t size, aclrtMemMallocPolicy policy) |
Parameters
Parameter |
Input/Output |
Description |
|---|---|---|
devPtr |
Output |
Pointer to the pointer to the allocated device memory. |
size |
Input |
Memory size in bytes to allocate. size cannot be 0. |
policy |
Input |
Memory allocation policy. For details about the type definition, see aclrtMemMallocPolicy. If the configured memory allocation policy is beyond the value range of aclrtMemMallocPolicy, and size is greater than or equal to 2 MB, huge page memory is allocated; otherwise, common page memory is allocated. |
Returns
0 on success; otherwise, failure. For details, see aclError.
Restrictions
- The memory allocated by this API is not initialized.
- 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 aclrtMallocWithCfg API. Otherwise, performance problems may occur or memory may fail to be allocated.
- Performance deterioration will be caused by too frequent calls to aclrtMallocAlign32 and aclrtFree. You are advised to allocate or manage memory in advance to avoid unnecessary memory allocation and deallocation.
- If you use this API to allocate a large memory block and divide and manage the memory, each memory segment must meet the requirements listed below. 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.
- The memory size alignment rules vary depending on the product model:
- For the
Ascend 950PR /Ascend 950DT , the memory size is rounded up to the nearest multiple of 32 bytes (m = ALIGN_UP[len, 32] bytes). - For the product models below, the memory size is rounded up to the nearest multiple of 32 plus 32 bytes (m = ALIGN_UP[len,32] + 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
- For the
- The memory start address must be 64-byte aligned (ALIGN_UP[m,64]).
- The memory size alignment rules vary depending on the product model: