Function: malloc_physical

Description

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.

The Atlas 200/300/500 inference product does not support this API.

Prototype

  • C Prototype
    1
    aclError aclrtMallocPhysical(aclrtDrvMemHandle *handle, size_t size, const aclrtPhysicalMemProp *prop, uint64_t flags)
    
  • Python Function
    1
    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 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

Return Value

Description

handle

Int, handle for storing physical memory information.

ret

Int, error code. 0 on success; else, failure.

Restrictions

  • For the Atlas 200I/500 A2 inference product in Ascend RC form does not support this API.
  • For SuperPoDs in the Atlas A3 Training Series Product, when the memory location prop["location"]["type"] is set to ACL_MEM_LOCATION_TYPE_HOST_NUMA and the memory attribute type prop["memAttr"] is set to a P2P option (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 the acl.rt.malloc_physical API to allocate memory based on the memory plan to check whether there are sufficient memory resources.
  • prop["memAttr"] supports only the following memory attribute types:
    • ACL_MEM_NORMAL: common memory.
    • ACL_MEM_HUGE: 2 MB huge page memory.
    • ACL_MEM_HUGE1G: 1 GB huge page memory. This option is supported only on the device.

      Only the Atlas A3 Training Series Product and Atlas A2 Training Series Product/Atlas 800I A2 Inference Product support this type.

      Other models do not support this type.

    • ACL_MEM_P2P_NORMAL: common memory for inter-device data copy.
    • ACL_MEM_P2P_HUGE: huge page memory for inter-device data copy. The memory granularity is 2 MB.
    • ACL_MEM_P2P_HUGE1G: huge page memory for inter-device data copy. The memory granularity is 1 GB. This option is supported only on the device.

      Only some interconnection modes in Atlas A3 Training Series Product support this type. The actual return value of the API prevails.

      Other models do not support this type.

    • ACL_HBM_MEM_HUGE: 2 MB huge page memory.
    • ACL_HBM_MEM_HUGE1G: 1 GB huge page memory. This option is supported only on the device.

      The Atlas 350 Accelerator Card supports this type.

      The Atlas A3 Training Series Product and Atlas A2 Training Series Product/Atlas 800I A2 Inference Product support this type.

      Other models do not support this type.

    • ACL_HBM_MEM_NORMAL: common memory. The API allocates huge page memory using ACL_HBM_MEM_HUGE.
    • ACL_DDR_MEM_HUGE: huge page memory. Only host memory is supported.
    • ACL_DDR_MEM_NORMAL: common memory. Only host memory is supported.
    • ACL_DDR_MEM_P2P_HUGE: huge page memory used for inter-device data copy. Only host memory is supported.
    • ACL_DDR_MEM_P2P_NORMAL: common memory used for inter-device data copy. Only host memory is supported.