已开启
【代码侦探Challenge05】补全gcw_93rlw6ed的MulCustom逐元素乘法算子 #2433
gcw_93rlw6ed创建于 17 天前
【代码侦探Challenge05】补全gcw_93rlw6ed的MulCustom逐元素乘法算子 #2433
已开启
合并受阻
17 天前 创建了 pull request,commit 0e90bec0
atomgit-bot
17 天前 评论:
17 天前 评论:
变更摘要
本 PR 为「代码侦探第五期」Challenge05 补全逐元素乘法算子 z[i] = x[i] * y[i],参照课程第 2 章 Add 算子范式在 mul_custom.asc 中实现 KernelMul 算子类、mul_custom kernel 入口、Host 侧封装 kernel_mul 与 main 验证流程,并新增 run.sh 构建运行脚本;整体逻辑为 8 核并行 × 每核 8 tile × BUFFER_NUM=2 双缓冲(16384 = 8×8×2×128 元素,整除无尾块),最终通过 VerifyResult 对输出与 golden 做精度比对。
主要改动
KernelMul算子类实现:Init按blockLength = totalLength / GetBlockNum()做多核切分并计算tileLength,SetGlobalBuffer按GetBlockIdx()偏移各核 Global Memory,pipe.InitBuffer为inQueueX/inQueueY/outQueueZ三个队列分配BUFFER_NUM=2双缓冲;Process以tileNum * BUFFER_NUM次迭代驱动 CopyIn → Compute → CopyOut 三段式流水线。CopyIn/Compute/CopyOut流水线阶段:CopyIn经AllocTensor+DataCopy将 GM 数据搬入 UB 后EnQue;Compute出队输入后调用AscendC::Mul(zLocal, xLocal, yLocal, tileLength)计算并EnQue、FreeTensor;CopyOut出队结果并DataCopy写回 GM 后释放。- kernel 入口
mul_custom:接收MulCustomTilingData(totalLength/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。


不准确?
atomgit-bot
17 天前 评论:
17 天前 评论:
17 天前 添加了label:cann-cla/yes
CANN-robot
17 天前 评论:
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
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)


CANN-robot
17 天前 评论:
17 天前 评论:
变更描述 / Description
参与【代码侦探第五期】活动,补全 Challenge05-MulCustom 逐元素乘法算子
z[i] = x[i] * y[i],基于课程第2章 Add 算子范式完成:KernelMul::Init:多核数据切分(blockLength = totalLength / GetBlockNum())、tileLength计算、SetGlobalBuffer按核偏移、pipe.InitBuffer为三个队列分配 BUFFER_NUM=2 双缓冲Process:tileNum * BUFFER_NUM次迭代的 CopyIn → Compute → CopyOut 三段式流水线CopyIn:AllocTensor→DataCopy从 GM 搬入 UB →EnQueCompute:DeQue→AscendC::Mul(zLocal, xLocal, yLocal, tileLength)→EnQue→FreeTensorCopyOut:DeQue→DataCopy搬回 GM →FreeTensorKERNEL_TASK_TYPE_DEFAULT(KERNEL_TYPE_AIV_ONLY)显式指定 AIV-only 任务类型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
关联 Issue / Related Issues
测试信息 / Testing
bash run.sh):检查清单 / Checklist
自验证报告 / Self-verification
代码仅包含任务书要求的三个文件(mul_custom.asc、CMakeLists.txt、run.sh),未提交 build 产物。精度验证逻辑与任务书预期输出一致([Success] Case accuracy is verification passed.)。