aclrtMalloc

Description

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

The device memory allocated by this API call is cacheable. Therefore, you do not need to care about the cache coherence between the CPU and NPU.

Before calling a media data processing API, acldvppMalloc must be called to allocate memory on the device for storing the input or output data.

Restrictions

Prototype

aclError aclrtMalloc(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

Requested allocation size in bytes.

Must not be 0.

policy

Input

Memory allocation policy.

typedef enum aclrtMemMallocPolicy {
ACL_MEM_MALLOC_HUGE_FIRST, //When the allocated memory is less than or equal to 1 MB, only normal page memory is allocated even under this memory allocation policy. When the allocated memory is greater than 1 MB, the allocation of huge page memory is prioritized. If the huge page memory is insufficient, normal page memory is allocated.
ACL_MEM_MALLOC_HUGE_ONLY, //Only huge page memory is allocated. If huge page memory is insufficient, an error is returned.
ACL_MEM_MALLOC_NORMAL_ONLY, //Only normal page memory is allocated.
ACL_MEM_MALLOC_HUGE_FIRST_P2P, //Applies to inter-device memory copy. The allocation of huge page memory is prioritized. If huge page memory is insufficient, normal page memory will be allocated. This option is not supported by Ascend 310 AI Processor in the current version.
ACL_MEM_MALLOC_HUGE_ONLY_P2P, //Applies to inter-device memory copy. Only huge page memory is allocated. If huge page memory is insufficient, a failure will be returned. This option is not supported by Ascend 310 AI Processor in the current version.
ACL_MEM_MALLOC_NORMAL_ONLY_P2P, //Applies to inter-device memory copy. Only normal page memory is allocated. This option is not supported by Ascend 310 AI Processor in the current version.
} aclrtMemMallocPolicy;

Returns

0 on success; else, failure.

See Also

For the API call example, see Data Transfer.