Function: mem_import_from_shareable_handle

C Prototype

aclError aclrtMemImportFromShareableHandle(uint64_t shareableHandle, int32_t deviceId, aclrtDrvMemHandle *handle)

Python Function

handle, ret = acl.rt.mem_import_from_shareable_handle(shareable_handle, device_id)

Function Usage

Obtains the information in shareable_handle in this process and returns the handle in this process to establish the mapping between virtual addresses and physical addresses in this process. This API can also be used to generate a handle for a specified device.

This API must work with other APIs to implement memory sharing. For details, see the description of acl.rt.mem_export_to_shareable_handle.

Input Description

shareableHandle: int, shareable_handle to be shared.

The value must be the same as the value of shareable_handle exported from acl.rt.mem_export_to_shareable_handle.

deviceId: int, generates the handle of a specified device ID.

Must be in the range of [0, Device count – 1]. Call acl.rt.get_device_count to obtain the device count.

Return Value

handle: int, physical memory handle of the process.

ret: int, error code.

Restrictions

  • This API is not supported in Ascend RC form.
  • Before calling this API, ensure that the physical memory to be shared exists and cannot be released in advance.
  • There is a one-to-one mapping between handles and shareable_handle. In the same process, one-to-many or many-to-one mapping is not allowed. Otherwise, an error is reported. For example, if this API is repeatedly called to import data, an error is reported.
  • The acl.rt.mem_import_from_shareable_handle and acl.rt.mem_export_to_shareable_handle APIs cannot be called in the same process. Only cross-process calling is supported.
  • The handle can be exported by calling acl.rt.mem_export_to_shareable_handle on a device, and then the handle on another device can be generated by calling this API.
  • If acl.rt.free_physical is called to destroy the handle, the handle is being destroyed only when shareable_handle is destroyed by all processes that call this API.