Merged
feat(sparse_flash_mla): add SWA DSpark ori sparse support #9384
feat(sparse_flash_mla): add SWA DSpark ori sparse support #9384
Merged
何宇航Add on Jul 30
何宇航
何宇航Collaborators
Jul 30

描述

关联的Issue

测试

文档更新

类型标签

likedislike
Pull Request has been successfully merged by CANN-robot.
(Thank you for 何宇航's contribution.)
何宇航何宇航Collaborators
Jul 30 Created pull request, commit 7551a16d
atomgit-bot
atomgit-bot
Jul 30 Comments:

变更摘要

此 PR 将原先独立的 ORI_SPARSE_TEMPLATE_MODE 和 ORI_CMP_SPARSE_TEMPLATE_MODE 模板模式移除,改为将 ori sparse(DSpark 风格稀疏索引)功能直接集成到 SWA 模板模式中。核心变更在于:当 hasOriSparseIndices 为真时,kernel 不再依赖窗口掩码(oriWinLeft/oriWinRight)来决定注意力范围,而是通过外部传入的稀疏索引(oriSparseIndices)和 topk 长度(oriTopkLength)动态选择参与计算的 KV token。Vector 核负责预加载稀疏索引并将对应的 KV 行拷贝到 GM 合并工作区,Cube 核随后从该工作区读取数据进行 MatMul 计算,两者通过跨核同步标志协调。

主要改动

  • 移除独立稀疏模板模式:在 sparse_flash_mla_tiling.h 的 SMLATemplateMode 枚举中删除 ORI_SPARSE_TEMPLATE_MODE 和 ORI_CMP_SPARSE_TEMPLATE_MODE,在 sparse_flash_mla.cpp 的 kernel 入口中移除对应的模板分支,将稀疏场景统一走 SWA / CSA 路径。

  • 新增稀疏索引与 topk 长度支持:在 tiling 数据结构(SparseFlashMlaSwaParams)、ConstInfo、SMLAInfoParser 等多处新增 hasOriSparseIndices、oriSparseIndexWidth、hasOriTopkLength 字段;kernel Init 签名中新增 oriSparseIndices、oriTopkLength、cmpTopkLength 输入参数。

  • Vector 核新增稀疏预处理管线 ProcessVec0L:在 sparse_flash_mla_swa_block_vector.h 中新增 ProcessVec0L、InitVec0GlobalTensor、GetOriSparseKeyGmOffset、CopyOriSparseRowToMerge 等方法,负责从 oriSparseIndices 读取逻辑索引、查 PA block table 获取物理偏移,并将对应 KV 行拷贝到 GM 合并缓冲区(kvMergeGm_)。

  • Cube 核新增合并缓冲区读取路径:在 sparse_flash_mla_swa_block_cube.h 的 ComputeMm1/ComputeMm2 中,当 hasOriSparseIndices 为真时,跳过原有的 PA block table 路径,改为从以 MERGE_CACHE_GM_BUF_NUM = 3 槽位轮换的 kvMergeGm_ 直接读取预拷贝的 KV 数据。

  • 掩码计算逻辑适配稀疏模式:在 sparse_flash_mla_swa_block_vector.h 的 ElewiseCompute 和 sparse_flash_mla_swa_kernel.h 的 ProcessBalance/UpdateInnerLoopCond 中,新增 hasOriSparseIndices 分支,使用 oriTopkLength 和稀疏索引逐行判断有效列范围并设置 mask,替代原有的滑动窗口左右边界计算。

likedislike
Incorrect?
CANN-robotCANN-robotCollaborators
Jul 30 Added label: cann-cla/yes
CANN-robot
CANN-robotCollaborators
Jul 30 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.
For more, you also can visit HICANN.


PR Approval Progress

✅ Congratulations! All modules have met the lgtm and approve requirements.

Module Approval Details

module lgtm status approve status
attention ✅ 黄俊健, yuhao_ (2/2) ✅ 黄俊健 (1/1)

💡 Tip:

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

CLA Signature Pass

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

likedislike
CANN-robotCANN-robotCollaborators
Jul 30 Set hz36amy_00,coder_linx,juyangokok,monologue815,xuanyuandy,crystalhu,yu-xinjie62,huangwei791,jiang-lirui,yang-binrong,Allan_Yu,gitee-duhuiping,claire8090,liudan12,wangzhe123456789,gitcode-chenjiao,cc-z,shen_weiling,Ww7012,zhouwenfang,gaoxiang618,songjionghui,wenxin_fight,miaofangzheng,mabing1118,tang-hao-hw-gitcode,haijie_699874,wuyao51511,zzy__,yuhao_,L_Euler,caiwenwen as approver
189 messages are collapsed here。 See more
monologue815
monologue815Collaborators
Aug 17 Comments:

/approve

likedislike
CANN-robotCANN-robotCollaborators
Aug 17 Added label: approved
CANN-robot
CANN-robotCollaborators
Aug 17 Comments:

The MR can not be merged, because of CodeReview discussion not resolved

If you want to solve this problem, you can click here to do it in the FAQs.

likedislike
何宇航何宇航Collaborators
Aug 17 Resolved final issue
CANN-robotCANN-robotCollaborators
Aug 17 Merged pull request