Merged
[feat]: 支持device传输异常上报 #681
lining23666Add on Jun 26
[feat]: 支持device传输异常上报 #681
Merged
lining23666Add on Jun 26
lining23666
lining23666Collaborators
Jun 26

提交 PR 前,请先阅读 HIXL贡献指南 ,查看 PR 提交方式并遵守相关提交规范。

类型标签

描述

当前 HIXL CS 路径(TransferPool + HixlCSClient)在传输过程中若 Device 侧 Hcomm 通信线程发生底层传输异常(如 RDMA 重传超次、网卡故障、链路闪断等),AICPU Kernel 无法正常完成,用户侧无法及时感知异常:

  • 异步传输场景:complete_flag 永远不会被置位,用户侧只能等待超时。
  • 同步传输场景:notify 不会被触发,同步接口只能等待超时后返回。

本 PR 在 Device 侧建立一条从 Hcomm 到 TSFW 的异常上报通路。Device 侧捕获 Hcomm 传输异常后,通知 TSFW 终止 notify wait,使同步和异步场景均能在异常时立即返回,无需等待超时。同时,HixlBatchTransfer 失败时自动写 err_flag,Host 侧可通过读取 err_flag 感知传输失败。

主要改动

1. TaskExceptionHandler 单例(src/ops/hixl_kernel/task_exception_handler.h/.cc,新增)

封装 Hcomm 异常回调注册/注销和 TSFW 通知逻辑:

  • EnableExceptionCallback():调用 HcommRegisterExceptionCallback 注册回调,内部 atomic<bool> CAS 保证只注册一次
  • DisableExceptionCallback():调用 HcommUnregisterExceptionCallback 按函数指针注销
  • 回调函数 HixlTaskExceptionCallback:查映射表 → 写 err_flag → 通过 halEschedSubmitEvent 通知 TSFW
  • 非 HIXL 任务的异常静默丢弃(Hcomm 回调通知所有注册的回调)
  • 使用 ts_aicpu_msg_info_t(david 形态)构造 TSFW 消息,错误码统一上报 TS_ERROR_HCCL_OTHER_ERROR

2. TransferContextManager 扩展(src/ops/hixl_kernel/transfer_context_manager.h/.cc)

  • TransferContext 新增 notify_id/err_flag_dev_va 字段和 WriteErrorFlag() 方法(固定写 1)
  • Add 时自动调用 TaskExceptionHandler::EnableExceptionCallback()(锁外调用,避免死锁)
  • Delete 后映射表为空时调用 TaskExceptionHandler::DisableExceptionCallback()(锁外调用)

3. HixlBatchTransfer 失败写 err_flag(src/ops/hixl_kernel/hixl_batch_transfer.cc)

传输失败时通过 HIXL_DISMISSABLE_GUARD 自动写 err_flag,成功时 dismiss

4. Hcomm 异常接口适配(src/hixl/proxy/)

  • 新增 hcomm/hcomm_exception_notify.h:Hcomm 异常信息结构体定义(HcommExceptionInfo、ExceptionCallback 等)
  • hcomm_proxy.h/.cc:新增 RegisterExceptionCallback/UnregisterExceptionCallback 代理方法

5. extern 头文件(src/ops/hixl_kernel/extern_include/tsch/,新增)

  • aicpu_msg.h:TS AICPU 消息结构体(ts_aicpu_msg_info_t、ts_aicpu_record_msg_t 等)
  • task_scheduler_error.h:TS 错误码定义(TS_ERROR_HCCL_OTHER_ERROR 等)

6. 测试(tests/)

  • 新增 tests/depends/aicpu/:打桩 aicpuGetContext
  • 扩展 hccl_stub:打桩 HcommRegisterExceptionCallback/HcommUnregisterExceptionCallback
  • 新增 20+ 测试用例覆盖 WriteErrorFlag、TaskExceptionHandler、HixlBatchTransfer 失败写 err_flag、异常回调(含 STARS 异常类型、TSFW 通知成功/失败)

测试项

测试项 说明
UT: WriteErrorFlag err_flag_dev_va 非空时写 1,为 0 时不崩溃
UT: TaskExceptionHandler 注册/注销/重复调用/失败回滚
UT: BatchTransfer err_flag 传输成功 err_flag 保持 0,失败写 1,Fence 失败写 1
UT: 异常回调 HIXL 线程写 err_flag + 通知 TSFW,非 HIXL 线程丢弃,null 不崩溃,DELETING 状态跳过
UT: STARS 异常 覆盖 HcommExceptionInfoToString STARS 分支
UT: TSFW 通知 halEschedSubmitEvent 成功/失败/aicpuGetContext 失败

