Closed
[Documentation|文档反馈]: aclnnForeachCopy 的 out dtype 对应关系漏列 BFLOAT16→FLOAT32(实现支持) #7941
liuhanwen8Add on 20 days agoClosed at 17 days ago
20 days ago Added label: documentation
east_yang
20 days ago Comments:
20 days ago Comments:
/assign @Tian_1122


20 days ago Assign Tian_1122 as responsible person
20 days ago Assign east_yang as responsible person
20 days ago Removed responsible person Tian_1122
19 days ago Assign fengying555682 as responsible person
yuning_chen
19 days ago Comments:
19 days ago Comments:
初步分析
感谢反馈,我们已开始核对这个问题。
现象理解:缺陷反馈;aclnnForeachCopy 的 out dtype 对应关系漏列 BFLOAT16→FLOAT32(实现支持)。
当前判断:从描述看这是缺陷反馈「aclnnForeachCopy 的 out dtype 对应关系漏列 BFLOAT16→FLOAT32(实现支持)」。目前只能根据现象做文字核对,还没有上板复现。以上为初步判断,待复现确认,不能当成已确认根因。
涉及范围:aclnnForeachCopy、aclnn_foreach_copy、test_aclnn_foreach_copy、has_bf16_to_f32、BFLOAT16、FLOAT32
下一步:我们会继续对照代码/文档定位。为便于继续定位,请尽量补充:关键报错或日志片段。


yuning_chen
19 days ago Comments:
19 days ago Comments:
您好,该问题已收到,当前问题 @east_yang 正在处理中


19 days ago Assign gitee-duhuiping as responsible person
19 days ago Removed responsible person fengying555682
17 days ago Close issue
16 days ago Added label: resolved
文档位置
foreach/foreach_copy/docs/aclnnForeachCopy.md→ 参数表 →out行的「使用说明」列(第 4 列)。原文摘录:
现象
上面第三句把「x 不是 FLOAT32/FLOAT16」的情况收敛成「out 与 x 同 dtype」,
按此口径
x=BFLOAT16时out只允许 BFLOAT16,out=FLOAT32应当属于非法组合(161002)。但实现支持
BFLOAT16 → FLOAT32,且数值为精确转换:foreach/foreach_copy/op_api/aclnn_foreach_copy.cpp的IsValidDtypeMapping()(master
7044c832,该函数第 81 行起)显式允许DT_BF16 → DT_FLOAT;x=bf16[2x3] out=fp32[2x3]两段返回 0,输出
0.1328125 / 0.96875 / -0.24609375 …,即 bf16 值到 fp32 的精确表示。因此资料的「对应关系」漏了一种实际支持的组合,读者按文档会把一个合法用法当成非法。
期望
资料应把
out的 dtype 对应关系补全为四类(与实现一致):x=FLOAT32→ out 支持 FLOAT16 / BFLOAT16;x=FLOAT16→ out 支持 FLOAT32;x=BFLOAT16→ out 支持 BFLOAT16 / FLOAT32(当前缺失);若实现侧的
BFLOAT16 → FLOAT32属非预期能力,则应改为返回 161002 并保持资料现状——两种处置均可,但资料与实现必须一致。环境
910B2),npu-smi 26.1.19.2.0,Linux aarch64cann/ops-nn7044c8328cfb3bb0a298034fd9c56f49aca0bbd7(2026-11-02git fetch后)复现步骤
doc_repro.pypython3 doc_repro.py foreach/foreach_copy/docs/aclnnForeachCopy.md[DEFECT] 资料未声明 BFLOAT16 → FLOAT32 …,退出码为1(实现侧可选用同仓库
examples/test_aclnn_foreach_copy.cpp改成x=bf16 / out=fp32复核,两段返回 0。)复现脚本
#!/usr/bin/env python3 # 断言方向:应存在(资料该列而未列 ⇒ DEFECT)。退出码 0=符合预期 / 1=缺陷成立 / 2=无法判定 import re, sys def cell_text(txt, param): for tr in re.findall(r"<tr>(.*?)</tr>", txt, re.S): if param not in tr: continue cells = [re.sub(r"\s+", " ", re.sub(r"<[^>]+>", "", c)).strip() for c in re.findall(r"<td[^>]*>(.*?)</td>", tr, re.S)] if len(cells) >= 4 and cells[0].startswith(param): return cells[3] return "" path = sys.argv[1] if len(sys.argv) > 1 else "foreach/foreach_copy/docs/aclnnForeachCopy.md" txt = open(path, encoding="utf-8").read() usage = cell_text(txt, "out") if not usage: print("[SKIP] 未定位到 out 的使用说明单元格"); sys.exit(2) print("out 使用说明:" + usage[:400]) has_bf16_to_f32 = bool(re.search(r"BFLOAT16[^。;]{0,40}FLOAT32", usage)) print("已列 BFLOAT16 → FLOAT32:%s" % has_bf16_to_f32) if has_bf16_to_f32: print("[OK] 资料已声明,本条不成立"); sys.exit(0) print("[DEFECT] 资料未声明 BFLOAT16 → FLOAT32,而实现允许该转换" "(aclnn_foreach_copy.cpp IsValidDtypeMapping 允许 DT_BF16 → DT_FLOAT,实测 rc=0)") sys.exit(1)实测输出:
影响
按现资料阅读,
x=BFLOAT16的用户会认为out只能是 BFLOAT16,把out=FLOAT32当成非法组合而放弃一条本就可用(且数值精确)的路径;反之,若有人照资料写用例,会把这段合法用法判成缺陷。资料与实际能力不一致,会同时误导使用方与测试方。建议
把 out 参数的「对应关系」补成三类(或四类):
x=FLOAT32→ out 支持 FLOAT16 / BFLOAT16;x=FLOAT16→ out 支持 FLOAT32;x=BFLOAT16→ out 支持 BFLOAT16 / FLOAT32;若实现侧的
BFLOAT16 → FLOAT32属于非预期能力,则请改为返回 161002,并保持资料现状——两种处置都可,但资料与实现需要一致。