Function: malloc_physical

Applicable Products

Product

Supported (√/x)

Ascend 950PR/Ascend 950DT

√

Atlas A3 training products/Atlas A3 inference products

√

Atlas A2 training products/Atlas A2 inference products

√

Atlas training products

√

Atlas inference products

√

Atlas 200I/500 A2 inference products

√

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 products do not support this API.

Prototype

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 Values

Return Value

Description

handle

Int, handle for storing physical memory information.

ret

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

Restrictions