已合并
[fix] 替换 deprecated aclrtSetExceptionInfoCallback 为新接口 Register/Unregister #4542
[fix] 替换 deprecated aclrtSetExceptionInfoCallback 为新接口 Register/Unregister #4542
已合并
zengls创建于 13 天前
11 个文件变更+65-21
Msrc/coll_communicator_mgr/dfx/taskException/host/hcclCommTaskException.cc+8-8
@@ -106,8 +106,8 @@ TaskExceptionHost::~TaskExceptionHost()
106 std::unique_lock<std::mutex> lock(taskExceptionMutex_);106 std::unique_lock<std::mutex> lock(taskExceptionMutex_);
107 if (!CommRegisterMap_.empty()) {107 if (!CommRegisterMap_.empty()) {
108 CommRegisterMap_.clear();108 CommRegisterMap_.clear();
109- aclError ret = aclrtSetExceptionInfoCallback(nullptr); // 注册给rts的TaskException回调函数指针置空109+ aclError ret = aclrtExceptionInfoCallbackUnregister(ProcessCallback); // 注销注册给rts的TaskException回调
110- HCCL_RUN_INFO("[%s]aclrtSetExceptionInfoCallback set nullptr, ret[%d]", __func__, ret);110+ HCCL_RUN_INFO("[%s]aclrtExceptionInfoCallbackUnregister, ret[%d]", __func__, ret);
111 }111 }
112}112}
113 113 
@@ -124,11 +124,11 @@ HcclResult TaskExceptionHost::Register(u64 commHandle)
124{124{
125 std::unique_lock<std::mutex> lock(taskExceptionMutex_);125 std::unique_lock<std::mutex> lock(taskExceptionMutex_);
126 if (CommRegisterMap_.empty()) {126 if (CommRegisterMap_.empty()) {
127- aclError ret = aclrtSetExceptionInfoCallback(ProcessCallback);127+ aclError ret = aclrtExceptionInfoCallbackRegister(ProcessCallback);
128 CHK_PRT_RET(128 CHK_PRT_RET(
129- ret != ACL_SUCCESS, HCCL_ERROR("[%s]aclrtSetExceptionInfoCallback failed, ret[%d]", __func__, ret),129+ ret != ACL_SUCCESS, HCCL_ERROR("[%s]aclrtExceptionInfoCallbackRegister failed, ret[%d]", __func__, ret),
130 HCCL_E_RUNTIME);130 HCCL_E_RUNTIME);
131- HCCL_RUN_INFO("[%s]aclrtSetExceptionInfoCallback set ProcessCallback success", __func__);131+ HCCL_RUN_INFO("[%s]aclrtExceptionInfoCallbackRegister set ProcessCallback success", __func__);
132 }132 }
133 133 
134 CommRegisterMap_.insert(commHandle);134 CommRegisterMap_.insert(commHandle);
@@ -146,11 +146,11 @@ HcclResult TaskExceptionHost::UnRegister(u64 commHandle)
146 146 
147 CommRegisterMap_.erase(commHandle);147 CommRegisterMap_.erase(commHandle);
148 if (CommRegisterMap_.empty()) {148 if (CommRegisterMap_.empty()) {
149- aclError ret = aclrtSetExceptionInfoCallback(nullptr); // 注册给rts的TaskException回调函数指针置空149+ aclError ret = aclrtExceptionInfoCallbackUnregister(ProcessCallback); // 注销注册给rts的TaskException回调
150 CHK_PRT_RET(150 CHK_PRT_RET(
151- ret != ACL_SUCCESS, HCCL_ERROR("[%s]aclrtSetExceptionInfoCallback failed, ret[%d]", __func__, ret),151+ ret != ACL_SUCCESS, HCCL_ERROR("[%s]aclrtExceptionInfoCallbackUnregister failed, ret[%d]", __func__, ret),
152 HCCL_E_RUNTIME);152 HCCL_E_RUNTIME);
153- HCCL_RUN_INFO("[%s]aclrtSetExceptionInfoCallback set nullptr success", __func__);153+ HCCL_RUN_INFO("[%s]aclrtExceptionInfoCallbackUnregister success", __func__);
154 }154 }
155 155 
156 HCCL_INFO("[%s]success, commHandle[0x%llx]", __func__, commHandle);156 HCCL_INFO("[%s]success, commHandle[0x%llx]", __func__, commHandle);
Msrc/coll_communicator_mgr/dfx/taskException/taskException.md+3-3
@@ -146,7 +146,7 @@ sequenceDiagram
146 Note right of CollComm: 注册AICPU异常回调146 Note right of CollComm: 注册AICPU异常回调
147 147 
148 CollComm->>TaskExceptionHost: Register148 CollComm->>TaskExceptionHost: Register
149- Note right of TaskExceptionHost: 写入CommRegisterMap_<br/>首个comm注册时调用<br/>aclrtSetExceptionInfoCallback149+ Note right of TaskExceptionHost: 写入CommRegisterMap_<br/>首个comm注册时调用<br/>aclrtExceptionInfoCallbackRegister
150 150 
151 hcomm_c_adpt->>HcclCommDfx: GetMirrorTaskManager151 hcomm_c_adpt->>HcclCommDfx: GetMirrorTaskManager
152 HcclCommDfx-->>hcomm_c_adpt: mirrorTaskManager152 HcclCommDfx-->>hcomm_c_adpt: mirrorTaskManager
@@ -580,8 +580,8 @@ classDiagram
580| 接口 | 类型 | 参数 | 返回值 | 功能说明 |580| 接口 | 类型 | 参数 | 返回值 | 功能说明 |
581|------|------|------|--------|----------|581|------|------|------|--------|----------|
582| `GetInstance(s32)` | 公有静态 | [in] deviceLogicID | `TaskExceptionHost*` | 获取指定设备的异常处理器,最大支持 65 个设备 |582| `GetInstance(s32)` | 公有静态 | [in] deviceLogicID | `TaskExceptionHost*` | 获取指定设备的异常处理器,最大支持 65 个设备 |
583-| `Register(u64)` | 公有 | [in] commHandle | `HcclResult` | 将 commHandle 写入 CommRegisterMap_;首个 comm 注册时调用 `aclrtSetExceptionInfoCallback(ProcessCallback)` 向 RTS 注册异常回调 |583+| `Register(u64)` | 公有 | [in] commHandle | `HcclResult` | 将 commHandle 写入 CommRegisterMap_;首个 comm 注册时调用 `aclrtExceptionInfoCallbackRegister(ProcessCallback)` 向 RTS 注册异常回调 |
584-| `UnRegister(u64)` | 公有 | [in] commHandle | `HcclResult` | 从 CommRegisterMap_ 移除 commHandle;最后一个 comm 注销时将回设为 nullptr |584+| `UnRegister(u64)` | 公有 | [in] commHandle | `HcclResult` | 从 CommRegisterMap_ 移除 commHandle;最后一个 comm 注销时调 `aclrtExceptionInfoCallbackUnregister(ProcessCallback)` 向 RTS 注销回调 |
585| `ProcessCallback(rtExceptionInfo_t*)` | 公有静态 | [in] exceptionInfo | void | Runtime 异常回调入口,通过 GetInstance 获取处理器后转发到 Process |585| `ProcessCallback(rtExceptionInfo_t*)` | 公有静态 | [in] exceptionInfo | void | Runtime 异常回调入口,通过 GetInstance 获取处理器后转发到 Process |
586| `HandleAicpuErrorReport(rtExceptionInfo_t*, const ErrorMessageReport&, const TaskInfo&)` | 私有 | [in] exceptionInfo, [in] errorMessage, [in] taskInfo | void | 处理 AICPU 侧已上报的错误:打印 BaseInfo/ParaInfo/GroupInfo/OpDataInfo,调用 PrintUbDfxInfo、ReportErrorMsg,ubCqeStatus 非零时调用 GetAicpuCqeErrInfo |586| `HandleAicpuErrorReport(rtExceptionInfo_t*, const ErrorMessageReport&, const TaskInfo&)` | 私有 | [in] exceptionInfo, [in] errorMessage, [in] taskInfo | void | 处理 AICPU 侧已上报的错误:打印 BaseInfo/ParaInfo/GroupInfo/OpDataInfo,调用 PrintUbDfxInfo、ReportErrorMsg,ubCqeStatus 非零时调用 GetAicpuCqeErrInfo |
587| `HandleHostErrorReport(rtExceptionInfo_t*, const TaskInfo&)` | 私有 | [in] exceptionInfo, [in] taskInfo | void | Host 侧自行处理异常:TASK_NOTIFY_WAIT 时打印前序 task 上下文并上报 EI0002,打印集群监控错误信息 |587| `HandleHostErrorReport(rtExceptionInfo_t*, const TaskInfo&)` | 私有 | [in] exceptionInfo, [in] taskInfo | void | Host 侧自行处理异常:TASK_NOTIFY_WAIT 时打印前序 task 上下文并上报 EI0002,打印集群监控错误信息 |
Msrc/coll_communicator_mgr/dfx/taskException/taskException_en.md+3-3
@@ -146,7 +146,7 @@ sequenceDiagram
146 Note right of CollComm: Register AICPU exception callback146 Note right of CollComm: Register AICPU exception callback
147 147 
148 CollComm->>TaskExceptionHost: Register148 CollComm->>TaskExceptionHost: Register
149- Note right of TaskExceptionHost: Write to CommRegisterMap_. The first comm registration calls aclrtSetExceptionInfoCallback.149+ Note right of TaskExceptionHost: Write to CommRegisterMap_. The first comm registration calls aclrtExceptionInfoCallbackRegister.
150 150 
151 hcomm_c_adpt->>HcclCommDfx: GetMirrorTaskManager151 hcomm_c_adpt->>HcclCommDfx: GetMirrorTaskManager
152 HcclCommDfx-->>hcomm_c_adpt: mirrorTaskManager152 HcclCommDfx-->>hcomm_c_adpt: mirrorTaskManager
@@ -580,8 +580,8 @@ classDiagram
580| Interface | Type | Parameters | Return Value | Description |580| Interface | Type | Parameters | Return Value | Description |
581|------|------|------|--------|----------|581|------|------|------|--------|----------|
582| `GetInstance(s32)` | Public static | [in] deviceLogicID | `TaskExceptionHost*` | Gets the exception handler for the specified device. Supports up to 65 devices. |582| `GetInstance(s32)` | Public static | [in] deviceLogicID | `TaskExceptionHost*` | Gets the exception handler for the specified device. Supports up to 65 devices. |
583-| `Register(u64)` | Public | [in] commHandle | `HcclResult` | Writes commHandle to CommRegisterMap_. The first comm registration calls `aclrtSetExceptionInfoCallback(ProcessCallback)` to register the exception callback with RTS. |583+| `Register(u64)` | Public | [in] commHandle | `HcclResult` | Writes commHandle to CommRegisterMap_. The first comm registration calls `aclrtExceptionInfoCallbackRegister(ProcessCallback)` to register the exception callback with RTS. |
584-| `UnRegister(u64)` | Public | [in] commHandle | `HcclResult` | Removes commHandle from CommRegisterMap_. When the last comm is unregistered, sets the callback to nullptr. |584+| `UnRegister(u64)` | Public | [in] commHandle | `HcclResult` | Removes commHandle from CommRegisterMap_. When the last comm is unregistered, calls `aclrtExceptionInfoCallbackUnregister(ProcessCallback)` to unregister the callback with RTS. |
585| `ProcessCallback(rtExceptionInfo_t*)` | Public static | [in] exceptionInfo | void | Runtime exception callback entry point. Obtains the handler through GetInstance and forwards to Process. |585| `ProcessCallback(rtExceptionInfo_t*)` | Public static | [in] exceptionInfo | void | Runtime exception callback entry point. Obtains the handler through GetInstance and forwards to Process. |
586| `HandleAicpuErrorReport(rtExceptionInfo_t*, const ErrorMessageReport&, const TaskInfo&)` | Private | [in] exceptionInfo, [in] errorMessage, [in] taskInfo | void | Handles errors already reported by the AICPU side: prints BaseInfo/ParaInfo/GroupInfo/OpDataInfo, calls PrintUbDfxInfo, ReportErrorMsg. When ubCqeStatus is non-zero, calls GetAicpuCqeErrInfo. |586| `HandleAicpuErrorReport(rtExceptionInfo_t*, const ErrorMessageReport&, const TaskInfo&)` | Private | [in] exceptionInfo, [in] errorMessage, [in] taskInfo | void | Handles errors already reported by the AICPU side: prints BaseInfo/ParaInfo/GroupInfo/OpDataInfo, calls PrintUbDfxInfo, ReportErrorMsg. When ubCqeStatus is non-zero, calls GetAicpuCqeErrInfo. |
587| `HandleHostErrorReport(rtExceptionInfo_t*, const TaskInfo&)` | Private | [in] exceptionInfo, [in] taskInfo | void | Host-side independent exception handling: prints preceding task context for TASK_NOTIFY_WAIT and reports EI0002, prints cluster monitoring error info. |587| `HandleHostErrorReport(rtExceptionInfo_t*, const TaskInfo&)` | Private | [in] exceptionInfo, [in] taskInfo | void | Host-side independent exception handling: prints preceding task context for TASK_NOTIFY_WAIT and reports EI0002, prints cluster monitoring error info. |
Msrc/legacy/ascend950/framework/dfx/task_exception/task_exception_handler.cpp+1-1
@@ -64,7 +64,7 @@ void TaskExceptionHandler::Register() const
64 HCCL_INFO("[TaskExceptionHandler]exception process func registered.");64 HCCL_INFO("[TaskExceptionHandler]exception process func registered.");
65}65}
66 66 
67-void TaskExceptionHandler::UnRegister() const { HrtRegTaskFailCallbackByModule(nullptr); }67+void TaskExceptionHandler::UnRegister() const { HrtUnregTaskFailCallbackByModule(Process); }
68 68 
69TaskExceptionHandler* TaskExceptionHandlerManager::GetHandler(size_t devId)69TaskExceptionHandler* TaskExceptionHandlerManager::GetHandler(size_t devId)
70{70{
Msrc/legacy/ascend950/unified_platform/external_system/orion_adapter_rts.cc+13-2
@@ -1092,10 +1092,21 @@ void HrtAicpuLaunchKernelWithHostArgs(
1092void HrtRegTaskFailCallbackByModule(aclrtExceptionInfoCallback callback)1092void HrtRegTaskFailCallbackByModule(aclrtExceptionInfoCallback callback)
L
Llaodazhao113 天前
已过期

aclrtExceptionInfoCallbackRegister是新开发的接口吗?新的hcomm配套老的rts兼容性怎么处理?

likedislike
1093{1093{
1094 HCCL_INFO("[HrtRegTaskFailCallbackByModule] callback[%p].", callback);1094 HCCL_INFO("[HrtRegTaskFailCallbackByModule] callback[%p].", callback);
1095- aclError ret = aclrtSetExceptionInfoCallback(callback);1095+ aclError ret = aclrtExceptionInfoCallbackRegister(callback);
atomgit-bot
atomgit-botatomgit-bot13 天前

🟠 High Priority

变更行 1095:aclrtSetExceptionInfoCallback(callback) 被替换为 aclrtExceptionInfoCallbackRegister(callback),但未按 PR 描述要求对 callback == nullptr 做分流。

旧接口 aclrtSetExceptionInfoCallback 传入 nullptr 即表示注销回调;新接口中 Register/Unregister 已拆分为两个独立函数。HrtRegTaskFailCallbackByModule 的调用方 TaskExceptionHandler::UnRegister()(task_exception_handler.cpp:67)传入的正是 nullptr: void TaskExceptionHandler::UnRegister() const { HrtRegTaskFailCallbackByModule(nullptr); } 由于 HrtRegTaskFailCallbackByModule 无条件调用 aclrtExceptionInfoCallbackRegister(nullptr),Unregister 路径实际将空指针注册为回调,而非注销之前注册的 Process 回调。这导致 task exception 注销逻辑完全失效,可能引发回调悬挂或其他未定义行为。

修复方向:在 HrtRegTaskFailCallbackByModule 函数体内根据 callback 是否为空分流:

建议:在 HrtRegTaskFailCallbackByModule 函数体内增加 callback 空值判断,分流到 Register 或 Unregister 接口。同时更新对应的错误日志消息。

likedislike
zengls
13 天前 评论:
1096 if (ret != ACL_SUCCESS) {1096 if (ret != ACL_SUCCESS) {
1097 string msg1097 string msg
1098- = StringFormat("Call aclrtSetExceptionInfoCallback failed. return[%d], callback[%p].", ret, callback);1098+ = StringFormat("Call aclrtExceptionInfoCallbackRegister failed. return[%d], callback[%p].", ret, callback);
1099+ THROW<RuntimeApiException>(msg);
L
Llaodazhao113 天前

建议不要使用抛异常

likedislike
1100+ }
1101+}
1102+ 
1103+void HrtUnregTaskFailCallbackByModule(aclrtExceptionInfoCallback callback)
1104+{
1105+ HCCL_INFO("[HrtUnregTaskFailCallbackByModule] callback[%p].", callback);
1106+ aclError ret = aclrtExceptionInfoCallbackUnregister(callback);
1107+ if (ret != ACL_SUCCESS) {
1108+ string msg = StringFormat(
1109+ "Call aclrtExceptionInfoCallbackUnregister failed. return[%d], callback[%p].", ret, callback);
1099 THROW<RuntimeApiException>(msg);1110 THROW<RuntimeApiException>(msg);
L
Llaodazhao113 天前

建议不要使用抛异常

likedislike
1100 }1111 }
1101}1112}
Msrc/legacy/ascend950/unified_platform/external_system/orion_adapter_rts.h+1-0
@@ -295,6 +295,7 @@ void HrtAicpuLaunchKernelWithHostArgs(
295 295 
296// rts task exception api296// rts task exception api
297void HrtRegTaskFailCallbackByModule(aclrtExceptionInfoCallback callback);297void HrtRegTaskFailCallbackByModule(aclrtExceptionInfoCallback callback);
298+void HrtUnregTaskFailCallbackByModule(aclrtExceptionInfoCallback callback);
298 299 
299// 添加任一task后可获取得到 taskId, streamId300// 添加任一task后可获取得到 taskId, streamId
300void HrtGetTaskIdAndStreamID(u32& taskId, u32& streamId);301void HrtGetTaskIdAndStreamID(u32& taskId, u32& streamId);
Mtest/hccl_vm/src/proxy/aclrt_exception_stub.cc+8-1
@@ -28,7 +28,14 @@
28extern "C" {28extern "C" {
29#endif // __cplusplus29#endif // __cplusplus
30 30 
31-aclError aclrtSetExceptionInfoCallback(aclrtExceptionInfoCallback callback)31+aclError aclrtExceptionInfoCallbackRegister(aclrtExceptionInfoCallback callback)
32+{
33+ (void)callback;
34+ HCCL_VM_TRACE("not supported");
35+ return ACL_SUCCESS;
36+}
37+ 
38+aclError aclrtExceptionInfoCallbackUnregister(aclrtExceptionInfoCallback callback)
32{39{
33 (void)callback;40 (void)callback;
34 HCCL_VM_TRACE("not supported");41 HCCL_VM_TRACE("not supported");
Mtest/legacy/st/fwk/rts_stub/rts_stub.cc+2-1
@@ -381,7 +381,8 @@ rtError_t rtStreamGetSqid(const rtStream_t stm, uint32_t* sqId) { return RT_ERRO
381 381 
382rtError_t rtStreamGetCqid(const rtStream_t stm, uint32_t* cqId, uint32_t* logicCqId) { return RT_ERROR_NONE; }382rtError_t rtStreamGetCqid(const rtStream_t stm, uint32_t* cqId, uint32_t* logicCqId) { return RT_ERROR_NONE; }
383 383 
384-aclError aclrtSetExceptionInfoCallback(aclrtExceptionInfoCallback callback) { return ACL_SUCCESS; }384+aclError aclrtExceptionInfoCallbackRegister(aclrtExceptionInfoCallback callback) { return ACL_SUCCESS; }
385+aclError aclrtExceptionInfoCallbackUnregister(aclrtExceptionInfoCallback callback) { return ACL_SUCCESS; }
385 386 
386rtError_t rtNotifyCreateWithFlag(int32_t deviceId, rtNotify_t* notify, uint32_t flag) { return RT_ERROR_NONE; }387rtError_t rtNotifyCreateWithFlag(int32_t deviceId, rtNotify_t* notify, uint32_t flag) { return RT_ERROR_NONE; }
387 388 
Mtest/legacy/ut/unified_platform/external_system/system/rts_stub_ut.cc+2-1
@@ -304,7 +304,8 @@ rtError_t rtStreamGetSqid(const rtStream_t stm, uint32_t* sqId) { return RT_ERRO
304 304 
305rtError_t rtStreamGetCqid(const rtStream_t stm, uint32_t* cqId, uint32_t* logicCqId) { return RT_ERROR_NONE; }305rtError_t rtStreamGetCqid(const rtStream_t stm, uint32_t* cqId, uint32_t* logicCqId) { return RT_ERROR_NONE; }
306 306 
307-aclError aclrtSetExceptionInfoCallback(aclrtExceptionInfoCallback callback) { return ACL_SUCCESS; }307+aclError aclrtExceptionInfoCallbackRegister(aclrtExceptionInfoCallback callback) { return ACL_SUCCESS; }
308+aclError aclrtExceptionInfoCallbackUnregister(aclrtExceptionInfoCallback callback) { return ACL_SUCCESS; }
308 309 
309rtError_t rtNotifyCreateWithFlag(int32_t deviceId, rtNotify_t* notify, uint32_t flag) { return RT_ERROR_NONE; }310rtError_t rtNotifyCreateWithFlag(int32_t deviceId, rtNotify_t* notify, uint32_t flag) { return RT_ERROR_NONE; }
310 311 
Mtest/stub/depends/include/acl/acl_rt.h+22-0
@@ -764,6 +764,28 @@ ACL_FUNC_VISIBILITY aclError aclrtGetLastError(aclrtLastErrLevel level);
764 */764 */
765ACL_FUNC_VISIBILITY aclError aclrtSetExceptionInfoCallback(aclrtExceptionInfoCallback callback);765ACL_FUNC_VISIBILITY aclError aclrtSetExceptionInfoCallback(aclrtExceptionInfoCallback callback);
766 766 
767+/**
768+ * @ingroup AscendCL
769+ * @brief Register a callback function to handle exception information
770+ *
771+ * @param callback [IN] callback function to handle exception information
772+ *
773+ * @retval ACL_SUCCESS The function is successfully executed.
774+ * @retval OtherValues Failure
775+ */
776+ACL_FUNC_VISIBILITY aclError aclrtExceptionInfoCallbackRegister(aclrtExceptionInfoCallback callback);
777+ 
778+/**
779+ * @ingroup AscendCL
780+ * @brief Unregister the exception information callback function
781+ *
782+ * @param callback [IN] callback function to unregister
783+ *
784+ * @retval ACL_SUCCESS The function is successfully executed.
785+ * @retval OtherValues Failure
786+ */
787+ACL_FUNC_VISIBILITY aclError aclrtExceptionInfoCallbackUnregister(aclrtExceptionInfoCallback callback);
788+ 
767/**789/**
768 * @ingroup AscendCL790 * @ingroup AscendCL
769 * @brief Get task id from exception information791 * @brief Get task id from exception information
Mtest/ut/stub/llt_next_orion_stub.cc+2-1
@@ -1637,7 +1637,8 @@ HcclResult RaGetAuxInfo(const RdmaHandle rdmaHandle, AuxInfoIn auxInfoIn, AuxInf
1637void HrtRaSocketGetVnicIpInfos(u32 phyId, DeviceIdType deviceIdType, u32 deviceId, IpAddress& vnicIP) {}1637void HrtRaSocketGetVnicIpInfos(u32 phyId, DeviceIdType deviceIdType, u32 deviceId, IpAddress& vnicIP) {}
1638 1638 
1639extern "C" {1639extern "C" {
1640-aclError aclrtSetExceptionInfoCallback(aclrtExceptionInfoCallback callback) { return ACL_ERROR_NONE; }1640+aclError aclrtExceptionInfoCallbackRegister(aclrtExceptionInfoCallback callback) { return ACL_ERROR_NONE; }
1641+aclError aclrtExceptionInfoCallbackUnregister(aclrtExceptionInfoCallback callback) { return ACL_ERROR_NONE; }
1641}1642}
1642 1643 
1643u32 Hccl::HcclCommunicator::GetRankInParentComm() { return 0; }1644u32 Hccl::HcclCommunicator::GetRankInParentComm() { return 0; }