Merged
[feat]: 支持device传输异常上报 #681
lining23666Add on Jun 26
[feat]: 支持device传输异常上报 #681
Merged
lining23666Add on Jun 26
Total: 20 files changed+1455-5
@@ -0,0 +1,91 @@
1+/**
2+ * Copyright (c) 2026 Huawei Technologies Co., Ltd.
3+ * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
4+ * CANN Open Software License Agreement Version 2.0 (the "License").
5+ * Please refer to the License for details. You may not use this file except in compliance with the License.
6+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7+ * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8+ * See LICENSE in the root of the software repository for the full text of the License.
9+ */
10+ 
11+#ifndef HCOMM_EXCEPTION_NOTIFY_H
12+#define HCOMM_EXCEPTION_NOTIFY_H
13+ 
14+#include <stdint.h>
15+ 
16+#ifdef __cplusplus
17+extern "C" {
18+#endif
19+ 
20+/**
21+ * @brief 异常扩展信息类型枚举
22+ */
23+typedef enum tagHcommExceptionExpandType {
24+ HCOMM_EXCEPTION_INVALID = 0,
25+ HCOMM_EXCEPTION_STARS,
26+ HCOMM_EXCEPTION_ROCE_HOST,
27+ HCOMM_EXCEPTION_ROCE_DEVICE,
28+ HCOMM_EXCEPTION_UB_HOST,
29+ HCOMM_EXCEPTION_UB_DEVICE,
30+} HcommExceptionExpandType;
31+ 
32+/**
33+ * @brief STARS异常详情信息
34+ * 当异常类型为HCOMM_EXCEPTION_STARS时使用
35+ */
36+typedef struct tagStarsExDetailInfo {
37+ uint32_t starsErrcode;
38+ uint8_t seqType;
39+ uint8_t statusMerged;
40+ uint8_t rsvd[122]; // 结构体对齐128
41+} StarsExDetailInfo;
42+ 
43+/**
44+ * @brief 异常扩展信息
45+ */
46+typedef struct tagHcommExceptionExpandInfo {
47+ HcommExceptionExpandType type;
48+ union {
49+ StarsExDetailInfo starsInfo;
50+ } detail;
51+} HcommExceptionExpandInfo;
52+ 
53+/**
54+ * @brief 异常信息结构体
55+ */
56+typedef struct tagHcommExceptionInfo {
57+ uint64_t thread;
58+ uint64_t channel;
59+ uint32_t taskId;
60+ uint32_t retCode;
61+ uint8_t rsvd[40];
62+ HcommExceptionExpandInfo expandInfo;
63+} HcommExceptionInfo;
64+ 
65+/**
66+ * @brief 异常回调函数原型
67+ * @param[in] exceptionInfo 异常信息
68+ * @param[in] userData 用户自定义数据指针
69+ */
70+typedef void (*ExceptionCallback)(const HcommExceptionInfo *exceptionInfo, void *userData);
71+ 
72+/**
73+ * @brief 注册异常回调
74+ * @param[in] cb 回调函数指针
75+ * @param[in] userData 用户自定义数据指针,回调时透传
76+ * @return 0表示成功,非0表示失败
77+ */
78+int32_t HcommRegisterExceptionCallback(ExceptionCallback cb, void *userData);
79+ 
80+/**
81+ * @brief 注销异常回调
82+ * @param[in] cb 需要注销的回调函数指针
83+ * @return 0表示成功,非0表示失败
84+ */
85+int32_t HcommUnregisterExceptionCallback(ExceptionCallback cb);
86+ 
87+#ifdef __cplusplus
88+}
89+#endif
90+ 
91+#endif
@@ -65,6 +65,9 @@ __attribute__((weak)) int32_t HcommBatchTransferOnThread(ThreadHandle thread, Ch
65 uint32_t transfer_desc_num);65 uint32_t transfer_desc_num);
66 66 
67__attribute__((weak)) int32_t HcommAclrtNotifyRecordOnThread(ThreadHandle thread, uint64_t dstNotifyId);67__attribute__((weak)) int32_t HcommAclrtNotifyRecordOnThread(ThreadHandle thread, uint64_t dstNotifyId);
68+ 
69+__attribute__((weak)) int32_t HcommRegisterExceptionCallback(ExceptionCallback cb, void *user_data);
70+__attribute__((weak)) int32_t HcommUnregisterExceptionCallback(ExceptionCallback cb);
68}71}
69 72 
70namespace hixl {73namespace hixl {
@@ -213,4 +216,20 @@ int32_t HcommProxy::aclrtNotifyRecordOnThread(ThreadHandle thread, int32_t notif
213 return HcommAclrtNotifyRecordOnThread(thread, notify_id);216 return HcommAclrtNotifyRecordOnThread(thread, notify_id);
214}217}
215 218 
219+int32_t HcommProxy::RegisterExceptionCallback(ExceptionCallback cb, void *user_data) {
220+ if (HcommRegisterExceptionCallback == nullptr) {
221+ HIXL_LOGI("function HcommRegisterExceptionCallback is null, maybe unsupported.");
222+ return HCCL_E_NOT_SUPPORT;
223+ }
224+ return HcommRegisterExceptionCallback(cb, user_data);
225+}
226+ 
227+int32_t HcommProxy::UnregisterExceptionCallback(ExceptionCallback cb) {
228+ if (HcommUnregisterExceptionCallback == nullptr) {
229+ HIXL_LOGI("function HcommUnregisterExceptionCallback is null, maybe unsupported.");
230+ return HCCL_E_NOT_SUPPORT;
231+ }
232+ return HcommUnregisterExceptionCallback(cb);
233+}
234+ 
216} // namespace hixl235} // namespace hixl
@@ -12,6 +12,7 @@
12#define CANN_HIXL_SRC_PROXY_HCOMM_PROXY_H_12#define CANN_HIXL_SRC_PROXY_HCOMM_PROXY_H_
13 13 
14#include "hcomm/hcomm_res_defs.h"14#include "hcomm/hcomm_res_defs.h"
15+#include "hcomm/hcomm_exception_notify.h"
15#include "hccl/hccl_types.h"16#include "hccl/hccl_types.h"
16 17 
17namespace hixl {18namespace hixl {
@@ -47,6 +48,8 @@ class HcommProxy {
47 static int32_t BatchTransferOnThread(ThreadHandle thread, ChannelHandle channel,48 static int32_t BatchTransferOnThread(ThreadHandle thread, ChannelHandle channel,
48 const HcommBatchTransferDesc *transfer_descs, uint32_t transfer_desc_num);49 const HcommBatchTransferDesc *transfer_descs, uint32_t transfer_desc_num);
49 static int32_t aclrtNotifyRecordOnThread(ThreadHandle thread, int32_t notify_id);50 static int32_t aclrtNotifyRecordOnThread(ThreadHandle thread, int32_t notify_id);
51+ static int32_t RegisterExceptionCallback(ExceptionCallback cb, void *user_data);
52+ static int32_t UnregisterExceptionCallback(ExceptionCallback cb);
50};53};
51 54 
52} // namespace hixl55} // namespace hixl
@@ -19,11 +19,13 @@ add_library(cann_hixl_kernel SHARED
19 hixl_batch_transfer.cc19 hixl_batch_transfer.cc
20 hixl_sync_transfer_context.cc20 hixl_sync_transfer_context.cc
21 transfer_context_manager.cc21 transfer_context_manager.cc
22+ task_exception_handler.cc
22)23)
23 24 
24target_include_directories(cann_hixl_kernel PRIVATE25target_include_directories(cann_hixl_kernel PRIVATE
25 ${INCLUDE_LIST}26 ${INCLUDE_LIST}
26 ${HIXL_CODE_DIR}/src/hixl/proxy27 ${HIXL_CODE_DIR}/src/hixl/proxy
28+ ${CMAKE_CURRENT_SOURCE_DIR}/extern_include
27)29)
28 30 
29target_link_libraries(cann_hixl_kernel PRIVATE31target_link_libraries(cann_hixl_kernel PRIVATE
@@ -0,0 +1,345 @@
1+/**
2+ * Copyright (c) 2025 Huawei Technologies Co., Ltd.
3+ * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
4+ * CANN Open Software License Agreement Version 2.0 (the "License").
5+ * Please refer to the License for details. You may not use this file except in compliance with the License.
6+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7+ * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8+ * See LICENSE in the root of the software repository for the full text of the License.
9+ */
10+ 
11+#ifndef TS_AICPU_MSG_H
12+#define TS_AICPU_MSG_H
13+ 
14+#include <stdint.h>
15+ 
16+#ifdef __cplusplus
17+extern "C" {
18+#endif /* __cplusplus */
19+ 
20+/* ================================== for obp ============================ */
21+enum tag_ts_aicpu_mail_box_cmd_type {
22+ AICPU_MSG_VERSION = 0, /* 0 aicpu msg version */
23+ AICPU_MODEL_OPERATE, /* 1 aicpu model operate */
24+ AICPU_MODEL_OPERATE_RESPONSE, /* 2 aicpu model operate response */
25+ AIC_TASK_REPORT, /* 3 aic task report */
26+ AICPU_ACTIVE_STREAM, /* 4 aicpu active stream */
27+ AICPU_NOTIFY_RECORD, /* 5 aicpu notify */
28+ AICPU_DATADUMP_REPORT, /* 6 data dump report */
29+ AICPU_DATADUMP_LOADINFO, /* 7 data dump load info */
30+ AICPU_DATADUMP_RESPONSE, /* 8 data dump response */
31+ AICPU_ABNORMAL, /* 9 aicpu abnormal report */
32+ AICPU_TASK_ACTIVE_FOR_WAIT, /* 10 aicpu dvpp task active */
33+ AICPU_NOTICE_TS_PID, /* 11 aicpu pid */
34+ AICPU_RECORD, /* 12 aicpu record: 1-event_record; 2-notify_record */
35+ AICPU_TIMEOUT_CONFIG, /* 13 aicpu timeout config */
36+ AICPU_TIMEOUT_CONFIG_RESPONSE, /* 14 aicpu timeout response */
37+ CALLBACK_RECORD, /* 15 synchronized callback record from runtime, not for aicpu */
38+ AICPU_ERR_MSG_REPORT, /* 16 aicpu err msg report */
39+ AICPU_FFTS_PLUS_DATADUMP_REPORT, /* 17 ffts plus data dump report */
40+ AICPU_INFO_LOAD, /* 18 aicpu info load for tiling key sink */
41+ AICPU_INFO_LOAD_RESPONSE, /* 19 aicpu info load response */
42+ AIC_ERROR_REPORT, /* 20 aic task err report */
43+ INVALID_AICPU_CMD, /* invalid flag */
44+};
45+ 
46+typedef struct tag_ts_aicpu_msg_version {
47+ volatile uint16_t magic_num;
48+ volatile uint16_t version;
49+} ts_aicpu_msg_version_t;
50+ 
51+typedef struct tag_ts_aicpu_active_stream {
52+ volatile uint16_t stream_id;
53+ volatile uint8_t reserved[6];
54+ volatile uint64_t aicpu_stamp;
55+} ts_aicpu_active_stream_t;
56+ 
57+typedef struct tag_ts_aicpu_model_operate {
58+ volatile uint64_t arg_ptr;
59+ volatile uint16_t sq_id;
60+ volatile uint16_t task_id;
61+ volatile uint16_t model_id;
62+ volatile uint8_t cmd_type;
63+ volatile uint8_t reserved;
64+} ts_aicpu_model_operate_t;
65+ 
66+typedef struct tag_ts_aicpu_model_operate_response {
67+ volatile uint8_t cmd_type;
68+ volatile uint8_t sub_cmd_type;
69+ volatile uint16_t model_id;
70+ volatile uint16_t task_id;
71+ volatile uint16_t result_code;
72+ volatile uint16_t sq_id;
73+ volatile uint8_t reserved[2];
74+} ts_aicpu_model_operate_response_t;
75+ 
76+typedef struct tag_ts_to_aicpu_task_report {
77+ volatile uint16_t model_id;
78+ volatile uint16_t stream_id;
79+ volatile uint16_t task_id;
80+ volatile uint16_t result_code;
81+} ts_to_aicpu_task_report_t;
82+ 
83+typedef struct tag_ts_to_aicpu_aic_err_report {
84+ volatile uint64_t aiv_err_bitmap;
85+ volatile uint32_t aic_err_bitmap;
86+ volatile uint16_t result_code;
87+} ts_to_aicpu_aic_err_report_t;
88+ 
89+typedef struct tag_ts_aicpu_notify {
90+ volatile uint32_t notify_id;
91+ volatile uint16_t ret_code; // using ts_error_t
92+} ts_aicpu_notify_t;
93+ 
94+typedef struct tag_ts_aicpu_event {
95+ volatile uint32_t record_id;
96+ volatile uint8_t record_type;
97+ volatile uint8_t reserved;
98+ volatile uint16_t ret_code; // using ts_error_t
99+ volatile uint16_t fault_task_id; // using report error of operator
100+ volatile uint16_t fault_stream_id; // using report error of operator
101+} ts_aicpu_record_t;
102+ 
103+typedef struct tag_ts_to_aicpu_datadump {
104+ volatile uint16_t model_id;
105+ volatile uint16_t stream_id; // first dump task info
106+ volatile uint16_t task_id; // first dump task info
107+ volatile uint16_t stream_id1; // second dump task info
108+ volatile uint16_t task_id1; // second dump task info
109+ volatile uint16_t ack_stream_id; // record overflow dump aic task info
110+ volatile uint16_t ack_task_id; // record overflow dump aic task info
111+ volatile uint8_t reserved[2];
112+} ts_to_aicpu_datadump_t;
113+ 
114+typedef struct tag_ts_to_aicpu_ffts_plus_datadump {
115+ volatile uint16_t model_id; // model id
116+ volatile uint16_t stream_id; // first dump task info
117+ volatile uint16_t task_id; // first dump task info
118+ volatile uint16_t stream_id1; // second dump task info
119+ volatile uint16_t task_id1; // second dump task info
120+ volatile uint16_t context_id; // context id
121+ volatile uint16_t thread_id; // current thread ID
122+ volatile uint8_t reserved[2];
123+#if (defined(DAVINCI_CLOUD_V2) || defined(DAVINCI_CLOUD_V2_FFTS))
124+ volatile uint32_t pid;
125+#endif
126+} ts_to_aicpu_ffts_plus_datadump_t;
127+ 
128+typedef struct tag_ts_datadumploadinfo {
129+ volatile uint64_t dumpinfo_ptr;
130+ volatile uint32_t length;
131+ volatile uint16_t stream_id;
132+ volatile uint16_t task_id;
133+ volatile uint16_t kernel_type;
134+ volatile uint16_t reserved;
135+} ts_datadumploadinfo_t;
136+ 
137+typedef struct tag_ts_to_aicpu_datadumploadinfo {
138+ volatile uint64_t dumpinfoPtr;
139+ volatile uint32_t length;
140+ volatile uint16_t stream_id;
141+ volatile uint16_t task_id;
142+} ts_to_aicpu_datadumploadinfo_t;
143+ 
144+typedef struct tag_ts_to_aicpu_loadinfo {
145+ volatile uint64_t aicpuInfoPtr;
146+ volatile uint32_t length;
147+ volatile uint16_t stream_id;
148+ volatile uint16_t task_id;
149+} ts_to_aicpu_loadinfo_t;
150+ 
151+typedef struct tag_ts_aicpu_dump_response {
152+ volatile uint16_t task_id;
153+ volatile uint16_t result_code;
154+ volatile uint16_t stream_id;
155+ volatile uint8_t cmd_type;
156+ volatile uint8_t reserved;
157+} ts_aicpu_dump_response_t;
158+ 
159+typedef struct tag_ts_aicpu_response {
160+ volatile uint16_t task_id;
161+ volatile uint16_t result_code;
162+ volatile uint16_t stream_id;
163+ volatile uint8_t cmd_type;
164+ volatile uint8_t reserved;
165+} ts_aicpu_response_t;
166+ 
167+typedef struct tag_ts_aicpu_task_active_for_wait {
168+ volatile uint16_t stream_id;
169+ volatile uint16_t task_id;
170+ volatile uint32_t result_code;
171+} ts_aicpu_task_active_for_wait_t;
172+ 
173+typedef struct tag_ts_aicpu_timeout_config_response {
174+ uint32_t result;
175+} ts_aicpu_timeout_config_response_t;
176+ 
177+typedef struct tag_ts_callback_record {
178+ volatile uint16_t stream_id;
179+ volatile uint16_t record_id;
180+ volatile uint16_t task_id;
181+ volatile uint16_t reserved;
182+} ts_callback_record_t;
183+ 
184+typedef struct tag_ts_aicpu_err_msg_report {
185+ volatile uint32_t result_code;
186+ volatile uint16_t stream_id;
187+ volatile uint16_t task_id;
188+ volatile uint16_t offset;
189+ volatile uint8_t reserved[2];
190+} ts_aicpu_err_msg_report_t;
191+ 
192+typedef struct tag_ts_to_aicpu_timeout_config {
193+ volatile uint32_t op_wait_timeout_en : 1;
194+ volatile uint32_t op_execute_timeout_en : 1;
195+ volatile uint32_t rsv : 30;
196+ volatile uint32_t op_wait_timeout;
197+ volatile uint32_t op_execute_timeout;
198+} ts_to_aicpu_timeout_config_t;
199+ 
200+// 51 and 71 share this structure. 51 supports only 24 bytes and 71 supports 40 bytes
201+// It is recommended that macro control be performed when adding fields.
202+typedef struct tag_ts_aicpu_sqe {
203+ volatile uint32_t pid;
204+ volatile uint8_t cmd_type;
205+ volatile uint8_t vf_id;
206+ volatile uint8_t tid;
207+ volatile uint8_t ts_id;
208+ union {
209+ ts_aicpu_model_operate_t aicpu_model_operate;
210+ ts_aicpu_model_operate_response_t aicpu_model_operate_resp;
211+ ts_to_aicpu_task_report_t ts_to_aicpu_task_report;
212+ ts_aicpu_active_stream_t aicpu_active_stream;
213+ ts_aicpu_notify_t aicpu_notify;
214+ ts_aicpu_record_t aicpu_record;
215+ ts_to_aicpu_datadump_t ts_to_aicpu_datadump;
216+ ts_to_aicpu_datadumploadinfo_t ts_to_aicpu_datadumploadinfo;
217+ ts_aicpu_dump_response_t aicpu_dump_resp;
218+ ts_aicpu_task_active_for_wait_t task_active_for_wait;
219+ ts_to_aicpu_timeout_config_t ts_to_aicpu_timeout_cfg;
220+ ts_aicpu_timeout_config_response_t aicpu_timeout_cfg_resp;
221+ ts_callback_record_t callback_record; /* synchronized callback record from runtime, not for aicpu */
222+ ts_aicpu_err_msg_report_t aicpu_err_msg_report;
223+ ts_to_aicpu_ffts_plus_datadump_t ts_to_aicpu_ffts_plus_datadump;
224+ ts_to_aicpu_loadinfo_t ts_to_aicpu_info;
225+ ts_aicpu_response_t aicpu_resp;
226+ ts_to_aicpu_aic_err_report_t ts_to_aicpu_aic_err_report;
227+ ts_aicpu_msg_version_t aicpu_msg_version;
228+ } u;
229+} ts_aicpu_sqe_t;
230+ 
231+/*============================== for david =======================================*/
232+ 
233+enum tag_ts_to_aicpu_msg_cmd_type {
234+ TS_AICPU_MSG_VERSION = 0, /* 0 aicpu msg version */
235+ TS_AICPU_MODEL_OPERATE = 1, /* 1 model operate */
236+ TS_AICPU_TASK_REPORT = 2, /* 2 aic task report */
237+ TS_AICPU_ACTIVE_STREAM = 3, /* 3 aicpu active stream */
238+ TS_AICPU_RECORD = 4, /* 4 aicpu notify */
239+ TS_AICPU_NORMAL_DATADUMP_REPORT = 5, /* 5 normal data dump report */
240+ TS_AICPU_DEBUG_DATADUMP_REPORT = 6, /* 6 debug datadump report */
241+ TS_AICPU_DATADUMP_INFO_LOAD = 7, /* 7 datadump info load */
242+ TS_AICPU_TIMEOUT_CONFIG = 8, /* 8 aicpu timeout config */
243+ TS_AICPU_INFO_LOAD = 9, /* 9 aicpu info load for tiling key sink */
244+ TS_AIC_ERROR_REPORT = 10, /* 10 aic task err report */
245+ TS_INVALID_AICPU_CMD /* invalid flag */
246+};
247+ 
248+typedef struct tag_ts_aicpu_model_operate_msg {
249+ uint64_t arg_ptr;
250+ uint16_t stream_id;
251+ uint16_t model_id;
252+ uint8_t cmd_type;
253+ uint8_t reserved[3];
254+} ts_aicpu_model_operate_msg_t;
255+ 
256+typedef struct tag_ts_to_aicpu_task_report_msg {
257+ uint16_t model_id;
258+ uint16_t stream_id;
259+ uint32_t task_id;
260+ uint16_t result_code;
261+ uint16_t reserve;
262+} ts_to_aicpu_task_report_msg_t;
263+ 
264+typedef struct tag_ts_aicpu_record_msg {
265+ uint32_t record_id;
266+ uint8_t record_type;
267+ uint8_t reserved;
268+ uint16_t ret_code; // using ts_error_t
269+ uint32_t fault_task_id; // using report error of operator
270+} ts_aicpu_record_msg_t;
271+ 
272+typedef struct tag_ts_to_aicpu_normal_datadump_msg {
273+ uint32_t dump_task_id;
274+ uint16_t dump_stream_id;
275+ uint8_t is_model : 1;
276+ uint8_t rsv : 7;
277+ uint8_t dump_type;
278+} ts_to_aicpu_normal_datadump_msg_t;
279+ 
280+typedef struct tag_ts_to_aicpu_debug_datadump_msg {
281+ uint32_t dump_task_id;
282+ uint32_t debug_dump_task_id;
283+ uint16_t dump_stream_id;
284+ uint8_t is_model : 1;
285+ uint8_t rsv : 7;
286+ uint8_t dump_type;
287+} ts_to_aicpu_debug_datadump_msg_t;
288+ 
289+typedef struct ts_to_aicpu_datadump_info_load_msg {
290+ uint64_t dumpinfoPtr;
291+ uint32_t length;
292+ uint32_t task_id;
293+ uint16_t stream_id;
294+ uint16_t reserve;
295+} ts_to_aicpu_datadump_info_load_msg_t;
296+ 
297+typedef struct tag_ts_to_aicpu_info_load_msg {
298+ uint64_t aicpu_info_ptr;
299+ uint32_t length;
300+ uint32_t task_id;
301+ uint16_t stream_id;
302+ uint16_t reserve;
303+} ts_to_aicpu_info_load_msg_t;
304+ 
305+typedef struct tag_ts_aicpu_response_msg {
306+ uint32_t task_id;
307+ uint16_t stream_id;
308+ uint16_t result_code;
309+ uint8_t reserved; /* for normal/debug dump, and info load */
310+ uint8_t rsv[3];
311+} ts_aicpu_response_msg_t;
312+ 
313+typedef struct tag_ts_to_aicpu_aic_err_msg {
314+ uint16_t result_code;
315+ uint16_t aic_bitmap_num;
316+ uint16_t aiv_bitmap_num;
317+ uint8_t bitmap[26];
318+} ts_to_aicpu_aic_err_msg_t;
319+ 
320+typedef struct tag_ts_aicpu_msg_info {
321+ uint32_t pid;
322+ uint8_t cmd_type;
323+ uint8_t vf_id;
324+ uint8_t tid;
325+ uint8_t ts_id;
326+ union {
327+ ts_aicpu_msg_version_t aicpu_msg_version;
328+ ts_aicpu_model_operate_msg_t aicpu_model_operate;
329+ ts_to_aicpu_task_report_msg_t ts_to_aicpu_task_report;
330+ ts_aicpu_active_stream_t aicpu_active_stream;
331+ ts_aicpu_record_msg_t aicpu_record;
332+ ts_to_aicpu_normal_datadump_msg_t ts_to_aicpu_normal_datadump;
333+ ts_to_aicpu_debug_datadump_msg_t ts_to_aicpu_debug_datadump;
334+ ts_to_aicpu_datadump_info_load_msg_t ts_to_aicpu_datadump_info_load;
335+ ts_to_aicpu_timeout_config_t ts_to_aicpu_timeout_cfg;
336+ ts_to_aicpu_info_load_msg_t ts_to_aicpu_info_load;
337+ ts_aicpu_response_msg_t aicpu_resp;
338+ ts_to_aicpu_aic_err_msg_t aic_err_msg;
339+ } u;
340+} ts_aicpu_msg_info_t;
341+ 
342+#ifdef __cplusplus
343+}
344+#endif /* __cplusplus */
345+#endif /* TS_AICPU_MSG_H */
@@ -0,0 +1,235 @@
1+/**
2+ * Copyright (c) 2025 Huawei Technologies Co., Ltd.
zhaozhihui

日期2026

likedislike
lining23666
lining23666
Jul 28 Comments:
likedislike
3+ * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
4+ * CANN Open Software License Agreement Version 2.0 (the "License").
5+ * Please refer to the License for details. You may not use this file except in compliance with the License.
6+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7+ * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8+ * See LICENSE in the root of the software repository for the full text of the License.
9+ */
10+#ifndef TS_TASK_SCHEDULER_ERROR_H
11+#define TS_TASK_SCHEDULER_ERROR_H
12+ 
13+#ifdef __cplusplus
14+extern "C" {
15+#endif /* __cplusplus */
16+ 
17+/**
18+ * @ingroup tsch
19+ * @brief the return value of task scheduler module
20+ */
21+typedef enum tag_ts_error {
22+ TS_SUCCESS = 0x0, /**< success */
23+ TS_ERROR_UNKNOWN = 0x1, /**< unknownn error */
24+ TS_ERROR_NULL_PTR = 0x2, /**< NULL ptr */
25+ TS_ERROR_ILLEGAL_AI_CORE_ID = 0x3, /**< illegal ai core id */
26+ TS_ERROR_ILLEGAL_PARAM = 0x4, /**< illegal param */
27+ TS_ERROR_TASK_CMD_QUEUE_FULL = 0x5, /**< task cmd queue is full */
28+ TS_ERROR_TASK_CMD_QUEUE_EMPTY = 0x6, /**< task cmd queue is empty */
29+ TS_ERROR_TASK_REPORT_QUEUE_FULL = 0x7, /**< task report queue is full */
30+ TS_ERROR_TASK_REPORT_QUEUE_EMPTY = 0x8, /**< task report queue is empty */
31+ TS_ERROR_TASK_NODE_BUFF_ALL_OCCUPYED = 0x9, /**< all the node of public task buff are occupyed */
32+ TS_ERROR_TASK_NODE_BUFF_ALL_FREED = 0xA, /**< all the node of public task buff are free */
33+ TS_ERROR_L2_MEM_INSUFFICIENT_SPACE = 0xB, /**< there is not enough space on l2 memory */
34+ TS_ERROR_L2_MALLOC_FAILED = 0xC, /**< malloc l2 failed */
35+ TS_ERROR_DMA_CHANNEL_ALL_OCCUPYED = 0xD, /**< all the dma channel are occupyed */
36+ TS_ERROR_MEMCPY_OP_FAILED = 0xE, /**< memcpy failed */
37+ TS_ERROR_BS_SLOT_ALL_OCCUPYED = 0xF, /**< there is not free bs slot for new task */
38+ TS_ERROR_TBS_SLOT_REPEAT_FREE = 0x10, /**< one free bs slot cannot be freed again */
39+ TS_ERROR_PRIORITY_TASK_LIST_FULL = 0x11, /**< the priority list is full */
40+ TS_ERROR_PRIORITY_TASK_LIST_EMPTY = 0x12, /**< the priority list is empty */
41+ TS_ERROR_NO_STREAM_LIST_NEED_TO_BE_PROCESSED = 0x13, /**< there is no stream list need service */
42+ TS_ERROR_REPEAT_MARK_STREAM_NEED_SERVICE = 0x14, /**< repeat mark the stream list need service */
43+ TS_ERROR_SYS_DMA_CHANNEL_ALL_OCCUPAPYED = 0x15, /**< system dma channel all occupapyed */
44+ TS_ERROR_NO_HBML2TASKNODE_FOUND = 0x16, /**< no hbm l2 task node found */
45+ TS_ERROR_SQNODE_NODE_SLOT_ALL_OCCUPAPYED = 0x17, /**< all the node of the current sq are occupyed */
46+ TS_ERROR_CQNODE_NODE_SLOT_ALL_OCCUPAPYED = 0x18, /**< all the node of the current sq are occupyed */
47+ TS_ERROR_SQNODE_NOT_ENOUGH = 0x19, /**< the sq node is not enough for data transfer */
48+ TS_ERROR_SQNODE_SLOT_REPEAT_FREE = 0x1A, /**< sq node slot repeat free */
49+ TS_ERROR_CQNODE_SLOT_REPEAT_FREE = 0x1B, /**< cq node slot repeat free */
50+ TS_ERROR_CQ_REPORT_FAILED = 0x1C, /**< cq report failed */
51+ TS_SYS_DMA_RESET_SUCCESS = 0x1D, /**< sys dma reset success */
52+ TS_SYS_DMA_RESET_FAILED = 0x1E, /**< sys dma reset failed */
53+ TS_SYS_DMA_TRNSFER_FAILED = 0x1F, /**< sys dma transfer failed */
54+ TS_SYS_DMA_MEMADDRALIGN_FAILED = 0x20, /**< sys dma mem address align failed */
55+ TS_SYS_DMA_ERROR_QUEUE_FULL = 0x21, /**< sys dma queue full */
56+ TS_SYS_DMA_ERROR_QUEUE_EMPTY = 0x22, /**< sys dma queue empty */
57+ TS_ERROR_TIMER_EVENT_FULL = 0x23, /**< timer event full */
58+ TS_TASK_L2_DESC_ENTRY_NOT_ENOUGH = 0x24, /**< l2 description enter not enough */
59+ TS_ERROR_AICORE_TIMEOUT = 0x25, /**< aicore timeout */
60+ TS_ERROR_AICORE_EXCEPTION = 0x26, /**< aicore exception */
61+ TS_ERROR_AICORE_TRAP_EXCEPTION = 0x27, /**< aicore trap exception */
62+ TS_ERROR_AICPU_TIMEOUT = 0x28, /**< aicpu timeout */
63+ TS_ERROR_SDMA_L2_TO_DDR_MALLOC_FAIL = 0x29, /**< sdma move l2 to ddr malloc failed */
64+ TS_ERROR_AICPU_EXCEPTION = 0x2A, /**< aicpu exception */
65+ TS_ERROR_AICPU_DATADUMP_RSP_ERR = 0x2B, /**< aicpu datadump response error */
66+ TS_ERROR_AICPU_MODEL_RSP_ERR = 0x2C, /**< aicpu model operate response error */
67+ TS_ERROR_REPEAT_ACTIVE_MODEL_STREAM = 0x2D, /**< repeat active model stream */
68+ TS_ERROR_REPEAT_NOTIFY_WAIT = 0x2E, /**< repeat notify wait */
69+ TS_ERROR_AICORE_OVERFLOW = 0x2F, /**< aicore over flow error */
70+ TS_ERROR_VECTOR_CORE_TIMEOUT = 0x30, /**< vector core timeout */
71+ TS_ERROR_VECTOR_CORE_EXCEPTION = 0x31, /**< vector core exception */
72+ TS_ERROR_VECTOR_CORE_TRAP_EXCEPTION = 0x32, /**< vector core trap exception */
73+ TS_ERROR_AIVEC_OVERFLOW = 0x33, /**< aivec over flow error */
74+ TS_ERROR_AICPU_OVERFLOW = 0x34, /**< aicpu over flow error */
75+ TS_ERROR_SDMA_OVERFLOW = 0x35, /**< sdma over flow error */
76+ TS_ERROR_NORMAL_SQCQ_EXISTED = 0x36, /**< sq or cq id is existed*/
77+ TS_ERROR_SQ_CQ_INVALID = 0x37, /**< sq or cq invalid */
78+ TS_ERROR_SQ_RANGE_INVALID = 0x38, /**< sq range invalid */
79+ TS_ERROR_IRQ_INVALID = 0x39, /**< irq id invalid */
80+ TS_ERROR_LOGIC_CQID_INVALID = 0x40, /**< logic cqid invalid */
81+ TS_ERROR_APPFLAG_INVALID = 0x41, /**< app flag invalid */
82+ TS_ERROR_PHY_CQID_INVALID = 0x42, /**< physical cq id invalid */
83+ TS_ERROR_VFID_NOT_ZERO = 0x43, /**< vfid must be 0(physical vm) */
84+ TS_ERROR_VFID_NOT_RANGE = 0x44, /**< vfid not range(virtual vm) */
85+ TS_ERROR_STREAMID_INVALID = 0x45, /**< stream id invalid */
86+ TS_ERROR_VFGID_INVALID = 0x46, /**< vfgroup id invalid */
87+ TS_ERROR_AICORENUM_INVALID = 0x47, /**< aicore num invalid(virtual vm) */
88+ TS_ERROR_VM_IS_WORKING = 0x48, /**< vm is working(virtual vm) */
89+ TS_ERROR_VM_IS_IDLE = 0x49, /**< vm is idle(virtual vm) */
90+ TS_ERROR_VM_RESOURCE_CONFLICT = 0x50, /**< vm resource conflict(virtual vm) */
91+ TS_ERROR_OPER_TYPE_INVALID = 0x51, /**< operation type invalid(must be 1 or 0) */
92+ TS_ERROR_RESOURCE_TYPE_NOT_SUPPORT = 0x52, /**< resource_type not support */
93+ TS_ERROR_VIR_ID_INVALID = 0x53, /**< vir id invalid */
94+ TS_ERROR_PHY_ID_INVALID = 0x54, /**< phy id invalid */
95+ TS_ERROR_SQ_CTRL_FLAG_INVALID = 0x55, /**< sq ctrl flag invalid */
96+ TS_ERROR_APP_COUNT_INVALID = 0x56, /**< app count invalid */
97+ TS_ERROR_AICPU_INFO_LOAD_RSP_ERR = 0x57, /**< aicpu info load response error */
98+ TS_ERROR_AICORE_MTE_ERROR = 0x58, /**< aicore mte error */
99+ TS_ERROR_AICPU_ACTIVE_STREAM_FAIL = 0x59, /**< aicpu active stream error */
100+ TS_ERROR_SUSPECT_MTE_ERROR = 0x5A, /**< suspect mte error */
101+ TS_ERROR_AICORE_ERROR_SW = 0x5B, /**< aicore software error */
102+ TS_ERROR_AICORE_ERROR_HW_L = 0x5C, /**< aicore Internal hardware error */
103+ 
104+ TS_ERROR_DEBUG_INVALID_SQCQ = 0x70, /**< debug invalid sqcq */
105+ TS_ERROR_DEBUG_WRONG_COMMAND_TYPE = 0x71, /**< debug wrong command type */
106+ TS_ERROR_DEBUG_CMD_PROCESS = 0x72, /**< dbg cmd process */
107+ TS_ERROR_DEBUG_INVALID_DEVICE_STATUS = 0x73, /**< debug invalid device status */
108+ TS_ERROR_DEBUG_NOT_IN_DEBUG_STATUS = 0x74, /**< debug not in debug status */
109+ TS_ERROR_DEBUG_INVALID_TASK_STATUS = 0x75, /**< debug invalid task status */
110+ TS_ERROR_DEBUG_TASK_EMPTY = 0x76, /**< debug task empty */
111+ TS_ERROR_DEBUG_TASK_FULL = 0x77, /**< debug task full */
112+ TS_ERROR_DEBUG_TASK_NOT_EXIST = 0x78, /**< debug task not exist */
113+ TS_ERROR_DEBUG_AI_CORE_FULL = 0x79, /**< debug ai core full */
114+ TS_ERROR_DEBUG_AI_CORE_NOT_EXIST = 0x7A, /**< debug ai core not exist */
115+ TS_ERROR_DEBUG_AI_CORE_EXCEPTION = 0x7B, /**< debug ai core exception */
116+ TS_ERROR_DEBUG_AI_CORE_TIMEOUT = 0x7C, /**< debug ai core timeout */
117+ TS_ERROR_DEBUG_BREAKPOINT_FULL = 0x7D, /**< debug breakpoint full */
118+ TS_ERROR_DEBUG_READ_ERROR = 0x7E, /**< debug read error */
119+ TS_ERROR_DEBUG_WRITE_FAIL = 0x7F, /**< debug write fail */
120+ TS_QUEUE_FULL = 0x80, /**< ts queue full */
121+ TS_QUEUE_EMPTY = 0x81, /**< ts queue empty */
122+ TS_QUEUE_ALLOC_MEM_FAIL = 0x82, /**< ts queue alloc mem fail */
123+ TS_QUEUE_DATA_SIZE_UNMATCH = 0x83, /**< ts queue data size unmatch */
124+ TS_PCIE_DMA_INVLD_CPY_TYPE = 0x84, /**< pcie dma invalid copy type */
125+ TS_INVLD_CPY_DIR = 0x85, /**< invalid copy dir */
126+ TS_PCIE_DMA_INVLD_CQ_DES = 0x86, /**< pcie dma invalid cq des */
127+ TS_PCIE_DMA_CPY_ERR = 0x87, /**< pcie dma copy error */
128+ TS_PCIE_DMA_LNK_CHN_BUSY = 0x88, /**< pcie dima link channal busy */
129+ TS_ERROR_PROFILE_BUFF_FULL = 0x89, /**< profile buff full */
130+ TS_ERROR_PROFILE_MODE_CONFLICT = 0x8A, /**< profile mode conflict */
131+ TS_ERROR_PROFILE_OTHER_PID_ON = 0x8B, /**< profile other pid on */
132+ TS_ERROR_SCHD_AIC_TASK_PRELOAD_FAILED = 0x8C, /**< sched aic task preload failed */
133+ TS_ERROR_TSCPU_CLOSE_FAILED = 0x8D, /**< tscpu close failed */
134+ TS_ERROR_EXPECT_FAIL = 0x8E, /**< expect failed */
135+ TS_ERROR_REPEAT_MODEL_STREAM = 0x8F, /**< repeat model stream */
136+ TS_ERROR_STREAM_MODEL_UNBIND = 0x90, /**< the model stream unbind failed */
137+ TS_MODEL_STREAM_EXE_FAILED = 0x91, /**< the model stream execute failed */
138+ TS_ERROR_IPC_SEND_FAILED = 0x92, /**< ipc send failed */
139+ TS_ERROR_IPC_PROC_REG_FAILED = 0x93, /**< ipc process register failed */
140+ TS_STREAM_SQ_FULL = 0x94, /**< stream sq full */
141+ TS_ERROR_END_OF_SEQUENCE = 0x95, /**< end of sequence */
142+ TS_ERROR_SWITCH_STREAM_LABEL = 0x96, /**< switch stream label failed */
143+ TS_ERROR_TASK_TYPE_NOT_SUPPORT = 0x97, /**< task type not support */
144+ TS_ERROR_TRANS_SQE_FAIL = 0x98, /**< trans sqe fail */
145+ TS_MODEL_ABORT_NORMAL = 0x99, /**< model exit */
146+ TS_ERROR_RINGBUFFER_NOT_FIND = 0x100, /**< not find the ringbuffer */
147+ TS_ERROR_RINGBUFFER_MANAGE_IS_NOT_FREE = 0x101, /**< not find the idle ringbuffer manage */
148+ TS_ERROR_RINGBUFFER_IS_FULL = 0x102, /**< the current ringbuffer is full */
149+ TS_ERROR_TASK_EXCEPTION = 0x103, /**< task exception */
150+ TS_ERROR_TASK_TRAP = 0x104, /**< task trap exception */
151+ TS_ERROR_TASK_TIMEOUT = 0x105, /**< task timeout */
152+ TS_ERROR_TASK_SQE_ERROR = 0x106, /**< task sqe error */
153+ TS_ERROR_VF_SLOT_ALLOC_FAIL = 0x107, /**< vf slot alloc fail */
154+ TS_PCIE_DMA_LIMIT_CONTROL = 0x108, /**< vf mode pcie copy limit control */
155+ TS_ERROR_DEBUG_REGISTER_CONFLICT = 0x109, /**< debug register conflict */
156+ TS_ERROR_AIC_TRAP_RD_OVERFLOW = 0x10A, /**< aicore trap read overflow */
157+ TS_ERROR_AIC_TRAP_WR_OVERFLOW = 0x10B, /**< aicore trap write overflow */
158+ TS_ERROR_AIV_TRAP_RD_OVERFLOW = 0x10C, /**< aivec trap read overflow */
159+ TS_ERROR_AIV_TRAP_WR_OVERFLOW = 0x10D, /**< aivec trap write overflow */
160+ TS_ERROR_MODEL_ABORTED = 0x10E, /**< model abort */
161+ TS_ERROR_FFTSPLUS_TASK_EXCEPTION = 0x10F, /* ftsplus exception */
162+ TS_ERROR_FFTSPLUS_TASK_TRAP = 0x110, /* fftsplus trap exception */
163+ TS_ERROR_FFTSPLUS_TASK_TIMEOUT = 0x111, /* fftsplus timeout */
164+ TS_ERROR_TASK_BUS_ERROR = 0x112, /* bus error on david */
165+ TS_ERROR_TASK_RES_CONFLICT_ERROR = 0x113, /* res conflict error on david */
166+ TS_ERROR_TASK_SW_STATUS_ERROR = 0x114, /* sq sw status error on david */
167+ TS_ERROR_APP_QUEUE_FULL = 0x115, /* app queue full*/
168+ TS_ERROR_ABORT_UNFINISHED = 0x116, /* ts is aborting */
169+ TS_ERROR_STARS_QOS_ERROR = 0x117,
170+ // the following error codes are define for error msg
171+ TS_ERR_MSG_EXCEED_MAX_SIZE = 0x200,
172+ TS_ERROR_MALLOC_MEM_FAILED = 0X201, /**< malloc memory fail, system error */
173+ TS_ERROR_DELETE_NODE_FAILED = 0X202, /* delete node from list error */
174+ TS_ERROR_ONLINE_PROF_ADDR_CANNOT_BE_ZERO = 0X203, /* online profiling addr cannot be zero */
175+ TS_ERROR_GET_HWTS_TASK_LOG_ERROR = 0X204, /* not get hwts task log */
176+ TS_ERROR_KERNEL_DATA_FULL = 0X205, /* ts kernel data full */
177+ TS_ERROR_SHARED_BUFF_INVALID = 0x206, /* shared buffer invalid */
178+ TS_ERROR_READ_REGISTER_FAILED = 0x207, /* read register failed */
179+ TS_ERROR_TS_STATUS_POWER_OFF = 0x208, /* ts status power off */
180+ TS_ERROR_PRIVATE_BUFFER_FULL = 0x209, /* ts private buffer full */
181+ TS_ERROR_TRANS_ADDR_FAILED = 0x20A, /* ts trans addr failed */
182+ TS_ERROR_SDMA_ERROR = 0x20B,
183+ TS_ERROR_SDMA_TIMEOUT = 0x20C, /* hwts sdma timeout */
184+ TS_ERROR_AICORE_RESET_FAILED = 0x20D, /* aicore reset failed */
185+ TS_ERROR_AIV_RESET_FAILED = 0x20E, /* aiv reset failed */
186+ TS_ERROR_HWTS_SW_STATUS_ERROR = 0x20F, /* hwts sw status failed */
187+ TS_ERROR_HWTS_EXCEPTION = 0x210, /* hwts exception */
188+ TS_ERROR_MEMSET_FAILED = 0x211, /* memset failed */
189+ TS_ERROR_AICPU_BS_DONE_PRE_CHECK_FAILED = 0x212, /* aicpu bs done pre check failed */
190+ TS_ERROR_GOING_DOWN = 0x213,
191+ TS_ERROR_HWTS_POOL_CONFLICT = 0x214, /* hwts pool conflict */
192+ TS_ERROR_GET_SQ_ID_FAILED = 0x215, /* get stream sq id failed */
193+ TS_ERROR_MODEL_END_GRAPH_EXCEPTION = 0x216, /* end graph exception */
194+ TS_ERROR_SDMA_COPY_ERROR = 0x217,
195+ TS_ERROR_SDMA_REDUCE_ERROR = 0x218,
196+ TS_ERROR_ALLOC_STREAM_ID_FAILED = 0x219, /* alloc stream id failed */
197+ TS_ERROR_SDMA_DDRC_ERROR = 0x220, /**< sdma ddrc error */
198+ TS_ERROR_SDMA_POISON_ERROR = 0x221, /**< sdma position error */
199+ TS_ERROR_SDMA_LINK_ERROR = 0x222, /**< sdma link error */
200+ TS_ERROR_HCCL_OTHER_ERROR = 0x223, /**< hccl other error */
201+ TS_ERROR_AICPU_HCCL_OP_RETRY_FAILED = 0x224, /* aicpu hccl op retry failed */
202+ TS_ERROR_LOCAL_MEM_ERROR = 0x225, /*local mem error*/
203+ TS_ERROR_REMOTE_MEM_ERROR = 0x226, /*remote mem error*/
204+ TS_ERROR_GET_PAGES_WRONG = 0x300, /* get pages wrong */
205+ // the following error codes are ts inner codes, no need return to runtime
206+ TS_EXEC_AGAIN = 0x900, /**< task exec again */
207+ TS_PROFILE_CMD_COMPLETED = 0x901, /**< profiling config completed */
208+ TS_PROFILE_CMD_FAILED = 0x902, /**< profiling config failed */
209+ TS_EXEC_NEW_SCHE = 0x903, /**< task need use new slot sche */
210+ TS_APP_EXIT_UNFINISHED = 0x904, /**< app exit is still processing */
211+ TS_ERROR_STREAM_NOT_IN_MODEL = 0x905, /* target stream is not in model */
212+ TS_ERROR_MODEL_EXEC_REC_ACT_STREAM = 0x906, /* model is running, but active stream receive */
213+ TS_APP_EXIT_NO_SEND_CQ = 0x907, /**< app exit no send cq report */
214+ TS_STREAM_RECYCLED = 0x908, /**< stream is recycled */
215+ TS_ERROR_TS_CLOSED = 0x909, /**< sentinel mode, ts is closed */
216+ TS_ERROR_FEATURE_NOT_SUPPORT = 0x90A, /**< feature not support on this chip */
217+ // thf following error codes are ts paas to log daemon, no need to runtime
218+ TS_LOG_DEAMON_RESET_ACC_SWITCH_INVALID = 0x90B, /* log daemon reset acc switch param invalid */
219+ TS_LOG_DEAMON_CORE_SWITCH_INVALID = 0x90C, /* core switch invalid */
220+ TS_LOG_DEAMON_CORE_ID_INVALID = 0x90D, /* core id invalid */
221+ TS_LOG_DEAMON_NO_VALID_CORE_ID = 0x90E, /* no valid core id */
222+ TS_LOG_DEAMON_CORE_ID_PG_DOWN = 0x90F, /* core mask on pgmap */
223+ TS_LOG_DEAMON_NOT_SUPPORT_CORE_MASK = 0x910, /* not support core mask */
224+ TS_LOG_DEAMON_SINGLE_COMMIT_INVALID = 0x911, /* single commit invalid */
225+ TS_LOG_DEAMON_NOT_SUPPORT_AIV_CORE_MASK = 0x912, /* not support aiv core mask */
226+ TS_LOG_DEAMON_NOT_IN_POOL = 0x913, /* 51 core maybe not in pool */
227+ TS_LOG_DEAMON_CORE_POOLING_STATUS_FAIL = 0x914, /* 51 disable/enable core need pooling status */
228+ TS_ERROR_RESERVED, /**< unknown error */
229+} ts_error_t;
230+ 
231+#ifdef __cplusplus
232+}
233+#endif /* __cplusplus */
234+ 
235+#endif /* TS_TASK_SCHEDULER_ERROR_H */
@@ -172,6 +172,8 @@ uint32_t HixlBatchTransfer(bool is_read, HixlOneSideOpParam *param) {
172 return FAILED;172 return FAILED;
173 }173 }
174 174 
175+ HIXL_DISMISSABLE_GUARD(err_flag_guard, ([&ctx]() { ctx->WriteErrorFlag(); }));
176+ 
175 constexpr const char *kBatchTag = "HixlKernel";177 constexpr const char *kBatchTag = "HixlKernel";
176 int32_t ret = HcommProxy::BatchModeStart(kBatchTag);178 int32_t ret = HcommProxy::BatchModeStart(kBatchTag);
177 HIXL_CHK_BOOL_RET_STATUS(ret == 0, FAILED, "[HixlBatchPutAndGet] HcommBatchModeStart failed, ret is %d", ret);179 HIXL_CHK_BOOL_RET_STATUS(ret == 0, FAILED, "[HixlBatchPutAndGet] HcommBatchModeStart failed, ret is %d", ret);
@@ -194,6 +196,7 @@ uint32_t HixlBatchTransfer(bool is_read, HixlOneSideOpParam *param) {
194 HIXL_DISMISS_GUARD(batch_mode);196 HIXL_DISMISS_GUARD(batch_mode);
195 HIXL_CHK_BOOL_RET_STATUS(ret == 0, FAILED, "[HixlBatchPutAndGet] HcommBatchModeEnd failed, ret is %d", ret);197 HIXL_CHK_BOOL_RET_STATUS(ret == 0, FAILED, "[HixlBatchPutAndGet] HcommBatchModeEnd failed, ret is %d", ret);
196 198 
199+ HIXL_DISMISS_GUARD(err_flag_guard);
197 return SUCCESS;200 return SUCCESS;
198}201}
199} // namespace202} // namespace
@@ -0,0 +1,191 @@
1+/**
2+ * Copyright (c) 2026 Huawei Technologies Co., Ltd.
3+ * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
4+ * CANN Open Software License Agreement Version 2.0 (the "License").
5+ * Please refer to the License for details. You may not use this file except in compliance with the License.
6+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7+ * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8+ * See LICENSE in the root of the software repository for the full text of the License.
9+ */
10+#include "task_exception_handler.h"
11+ 
12+#include "common/hixl_log.h"
13+#include "hixl/hixl_types.h"
14+#include "hcomm_proxy.h"
15+#include "transfer_context_manager.h"
16+#include "driver/ascend_hal.h"
17+#include "aicpu/aicpu_schedule/aicpu_context.h"
18+#include "tsch/aicpu_msg.h"
19+#include "tsch/task_scheduler_error.h"
20+#include "common/scope_guard.h"
21+#include <sstream>
22+#include <string>
23+ 
24+namespace hixl {
25+namespace {
26+char g_hixl_ex_cb_user_data[] = "HIXL";
27+ 
28+// notify record type: 1=event record, 2=notify record.
29+constexpr uint8_t kAicpuMsgNotifyRecord = 2U;
30+ 
31+Status NotifyTsfwTaskException(uint32_t notify_id, uint32_t error_code) {
32+ if (halEschedSubmitEvent == nullptr) {
33+ HIXL_LOGE(FAILED, "[TaskExceptionHandler] halEschedSubmitEvent is null, API unavailable");
34+ return FAILED;
35+ }
36+ aicpu::aicpuContext_t ctx = {};
37+ if (aicpu::aicpuGetContext == nullptr) {
38+ HIXL_LOGE(FAILED, "[TaskExceptionHandler] aicpuGetContext is null, API unavailable");
39+ return FAILED;
40+ }
41+ aicpu::status_t ctx_ret = aicpu::aicpuGetContext(&ctx);
42+ if (ctx_ret != aicpu::AICPU_ERROR_NONE) {
43+ HIXL_LOGE(FAILED, "[TaskExceptionHandler] aicpuGetContext failed, ret=%d", ctx_ret);
44+ return FAILED;
45+ }
46+ // 透传 HComm 错误码会导致 runtime 打印错误码描述混乱,暂时统一上报 TS_ERROR_HCCL_OTHER_ERROR
47+ constexpr uint16_t report_err_code = static_cast<uint16_t>(TS_ERROR_HCCL_OTHER_ERROR);
48+ ts_aicpu_msg_info_t aicpu_msg = {};
49+ aicpu_msg.pid = static_cast<uint32_t>(ctx.hostPid);
50+ aicpu_msg.cmd_type = TS_AICPU_RECORD;
51+ aicpu_msg.vf_id = static_cast<uint8_t>(ctx.vfId);
52+ aicpu_msg.tid = 0U;
53+ aicpu_msg.ts_id = static_cast<uint8_t>(ctx.tsId);
54+ aicpu_msg.u.aicpu_record.record_type = kAicpuMsgNotifyRecord;
55+ aicpu_msg.u.aicpu_record.record_id = notify_id;
56+ aicpu_msg.u.aicpu_record.ret_code = report_err_code;
57+ event_summary event = {};
58+ event.dst_engine = TS_CPU;
59+ event.policy = ONLY;
60+ event.pid = 0;
61+ event.grp_id = 0;
62+ event.event_id = EVENT_TS_CTRL_MSG;
63+ event.subevent_id = 0U;
64+ event.msg_len = static_cast<uint32_t>(sizeof(ts_aicpu_msg_info_t));
65+ event.msg = reinterpret_cast<char *>(&aicpu_msg);
66+ 
67+ drvError_t ret = halEschedSubmitEvent(ctx.deviceId, &event);
68+ if (ret != DRV_ERROR_NONE) {
69+ HIXL_LOGE(FAILED, "[TaskExceptionHandler] halEschedSubmitEvent failed, ret=%d, notifyId=%u", ret, notify_id);
70+ return FAILED;
71+ }
72+ HIXL_LOGI("[TaskExceptionHandler] Submit to TSFW success. deviceId=%u, notifyId=%u, errCode=%u, reportErrCode=%u",
73+ ctx.deviceId, notify_id, error_code, report_err_code);
74+ return SUCCESS;
75+}
76+ 
77+const char *ExpandTypeToString(HcommExceptionExpandType type) {
78+ switch (type) {
79+ case HCOMM_EXCEPTION_STARS:
80+ return "STARS";
81+ case HCOMM_EXCEPTION_ROCE_HOST:
82+ return "ROCE_HOST";
83+ case HCOMM_EXCEPTION_ROCE_DEVICE:
84+ return "ROCE_DEVICE";
85+ case HCOMM_EXCEPTION_UB_HOST:
86+ return "UB_HOST";
87+ case HCOMM_EXCEPTION_UB_DEVICE:
88+ return "UB_DEVICE";
89+ default:
90+ return "INVALID";
91+ }
92+}
93+ 
94+std::string HcommExceptionInfoToString(const HcommExceptionInfo *info) {
95+ std::ostringstream oss;
96+ oss << "HcommExceptionInfo{taskId=" << info->taskId << ", thread=" << info->thread << ", channel=" << info->channel
97+ << ", retCode=" << info->retCode << ", expandType=" << ExpandTypeToString(info->expandInfo.type);
98+ if (info->expandInfo.type == HCOMM_EXCEPTION_STARS) {
99+ const auto &s = info->expandInfo.detail.starsInfo;
100+ oss << ", seqType=" << static_cast<uint32_t>(s.seqType)
101+ << ", statusMerged=" << static_cast<uint32_t>(s.statusMerged) << ", starsErrcode=" << s.starsErrcode;
102+ }
103+ oss << "}";
104+ return oss.str();
105+}
106+ 
107+void HixlTaskExceptionCallback(const HcommExceptionInfo *exception_info, void *user_data) {
108+ if (exception_info == nullptr) {
109+ HIXL_LOGE(FAILED, "[TaskExceptionHandler] Exception callback received null exception_info, user_data=%p",
110+ user_data);
111+ return;
112+ }
113+ uint64_t thread_handle = exception_info->thread;
114+ uint32_t error_code = exception_info->retCode;
115+ std::string info_str = HcommExceptionInfoToString(exception_info);
116+ 
117+ auto ctx = TransferContextManager::Instance().Get(thread_handle);
118+ if (ctx == nullptr) {
119+ HIXL_LOGI("[TaskExceptionHandler] Thread %lu not found, maybe not HIXL task or thread is deleted. user_data=%p. %s",
120+ thread_handle, user_data, info_str.c_str());
121+ return;
122+ }
123+ 
124+ HIXL_LOGE(FAILED, "[TaskExceptionHandler] Thread %lu task exception. user_data=%p. %s", thread_handle, user_data,
125+ info_str.c_str());
126+ 
127+ uint32_t notify_id = 0;
128+ {
129+ ctx->lock();
130+ ScopeGuard ctx_lock([&ctx] { ctx->unlock(); });
131+ if (ctx->GetState() != TRANSFER_THREAD_STATE_INITIALIZED) {
132+ HIXL_LOGE(FAILED, "[TaskExceptionHandler] Thread %lu state is not INITIALIZED, state=%u, skip processing",
133+ thread_handle, static_cast<uint32_t>(ctx->GetState()));
134+ return;
135+ }
136+ ctx->WriteErrorFlag();
137+ notify_id = ctx->notify_id;
138+ }
139+ 
140+ Status notify_ret = NotifyTsfwTaskException(notify_id, error_code);
141+ if (notify_ret != SUCCESS) {
142+ HIXL_LOGE(FAILED, "[TaskExceptionHandler] Thread %lu NotifyTsfwTaskException failed, ret=%u", thread_handle,
143+ notify_ret);
144+ }
145+}
146+ 
147+} // namespace
148+ 
149+TaskExceptionHandler &TaskExceptionHandler::Instance() {
150+ static TaskExceptionHandler handler;
151+ return handler;
152+}
153+ 
154+void TaskExceptionHandler::EnableExceptionCallback() {
155+ if (callback_registered_.load()) {
156+ return;
157+ }
158+ HIXL_LOGI("[TaskExceptionHandler] Registering callback with user_data=%p",
159+ static_cast<const void *>(g_hixl_ex_cb_user_data));
160+ const int32_t ret = HcommProxy::RegisterExceptionCallback(HixlTaskExceptionCallback, g_hixl_ex_cb_user_data);
161+ if (ret == 0) {
162+ callback_registered_.store(true);
163+ HIXL_LOGI("[TaskExceptionHandler] Register callback success");
164+ return;
165+ }
166+ if (ret == static_cast<int32_t>(HCCL_E_NOT_SUPPORT)) {
167+ HIXL_LOGI("[TaskExceptionHandler] HcommRegisterExceptionCallback unsupported, ret=%d", ret);
168+ } else {
169+ HIXL_LOGE(FAILED, "[TaskExceptionHandler] HcommRegisterExceptionCallback failed, ret=%d", ret);
170+ }
171+}
172+ 
173+void TaskExceptionHandler::DisableExceptionCallback() {
174+ if (!callback_registered_.load()) {
175+ return;
176+ }
177+ HIXL_LOGI("[TaskExceptionHandler] Unregistering callback");
178+ int32_t ret = HcommProxy::UnregisterExceptionCallback(HixlTaskExceptionCallback);
179+ if (ret == 0) {
180+ callback_registered_.store(false);
181+ HIXL_LOGI("[TaskExceptionHandler] Unregister callback success");
182+ return;
183+ }
184+ if (ret == static_cast<int32_t>(HCCL_E_NOT_SUPPORT)) {
185+ HIXL_LOGI("[TaskExceptionHandler] HcommUnregisterExceptionCallback unsupported, ret=%d", ret);
186+ } else {
187+ HIXL_LOGE(FAILED, "[TaskExceptionHandler] HcommUnregisterExceptionCallback failed, ret=%d", ret);
188+ }
189+}
190+ 
191+} // namespace hixl
@@ -0,0 +1,34 @@
1+/**
2+ * Copyright (c) 2026 Huawei Technologies Co., Ltd.
3+ * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
4+ * CANN Open Software License Agreement Version 2.0 (the "License").
5+ * Please refer to the License for details. You may not use this file except in compliance with the License.
6+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7+ * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8+ * See LICENSE in the root of the software repository for the full text of the License.
9+ */
10+#ifndef CANN_HIXL_SRC_OPS_HIXL_KERNEL_TASK_EXCEPTION_HANDLER_H_
11+#define CANN_HIXL_SRC_OPS_HIXL_KERNEL_TASK_EXCEPTION_HANDLER_H_
12+ 
13+#include <atomic>
14+ 
15+namespace hixl {
16+ 
17+class TaskExceptionHandler {
18+ public:
19+ static TaskExceptionHandler &Instance();
20+ 
21+ void EnableExceptionCallback();
22+ 
23+ void DisableExceptionCallback();
24+ 
25+ private:
26+ TaskExceptionHandler() = default;
27+ 
28+ // 调用方保证 Enable/Disable 不会并发,atomic 仅用于跨线程可见性
29+ std::atomic<bool> callback_registered_{false};
30+};
31+ 
32+} // namespace hixl
33+ 
34+#endif // CANN_HIXL_SRC_OPS_HIXL_KERNEL_TASK_EXCEPTION_HANDLER_H_
@@ -10,15 +10,24 @@
10#include "transfer_context_manager.h"10#include "transfer_context_manager.h"
11 11 
12#include "common/hixl_log.h"12#include "common/hixl_log.h"
13+#include "task_exception_handler.h"
13 14 
14namespace hixl {15namespace hixl {
15 16 
17+void TransferContext::WriteErrorFlag() const {
18+ if (err_flag_dev_va != 0U) {
19+ volatile uint8_t *err_flag_ptr = reinterpret_cast<volatile uint8_t *>(static_cast<uintptr_t>(err_flag_dev_va));
20+ *err_flag_ptr = 1U;
21+ HIXL_LOGI("[TransferContext] Written err_flag=1 to va=0x%lx", err_flag_dev_va);
22+ }
23+}
24+ 
16TransferContextManager &TransferContextManager::Instance() {25TransferContextManager &TransferContextManager::Instance() {
17 static TransferContextManager manager;26 static TransferContextManager manager;
18 return manager;27 return manager;
19}28}
20 29 
21-std::shared_ptr<TransferContext> TransferContextManager::Get(ThreadHandle thread) {30+std::shared_ptr<TransferContext> TransferContextManager::Get(ThreadHandle thread) const {
22 std::lock_guard<std::mutex> lock(mutex_);31 std::lock_guard<std::mutex> lock(mutex_);
23 auto it = contexts_.find(thread);32 auto it = contexts_.find(thread);
24 if (it == contexts_.end()) {33 if (it == contexts_.end()) {
@@ -28,7 +37,7 @@ std::shared_ptr<TransferContext> TransferContextManager::Get(ThreadHandle thread
28}37}
29 38 
30HixlTransferThreadState TransferContextManager::Add(ThreadHandle thread, uint32_t notify_id, uint64_t err_flag_dev_va) {39HixlTransferThreadState TransferContextManager::Add(ThreadHandle thread, uint32_t notify_id, uint64_t err_flag_dev_va) {
31- std::lock_guard<std::mutex> lock(mutex_);40+ std::unique_lock<std::mutex> lock(mutex_);
32 auto &ctx = contexts_[thread];41 auto &ctx = contexts_[thread];
33 if (ctx == nullptr) {42 if (ctx == nullptr) {
34 ctx = std::make_shared<TransferContext>();43 ctx = std::make_shared<TransferContext>();
@@ -39,11 +48,17 @@ HixlTransferThreadState TransferContextManager::Add(ThreadHandle thread, uint32_
39 48 
40 HIXL_LOGI("[TransferContextManager] add transfer context success. thread=%lu notify_id=%u err_flag_dev_va=0x%lx",49 HIXL_LOGI("[TransferContextManager] add transfer context success. thread=%lu notify_id=%u err_flag_dev_va=0x%lx",
41 static_cast<uint64_t>(thread), notify_id, static_cast<uint64_t>(err_flag_dev_va));50 static_cast<uint64_t>(thread), notify_id, static_cast<uint64_t>(err_flag_dev_va));
51+ lock.unlock();
52+ 
53+ // 防止hcomm接口内回调hixl触发Get导致死锁,所以这里放到锁外面
54+ TaskExceptionHandler::Instance().EnableExceptionCallback();
55+ 
42 return TRANSFER_THREAD_STATE_INITIALIZED;56 return TRANSFER_THREAD_STATE_INITIALIZED;
43}57}
44 58 
45HixlTransferThreadState TransferContextManager::Delete(ThreadHandle thread) {59HixlTransferThreadState TransferContextManager::Delete(ThreadHandle thread) {
46- std::lock_guard<std::mutex> lock(mutex_);60+ bool need_disable = false;
61+ std::unique_lock<std::mutex> lock(mutex_);
47 auto it = contexts_.find(thread);62 auto it = contexts_.find(thread);
48 if (it == contexts_.end() || it->second == nullptr) {63 if (it == contexts_.end() || it->second == nullptr) {
49 return TRANSFER_THREAD_STATE_DELETED;64 return TRANSFER_THREAD_STATE_DELETED;
@@ -59,6 +74,14 @@ HixlTransferThreadState TransferContextManager::Delete(ThreadHandle thread) {
59 ctx->unlock();74 ctx->unlock();
60 75 
61 HIXL_LOGI("[TransferContextManager] delete transfer context success. thread=%lu", static_cast<uint64_t>(thread));76 HIXL_LOGI("[TransferContextManager] delete transfer context success. thread=%lu", static_cast<uint64_t>(thread));
77+ need_disable = contexts_.empty();
78+ lock.unlock();
79+ 
80+ if (need_disable) {
81+ // 防止hcomm接口内回调hixl触发Get导致死锁,所以这里放到锁外面
82+ TaskExceptionHandler::Instance().DisableExceptionCallback();
83+ }
84+ 
62 return TRANSFER_THREAD_STATE_DELETED;85 return TRANSFER_THREAD_STATE_DELETED;
63}86}
64 87 
@@ -45,6 +45,8 @@ struct TransferContext {
45 spin_lock.clear(std::memory_order_release);45 spin_lock.clear(std::memory_order_release);
46 }46 }
47 47 
48+ void WriteErrorFlag() const;
49+ 
48 std::atomic_flag spin_lock = ATOMIC_FLAG_INIT;50 std::atomic_flag spin_lock = ATOMIC_FLAG_INIT;
49 std::atomic<HixlTransferThreadState> state{TRANSFER_THREAD_STATE_INITIALIZED};51 std::atomic<HixlTransferThreadState> state{TRANSFER_THREAD_STATE_INITIALIZED};
50 uint32_t notify_id{0};52 uint32_t notify_id{0};
@@ -55,14 +57,14 @@ class TransferContextManager {
55 public:57 public:
56 static TransferContextManager &Instance();58 static TransferContextManager &Instance();
57 59 
58- std::shared_ptr<TransferContext> Get(ThreadHandle thread);60+ std::shared_ptr<TransferContext> Get(ThreadHandle thread) const;
59 HixlTransferThreadState Add(ThreadHandle thread, uint32_t notify_id = 0U, uint64_t err_flag_dev_va = 0U);61 HixlTransferThreadState Add(ThreadHandle thread, uint32_t notify_id = 0U, uint64_t err_flag_dev_va = 0U);
60 HixlTransferThreadState Delete(ThreadHandle thread);62 HixlTransferThreadState Delete(ThreadHandle thread);
61 63 
62 private:64 private:
63 TransferContextManager() = default;65 TransferContextManager() = default;
64 66 
65- std::mutex mutex_;67+ mutable std::mutex mutex_;
66 std::unordered_map<ThreadHandle, std::shared_ptr<TransferContext>> contexts_;68 std::unordered_map<ThreadHandle, std::shared_ptr<TransferContext>> contexts_;
67};69};
68 70 
@@ -21,4 +21,5 @@ add_subdirectory(depends/runtime)
21add_subdirectory(depends/msprof)21add_subdirectory(depends/msprof)
22add_subdirectory(depends/dcmi)22add_subdirectory(depends/dcmi)
23add_subdirectory(depends/dsmi)23add_subdirectory(depends/dsmi)
24+add_subdirectory(depends/aicpu)
24add_subdirectory(cpp)25add_subdirectory(cpp)
@@ -98,9 +98,11 @@ target_include_directories(hixl_test PRIVATE
98 ${HIXL_CODE_DIR}/src/hixl/engine98 ${HIXL_CODE_DIR}/src/hixl/engine
99 ${HIXL_CODE_DIR}/src/hixl/profiling99 ${HIXL_CODE_DIR}/src/hixl/profiling
100 ${HIXL_CODE_DIR}/src/ops100 ${HIXL_CODE_DIR}/src/ops
101+ ${HIXL_CODE_DIR}/src/ops/hixl_kernel/extern_include
101 ${HIXL_CODE_DIR}/tests102 ${HIXL_CODE_DIR}/tests
102 ${HIXL_CODE_DIR}/tests/depends/ascendcl/src103 ${HIXL_CODE_DIR}/tests/depends/ascendcl/src
103 ${HIXL_CODE_DIR}/tests/depends/hccl/src104 ${HIXL_CODE_DIR}/tests/depends/hccl/src
105+ ${HIXL_CODE_DIR}/tests/depends/aicpu/src
104 ${HIXL_CODE_DIR}/tests/depends/slog/src106 ${HIXL_CODE_DIR}/tests/depends/slog/src
105 )107 )
106 108 
@@ -131,6 +133,7 @@ target_link_libraries(hixl_test
131 -Wl,--no-as-needed133 -Wl,--no-as-needed
132 hccl_stub134 hccl_stub
133 error_manager_stub135 error_manager_stub
136+ aicpu_stub
134 -Wl,--as-needed)137 -Wl,--as-needed)
135 138 
136# 让 dlopen("libdcmi.so") 和 dlopen("libdrvdsmi_host.so") 能找到测试桩139# 让 dlopen("libdcmi.so") 和 dlopen("libdrvdsmi_host.so") 能找到测试桩
@@ -10,6 +10,7 @@
10#include <array>10#include <array>
11#include <algorithm>11#include <algorithm>
12#include <cstdint>12#include <cstdint>
13+#include <cstring>
13#include <utility>14#include <utility>
14#include "gtest/gtest.h"15#include "gtest/gtest.h"
15#include "cs/hixl_cs.h"16#include "cs/hixl_cs.h"
@@ -17,12 +18,19 @@
17#include "hixl_kernel/hixl_batch_transfer.h"18#include "hixl_kernel/hixl_batch_transfer.h"
18#include "hixl_kernel/hixl_sync_transfer_context.h"19#include "hixl_kernel/hixl_sync_transfer_context.h"
19#include "hixl_kernel/transfer_context_manager.h"20#include "hixl_kernel/transfer_context_manager.h"
21+#include "hixl_kernel/task_exception_handler.h"
20#include "proxy/hcomm/hcomm_res_defs.h"22#include "proxy/hcomm/hcomm_res_defs.h"
23+#include "proxy/hcomm/hcomm_exception_notify.h"
21#include "hccl/hccl_types.h"24#include "hccl/hccl_types.h"
25+#include "hccl_stub.h"
26+#include "aicpu_stub.h"
27+#include "driver/ascend_hal.h"
22 28 
23// Mock 控制变量29// Mock 控制变量
24static int32_t g_mock_batch_transfer_ret = 0;30static int32_t g_mock_batch_transfer_ret = 0;
25static uint32_t g_mock_batch_transfer_call_count = 0;31static uint32_t g_mock_batch_transfer_call_count = 0;
32+static int32_t g_hal_esched_submit_ret = 0;
33+static uint32_t g_hal_esched_submit_call_count = 0;
26 34 
27// Mock 函数覆盖弱引用35// Mock 函数覆盖弱引用
28extern "C" int32_t HcommBatchTransferOnThread(ThreadHandle thread, ChannelHandle channel,36extern "C" int32_t HcommBatchTransferOnThread(ThreadHandle thread, ChannelHandle channel,
@@ -36,6 +44,14 @@ extern "C" int32_t HcommBatchTransferOnThread(ThreadHandle thread, ChannelHandle
36 return g_mock_batch_transfer_ret;44 return g_mock_batch_transfer_ret;
37}45}
38 46 
47+// 覆盖 halEschedSubmitEvent 弱符号
48+extern "C" drvError_t halEschedSubmitEvent(unsigned int devId, struct event_summary *event) {
49+ (void)devId;
50+ (void)event;
51+ g_hal_esched_submit_call_count++;
52+ return static_cast<drvError_t>(g_hal_esched_submit_ret);
53+}
54+ 
39namespace {55namespace {
40template <size_t kN>56template <size_t kN>
41struct TestArgs {57struct TestArgs {
@@ -74,6 +90,11 @@ static uint64_t g_remote_flag_buf = 1;
74static uint64_t g_local_flag_buf = 0;90static uint64_t g_local_flag_buf = 0;
75constexpr ThreadHandle kKernelTestThread = 910001ULL;91constexpr ThreadHandle kKernelTestThread = 910001ULL;
76 92 
93+static void ResetHalEschedStub() {
94+ g_hal_esched_submit_ret = 0;
95+ g_hal_esched_submit_call_count = 0;
96+}
97+ 
77uint32_t SyncContext(ThreadHandle thread, uint32_t op, uint32_t *state) {98uint32_t SyncContext(ThreadHandle thread, uint32_t op, uint32_t *state) {
78 HixlTransferContextSyncEntry entry{};99 HixlTransferContextSyncEntry entry{};
79 entry.thread = thread;100 entry.thread = thread;
@@ -580,3 +601,337 @@ TEST_F(HixlSyncTransferContextTest, ExtendedFieldsStoredAfterAdd) {
580 EXPECT_EQ(ctx->notify_id, kNotifyId);601 EXPECT_EQ(ctx->notify_id, kNotifyId);
581 EXPECT_EQ(ctx->err_flag_dev_va, kErrFlagDevVa);602 EXPECT_EQ(ctx->err_flag_dev_va, kErrFlagDevVa);
582}603}
604+ 
605+// ==================== TransferContext::WriteErrorFlag tests ====================
606+ 
607+class WriteErrorFlagTest : public ::testing::Test {
608+ protected:
609+ void SetUp() override {
610+ aicpu_test::ResetAicpuGetContextResult();
611+ ResetExceptionCallbackStub();
612+ TaskExceptionHandler::Instance().DisableExceptionCallback();
613+ ResetExceptionCallbackStub();
614+ uint32_t state = TRANSFER_THREAD_STATE_DELETED;
615+ (void)SyncContext(kKernelTestThread, TRANSFER_CONTEXT_OP_DELETE, &state);
616+ (void)SyncContext(kKernelTestThread, TRANSFER_CONTEXT_OP_ADD, &state);
617+ }
618+ 
619+ void TearDown() override {
620+ uint32_t state = TRANSFER_THREAD_STATE_DELETED;
621+ (void)SyncContext(kKernelTestThread, TRANSFER_CONTEXT_OP_DELETE, &state);
622+ TaskExceptionHandler::Instance().DisableExceptionCallback();
623+ aicpu_test::ResetAicpuGetContextResult();
624+ ResetExceptionCallbackStub();
625+ }
626+};
627+ 
628+TEST_F(WriteErrorFlagTest, WritesOneWhenErrFlagDevVaNonZero) {
629+ uint8_t err_flag = 0U;
630+ uint32_t state = TRANSFER_THREAD_STATE_DELETED;
631+ ASSERT_EQ(SyncContext(kKernelTestThread, TRANSFER_CONTEXT_OP_DELETE, &state), SUCCESS);
632+ 
633+ HixlTransferContextSyncEntry entry{};
634+ entry.thread = kKernelTestThread;
635+ entry.op = TRANSFER_CONTEXT_OP_ADD;
636+ entry.err_flag_dev_va = reinterpret_cast<uint64_t>(&err_flag);
637+ HixlTransferContextSyncParam param{};
638+ param.entry_list_addr = reinterpret_cast<uint64_t>(&entry);
639+ param.state_list_addr = reinterpret_cast<uint64_t>(&state);
640+ param.entry_num = 1U;
641+ ASSERT_EQ(HixlSyncTransferContext(&param), SUCCESS);
642+ 
643+ auto ctx = TransferContextManager::Instance().Get(kKernelTestThread);
644+ ASSERT_NE(ctx, nullptr);
645+ ctx->WriteErrorFlag();
646+ EXPECT_EQ(err_flag, 1U);
647+}
648+ 
649+TEST_F(WriteErrorFlagTest, NoopWhenErrFlagDevVaZero) {
650+ auto ctx = TransferContextManager::Instance().Get(kKernelTestThread);
651+ ASSERT_NE(ctx, nullptr);
652+ EXPECT_EQ(ctx->err_flag_dev_va, 0U);
653+ ctx->WriteErrorFlag();
654+ SUCCEED();
655+}
656+ 
657+// ==================== TaskExceptionHandler tests ====================
658+ 
659+class TaskExceptionHandlerTest : public ::testing::Test {
660+ protected:
661+ void SetUp() override {
662+ aicpu_test::ResetAicpuGetContextResult();
663+ ResetExceptionCallbackStub();
664+ TaskExceptionHandler::Instance().DisableExceptionCallback();
665+ ResetExceptionCallbackStub();
666+ }
667+ 
668+ void TearDown() override {
669+ uint32_t state = TRANSFER_THREAD_STATE_DELETED;
670+ (void)SyncContext(kKernelTestThread, TRANSFER_CONTEXT_OP_DELETE, &state);
671+ aicpu_test::ResetAicpuGetContextResult();
672+ ResetExceptionCallbackStub();
673+ }
674+};
675+ 
676+TEST_F(TaskExceptionHandlerTest, EnableRegistersCallback) {
677+ TaskExceptionHandler::Instance().EnableExceptionCallback();
678+ EXPECT_NE(GetRegisteredExceptionCallback(), nullptr);
679+}
680+ 
681+TEST_F(TaskExceptionHandlerTest, EnableTwiceRegistersOnce) {
682+ TaskExceptionHandler::Instance().EnableExceptionCallback();
683+ ExceptionCallback first_cb = GetRegisteredExceptionCallback();
684+ TaskExceptionHandler::Instance().EnableExceptionCallback();
685+ EXPECT_EQ(GetRegisteredExceptionCallback(), first_cb);
686+}
687+ 
688+TEST_F(TaskExceptionHandlerTest, DisableUnregistersCallback) {
689+ TaskExceptionHandler::Instance().EnableExceptionCallback();
690+ EXPECT_NE(GetRegisteredExceptionCallback(), nullptr);
691+ TaskExceptionHandler::Instance().DisableExceptionCallback();
692+ EXPECT_EQ(GetRegisteredExceptionCallback(), nullptr);
693+}
694+ 
695+TEST_F(TaskExceptionHandlerTest, DisableTwiceUnregistersOnce) {
696+ TaskExceptionHandler::Instance().EnableExceptionCallback();
697+ TaskExceptionHandler::Instance().DisableExceptionCallback();
698+ EXPECT_EQ(GetRegisteredExceptionCallback(), nullptr);
699+ TaskExceptionHandler::Instance().DisableExceptionCallback();
700+ EXPECT_EQ(GetRegisteredExceptionCallback(), nullptr);
701+}
702+ 
703+TEST_F(TaskExceptionHandlerTest, EnableAfterFailureCanRegisterAgain) {
704+ SetRegisterExceptionResult(HCCL_E_INTERNAL);
705+ TaskExceptionHandler::Instance().EnableExceptionCallback();
706+ EXPECT_EQ(GetRegisteredExceptionCallback(), nullptr);
707+ 
708+ SetRegisterExceptionResult(0);
709+ TaskExceptionHandler::Instance().EnableExceptionCallback();
710+ EXPECT_NE(GetRegisteredExceptionCallback(), nullptr);
711+}
712+ 
713+// ==================== HixlBatchTransfer err_flag tests ====================
714+ 
715+class BatchTransferErrFlagTest : public ::testing::Test {
716+ protected:
717+ uint8_t err_flag_ = 0U;
718+ 
719+ void SetUp() override {
720+ g_mock_batch_transfer_ret = 0;
721+ g_mock_batch_transfer_call_count = 0;
722+ err_flag_ = 0U;
723+ aicpu_test::ResetAicpuGetContextResult();
724+ 
725+ HixlTransferContextSyncEntry entry{};
726+ entry.thread = kKernelTestThread;
727+ entry.op = TRANSFER_CONTEXT_OP_ADD;
728+ entry.err_flag_dev_va = reinterpret_cast<uint64_t>(&err_flag_);
729+ uint32_t state = 0U;
730+ HixlTransferContextSyncParam param{};
731+ param.entry_list_addr = reinterpret_cast<uint64_t>(&entry);
732+ param.state_list_addr = reinterpret_cast<uint64_t>(&state);
733+ param.entry_num = 1U;
734+ ASSERT_EQ(HixlSyncTransferContext(&param), SUCCESS);
735+ }
736+ 
737+ void TearDown() override {
738+ uint32_t state = TRANSFER_THREAD_STATE_DELETED;
739+ (void)SyncContext(kKernelTestThread, TRANSFER_CONTEXT_OP_DELETE, &state);
740+ TaskExceptionHandler::Instance().DisableExceptionCallback();
741+ g_mock_batch_transfer_ret = HCCL_E_NOT_SUPPORT;
742+ g_mock_batch_transfer_call_count = 0;
743+ }
744+};
745+ 
746+TEST_F(BatchTransferErrFlagTest, ErrFlagStaysZeroOnSuccess) {
747+ std::array<std::array<uint8_t, 8>, 1> local_addr{};
748+ std::array<std::array<uint8_t, 8>, 1> remote_addr{};
749+ std::array<uint64_t, 1> lens{8};
750+ 
751+ auto args = CreateTestArgs<1>(local_addr, remote_addr, lens, reinterpret_cast<uint64_t>(&g_remote_flag_buf),
752+ reinterpret_cast<uint64_t>(&g_local_flag_buf), kKernelTestThread);
753+ g_mock_batch_transfer_ret = HCCL_SUCCESS;
754+ 
755+ EXPECT_EQ(HixlBatchPut(&args.param), SUCCESS);
756+ EXPECT_EQ(err_flag_, 0U);
757+}
758+ 
759+TEST_F(BatchTransferErrFlagTest, ErrFlagWrittenOnTransferFailure) {
760+ std::array<std::array<uint8_t, 8>, 1> local_addr{};
761+ std::array<std::array<uint8_t, 8>, 1> remote_addr{};
762+ std::array<uint64_t, 1> lens{8};
763+ 
764+ auto args = CreateTestArgs<1>(local_addr, remote_addr, lens, reinterpret_cast<uint64_t>(&g_remote_flag_buf),
765+ reinterpret_cast<uint64_t>(&g_local_flag_buf), kKernelTestThread);
766+ g_mock_batch_transfer_ret = HCCL_E_PARA;
767+ 
768+ EXPECT_EQ(HixlBatchPut(&args.param), FAILED);
769+ EXPECT_EQ(err_flag_, 1U);
770+}
771+ 
772+TEST_F(BatchTransferErrFlagTest, ErrFlagWrittenOnFenceFailure) {
773+ std::array<std::array<uint8_t, 8>, 1> local_addr{};
774+ std::array<std::array<uint8_t, 8>, 1> remote_addr{};
775+ std::array<uint64_t, 1> lens{8};
776+ 
777+ auto args = CreateTestArgs<1>(local_addr, remote_addr, lens, reinterpret_cast<uint64_t>(&g_remote_flag_buf),
778+ reinterpret_cast<uint64_t>(&g_local_flag_buf), kKernelTestThread);
779+ g_mock_batch_transfer_ret = HCCL_SUCCESS;
780+ SetNextFenceFailure(HCCL_E_INTERNAL);
781+ 
782+ EXPECT_EQ(HixlBatchPut(&args.param), FAILED);
783+ EXPECT_EQ(err_flag_, 1U);
784+}
785+ 
786+// ==================== HixlTaskExceptionCallback tests ====================
787+ 
788+class ExceptionCallbackTest : public ::testing::Test {
789+ protected:
790+ uint8_t err_flag_ = 0U;
791+ 
792+ void SetUp() override {
793+ aicpu_test::ResetAicpuGetContextResult();
794+ aicpu_test::SetAicpuGetContextResult(7, 0, 12345, 0, 0);
795+ ResetExceptionCallbackStub();
796+ ResetHalEschedStub();
797+ TaskExceptionHandler::Instance().DisableExceptionCallback();
798+ ResetExceptionCallbackStub();
799+ err_flag_ = 0U;
800+ }
801+ 
802+ void TearDown() override {
803+ uint32_t state = TRANSFER_THREAD_STATE_DELETED;
804+ (void)SyncContext(kExceptionThread, TRANSFER_CONTEXT_OP_DELETE, &state);
805+ TaskExceptionHandler::Instance().DisableExceptionCallback();
806+ aicpu_test::ResetAicpuGetContextResult();
807+ ResetExceptionCallbackStub();
808+ ResetHalEschedStub();
809+ }
810+ 
811+ static constexpr ThreadHandle kExceptionThread = 910400ULL;
812+ 
813+ void AddContextWithErrFlag() {
814+ HixlTransferContextSyncEntry entry{};
815+ entry.thread = kExceptionThread;
816+ entry.op = TRANSFER_CONTEXT_OP_ADD;
817+ entry.err_flag_dev_va = reinterpret_cast<uint64_t>(&err_flag_);
818+ entry.notify_id = 3U;
819+ uint32_t state = 0U;
820+ HixlTransferContextSyncParam param{};
821+ param.entry_list_addr = reinterpret_cast<uint64_t>(&entry);
822+ param.state_list_addr = reinterpret_cast<uint64_t>(&state);
823+ param.entry_num = 1U;
824+ ASSERT_EQ(HixlSyncTransferContext(&param), SUCCESS);
825+ }
826+ 
827+ void TriggerCallback(uint64_t thread, uint32_t ret_code) {
828+ ExceptionCallback cb = GetRegisteredExceptionCallback();
829+ ASSERT_NE(cb, nullptr);
830+ HcommExceptionInfo info{};
831+ info.thread = thread;
832+ info.retCode = ret_code;
833+ cb(&info, GetRegisteredExceptionUserData());
834+ }
835+ 
836+ void TriggerCallbackStars(uint64_t thread, uint32_t ret_code, uint32_t stars_errcode, uint8_t seq_type,
837+ uint8_t status_merged) {
838+ ExceptionCallback cb = GetRegisteredExceptionCallback();
839+ ASSERT_NE(cb, nullptr);
840+ HcommExceptionInfo info{};
841+ info.thread = thread;
842+ info.retCode = ret_code;
843+ info.expandInfo.type = HCOMM_EXCEPTION_STARS;
844+ info.expandInfo.detail.starsInfo.starsErrcode = stars_errcode;
845+ info.expandInfo.detail.starsInfo.seqType = seq_type;
846+ info.expandInfo.detail.starsInfo.statusMerged = status_merged;
847+ cb(&info, GetRegisteredExceptionUserData());
848+ }
849+};
850+ 
851+TEST_F(ExceptionCallbackTest, CallbackWritesErrFlagForHixlThread) {
852+ AddContextWithErrFlag();
853+ TaskExceptionHandler::Instance().EnableExceptionCallback();
854+ TriggerCallback(kExceptionThread, HCCL_E_ROCE_TRANSFER);
855+ EXPECT_EQ(err_flag_, 1U);
856+}
857+ 
858+TEST_F(ExceptionCallbackTest, CallbackSkipsNonHixlThread) {
859+ AddContextWithErrFlag();
860+ TaskExceptionHandler::Instance().EnableExceptionCallback();
861+ TriggerCallback(999999ULL, HCCL_E_ROCE_TRANSFER);
862+ EXPECT_EQ(err_flag_, 0U);
863+}
864+ 
865+TEST_F(ExceptionCallbackTest, CallbackHandlesNullExceptionInfo) {
866+ AddContextWithErrFlag();
867+ TaskExceptionHandler::Instance().EnableExceptionCallback();
868+ ExceptionCallback cb = GetRegisteredExceptionCallback();
869+ ASSERT_NE(cb, nullptr);
870+ cb(nullptr, GetRegisteredExceptionUserData());
871+ EXPECT_EQ(err_flag_, 0U);
872+}
873+ 
874+TEST_F(ExceptionCallbackTest, CallbackSkipsDeletingThread) {
875+ AddContextWithErrFlag();
876+ TaskExceptionHandler::Instance().EnableExceptionCallback();
877+ 
878+ auto ctx = TransferContextManager::Instance().Get(kExceptionThread);
879+ ASSERT_NE(ctx, nullptr);
880+ ctx->lock();
881+ ctx->SetState(TRANSFER_THREAD_STATE_DELETING);
882+ ctx->unlock();
883+ 
884+ TriggerCallback(kExceptionThread, HCCL_E_ROCE_TRANSFER);
885+ EXPECT_EQ(err_flag_, 0U);
886+}
887+ 
888+TEST_F(ExceptionCallbackTest, CallbackNotifiesTsfwOnSuccess) {
889+ AddContextWithErrFlag();
890+ TaskExceptionHandler::Instance().EnableExceptionCallback();
891+ ResetHalEschedStub();
892+ 
893+ TriggerCallback(kExceptionThread, HCCL_E_ROCE_TRANSFER);
894+ EXPECT_EQ(err_flag_, 1U);
895+ EXPECT_EQ(g_hal_esched_submit_call_count, 1U);
896+}
897+ 
898+TEST_F(ExceptionCallbackTest, CallbackTsfwFailureStillWritesErrFlag) {
899+ AddContextWithErrFlag();
900+ TaskExceptionHandler::Instance().EnableExceptionCallback();
901+ g_hal_esched_submit_ret = 1;
902+ 
903+ TriggerCallback(kExceptionThread, HCCL_E_ROCE_TRANSFER);
904+ EXPECT_EQ(err_flag_, 1U);
905+ EXPECT_EQ(g_hal_esched_submit_call_count, 1U);
906+}
907+ 
908+TEST_F(ExceptionCallbackTest, CallbackTsfwFailureWithAicpuGetContextFailure) {
909+ AddContextWithErrFlag();
910+ TaskExceptionHandler::Instance().EnableExceptionCallback();
911+ aicpu_test::SetAicpuGetContextResult(0, 0, 0, 0, 1);
912+ ResetHalEschedStub();
913+ 
914+ TriggerCallback(kExceptionThread, HCCL_E_ROCE_TRANSFER);
915+ EXPECT_EQ(err_flag_, 1U);
916+ EXPECT_EQ(g_hal_esched_submit_call_count, 0U);
917+}
918+ 
919+TEST_F(ExceptionCallbackTest, CallbackWithStarsExceptionWritesErrFlagAndNotifiesTsfw) {
920+ AddContextWithErrFlag();
921+ TaskExceptionHandler::Instance().EnableExceptionCallback();
922+ ResetHalEschedStub();
923+ 
924+ TriggerCallbackStars(kExceptionThread, HCCL_E_ROCE_TRANSFER, 0x1234, 1, 2);
925+ EXPECT_EQ(err_flag_, 1U);
926+ EXPECT_EQ(g_hal_esched_submit_call_count, 1U);
927+}
928+ 
929+TEST_F(ExceptionCallbackTest, CallbackWithStarsExceptionNonHixlThreadSkips) {
930+ AddContextWithErrFlag();
931+ TaskExceptionHandler::Instance().EnableExceptionCallback();
932+ ResetHalEschedStub();
933+ 
934+ TriggerCallbackStars(999999ULL, HCCL_E_ROCE_TRANSFER, 0x5678, 3, 4);
935+ EXPECT_EQ(err_flag_, 0U);
936+ EXPECT_EQ(g_hal_esched_submit_call_count, 0U);
937+}
@@ -0,0 +1,22 @@
1+# ----------------------------------------------------------------------------
2+# Copyright (c) 2026 Huawei Technologies Co., Ltd.
3+# This program is free software, you can redistribute it and/or modify it under the terms and conditions of
4+# CANN Open Software License Agreement Version 2.0 (the "License").
5+# Please refer to the License for details. You may not use this file except in compliance with the License.
6+# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7+# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8+# See LICENSE in the root of the software repository for the full text of the License.
9+# ----------------------------------------------------------------------------
10+ 
11+add_library(aicpu_stub SHARED src/aicpu_stub.cc)
12+target_compile_options(aicpu_stub PRIVATE -g)
13+target_include_directories(aicpu_stub PRIVATE
14+ ${CMAKE_CURRENT_LIST_DIR}/src
15+ ${HIXL_CODE_DIR}/src/ops/hixl_kernel/extern_include
16+)
17+target_link_libraries(aicpu_stub
18+ PRIVATE
19+ runtime_headers
20+)
21+ 
22+stub_module(aicpu aicpu_stub)
@@ -0,0 +1,54 @@
1+/**
2+ * Copyright (c) 2026 Huawei Technologies Co., Ltd.
3+ * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
4+ * CANN Open Software License Agreement Version 2.0 (the "License").
5+ * Please refer to the License for details. You may not use this file except in compliance with the License.
6+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7+ * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8+ * See LICENSE in the root of the software repository for the full text of the License.
9+ */
10+#include "aicpu_stub.h"
11+#include "aicpu/aicpu_schedule/aicpu_context.h"
12+ 
13+namespace {
14+struct AicpuContextMock {
15+ uint32_t device_id = 0U;
16+ uint32_t ts_id = 0U;
17+ int32_t host_pid = 1000;
18+ uint32_t vf_id = 0U;
19+ int32_t ret = 0;
20+};
21+ 
22+AicpuContextMock g_aicpu_context_mock;
23+ 
24+void ResetMock() {
25+ g_aicpu_context_mock = AicpuContextMock{};
26+}
27+} // namespace
28+ 
29+namespace aicpu_test {
30+void SetAicpuGetContextResult(uint32_t device_id, uint32_t ts_id, int32_t host_pid, uint32_t vf_id, int32_t ret) {
31+ g_aicpu_context_mock.device_id = device_id;
32+ g_aicpu_context_mock.ts_id = ts_id;
33+ g_aicpu_context_mock.host_pid = host_pid;
34+ g_aicpu_context_mock.vf_id = vf_id;
35+ g_aicpu_context_mock.ret = ret;
36+}
37+ 
38+void ResetAicpuGetContextResult() {
39+ ResetMock();
40+}
41+} // namespace aicpu_test
42+ 
43+namespace aicpu {
44+status_t aicpuGetContext(aicpuContext_t *ctx) {
45+ if (ctx == nullptr) {
46+ return AICPU_ERROR_FAILED;
47+ }
48+ ctx->deviceId = g_aicpu_context_mock.device_id;
49+ ctx->tsId = g_aicpu_context_mock.ts_id;
50+ ctx->hostPid = g_aicpu_context_mock.host_pid;
51+ ctx->vfId = g_aicpu_context_mock.vf_id;
52+ return static_cast<status_t>(g_aicpu_context_mock.ret);
53+}
54+} // namespace aicpu
@@ -0,0 +1,20 @@
1+/**
2+ * Copyright (c) 2026 Huawei Technologies Co., Ltd.
3+ * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
4+ * CANN Open Software License Agreement Version 2.0 (the "License").
5+ * Please refer to the License for details. You may not use this file except in compliance with the License.
6+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7+ * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8+ * See LICENSE in the root of the software repository for the full text of the License.
9+ */
10+#ifndef TEST_AICPU_STUB_H_
11+#define TEST_AICPU_STUB_H_
12+ 
13+#include <cstdint>
14+ 
15+namespace aicpu_test {
16+void SetAicpuGetContextResult(uint32_t device_id, uint32_t ts_id, int32_t host_pid, uint32_t vf_id, int32_t ret);
17+void ResetAicpuGetContextResult();
18+} // namespace aicpu_test
19+ 
20+#endif // TEST_AICPU_STUB_H_
@@ -13,6 +13,7 @@ add_library(hccl_stub SHARED ${SRC_FILES})
13target_include_directories(hccl_stub PRIVATE13target_include_directories(hccl_stub PRIVATE
14 ${HIXL_CODE_DIR}/src/hixl14 ${HIXL_CODE_DIR}/src/hixl
15 ${HIXL_CODE_DIR}/src/hixl/proxy15 ${HIXL_CODE_DIR}/src/hixl/proxy
16+ ${CMAKE_CURRENT_SOURCE_DIR}/src
16 )17 )
17target_link_libraries(hccl_stub PRIVATE intf_pub c_sec slog_headers18target_link_libraries(hccl_stub PRIVATE intf_pub c_sec slog_headers
18 PUBLIC hccl_headers19 PUBLIC hccl_headers
@@ -15,6 +15,7 @@
15#include <vector>15#include <vector>
16#include "hccl/hccl_types.h"16#include "hccl/hccl_types.h"
17#include "hcomm/hcomm_res_defs.h"17#include "hcomm/hcomm_res_defs.h"
18+#include "hcomm/hcomm_exception_notify.h"
18 19 
19#ifdef __cplusplus20#ifdef __cplusplus
20extern "C" {21extern "C" {
@@ -332,6 +333,45 @@ void ResetThreadLifecycleStats() {
332 g_thread_lifecycle_events.clear();333 g_thread_lifecycle_events.clear();
333}334}
334 335 
336+// ---- Exception callback stub ----
337+static ExceptionCallback g_registered_exception_callback = nullptr;
338+static void *g_registered_exception_user_data = nullptr;
339+static int32_t g_register_exception_ret = 0;
340+ 
341+int32_t HcommRegisterExceptionCallback(ExceptionCallback cb, void *user_data) {
342+ if (cb != nullptr && g_register_exception_ret == 0) {
343+ g_registered_exception_callback = cb;
344+ g_registered_exception_user_data = user_data;
345+ }
346+ return g_register_exception_ret;
347+}
348+ 
349+int32_t HcommUnregisterExceptionCallback(ExceptionCallback cb) {
350+ if (g_registered_exception_callback == cb) {
351+ g_registered_exception_callback = nullptr;
352+ g_registered_exception_user_data = nullptr;
353+ }
354+ return 0;
355+}
356+ 
357+void SetRegisterExceptionResult(int32_t ret) {
358+ g_register_exception_ret = ret;
359+}
360+ 
361+ExceptionCallback GetRegisteredExceptionCallback() {
362+ return g_registered_exception_callback;
363+}
364+ 
365+void *GetRegisteredExceptionUserData() {
366+ return g_registered_exception_user_data;
367+}
368+ 
369+void ResetExceptionCallbackStub() {
370+ g_registered_exception_callback = nullptr;
371+ g_registered_exception_user_data = nullptr;
372+ g_register_exception_ret = 0;
373+}
374+ 
335#ifdef __cplusplus375#ifdef __cplusplus
336}376}
337#endif377#endif
@@ -12,6 +12,7 @@
12#define AIR_TESTS_DEPENDS_HCCL_SRC_HCCL_STUB_H_12#define AIR_TESTS_DEPENDS_HCCL_SRC_HCCL_STUB_H_
13 13 
14#include <cstdint>14#include <cstdint>
15+#include "hcomm/hcomm_exception_notify.h"
15 16 
16#ifdef __cplusplus17#ifdef __cplusplus
17extern "C" {18extern "C" {
@@ -29,6 +30,11 @@ void ResetMemRegRecord();
29uint32_t GetMemRegRecordCount();30uint32_t GetMemRegRecordCount();
30int32_t GetMemRegRecordType(uint32_t index);31int32_t GetMemRegRecordType(uint32_t index);
31 32 
33+void SetRegisterExceptionResult(int32_t ret);
34+ExceptionCallback GetRegisteredExceptionCallback();
35+void *GetRegisteredExceptionUserData();
36+void ResetExceptionCallbackStub();
37+ 
32#ifdef __cplusplus38#ifdef __cplusplus
33}39}
34#endif40#endif