Closed
[Documentation|文档反馈]: 《aclnnMaxPool》A2/A3 约束说明未写明 4 维 ND 入参的实际限制(实测 561103) #7881
liuhanwen8Add on  21 days agoClosed at  4 days ago
liuhanwen8
liuhanwen8
21 days ago Create

现象

aclnnMaxPool 在 4 维 + ND 格式 入参下第一段返回 561103(实测 GetWorkspaceSize = 561103),
plog 的拒绝点固定为 TransData not support: ND -> NC1HWC0;同一 4 维 shape 改用 NCHW
描述符则正常返回 0,3 维 ND 也正常。

输入 GetWorkspaceSize / execute 说明
3D ND [2,8,8] fp32 0 / 0 参照
4D NCHW [2,2,8,8] fp32 0 / 0 参照
4D ND [2,2,8,8] fp32 561103 / — 复现项

期望

《aclnnMaxPool》参数表中 self 的格式列为 ND、维度列为 3-4;而 A2/A3 的
「约束说明」分组段目前只写了数据类型例外(不支持 BFLOAT16/整型),没有说明
4 维 ND 的实际约束。

希望在该分组段补一句可执行的限制说明,二选一:

  • 若 4 维确应按资料用 ND:修复 ExecMaxPoolV3 的 4 维路径(先 ReFormat 到 NCHW 再 Selfto5HDProcess);
  • 若 4 维暂不支持 ND:在 A2/A3 约束说明写明「4 维入参需使用 NCHW 描述符」。

不论哪种,当前资料让调用方无法预知 4 维 ND 会失败。

环境

  • 硬件:Atlas A2 训练系列(910B),npu-smi 26.1.1
  • CANN:9.2.0,Linux aarch64,g++ 11.4.0
  • 仓库与提交:cann/ops-nn a61e016a71f422cb280af0c024975f13629ca100(master)
  • 复现日期:2026-11-01

复现步骤

  1. 保存下方脚本为 repro.cpp
  2. g++ -std=c++17 -O2 repro.cpp -o repro -I$ASCEND_HOME_PATH/include -L$ASCEND_HOME_PATH/lib64 -lascendcl -lopapi -lnnopbase
  3. ./repro
  4. 观察输出:两行 对照组 均为 GetWorkspaceSize = 0,缺陷组 4D ND 行为 561103

复现脚本

// aclnnMaxPool 4 维 ND 输入最小复现
// g++ -std=c++17 -O2 repro.cpp -o repro -I$ASCEND_HOME_PATH/include \
//     -L$ASCEND_HOME_PATH/lib64 -lascendcl -lopapi -lnnopbase
#include <aclnnop/aclnn_max_pool.h>
#include <acl/acl.h>
#include <cstdio>
#include <vector>

static aclTensor* mkT(void* p, std::vector<int64_t> sh, aclFormat fmt) {
    std::vector<int64_t> st(sh.size());
    int64_t acc = 1;
    for (int i = (int)sh.size() - 1; i >= 0; --i) { st[i] = acc; acc *= sh[i]; }
    return aclCreateTensor(sh.data(), sh.size(), ACL_FLOAT, st.data(), 0, fmt,
                           sh.data(), sh.size(), p);
}

static int run(const char* tag, std::vector<int64_t> inShape, aclFormat fmt) {
    std::vector<int64_t> outShape = inShape;
    outShape[outShape.size() - 1] /= 2;
    outShape[outShape.size() - 2] /= 2;
    aclrtStream s;
    aclrtCreateStream(&s);
    size_t inB = 4, outB = 4;
    for (auto v : inShape) inB *= (size_t)v;
    for (auto v : outShape) outB *= (size_t)v;
    void* dIn = nullptr;
    void* dOut = nullptr;
    aclrtMalloc(&dIn, inB, ACL_MEM_MALLOC_HUGE_FIRST);
    aclrtMalloc(&dOut, outB, ACL_MEM_MALLOC_HUGE_FIRST);
    aclTensor* in = mkT(dIn, inShape, fmt);
    aclTensor* out = mkT(dOut, outShape, fmt);
    std::vector<int64_t> k{2, 2}, st{2, 2}, pd{0, 0}, dl{1, 1};
    aclIntArray* ak = aclCreateIntArray(k.data(), 2);
    aclIntArray* as = aclCreateIntArray(st.data(), 2);
    aclIntArray* ap = aclCreateIntArray(pd.data(), 2);
    aclIntArray* ad = aclCreateIntArray(dl.data(), 2);
    uint64_t ws = 0;
    aclOpExecutor* ex = nullptr;
    int r1 = (int)aclnnMaxPoolGetWorkspaceSize(in, ak, as, 0, ap, ad, 0, out, &ws, &ex);
    int r2 = -1;
    if (r1 == 0) {
        aclnnMaxPool(nullptr, 0, ex, s);
        r2 = 0;
        aclrtSynchronizeStream(s);
    }
    printf("[%s] GetWorkspaceSize = %d execute = %d\n", tag, r1, r2);
    return r1;
}

