Function: malloc_cached

Applicability

Product

Supported

Atlas 350 Accelerator Card

Atlas A3 training product/Atlas A3 inference product

Atlas A2 training product/Atlas A2 inference product

Atlas training product

Atlas inference product

Atlas 200I/500 A2 inference product

Description

Allocates device memory. The memory allocated by this API in any scenario supports cache. Allocates size bytes of linear memory on the device and returns in dev_ptr a pointer address to the allocated memory.

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

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

Prototype

  • C Prototype
    1
    aclError aclrtMallocCached(void **devPtr, size_t size, aclrtMemMallocPolicy policy)
    
  • Python Function
    1
    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 of aclrtMemMallocPolicy and size is greater than or equal to 2 MB, memory is allocated based on huge pages. Otherwise, memory is allocated based on normal pages.

Return Value

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

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