Closed
[Bug-Report|缺陷反馈]: 仿真 AOT 控制流回调中 DEV_ASSERT 异常无法穿越 AOT 帧,进程 terminate 而非 Python 异常 #3580
anyangleAdd on Oct 14Closed at 24 days ago
Oct 14 Added label: bug-report
Oct 14 Modify description of issue
Oct 15 changed custom category from 任务 to 缺陷
Oct 15 Assign quadrate as responsible person
Oct 15 Associated pull request
anyangle
Oct 26 Comments:
Oct 26 Comments:
commit 2f800ae814bcd43343c916565722014d14ff3d37 (HEAD -> error_log)
Author: anyangle anyangle@huawei.com
Date: Wed Oct 14 17:59:54 2026 +0800
fix(machine): guard AOT runtime callbacks to catch host DEV_ASSERT before terminate
commit fda2a21e82292dec80a8c2544a3336972471ea7c
Author: zhaojunhan zhaojunhan1@huawei.com
Date: Wed Oct 14 14:32:05 2026 +0800
feat(ir): Sink a for loop after if into both branches
Co-authored-by: zhaojunhan<zhaojunhan1@huawei.com>
# message auto-generated for no-merge-commit merge:
!6872 merge sink_for_into_if into master
feat(ir): Sink a for loop after if into both branches
Created-by: zhaojunhan
Commit-by: zhaojunhan
Merged-by: cann-robot
Description: feat(ir): Sink a for loop after if into both branches


anyangle
Oct 31 Comments:
Oct 31 Comments:
24 days ago changed custom state from 待办的 to 已解决
24 days ago Close issue
24 days ago Added label: resolved
Describe the current behavior / 问题描述 (Mandatory / 必填)
仿真(host Machine + AOT control flow)跑用例时,业务侧出现 workspace / stitch 类失败后,进程不是抛出 Python 异常,而是:
ErrCode: F7…! Enum: …+Caught exception: '…'_Exit(1)直接退出典型关联:
AssignIncastAddresses等路径上的 hostDEV_ASSERT,以及更早的DEV_ERROR(如F73001/CTRL_FLOW_EXEC_FAILED)。根因(一层层)
1. 业务失败点(仿真控制流 / machine runtime)
CallRootFunctionStitch做 workspace preflight 时,空DeviceTask塞不下 root,reason=runtime-outcast-metadata→DEV_ERROR(F73001)。随后
AssignIncastAddresses再触发DEV_ASSERT→MACHINE_ASSERT→ C++throw Error。(同类问题不限于这一条:凡在 AOT→host 回调里
DEV_ASSERT/MACHINE_ASSERT抛出的,都会落到同一终止路径,例如SlotMarkNeedAlloc、ShmemAllocator等。)2. 为什么不是「正常 Python 异常」
仿真跑控制流时走的是:
C++ 异常要穿过 AOT 那些栈帧才能回到 pybind、变成 Python 异常;AOT 裸代码没有可用的异常展开信息(无 EH unwind)→ 穿不过 →
std::terminate。对比:非 AOT、纯 C++ 栈上的同款
DEV_ASSERT,可以正常 unwind 到 pybind →RuntimeError。3. 为什么是屏上这种裸格式
terminate处理器(error.cpp/TerminateHandler)故意:Caught exception: ...)ErrorManager::OutputErrorMessage()→std::cerr打队列里的ErrCode: ...cerr << "Caught exception: '...'"_Exit(1)所以既进了 log,又打屏;且从未进入 Python 异常通道。
Environment / 环境信息 (Mandatory / 必填)
device_execute_context/ AOT code pool)DEV_ASSERT为abort(),机制不同)Steps to reproduce the issue / 重现步骤 (Mandatory / 必填)
DEV_ASSERT的用例(例如AssignIncastAddresses空fromSlotList,或 cell_match op_combo 等会进入 stitch /RUNTIME_SlotMarkNeedAlloc的 case)。也可临时在 AOT 回调入口(如
MarkSlotNeedAlloc)强制DEV_ASSERT验证同一终止路径。Describe the expected behavior / 预期结果 (Mandatory / 必填)
DEV_ASSERTthrow 不应导致std::terminate/_Exit。SetErrorState,CF 正常返回后由既有错误态路径上报。修复方案(方案一 · 表级 trampoline)执行逻辑
在
RunControlFlow组装runtimeCallList时(仅 host /#if !defined(__DEVICE__)),不直接挂裸的DeviceExecuteRuntimeCall*,而是挂统一 Guard。改前:
改后:
包装拆开是三层(以 Alloc 为例):
DeviceExecuteRuntimeCallRootAlloc(kRaw):原来的真实现(业务逻辑),模板参数编译期固定。AotGuardedRuntimeCall<kRaw, kStage>:try { return kRaw(ctx, arg); } catch …;kStage用于日志名与失败哨兵选择。&AotGuardedRuntimeCall<…>:取包装函数地址放进runtimeCallList;AOT 调到的是 Guard,不是裸 Alloc。改动文件:
framework/src/machine/device/dynamic/context/device_execute_context.cpp(device 侧仍用原表)。Related log / screenshot / 日志 / 截图 (Mandatory / 必填)
典型 terminate 打屏(修复前):
业务失败关联日志中亦可见
F73001/CTRL_FLOW_EXEC_FAILED与AssignIncastAddressesassert 行号叠加。修复后期望日志形态示例:
而不再出现 terminate 的
Caught exception+_Exit。Special notes for this issue/备注 (Optional / 选填)
__DEVICE__)DEV_ASSERT为abort(),与本问题不同,保持原runtimeCallList即可。RuntimeError,需在CallControlFlow返回后(普通 C++ 栈)再 throw / 上层转换,可作 follow-up。