已开启
【代码侦探Challenge05】补全gcw_93rlw6ed的MulCustom逐元素乘法算子 #2433
【代码侦探Challenge05】补全gcw_93rlw6ed的MulCustom逐元素乘法算子 #2433
已开启
gcw_93rlw6ed创建于 17 天前
gcw_93rlw6ed
17 天前

变更描述 / Description

参与【代码侦探第五期】活动,补全 Challenge05-MulCustom 逐元素乘法算子 z[i] = x[i] * y[i],基于课程第2章 Add 算子范式完成:

  • Kernel 侧 KernelMul::Init:多核数据切分(blockLength = totalLength / GetBlockNum())、tileLength 计算、SetGlobalBuffer 按核偏移、pipe.InitBuffer 为三个队列分配 BUFFER_NUM=2 双缓冲
  • ProcesstileNum * BUFFER_NUM 次迭代的 CopyIn → Compute → CopyOut 三段式流水线
  • CopyInAllocTensorDataCopy 从 GM 搬入 UB → EnQue
  • ComputeDeQueAscendC::Mul(zLocal, xLocal, yLocal, tileLength)EnQueFreeTensor
  • CopyOutDeQueDataCopy 搬回 GM → FreeTensor
  • kernel 入口:KERNEL_TASK_TYPE_DEFAULT(KERNEL_TYPE_AIV_ONLY) 显式指定 AIV-only 任务类型
  • Host 侧 kernel_mul:ACL 初始化、Host/Device 内存申请、H2D/D2H 拷贝、mul_custom<<<8, nullptr, stream>>> 启动、流同步、资源释放(各步骤含错误检查与回滚)
  • main:调用 kernel_mul 并通过 VerifyResult 精度验证

任务书参考:2026/CANN-Code-Detective/Challenge05-MulCustom/README.md
活动 issue:cann/cann-learning-hub#700

改动类型 / Change Type

  • References cann/cann-learning-hub#700

测试信息 / Testing

  • 数据规模 totalLength = 8 * 2048 = 16384,blockDim = 8,tileNum = 8,BUFFER_NUM = 2(16384 = 8核 × 8tile × 2buffer × 128 元素,整除无尾块)
  • 测试输入 x = 1.2f,y = 2.3f,期望输出 golden = 2.76f
  • 预期运行输出(bash run.sh):
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

自验证报告 / Self-verification

代码仅包含任务书要求的三个文件(mul_custom.asc、CMakeLists.txt、run.sh),未提交 build 产物。精度验证逻辑与任务书预期输出一致([Success] Case accuracy is verification passed.)。

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

变更摘要

本 PR 为「代码侦探第五期」Challenge05 补全逐元素乘法算子 z[i] = x[i] * y[i],参照课程第 2 章 Add 算子范式在 mul_custom.asc 中实现 KernelMul 算子类、mul_custom kernel 入口、Host 侧封装 kernel_mulmain 验证流程,并新增 run.sh 构建运行脚本;整体逻辑为 8 核并行 × 每核 8 tile × BUFFER_NUM=2 双缓冲(16384 = 8×8×2×128 元素,整除无尾块),最终通过 VerifyResult 对输出与 golden 做精度比对。

主要改动

  • KernelMul 算子类实现InitblockLength = totalLength / GetBlockNum() 做多核切分并计算 tileLengthSetGlobalBufferGetBlockIdx() 偏移各核 Global Memory,pipe.InitBufferinQueueX/inQueueY/outQueueZ 三个队列分配 BUFFER_NUM=2 双缓冲;ProcesstileNum * BUFFER_NUM 次迭代驱动 CopyIn → Compute → CopyOut 三段式流水线。
  • CopyIn/Compute/CopyOut 流水线阶段CopyInAllocTensor + DataCopy 将 GM 数据搬入 UB 后 EnQueCompute 出队输入后调用 AscendC::Mul(zLocal, xLocal, yLocal, tileLength) 计算并 EnQueFreeTensorCopyOut 出队结果并 DataCopy 写回 GM 后释放。
  • kernel 入口 mul_custom:接收 MulCustomTilingDatatotalLength/tileNum)结构体参数,通过 KERNEL_TASK_TYPE_DEFAULT(KERNEL_TYPE_AIV_ONLY) 显式指定 AIV-only(Vector 核)任务类型。
  • Host 侧 kernel_mul 封装:覆盖 ACL 初始化、Host/Device 内存申请、H2D/D2H 拷贝、mul_custom<<<8, nullptr, stream>>> 启动、流同步与资源释放的完整生命周期,各步骤均带错误检查与逐级回滚释放逻辑。
  • 验证与运行脚本main 构造 16384 长度输入(x=1.2f、y=2.3f)调用 kernel_mul 并由 VerifyResult 打印 Output/Golden 并判定精度;新增 run.sh 负责 source CANN 环境、cmake/make 构建并执行 ./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, 田晓亮, luzx66, shaoyf, li-shengxian3) ❌ (0/1)(You can also ask: yanhf, 傅涛, shaoyf, li-shengxian3, 王艳秋)

💡 Tip:

  • Committer can comment /approve or /lgtm
  • Commenting /approve implies both code review (lgtm) and intent to merge (approve)
likedislike
CANN-robot
CANN-robot成员
17 天前 评论:

CLA Signature Pass

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

likedislike