已合并
Align NPU mixed-dtype async host-device copy behavior with CUDA #39575
zzhongmin创建于 6月30日
Align NPU mixed-dtype async host-device copy behavior with CUDA #39575
已合并
Pull Request已成功合入, 合并人@ascend-robot
(感谢 zzhongmin 的贡献)ascend-robot
6月30日 评论:
6月30日 评论:
6月30日 添加了label:ascend-cla/yes
zzhongmin
6月30日 评论:
6月30日 评论:
compile


ascend-robot
6月30日 评论:
6月30日 评论:
Thanks for your pull-request.
The full list of commands accepted by me can be found at here。
You can get sig-info at here
PR Approval Progress
✅ Congratulations! All modules have met the lgtm and approve requirements.
Module Approval Details
| module | lgtm status | approve status |
|---|---|---|
| repo-Ascend/pytorch | ✅ li_jing_hw, hbhu_bin (2/2) | ✅ li_jing_hw (1/1) |
| test | ✅ li_jing_hw, hbhu_bin (2/2) | ✅ li_jing_hw (1/1) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)
CLA Signature Pass
zzhongmin, thanks for your pull request. All authors of the commits have signed the CLA. 👍


此处折叠了89条消息 查看更多
7月7日 添加了label:approved
7月7日 添加了label:lgtm
7月7日 合入了pull request
ascend-robot
7月7日 评论:
7月7日 评论:
流水线 pytorch_gitcode_PR_multiVersion#12061 [ commitID:c4e9b3f9 ] 已完成


【合入来源】
【修改方案】
Copy.cu的 mixed-dtype 异步 Host/Device 拷贝策略,调整 NPU OpApi 路径。当
non_blocking=True且 Host/Device dtype 不一致时,将可由aclnnCast支持的 dtype 转换前移到 NPU Device 侧完成,避免因 CPU 侧 dtype cast 产生非 pinned 临时 Tensor,导致 H2D/D2H 退化为同步拷贝。non_blocking=False与同 dtype fast path 保持原有逻辑。torch_npu/csrc/aten/ops/op_api/CopyKernelOpApi.cppaclnnCast转为目标 dtype 并写回目标 Tensor。custom_ops::_npu_dtype_cast转为目标 dtype,再执行同 dtype D2H 拷贝到 CPU 目标。NpuUtils::check_match(&src)判断;当 NPU 源 Tensor 是非连续 view 或 metadata 不满足 OpApi 要求时,先通过NpuUtils::format_contiguous(src)规范化输入,避免aclnnCast直接处理不匹配的 view。cast_dtype_out_baseformat_opapi,封装aclnnCastout 路径,用于 H2D mixed-dtype async 路径中将 NPU temporary 转换并写入目标 Tensor。should_fallback_to_cpu_cast:在 A2 及之后产品上,对aclnnCast不支持的 dtype 组合保留原 CPU cast 路径,避免 unsupported dtype 走设备侧 cast 失败。Tensor.copy_mixed-dtype 功能、异步行为与 fallback 测试。test/test_copy_.pycopy_(non_blocking=True)。int32 -> float32、int64 -> float32、float16 -> float32、float32 -> float16、complex64 <-> complex128等基础转换组合。bool、int8、int16、uint16、int64、float16、bfloat16、float32、complex dtype,并包含负数、边界值、小数和复数数据。gate_stream上的矩阵乘任务阻塞copy_stream,再使用done_event.query()验证copy_返回时没有同步等待异步拷贝完成。_npu_dtype_cast前的format_contiguous保护逻辑。float8_e5m2、float8_e4m3fn、complex32等aclnnCastunsupported dtype 的 CPU cast fallback 正确性测试。non_blocking=False的 H2D/D2H mixed-dtype 结果正确性回归测试。Ascend910B、Ascend910_93、Ascend950上执行。Tensor.tomixed-dtype 跨设备测试。test/npu/test_npu.pytest_to_non_blocking_different_dtype,覆盖 CPU ↔ NPU、non_blocking=True/False的跨设备 dtype 转换。int32 -> float32转换结果正确性。non_blocking=True时输出 Tensor 保持 pinned-memory 属性。Ascend910B、Ascend910_93、Ascend950上执行。【资料变更】
不涉及
【接口变更】
不涉及
【功能验证】
【CheckList】