Function: malloc_cached

Applicable Products

  • Ascend 950PR&950DT products: Supported
  • Atlas A3 products: Supported
  • Atlas A2 products: Supported
  • Atlas 200I/500 A2 inference products: Supported
  • Atlas inference products: Supported
  • Atlas training products: Supported

Function

Allocates cacheable device memory. Allocates linear memory of the specified size on the device and returns the pointer address of the allocated memory through dev\_ptr.

The memory allocated by calling acl.rt.malloc_cached is equivalent to that allocated by calling acl.rt.malloc. Both support cache. You do not need to handle the cache consistency between the CPU and NPU.

Before calling a media data processing API, call acl.media.dvpp_malloc to allocate memory on the device for storing the input or output data.

Prototype

  • C Prototype

    aclError aclrtMallocCached(void **devPtr, size_t size, aclrtMemMallocPolicy policy)
    
  • Python Function

    dev_ptr, ret = acl.rt.malloc_cached(size, policy)
    

Parameters

Parameter Description
size Int, allocated memory size, in bytes. Must not be 0.
policy Int, memory allocation policy.
If the configured memory allocation rule exceeds the value range in aclrtMemMallocPolicy and the size is greater than or equal to 2 MB, the huge page memory is allocated. Otherwise, common page memory is allocated.

Return Values

Return Value Description
dev_ptr Int, address of the pointer to the allocated device memory.
ret Int, error code. If 0 is returned, the operation is successful. If other values are returned, the operation fails.

Constraints

Other constraints are the same as those of acl.rt.malloc.