aclrtMemImportFromShareableHandle
Description
Obtains the information in shareableHandle 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 aclrtMemExportToShareableHandle.
Restrictions
- This API is not supported in the Ascend RC form.
Currently, the following models support the Ascend RC form:
Atlas 200/300/500 Inference Product
- 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 shareableHandles. 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 aclrtMemImportFromShareableHandle and aclrtMemExportToShareableHandle APIs cannot be called in the same process. Only cross-process calling is supported.
- The handle can be exported by calling aclrtMemExportToShareableHandle on a device, and then the handle on another device can be generated by calling this API.
- After the memory is used, call aclrtFreePhysical to destroy the handle in a timely manner. The handle is destroyed only when all processes that call this API destroy the shareableHandle.
- Physical memory can be shared across devices.
Cross-device physical memory sharing supports only the following models and must be used together with the aclrtDeviceEnablePeerAccess API:
Atlas Training Series Product
Prototype
aclError aclrtMemImportFromShareableHandle(uint64_t shareableHandle, int32_t deviceId, aclrtDrvMemHandle *handle)
Parameters
Parameter |
Input/Output |
Description |
|---|---|---|
shareableHandle |
Input |
shareableHandle to be shared. The value must be the same as the value of shareableHandle exported from aclrtMemExportToShareableHandle. |
deviceId |
Input |
ID of the device for which a handle is to be generated. Must be in the range of [0, Device count – 1]. Call aclrtGetDeviceCount to obtain the device count. |
handle |
Output |
Physical memory handle to the process. |
Returns
The value 0 indicates success, and other values indicate failure. For details, see aclError.