Closed
[Documentation|文档反馈]: aclnnFlip 文档与头文件 dtype 表漏 UINT16/UINT32/UINT64(REGBASE 白名单含且设备实测全对) #8934
liuhanwen8Add on  4 days agoClosed at  4 days ago
liuhanwen8
liuhanwen8
4 days ago Create

现象

aclnnFlip(算子 ReverseV2)的资料 docs/aclnnFlip.md:87 把 self 数据类型列为 12 种,不含 UINT16/UINT32/UINT64(公开头文件 aclnn_flip.h 同样未列,grep -c UINT16 = 0);而同仓实现侧 op_api/aclnn_flip.cpp:41-46 的 REGBASE_DTYPE_SUPPORT_LIST(Ascend 950 系列实走,见 :53 的 IsRegbase 分支)含这三种,设备实测也能正确翻转。

来源 位置 UINT16/32/64
资料 self 行 docs/aclnnFlip.md:87 ✗
aclnn 首段 REGBASE 列表(950 实走) op_api/aclnn_flip.cpp:41-46 ✓
设备实测(950/9.3.0) 6 组 dtype 同宽对照 3 种 uint 全部翻转全对

期望

资料 :87 的列表应补入 UINT16、UINT32、UINT64,与 aclnn_flip.cpp:41-46 白名单及实测一致。该表全产品共用(无按产品分段),故对 950 成立。

根因

REGBASE_DTYPE_SUPPORT_LIST 引入三种无符号整型时(与 DT_INT8/UINT8/INT16 同批),只更新了 op_api 白名单与 OpDef,未同步资料参数表。此类「int 有列、对应 uint 未列」的成对遗漏在 index/ 下另有同类(gather_v2 的 UINT16)。

环境

  • 硬件 / CANN:Ascend950PR(A5)+ CANN 9.3.0(950 包),x86_64,驱动 25.7.rc1;日期 2026-11-17
  • 仓与提交:cann/ops-nn 955fa5c92246c4851530034c798e7694412bca8f(git ls-remote 与 fetch 后本地 HEAD 一致);该提交下 aclnnFlip.md=f7be4510、aclnn_flip.cpp=f511ae7c(与前基线 7a2786b4 相同,未变动)
  • 契约核验:同提交下 grep -c UINT16 对 docs/aclnnFlip.md 与 op_api/aclnn_flip.h 均为 0

复现步骤

  1. 保存下方 repro.cpp,按文件首注释编译(需 CANN 9.3.0 及以上),然后 ./repro —— 6 种 dtype 逐个跑两段式接口(self=[16]、dims={0}),判断「两段返回 / 哨兵残留 / 是否逐元素等于翻转 golden」;观察 int16/int32/int64(资料已列)与 uint16/uint32/uint64(资料未列)全部 0/0 且翻转全对。

复现脚本

// repro.cpp — aclnnFlip dtype 契约实测
// build: g++ -O2 -std=c++17 repro.cpp -o repro -I$ASCEND_HOME_PATH/include -I$ASCEND_HOME_PATH/include/aclnn -I$ASCEND_HOME_PATH/include/aclnnop -L$ASCEND_HOME_PATH/lib64 -lopapi_cv -lopapi -lnnopbase -lascendcl
// 【缺陷组】uint16/32/64:资料 :87 未列,REGBASE 白名单含且实测翻转全对;【对照组】int16/32/64(资料已列)应全对
#include <cstdio>
#include <cstring>
#include <vector>
#include "acl/acl.h"
#include "aclnn/acl_meta.h"
#include "aclnn_flip.h"

