Function: malloc_physical

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)

Function Usage

Allocates physical 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.

Input Description

size: int, size of the physical address space (in byte)

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.

The memory allocation granularity is fixed to 2 MB. Therefore, the memory size must be 2 MB aligned.

prop: dict, physical memory attribute information. For details, see aclrtPhysicalMemProp.

flags: reserved. This parameter can only be set to 0.

Return Value

ret: int, error code.

Restrictions

  • This API is not supported in Ascend RC form.
  • The current version supports only ACL_HBM_MEM_HUGE (huge page memory) and ACL_HBM_MEM_NORMAL (common page memory). If ACL_HBM_MEM_NORMAL is specified, the system applies for huge page memory.