Closed
[Bug-Report|缺陷反馈]: aclnnMoeTokenUnpermuteWithRoutingMap paddedMode=true 时三个必填输出传 nullptr 未拒绝,执行期直接 SIGSEGV #8370
liuhanwen8Add on  7 days agoClosed at  3 days ago
liuhanwen8
liuhanwen8
7 days ago Create

关联:#8350(同接口不同根因:#8350 是 unpermutedTokens 置空在 DFX 阶段崩;本条是 pad=true 分支三个输出置空后直达 ViewCopy 未判空)

现象

paddedMode=true 时把 outIndex / permuteTokenId / permuteProbs 任一置 nullptr,首段返回 0(放行),执行期进程 SIGSEGV(exit=139),无错误码无日志。paddedMode=false 时三者「不生效」(资料明写),置空不崩 ⇒ 崩溃只由 pad=true 分支触发(同一探针 pad=true 全输出正常时返回 0,三个输出全部命中)。

对照(pad=false 的 A1/B1 与 pad=true 全输出正常的 B2 均返回 0,仅三个置空组 SIGSEGV,
证明崩溃只由「必填输出置空」触发,与 paddedMode 本身无关,三个输出全部命中)。

环境

  • CANN / 驱动 / 系统:CANN 9.3.0(Ascend-cann-950-ops,2026-11-11)/ 驱动 25.7.rc1 / Ubuntu 24.04 kernel 6.8 芯片:Ascend 950PR 框架:不涉及(纯 aclnn C) 分支:master(6246f63b)

根因

moe/moe_token_unpermute_with_routing_map/op_host/op_api/aclnn_moe_token_unpermute_with_routing_map.cpp:409(pad=true 分支,三处均未判 dst 空指针):

409:  l0op::ViewCopy(std::get<3>(permuteprob), permuteProbs, ...);   // dst 未判空
413:  l0op::ViewCopy(sortIndex, outIndex, ...);                      // dst 未判空
416:  l0op::ViewCopy(sortValuesI32, permuteTokenId, ...);            // dst 未判空
436:  if (permuteProbs != nullptr) { ... }                           // ← 另一路有判空

三处把输出张量直接传给 l0op::ViewCopy,而它内部对 dst 调 GetViewShape(),空指针即解引用。
CheckDtypeValid 对输出也是 if (outIndex != nullptr) { ... }(同文件 :156)—— 空指针跳过校验、随后被无条件使用,与 #8364 同一模式。

期望

三个输出资料都标必填(√),传 nullptr 属非法输入,应在首段返回 ACLNN_ERR_PARAM_NULLPTR / 161001,而非放行后执行期 SIGSEGV。 调用方「只关心主输出、其余出参按需申请」时,paddedMode=true 下漏填任一输出进程直接消失,
无日志无错误码,长驻服务表现为无 traceback 的进程消失。本轮先被 #8350 遮住。

影响

调用方「只关心主输出、其余出参按需申请」时,pad=true 下漏填任一输出进程直接消失,无日志无错误码;本轮先被 #8350 遮住。

建议

CheckParams 里补(与 :111-114、:436 同型):

paddedMode=false 分支本轮不崩(三者不生效),但 :409 同类调用是否受分支保护,建议一并确认。

复现步骤

  1. 保存文末 repro.cpp,用其中的 g++ 命令编译。
  2. 缺陷组 ./probe A2 / C2 / D2(pad=true,分别置空三个输出)→ 均 SIGSEGV,$? 为 139;对照组 ./probe B2 / A1 → 均正常退出。

复现脚本

#include "acl/acl.h"
#include "aclnnop/aclnn_moe_token_unpermute_with_routing_map.h"
#include <cstdio>
#include <cstring>
#include <string>
static constexpr int T = 16, K = 2, H = 64, E = 4, N = T * K;   // 几何

static aclTensor* mkT(int64_t d0, int64_t d1, aclDataType dt, void** dev, int fill) {
    int rank = (d1 > 0) ? 2 : 1;                       // d1<=0 表示 1 维
    int64_t sh[2] = {d0, d1}, st[2] = {d1 > 0 ? d1 : 1, 1};
    size_t b = (size_t)(rank == 2 ? d0 * d1 : d0) * (dt == ACL_INT8 ? 1 : (dt == ACL_INT32 ? 4 : 2));
    aclrtMalloc(dev, b, ACL_MEM_MALLOC_HUGE_FIRST);
    char* h = new char[b]; memset(h, fill, b);
    aclrtMemcpy(*dev, b, h, b, ACL_MEMCPY_HOST_TO_DEVICE); delete[] h;
    return aclCreateTensor(sh, (uint64_t)rank, dt, st, 0, ACL_FORMAT_ND, sh, (uint64_t)rank, *dev);
}