struct D { const char* n; aclDataType a; int b; bool doc; };
struct R { int r1, r2, sent; bool exact; };   // 跑一次 flip(dim=0) 的结果
static R run(aclrtStream st, aclDataType dt, int b, int N) {
    int64_t sh[1] = {N}, dv[1] = {0}; size_t sz = (size_t)N * b;
    void *sD = nullptr, *oD = nullptr;
    aclrtMalloc(&sD, sz, ACL_MEM_MALLOC_HUGE_FIRST); aclrtMalloc(&oD, sz, ACL_MEM_MALLOC_HUGE_FIRST);
    std::vector<unsigned char> hs(sz), ho(sz, 0xAB);   // out 预填哨兵
    for (int k = 0; k < N; ++k) { long long v = k + 1; memcpy(hs.data() + (size_t)k * b, &v, b < 8 ? b : 8); }
    aclrtMemcpy(sD, sz, hs.data(), sz, ACL_MEMCPY_HOST_TO_DEVICE); aclrtMemcpy(oD, sz, ho.data(), sz, ACL_MEMCPY_HOST_TO_DEVICE);
    aclTensor *tx = aclCreateTensor(sh, 1, dt, nullptr, 0, ACL_FORMAT_ND, sh, 1, sD),
              *to = aclCreateTensor(sh, 1, dt, nullptr, 0, ACL_FORMAT_ND, sh, 1, oD);
    aclIntArray* dims = aclCreateIntArray(dv, 1);
    R r; r.r1 = r.r2 = -1; r.sent = -1; r.exact = false; uint64_t w = 0; aclOpExecutor* e = nullptr;
    r.r1 = (int)aclnnFlipGetWorkspaceSize(tx, dims, to, &w, &e);
    if (r.r1 == 0) {
        void* p = nullptr; if (w) aclrtMalloc(&p, w, ACL_MEM_MALLOC_HUGE_FIRST);
        r.r2 = (int)aclnnFlip(p, w, e, st);
        if (r.r2 == 0) { aclrtSynchronizeStream(st);
            std::vector<unsigned char> g(sz, 0); aclrtMemcpy(g.data(), sz, oD, sz, ACL_MEMCPY_DEVICE_TO_HOST);
            r.sent = 0; for (size_t i = 0; i < sz; ++i) if (g[i] == 0xAB) r.sent++;
            r.exact = (r.sent == 0);
            for (int k = 0; k < N && r.exact; ++k)
                if (memcmp(&g[(size_t)k*b], &hs[(size_t)(N-1-k)*b], b)) r.exact = false;
        } if (p) aclrtFree(p);
    }
    aclDestroyTensor(tx); aclDestroyTensor(to); aclDestroyIntArray(dims); aclrtFree(sD); aclrtFree(oD);
    return r;
}

int main() {
    setvbuf(stdout, nullptr, _IONBF, 0);
    aclInit(nullptr); aclrtSetDevice(0);
    aclrtStream st = nullptr; aclrtCreateStream(&st);
    const int N = 16;
    D DS[] = {{"int16", ACL_INT16, 2, true},  {"uint16", ACL_UINT16, 2, false},
              {"int32", ACL_INT32, 4, true},  {"uint32", ACL_UINT32, 4, false},
              {"int64", ACL_INT64, 8, true},  {"uint64", ACL_UINT64, 8, false}};
    printf("%-8s %-5s %-12s %-8s %s\n", "dtype", "资料", "两段返回", "未写", "判定");
    int listedOK = 0, listedN = 0, unOK = 0, unN = 0;
    for (auto& d : DS) {
        R r = run(st, d.a, d.b, N);
        bool pass = (r.r1 == 0 && r.r2 == 0 && r.sent == 0 && r.exact);
        char rb[24]; snprintf(rb, sizeof(rb), "%d/%d", r.r1, r.r2);
        printf("%-8s %-5s %-12s %-8d %s\n", d.n, d.doc ? "有" : "无", rb, r.sent,
               r.r1 != 0 ? "REJ" : (r.sent > 0 ? "*** 未写 ***" : (r.exact ? "OK(翻转全对)" : "值错")));
        if (d.doc) { listedN++; listedOK += pass; } else { unN++; unOK += pass; }
    }
    printf("\n资料已列 %d/%d 通过;资料未列 %d/%d 通过\n", listedOK, listedN, unOK, unN);
    if (listedOK == listedN && unOK > 0)
        printf(">>> DOC-GAP: 资料未列的 %d 种 uint 实测通过且翻转正确(同宽 int 兄弟对照)\n"
               "    靶点: docs/aclnnFlip.md:87 只 12 种;aclnn_flip.cpp:41-46 REGBASE 含 3 种 uint\n", unOK);
    aclrtDestroyStream(st); aclrtResetDevice(0); aclFinalize();
    return 0;
}

