已开启
【代码侦探Challenge05】实现逐元素乘法算子 MulCustom #2431
【代码侦探Challenge05】实现逐元素乘法算子 MulCustom #2431
已开启
aodebiao创建于 17 天前
aodebiao
aodebiao
17 天前

当前PR是否有AI参与:

[x] 否
[ ] 是
__1. AI Agent 平台:
__2. AI 模型:
__3. Prompt上下文 :

PR功能描述 / 为什么需要这个合入**:

2026/CANN-Code-Detective/Challenge05-MulCustom/gxhgxh2475698/MulCustom 中完成 MulCustom 逐元素乘法算子:

  • 完成 8 核数据切分及每核 GM 地址偏移;
  • 完成 Double Buffer 下的 tile 切分与 TQue 初始化;
  • CopyIn -> Compute -> CopyOut 流程实现流水处理;
  • 使用 AscendC::Mul 完成 z[i] = x[i] * y[i]
  • 完成 Host 侧 ACL 初始化、内存管理、Kernel 直调、同步和结果回拷;
  • 完成主函数结果验证。

提交范围仅包含任务书要求的 mul_custom.ascCMakeLists.txtrun.sh,不包含构建产物。

该PR关联的issue

https://gitcode.com/cann/cann-learning-hub/issues/700

希望检视人员了解:

改动类型 / Change Type

测试信息 / Testing

  • 硬件:Ascend 910B,NPU 0
  • 架构:AArch64
  • CANN:8.5.0
  • 命令:bash run.sh

验证结果:

屏幕截图 2026-09-01 200838.png

likedislike
合并受阻
aodebiaoaodebiao
17 天前 创建了 pull request,commit dbdc8b6e
atomgit-bot
atomgit-bot
17 天前 评论:

变更摘要

该 PR 面向「代码侦探 Challenge05」挑战,实现了逐元素乘法算子 MulCustom,用于计算 z[i] = x[i] * y[i]。改动新增了一个完整的 AscendC 自定义算子实现:包含 KernelMul 内核类(完成 Init 初始化、Process 主循环、CopyIn 搬入、Compute 计算、CopyOut 搬出全流程,其中 Compute 通过 AscendC::Mul 完成逐元素相乘),并基于 Double Buffer(BUFFER_NUM = 2)实现数据流水。同时提供了 mul_custom kernel 入口函数、Host 侧 kernel_mul 直调封装(基于 ACL 运行时完成内存申请、H2D/D2H 拷贝与流同步),以及 VerifyResult 精度校验与 main 验证逻辑。整个算子通过 MulCustomTilingData 传递 totalLengthtileNum 分块参数,按 GetBlockNum()/GetBlockIdx() 进行多核切分。

主要改动

  • 新增内核算子实现(mul_custom.asc:实现 KernelMul 类及 Init/Process/CopyIn/Compute/CopyOut 方法,Compute 中调用 AscendC::Mulxy 逐元素相乘并输出到 z,整个过程使用 BUFFER_NUM = 2 的双缓冲队列 inQueueXinQueueYoutQueueZ 实现流水。
  • 新增 Host 侧调用与验证逻辑kernel_mul 通过 ACL 接口(aclrtMallocaclrtMemcpymul_custom<<<blockDim, nullptr, stream>>>aclrtSynchronizeStream 等)完成设备内存管理、数据搬入搬出与 kernel 启动;main 构造长度为 8 * 2048 的输入并经 VerifyResult 与 golden 结果逐元素比对。
  • 新增构建运行脚本(run.sh:脚本激活 CANN 环境(set_env.sh)、创建 build 目录、执行 cmakemake 编译,并运行生成的 mul_test 可执行程序完成验证。
likedislike
不准确?
atomgit-bot
atomgit-bot
17 天前 评论:

代码审查

✅ 未发现问题

likedislike
不准确?
CANN-robotCANN-robot成员
17 天前 添加了label:cann-cla/yes
CANN-robot
CANN-robot成员
17 天前 评论:

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.
You can self-configure the PR merge rules for this repository. For more details, please refer to Here.
For more, you also can visit HICANN.


PR Approval Progress

⚠️ This PR does not yet meet the following requirements:lgtm (requires ≥ 2 person(s) per module)、approve (requires ≥ 1 person(s) per module)

Module Approval Details

module lgtm status approve status
repo-cann/cann-outreach ❌ (0/2)(You can also ask: 田晓亮, yanhf, Carolina_yuan, 王艳秋, gcw_tgPdOLZT) ❌ (0/1)(You can also ask: yanhf, gcw_tgPdOLZT, Carolina_yuan, jxlang, yanyawen)

💡 Tip:

  • Committer can comment /approve or /lgtm
  • Commenting /approve implies both code review (lgtm) and intent to merge (approve)

CLA Signature Pass

gxhgxh2475698, thanks for your pull request. All authors of the commits have signed the CLA. 👍

likedislike
aodebiaoaodebiao
17 天前 修改了pull request 的描述
aodebiaoaodebiao
17 天前 修改了pull request 的描述
aodebiaoaodebiao
17 天前 修改了pull request 的描述
aodebiaoaodebiao
17 天前 修改了pull request 的描述