已开启
【代码侦探Challenge05】完成Qianqiuer的MulCustom逐元素乘法算子 #2424
【代码侦探Challenge05】完成Qianqiuer的MulCustom逐元素乘法算子 #2424
已开启
Qianqiuer创建于 9月1日
Qianqiuer
9月1日

变更描述 / Description

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

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

提交范围仅包含任务书要求的 mul_custom.asc、CMakeLists.txt 和 run.sh,不包含构建产物。

改动类型 / Change Type

测试信息 / Testing

  • 硬件:Ascend 910B3,NPU 0
  • 架构:AArch64
  • CANN:9.0.0
  • 命令:ASCEND_RT_VISIBLE_DEVICES=0 bash run.sh

验证结果:

[100%] Built target mul_test
Output: 2.76 2.76 2.76 2.76 2.76 2.76 2.76 2.76 2.76 2.76 2.76 2.76 2.76 2.76 2.76 2.76 2.76 2.76 2.76 2.76 ...
Golden: 2.76 2.76 2.76 2.76 2.76 2.76 2.76 2.76 2.76 2.76 2.76 2.76 2.76 2.76 2.76 2.76 2.76 2.76 2.76 2.76 ...
[Success] Case accuracy is verification passed.

检查清单 / Checklist

likedislike
合并受阻
QQianqiuer
9月1日 创建了 pull request,commit f2aea5e5
QQianqiuer
9月1日 关联了issue:代码侦探(第五期)|补全算子代码有奖,周周赢取定制礼品!
atomgit-bot
atomgit-bot
9月1日 评论:

变更摘要

本 PR 完成 CANN Code Detective Challenge05 中 MulCustom 逐元素乘法算子(z[i] = x[i] * y[i]),提交范围包含 mul_custom.asc、CMakeLists.txt 与 run.sh(不含构建产物)。mul_custom.asc 实现了设备侧 KernelMul 类(8 核数据切分、Double Buffer 双缓冲、CopyIn -> Compute -> CopyOut 流水)与主机侧 kernel_mul 封装(ACL 初始化、内存管理、Kernel 直调、流同步与结果回拷),并通过 main 中的 VerifyResult 完成真机精度验证。

主要改动

  • 设备侧算子实现(mul_custom.asc): 新增 KernelMul 类,在 Init 中按 GetBlockNum()/GetBlockIdx() 计算每核 blockLength 及 GM 地址偏移(blockOffset),并以 BUFFER_NUM = 2 的 TQue(inQueueX/inQueueY/outQueueZ)初始化 Double Buffer。
  • 流水处理流程: Process 按 tileNum * BUFFER_NUM 次循环依次执行 CopyIn → Compute → CopyOut:CopyIn 通过 DataCopy 将 GM 数据搬入 UB,Compute 调用 AscendC::Mul 完成逐元素乘法,CopyOut 将结果从 UB 写回 GM。
  • Kernel 入口与 Host 侧封装: 新增 __global__ __aicore__ 入口函数 mul_custom 及 kernel_mul 函数,完成 aclInit/aclrtSetDevice 初始化、aclrtMalloc/aclrtMallocHost 内存分配、mul_custom<<<blockDim, nullptr, stream>>> Kernel 直调、aclrtSynchronizeStream 同步与 ACL_MEMCPY_DEVICE_TO_HOST 结果回拷,并逐一释放资源。
  • 结果验证: main 构造 1.2f * 2.3f 的输入与 golden 向量,调用 kernel_mul 后由 VerifyResult 逐元素比较并输出 [Success]/[Failed] 判定。
  • 构建运行脚本(run.sh): 新增脚本,负责激活 CANN 环境(source "$ASCEND_TOOLKIT_HOME/set_env.sh")、创建 build 目录并通过 cmake + make 构建后运行 ./mul_test。
likedislike
不准确?
CANN-robot
CANN-robot成员
9月1日 评论:

Hi @Qianqiuer, 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
9月1日 评论:

代码审查

✅ 未发现问题

likedislike
不准确?
CANN-robotCANN-robot成员
9月1日 添加了label:cann-cla/yes
CANN-robot
CANN-robot成员
9月1日 评论:

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

💡 Tip:

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

CLA Signature Pass

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

likedislike
QQianqiuer
9月1日 修改了pull request 的描述