8. Notify Management
This topic describes the Notify management APIs of CANN Runtime, which are used to create, record, wait for/reset, and share Notify across processes.
aclError aclrtCreateNotify(aclrtNotify *notify, uint64_t flag): Creates a Notify.aclError aclrtDestroyNotify(aclrtNotify notify): Destroys a Notify.aclError aclrtRecordNotify(aclrtNotify notify, aclrtStream stream): Records a Notify on a specified stream. This is an asynchronous API.aclError aclrtWaitAndResetNotify(aclrtNotify notify, aclrtStream stream, uint32_t timeout): Blocks the execution of a specified stream until the specified Notify completes, and then resets the Notify. This is an asynchronous API.aclError aclrtGetNotifyId(aclrtNotify notify, uint32_t *notifyId): Obtains the ID of a specified Notify.aclError aclrtNotifyBatchReset(aclrtNotify *notifies, size_t num): Resets Notifies in batches.aclError aclrtNotifyGetExportKey(aclrtNotify notify, char *key, size_t len, uint64_t flags): Sets a specified Notify in the current process as an Inter-Process Communication (IPC) Notify and returns the key (that is, the shared name of the Notify), which is used to implement task synchronization between different processes on multiple devices.aclError aclrtNotifySetImportPid(aclrtNotify notify, int32_t *pid, size_t num): Sets the process trustlist for a shared Notify.aclError aclrtNotifySetImportPidInterServer(aclrtNotify notify, aclrtServerPid *serverPids, size_t num): Sets the process trustlist for a shared Notify.aclError aclrtNotifyImportByKey(aclrtNotify *notify, const char *key, uint64_t flags): Obtains the information of the key in the current process and returns the Notify pointer that can be used in the current process.
aclrtCreateNotify
aclError aclrtCreateNotify(aclrtNotify *notify, uint64_t flag)Applicable Products
- Ascend 950PR&950DT products: Supported
- Atlas A3 products: Supported
- Atlas A2 products: Supported
- Atlas 200I/500 A2 inference products: Supported
- Atlas inference products: Supported
- Atlas training products: Supported
Description
Creates a Notify.
Parameters
| Name | Input/Output | Description |
|---|---|---|
| notify | Output | Pointer to the Notify. For details about the type definition, see aclrtNotify. |
| flag | Input | Flag of the Notify pointer. Currently, the flag can be set to the following macros: - ACL_NOTIFY_DEFAULT: Enabling this bit indicates that the created Notify is called on the host by default. - ACL_NOTIFY_DEVICE_USE_ONLY: Enabling this bit indicates that the created Notify is called only on the device. The macro definitions are as follows: #define ACL_NOTIFY_DEFAULT 0x00000000U #define ACL_NOTIFY_DEVICE_USE_ONLY 0x00000001U |
Return Values
Returns 0 if the operation is successful; returns other values if the operation fails. For details, see aclError.
Constraints
The number of Notifies supported varies with the hardware model.
- For Ascend 950PR&950DT products, the maximum number of Notifies supported by a single device is 65,535.
- For Atlas A3 products and Atlas A2 products, the maximum number of Notifies supported by a single device is 8192.
- For Atlas 200I/500 A2 inference products, the maximum number of Notifies supported by a single device is 2048.
- For Atlas inference products and Atlas training products, the maximum number of Notifies supported by a single device is 1024.
aclrtDestroyNotify
aclError aclrtDestroyNotify(aclrtNotify notify)Applicable Products
- Ascend 950PR&950DT products: Supported
- Atlas A3 products: Supported
- Atlas A2 products: Supported
- Atlas 200I/500 A2 inference products: Supported
- Atlas inference products: Supported
- Atlas training products: Supported
Description
Destroys a Notify.
Parameters
| Name | Input/Output | Description |
|---|---|---|
| notify | Input | Notify to be destroyed. For details about the type definition, see aclrtNotify. |
Return Values
Returns 0 if the operation is successful; returns other values if the operation fails. For details, see aclError.
aclrtRecordNotify
aclError aclrtRecordNotify(aclrtNotify notify, aclrtStream stream)Applicable Products
- Ascend 950PR&950DT products: Supported
- Atlas A3 products: Supported
- Atlas A2 products: Supported
- Atlas 200I/500 A2 inference products: Supported
- Atlas inference products: Supported
- Atlas training products: Supported
Description
Records a Notify on a specified stream. This is an asynchronous API.
When used in conjunction with aclrtWaitAndResetNotify, aclrtRecordNotify is mainly used for synchronization waiting between multiple streams.
Parameters
| Name | Input/Output | Description |
|---|---|---|
| notify | Input | Notify to be recorded. For details about the type definition, see aclrtNotify. |
| stream | Input | Stream. For details about the type definition, see aclrtStream. In a multi-stream synchronization waiting scenario, for example, where Stream2 waits for Stream1, set this parameter to Stream1. |
Return Values
Returns 0 if the operation is successful; returns other values if the operation fails. For details, see aclError.
aclrtWaitAndResetNotify
aclError aclrtWaitAndResetNotify(aclrtNotify notify, aclrtStream stream, uint32_t timeout)Applicable Products
- Ascend 950PR&950DT products: Supported
- Atlas A3 products: Supported
- Atlas A2 products: Supported
- Atlas 200I/500 A2 inference products: Supported
- Atlas inference products: Supported
- Atlas training products: Supported
Description
Blocks the execution of the specified stream until the specified Notify is complete, and then resets the Notify. This is an asynchronous API.
Parameters
| Name | Input/Output | Description |
|---|---|---|
| notify | Input | Notify to wait for. For details about the type definition, see aclrtNotify. |
| stream | Input | Stream. For details about the type definition, see aclrtStream. In a multi-stream synchronous waiting scenario, for example, when Stream2 waits for Stream1, set this parameter to Stream2. |
| timeout | Input | Timeout period for waiting. The value options are as follows: - 0: permanent waiting. - >0: specific timeout period, in seconds. |
Return Values
Returns 0 if the operation is successful; returns other values if the operation fails. For details, see aclError.
aclrtGetNotifyId
aclError aclrtGetNotifyId(aclrtNotify notify, uint32_t *notifyId)Applicable Products
- Ascend 950PR&950DT products: Supported
- Atlas A3 products: Supported
- Atlas A2 products: Supported
- Atlas 200I/500 A2 inference products: Supported
- Atlas inference products: Supported
- Atlas training products: Supported
Description
Obtains the ID of a specified Notify.
Parameters
| Name | Input/Output | Description |
|---|---|---|
| notify | Input | Notify to be queried. For details about the type definition, see aclrtNotify. |
| notifyId | Output | Notify ID. |
Return Values
Returns 0 if the operation is successful; returns other values if the operation fails. For details, see aclError.
aclrtNotifyBatchReset
aclError aclrtNotifyBatchReset(aclrtNotify *notifies, size_t num)Applicable Products
- Ascend 950PR&950DT products: Supported
- Atlas A3 products: Supported
- Atlas A2 products: Supported
- Atlas 200I/500 A2 inference products: Not supported
- Atlas inference products: Not supported
- Atlas training products: Not supported
Description
Resets Notifies in batches.
Parameters
| Name | Input/Output | Description |
|---|---|---|
| notifies | Input | Notify array. For details about the type definition, see aclrtNotify. |
| num | Input | Length of the Notify array. |
Return Values
Returns 0 if the operation is successful; returns other values if the operation fails. For details, see aclError.
Constraints
This operation is not supported in the Ascend virtualization instance scenario.
aclrtNotifyGetExportKey
aclError aclrtNotifyGetExportKey(aclrtNotify notify, char *key, size_t len, uint64_t flags)Applicable Products
- Ascend 950PR products: Supported
- Ascend 950DT products: Not supported
- Atlas A3 products: Supported
- Atlas A2 products: Supported
- Atlas 200I/500 A2 inference products: Not supported
- Atlas inference products: Supported
- Atlas training products: Supported
Description
Sets a specified Notify in the current process as an Inter-Process Communication (IPC) Notify and returns a key (that is, the shared name of the Notify), which is used to implement task synchronization between different processes on multiple devices.
This API must be used in conjunction with the following other key APIs to achieve inter-process task synchronization on multiple devices. The following uses process A on Device 0 and process B on Device 1 as an example to describe the API call flow for task synchronization between the two processes:
In process A:
Call aclrtCreateNotify to create a Notify.
Call aclrtNotifyGetExportKey to export the key (that is, the shared name of the Notify).
When calling aclrtNotifyGetExportKey, you can specify whether to enable process trustlist verification. If enabled, you need to separately call aclrtNotifySetImportPid to set the ID of process B to the trustlist; otherwise, there is no need to call aclrtNotifySetImportPid.
Call aclrtWaitAndResetNotify to dispatch a wait task.
Call aclrtDestroyNotify to destroy the Notify.
All processes involved in the IPC Notify must release the Notify. The Notify is actually released only after all processes involved in the IPC Notify have completed the release operation.
In process B:
Call aclrtDeviceGetBareTgid to obtain the ID of process B.
When obtaining the process ID, this API has adapted to both physical machine and virtual machine scenarios. The user only needs to call this API to obtain the process ID and then use it together with other APIs to achieve memory sharing. If the user does not call this API and obtains the process ID by themselves, subsequent use of the process ID may be abnormal.
Call aclrtNotifyImportByKey to obtain the key information and return the Notify pointer that can be used by the current process. It is recommended that flag use ACL_RT_NOTIFY_IMPORT_FLAG_ENABLE_PEER_ACCESS to enable data interaction between two devices.
Before calling aclrtNotifyImportByKey, ensure that the IPC Notify has not been released in advance.
Call aclrtRecordNotify to dispatch a Record task.
Call aclrtDestroyNotify to destroy the Notify.
Parameters
| Name | Input/Output | Description |
|---|---|---|
| notify | Input | Notify. For details about the type definition, see aclrtNotify. |
| key | Output | Shared name of the Notify. |
| len | Input | Length of the Notify shared name, with a minimum length of 65. |
| flags | Input | Whether to enable process trustlist validation. The value is one of the following macros: - ACL_RT_NOTIFY_EXPORT_FLAG_DEFAULT: enable process trustlist validation. This is the default value. When this value is set, you must separately call aclrtNotifySetImportPid to add the process ID that uses the Notify shared name to the trustlist. - ACL_RT_NOTIFY_EXPORT_FLAG_DISABLE_PID_VALIDATION: disable process trustlist validation. When this value is set, you do not need to call aclrtNotifySetImportPid. The macros are defined as follows: #define ACL_RT_NOTIFY_EXPORT_FLAG_DEFAULT 0x0UL #define ACL_RT_NOTIFY_EXPORT_FLAG_DISABLE_PID_VALIDATION 0x02UL |
Return Values
Returns 0 if the operation is successful; returns other values if the operation fails. For details, see aclError.
Constraints
This operation is not supported in the Ascend virtualization instance scenario.
aclrtNotifySetImportPid
aclError aclrtNotifySetImportPid(aclrtNotify notify, int32_t *pid, size_t num)Applicable Products
- Ascend 950PR products: Supported
- Ascend 950DT products: Not supported
- Atlas A3 products: Supported
- Atlas A2 products: Supported
- Atlas 200I/500 A2 inference products: Not supported
- Atlas inference products: Supported
- Atlas training products: Supported
Description
Sets the process trustlist for a shared Notify.
This API must be used in conjunction with other APIs to achieve task synchronization between different processes on multiple devices. For details, see the description of the aclrtNotifyGetExportKey API.
Parameters
| Name | Input/Output | Description |
|---|---|---|
| notify | Input | Notify. For details about the type definition, see aclrtNotify. It must be consistent with the Notify in the aclrtNotifyGetExportKey API. |
| pid | Input | Array used to store trustlisted process IDs. The process ID can be obtained by calling the aclrtDeviceGetBareTgid API. In a docker scenario, the obtained ID is the process ID on the physical machine; in a non-docker scenario, the obtained ID is the process ID. |
| num | Input | Number of trustlisted processes, which must be consistent with the size of the pid parameter array. |
Return Values
Returns 0 if the operation is successful; returns other values if the operation fails. For details, see aclError.
Constraints
This operation is not supported in the Ascend virtualization instance scenario.
aclrtNotifySetImportPidInterServer
aclError aclrtNotifySetImportPidInterServer(aclrtNotify notify, aclrtServerPid *serverPids, size_t num)Applicable Products
- Ascend 950PR&950DT products: Not supported
- Atlas A3 products: Supported
- Atlas A2 products: Not supported
- Atlas 200I/500 A2 inference products: Not supported
- Atlas inference products: Not supported
- Atlas training products: Not supported
Description
Sets the process trustlist of a shared Notify.
This API applies only to the super node products in the Atlas A3 products.
Parameters
| Name | Input/Output | Description |
|---|---|---|
| notify | Input | Notify. For details about the type definition, see aclrtNotify. You must first call aclrtNotifyGetExportKey to obtain the shared name of the specified Notify, and then pass it as an input parameter. |
| serverPids | Input | Trustlist information array. For details about the type definition, see aclrtServerPid. |
| num | Input | Size of the serverPids array. |
Return Values
Returns 0 if the operation is successful; returns other values if the operation fails. For details, see aclError.
aclrtNotifyImportByKey
aclError aclrtNotifyImportByKey(aclrtNotify *notify, const char *key, uint64_t flags)Applicable Products
- Ascend 950PR products: Supported
- Ascend 950DT products: Not supported
- Atlas A3 products: Supported
- Atlas A2 products: Supported
- Atlas 200I/500 A2 inference products: Not supported
- Atlas inference products: Supported
- Atlas training products: Supported
Description
Obtains the key information in the current process and returns a Notify pointer that can be used in the current process.
This API must be used in conjunction with other APIs to achieve task synchronization between different processes on multiple devices. For details, see the description of the aclrtNotifyGetExportKey API.
Parameters
| Name | Input/Output | Description |
|---|---|---|
| notify | Output | Notify pointer. For details about the type definition, see aclrtNotify. |
| key | Input | Shared name of the Notify. You must first call the aclrtNotifyGetExportKey API to obtain the shared name of the specified Notify, and then pass it as an input parameter. |
| flags | Input | Whether to enable data interaction between two devices. The value is one of the following macros: - ACL_RT_NOTIFY_IMPORT_FLAG_DEFAULT: disable data interaction between two devices. This is the default value. When this value is set, you must separately call the aclrtDeviceEnablePeerAccess API to enable data interaction between two devices. - ACL_RT_NOTIFY_IMPORT_FLAG_ENABLE_PEER_ACCESS: enable data interaction between two devices. When this value is set, there is no need to call the aclrtDeviceEnablePeerAccess API. The macro definitions are as follows: #define ACL_RT_NOTIFY_IMPORT_FLAG_DEFAULT 0x0UL #define ACL_RT_NOTIFY_IMPORT_FLAG_ENABLE_PEER_ACCESS 0x02UL |
Return Values
Returns 0 if the operation is successful; returns other values if the operation fails. For details, see aclError.
Constraints
This operation is not supported in the Ascend virtualization instance scenario.