Function: malloc_physical
Applicability
Product |
Supported (√/x) |
|---|---|
√ |
|
√ |
|
√ |
|
√ |
|
√ |
Function Usage
Allocates physical host or device memory. A physical memory handle will be returned.
This API can be used together with acl.rt.reserve_mem_address (for allocating virtual memory) and acl.rt.map_mem (for establishing the mapping between the virtual memory and the physical memory) to allocate virtual memory with consecutive addresses and maximize the use of physical memory addresses.
This API can be used together with acl.rt.mem_export_to_shareable_handle (for exporting the physical memory handle) and acl.rt.mem_import_from_shareable_handle (for importing the shared handle) to implement physical memory sharing among multiple processes. In addition, the virtual memory can be used when the physical memory is shared. For details, see the description of acl.rt.mem_export_to_shareable_handle.
Prototype
- C Prototype
1aclError aclrtMallocPhysical(aclrtDrvMemHandle *handle, size_t size, const aclrtPhysicalMemProp *prop, uint64_t flags)
- Python Function
1handle, ret = acl.rt.malloc_physical(size, prop, flags)
Parameter Description
Parameter |
Description |
|---|---|
size |
Int, size of the physical address space, in bytes. Call acl.rt.mem_get_allocation_granularity to obtain the memory granularity, and then call this API to allocate the physical memory. The size is aligned based on the obtained memory granularity to save memory. |
prop |
Dict, physical memory attributes. For details, see aclrtPhysicalMemProp. |
flags |
Int, reserved. Currently, this parameter can only be set to 0. |
Return Value Description
Return Value |
Description |
|---|---|
handle |
Int, handle for storing physical memory information. |
ret |
Int, error code: 0 on success; else, failure. |
Restrictions
Atlas 200I/500 A2 inference products : This API is not supported in Ascend RC form.- In the current version, only the ACL_HBM_MEM_HUGE (2 MB aligned huge page), ACL_HBM_MEM_HUGE1G (1 GB aligned huge page), and ACL_HBM_MEM_NORMAL (normal page) memory types are supported. However, if ACL_HBM_MEM_NORMAL is passed, the system uses ACL_HBM_MEM_HUGE instead.For products that do not have HBM memory on the following devices, the system automatically allocates the DDR memory of the ACL_DDR_MEM_HUGE type.
Atlas inference products Atlas 200I/500 A2 inference products
The support for the ACL_HBM_MEM_HUGE1G option varies with the product model.- The
Atlas A3 training products /Atlas A3 inference products supports this option. - The
Atlas A2 training products /Atlas A2 inference products supports this option. - The
Atlas 200I/500 A2 inference products does not support this option. - The
Atlas inference products does not support this option. - The
Atlas training products does not support this option.