已开启
【代码侦探Challenge05】完成MulCustom逐元素乘法算子 #3609
【代码侦探Challenge05】完成MulCustom逐元素乘法算子 #3609
已开启
JeffDing创建于 16 天前
JeffDing
JeffDing
16 天前

Challenge05 · MulCustom 逐元素乘法算子

按任务书要求补全 mul_custom.asc,实现 Ascend C 逐元素乘法算子 z[i] = x[i] * y[i]。

实现要点

  • Vector 编程范式:CopyIn → Compute → CopyOut 三段式流水线
  • Double Buffer:TQue<TPosition::VECIN/VECOUT, BUFFER_NUM=2>,数据搬运与计算并行
  • 多核数据切分:GetBlockNum() / GetBlockIdx() + SetGlobalBuffer 设置每核偏移
  • Mul 指令:AscendC::Mul(zLocal, xLocal, yLocal, tileLength) 完成逐元素乘法
  • Host 侧:aclrtMalloc/Memcpy + kernel 直调 mul_custom<<<blockDim, nullptr, stream>>>

提交文件

  • mul_custom.asc —— 算子核函数实现
  • CMakeLists.txt —— 构建脚本
  • run.sh —— 编译运行脚本

主要改动

本 PR 由 @JeffDing 提交,目标是补全 mul_custom.asc,实现 Ascend C 逐元素乘法算子 z[i] = x[i] * y[i]。该实现采用 Vector 编程范式的 CopyIn → Compute → CopyOut 三段式流水线,通过 TQue<TPosition::VECIN/VECOUT, BUFFER_NUM=2> 双缓冲实现数据搬运与计算并行,并借助 GetBlockNum() / GetBlockIdx() + SetGlobalBuffer 完成多核数据切分,最终以 AscendC::Mul 指令完成逐元素乘法。Host 侧使用 aclrtMalloc/Memcpy 分配与拷贝数据,并直接以 mul_custom<<<blockDim, nullptr, stream>>> 方式调用核函数。
主要改动

  • 算子核函数实现:在 mul_custom.asc 中按 Vector 编程范式实现 MulCustom 算子的 CopyIn → Compute → CopyOut 三段式流水线,完成 z[i] = x[i] * y[i] 的逐元素乘法逻辑。
  • 双缓冲机制:使用 TQue<TPosition::VECIN/VECOUT, BUFFER_NUM=2> 配置输入输出队列,使数据搬运与计算并行执行。
  • 多核数据切分:通过 GetBlockNum() / GetBlockIdx() 结合 SetGlobalBuffer 设置每核数据偏移,实现多核并行处理。
  • Mul 指令调用:以 AscendC::Mul(zLocal, xLocal, yLocal, tileLength) 完成逐元素乘法计算。
  • Host 侧调用与构建脚本:Host 侧采用 aclrtMalloc/Memcpy 管理数据,以 kernel 直调方式启动;并新增 CMakeLists.txt 构建脚本与 run.sh 编译运行脚本以支撑算子编译与运行验证。
likedislike
合并受阻
JeffDingJeffDing
16 天前 创建了 pull request,commit 4061673b
CANN-robotCANN-robot成员
16 天前 添加了label:cann-cla/yes
CANN-robot
CANN-robot成员
16 天前 评论:

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, luzx66) ❌ (0/1)(You can also ask: yanhf, yanyawen, jxlang, 王艳秋, shaoyf)

💡 Tip:

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

CLA Signature Pass

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

likedislike
JeffDingJeffDing
16 天前 修改标题为 “【代码侦探Challenge05】完成Qianqiuer的MulCustom逐元素乘法算子”,原标题为“add MulCustom Code”
JeffDingJeffDing
16 天前 修改标题为 “【代码侦探Challenge05】完成MulCustom逐元素乘法算子”,原标题为“【代码侦探Challenge05】完成Qianqiuer的MulCustom逐元素乘法算子”
JeffDingJeffDing
16 天前 修改了pull request 的描述
JeffDingJeffDing
16 天前 修改了pull request 的描述
JeffDingJeffDing
16 天前 关联了issue:[Feature]: 【代码侦探Challenge05】完成MulCustom逐元素乘法算子