Closed
[Documentation|文档反馈]: foreach 同族六接口对 out 的 Tensor 个数要求 3:3 不一致,且六份资料都只约束单块 shape #7936
liuhanwen8Add on  20 days agoClosed at  5 days ago
liuhanwen8
liuhanwen8
20 days ago Create

关联:#7929(同为 foreach 的 out 块数资料缺失;本条差异:#7929 只说 AddScalar 的 561002 段缺子项,本条是同族六接口要求不一致 + 六份资料都只约束单块 shape)

现象

Atlas A2(910B3)上,按六份资料的 out 行构造(x 1 块、out 2 块,每块 shape 与 x 相同,
满足资料「shape size 大于等于入参 x 的 shape size」),第一段返回分成两派:

接口 out=1 out=2 判读
AddcdivList / AddScalarList / AddcdivScalarV2 0 0 放行
AddScalarV2 0 161001 拒绝
AddcdivScalar / AddcdivScalarList 0 161002 拒绝

即同族、同硬件、同 CANN 版本,out 块数要求 3:3 分裂;六份资料的 out 行措辞完全一致
(只有「支持空Tensor / 所有Tensor dtype 一致 / shape size 大于等于入参 x 的 shape size」),
没有任何一份说明 out 的 Tensor 个数该等于什么。

环境

设备 Atlas A2(910B3)单卡;CANN 9.2.0;仓 cann/ops-nn master b27fda24754e161dc8f489e5e0024f55ccdc69bd

期望

