Closed
[Bug-Report|缺陷反馈]: aclnnAffineGrid 未校验 size 的 N/H/W 值域,H=0 报 561103、H=100001 执行段抛 507018(资料声明 (0,100000]) #4127
liuhanwen8Add on 17 days agoClosed at 4 days ago
17 days ago Added label: bug-report
xujiachen8
17 days ago Comments:
17 days ago Comments:
您好,感谢提供首段、执行段和同步阶段的完整返回码!核对 master b08e885e7fac370203a51904fd0680523b9a9205,CheckShape 检查 theta 非空、size 长度、batch 对齐以及输出形状,但没有按资料对空间尺寸作显式的正值和 100000 上界检查。这里的前置检查缺口可以确认;不过 N 也受到 theta 非空及 batch 一致性约束,不能推广成所有非法 N 都会放行。
可在公共参数检查中明确 2D 的 N/H/W 范围,并确认 3D 的 D 是否适用相同限制后同步说明,非法组合在创建计算任务前返回 161002。验证应区分 0、负值、100000/100001 边界、2D/3D 以及 out 与 size 自洽和不自洽的情况,并核对 size 转 INT32 与形状乘积的边界。当前是 AICPU 后端,但前置参数缺口不能只归因于设备 kernel。
主贴上界用例的两段接口均返回 0,507018 出现在 aclrtSynchronizeStream,因此报告时需要保留这个阶段差异。561103 与同步异常的具体安装实现来源仍待定位;本轮没有独立上板复跑,尚未修复或确认目标版本全部错误路径。
核对依据:aclnnAffineGrid.md;aclnn_affine_grid.cpp;affine_grid.cpp。