int main() {
    aclInit(nullptr);
    aclrtSetDevice(0);
    run("对照组 3D ND 2x8x8", {2, 8, 8}, ACL_FORMAT_ND);
    run("缺陷组 4D ND 2x2x8x8", {2, 2, 8, 8}, ACL_FORMAT_ND);
    run("对照组 4D NCHW 2x2x8x8", {2, 2, 8, 8}, ACL_FORMAT_NCHW);
    aclrtResetDevice(0);
    aclFinalize();
    return 0;
}

实测输出:

[对照组 3D ND 2x8x8] GetWorkspaceSize = 0 execute = 0
[缺陷组 4D ND 2x2x8x8] GetWorkspaceSize = 561103 execute = -1
[对照组 4D NCHW 2x2x8x8] GetWorkspaceSize = 0 execute = 0

影响

按资料以 ND 传 4 维(含 batch,最常见形态)时调用方会在第一段接口失败,且资料未给出
NCHW 规避方式,只能靠读实现源码或试错定位。

建议

修改 pooling/max_pool_v3/docs/aclnnMaxPool.md 的 A2/A3 约束说明分组段;若判断属实现缺口,
则改 pooling/max_pool_v3/op_api/aclnn_max_pool.cpp 的 ExecMaxPoolV3(实测第 480 行)。

likedislike
liuhanwen8liuhanwen8
21 days ago Added label: bug-report
yuning_chenyuning_chenCollaborators
20 days ago Assign gitee-duhuiping as responsible person
yuning_chen
yuning_chenCollaborators
20 days ago Comments:

初步分析

感谢反馈,我们已开始核对这个问题。

现象理解:MaxPool 资料 A2/A3 未写明 4 维 ND 实际限制,实测 561103
当前判断:初步判断,待复现确认。资料约束缺失
涉及范围:aclnnMaxPool 文档 A2/A3 约束
下一步:核对实现限制并补 4 维 ND 说明

likedislike
yuning_chen
yuning_chenCollaborators
20 days ago Comments:

您好,该问题已收到,当前问题 @gitee-duhuiping 正在处理中

likedislike
gitee-duhuipinggitee-duhuipingCollaborators
20 days ago Removed responsible person gitee-duhuiping
gitee-duhuipinggitee-duhuipingCollaborators
20 days ago Assign gitee-duhuiping as responsible person
gitee-duhuipinggitee-duhuipingCollaborators
20 days ago Removed responsible person gitee-duhuiping
yuning_chenyuning_chenCollaborators
20 days ago Assign yuhao_ as responsible person
yuning_chen
yuning_chenCollaborators
20 days ago Comments:

您好,该问题已收到,当前问题 @yuhao_ 正在处理中

likedislike
memorecoolmemorecoolCollaborators
19 days ago Removed responsible person yuhao_
memorecoolmemorecoolCollaborators
19 days ago Assign cjz_ as responsible person
yuning_chenyuning_chenCollaborators
11 days ago Assign yu-xinjie62 as responsible person, remove original responsible person: cjz_
memorecoolmemorecoolCollaborators
11 days ago Removed responsible person yu-xinjie62
memorecoolmemorecoolCollaborators
11 days ago Assign cjz_ as responsible person
陈俊卓
陈俊卓Collaborators
4 days ago Comments:

已修改

likedislike
陈俊卓陈俊卓Collaborators
4 days ago changed custom state from 进行中 to 已完成
陈俊卓陈俊卓Collaborators
4 days ago Close issue
CANN-robotCANN-robotCollaborators
3 days ago Added label: resolved