Closed
[Bug-Report|缺陷反馈]: aclnnInplaceAtan2 的 selfRef 表外 dtype 未拒绝(实测 0/0,应 161002)且该入口 UT 零覆盖 #4200
liuhanwen8Add on  20 days agoClosed at  1 day ago
liuhanwen8
liuhanwen8
20 days ago Create

现象

aclnnInplaceAtan2 的第一段接口不校验 selfRef(即 out)的 dtype:资料声明 out 只支持 FLOAT/FLOAT16/DOUBLE/BFLOAT16,传 INT8/UINT8/INT32/BOOL 一律返回 0/0,把结果静默截断后原地写回 selfRef,而不是按资料返回 161002。

selfRef={1.0}×8、other={1.0}×8,atan2 正确值 0.785398。4 组表外 dtype 全部 0/0 并原地截断写入:

selfRef dtype 两段返回 应得
FLOAT / FLOAT16(资料声明支持,对照) 0 / 0 0/0
INT8 / UINT8 / INT32 / BOOL(表外) 0 / 0 161002

期望

资料 math/atan2/docs/aclnnAtan2&aclnnInplaceAtan2.md 原地接口段:错误码 161002 子项写「selfRef 的数据类型不在支持的范围之内」,selfRef 参数行「数据类型」列为 FLOAT/FLOAT16/DOUBLE/BFLOAT16。故表外 dtype 应在第一段返回 161002。

根因与 #4187 同源(CheckDtypeValid 形参缺 out),但入口不同,故单独提本单:

math/atan2/op_api/aclnn_atan2.cpp:174-180:

auto out = const_cast<aclTensor*>(selfRef);        // out 就是 selfRef
return ExecAtan2GetWorkspaceSize(selfRef, other, out, workspaceSize, executor);

out 由 selfRef 代入,本应共享同一个校验。但仓库 UT 对该入口零覆盖:test_atan2.cpp 中 aclnnInplaceAtan2 计数为 0,全部用例只构造 out-of-place 的 aclnnAtan2。

与 #4187 的关系:其修复 !6785 改 CheckDtypeValid 与 CheckParams,代码层面会顺带覆盖 Inplace 入口,但新增 UT 只有 aclnnAtan2_out_dtype_error(out-of-place),无 Inplace 断言。本单诉求是为该独立入口补独立 UT,而非再修一次代码。

环境

Atlas A2 910B2;CANN 26.1.1;Linux aarch64 / g++ 10.3.1;仓库 cann/ops-math 9c1a58283(fetch 后 master;:59 仍两形参、:174-180 原地入口未变);2026-10-29。

复现步骤

  1. 保存下方脚本为 repro.cpp,source <CANN安装目录>/set_env.sh
  2. g++ -std=c++17 -O2 repro.cpp -o repro -I$ASCEND_HOME_PATH/include -L$ASCEND_HOME_PATH/lib64 -lascendcl -lopapi -lnnopbase
  3. ASCEND_RT_VISIBLE_DEVICES=<空闲die> ./repro,观察:对照组应 0/0,四组表外 dtype 应 161002,实测均 0/0

复现脚本

#include <acl/acl.h>
#include <aclnnop/aclnn_atan2.h>
#include <cstdio>
#include <cstdint>
#include <vector>
static const int64_t N = 8;
static aclTensor* mk(void* d, aclDataType t, const std::vector<int64_t>& sh) {
    std::vector<int64_t> st(sh.size(), 1);
    for (int i = (int)sh.size() - 2; i >= 0; --i) st[i] = st[i + 1] * sh[i + 1];
    return aclCreateTensor(sh.data(), (uint64_t)sh.size(), t, st.data(), 0,
                           ACL_FORMAT_ND, sh.data(), (uint64_t)sh.size(), d);
}
static void run(aclrtStream s, aclDataType dt, int* r1, int* r2) {
    void* d = nullptr; size_t b = N * 4;
    aclrtMalloc(&d, b, ACL_MEM_MALLOC_HUGE_FIRST);
    std::vector<int32_t> h(N, 0x3f800000);   // 1.0f 位模式
    aclrtMemcpy(d, b, h.data(), b, ACL_MEMCPY_HOST_TO_DEVICE);
    std::vector<int64_t> sh = {N};
    aclTensor* ref = mk(d, dt, sh);
    aclTensor* oth = mk(d, ACL_FLOAT, sh);
    uint64_t ws = 0; aclOpExecutor* ex = nullptr;
    *r1 = (int)aclnnInplaceAtan2GetWorkspaceSize(ref, oth, &ws, &ex);
    *r2 = -1;
    if (*r1 == 0) {
        void* w = nullptr;
        if (ws > 0) aclrtMalloc(&w, ws, ACL_MEM_MALLOC_HUGE_FIRST);
        *r2 = (int)aclnnInplaceAtan2(w, ws, ex, s);
        if (*r2 == 0) aclrtSynchronizeStream(s);
        if (w) aclrtFree(w);
    }
    aclDestroyTensor(ref); aclDestroyTensor(oth); aclrtFree(d);
}
int main() {
    aclInit(nullptr); aclrtSetDevice(0);
    aclrtStream s; aclrtCreateStream(&s);
    const char* nm[] = {"FLOAT", "FLOAT16", "INT8", "UINT8", "INT32", "BOOL"};
    aclDataType cs[] = {ACL_FLOAT, ACL_FLOAT16, ACL_INT8, ACL_UINT8, ACL_INT32, ACL_BOOL};
    printf("%-8s %-6s %-6s\n", "selfRef", "ret1", "ret2");
    for (int i = 0; i < 6; ++i) {
        int r1 = 0, r2 = 0; run(s, cs[i], &r1, &r2);
        printf("%-8s %-6d %-6d\n", nm[i], r1, r2);
    }
    aclrtDestroyStream(s); aclrtResetDevice(0); aclFinalize(); return 0;
}