实测输出:

dtype   资料 两段返回 未写 判定            |  dtype   资料 两段返回 未写 判定
int16   有   0/0     0   OK(翻转全对)     |  uint16  无   0/0     0   OK(翻转全对) <-资料未列
int32   有   0/0     0   OK(翻转全对)     |  uint32  无   0/0     0   OK(翻转全对) <-资料未列
int64   有   0/0     0   OK(翻转全对)     |  uint64  无   0/0     0   OK(翻转全对) <-资料未列
资料已列 3/3 通过;资料未列 3/3 通过

[SELFPROOF positive] 资料已列的 int16/int32/int64 同宽对照两段 0/0、残留 0、翻转逐元素正确,证明夹具与 golden(out[k]=self[N-1-k])无误。
[SELFPROOF oracle] 期望值来源:资料 aclnnFlip.md:87 dtype 列与 aclnn_flip.cpp:41-46 白名单原文(grep -c UINT16 对资料/头文件均为 0),非自拟。
[SELFPROOF canary] out 预填 0xAB,六种 dtype 的 16 元素残留均为 0;uint 与 int 同宽同值域结果一致,双排除偶合。
[SELFPROOF dtype] enum_source=header (acl_base_rt.h):ACL_INT16=6(:180)、ACL_UINT16=7(:181)、ACL_UINT32=8(:182)、ACL_INT32=3(:178)、ACL_INT64=9、ACL_UINT64=10。

影响

使用者按资料选型时会误判 aclnnFlip 不支持三种 uint:上层框架(PTA 等)若以文档为准做 dtype 能力探测,会把无符号整型输入判为不支持而提前插入 cast 降级或拒绝,损失三条已可用通路。严重性为文档级(对外契约窄于实现,不会拿到错误结果)。

建议

  1. docs/aclnnFlip.md:87 的 self 数据类型列补入 UINT16、UINT32、UINT64(紧随对应 INT16/INT32/INT64 之后,与本仓 aclnn_take.h:36 风格一致);out 行写「与 self 一致」,无需改动。
  2. 顺带统一别名:该列用 FLOAT64 而其余仓多用 DOUBLE,建议对齐 aclnn_flip.cpp 的 DT_DOUBLE(纯文档用词,无行为影响)。
  3. 本条与 #7145(同接口 COMPLEX128 被白名单放行但 OpDef 未注册、静默全 0)方向相反、对象不同:本条是白名单已含 uint 且实测可用、仅文档缺失,两者互不覆盖。
likedislike
liuhanwen8liuhanwen8
4 days ago Added label: bug-report
LimpuLimpu
4 days ago Associated pull request
yuning_chen
yuning_chenCollaborators
4 days ago Comments:

问题成立,文档与头文件/实现不一致。建议以实际行为为准收敛资料(dtype 表、约束、错误码三处),中英文同一 PR 一起改,并顺手核对同族算子是否有同类漂移。

本条:aclnnFlip 文档与头文件 dtype 表漏 UINT16/UINT32/UINT64。注意:责任田表里没有 Flip 行,我先回复不指派,等确认归属后再落人。

likedislike
yuning_chenyuning_chenCollaborators
4 days ago Assign yue-ma as responsible person
yuning_chen
yuning_chenCollaborators
4 days ago Comments:

您好,问题已收到,当前 @yue-ma 正在处理中。

likedislike
xingtaowuxingtaowuCollaborators
4 days ago Assign xingtaowu as responsible person
xingtaowuxingtaowuCollaborators
4 days ago Removed responsible person yue-ma
xingtaowuxingtaowuCollaborators
4 days ago Deleted associated pull request: docs: add missing UINT16/UINT32/UINT64 to aclnnFlip dtype tables
xingtaowuxingtaowuCollaborators
4 days ago changed custom state from 待办的 to 已解决
xingtaowuxingtaowuCollaborators
4 days ago Close issue
CANN-robotCANN-robotCollaborators
4 days ago Added label: resolved