Open
【CANN社区任务】新增 aclsparseAxpyi 算子(Atlas A2/A3 arch22 & Ascend 950 arch35 + PyTorch 封装) #567
【CANN社区任务】新增 aclsparseAxpyi 算子(Atlas A2/A3 arch22 & Ascend 950 arch35 + PyTorch 封装) #567
Open
huier325Add on 4 days ago
huier325
huier325
4 days ago

任务:12月社区任务-aclsparseAxpyi算子开发(950/910)
设计文档PR:https://gitcode.com/cann/cann-ops-competitions/pull/3874
账号:huier325
实现:双架构(Atlas A2/A3 arch22 零Workspace纯PIPE_V流水线 + Ascend 950 arch35 SIMT 4路展开与位精确Copy)+ PyTorch扩展 + C++/Python全量测试与Benchmark,双架构Release零告警。
自测(150/150 PASS):950仿真9/9、A3 C++ 18/18、官方pytest 43/43、全量TC-01~11 80/80。
性能:A3 24组Shape×DType较同机torch_npu提速7.60x-48.46x,10M/500k FP32达0.1678ms(aiv_mte3_ratio=0.952)。

likedislike
Merge blocked
huier325huier325
4 days ago Created pull request, commit 1beab3f9
atomgit-bot
atomgit-bot
4 days ago Comments:

🤖 正在生成合并请求摘要,请稍候…

likedislike
Incorrect?
CANN-robot
CANN-robotCollaborators
4 days ago Comments:

Hi @huier325, welcome to submitting your first PR to CANN!

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.
%!(EXTRA string=https://atomgit.com/cann/community/blob/master/en/sig-infrastructure/command.md)

likedislike
atomgit-bot
atomgit-bot
4 days ago Comments:

🤖 AI 代码检视正在进行中,请稍候…

likedislike
Incorrect?
CANN-robotCANN-robotCollaborators
4 days ago Added label: stat/needs-squash
CANN-robotCANN-robotCollaborators
4 days ago Added label: cann-cla/yes
CANN-robot
CANN-robotCollaborators
4 days ago Comments:

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/ops-sparse ❌ (0/2)(You can also ask: chenbinbin199309, fanzhaoyun001, xutianze, 朱如意, HuangKun8682) ❌ (0/1)(You can also ask: 唐超, 朱志明, 唐超力, HuangKun8682, fanzhaoyun001)

💡 Tip:

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

CLA Signature Pass

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

likedislike
CANN-robotCANN-robotCollaborators
4 days ago Set HuangKun8682,chaotang233,chenbinbin199309,QK_25415,MaskHunter2008,songkai111,xutianze,wangzitao_leo,nino888,rueenov11,demoauguste,fanzhaoyun001,zizhongchen as approver
atomgit-bot
atomgit-bot
4 days ago Comments:

⚠️ 本次变更过大(22 个可审文件、3876 行,预估需 4 轮分片审查),已超出 AI 代码评审的处理范围,本次跳过。建议拆分为更小的 PR 以获得有效评审。

likedislike
Incorrect?
CANN-robotCANN-robotCollaborators
4 days ago Set HuangKun8682,chaotang233,chenbinbin199309,QK_25415,MaskHunter2008,songkai111,xutianze,wangzitao_leo,nino888,rueenov11,demoauguste,fanzhaoyun001,zizhongchen as approver
huier325
huier325
4 days ago Comments:

compile

likedislike
huier325huier325
4 days ago Pre merge succeeded (commit_id: 69b1ba9d9c8f4c4b01624dfb7f1af0f9f15ea46d)
atomgit-bot
atomgit-bot
4 days ago Comments:

⚠️ 本次变更过大(22 个可审文件、3876 行,预估需 4 轮分片审查),已超出 AI 代码评审的处理范围,本次跳过。建议拆分为更小的 PR 以获得有效评审。

likedislike
Incorrect?
CANN-robotCANN-robotCollaborators
4 days ago Added label: ci-pipeline-running
CANN-robot
CANN-robotCollaborators
4 days ago Comments:

流水线任务触发成功
任务链接 [499972c49a18483d8d3c32a873f87508][流水线指导]

任务名称状态日志下载链接
SCA ✅ SUCCESS >>>>>
antipoison ✅ SUCCESS >>>>>
Check_Pr ✅ SUCCESS >>>>>
pre_comment ✅ SUCCESS >>>>>
Compile_Ascend_X86_A2 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_A5 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM_A2 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM_A5 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_A2_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_A5_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM_A2_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM_A5_ubuntu24 ✅ SUCCESS >>>>> >>>>>
codecheck ❌ FAILED >>>>>
codecheck_style ✅ SUCCESS >>>>>
pre-commit ✅ SUCCESS
likedislike
CANN-robotCANN-robotCollaborators
4 days ago Removed label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
4 days ago Added label: ci-pipeline-failed
fanzhaoyun001
fanzhaoyun001Collaborators3 days agoStart code review1
sparse/axpyi/arch22/axpyi_host.cpp
@@ -0,0 +187,4 @@
187+ const uint64_t valBytes = static_cast<uint64_t>(nnz) * elemBytes;
188+ const uint64_t idxElemBytes = (idxType == ACL_SPARSE_INDEX_64I) ? sizeof(int64_t) : sizeof(int32_t);
189+ const uint64_t idxBytes = static_cast<uint64_t>(nnz) * idxElemBytes;
190+ if (AxpyiRangesOverlap(yDstPtr, yBytes, xValPtr, valBytes) ||
fanzhaoyun001
fanzhaoyun0013 days agoComments:

[Major] 内存别名校验发生在 copy kernel 入队之后,校验形同虚设

L134-L174 已经根据 ySrcPtr != yDstPtr 异步入队了 axpyi_copy_kernel_do 写入 yDst,之后 L190-L194 才用 AxpyiRangesOverlap 校验 yDst 与 xVal/xInd 是否重叠。若 yDst 与 xVal/xInd 确实重叠,此时 copy 已在 stream 上执行,会先覆写稀疏向量输入,再返回 ACL_SPARSE_STATUS_INVALID_VALUE,既不满足“非法输入不产生副作用”,还可能让调用方在释放输入后遭遇设备侧 use-after-free。建议把所有空指针/别名/参数校验整体前移到任何 kernel 入队之前,校验通过后再执行 copy 与 scatter-add。

likedislike
fanzhaoyun001
fanzhaoyun001Collaborators3 days agoStart code review1
sparse/axpyi/arch22/axpyi_host.cpp
@@ -0,0 +131,4 @@
131+ const uint64_t yBytes = static_cast<uint64_t>(yLen) * elemBytes;
132+ 
133+ // 1. Out-of-place copy via AIV bulk DataCopy (full AIV-to-L2/HBM bandwidth, bit-exact).
134+ if (ySrcPtr != yDstPtr && yLen > 0) {
fanzhaoyun001
fanzhaoyun0013 days agoComments:

[Major] 异地模式只判断指针不等,未校验 ySrc/yDst 区间部分重叠

if (ySrcPtr != yDstPtr && yLen > 0) 仅区分原地/异地,未检测 ySrc 与 yDst 两个 yBytes 区间是否存在部分重叠。copy 核按块 DataCopy 语义等价于 memcpy,要求源目区间不重叠;当调用方传入如 yDst = ySrc + 1 的部分重叠缓冲区时,会静默产生错误结果。建议对异地模式追加 AxpyiRangesOverlap(ySrcPtr, yBytes, yDstPtr, yBytes) 校验并返回 INVALID_VALUE。

likedislike
fanzhaoyun001
fanzhaoyun001Collaborators3 days agoStart code review1
sparse/axpyi/arch22/axpyi_host.cpp
@@ -0,0 +70,4 @@
70+ 
71+inline uint32_t GetCachedAivCoreCount()
72+{
73+ static uint32_t cached = 0u;
fanzhaoyun001
fanzhaoyun0013 days agoComments:

[Minor] AIV 核数缓存为非线程安全的函数内 static 且跨 device 复用

GetCachedAivCoreCount 用未加锁的 static uint32_t cached 缓存结果,多线程首次并发调用存在数据竞争(UB);同时该缓存按进程全局保存、不区分 deviceId,多卡场景下不同设备 AIV 核数不同会返回错误核数,影响 blockNum 切分。建议改用 std::once_flag/std::atomic 保证线程安全,或按 deviceId 维度做缓存。

likedislike