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

当前PR是否有AI参与:

[ ] 否

[x] 是

  1. AI Agent 平台:OpenAI Codex
  2. AI 模型:GPT-5(OpenAI)
  3. Prompt上下文:依据 Challenge05 任务书及 MulCustom 模板中的补充提示,完成 Ascend C Kernel 的多核切分、Double Buffer、CopyIn → Compute → CopyOut 流程、Host 侧 ACL 调用,并在 Ascend 910B2 / CANN 8.5.2 环境完成真机精度验证。

实现概述

  • 补全 MulCustom 的 Kernel 初始化、分块和 Double Buffer 队列管理。
  • 按 CopyIn → Compute → CopyOut 流程实现 float32 逐元素乘法。
  • 补全 Host 侧内存申请、数据搬运、Kernel 启动、同步及精度校验。
  • 提交内容严格限定为题目要求的 3 个文件,无构建产物。

自验证

  • 设备:单卡 Ascend 910B2(64 GB HBM)
  • 架构:aarch64
  • CANN Toolkit:8.5.2
  • 构建结果:[100%] Built target mul_test
  • 数值结果:Output 与 Golden 均为 2.76
  • 精度结果:[Success] Case accuracy is verification passed.

MulCustom_verify.png

likedislike
合并受阻
Ggang1022
18 天前 创建了 pull request,commit b38fa70c
atomgit-bot
atomgit-bot
18 天前 评论:

变更摘要

本 PR 为「代码侦探 Challenge05」的提交,目标是补全 MulCustom 逐元素乘法算子(z[i] = x[i] * y[i])。改动新增了 Kernel 侧的初始化、分块(Tiling)与双缓冲(Double Buffer)队列管理,按 CopyIn → Compute → CopyOut 流程完成 float32 逐元素乘法,并在 Host 侧补全了内存申请、数据搬运、Kernel 启动、流同步及精度校验逻辑,另附带一键构建脚本 run.sh;整个实现被严格限定在题目要求的 3 个文件内。

主要改动

  • 算子核心流程实现:新增 KernelMul 算子类,实现 Init(按 GetBlockNum() 分块并初始化三个 GlobalTensor 与队列缓冲)、Process(循环驱动 CopyInComputeCopyOut),其中 Compute 通过 AscendC::Mul 完成 z = x * y,数据流为 GM → UB → GM;__global__ 入口 mul_custom 接收 MulCustomTilingDatatotalLengthtileNum)并调度算子执行。
  • 双缓冲与队列管理:通过 BUFFER_NUM = 2 定义 TPipe 及输入队列 inQueueX/inQueueY、输出队列 outQueueZ,在 CopyIn/CopyOut 中使用 AllocTensorEnQueDeQueFreeTensor 维护数据搬运与计算的重叠,提升流水效率。
  • Host 侧驱动逻辑:在 kernel_mul 中补全 Host 端流程——aclInit/aclrtSetDevice 初始化、aclrtMalloc 申请显存与 aclrtMallocHost 申请主机内存、aclrtMemcpy 完成 H2D/D2H 搬运、以 <<<blockDim, nullptr, stream>>> 启动 Kernel、aclrtSynchronizeStream 同步后统一释放资源并 aclFinalize
  • 精度校验与测试入口:新增 VerifyResult,打印 Output/Golden 前若干元素并通过 std::equal 逐元素比对,输出 [Success]/[Failed] 判定结果;main 以固定长度(8 * 2048)与常量 1.2f2.3f 构造输入并生成期望的乘法 golden 值,返回校验结果作为进程退出码。
  • 一键构建脚本:新增 run.sh,激活 CANN 环境(source set_env.sh),在 build 目录执行 cmakemake 构建出 mul_test 并运行可执行文件完成验证。
likedislike
不准确?
CANN-robot
CANN-robot成员
18 天前 评论:

Hi @gang1022, 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
18 天前 评论:

代码审查

✅ 未发现问题

likedislike
不准确?
CANN-robotCANN-robot成员
18 天前 添加了label:cann-cla/no
CANN-robot
CANN-robot成员
18 天前 评论:

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

💡 Tip:

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

CLA Signature Pass

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

likedislike
gang1022
18 天前 评论:

/compile

likedislike
Ggang1022
18 天前 预合并成功(commit_id: 2345aabb35e8204960c97db3e5b604c8c662d674)
Ggang1022
18 天前 强制推送  1 个提交:4fa6ada9-feat: complete Challenge05 MulCustom
Ggang1022
18 天前 预合并成功(commit_id: fd8c0b664c225d5c4a688bae03c428834cba5e5a)
gang1022
18 天前 评论:

/check-cla

likedislike
CANN-robotCANN-robot成员
18 天前 删除了label:cann-cla/no
CANN-robotCANN-robot成员
18 天前 添加了label:cann-cla/yes
CANN-robotCANN-robot成员
18 天前 删除了label:cann-cla/yes
CANN-robotCANN-robot成员
18 天前 添加了label:cann-cla/yes
CANN-robot
CANN-robot成员
18 天前 评论:

CLA检查已通过,详情可参考这里

likedislike
gang1022
18 天前 评论:

/compile

likedislike
Ggang1022
18 天前 预合并成功(commit_id: 2e16e714dc7ee83a66b83a80547061cc60f7c35a)
此处折叠了7条事件消息 查看更多
CANN-robotCANN-robot成员
18 天前 添加了label:ai-compliance-failed
CANN-robot
CANN-robot成员
18 天前 评论:

AI Declaration Check Failed

@gang1022, AI declaration is not compliant. AI tool: Codex

Please check:

  1. The AI tool and model declared in the PR description must be real.
  2. Commit messages must include the AI model, and it must be consistent with the PR description. ⚠️
likedislike
Ggang1022
18 天前 修改了pull request 的描述
CANN-robotCANN-robot成员
18 天前 删除了label:ai-compliance-failed
CANN-robotCANN-robot成员
18 天前 添加了label:ai-compliance-successful