int main(int argc, char** argv) {
    std::string g = (argc > 1) ? argv[1] : "A2";
    bool padded = (g == "A2" || g == "B2" || g == "C2" || g == "D2");
    std::string nul = (g == "A1" || g == "A2") ? "outIndex"
                    : (g == "C2") ? "permuteTokenId" : (g == "D2") ? "permuteProbs" : "";
    printf("group=%s pad=%d null=%s\n", g.c_str(), (int)padded, nul.empty() ? "-" : nul.c_str());

    aclInit(nullptr); aclrtSetDevice(0);
    aclrtStream stream; aclrtCreateStream(&stream);

    void *d[8] = {nullptr};
    aclTensor* pt = mkT(N, H, ACL_BF16, &d[0], 0x11);
    aclTensor* si = mkT(N, 0, ACL_INT32, &d[1], 0x00);
    aclTensor* rm = mkT(T, E, ACL_INT8, &d[2], 0x01);
    aclTensor* pr = mkT(T, E, ACL_BF16, &d[3], 0x11);
    aclTensor* un = mkT(T, H, ACL_BF16, &d[4], 0x00);
    aclTensor* oi = mkT(N, 0, ACL_INT32, &d[5], 0x00);
    aclTensor* pi = mkT(N, 0, ACL_INT32, &d[6], 0x00);
    aclTensor* pp = mkT(N, 0, ACL_BF16,  &d[7], 0x00);

    int64_t rs[2] = {T, H};
    aclIntArray* restore = aclCreateIntArray(rs, 2);
    uint64_t ws = 0;
    aclOpExecutor* ex = nullptr;

    aclTensor* use_oi = (nul == "outIndex") ? nullptr : oi;
    aclTensor* use_pi = (nul == "permuteTokenId") ? nullptr : pi;
    aclTensor* use_pp = (nul == "permuteProbs") ? nullptr : pp;
    aclnnStatus r1 = aclnnMoeTokenUnpermuteWithRoutingMapGetWorkspaceSize(
        pt, si, rm, pr, padded, restore, un, use_oi, use_pi, use_pp, &ws, &ex);
    printf("ret_gws = %d  ws = %llu\n", (int)r1, (unsigned long long)ws);
    if (r1 != 0) return 1;

    void* wb = nullptr;
    if (ws) aclrtMalloc(&wb, (size_t)ws, ACL_MEM_MALLOC_HUGE_FIRST);
    printf("ret_exec = %d\n", (int)aclnnMoeTokenUnpermuteWithRoutingMap(wb, ws, ex, stream));
    printf("sync = %d\n", (int)aclrtSynchronizeStream(stream));
    return 0;
}
g++ -O1 -std=c++17 -o probe repro.cpp -I$ASCEND_HOME_PATH/include -L$ASCEND_HOME_PATH/lib64 -lascendcl -lnnopbase -lopapi

实测输出:

$ ./probe A2   -> ret_gws = 0 后 Segmentation fault (core dumped)   # rc=139
$ ./probe B2   -> ret_gws = 0  ret_exec = 0  sync = 0               # 基线正常
$ ./probe A1   -> ret_gws = 0  ret_exec = 0  sync = 0               # pad=false 不生效
likedislike
liuhanwen8liuhanwen8
7 days ago Added label: bug-report
周云飞
周云飞Collaborators
7 days ago Comments:

从您提供的复现结果看,paddedMode=true 时这三个输出中任一为空,可能导致进程崩溃。您指出的 ViewCopy 空指针解引用路径仍需进一步核实。

有一处接口说明需要确认:头文件将 outIndex 和 permuteTokenId 标为必选,但将 permuteProbs 标为可选,与您提到的资料不一致。可以考虑在首段按实际接口约定检查输出指针,对必填参数为空的情况返回参数错误;可选输出则需确认其为空时的处理方式,同时核对 paddedMode=false 分支。

临时规避时,建议 paddedMode=true 下为三个输出都提供有效张量,即使调用方不使用这些结果。

likedislike
周云飞周云飞Collaborators
5 days ago Assign aaaakai as responsible person
Yuan BinYuan BinCollaborators
5 days ago Removed responsible person aaaakai
Yuan BinYuan BinCollaborators
5 days ago Assign aaaakai as responsible person
CANN-robotCANN-robotCollaborators
3 days ago Close issue
CANN-robotCANN-robotCollaborators
3 days ago changed custom state from 待办的 to 已完成
周云飞
周云飞Collaborators
3 days ago Comments:

已合入 PR #17003,将参数检查提前到接口诊断记录之前,并在相关执行分支中增加输出指针检查:outIndex 和 permuteTokenId 不得为空;提供 probsOptional 时,permuteProbs 不得为空,否则返回空指针错误。同时增加了 routingMapOptional 连续化结果的检查。

关联 PR:PR #17003

likedislike
CANN-robotCANN-robotCollaborators
3 days ago Added label: resolved