Function: malloc_with_cfg
Applicable Products
Product |
Supported (√/x) |
|---|---|
√ |
|
√ |
|
√ |
|
√ |
|
√ |
|
√ |
Description
Allocates size bytes of linear memory on the device and returns in dev_ptr a pointer to the allocated memory.
Compared with the acl.rt.malloc API, this API can also specify memory-related configuration when allocating memory.
Memory allocated by this call needs to be freed by the acl.rt.free call.
Prototype
- C Prototype
1aclError aclrtMallocWithCfg(void **devPtr, size_t size, aclrtMemMallocPolicy policy, aclrtMallocConfig *cfg)
- Python Function
1dev_ptr, ret = acl.rt.malloc_with_cfg(size, policy, cfg)
Parameters
Parameter |
Description |
|---|---|
size |
Int, allocated memory size, in bytes. Must not be 0. |
policy |
Int, memory allocation policy. 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 |
Dict, memory configuration. If no configuration is specified, an empty dictionary can be transferred. For details, see aclrtMallocConfig. |
Return Values
Return Value |
Description |
|---|---|
devPtr |
Int, address of the pointer to the allocated device memory. |
ret |
Int, error code. 0 on success; else, failure. |
Constraints
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