Merged
foreach 解决ISSUE问题 #14276
tramp-llAdd on 10 days ago
foreach 解决ISSUE问题 #14276
Merged
tramp-llAdd on 10 days ago
Total: 22 files changed+250-29
@@ -107,7 +107,7 @@ aclnnStatus aclnnForeachAddScalar(
107 <td>out(aclTensorList*)</td>107 <td>out(aclTensorList*)</td>
108 <td>输出</td>108 <td>输出</td>
109 <td>表示加法运算的输出张量列表。对应公式中的`y`。</td>109 <td>表示加法运算的输出张量列表。对应公式中的`y`。</td>
110- <td><ul><li>支持空Tensor。</li><li>该参数中所有Tensor的数据类型保持一致。</li><li>数据类型和数据格式与入参`x`的数据类型和数据格式一致,shape size大于等于入参`x`的shape size。</li></ul></td>110+ <td><ul><li>支持空Tensor。</li><li>该参数中所有Tensor的数据类型保持一致。</li><li>数据类型和数据格式与入参`x`的数据类型和数据格式一致,shape size大于等于入参`x`的shape size,out与x的tensorList长度需满足一定约束关系,参见<a href="#约束说明"> 约束说明</a>。</li></ul></td>
111 <td>FLOAT32、FLOAT16、BFLOAT16、INT32、INT16、INT8、UINT8</td>111 <td>FLOAT32、FLOAT16、BFLOAT16、INT32、INT16、INT8、UINT8</td>
112 <td>ND</td>112 <td>ND</td>
113 <td>0-8</td>113 <td>0-8</td>
@@ -187,7 +187,7 @@ aclnnStatus aclnnForeachAddScalar(
187 <td>x和out的数据类型不一致。</td>187 <td>x和out的数据类型不一致。</td>
188 </tr>188 </tr>
189 <tr>189 <tr>
190- <td>x与out的tensorList长度(包含的Tensor个数)不一致。</td>190+ <td>x的tensorList长度(包含的Tensor个数)大于out的tensorList长度(包含的Tensor个数)。</td>
gitee-duhuiping
gitee-duhuipinggitee-duhuiping9 days ago

如果不同产品的约束不一样,建议这个改一下,没有包含A5的报错

likedislike
191 </tr>191 </tr>
192 <tr>192 <tr>
193 <td rowspan="4">ACLNN_ERR_INNER_TILING_ERROR</td>193 <td rowspan="4">ACLNN_ERR_INNER_TILING_ERROR</td>
@@ -205,6 +205,13 @@ aclnnStatus aclnnForeachAddScalar(
205 </tr>205 </tr>
206 </tbody></table>206 </tbody></table>
207 207 
208+ <!-- npu="950" id13 -->
209+ > 说明:
210+ >
211+ > <term>Ascend 950PR&950DT系列产品</term>:x的tensorList长度(包含的Tensor个数)小于out的tensorList长度(包含的Tensor个数),报错的返回码和错误码分别为:'ACLNN_ERR_INNER_TILING_ERROR 和 561002'。
212+ 
213+ <!-- end id13 -->
214+ 
208## aclnnForeachAddScalar215## aclnnForeachAddScalar
209 216 
210- **参数说明**217- **参数说明**
@@ -252,6 +259,16 @@ aclnnStatus aclnnForeachAddScalar(
252 259 
253- 确定性计算:260- 确定性计算:
254 - aclnnForeachAddScalar默认确定性实现。261 - aclnnForeachAddScalar默认确定性实现。
262+- 不同产品中out与x的tensorList长度约束关系如下:
263+ <!-- npu="A3,910b" id10 -->
264+ - <term>Atlas A2系列产品</term>、<term>Atlas A3系列产品</term>:
265+ out的tensorList长度(包含的Tensor个数)需大于等于x的tensorList长度(包含的Tensor个数)。
266+ <!-- end id10 -->
267+ 
268+ <!-- npu="950" id11 -->
269+ - <term>Ascend 950PR&950DT系列产品</term>:
270+ x与out的tensorList长度(包含的Tensor个数)需一致。
271+ <!-- end id11 -->
255 272 
256## 调用示例273## 调用示例
257 274 
@@ -105,7 +105,7 @@ aclnnStatus aclnnForeachAddScalarV2(
105 <td>out(aclTensorList*)</td>105 <td>out(aclTensorList*)</td>
106 <td>输出</td>106 <td>输出</td>
107 <td>表示加法运算的输出张量列表,对应公式中的`y`。</td>107 <td>表示加法运算的输出张量列表,对应公式中的`y`。</td>
108- <td><ul><li>支持空Tensor。</li><li>该参数中所有Tensor的数据类型保持一致。</li><li>数据类型和数据格式与入参`x`的数据类型和数据格式一致,shape size大于等于入参`x`的shape size。</li></ul></td>108+ <td><ul><li>支持空Tensor。</li><li>该参数中所有Tensor的数据类型保持一致。</li><li>数据类型和数据格式与入参`x`的数据类型和数据格式一致,shape size大于等于入参`x`的shape size,out与x的tensorList长度需满足一定约束关系,参见<a href="#约束说明"> 约束说明</a>。</li></ul></td>
109 <td>FLOAT32、FLOAT16、BFLOAT16、INT32、INT16、INT8、UINT8</td>109 <td>FLOAT32、FLOAT16、BFLOAT16、INT32、INT16、INT8、UINT8</td>
110 <td>ND</td>110 <td>ND</td>
111 <td>0-8</td>111 <td>0-8</td>
@@ -196,10 +196,17 @@ aclnnStatus aclnnForeachAddScalarV2(
196 <td>x或out中的Tensor维度超过8维。</td>196 <td>x或out中的Tensor维度超过8维。</td>
197 </tr>197 </tr>
198 <tr>198 <tr>
199- <td>x与out的tensorList长度(包含的Tensor个数)不一致。</td>199+ <td>x的tensorList长度(包含的Tensor个数)大于out的tensorList长度(包含的Tensor个数)。</td>
200 </tr>200 </tr>
201 </tbody></table>201 </tbody></table>
202 202 
203+ <!-- npu="950" id13 -->
204+ > 说明:
205+ >
206+ > <term>Ascend 950PR&950DT系列产品</term>:x的tensorList长度(包含的Tensor个数)小于out的tensorList长度(包含的Tensor个数),报错的返回码和错误码分别为:'ACLNN_ERR_INNER_TILING_ERROR 和 561002'。
207+ 
208+ <!-- end id13 -->
209+ 
203## aclnnForeachAddScalarV2210## aclnnForeachAddScalarV2
204 211 
205- **参数说明**212- **参数说明**
@@ -247,6 +254,16 @@ aclnnStatus aclnnForeachAddScalarV2(
247 254 
248- 确定性计算:255- 确定性计算:
249 - aclnnForeachAddScalarV2默认确定性实现。256 - aclnnForeachAddScalarV2默认确定性实现。
257+- 不同产品中out与x的tensorList长度约束关系如下:
258+ <!-- npu="A3,910b" id10 -->
259+ - <term>Atlas A2系列产品</term>、<term>Atlas A3系列产品</term>:
260+ out的tensorList长度(包含的Tensor个数)需大于等于x的tensorList长度(包含的Tensor个数)。
261+ <!-- end id10 -->
262+ 
263+ <!-- npu="950" id11 -->
264+ - <term>Ascend 950PR&950DT系列产品</term>
265+ x与out的tensorList长度(包含的Tensor个数)需一致。
266+ <!-- end id11 -->
250 267 
251## 调用示例268## 调用示例
252 269 
@@ -119,8 +119,13 @@ static inline bool ForeachAddScalarCheckDtypeValid(const aclTensorList* self, co
119 119 
120static inline bool ForeachAddScalarCheckShape(const aclTensorList* self, const aclTensorList* out)120static inline bool ForeachAddScalarCheckShape(const aclTensorList* self, const aclTensorList* out)
121{121{
122- // tensorlist size检查122+ // x 与 out 的 tensor 个数:要求 x->Size() <= out->Size(),多传放行、少传拒绝
123- OP_CHECK_TENSORLIST_SIZE_EQUAL(self, out, return false);123+ if (self->Size() > out->Size()) {
124+ const std::string reason = (std::string("The tensor nums in {x, out} must satisfy x <= out, but got x=") +
125+ std::to_string(self->Size()) + ", out=" + std::to_string(out->Size()));
126+ OP_LOGE_WITHOUT_REPORT(ACLNN_ERR_PARAM_INVALID, "%s", reason.c_str());
127+ return false;
128+ }
atomgit-bot
atomgit-botatomgit-bot10 days ago

🟡 Medium Priority

变更行:ForeachAddScalarCheckShape 把 OP_CHECK_TENSORLIST_SIZE_EQUAL(self, out, ...) 改成 if (self->Size() > out->Size())(aclnn_foreach_add_scalar.cpp:122-128,同样的改动在 aclnn_foreach_add_scalar_v2.cpp:154-160),即允许 out 列表比 x 长。

受影响契约:ExecForeachAddScalarGetWorkspaceSize 把整个 contiguousOut(长度 = out->Size())原样传给 l0op ForeachAddScalarV2,而 l0op 直接 ADD_TO_LAUNCHER_LIST_AICORE(ForeachAddScalar, OP_INPUT(x, scalar), OP_OUTPUT(out))(foreach_add_scalar_v2.cpp:31),列表长度原封不动进入算子实例信息。算子侧 tiling 明确要求 x/y 实例数相等:ForeachRegbaseTiling::CheckOutput() 中 OP_CHECK_IF(totalTensorCount_ != outputCount, ... "The tensor nums in {x, y} must be the same") 返回 GRAPH_FAILED(foreach/foreach_utils/op_host/foreach_regbase_tiling.cpp:491-496)。

失效模式:用户按新放行的用法传入 out->Size() > x->Size() 时,第一段 GetWorkspaceSize 校验通过(成功返回),失败被推迟到执行阶段/tiling 阶段,以 GRAPH_FAILED→内部 tiling 错误暴露,而不是原先干净的首阶段 ACLNN_ERR_PARAM_INVALID;即便某设备路径未做该 tiling 校验,kernel 是按 x 下标逐成员写 y 的(参考 foreach_maximum_scalar_list tiling 注释“Kernel 按 x 的 count 写 y”),多出的 out 成员永远不会被计算,用户读到的是未初始化/陈旧数据。也就是说本次“多传放行”在算子侧并不成立。

likedislike
Incorrect?
124 // tensor 维度检查129 // tensor 维度检查
125 for (uint64_t i = 0; i < self->Size(); i++) {130 for (uint64_t i = 0; i < self->Size(); i++) {
126 OP_CHECK_MAX_DIM((*self)[i], MAX_SUPPORT_DIMS_NUMS, return false);131 OP_CHECK_MAX_DIM((*self)[i], MAX_SUPPORT_DIMS_NUMS, return false);
@@ -151,8 +151,13 @@ static inline bool ForeachAddScalarV2CheckDtypeValid(const aclTensorList* self,
151 151 
152static inline bool ForeachAddScalarV2CheckShape(const aclTensorList* self, const aclTensorList* out)152static inline bool ForeachAddScalarV2CheckShape(const aclTensorList* self, const aclTensorList* out)
153{153{
154- // tensorlist size检查154+ // x 与 out 的 tensor 个数:要求 x->Size() <= out->Size(),多传放行、少传拒绝
155- OP_CHECK_TENSORLIST_SIZE_EQUAL(self, out, return false);155+ if (self->Size() > out->Size()) {
156+ const std::string reason = (std::string("The tensor nums in {x, out} must satisfy x <= out, but got x=") +
157+ std::to_string(self->Size()) + ", out=" + std::to_string(out->Size()));
158+ OP_LOGE_WITHOUT_REPORT(ACLNN_ERR_PARAM_INVALID, "%s", reason.c_str());
159+ return false;
160+ }
156 // tensor 维度检查161 // tensor 维度检查
157 for (uint64_t i = 0; i < self->Size(); i++) {162 for (uint64_t i = 0; i < self->Size(); i++) {
158 OP_CHECK_MAX_DIM((*self)[i], MAX_SUPPORT_DIMS_NUMS, return false);163 OP_CHECK_MAX_DIM((*self)[i], MAX_SUPPORT_DIMS_NUMS, return false);
@@ -108,7 +108,7 @@ aclnnStatus aclnnForeachAddScalarList(
108 <td>out(aclTensorList*)</td>108 <td>out(aclTensorList*)</td>
109 <td>输出</td>109 <td>输出</td>
110 <td>表示进行加法运算的输出张量列表。对应公式中的`y`。</td>110 <td>表示进行加法运算的输出张量列表。对应公式中的`y`。</td>
111- <td><ul><li>支持空Tensor。</li><li>该参数中所有Tensor的数据类型保持一致。</li><li>数据类型和数据格式与入参`x`的数据类型和数据格式一致,shape size大于等于入参`x`的shape size。</li></ul></td>111+ <td><ul><li>支持空Tensor。</li><li>该参数中所有Tensor的数据类型保持一致。</li><li>数据类型和数据格式与入参`x`的数据类型和数据格式一致,shape size大于等于入参`x`的shape size,out与x的tensorList长度需满足一定约束关系,参见<a href="#约束说明"> 约束说明</a>。</li></ul></td>
112 <td>FLOAT32、FLOAT16、BFLOAT16、INT32</td>112 <td>FLOAT32、FLOAT16、BFLOAT16、INT32</td>
113 <td>ND</td>113 <td>ND</td>
114 <td>0-8</td>114 <td>0-8</td>
@@ -180,8 +180,24 @@ aclnnStatus aclnnForeachAddScalarList(
180 <tr>180 <tr>
181 <td>x或out中的Tensor维度超过8维。</td>181 <td>x或out中的Tensor维度超过8维。</td>
182 </tr>182 </tr>
183+ <tr>
184+ <td>out与x的tensorList长度不满足约束关系。</td>
185+ </tr>
183 </tbody></table>186 </tbody></table>
184 187 
188+ <!-- npu="950" id13 -->
189+ > 说明:
190+ >
191+ > <term>Ascend 950PR&950DT系列产品</term>:x与out的tensorList长度(包含的Tensor个数)不一致,报错的返回码和错误码分别为:'ACLNN_ERR_INNER_TILING_ERROR 和 561002'。
192+ 
193+ <!-- end id13 -->
194+ 
195+ <!-- npu="A3,910b" id14 -->
196+ > 说明:
197+ >
198+ > <term>Atlas A2系列产品</term>、<term>Atlas A3系列产品</term>:x的tensorList长度(包含的Tensor个数)大于out的tensorList长度(包含的Tensor个数),报错的返回码和错误码分别为:'ACLNN_ERR_INNER_TILING_ERROR 和 561002'。
199+ <!-- end id14 -->
200+ 
185## aclnnForeachAddScalarList201## aclnnForeachAddScalarList
186 202 
187- **参数说明**203- **参数说明**
@@ -229,6 +245,16 @@ aclnnStatus aclnnForeachAddScalarList(
229 245 
230- 确定性计算:246- 确定性计算:
231 - aclnnForeachAddScalarList默认确定性实现。247 - aclnnForeachAddScalarList默认确定性实现。
248+- 不同产品中out与x的tensorList长度约束关系如下:
249+ <!-- npu="A3,910b" id10 -->
250+ - <term>Atlas A2系列产品</term>、<term>Atlas A3系列产品</term>:
251+ out的tensorList长度(包含的Tensor个数)需大于等于x的tensorList长度(包含的Tensor个数)。
252+ <!-- end id10 -->
253+ 
254+ <!-- npu="950" id11 -->
255+ - <term>Ascend 950PR&950DT系列产品</term>
256+ x与out的tensorList长度(包含的Tensor个数)需一致。
257+ <!-- end id11 -->
232 258 
233## 调用示例259## 调用示例
234 260 
@@ -128,7 +128,7 @@ aclnnStatus aclnnForeachAddcdivList(
128 <td>out(aclTensorList*)</td>128 <td>out(aclTensorList*)</td>
129 <td>输出</td>129 <td>输出</td>
130 <td>表示混合运算的输出张量列表。对应公式中的`y`。</td>130 <td>表示混合运算的输出张量列表。对应公式中的`y`。</td>
131- <td><ul><li>支持空Tensor。</li><li>该参数中所有Tensor的数据类型保持一致。</li><li>数据类型和数据格式与入参`x1`的数据类型和数据格式一致,shape size大于等于入参`x1`的shape size。</li></ul></td>131+ <td><ul><li>支持空Tensor。</li><li>该参数中所有Tensor的数据类型保持一致。</li><li>数据类型和数据格式与入参`x1`的数据类型和数据格式一致,shape size大于等于入参`x1`的shape size,out与x1的tensorList长度需满足一定约束关系,参见<a href="#约束说明"> 约束说明</a>。</li></ul></td>
132 <td>FLOAT32、FLOAT16、BFLOAT16</td>132 <td>FLOAT32、FLOAT16、BFLOAT16</td>
133 <td>ND</td>133 <td>ND</td>
134 <td>0-8</td>134 <td>0-8</td>
@@ -206,11 +206,27 @@ aclnnStatus aclnnForeachAddcdivList(
206 <tr>206 <tr>
207 <td>scalars的元素个数与x1的Tensor数量不一致。</td>207 <td>scalars的元素个数与x1的Tensor数量不一致。</td>
208 </tr>208 </tr>
209+ <tr>
210+ <td>out的与x1的Tensor数量不满足约束关系。</td>
211+ </tr>
209 <tr>212 <tr>
210 <td>scalars维度超过8维。</td>213 <td>scalars维度超过8维。</td>
211 </tr>214 </tr>
212 </tbody></table>215 </tbody></table>
213 216 
217+ <!-- npu="950" id13 -->
218+ > 说明:
219+ >
220+ > <term>Ascend 950PR&950DT系列产品</term>:x与out的tensorList长度(包含的Tensor个数)不一致,报错的返回码和错误码分别为:'ACLNN_ERR_INNER_TILING_ERROR 和 561002'。
221+ 
222+ <!-- end id13 -->
223+ 
224+ <!-- npu="A3,910b" id14 -->
225+ > 说明:
226+ >
227+ > <term>Atlas A2系列产品</term>、<term>Atlas A3系列产品</term>:x的tensorList长度(包含的Tensor个数)大于out的tensorList长度(包含的Tensor个数),报错的返回码和错误码分别为:'ACLNN_ERR_INNER_TILING_ERROR 和 561002'。
228+ <!-- end id14 -->
229+ 
214## aclnnForeachAddcdivList230## aclnnForeachAddcdivList
215 231 
216- **参数说明**232- **参数说明**
@@ -258,6 +274,16 @@ aclnnStatus aclnnForeachAddcdivList(
258 274 
259- 确定性计算:275- 确定性计算:
260 - aclnnForeachAddcdivList默认确定性实现。276 - aclnnForeachAddcdivList默认确定性实现。
277+- 不同产品中out与x1的tensorList长度约束关系如下:
278+ <!-- npu="A3,910b" id10 -->
279+ - <term>Atlas A2系列产品</term>、<term>Atlas A3系列产品</term>:
280+ out的tensorList长度(包含的Tensor个数)需大于等于x1的tensorList长度(包含的Tensor个数)。
281+ <!-- end id10 -->
282+ 
283+ <!-- npu="950" id11 -->
284+ - <term>Ascend 950PR&950DT系列产品</term>
285+ x1与out的tensorList长度(包含的Tensor个数)需一致。
286+ <!-- end id11 -->
261 287 
262## 调用示例288## 调用示例
263 289 
@@ -252,7 +252,7 @@ aclnnStatus aclnnForeachAddcdivScalar(
252 252 
253## 约束说明253## 约束说明
254 254 
255-- `x1`、`x2`、`x3`、`out`的Tensor列表长度必须一致,单个Tensor列表中Tensor的数量不超过256个。255+- `x1`、`x2`、`x3`的Tensor列表长度必须一致,`out`的Tensor数量必须大于等于`x1`的tensor数量, 单个Tensor列表中Tensor的数量不超过256个。
256- 确定性计算:256- 确定性计算:
257 - aclnnForeachAddcdivScalar默认确定性实现。257 - aclnnForeachAddcdivScalar默认确定性实现。
258 258 
@@ -251,7 +251,7 @@ aclnnStatus aclnnForeachAddcdivScalarV2(
251 251 
252## 约束说明252## 约束说明
253 253 
254-- `x1`、`x2`、`x3`、`out`的Tensor列表长度必须一致,单个Tensor列表中Tensor的数量不超过256个。254+- `x1`、`x2`、`x3`的Tensor列表长度必须一致,`out`的Tensor数量必须大于等于`x1`的tensor数量,单个Tensor列表中Tensor的数量不超过256个。
255- 确定性计算:255- 确定性计算:
256 - aclnnForeachAddcdivScalarV2默认确定性实现。256 - aclnnForeachAddcdivScalarV2默认确定性实现。
257 257 
@@ -146,11 +146,11 @@ static inline bool CheckScalar(const aclTensor* scalar)
146static inline bool CheckShape(const aclTensorList* x1, const aclTensorList* x2, const aclTensorList* x3,146static inline bool CheckShape(const aclTensorList* x1, const aclTensorList* x2, const aclTensorList* x3,
147 const aclTensorList* out)147 const aclTensorList* out)
148{148{
149- if (x1->Size() != x2->Size() || x1->Size() != x3->Size() || x1->Size() != out->Size()) {149+ if (x1->Size() != x2->Size() || x1->Size() != x3->Size()) {
150 const bool x2Mismatch = x1->Size() != x2->Size();150 const bool x2Mismatch = x1->Size() != x2->Size();
151 const bool x3Mismatch = x1->Size() != x3->Size();151 const bool x3Mismatch = x1->Size() != x3->Size();
152- const char* parameter = x2Mismatch ? "x2" : (x3Mismatch ? "x3" : "out");152+ const char* parameter = x2Mismatch ? "x2" : "x3";
153- const auto actualSize = x2Mismatch ? x2->Size() : (x3Mismatch ? x3->Size() : out->Size());153+ const auto actualSize = x2Mismatch ? x2->Size() : x3->Size();
154 const std::string reason = (("Tensor lists must have the same number of tensors; x2=" +154 const std::string reason = (("Tensor lists must have the same number of tensors; x2=" +
155 std::to_string(x2->Size()) + ", x1=" + std::to_string(x1->Size()) + ", x3=" +155 std::to_string(x2->Size()) + ", x1=" + std::to_string(x1->Size()) + ", x3=" +
156 std::to_string(x3->Size()) + ", out=" + std::to_string(out->Size()) + "."));156 std::to_string(x3->Size()) + ", out=" + std::to_string(out->Size()) + "."));
@@ -162,6 +162,17 @@ static inline bool CheckShape(const aclTensorList* x1, const aclTensorList* x2,
162 return false;162 return false;
163 }163 }
164 164 
165+ // x 与 out 的 tensor 个数:要求 x->Size() <= out->Size(),多传放行、少传拒绝
166+ if (x1->Size() > out->Size()) {
167+ const std::string reason = (std::string("The tensor nums in {x, out} must satisfy x <= out, but got x=") +
168+ std::to_string(x1->Size()) + ", out=" + std::to_string(out->Size()));
169+ OP_LOGE_WITHOUT_REPORT(ACLNN_ERR_PARAM_INVALID, "%s", reason.c_str());
170+ REPORT_PREDEFINED_ERR_MSG("EZ0038",
171+ (std::vector<const char*>{"param_name", "op_name", "incorrect_size", "reason"}),
172+ (std::vector<const char*>{"out", "aclnnForeachAddcdivScalar",
173+ (std::to_string(out->Size())).c_str(), reason.c_str()}));
174+ return false;
175+ }
165 for (uint64_t i = 0; i < x1->Size(); i++) {176 for (uint64_t i = 0; i < x1->Size(); i++) {
166 OP_CHECK_SHAPE_NOT_EQUAL((*x1)[i], (*out)[i], return false);177 OP_CHECK_SHAPE_NOT_EQUAL((*x1)[i], (*out)[i], return false);
167 }178 }
@@ -166,10 +166,10 @@ static inline bool ForeachAddcdivScalarV2CheckShape(const aclTensorList* self, c
166 return false;166 return false;
167 }167 }
168 168 
169- // tensorlist size检查169+ // x 与 out 的 tensor 个数:要求 x->Size() <= out->Size(),多传放行、少传拒绝
170- if (self->Size() != out->Size()) {170+ if (self->Size() > out->Size()) {
171- const std::string reason = (("Tensor lists must have the same number of tensors, got " +171+ const std::string reason = (std::string("The tensor nums in {x, out} must satisfy x <= out, but got x=") +
172- std::to_string(self->Size()) + " and " + std::to_string(out->Size())));172+ std::to_string(self->Size()) + ", out=" + std::to_string(out->Size()));
173 OP_LOGE_WITHOUT_REPORT(ACLNN_ERR_PARAM_INVALID, "%s", reason.c_str());173 OP_LOGE_WITHOUT_REPORT(ACLNN_ERR_PARAM_INVALID, "%s", reason.c_str());
174 REPORT_PREDEFINED_ERR_MSG("EZ0038",174 REPORT_PREDEFINED_ERR_MSG("EZ0038",
175 (std::vector<const char*>{"param_name", "op_name", "incorrect_size", "reason"}),175 (std::vector<const char*>{"param_name", "op_name", "incorrect_size", "reason"}),
@@ -177,7 +177,6 @@ static inline bool ForeachAddcdivScalarV2CheckShape(const aclTensorList* self, c
177 (std::to_string(out->Size())).c_str(), reason.c_str()}));177 (std::to_string(out->Size())).c_str(), reason.c_str()}));
178 return false;178 return false;
179 }179 }
atomgit-bot
atomgit-botatomgit-bot10 days ago

🟡 Medium Priority

变更行:ForeachAddcdivScalarV2CheckShape 由 self->Size() != out->Size() 改为 self->Size() > out->Size(),允许 out 列表更长(aclnn_foreach_addcdiv_scalar_v2.cpp:169-179;aclnn_foreach_addcdiv_scalar.cpp:165-175 的 CheckShape 同样放宽)。

受影响契约:本算子自身的 tiling 明确要求输出实例数与 x1 实例数相等——foreach/foreach_addcdiv_scalar/op_host/arch35/foreach_addcdiv_scalar_tiling_arch35.cpp:174-177: OP_CHECK_IF(context->GetComputeNodeOutputNum() != tensorNum, OP_LOGE(context, "The tensor num of output y is %zu, which is not equal to that of x1 %lu.", ...), return ge::GRAPH_FAILED); 而 aclnn 侧把完整 out 列表透传给 l0op(OP_OUTPUT(contiguousOut)),长度差异会原样进入 tiling。

失效模式:out->Size() > x1->Size() 的用例现在通过了 *GetWorkspaceSize,随后在 tiling 阶段 GRAPH_FAILED,用户拿到的不是参数错误而是内部错误(且此时连续化/ViewCopy 图已部分构建);此外 out 中多出的成员不会被 kernel 写回,若上层读取即得到未初始化数据。原实现(等长校验)属于“首阶段即可诊断”的明确错误,本次改动把该错误后移且语义上并未真正支持该用法。

likedislike
Incorrect?
180- 
181 // 空Tensor检查:文档声明x1/x2/x3/out均不支持空Tensor,显式拒绝,避免依赖shape校验的副作用180 // 空Tensor检查:文档声明x1/x2/x3/out均不支持空Tensor,显式拒绝,避免依赖shape校验的副作用
182 const aclTensorList* tensorLists[4] = {self, x2, x3, out};181 const aclTensorList* tensorLists[4] = {self, x2, x3, out};
183 const char* listNames[4] = {"x1", "x2", "x3", "out"};182 const char* listNames[4] = {"x1", "x2", "x3", "out"};
@@ -89,3 +89,83 @@ TEST_F(l2_foreach_addcdiv_scalar_test, ascend910B2_foreach_addcdiv_scalar_test_s
89 aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize);89 aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize);
90 EXPECT_EQ(getWorkspaceResult, ACLNN_ERR_PARAM_INVALID);90 EXPECT_EQ(getWorkspaceResult, ACLNN_ERR_PARAM_INVALID);
91}91}
92+ 
93+// 增量覆盖:x1 与 x2 的 tensor 个数不一致 -> 161002(命中 x2Mismatch 分支)
94+TEST_F(l2_foreach_addcdiv_scalar_test, ascend910B2_foreach_addcdiv_scalar_test_x2_list_shorter)
95+{
96+ vector<int64_t> dims = {2, 2};
97+ vector<int64_t> scalarDims = {1};
98+ auto x = TensorDesc(dims, ACL_FLOAT, ACL_FORMAT_ND).ValueRange(-1.0, 1.0);
99+ auto x2 = TensorDesc(dims, ACL_FLOAT, ACL_FORMAT_ND).ValueRange(-1.0, 1.0);
100+ auto x3 = TensorDesc(dims, ACL_FLOAT, ACL_FORMAT_ND).ValueRange(0.1, 1.0);
101+ auto scalar = TensorDesc(scalarDims, ACL_FLOAT, ACL_FORMAT_ND).ValueRange(1.0, 2.0);
102+ auto out = TensorDesc(dims, ACL_FLOAT, ACL_FORMAT_ND).Precision(0.001, 0.001);
103+ auto xList = TensorListDesc({x, x});
104+ auto x2List = TensorListDesc({x2});
105+ auto x3List = TensorListDesc({x3, x3});
106+ auto outList = TensorListDesc({out, out});
107+ 
108+ auto ut = OP_API_UT(aclnnForeachAddcdivScalar, INPUT(xList, x2List, x3List, scalar), OUTPUT(outList));
109+ uint64_t workspaceSize = 0;
110+ EXPECT_EQ(ut.TestGetWorkspaceSize(&workspaceSize), ACLNN_ERR_PARAM_INVALID);
111+}
112+ 
113+// 增量覆盖:x1 与 x3 的 tensor 个数不一致 -> 161002(x2 长度一致,走 x3Mismatch 分支)
114+TEST_F(l2_foreach_addcdiv_scalar_test, ascend910B2_foreach_addcdiv_scalar_test_x3_list_shorter)
115+{
116+ vector<int64_t> dims = {2, 2};
117+ vector<int64_t> scalarDims = {1};
118+ auto x = TensorDesc(dims, ACL_FLOAT, ACL_FORMAT_ND).ValueRange(-1.0, 1.0);
119+ auto x2 = TensorDesc(dims, ACL_FLOAT, ACL_FORMAT_ND).ValueRange(-1.0, 1.0);
120+ auto x3 = TensorDesc(dims, ACL_FLOAT, ACL_FORMAT_ND).ValueRange(0.1, 1.0);
121+ auto scalar = TensorDesc(scalarDims, ACL_FLOAT, ACL_FORMAT_ND).ValueRange(1.0, 2.0);
122+ auto out = TensorDesc(dims, ACL_FLOAT, ACL_FORMAT_ND).Precision(0.001, 0.001);
123+ auto xList = TensorListDesc({x, x});
124+ auto x2List = TensorListDesc({x2, x2});
125+ auto x3List = TensorListDesc({x3});
126+ auto outList = TensorListDesc({out, out});
127+ 
128+ auto ut = OP_API_UT(aclnnForeachAddcdivScalar, INPUT(xList, x2List, x3List, scalar), OUTPUT(outList));
129+ uint64_t workspaceSize = 0;
130+ EXPECT_EQ(ut.TestGetWorkspaceSize(&workspaceSize), ACLNN_ERR_PARAM_INVALID);
131+}
132+ 
133+// 增量覆盖:x 列表比 out 长 -> 161002("少传拒绝")
134+TEST_F(l2_foreach_addcdiv_scalar_test, ascend910B2_foreach_addcdiv_scalar_test_x_list_longer_than_out)
135+{
136+ vector<int64_t> dims = {2, 2};
137+ vector<int64_t> scalarDims = {1};
138+ auto x = TensorDesc(dims, ACL_FLOAT, ACL_FORMAT_ND).ValueRange(-1.0, 1.0);
139+ auto x2 = TensorDesc(dims, ACL_FLOAT, ACL_FORMAT_ND).ValueRange(-1.0, 1.0);
140+ auto x3 = TensorDesc(dims, ACL_FLOAT, ACL_FORMAT_ND).ValueRange(0.1, 1.0);
141+ auto scalar = TensorDesc(scalarDims, ACL_FLOAT, ACL_FORMAT_ND).ValueRange(1.0, 2.0);
142+ auto out = TensorDesc(dims, ACL_FLOAT, ACL_FORMAT_ND).Precision(0.001, 0.001);
143+ auto xList = TensorListDesc({x, x});
144+ auto x2List = TensorListDesc({x2, x2});
145+ auto x3List = TensorListDesc({x3, x3});
146+ auto outList = TensorListDesc({out});
147+ 
148+ auto ut = OP_API_UT(aclnnForeachAddcdivScalar, INPUT(xList, x2List, x3List, scalar), OUTPUT(outList));
149+ uint64_t workspaceSize = 0;
150+ EXPECT_EQ(ut.TestGetWorkspaceSize(&workspaceSize), ACLNN_ERR_PARAM_INVALID);
151+}
152+ 
153+// 增量覆盖:x 列表比 out 短 -> 放行("多传放行"),保证新增判据不是双向相等
154+TEST_F(l2_foreach_addcdiv_scalar_test, ascend910B2_foreach_addcdiv_scalar_test_x_list_shorter_than_out)
155+{
156+ vector<int64_t> dims = {2, 2};
157+ vector<int64_t> scalarDims = {1};
158+ auto x = TensorDesc(dims, ACL_FLOAT, ACL_FORMAT_ND).ValueRange(-1.0, 1.0);
159+ auto x2 = TensorDesc(dims, ACL_FLOAT, ACL_FORMAT_ND).ValueRange(-1.0, 1.0);
160+ auto x3 = TensorDesc(dims, ACL_FLOAT, ACL_FORMAT_ND).ValueRange(0.1, 1.0);
161+ auto scalar = TensorDesc(scalarDims, ACL_FLOAT, ACL_FORMAT_ND).ValueRange(1.0, 2.0);
162+ auto out = TensorDesc(dims, ACL_FLOAT, ACL_FORMAT_ND).Precision(0.001, 0.001);
163+ auto xList = TensorListDesc({x});
164+ auto x2List = TensorListDesc({x2});
165+ auto x3List = TensorListDesc({x3});
166+ auto outList = TensorListDesc({out, out});
167+ 
168+ auto ut = OP_API_UT(aclnnForeachAddcdivScalar, INPUT(xList, x2List, x3List, scalar), OUTPUT(outList));
169+ uint64_t workspaceSize = 0;
170+ EXPECT_EQ(ut.TestGetWorkspaceSize(&workspaceSize), ACL_SUCCESS);
171+}
@@ -193,7 +193,7 @@ TEST_F(l2_foreach_addcdiv_scalar_v2_test, ascend910B2_foreach_addcdiv_scalar_v2_
193 EXPECT_EQ(getWorkspaceResult, ACLNN_ERR_PARAM_INVALID);193 EXPECT_EQ(getWorkspaceResult, ACLNN_ERR_PARAM_INVALID);
194}194}
195 195 
196-// out 列表比 x1 长:应拒绝,避免多余 out 静默未写196+// 接受out 列表比 x1 长
197TEST_F(l2_foreach_addcdiv_scalar_v2_test, ascend910B2_foreach_addcdiv_scalar_v2_test_out_list_longer)197TEST_F(l2_foreach_addcdiv_scalar_v2_test, ascend910B2_foreach_addcdiv_scalar_v2_test_out_list_longer)
198{198{
199 vector<int64_t> dims = {2, 2};199 vector<int64_t> dims = {2, 2};
@@ -210,7 +210,7 @@ TEST_F(l2_foreach_addcdiv_scalar_v2_test, ascend910B2_foreach_addcdiv_scalar_v2_
210 auto ut = OP_API_UT(aclnnForeachAddcdivScalarV2, INPUT(xList, x2List, x3List, scalar_desc), OUTPUT(outList));210 auto ut = OP_API_UT(aclnnForeachAddcdivScalarV2, INPUT(xList, x2List, x3List, scalar_desc), OUTPUT(outList));
211 uint64_t workspaceSize = 0;211 uint64_t workspaceSize = 0;
212 aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize);212 aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize);
213- EXPECT_EQ(getWorkspaceResult, ACLNN_ERR_PARAM_INVALID);213+ EXPECT_EQ(getWorkspaceResult, ACL_SUCCESS);
214}214}
215 215 
216// 对称空 Tensor:文档声明不支持,应拒绝216// 对称空 Tensor:文档声明不支持,应拒绝
@@ -197,7 +197,7 @@ aclnnStatus aclnnForeachAddcdivScalarList(
197 <td>x1、x2、x3、out的shape不满足约束。</td>197 <td>x1、x2、x3、out的shape不满足约束。</td>
198 </tr>198 </tr>
199 <tr>199 <tr>
200- <td>x1、x2、x3、out的Tensor列表长度不一致。</td>200+ <td>x1、x2、x3的Tensor列表长度不一致;x1的Tensor列表长度大于out的Tensor列表长度</td>
201 </tr>201 </tr>
202 <tr>202 <tr>
203 <td>x1、x2、x3或out的Tensor列表内含空Tensor指针。</td>203 <td>x1、x2、x3或out的Tensor列表内含空Tensor指针。</td>
@@ -261,6 +261,7 @@ aclnnStatus aclnnForeachAddcdivScalarList(
261 - aclnnForeachAddcdivScalarList默认确定性实现。261 - aclnnForeachAddcdivScalarList默认确定性实现。
262- 单个Tensor列表中Tensor的数量不超过256个,超出上限时算子执行失败。262- 单个Tensor列表中Tensor的数量不超过256个,超出上限时算子执行失败。
263- 空TensorList(含0个Tensor的TensorList)为合法输入:`x1`、`x2`、`x3`、`out`均为空TensorList时,`scalars`的元素个数为0,接口返回成功,不执行计算、不修改`out`。263- 空TensorList(含0个Tensor的TensorList)为合法输入:`x1`、`x2`、`x3`、`out`均为空TensorList时,`scalars`的元素个数为0,接口返回成功,不执行计算、不修改`out`。
264+- `out`的Tensor数量必须大于等于`x1`的tensor数量。
264 265 
265## 调用示例266## 调用示例
266 267 
@@ -155,8 +155,9 @@ static inline aclnnStatus CheckParams(const aclTensorList* x1, const aclTensorLi
155 (std::to_string(x3->Size())).c_str(), reason.c_str()}));155 (std::to_string(x3->Size())).c_str(), reason.c_str()}));
156 return ACLNN_ERR_PARAM_INVALID;156 return ACLNN_ERR_PARAM_INVALID;
157 }157 }
158- if (x1->Size() != out->Size()) {158+ // x 与 out 的 tensor 个数:要求 x1->Size() <= out->Size(),多传放行、少传拒绝
159- const std::string reason = (std::string("Tensor lists must have equal lengths; x1=") +159+ if (x1->Size() > out->Size()) {
160+ const std::string reason = (std::string("The tensor nums in {x1, out} must satisfy x1 <= out, but got x1=") +
160 std::to_string(x1->Size()) + ", out=" + std::to_string(out->Size()));161 std::to_string(x1->Size()) + ", out=" + std::to_string(out->Size()));
161 OP_LOGE_WITHOUT_REPORT(ACLNN_ERR_PARAM_INVALID, "%s", reason.c_str());162 OP_LOGE_WITHOUT_REPORT(ACLNN_ERR_PARAM_INVALID, "%s", reason.c_str());
162 REPORT_PREDEFINED_ERR_MSG("EZ0038",163 REPORT_PREDEFINED_ERR_MSG("EZ0038",
@@ -165,7 +166,6 @@ static inline aclnnStatus CheckParams(const aclTensorList* x1, const aclTensorLi
165 (std::to_string(out->Size())).c_str(), reason.c_str()}));166 (std::to_string(out->Size())).c_str(), reason.c_str()}));
166 return ACLNN_ERR_PARAM_INVALID;167 return ACLNN_ERR_PARAM_INVALID;
167 }168 }
atomgit-bot
atomgit-botatomgit-bot10 days ago

🟡 Medium Priority

变更行:CheckParams 中 if (x1->Size() != out->Size()) 改为 if (x1->Size() > out->Size())(aclnn_foreach_addcdiv_scalar_list.cpp:158-168),允许 out 列表比 x1 长。

证据链:本算子的 arch35 tiling 只校验 x2/x3 与 x1 的实例数(foreach_addcdiv_scalar_list_tiling.cpp:145-150),没有校验输出实例数(在 foreach/foreach_addcdiv_scalar_list/op_host 全目录检索 GetComputeNodeOutputNum/GetOutputShape/output y 无命中);tiling 以 x1 的 tensorNum 逐成员切分并按 x1 下标访问,kernel 同理按 x1 下标写 y。

失效模式:用户传入 out->Size() > x1->Size() 时,第一段接口返回成功、tiling 也放行,kernel 只计算前 x1->Size() 个成员,多出的 out 成员保持用户传入前的旧值/未初始化内存,且接口没有任何报错或提示。即“成功的调用返回了部分未写入的输出”,属于静默的数据正确性问题,比原先的等长参数错误更危险。

likedislike
Incorrect?
168- 
169 // Check every entry in tensor lists is not null, to avoid null pointer169 // Check every entry in tensor lists is not null, to avoid null pointer
170 // dereference in CheckDtypeValid/CheckShape/CheckFormat.170 // dereference in CheckDtypeValid/CheckShape/CheckFormat.
171 CHECK_RET(CheckTensorListNotNull(x1, "x1"), ACLNN_ERR_PARAM_INVALID);171 CHECK_RET(CheckTensorListNotNull(x1, "x1"), ACLNN_ERR_PARAM_INVALID);
@@ -217,6 +217,7 @@ aclnnStatus aclnnForeachCopy(
217 217 
218- 确定性计算:218- 确定性计算:
219 - aclnnForeachCopy默认确定性实现。219 - aclnnForeachCopy默认确定性实现。
220+- 不支持x与out为同一存储且重叠场景,该场景下无法保证精度正确。
220 221 
221## 调用示例222## 调用示例
222 223 
@@ -180,6 +180,11 @@ aclnnStatus aclnnForeachNorm(
180 - <term>Ascend 950PR&950DT系列产品</term>:参数`x`、`out`支持的最大长度为256个。180 - <term>Ascend 950PR&950DT系列产品</term>:参数`x`、`out`支持的最大长度为256个。
181 <!-- end id9 -->181 <!-- end id9 -->
182 182 
183+ <!-- npu="A3,910b" id10 -->
184+ - <term>Atlas A2系列产品</term>、<term>Atlas A3系列产品</term>:
185+ scalar参数仅支持1和2两种取值,其他取值无法保证精度。
186+ <!-- end id10 -->
187+ 
183- **返回值**188- **返回值**
184 189 
185 aclnnStatus:返回状态码,具体参见[aclnn返回码](../../../docs/zh/context/aclnn_return_code.md)。190 aclnnStatus:返回状态码,具体参见[aclnn返回码](../../../docs/zh/context/aclnn_return_code.md)。
@@ -69,6 +69,7 @@
69 </tbody></table>69 </tbody></table>
70 70 
71- <term>Kirin X90处理器系列产品</term>、<term>Kirin 9030处理器系列产品</term>:不支持BFLOAT16、INT16。71- <term>Kirin X90处理器系列产品</term>、<term>Kirin 9030处理器系列产品</term>:不支持BFLOAT16、INT16。
72+- <term>Atlas A2系列产品</term>、<term>Atlas A3系列产品</term>、<term>Kirin X90处理器系列产品</term>、<term>Kirin 9030处理器系列产品</term>:roundMode参数仅支持取值1、2、3、4、5、7;若传入其他值,系统将忽略舍入逻辑,返回原始结果。
72 73 
73## 约束说明74## 约束说明
74 75 
@@ -71,6 +71,7 @@ English | [简体中文](./README.md)
71 </tbody></table>71 </tbody></table>
72 72 
73- <term>Kirin X90 processor series products</term> and <term>Kirin 9030 processor series products</term>: BFLOAT16 and INT16 are not supported.73- <term>Kirin X90 processor series products</term> and <term>Kirin 9030 processor series products</term>: BFLOAT16 and INT16 are not supported.
74+- <term>Atlas A2系列产品</term>、<term>Atlas A3系列产品</term>、<term>Kirin X90处理器系列产品</term>、<term>Kirin 9030处理器系列产品</term>:roundMode参数仅支持取值1、2、3、4、5、7;若传入其他值,系统将忽略舍入逻辑,返回原始结果。
74 75 
75## Constraints76## Constraints
76 77 
@@ -187,6 +187,11 @@ aclnnStatus aclnnForeachRoundOffNumber(
187 </tr>187 </tr>
188 </tbody></table>188 </tbody></table>
189 189 
190+ <!-- npu="A3,910b" id10 -->
191+ - <term>Atlas A2系列产品</term>、<term>Atlas A3系列产品</term>:
192+ roundMode参数仅支持取值1、2、3、4、5、7;若传入其他值,系统将忽略舍入逻辑,返回原始结果。
193+ <!-- end id10 -->
194+ 
190## aclnnForeachRoundOffNumber195## aclnnForeachRoundOffNumber
191 196 
192- **参数说明**197- **参数说明**
@@ -134,6 +134,11 @@ aclnnStatus aclnnForeachRoundOffNumberV2(
134 </tbody>134 </tbody>
135 </table>135 </table>
136 136 
137+ <!-- npu="A3,910b" id10 -->
138+ - <term>Atlas A2系列产品</term>、<term>Atlas A3系列产品</term>:
139+ roundMode参数仅支持取值1、2、3、4、5、7;若传入其他值,系统将忽略舍入逻辑,返回原始结果。
140+ <!-- end id10 -->
141+ 
137- **返回值**142- **返回值**
138 143 
139 aclnnStatus:返回状态码,具体参见[aclnn返回码](../../../docs/zh/context/aclnn_return_code.md)。144 aclnnStatus:返回状态码,具体参见[aclnn返回码](../../../docs/zh/context/aclnn_return_code.md)。
@@ -32,6 +32,12 @@ constexpr int8_t CAST_TRUNC = 5;
32constexpr int8_t CAST_ODD = 6;32constexpr int8_t CAST_ODD = 6;
33constexpr int8_t CAST_FRAC = 7;33constexpr int8_t CAST_FRAC = 7;
34 34 
35+// roundMode 仅 1/2/3/4/5/7 为有效舍入;其余取值(0、6、>=8 等)一律按“不舍入”处理
36+__aicore__ inline bool IsSupportedRoundMode(int8_t mode)
37+{
38+ return (mode >= CAST_RINT && mode <= CAST_TRUNC) || (mode == CAST_FRAC);
39+}
atomgit-bot
atomgit-botatomgit-bot10 days ago

🟡 Medium Priority

变更行:新增 IsSupportedRoundMode(foreach_round_off_number.h:35-39)把有效舍入限制为 1..5 与 7,并在此处用它替换原来的 else 分支(117、145 行)。

证据链:CAST_ODD = 6 在本文件就被定义为合法舍入模式,ConvertRoundMode 也有专门的 case CAST_ODD: retR = RoundMode::CAST_ODD;(本文件 67-69 行),说明 mode=6 之前是走 hardware CAST_ODD 舍入的。改动后 6 落入新的“不舍入”分支(Muls×1.0 恒等拷贝),直接丢弃该舍入语义。而同一算子的 arch35 SIMT 实现仍然保留 case CAST_ODD: return RoundToOdd(value);(foreach/foreach_round_off_number/op_kernel/arch35/foreach_round_off_number_simt.h:86-87),测试参考实现也按 round-to-odd 计算 mode 6(tests/assets/golden.py:195-196,且注释只声明“CAST_NONE 与非法值回退恒等”)。

失效模式:同样的输入与 roundMode=6,910B/arch22 路径(本文件)输出未舍入的原值,arch35 路径输出 round-to-odd 结果,两份实现与 golden 结果不一致;对 2.5 这类值会得到如 2.0 vs 3.0 的差异,属于静默精度回归,且 ST/UT 在 arch22 上会出现精度比对失败(或被误判为已在别处放宽的期望)。若硬件确实不支持 f32->f32 的 CAST_ODD,也应显式报错或在 host 侧拒绝 mode=6,而不是静默按“不舍入”处理。

建议:让 IsSupportedRoundMode 覆盖 CAST_ODD(6),使 arch22 路径与 arch35 SIMT 实现及 golden 参考保持一致的 round-to-odd 语义;若确实不支持 6,则改为在 host 侧显式拒绝并同步清理枚举/ConvertRoundMode/golden。

likedislike
Incorrect?
40+ 
35constexpr uint8_t COPY_SPACE_MULTIPLE = 9;41constexpr uint8_t COPY_SPACE_MULTIPLE = 9;
36 42 
37constexpr uint8_t INPUT_PARAMETER_COUNT = 2;43constexpr uint8_t INPUT_PARAMETER_COUNT = 2;
@@ -108,10 +114,16 @@ private:
108 PipeBarrier<PIPE_V>();114 PipeBarrier<PIPE_V>();
109 Sub(float32Tensor[maxCastDataCount], float32Tensor, float32Tensor[maxCastDataCount], dataCount);115 Sub(float32Tensor[maxCastDataCount], float32Tensor, float32Tensor[maxCastDataCount], dataCount);
110 PipeBarrier<PIPE_V>();116 PipeBarrier<PIPE_V>();
111- } else {117+ } else if (IsSupportedRoundMode(roundModeValue)) {
112 PipeBarrier<PIPE_V>();118 PipeBarrier<PIPE_V>();
113 Cast(float32Tensor[maxCastDataCount], float32Tensor, ConvertRoundMode(roundModeValue), dataCount);119 Cast(float32Tensor[maxCastDataCount], float32Tensor, ConvertRoundMode(roundModeValue), dataCount);
114 PipeBarrier<PIPE_V>();120 PipeBarrier<PIPE_V>();
121+ } else {
122+ // 不舍入:不做 f32->f32 变换,把升精度后的原值搬到回程源区
123+ // (f16/bf16 -> f32 -> f16/bf16 精确可逆,回程 CAST_RINT 原样写回)
124+ // 用乘 1.0 而非加 0.0:加 0 会把 -0.0 变成 +0.0
125+ Muls(float32Tensor[maxCastDataCount], float32Tensor, 1.0f, dataCount);
126+ PipeBarrier<PIPE_V>();
115 }127 }
116 128 
117 Cast(outLocal[index * maxCastDataCount], float32Tensor[maxCastDataCount], RoundMode::CAST_RINT, dataCount);129 Cast(outLocal[index * maxCastDataCount], float32Tensor[maxCastDataCount], RoundMode::CAST_RINT, dataCount);
@@ -130,8 +142,12 @@ public:
130 Cast(outLocal, dataLocal, RoundMode::CAST_TRUNC, dataCount);142 Cast(outLocal, dataLocal, RoundMode::CAST_TRUNC, dataCount);
131 PipeBarrier<PIPE_V>();143 PipeBarrier<PIPE_V>();
132 Sub(outLocal, dataLocal, outLocal, dataCount);144 Sub(outLocal, dataLocal, outLocal, dataCount);
133- } else {145+ } else if (IsSupportedRoundMode(roundModeValue)) {
134 Cast(outLocal, dataLocal, ConvertRoundMode(roundModeValue), dataCount);146 Cast(outLocal, dataLocal, ConvertRoundMode(roundModeValue), dataCount);
147+ } else {
148+ // 不舍入:UB 内逐元素拷贝,不下发 f32->f32 的 Cast
149+ // 用乘 1.0 而非加 0.0:加 0 会把 -0.0 变成 +0.0
150+ Muls(outLocal, dataLocal, 1.0f, dataCount);
135 }151 }
136 }152 }
137};153};
@@ -164,7 +164,7 @@ aclnnStatus aclnnForeachSqrt(
164 <td>x和out的数据类型不一致。</td></tr>164 <td>x和out的数据类型不一致。</td></tr>
165 <tr>165 <tr>
166 <td rowspan="3">ACLNN_ERR_INNER_TILING_ERROR</td>166 <td rowspan="3">ACLNN_ERR_INNER_TILING_ERROR</td>
167- <td rowspan="3">561002</td>167+ <td rowspan="3">161002</td>
168 <td>x与out的shape不满足约束。</td>168 <td>x与out的shape不满足约束。</td>
169 </tr>169 </tr>
170 <tr>170 <tr>