六份资料的 out 行统一补「out 含多少个 Tensor」并统一实现口径:若「必须相等」,三个放行
接口补校验;若「可多传」(与 #7740 一致),三个拒绝接口放开。

应得值依据

  1. 「shape size」约束的是单块,不是块数:out 行原文中 shape size 指单个 Tensor 的
    元素数。按这句构造(每块与 x 同形、只多给一块)不违反任何一句,却有一半接口被拒。
  2. 同族应一致:六接口同属 foreach 同族、out 都是 aclTensorList*、资料措辞逐字相同,
    没有理由一半要 ==、一半不要。这是族内自相矛盾,不依赖外部契约即可判定「至少有一半
    不符合应有行为」。可行性:OP_CHECK_TENSORLIST_SIZE_EQUAL 已在三个接口用了,host 侧取块数无成本。

复现步骤

  1. 把下方 repro.cpp 存盘,按块首注释编译;运行 ./repro 得 缺 out 上界校验: 3 / 6。
  2. 打开六份资料搜 out(aclTensorList*),确认每份都只写「shape size 大于等于入参 x 的
    shape size」;全文 Tensor个数 只在 aclnnForeachAddScalarV2.md 的 npu="950" 段出现。

复现脚本

实测输出(910B3 / CANN 9.2.0):

interface              out=1 (base) out=2 > x=1  verdict
AddcdivList            ret1=0        ret1=0        **MISSING CHECK**
AddScalarList          ret1=0        ret1=0        **MISSING CHECK**
AddScalarV2            ret1=0        ret1=161001   rejected (correct)
AddcdivScalar          ret1=0        ret1=161002   rejected (correct)
AddcdivScalarList      ret1=0        ret1=161002   rejected (correct)
AddcdivScalarV2        ret1=0        ret1=0        **MISSING CHECK**
缺 out 上界校验: 3 / 6
// g++ -std=c++17 -O1 repro.cpp -o repro -I$ASCEND_HOME_PATH/include -L$ASCEND_HOME_PATH/lib64 -lopapi -lnnopbase -lascendcl
#include <cstdio>
#include <vector>
#include "acl/acl.h"
#include "aclnn/acl_meta.h"
#include "aclnnop/aclnn_foreach_addcdiv_list.h"
#include "aclnnop/aclnn_foreach_add_scalar_list.h"
#include "aclnnop/aclnn_foreach_add_scalar_v2.h"
#include "aclnnop/aclnn_foreach_addcdiv_scalar.h"
#include "aclnnop/aclnn_foreach_addcdiv_scalar_list.h"
#include "aclnnop/aclnn_foreach_addcdiv_scalar_v2.h"

static aclTensor* mk(void* p, std::vector<int64_t> d) {
    std::vector<int64_t> st(d.size(), 1);
    for (int i = (int)d.size() - 2; i >= 0; --i) st[i] = st[i + 1] * d[i + 1];
    return aclCreateTensor(d.data(), d.size(), ACL_FLOAT, st.data(), 0, ACL_FORMAT_ND, d.data(), d.size(), p);
}
int main() {
    aclInit(nullptr); aclrtSetDevice(0); const int64_t N = 8; const size_t B = N * 4;
    void *a=nullptr,*b=nullptr,*c=nullptr,*o1=nullptr,*o2=nullptr;
    for (void** q : {&a,&b,&c,&o1,&o2}) aclrtMalloc(q, B, ACL_MEM_MALLOC_HUGE_FIRST);
    std::vector<float> h(N, 1.5f);
    for (void* q : {a,b,c,o1,o2}) aclrtMemcpy(q, B, h.data(), B, ACL_MEMCPY_HOST_TO_DEVICE);
    std::vector<int64_t> d{N}; aclTensor *ta=mk(a,d),*tb=mk(b,d),*tc=mk(c,d),*to1=mk(o1,d),*to2=mk(o2,d),*scT=mk(o1,{1});
    float sv = 2.0f; aclScalar *sc = aclCreateScalar(&sv, ACL_FLOAT), *sa[1] = {sc};
    aclScalarList* SL = aclCreateScalarList(sa, 1);
    std::vector<aclTensor*> vx{ta},vy{tb},vz{tc},v1{to1},v2{to1,to2};
    aclTensorList *LX=aclCreateTensorList(vx.data(),1),*LY=aclCreateTensorList(vy.data(),1);
    aclTensorList *LZ=aclCreateTensorList(vz.data(),1);
    aclTensorList *outs[2] = {aclCreateTensorList(v1.data(),1), aclCreateTensorList(v2.data(),2)};
    const char* nm[] = {"AddcdivList","AddScalarList","AddScalarV2","AddcdivScalar","AddcdivScalarList","AddcdivScalarV2"};
    int miss = 0; printf("interface              out=1   out=2   verdict\n");
    for (int k = 0; k < 6; ++k) {
        int r[2];
        for (int j = 0; j < 2; ++j) {
            uint64_t w = 0; aclOpExecutor* e = nullptr; aclTensorList* o = outs[j];
            if (k == 0) r[j] = (int)aclnnForeachAddcdivListGetWorkspaceSize(LX,LY,LZ,scT,o,&w,&e);
            else if (k == 1) r[j] = (int)aclnnForeachAddScalarListGetWorkspaceSize(LX,SL,o,&w,&e);
            else if (k == 2) r[j] = (int)aclnnForeachAddScalarV2GetWorkspaceSize(LX,sc,o,&w,&e);
            else if (k == 3) r[j] = (int)aclnnForeachAddcdivScalarGetWorkspaceSize(LX,LY,LZ,scT,o,&w,&e);
            else if (k == 4) r[j] = (int)aclnnForeachAddcdivScalarListGetWorkspaceSize(LX,LY,LZ,scT,o,&w,&e);
            else r[j] = (int)aclnnForeachAddcdivScalarV2GetWorkspaceSize(LX,LY,LZ,sc,o,&w,&e);
        }
        if (r[1] == 0) ++miss;
        printf("%-22s %-7d %-7d %s\n", nm[k], r[0], r[1], r[1] == 0 ? "**MISSING CHECK**" : "rejected");
    }
    printf("缺 out 上界校验: %d / 6\n", miss);
    return 0;
}

影响

  • 按资料写「out 每块与 x 同形、多留一块备用 buffer」时,三个接口报错(161001/161002)、
    另三个静默放行;报错文案没有一句指向「块数」,排查会落在 shape/dtype。
  • 静默放行的三个,多给的 out 块不会被写入(预填哨兵后保持哨兵值、接口仍返回 0),
    调用方若以为已填充会读到未初始化数据。按 #7740 需放开三个拒绝接口,否则另三个补 ==。

建议

  1. 六份资料的 out 行统一补「out 含多少个 Tensor」:明确是「必须等于 x」还是「可大于等于」。
  2. 若「必须等于」→ 三个放行接口补 OP_CHECK_TENSORLIST_SIZE_EQUAL;若「可大于等于」→
    三个拒绝接口放开并说明多出的块是否 no-op(不写)。
  3. 161001/161002 段建议补「out 的 Tensor 个数不满足约束」子项。
likedislike
liuhanwen8liuhanwen8
20 days ago Added label: bug-report
east_yang
east_yangCollaborators
20 days ago Comments:

/assign @Tian_1122

likedislike
CANN-robotCANN-robotCollaborators
20 days ago Assign Tian_1122 as responsible person
east_yang
east_yangCollaborators
20 days ago Comments:

/unassign @Tian_1122

likedislike
CANN-robotCANN-robotCollaborators
20 days ago Removed responsible person Tian_1122
east_yang
east_yangCollaborators
20 days ago Comments:

/assign @tramp-ll

likedislike
CANN-robotCANN-robotCollaborators
20 days ago Assign tramp-ll as responsible person
yuning_chenyuning_chenCollaborators
11 days ago Assign east_yang as responsible person, remove original responsible person: tramp-ll
east_yangeast_yangCollaborators
11 days ago Assign Tian_1122 as responsible person
east_yangeast_yangCollaborators
11 days ago Removed responsible person east_yang
tramp-lltramp-llCollaborators
10 days ago Assign tramp-ll as responsible person
tramp-ll
tramp-llCollaborators
10 days ago Comments:

目前均统一为out的tensor个数可以大于等于x的tensor个数

likedislike
Tian_1122Tian_1122Collaborators
6 days ago Deleted associated pull request: fix(foreach): #8272资料补256披露、#8677/#8679/#8680/#8681四个ScalarList转手写支持非连续输出
yuning_chen
yuning_chenCollaborators
6 days ago Comments:

问题成立。空 Tensor 场景被误拒或跳过校验。建议:①numel()==0 且 shape 合法时放行并短路;②错误码统一 ACLNN_ERR_PARAM_INVALID;③补 N=0/H·W=0 UT。

本条要点:关联:7929(同为 foreach 的 out 块数资料缺失;本条差异:7929 只说 AddScalar 的 561002 段缺子项,本条是同族六接口要求不一致 + 六份资料都只约束单块 shape)

likedislike
tramp-ll
tramp-llCollaborators
5 days ago Comments:
likedislike
tramp-lltramp-llCollaborators
5 days ago changed custom state from 进行中 to 已完成
tramp-lltramp-llCollaborators
5 days ago Close issue
Tian_1122Tian_1122Collaborators
5 days ago Deleted associated pull request: fix(foreach): #8272资料补256披露、#8677/#8679/#8680/#8681四个ScalarList转手写支持非连续输出
CANN-robotCANN-robotCollaborators
4 days ago Added label: resolved