aclrtMallocWithCfg

Applicable Products

Product

Supported

Ascend 950PR/Ascend 950DT

√

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

√

Function

Allocates size bytes of linear memory on the device and returns the pointer to the allocated memory through *devPtr. The start address of the memory is 64-byte aligned.

Compared with aclrtMalloc, this API can also specify memory configuration information when allocating memory.

The memory allocated by this API can only be freed by calling aclrtFree or aclrtFreeWithDevSync.

Prototype

1
aclError aclrtMallocWithCfg(void **devPtr, size_t size, aclrtMemMallocPolicy policy, aclrtMallocConfig *cfg)

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.

cfg

Input

Memory configuration. For details about the type definition, see aclrtMallocConfig.

If no configuration is specified, NULL can be passed.

Returns

0 on success; otherwise, failure. For details, see aclError.

Restrictions

The value of policy can be a single enumeration item or multiple enumeration items combined with bitwise OR. If bitwise OR is used, combinations of enumeration items from the three predefined groups are supported, for example, ACL_MEM_TYPE_HIGH_BAND_WIDTH | ACL_MEM_ACCESS_USER_SPACE_READONLY | ACL_MEM_MALLOC_HUGE_FIRST:

  • High or low bandwidth: ACL_MEM_TYPE_LOW_BAND_WIDTH and ACL_MEM_TYPE_HIGH_BAND_WIDTH
  • Read-only memory in user mode: ACL_MEM_ACCESS_USER_SPACE_READONLY
  • Other basic memory allocation policies: for example, ACL_MEM_MALLOC_HUGE_FIRST, ACL_MEM_MALLOC_HUGE_ONLY, or ACL_MEM_MALLOC_NORMAL_ONLY