实测输出(A2 910B2,CANN 26.1.1,master 9c1a58283):

selfRef  ret1   ret2
FLOAT    0      0
FLOAT16  0      0
INT8     0      0
UINT8    0      0
INT32    0      0
BOOL     0      0

对照组 FLOAT/FLOAT16 正常返回 0,证明探针与设备可用;四组表外 dtype 未被拒绝。

影响

  • 按资料 161002 写的容错逻辑对原地接口永不触发;非法 dtype 被静默截断并原地写回 selfRef,输入缓冲被破坏且无告警。原地接口常用于大 tensor 就地更新省显存,截断后原始输入不可恢复,比 out-of-place 更难排查。
  • UT 零覆盖使该入口无回归保护:!6785 后 Inplace 只是"顺带能过",后续给 selfRef 单独开分支即静默退化而 UT 全绿。

建议

  1. 补 UT(本单主诉求):在 math/atan2/tests/ut/op_api/test_atan2.cpp 增加 aclnnInplaceAtan2_out_dtype_error,与 !6785 的 aclnnAtan2_out_dtype_error 同构:
// selfRef 用 ACL_INT8、other 用 ACL_FLOAT,其余照抄 !6785 的 aclnnAtan2_out_dtype_error
auto ut = OP_API_UT(aclnnInplaceAtan2, INPUT(selfRefDesc, otherDesc), OUTPUT(selfRefDesc));
EXPECT_EQ(ut.TestGetWorkspaceSize(&workspaceSize), ACLNN_ERR_PARAM_INVALID);
  1. 代码侧无需额外改动——!6785 对 CheckDtypeValid 的修改已覆盖该入口;请确认合入后原地入口的表外 dtype 同样返回 161002。

  2. 若维护方认为应并入 #4187 处理,请直接关闭本单并在 !6785 中追加该 UT。

likedislike
liuhanwen8liuhanwen8
20 days ago Added label: bug-report
陈思
陈思Collaborators
20 days ago Comments:

您好,感谢补充原地入口的测试诉求。已核对固定提交 8c1f633e3679,您列出的 UT 文件没有直接调用 aclnnInplaceAtan2,补充该入口的独立覆盖确有价值。

这里需先核对测试预期:同版原地接口资料中,selfRef 的支持列表明确列出了 INT8、INT16、INT32、INT64、UINT8、BOOL;非原地 out 的列表则更窄。因此不能仅因为这些类型不在非原地输出表内,就认定原地 selfRef 也应一律返回 161002。这个原地契约与您正文中“selfRef 仅支持四种浮点”的引用存在差异,需要先对齐,再决定断言应拒绝还是保留既有接受行为。

当前实现确实将 selfRef 同时作为输入和输出传入公共函数。!6785 的做法是在公共路径加入输出支持列表校验,目前尚未合入;这会同时影响两个入口,也正因如此,原地的类型约定需要单独确认。

一个可行的方向是为原地接口补齐独立用例:在明确支持列表后校验支持类型的计算和原地写回,对确定不支持的类型校验第一段返回码;同时覆盖广播形状及合法浮点对照。这样可以建立独立回归保护,而不是直接照搬非原地 INT8 out 的错误断言。我们会继续确认原地契约和公共校验修改的兼容边界。

likedislike
陈思陈思Collaborators
20 days ago Assign chen_0715 as responsible person
陈思陈思Collaborators
20 days ago Added label: pending-confirmation
CchenyifengCollaborators
20 days ago Assign sakuraqqz as responsible person
CchenyifengCollaborators
20 days ago Removed responsible person chen_0715
SsakuraqqzCollaborators
16 days ago Associated pull request
CANN-robotCANN-robotCollaborators
1 day ago Close issue
CANN-robotCANN-robotCollaborators
1 day ago changed custom state from 进行中 to 已完成
CANN-robotCANN-robotCollaborators
1 day ago Added label: resolved