Closed
[Bug-Report|缺陷反馈]: aclnnSquaredRelu 放行非连续 out 且忽略 strides 导致输出静默错位 #7757
liuhanwen8Add on 23 days agoClosed at 18 days ago
23 days ago Added label: bug-report
23 days ago Modify description of issue
23 days ago Assign east_yang as responsible person
yuning_chen
23 days ago Comments:
23 days ago Comments:
yuning_chen
23 days ago Comments:
23 days ago Comments:
您好,该问题已收到,当前问题 @east_yang 正在处理中


east_yang
19 days ago Comments:
19 days ago Comments:
/unassign @east_yang


19 days ago Removed responsible person east_yang
east_yang
19 days ago Comments:
19 days ago Comments:
/assign @guijianwei


19 days ago Assign guijianwei as responsible person
18 days ago Associated pull request
18 days ago Close issue
17 days ago Added label: resolved
aclnnSquaredRelu 放行非连续 out 且忽略 strides,输出静默错位
现象
out传非连续张量(shape[2,4]、strides[8,1],底层 storage[2,8])时,第一段接口返回 0,内核按连续内存写入 8 个结果,而按 out 的逻辑 stride 读回时第二行仍是初始化哨兵值:8 个逻辑元素里有 4 个没有被写到。实测输出:
期望
资料
activation/squared_relu/docs/aclnnSquaredRelu.md参数表中out的「非连续Tensor」列标注为×。既然不支持,第一段就应返回161002拒绝;若要支持,则必须按 out 的 strides 写入。当前既不拒绝、也不按 stride 写,调用方拿到的是静默错值。环境
cann/ops-nnmaster59c0720cactivation/squared_relu/docs/aclnnSquaredRelu.md复现步骤
repro.cpp。g++ -O2 -std=c++17 repro.cpp -o repro -I$ASCEND_HOME_PATH/include -L$ASCEND_HOME_PATH/lib64 -lascendcl -lnnopbase -lopapi_nn -lopapi_math。ASCEND_RT_VISIBLE_DEVICES=0 ./repro。复现脚本
#include <cmath> #include <cstdio> #include <vector> #include "acl/acl.h" #include "aclnnop/aclnn_squared_relu.h" static const float SENT = -12345.0f; static void *Dev(const std::vector<float> &v) { void *p = nullptr; aclrtMalloc(&p, v.size() * sizeof(float), ACL_MEM_MALLOC_HUGE_FIRST); aclrtMemcpy(p, v.size() * sizeof(float), v.data(), v.size() * sizeof(float), ACL_MEMCPY_HOST_TO_DEVICE); return p; } // outShape=[2,4],outStrides 由调用方给;storage 恒为 [2,8](16 个 float) static void Run(const char *tag, std::vector<int64_t> outStrides, aclrtStream stream) { std::vector<int64_t> shape = {2, 4}; std::vector<int64_t> storage = {2, 8}; std::vector<float> inVals = {1, -2, 3, -4, 5, -6, 7, -8}; std::vector<float> outVals(16, SENT); void *iPtr = Dev(inVals), *oPtr = Dev(outVals); aclTensor *in = aclCreateTensor(shape.data(), 2, ACL_FLOAT, (std::vector<int64_t>{4, 1}).data(), 0, ACL_FORMAT_ND, shape.data(), 2, iPtr); aclTensor *out = aclCreateTensor(shape.data(), 2, ACL_FLOAT, outStrides.data(), 0, ACL_FORMAT_ND, storage.data(), 2, oPtr); uint64_t ws = 0; aclOpExecutor *exec = nullptr; int ret = aclnnSquaredReluGetWorkspaceSize(in, out, &ws, &exec); if (ret == 0) { void *w = nullptr; if (ws > 0) aclrtMalloc(&w, ws, ACL_MEM_MALLOC_HUGE_FIRST); ret = aclnnSquaredRelu(w, ws, exec, stream); if (ret == 0) aclrtSynchronizeStream(stream); if (w) aclrtFree(w); } std::vector<float> back(16, 0.0f); aclrtMemcpy(back.data(), 64, oPtr, 64, ACL_MEMCPY_DEVICE_TO_HOST); int wrong = 0; for (int r = 0; r < 2; ++r) { for (int c = 0; c < 4; ++c) { float want = inVals[r * 4 + c] > 0 ? inVals[r * 4 + c] * inVals[r * 4 + c] : 0.0f; if (std::fabs(back[r * outStrides[0] + c * outStrides[1]] - want) > 1e-3) ++wrong; } } std::printf("%s return code = %d\n", tag, ret); std::printf("%s wrong elements in logical view = %d\n", tag, wrong); aclDestroyTensor(in); aclDestroyTensor(out); aclrtFree(iPtr); aclrtFree(oPtr); } int main() { aclInit(nullptr); aclrtSetDevice(0); aclrtStream stream = nullptr; aclrtCreateStream(&stream); Run("CTRL ", {4, 1}, stream); // 连续 out:[2,4] 紧凑 Run("DEFECT", {8, 1}, stream); // 非连续 out:行间隔 8(资料标 ×,应拒绝) aclrtDestroyStream(stream); aclrtResetDevice(0); aclFinalize(); return 0; }影响
框架侧把
out传成视图(切片、转置后 buffer、narrow结果)时很常见;此时算子返回成功但结果错位,误差被后续层放大,且没有任何告警。数据静默错误比报错更难排查。建议
在
out的校验里补连续性检查:非连续时返回161002(与资料×对齐);如果产品上确实要支持非连续 out,则 kernel 侧按 out 的 strides 写,并补一条覆盖该形态的 UT/ST。