Pull Request已成功合入, 合并人@CANN-robot
(感谢 小东 的贡献)变更摘要
本 PR 完成「代码侦探 Challenge05 - MulCustom」逐元素乘法算子的实现:基于 Ascend C 编写 mul_custom.asc 内核,通过 Tiling 切分与 Double Buffer(BUFFER_NUM=2)构建 CopyIn/Compute/CopyOut 流水线,使用 AscendC::Mul 指令计算 z = x * y,数据通路为 GM(x,y) → UB → Compute → UB → GM(z);Host 侧通过 ACL 接口完成内存分配、数据搬运、内核调用与结果校验,并在昇腾 910B(CANN 9.1.0)上以 x=1.2、y=2.3 验证输出与 golden 一致。此外,本 PR 的改动集还一并包含同作者 Challenge03 的 CoshCustom 双曲余弦算子(cosh_custom.asc 及对应 run.sh)。
主要改动
- 新增 MulCustom 算子内核:
mul_custom.asc中定义MulCustomTilingData(字段totalLength、tileNum)与KernelMul类,Init按核号GetBlockIdx()对 GM 地址做偏移切分并为输入输出队列申请双缓冲 UB 内存,Compute使用AscendC::Mul完成逐元素乘法z = x * y,Process按tileNum * BUFFER_NUM次迭代执行 CopyIn/Compute/CopyOut 三级流水。 - 新增 Host 侧调用与验证逻辑:
kernel_mul通过 ACL API(aclInit、aclrtMalloc、aclrtMemcpy、aclrtSynchronizeStream等)完成 Host/Device 数据搬运,以mul_custom<<<blockDim, nullptr, stream>>>调用内核并释放资源;main构造 x=1.2、y=2.3 的输入与 golden,经VerifyResult校验输出一致性。 - 新增构建脚本:
run.sh激活 CANN 环境(ASCEND_TOOLKIT_HOME/set_env.sh)、执行 cmake/make 编译并运行./mul_test完成端到端测试。 - 附带 Challenge03 CoshCustom 实现:
cosh_custom.asc使用AscendC::Exp、Muls、Add计算cosh(x) = (Exp(x) + Exp(-x)) / 2,通过TBuf管理两个中间结果,并提供对应的run.sh构建脚本。


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
✅ Congratulations! All modules have met the lgtm and approve requirements.
Module Approval Details
| module | lgtm status | approve status |
|---|---|---|
| repo-cann/cann-outreach | ✅ shaoyf, 傅涛 (2/2) | ✅ shaoyf, 傅涛 (2/1) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)
CLA Signature Pass
ciknife, thanks for your pull request. All authors of the commits have signed the CLA. 👍


题目
代码侦探 Challenge05 - MulCustom 逐元素乘法算子
实现内容
验证结果
![验证截图]
关联 Issue
https://gitcode.com/cann/cann-learning-hub/issues/700