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

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

实现 Challenge05 MulCustom 逐元素乘法算子。

主要内容:

  • 完成多核数据切分和 Global Memory 地址初始化
  • 使用 Double Buffer 管理输入、输出队列
  • 实现 CopyIn → Compute → CopyOut 处理流程
  • 使用 AscendC::Mul 完成逐元素乘法计算
  • 完成 Host 侧内存申请、数据搬运、Kernel 调用和精度校验
  • 新增 PPParticle/MulCustom 目录,不修改官方 Template

该PR关联的issue

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

希望检视人员了解:

已在真实 Ascend NPU 环境完成编译运行和精度验证。

改动类型 / Change Type

测试信息 / Testing

测试环境:

  • 硬件:Ascend 910B3
  • CANN:9.1.0
  • 执行命令:bash run.sh
  • 构建结果:[100%] Built target mul_test
  • 精度验证:[Success] Case accuracy is verification passed.
  • 退出码:RUN_EXIT=0

测试截图:

success.png

检查清单 / Checklist

likedislike
合并受阻
PPParticlePPParticle
19 天前 创建了 pull request,commit 0f3e9dde
PPParticlePPParticle
19 天前 关联了issue:代码侦探(第五期)|补全算子代码有奖,周周赢取定制礼品!
atomgit-bot
atomgit-bot
19 天前 评论:

变更摘要

该 PR 为「代码侦探 Challenge05」新增 MulCustom 逐元素乘法算子(z[i] = x[i] * y[i]),完整实现了 AscendC 算子内核与 Host 侧调用流程,并新增独立目录 PPParticle/MulCustom,不修改官方 Template。核心是定义 KernelMul 类完成多核数据切分与 Global Memory 地址初始化,使用双缓冲(BUFFER_NUM = 2)管理输入/输出队列,按 CopyIn → Compute → CopyOut 流水处理并调用 AscendC::Mul 完成计算;Host 侧通过 kernel_mul 封装 ACL 初始化、内存申请、H2D/D2H 数据搬运、Kernel 启动与资源清理,最终由 VerifyResult 与 golden 结果比对完成精度校验。算子仅支持长度固定为 8 * 2048 的 float32 输入。

主要改动

  • 内核类 KernelMul 与数据切分: 在 Init 中基于 AscendC::GetBlockNum()/AscendC::GetBlockIdx() 计算每核 blockLength 和偏移,通过 SetGlobalBuffer 初始化 xGm/yGm/zGm 三个 Global Tensor,并配置 AIV-only 的 mul_custom 入口函数及 MulCustomTilingData 切分参数结构体。
  • 双缓冲与处理流水线: 使用 TQueinQueueX/inQueueY/outQueueZ,深度 2)实现 Double Buffer,ProcesstileNum * BUFFER_NUM 次循环依次执行 CopyInDataCopy 搬入)、ComputeAscendC::Mul 逐元素相乘)、CopyOut(结果写回 Global Memory)并配对 EnQue/DeQue/FreeTensor
  • Host 侧 kernel_mul 流程: 完成 aclInitaclrtSetDevice、流创建、aclrtMalloc/aclrtMallocHost 内存申请、H2D/D2H aclrtMemcpy 搬运以及 mul_custom<<<BLOCK_DIM, nullptr, stream>>> Kernel 启动,并以 lambda cleanup 统一释放设备/主机内存并复位设备。
  • 精度校验 VerifyResultmain: main 以常量 1.2f2.3f 构造长度为 EXPECTED_TOTAL_LENGTH 的输入和 golden 向量,VerifyResult 通过 std::equal 逐元素比对输出与 golden,成功/失败时分别打印 [Success]/[Failed] 结果并返回退出码。
  • 构建运行脚本 run.sh: 校验 ASCEND_TOOLKIT_HOME/ASCEND_HOME_PATH 环境变量并加载环境,随后调用 cmake 配置、并行编译并执行生成的 mul_test 可执行文件完成验证。
likedislike
不准确?
CANN-robot
CANN-robot成员
19 天前 评论:

Hi @PPParticle, welcome to submitting your first PR to cann-outreach!

PR Merge Steps

1. CLA Signing

If the current PR label includes cann-cla/yes, it means you have signed the CLA and can proceed to the next step. If the label includes cann-cla/no, please sign the CLA first. If you have any questions, please refer to the FAQ.

2. CI Check

Please comment /compile to trigger the CI pipeline check. If the CI run is successful, the PR will be tagged with ci-pipeline-passed and you can proceed to the next step. If the CI run fails, the PR will be tagged with ci-pipeline-failed, please check the CI logs to fix the issues in the PR. If you have any questions, please refer to the FAQ.

3. Code Review

After CI passes, please refer to the PR Approval Progress and proactively @ the committers in the table to review the code. After approval, committers will comment /lgtm and /approve. Once the lgtm and approved labels are successfully added, the PR will be merged automatically.

likedislike
atomgit-bot
atomgit-bot
19 天前 评论:

代码审查

✅ 未发现问题

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

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: luzx66, 傅涛, Carolina_yuan, 王艳秋, shaoyf) ❌ (0/1)(You can also ask: 傅涛, luzx66, li-shengxian3, Carolina_yuan, shaoyf)

💡 Tip:

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

CLA Signature Pass

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

likedislike
PPParticle
PPParticle
19 天前 评论:

/check-cla

likedislike
CANN-robot
CANN-robot成员
19 天前 评论:

CLA检查未通过,详情可参考这里

likedislike
PPParticle
PPParticle
19 天前 评论:

/check-cla

likedislike
CANN-robot
CANN-robot成员
19 天前 评论:

CLA检查未通过,详情可参考这里

likedislike
PPParticlePPParticle
19 天前 预合并成功(commit_id: 2451d84540423fb886519a4dbf125f8c692ee40a)
PPParticlePPParticle
19 天前 强制推送  1 个提交:57a34177-【代码侦探Challenge05】实现 MulCustom 逐元素乘法算子
PPParticlePPParticle
19 天前 预合并成功(commit_id: d0bfd26f8aa7b4abf3f1d62e84150db14b684d05)
CANN-robotCANN-robot成员
19 天前 删除了label:cann-cla/no
CANN-robotCANN-robot成员
19 天前 添加了label:cann-cla/yes
PPParticle
PPParticle
18 天前 评论:

/check-cla

likedislike
CANN-robotCANN-robot成员
18 天前 删除了label:cann-cla/yes
CANN-robotCANN-robot成员
18 天前 添加了label:cann-cla/yes
CANN-robot
CANN-robot成员
18 天前 评论:

CLA检查已通过,详情可参考这里

likedislike