Function: malloc_physical
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 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
aclError aclrtMallocPhysical(aclrtDrvMemHandle *handle, size_t size, const aclrtPhysicalMemProp *prop, uint64_t flags) -
Python Function
handle, ret = acl.rt.malloc_physical(size, prop, flags)
Parameters
| Parameter | Description |
|---|---|
| size | Int, size of the physical address space, in bytes. Call acl.rt.mem_get_allocation_granularity to obtain the memory allocation granularity, and then call this API to allocate physical memory. The size is aligned based on the obtained memory allocation 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 Values
| Return Value | Description |
|---|---|
| handle | Int, handle for storing physical memory information. |
| ret | Int, error code. If 0 is returned, the operation is successful. If other values are returned, the operation fails. |
Constraints
- On Atlas 200I/500 A2 inference products, this API cannot be called in Ascend RC mode.
- On Atlas A3 SuperPoD products, when the memory location
prop["location"]["type"]isACL_MEM_LOCATION_TYPE_HOST_NUMAand the memory attribute typeprop["memAttr"]is P2P (for example,ACL_MEM_P2P_HUGE), the maximum memory size that can be allocated varies depending on the server model and BIOS version. You are advised to call theacl.rt.malloc_physicalAPI to allocate memory based on the memory plan to check whether the memory is sufficient.
prop["memAttr"]supports only the following memory attribute types:-
ACL_MEM_NORMAL: normal memory. -
ACL\_MEM\_HUGE: 2 MB huge page. -
ACL\_MEM\_HUGE1G: 1 GB huge page, which is supported only by devices.Only Atlas A3 and Atlas A2 products support this type.
Other models do not support this type.
-
ACL\_MEM\_P2P\_NORMAL: Normal page memory for inter-device memory copy. -
ACL\_MEM\_P2P\_HUGE: Huge page memory for inter-device memory copy. The memory allocation granularity is 2 MB. -
ACL\_MEM\_P2P\_HUGE1G: Huge page memory for inter-device memory copy. The memory allocation granularity is 1 GB, which is supported only by the device.Only certain Atlas A3 interconnect products support this type. The actual return result of the API is used.
Other models do not support this type.
-
ACL\_HBM\_MEM\_HUGE: 2 MB huge page. -
ACL\_HBM\_MEM\_HUGE1G: 1 GB huge page, which is supported only by devices.Ascend 950PR&950DT, Atlas A3, and Atlas A2 products support this type.
Other models do not support this type.
-
ACL\_HBM\_MEM\_NORMAL: normal memory. The API allocates huge page memory based on theACL\_HBM\_MEM\_HUGEtype. -
ACL\_DDR\_MEM\_HUGE: huge page memory, which is supported only by the host. -
ACL\_DDR\_MEM\_NORMAL: normal memory, which is supported only by the host. -
ACL\_DDR\_MEM\_P2P\_HUGE: huge page memory used for data replication between devices, which is supported only by the host. -
ACL\_DDR\_MEM\_P2P\_NORMAL: normal memory used for data replication between devices, which is supported only by the host.
-