测试结果

  • bash tests/run_test.sh -t cpp -s hixl:747 tests PASSED
  • bash build.sh:Build success(device kernel 编译通过)
  • 使用benchmark执行模拟传输失败的场景报错如下
    同步
[ERROR] TransferSync failed, ret = 507001, errmsg: EE9999: Internal error!
EE9999[PID: 518352] 2026-07-28-02:24:05.290.325 (EE9999):  The error from device(chipId:0, dieId:0), serial number is 4, wait timeout occurred during task execution, stream_id:155, sq_id:203, task_pos:1, id=224, timeout=1800s, cntFlag = 0, subType = 1(single notify wait), cntValue = 0, clrFlag = 1, waitMode = 0, bitmap = 0.[FUNC:ProcessDavidStarsWaitTimeoutErrorInfo][FILE:device_error_proc_c.cc][LINE:924]
TraceBack (most recent call last):
       rtStreamSynchronizeWithTimeout execution failed, reason=hccl other error[FUNC:FuncErrorReason][FILE:error_message_manage.cc][LINE:69]
       Call sync_ret fail. [HixlClient] aclrtSynchronizeStreamWithTimeout failed, kernel=HixlBatchGet, list_num=32, slot=96, thread=4397658434368[FUNC:BatchTransferDeviceSync][FILE:hixl_cs_client.cc][LINE:943]
       Call LatchTransferFailureIfNeeded(ret) fail. [HixlClient] BatchTransferSync failed, is_get=1, list_num=32, local=[protocol=uboe, addr=IPv4:20.0.224.153, devPhyId=4], remote=[protocol=uboe, addr=IPv4:20.0.226.152, devPhyId=3][FUNC:BatchTransferSync][FILE:hixl_cs_client.cc][LINE:1008]
       Call ret fail. HixlCSClientBatchGetSync failed, client_handle is 0x4caceda0, list_num:32[FUNC:HixlCSClientBatchGetSync][FILE:hixl_cs.cc][LINE:199]
       Call engine_->TransferSync(remote_engine, operation, op_descs, timeout_in_millis) fail. Failed to transfer sync.[FUNC:TransferSync][FILE:hixl_impl.cc][LINE:185]
       Failed to TransferSync, remote_engine:127.0.0.1:16001, operation:read, op_descs size:32, timeout:60000 ms[FUNC:TransferSync][FILE:hixl_impl.cc][LINE:365]

异步

[ERROR] Transfer failed at req 0, status=3
[ERROR] Async transfer failed at step 0

Checklist

其它

本 PR 仅实现 Device 侧(Part 2),Host 侧 err_flag 资源管理、HixlSyncTransferContext Kernel 下发、CheckStatusDevice 扩展等待后续 PR 实现。

likedislike
Pull Request has been successfully merged by CANN-robot.
(Thank you for lining23666's contribution.)
lining23666lining23666Collaborators
Jun 26 Created pull request, commit a95d5182
CANN-robotCANN-robotCollaborators
Jun 26 Added label: cann-cla/yes
CANN-robot
CANN-robotCollaborators
Jun 26 Comments:

Thanks for your pull-request.
The full list of commands accepted by me can be found at here。
You can get sig-info at here


PR Approval Progress

✅ Congratulations! All modules have met the lgtm and approve requirements.

Module Approval Details

module lgtm status approve status
repo-cann/hixl ✅ zhujingjing, youyx, zhaozhihui (3/2) ✅ zhujingjing (1/1)

💡 Tip:

  • Committer can comment /approve or /lgtm
  • Commenting /approve implies both code review (lgtm) and intent to merge (approve)

CLA Signature Pass

lining23666, thanks for your pull request. All authors of the commits have signed the CLA. 👍

likedislike
lining23666lining23666Collaborators
Jun 26 Pre merge succeeded (commit_id: 2ac0442d2b95da6a298f8f07ed69bbc6a1ef524f)
lining23666lining23666Collaborators
Jun 26 Force-pushed 1 commits:a6c175a2-[feat]: add HixlSyncTransferCtx device kernel for exception reporting
289 messages are collapsed here。 See more
youxiao
youxiaoCollaborators
Jul 29 Comments:

/lgtm

likedislike
CANN-robotCANN-robotCollaborators
Jul 29 Added label: lgtm
zhujingjing
zhujingjingCollaborators
Jul 29 Comments:

/approve

likedislike
CANN-robotCANN-robotCollaborators
Jul 29 Added label: approved
CANN-robotCANN-robotCollaborators
Jul 29 Merged pull request