17 days ago Assign liu-wei as responsible person
17 days ago Added label: pending-confirmation
16 days ago Removed label: pending-confirmation
15 days ago Removed responsible person liu-wei
15 days ago Assign chen_0715 as responsible person
15 days ago Added label: pending-confirmation
15 days ago Assign gcw_SUaZx3UQ as responsible person
15 days ago Removed responsible person chen_0715
11 days ago Associated pull request
Zzhangqijia1
10 days ago Deleted associated pull request: fix(affine-grid): validate size values before dispatch
10 days ago Deleted associated pull request: fix(affine-grid): validate size values before dispatch
10 days ago Associated pull request
Zzhangqijia1
10 days ago Deleted associated pull request: fix(affine-grid): validate size values before dispatch
10 days ago Deleted associated pull request: fix(affine-grid): validate size values before dispatch
4 days ago Close issue
4 days ago changed custom state from 进行中 to 已完成
4 days ago Added label: resolved
环境
Ascend-cann-toolkit_9.2.0+Ascend-cann-910b-ops_9.2.0),Linux aarch64,g++ 13cann/ops-math,git fetch origin master后git rev-parse --short FETCH_HEAD=68d145576(2026-10-27 21:02 +0800)
math/affine_grid/op_api/aclnn_affine_grid.cpp:78CheckShapemath/affine_grid/docs/aclnnAffineGrid.md:236「size 中的 N、H、W 的取值必须在 (0, 100000] 的取值范围内」现象
CheckShape只校验了 theta 的 rank、theta 与 size 的形状一致性、out 与 size 推导形状的一致性,对
size里 N/H/W 的取值一条都没查(下界、上界都没有)。越界值因此穿过第一段校验,落到资料错误码表没有声明的内部错误码上:
H=0(out 形状自洽)ACLNN_ERR_INNER_NULLPTR)W=0/ 3DD=0H=100001(超上界)aclrtSynchronizeStream507018(ACL_ERROR_RT_AICPU_EXCEPTION)上界那条最危险:第一段返回 0,调用方会认为参数合法,失败被推迟到执行段的 AICPU 异常。
561103 / 507018 均不在资料错误码表(161001、161002)中,无法按错误码分支处理。
复现步骤
## 复现脚本里的repro.cpp存盘;g++ -O2 repro.cpp -o repro -I${ASCEND_HOME_PATH}/include -L${ASCEND_HOME_PATH}/lib64 -lascendcl -lnnopbase -lopapi./repro(默认 device 0,可用ASCEND_RT_VISIBLE_DEVICES指定)H=0、CH=100001复现脚本
#include <cstdio> #include <vector> #include "acl/acl.h" #include "aclnnop/aclnn_affine_grid.h" static aclTensor* T(std::vector<int64_t> sh, void** p) { size_t n = 4; for (auto d : sh) n *= d; if (!n) n = 4; aclrtMalloc(p, n, ACL_MEM_MALLOC_HUGE_FIRST); std::vector<float> h(n / 4, 0.5f); aclrtMemcpy(*p, n, h.data(), n, ACL_MEMCPY_HOST_TO_DEVICE); std::vector<int64_t> st(sh.size(), 1); for (int i = (int)sh.size() - 2; i >= 0; --i) st[i] = sh[i + 1] * st[i + 1]; return aclCreateTensor(sh.data(), sh.size(), ACL_FLOAT, st.data(), 0, ACL_FORMAT_ND, sh.data(), sh.size(), *p); } static void Run(const char* tag, std::vector<int64_t> th, std::vector<int64_t> size, std::vector<int64_t> os, aclrtStream s) { void *td = nullptr, *od = nullptr; aclTensor* theta = T(th, &td); aclTensor* out = T(os, &od); aclIntArray* sz = aclCreateIntArray(size.data(), size.size()); uint64_t ws = 0; aclOpExecutor* ex = nullptr; int r1 = aclnnAffineGridGetWorkspaceSize(theta, sz, false, out, &ws, &ex); int r2 = -1, r3 = -1; if (r1 == 0) { void* w = nullptr; if (ws) aclrtMalloc(&w, ws, ACL_MEM_MALLOC_HUGE_FIRST); r2 = aclnnAffineGrid(w, ws, ex, s); r3 = aclrtSynchronizeStream(s); if (w) aclrtFree(w); } printf("%-12s ret1=%d ret2=%d sync=%d\n", tag, r1, r2, r3); fflush(stdout); aclDestroyTensor(theta); aclDestroyTensor(out); aclDestroyIntArray(sz); aclrtFree(td); aclrtFree(od); } int main() { aclInit(nullptr); aclrtSetDevice(0); aclrtStream s = nullptr; aclrtCreateStream(&s); Run("A-valid", {1, 2, 3}, {1, 1, 2, 3}, {1, 2, 3, 2}, s); Run("B-H0", {1, 2, 3}, {1, 1, 0, 3}, {1, 0, 3, 2}, s); Run("C-H100001", {1, 2, 3}, {1, 1, 100001, 1}, {1, 100001, 1, 2}, s); aclrtDestroyStream(s); aclrtResetDevice(0); aclFinalize(); return 0; }实测输出(三次执行一致):
期望
H=0/W=0/ 3DD=0/H=100001都在第一段返回 161002(ACLNN_ERR_PARAM_INVALID),与资料
(0, 100000]对齐;影响
以第一段返回码做参数校验的调用方会把越界
size判成合法(尤其上界那条 ret1=0),失败延迟到执行段以 AICPU 异常暴露;AICPU 异常会污染该 stream 上的任务序列,
上层只能看到设备侧错误,无法定位到「size 传大了」这个真实原因。
建议
在
CheckShape里对size的 N/H/W(3D 再含 D)加显式值域判断(
> 0 && <= 100000),不满足返回ACLNN_ERR_PARAM_INVALID;补 UT 覆盖H=0 / W=0 / D=0 / H=100001 / N=0 五条边界。
同仓同族参考(接口与 kernel 分支均不同,不合并):#3998(aclnnRepeat 超维报 561103)、
#4111(aclnnFloorDivide 除零 507018)。