Merged
smlag支持sequseq/sequsek #11087
memorecoolAdd on Sep 2
smlag支持sequseq/sequsek #11087
Merged
Merged fromDeleted :smlag_eodintocann/ops-transformermaster
Total: 8 files changed+240-96
| @@ -80,6 +80,12 @@ TILING_DATA_FIELD_DEF(uint32_t, selectedBlockSize); | |||
| 80 | TILING_DATA_FIELD_DEF(int64_t, cmpRatio); | 80 | TILING_DATA_FIELD_DEF(int64_t, cmpRatio); |
| 81 | TILING_DATA_FIELD_DEF(int64_t, oriWinLeft); | 81 | TILING_DATA_FIELD_DEF(int64_t, oriWinLeft); |
| 82 | TILING_DATA_FIELD_DEF(int64_t, oriWinRight); | 82 | TILING_DATA_FIELD_DEF(int64_t, oriWinRight); |
| 83 | +TILING_DATA_FIELD_DEF(uint8_t, hasUsedSeqQ); | ||
| 84 | +TILING_DATA_FIELD_DEF(uint8_t, hasUsedSeqOriKV); | ||
| 85 | +TILING_DATA_FIELD_DEF(uint8_t, hasUsedSeqCmpKV); | ||
| 86 | +// tilingData需要8字节对齐 | ||
| 87 | +TILING_DATA_FIELD_DEF(uint8_t, reserved0); | ||
| 88 | +TILING_DATA_FIELD_DEF(uint32_t, reserved1); | ||
| 83 | END_TILING_DATA_DEF; | 89 | END_TILING_DATA_DEF; |
| 84 | REGISTER_TILING_DATA_CLASS(SparseFlashMlaGradBasicParamsOp, SparseFlashMlaGradBasicParams) | 90 | REGISTER_TILING_DATA_CLASS(SparseFlashMlaGradBasicParamsOp, SparseFlashMlaGradBasicParams) |
| 85 | 91 | ||
| @@ -222,7 +222,8 @@ uint64_t SparseFlashMlaGradBasicTiling::GetTilingKey() const | |||
| 222 | // LAYOUT: 0(BSND); 1(TND) | 222 | // LAYOUT: 0(BSND); 1(TND) |
| 223 | // CMP_MODE: 0(SWA); 1(CFA); 2(SCFA) | 223 | // CMP_MODE: 0(SWA); 1(CFA); 2(SCFA) |
| 224 | uint32_t layout = tmpData.layout == static_cast<uint32_t>(InputLayout::TND) ? 1U : 0U; | 224 | uint32_t layout = tmpData.layout == static_cast<uint32_t>(InputLayout::TND) ? 1U : 0U; |
| 225 | - return GET_TPL_TILING_KEY(layout, tmpData.mode); | 225 | + bool hasSeqused = tmpData.usedSeqQ || tmpData.usedSeqOriKV || tmpData.usedSeqCmpKV; |
| 226 | + return GET_TPL_TILING_KEY(layout, tmpData.mode, static_cast<uint8_t>(hasSeqused)); | ||
| 226 | } | 227 | } |
| 227 | 228 | ||
| 228 | ge::graphStatus SparseFlashMlaGradBasicTiling::DoBlockTiling() | 229 | ge::graphStatus SparseFlashMlaGradBasicTiling::DoBlockTiling() |
| @@ -394,25 +395,29 @@ ge::graphStatus SparseFlashMlaGradBasicTiling::GetBaseShapeInfo() | |||
| 394 | 395 | ||
| 395 | // -------------- 当前不支持参数必须传空校验 -------------- | 396 | // -------------- 当前不支持参数必须传空校验 -------------- |
| 396 | auto oriSparseIndicesTensor = context_->GetOptionalInputTensor(static_cast<size_t>(InputIndex::ORI_SPARSE_INDICES)); | 397 | auto oriSparseIndicesTensor = context_->GetOptionalInputTensor(static_cast<size_t>(InputIndex::ORI_SPARSE_INDICES)); |
| 397 | - auto seqUsedQTensor = context_->GetOptionalInputTensor(static_cast<size_t>(InputIndex::SEQUSED_Q)); | ||
| 398 | - auto seqUsedOriKvTensor = context_->GetOptionalInputTensor(static_cast<size_t>(InputIndex::SEQUSED_ORI_KV)); | ||
| 399 | - auto seqUsedCmpKvTensor = context_->GetOptionalInputTensor(static_cast<size_t>(InputIndex::SEQUSED_CMP_KV)); | ||
| 400 | auto oriTopkLenTensor = context_->GetOptionalInputTensor(static_cast<size_t>(InputIndex::ORI_TOPK_LENGTH)); | 398 | auto oriTopkLenTensor = context_->GetOptionalInputTensor(static_cast<size_t>(InputIndex::ORI_TOPK_LENGTH)); |
| 401 | auto cmpTopkLenTensor = context_->GetOptionalInputTensor(static_cast<size_t>(InputIndex::CMP_TOPK_LENGTH)); | 399 | auto cmpTopkLenTensor = context_->GetOptionalInputTensor(static_cast<size_t>(InputIndex::CMP_TOPK_LENGTH)); |
| 402 | auto metadataTensor = context_->GetOptionalInputTensor(static_cast<size_t>(InputIndex::METADATA)); | 400 | auto metadataTensor = context_->GetOptionalInputTensor(static_cast<size_t>(InputIndex::METADATA)); |
| 403 | OP_CHECK_IF(oriSparseIndicesTensor != nullptr, | 401 | OP_CHECK_IF(oriSparseIndicesTensor != nullptr, |
| 404 | OP_LOGE("SparseFlashMlaGrad", "oriSparseIndices should be nullptr now."), return ge::GRAPH_FAILED); | 402 | OP_LOGE("SparseFlashMlaGrad", "oriSparseIndices should be nullptr now."), return ge::GRAPH_FAILED); |
| 405 | - OP_CHECK_IF(seqUsedQTensor != nullptr, OP_LOGE("SparseFlashMlaGrad", "seqUsedQ should be nullptr now."), | ||
| 406 | - return ge::GRAPH_FAILED); | ||
| 407 | - OP_CHECK_IF(seqUsedOriKvTensor != nullptr, OP_LOGE("SparseFlashMlaGrad", "seqUsedOriKv should be nullptr now."), | ||
| 408 | - return ge::GRAPH_FAILED); | ||
| 409 | - OP_CHECK_IF(seqUsedCmpKvTensor != nullptr, OP_LOGE("SparseFlashMlaGrad", "seqUsedCmpKv should be nullptr now."), | ||
| 410 | - return ge::GRAPH_FAILED); | ||
| 411 | OP_CHECK_IF(oriTopkLenTensor != nullptr, OP_LOGE("SparseFlashMlaGrad", "oriTopkLength should be nullptr now."), | 403 | OP_CHECK_IF(oriTopkLenTensor != nullptr, OP_LOGE("SparseFlashMlaGrad", "oriTopkLength should be nullptr now."), |
| 412 | return ge::GRAPH_FAILED); | 404 | return ge::GRAPH_FAILED); |
| 413 | OP_CHECK_IF(cmpTopkLenTensor != nullptr, OP_LOGE("SparseFlashMlaGrad", "cmpTopkLength should be nullptr now."), | 405 | OP_CHECK_IF(cmpTopkLenTensor != nullptr, OP_LOGE("SparseFlashMlaGrad", "cmpTopkLength should be nullptr now."), |
| 414 | return ge::GRAPH_FAILED); | 406 | return ge::GRAPH_FAILED); |
| 415 | 407 | ||
| 408 | + auto usedSeqQ = context_->GetOptionalInputShape(static_cast<size_t>(InputIndex::SEQUSED_Q)); | ||
| 409 | + if (usedSeqQ != nullptr) { | ||
| 410 | + tmpData.usedSeqQ = true; | ||
| 411 | + } | ||
| 412 | + auto usedSeqOriKV = context_->GetOptionalInputShape(static_cast<size_t>(InputIndex::SEQUSED_ORI_KV)); | ||
| 413 | + if (usedSeqOriKV != nullptr) { | ||
| 414 | + tmpData.usedSeqOriKV = true; | ||
| 415 | + } | ||
| 416 | + auto usedSeqCmpKV = context_->GetOptionalInputShape(static_cast<size_t>(InputIndex::SEQUSED_CMP_KV)); | ||
| 417 | + if (usedSeqCmpKV != nullptr) { | ||
| 418 | + tmpData.usedSeqCmpKV = true; | ||
| 419 | + } | ||
| 420 | + | ||
| 416 | // -------------- attrs ---------------- | 421 | // -------------- attrs ---------------- |
| 417 | const char *inputLayoutQ = context_->GetAttrs()->GetAttrPointer<char>(static_cast<size_t>(AttrIndex::LAYOUT_Q)); | 422 | const char *inputLayoutQ = context_->GetAttrs()->GetAttrPointer<char>(static_cast<size_t>(AttrIndex::LAYOUT_Q)); |
| 418 | const char *inputLayoutKv = context_->GetAttrs()->GetAttrPointer<char>(static_cast<size_t>(AttrIndex::LAYOUT_KV)); | 423 | const char *inputLayoutKv = context_->GetAttrs()->GetAttrPointer<char>(static_cast<size_t>(AttrIndex::LAYOUT_KV)); |
| @@ -616,6 +621,10 @@ ge::graphStatus SparseFlashMlaGradBasicTiling::GetBaseShapeInfo() | |||
| 616 | return ge::GRAPH_FAILED); | 621 | return ge::GRAPH_FAILED); |
| 617 | } | 622 | } |
| 618 | } | 623 | } |
| 624 | + | ||
| 625 | + tilingData.opInfo.set_hasUsedSeqQ(tmpData.usedSeqQ); | ||
| 626 | + tilingData.opInfo.set_hasUsedSeqOriKV(tmpData.usedSeqOriKV); | ||
| 627 | + tilingData.opInfo.set_hasUsedSeqCmpKV(tmpData.usedSeqCmpKV); | ||
| 619 | tilingData.opInfo.set_selectedBlockSize(1); | 628 | tilingData.opInfo.set_selectedBlockSize(1); |
| 620 | 629 | ||
| 621 | return ge::GRAPH_SUCCESS; | 630 | return ge::GRAPH_SUCCESS; |
| @@ -45,6 +45,9 @@ struct TempParams { | |||
| 45 | uint32_t s1BasicSize; | 45 | uint32_t s1BasicSize; |
| 46 | uint32_t selected_block_count; | 46 | uint32_t selected_block_count; |
| 47 | uint32_t mode; | 47 | uint32_t mode; |
| 48 | + bool usedSeqQ = false; | ||
| 49 | + bool usedSeqOriKV = false; | ||
| 50 | + bool usedSeqCmpKV = false; | ||
| 48 | }; | 51 | }; |
| 49 | 52 | ||
| 50 | struct AiCoreParams { | 53 | struct AiCoreParams { |
Mattention/sparse_flash_mla_grad/op_kernel/arch22/basic_modules/sparse_flash_mla_grad_common_header.h+2-1
| @@ -37,12 +37,13 @@ constexpr static uint64_t MAX_CORE_NUM = 24; | |||
| 37 | ///////////////////////////////////////////////////// | 37 | ///////////////////////////////////////////////////// |
| 38 | 38 | ||
| 39 | template <class TILING_CLASS, typename T1, const bool IS_BSND = false, const uint32_t MODE = SMLAG_SCFA_MODE, | 39 | template <class TILING_CLASS, typename T1, const bool IS_BSND = false, const uint32_t MODE = SMLAG_SCFA_MODE, |
| 40 | - typename... Args> | 40 | + const bool HAS_SEQUSED = false, typename... Args> |
| 41 | struct SMLAG_TYPE { | 41 | struct SMLAG_TYPE { |
| 42 | using tiling_class = TILING_CLASS; | 42 | using tiling_class = TILING_CLASS; |
| 43 | using t1 = T1; | 43 | using t1 = T1; |
| 44 | static constexpr bool is_bsnd = IS_BSND; | 44 | static constexpr bool is_bsnd = IS_BSND; |
| 45 | static constexpr uint32_t mode = MODE; | 45 | static constexpr uint32_t mode = MODE; |
| 46 | + static constexpr bool has_seqused = HAS_SEQUSED; | ||
| 46 | }; | 47 | }; |
| 47 | 48 | ||
| 48 | struct RunInfo { | 49 | struct RunInfo { |
| @@ -28,18 +28,21 @@ class SelectedAttentionGradBasic { | |||
| 28 | using TILING_CLASS = typename SMLAGT::tiling_class; | 28 | using TILING_CLASS = typename SMLAGT::tiling_class; |
| 29 | using T1 = typename SMLAGT::t1; | 29 | using T1 = typename SMLAGT::t1; |
| 30 | static constexpr bool IS_BSND = SMLAGT::is_bsnd; | 30 | static constexpr bool IS_BSND = SMLAGT::is_bsnd; |
| 31 | + static constexpr bool HAS_SEQUSED = SMLAGT::has_seqused; | ||
| 31 | 32 | ||
| 32 | public: | 33 | public: |
| 33 | __aicore__ inline SelectedAttentionGradBasic(){}; | 34 | __aicore__ inline SelectedAttentionGradBasic(){}; |
| 34 | __aicore__ inline void Process(GM_ADDR query, GM_ADDR ori_kv, GM_ADDR cmp_kv, GM_ADDR attention_out, | 35 | __aicore__ inline void Process(GM_ADDR query, GM_ADDR ori_kv, GM_ADDR cmp_kv, GM_ADDR attention_out, |
| 35 | GM_ADDR attention_out_grad, GM_ADDR lse, GM_ADDR topk_indices, GM_ADDR cu_seqlens_q, | 36 | GM_ADDR attention_out_grad, GM_ADDR lse, GM_ADDR topk_indices, GM_ADDR cu_seqlens_q, |
| 36 | - GM_ADDR cu_seqlens_ori_kv, GM_ADDR cu_seqlens_cmp_kv, GM_ADDR cmp_residual_kv, | 37 | + GM_ADDR cu_seqlens_ori_kv, GM_ADDR cu_seqlens_cmp_kv, GM_ADDR seqused_q, |
| 38 | + GM_ADDR seqused_ori_kv, GM_ADDR seqused_cmp_kv, GM_ADDR cmp_residual_kv, | ||
| 37 | GM_ADDR sinks, GM_ADDR dq, GM_ADDR d_ori_kv, GM_ADDR d_cmp_kv, GM_ADDR dsinks, | 39 | GM_ADDR sinks, GM_ADDR dq, GM_ADDR d_ori_kv, GM_ADDR d_cmp_kv, GM_ADDR dsinks, |
| 38 | GM_ADDR cmp_softmax_l1_norm, GM_ADDR workspace, | 40 | GM_ADDR cmp_softmax_l1_norm, GM_ADDR workspace, |
| 39 | const TILING_CLASS *__restrict tilingData); | 41 | const TILING_CLASS *__restrict tilingData); |
| 40 | 42 | ||
| 41 | private: | 43 | private: |
| 42 | - __aicore__ inline void Init(const TILING_CLASS *__restrict tilingData); | 44 | + __aicore__ inline void Init(const TILING_CLASS *__restrict tilingData, const GM_ADDR seqused_q, |
| 45 | + const GM_ADDR seqused_ori_kv, const GM_ADDR seqused_cmp_kv); | ||
| 43 | __aicore__ inline void CubeCompute(CubeOp<SMLAGT> &cubeOp); | 46 | __aicore__ inline void CubeCompute(CubeOp<SMLAGT> &cubeOp); |
| 44 | __aicore__ inline void VecCompute(VecOp<SMLAGT> &vecOp); | 47 | __aicore__ inline void VecCompute(VecOp<SMLAGT> &vecOp); |
| 45 | __aicore__ inline void UpdateGmOffset(int64_t task, int32_t loop); | 48 | __aicore__ inline void UpdateGmOffset(int64_t task, int32_t loop); |
| @@ -49,6 +52,7 @@ private: | |||
| 49 | const int64_t t1Idx, int64_t &bIdx); | 52 | const int64_t t1Idx, int64_t &bIdx); |
| 50 | __aicore__ inline void GetActualSelCount(const int64_t t1Idx, const int64_t n2Idx, int32_t &actSelBlkCount, | 53 | __aicore__ inline void GetActualSelCount(const int64_t t1Idx, const int64_t n2Idx, int32_t &actSelBlkCount, |
| 51 | int32_t &curS2Loop); | 54 | int32_t &curS2Loop); |
| 55 | + __aicore__ inline void UpdateUsedSeqLen(int64_t batchIdx); | ||
| 52 | 56 | ||
| 53 | uint32_t cubeBlockIdx; | 57 | uint32_t cubeBlockIdx; |
| 54 | uint32_t subBlockIdx; | 58 | uint32_t subBlockIdx; |
| @@ -69,6 +73,10 @@ private: | |||
| 69 | int64_t curS1; | 73 | int64_t curS1; |
| 70 | int64_t curS2; | 74 | int64_t curS2; |
| 71 | int64_t curS3; | 75 | int64_t curS3; |
| 76 | + // EOD: 每个 batch 槽位内实际参与运算的长度;无 seqused 时等于 curS1/curS2/curS3 | ||
| 77 | + int64_t usedS1{0}; | ||
| 78 | + int64_t usedS2{0}; | ||
| 79 | + int64_t usedS3{0}; | ||
| 72 | int64_t residual; | 80 | int64_t residual; |
| 73 | int64_t curMaxS3; | 81 | int64_t curMaxS3; |
| 74 | int64_t dimS1; | 82 | int64_t dimS1; |
| @@ -140,12 +148,20 @@ private: | |||
| 140 | 148 | ||
| 141 | // gm | 149 | // gm |
| 142 | GlobalTensor<int32_t> topkIndicesGm; | 150 | GlobalTensor<int32_t> topkIndicesGm; |
| 151 | + const GM_ADDR seqused_q; | ||
| 152 | + const GM_ADDR seqused_ori_kv; | ||
| 153 | + const GM_ADDR seqused_cmp_kv; | ||
| 154 | + bool hasUsedSeqQ{false}; | ||
| 155 | + bool hasUsedSeqOriKV{false}; | ||
| 156 | + bool hasUsedSeqCmpKV{false}; | ||
| 143 | 157 | ||
| 144 | event_t vWaitMte3Proc; | 158 | event_t vWaitMte3Proc; |
| 145 | }; | 159 | }; |
| 146 | 160 | ||
| 147 | template <typename SMLAGT> | 161 | template <typename SMLAGT> |
| 148 | -__aicore__ inline void SelectedAttentionGradBasic<SMLAGT>::Init(const TILING_CLASS *__restrict tilingData) | 162 | +__aicore__ inline void SelectedAttentionGradBasic<SMLAGT>::Init(const TILING_CLASS *__restrict tilingData, |
| 163 | + const GM_ADDR seqused_q, const GM_ADDR seqused_ori_kv, | ||
| 164 | + const GM_ADDR seqused_cmp_kv) | ||
| 149 | { | 165 | { |
| 150 | dimS1 = tilingData->opInfo.S1; | 166 | dimS1 = tilingData->opInfo.S1; |
| 151 | dimG = tilingData->opInfo.G; | 167 | dimG = tilingData->opInfo.G; |
| @@ -190,16 +206,25 @@ __aicore__ inline void SelectedAttentionGradBasic<SMLAGT>::Init(const TILING_CLA | |||
| 190 | } | 206 | } |
| 191 | selectedBlockSize = tilingData->opInfo.selectedBlockSize; | 207 | selectedBlockSize = tilingData->opInfo.selectedBlockSize; |
| 192 | s1BasicSize = tilingData->splitCoreParams.s1BasicSize; | 208 | s1BasicSize = tilingData->splitCoreParams.s1BasicSize; |
| 209 | + this->seqused_q = seqused_q; | ||
| 210 | + this->seqused_ori_kv = seqused_ori_kv; | ||
| 211 | + this->seqused_cmp_kv = seqused_cmp_kv; | ||
| 212 | + if constexpr (HAS_SEQUSED) { | ||
| 213 | + hasUsedSeqQ = tilingData->opInfo.hasUsedSeqQ; | ||
| 214 | + hasUsedSeqOriKV = tilingData->opInfo.hasUsedSeqOriKV; | ||
| 215 | + hasUsedSeqCmpKV = tilingData->opInfo.hasUsedSeqCmpKV; | ||
| 216 | + } | ||
| 193 | } | 217 | } |
| 194 | 218 | ||
| 195 | template <typename SMLAGT> | 219 | template <typename SMLAGT> |
| 196 | __aicore__ inline void SelectedAttentionGradBasic<SMLAGT>::Process( | 220 | __aicore__ inline void SelectedAttentionGradBasic<SMLAGT>::Process( |
| 197 | GM_ADDR query, GM_ADDR ori_kv, GM_ADDR cmp_kv, GM_ADDR attention_out, GM_ADDR attention_out_grad, GM_ADDR lse, | 221 | GM_ADDR query, GM_ADDR ori_kv, GM_ADDR cmp_kv, GM_ADDR attention_out, GM_ADDR attention_out_grad, GM_ADDR lse, |
| 198 | - GM_ADDR topk_indices, GM_ADDR cu_seqlens_q, GM_ADDR cu_seqlens_ori_kv, GM_ADDR cu_seqlens_cmp_kv, | 222 | + GM_ADDR topk_indices, GM_ADDR cu_seqlens_q, GM_ADDR cu_seqlens_ori_kv, GM_ADDR cu_seqlens_cmp_kv, GM_ADDR seqused_q, |
| 199 | - GM_ADDR cmp_residual_kv, GM_ADDR sinks, GM_ADDR dq, GM_ADDR d_ori_kv, GM_ADDR d_cmp_kv, GM_ADDR dsinks, | 223 | + GM_ADDR seqused_ori_kv, GM_ADDR seqused_cmp_kv, GM_ADDR cmp_residual_kv, GM_ADDR sinks, GM_ADDR dq, |
| 200 | - GM_ADDR cmp_softmax_l1_norm, GM_ADDR workspace, const TILING_CLASS *__restrict tilingData) | 224 | + GM_ADDR d_ori_kv, GM_ADDR d_cmp_kv, GM_ADDR dsinks, GM_ADDR cmp_softmax_l1_norm, GM_ADDR workspace, |
| 225 | + const TILING_CLASS *__restrict tilingData) | ||
| 201 | { | 226 | { |
| 202 | - Init(tilingData); | 227 | + Init(tilingData, seqused_q, seqused_ori_kv, seqused_cmp_kv); |
| 203 | topkIndicesGm.SetGlobalBuffer((__gm__ int32_t *)topk_indices); | 228 | topkIndicesGm.SetGlobalBuffer((__gm__ int32_t *)topk_indices); |
| 204 | 229 | ||
| 205 | if constexpr (IS_BSND == true) { | 230 | if constexpr (IS_BSND == true) { |
| @@ -218,6 +243,12 @@ __aicore__ inline void SelectedAttentionGradBasic<SMLAGT>::Process( | |||
| 218 | scatterTaskId = i % 2; | 243 | scatterTaskId = i % 2; |
| 219 | int64_t t1Index = static_cast<int64_t>(cubeBlockIdx) + usedCoreNum * i; | 244 | int64_t t1Index = static_cast<int64_t>(cubeBlockIdx) + usedCoreNum * i; |
| 220 | GetTndSeqLen(cu_seqlens_q, cu_seqlens_ori_kv, cu_seqlens_cmp_kv, cmp_residual_kv, t1Index, bIndex); | 245 | GetTndSeqLen(cu_seqlens_q, cu_seqlens_ori_kv, cu_seqlens_cmp_kv, cmp_residual_kv, t1Index, bIndex); |
| 246 | + if constexpr (HAS_SEQUSED) { | ||
| 247 | + // EOD: 槽位内 [usedS1, curS1) 为 padding 行,整 token 不发 task | ||
| 248 | + if (s1Index >= usedS1) { | ||
| 249 | + continue; | ||
| 250 | + } | ||
| 251 | + } | ||
| 221 | changePingpong = false; | 252 | changePingpong = false; |
| 222 | for (n2Index = 0; n2Index < dimN2; n2Index++) { | 253 | for (n2Index = 0; n2Index < dimN2; n2Index++) { |
| 223 | GetActualSelCount(t1Index, n2Index, actualSelectedBlockCount, s2Loop); | 254 | GetActualSelCount(t1Index, n2Index, actualSelectedBlockCount, s2Loop); |
| @@ -261,6 +292,12 @@ __aicore__ inline void SelectedAttentionGradBasic<SMLAGT>::Process( | |||
| 261 | scatterTaskId = i % 2; | 292 | scatterTaskId = i % 2; |
| 262 | int64_t t1Index = static_cast<int64_t>(cubeBlockIdx) + usedCoreNum * i; | 293 | int64_t t1Index = static_cast<int64_t>(cubeBlockIdx) + usedCoreNum * i; |
| 263 | GetTndSeqLen(cu_seqlens_q, cu_seqlens_ori_kv, cu_seqlens_cmp_kv, cmp_residual_kv, t1Index, bIndex); | 294 | GetTndSeqLen(cu_seqlens_q, cu_seqlens_ori_kv, cu_seqlens_cmp_kv, cmp_residual_kv, t1Index, bIndex); |
| 295 | + if constexpr (HAS_SEQUSED) { | ||
| 296 | + // EOD: 槽位内 [usedS1, curS1) 为 padding 行,整 token 不发 task | ||
| 297 | + if (s1Index >= usedS1) { | ||
| 298 | + continue; | ||
| 299 | + } | ||
| 300 | + } | ||
| 264 | changePingpong = false; | 301 | changePingpong = false; |
| 265 | for (n2Index = 0; n2Index < dimN2; n2Index++) { | 302 | for (n2Index = 0; n2Index < dimN2; n2Index++) { |
| 266 | GetActualSelCount(t1Index, n2Index, actualSelectedBlockCount, s2Loop); | 303 | GetActualSelCount(t1Index, n2Index, actualSelectedBlockCount, s2Loop); |
| @@ -414,8 +451,8 @@ __aicore__ inline void SelectedAttentionGradBasic<SMLAGT>::UpdateGmOffset(int64_ | |||
| 414 | runInfo[mmPingPongIdx].scatterTaskId = scatterTaskId; | 451 | runInfo[mmPingPongIdx].scatterTaskId = scatterTaskId; |
| 415 | runInfo[mmPingPongIdx].s1Index = s1Index; | 452 | runInfo[mmPingPongIdx].s1Index = s1Index; |
| 416 | runInfo[mmPingPongIdx].actualSelectedBlockCount = actualSelectedBlockCount; | 453 | runInfo[mmPingPongIdx].actualSelectedBlockCount = actualSelectedBlockCount; |
| 417 | - runInfo[mmPingPongIdx].curS1 = curS1; | 454 | + runInfo[mmPingPongIdx].curS1 = usedS1; |
| 418 | - runInfo[mmPingPongIdx].curS3 = curS3; | 455 | + runInfo[mmPingPongIdx].curS3 = usedS3; |
| 419 | runInfo[mmPingPongIdx].selectedKGmOffset = runInfo[mmPingPongIdx].isOri ? | 456 | runInfo[mmPingPongIdx].selectedKGmOffset = runInfo[mmPingPongIdx].isOri ? |
| 420 | oriKeyGmOffset + (oriWinStart + blkCntOffset) * dimN2 * dimDqk : | 457 | oriKeyGmOffset + (oriWinStart + blkCntOffset) * dimN2 * dimDqk : |
| 421 | selectedKGmOffset; | 458 | selectedKGmOffset; |
| @@ -472,12 +509,33 @@ __aicore__ inline void SelectedAttentionGradBasic<SMLAGT>::GetTndSeqLen(const GM | |||
| 472 | } | 509 | } |
| 473 | 510 | ||
| 474 | s1Index = t1Idx - t1Offset; | 511 | s1Index = t1Idx - t1Offset; |
| 512 | + UpdateUsedSeqLen(bIndex == 0 ? 0 : bIndex - 1); | ||
| 475 | } else { | 513 | } else { |
| 476 | t1Offset = t1Idx; | 514 | t1Offset = t1Idx; |
| 477 | bIdx = t1Idx / curS1; | 515 | bIdx = t1Idx / curS1; |
| 478 | s1Index = t1Idx % dimS1; | 516 | s1Index = t1Idx % dimS1; |
| 479 | t2Offset = bIdx * curS2; | 517 | t2Offset = bIdx * curS2; |
| 480 | t3Offset = bIdx * curS3; | 518 | t3Offset = bIdx * curS3; |
| 519 | + UpdateUsedSeqLen(bIdx); | ||
| 520 | + } | ||
| 521 | +} | ||
| 522 | + | ||
| 523 | +template <typename SMLAGT> | ||
| 524 | +__aicore__ inline void SelectedAttentionGradBasic<SMLAGT>::UpdateUsedSeqLen(int64_t batchIdx) | ||
| 525 | +{ | ||
| 526 | + usedS1 = curS1; | ||
| 527 | + usedS2 = curS2; | ||
| 528 | + usedS3 = curS3; | ||
| 529 | + if constexpr (HAS_SEQUSED) { | ||
| 530 | + if (hasUsedSeqQ) { | ||
| 531 | + usedS1 = ((__gm__ int32_t *)seqused_q)[batchIdx]; | ||
| 532 | + } | ||
| 533 | + if (hasUsedSeqOriKV) { | ||
| 534 | + usedS2 = ((__gm__ int32_t *)seqused_ori_kv)[batchIdx]; | ||
| 535 | + } | ||
| 536 | + if (hasUsedSeqCmpKV) { | ||
| 537 | + usedS3 = ((__gm__ int32_t *)seqused_cmp_kv)[batchIdx]; | ||
| 538 | + } | ||
| 481 | } | 539 | } |
| 482 | } | 540 | } |
| 483 | 541 | ||
| @@ -486,16 +544,17 @@ __aicore__ inline void SelectedAttentionGradBasic<SMLAGT>::GetActualSelCount(con | |||
| 486 | int32_t &actSelBlkCount, | 544 | int32_t &actSelBlkCount, |
| 487 | int32_t &curS2Loop) | 545 | int32_t &curS2Loop) |
| 488 | { | 546 | { |
| 489 | - int64_t maxS3 = Max((curS3 * cmpRatio + residual - curS1 + s1Index + 1) / cmpRatio, 0); | 547 | + // EOD 下 usedS* 为槽位内有效长度(非 EOD 时等于 curS*) |
| 548 | + int64_t maxS3 = Max((usedS3 * cmpRatio + residual - usedS1 + s1Index + 1) / cmpRatio, 0); | ||
| 490 | curMaxS3 = (maxS3 + selectedBlockSize - 1) / selectedBlockSize; | 549 | curMaxS3 = (maxS3 + selectedBlockSize - 1) / selectedBlockSize; |
| 491 | 550 | ||
| 492 | - actualSelectedBlockCount = Min(selectedBlockCount, curMaxS3); | 551 | + actualSelectedBlockCount = Min(Min(selectedBlockCount, curMaxS3), usedS3); |
| 493 | cmpS2Loop = CeilDiv(actualSelectedBlockCount, selectedCountOffset); | 552 | cmpS2Loop = CeilDiv(actualSelectedBlockCount, selectedCountOffset); |
| 494 | cmpS2Tail = actualSelectedBlockCount % selectedCountOffset ? actualSelectedBlockCount % selectedCountOffset : | 553 | cmpS2Tail = actualSelectedBlockCount % selectedCountOffset ? actualSelectedBlockCount % selectedCountOffset : |
| 495 | selectedCountOffset; | 554 | selectedCountOffset; |
| 496 | 555 | ||
| 497 | - int64_t oriWinDiagOffset = curS2 - curS1; | 556 | + int64_t oriWinDiagOffset = usedS2 - usedS1; |
| 498 | - oriWinEnd = Min(s1Index + oriWinRight + 1 + oriWinDiagOffset, curS2); | 557 | + oriWinEnd = Min(s1Index + oriWinRight + 1 + oriWinDiagOffset, usedS2); |
| 499 | oriWinEnd = Max(oriWinEnd, 0); | 558 | oriWinEnd = Max(oriWinEnd, 0); |
| 500 | oriWinStart = Max(s1Index - oriWinLeft + oriWinDiagOffset, 0); | 559 | oriWinStart = Max(s1Index - oriWinLeft + oriWinDiagOffset, 0); |
| 501 | int64_t oriWinS2Len = oriWinEnd - oriWinStart; | 560 | int64_t oriWinS2Len = oriWinEnd - oriWinStart; |
| @@ -29,12 +29,14 @@ class SparseFlashMlaGrad { | |||
| 29 | using T1 = typename SMLAGT::t1; | 29 | using T1 = typename SMLAGT::t1; |
| 30 | static constexpr bool IS_BSND = SMLAGT::is_bsnd; | 30 | static constexpr bool IS_BSND = SMLAGT::is_bsnd; |
| 31 | static constexpr uint32_t MODE = SMLAGT::mode; | 31 | static constexpr uint32_t MODE = SMLAGT::mode; |
| 32 | + static constexpr bool HAS_SEQUSED = SMLAGT::has_seqused; | ||
| 32 | 33 | ||
| 33 | public: | 34 | public: |
| 34 | __aicore__ inline SparseFlashMlaGrad(){}; | 35 | __aicore__ inline SparseFlashMlaGrad(){}; |
| 35 | __aicore__ inline void Process(GM_ADDR query, GM_ADDR ori_kv, GM_ADDR cmp_kv, GM_ADDR attention_out, | 36 | __aicore__ inline void Process(GM_ADDR query, GM_ADDR ori_kv, GM_ADDR cmp_kv, GM_ADDR attention_out, |
| 36 | GM_ADDR attention_out_grad, GM_ADDR lse, GM_ADDR topk_indices, GM_ADDR cu_seqlens_q, | 37 | GM_ADDR attention_out_grad, GM_ADDR lse, GM_ADDR topk_indices, GM_ADDR cu_seqlens_q, |
| 37 | - GM_ADDR cu_seqlens_ori_kv, GM_ADDR cu_seqlens_cmp_kv, GM_ADDR cmp_residual_kv, | 38 | + GM_ADDR cu_seqlens_ori_kv, GM_ADDR cu_seqlens_cmp_kv, GM_ADDR seqused_q, |
| 39 | + GM_ADDR seqused_ori_kv, GM_ADDR seqused_cmp_kv, GM_ADDR cmp_residual_kv, | ||
| 38 | GM_ADDR sinks, GM_ADDR dq, GM_ADDR d_ori_kv, GM_ADDR d_cmp_kv, GM_ADDR dsinks, | 40 | GM_ADDR sinks, GM_ADDR dq, GM_ADDR d_ori_kv, GM_ADDR d_cmp_kv, GM_ADDR dsinks, |
| 39 | GM_ADDR cmp_softmax_l1_norm, GM_ADDR workspace, | 41 | GM_ADDR cmp_softmax_l1_norm, GM_ADDR workspace, |
| 40 | const TILING_CLASS *__restrict tilingData); | 42 | const TILING_CLASS *__restrict tilingData); |
| @@ -42,6 +44,7 @@ public: | |||
| 42 | private: | 44 | private: |
| 43 | __aicore__ inline void Init(const TILING_CLASS *__restrict tilingData, const GM_ADDR cu_seqlens_q, | 45 | __aicore__ inline void Init(const TILING_CLASS *__restrict tilingData, const GM_ADDR cu_seqlens_q, |
| 44 | const GM_ADDR cu_seqlens_ori_kv, const GM_ADDR cu_seqlens_cmp_kv, | 46 | const GM_ADDR cu_seqlens_ori_kv, const GM_ADDR cu_seqlens_cmp_kv, |
| 47 | + const GM_ADDR seqused_q, const GM_ADDR seqused_ori_kv, const GM_ADDR seqused_cmp_kv, | ||
| 45 | const GM_ADDR cmp_residual_kv); | 48 | const GM_ADDR cmp_residual_kv); |
| 46 | __aicore__ inline void CubeCompute(CubeOp<SMLAGT> &cubeOp); | 49 | __aicore__ inline void CubeCompute(CubeOp<SMLAGT> &cubeOp); |
| 47 | __aicore__ inline void VecCompute(VecOp<SMLAGT> &vecOp); | 50 | __aicore__ inline void VecCompute(VecOp<SMLAGT> &vecOp); |
| @@ -50,6 +53,7 @@ private: | |||
| 50 | __aicore__ inline void GetTndSeqLen(const int64_t t1Idx, int64_t &bIdx, int32_t &s1Loop); | 53 | __aicore__ inline void GetTndSeqLen(const int64_t t1Idx, int64_t &bIdx, int32_t &s1Loop); |
| 51 | __aicore__ inline void GetActualSelCount(const int64_t t1Idx, const int64_t n2Idx, int32_t &curS2Loop); | 54 | __aicore__ inline void GetActualSelCount(const int64_t t1Idx, const int64_t n2Idx, int32_t &curS2Loop); |
| 52 | __aicore__ inline void ChangeBatchUpdate(); | 55 | __aicore__ inline void ChangeBatchUpdate(); |
| 56 | + __aicore__ inline void UpdateUsedSeqLen(int64_t batchIdx); | ||
| 53 | 57 | ||
| 54 | uint32_t cubeBlockIdx; | 58 | uint32_t cubeBlockIdx; |
| 55 | uint32_t subBlockIdx; | 59 | uint32_t subBlockIdx; |
| @@ -70,6 +74,10 @@ private: | |||
| 70 | int64_t curS1; | 74 | int64_t curS1; |
| 71 | int64_t curS2; | 75 | int64_t curS2; |
| 72 | int64_t curS3; | 76 | int64_t curS3; |
| 77 | + // EOD: 每个 batch 槽位内实际参与运算的长度;无 seqused 时等于 curS1/curS2/curS3 | ||
| 78 | + int64_t usedS1{0}; | ||
| 79 | + int64_t usedS2{0}; | ||
| 80 | + int64_t usedS3{0}; | ||
| 73 | int64_t residual; | 81 | int64_t residual; |
| 74 | int64_t curMaxS3; | 82 | int64_t curMaxS3; |
| 75 | int64_t dimS1; | 83 | int64_t dimS1; |
| @@ -138,6 +146,12 @@ private: | |||
| 138 | const GM_ADDR cu_seqlens_ori_kv; | 146 | const GM_ADDR cu_seqlens_ori_kv; |
| 139 | const GM_ADDR cu_seqlens_cmp_kv; | 147 | const GM_ADDR cu_seqlens_cmp_kv; |
| 140 | const GM_ADDR cmp_residual_kv; | 148 | const GM_ADDR cmp_residual_kv; |
| 149 | + const GM_ADDR seqused_q; | ||
| 150 | + const GM_ADDR seqused_ori_kv; | ||
| 151 | + const GM_ADDR seqused_cmp_kv; | ||
| 152 | + bool hasUsedSeqQ{false}; | ||
| 153 | + bool hasUsedSeqOriKV{false}; | ||
| 154 | + bool hasUsedSeqCmpKV{false}; | ||
| 141 | 155 | ||
| 142 | RunInfo runInfo[2]; | 156 | RunInfo runInfo[2]; |
| 143 | }; | 157 | }; |
| @@ -145,7 +159,9 @@ private: | |||
| 145 | template <typename SMLAGT> | 159 | template <typename SMLAGT> |
| 146 | __aicore__ inline void SparseFlashMlaGrad<SMLAGT>::Init(const TILING_CLASS *__restrict tilingData, | 160 | __aicore__ inline void SparseFlashMlaGrad<SMLAGT>::Init(const TILING_CLASS *__restrict tilingData, |
| 147 | const GM_ADDR cu_seqlens_q, const GM_ADDR cu_seqlens_ori_kv, | 161 | const GM_ADDR cu_seqlens_q, const GM_ADDR cu_seqlens_ori_kv, |
| 148 | - const GM_ADDR cu_seqlens_cmp_kv, const GM_ADDR cmp_residual_kv) | 162 | + const GM_ADDR cu_seqlens_cmp_kv, const GM_ADDR seqused_q, |
| 163 | + const GM_ADDR seqused_ori_kv, const GM_ADDR seqused_cmp_kv, | ||
| 164 | + const GM_ADDR cmp_residual_kv) | ||
| 149 | { | 165 | { |
| 150 | dimB = tilingData->opInfo.B; | 166 | dimB = tilingData->opInfo.B; |
| 151 | dimS1 = tilingData->opInfo.S1; | 167 | dimS1 = tilingData->opInfo.S1; |
| @@ -191,6 +207,14 @@ __aicore__ inline void SparseFlashMlaGrad<SMLAGT>::Init(const TILING_CLASS *__re | |||
| 191 | this->cu_seqlens_ori_kv = cu_seqlens_ori_kv; | 207 | this->cu_seqlens_ori_kv = cu_seqlens_ori_kv; |
| 192 | this->cu_seqlens_cmp_kv = cu_seqlens_cmp_kv; | 208 | this->cu_seqlens_cmp_kv = cu_seqlens_cmp_kv; |
| 193 | } | 209 | } |
| 210 | + if constexpr (HAS_SEQUSED) { | ||
| 211 | + this->seqused_q = seqused_q; | ||
| 212 | + this->seqused_ori_kv = seqused_ori_kv; | ||
| 213 | + this->seqused_cmp_kv = seqused_cmp_kv; | ||
| 214 | + hasUsedSeqQ = tilingData->opInfo.hasUsedSeqQ; | ||
| 215 | + hasUsedSeqOriKV = tilingData->opInfo.hasUsedSeqOriKV; | ||
| 216 | + hasUsedSeqCmpKV = tilingData->opInfo.hasUsedSeqCmpKV; | ||
| 217 | + } | ||
| 194 | 218 | ||
| 195 | if constexpr (MODE == SMLAG_CFA_MODE) { | 219 | if constexpr (MODE == SMLAG_CFA_MODE) { |
| 196 | this->cmp_residual_kv = cmp_residual_kv; | 220 | this->cmp_residual_kv = cmp_residual_kv; |
| @@ -203,11 +227,13 @@ __aicore__ inline void SparseFlashMlaGrad<SMLAGT>::Init(const TILING_CLASS *__re | |||
| 203 | template <typename SMLAGT> | 227 | template <typename SMLAGT> |
| 204 | __aicore__ inline void SparseFlashMlaGrad<SMLAGT>::Process( | 228 | __aicore__ inline void SparseFlashMlaGrad<SMLAGT>::Process( |
| 205 | GM_ADDR query, GM_ADDR ori_kv, GM_ADDR cmp_kv, GM_ADDR attention_out, GM_ADDR attention_out_grad, GM_ADDR lse, | 229 | GM_ADDR query, GM_ADDR ori_kv, GM_ADDR cmp_kv, GM_ADDR attention_out, GM_ADDR attention_out_grad, GM_ADDR lse, |
| 206 | - GM_ADDR topk_indices, GM_ADDR cu_seqlens_q, GM_ADDR cu_seqlens_ori_kv, GM_ADDR cu_seqlens_cmp_kv, | 230 | + GM_ADDR topk_indices, GM_ADDR cu_seqlens_q, GM_ADDR cu_seqlens_ori_kv, GM_ADDR cu_seqlens_cmp_kv, GM_ADDR seqused_q, |
| 207 | - GM_ADDR cmp_residual_kv, GM_ADDR sinks, GM_ADDR dq, GM_ADDR d_ori_kv, GM_ADDR d_cmp_kv, GM_ADDR dsinks, | 231 | + GM_ADDR seqused_ori_kv, GM_ADDR seqused_cmp_kv, GM_ADDR cmp_residual_kv, GM_ADDR sinks, GM_ADDR dq, |
| 208 | - GM_ADDR cmp_softmax_l1_norm, GM_ADDR workspace, const TILING_CLASS *__restrict tilingData) | 232 | + GM_ADDR d_ori_kv, GM_ADDR d_cmp_kv, GM_ADDR dsinks, GM_ADDR cmp_softmax_l1_norm, GM_ADDR workspace, |
| 233 | + const TILING_CLASS *__restrict tilingData) | ||
| 209 | { | 234 | { |
| 210 | - Init(tilingData, cu_seqlens_q, cu_seqlens_ori_kv, cu_seqlens_cmp_kv, cmp_residual_kv); | 235 | + Init(tilingData, cu_seqlens_q, cu_seqlens_ori_kv, cu_seqlens_cmp_kv, seqused_q, seqused_ori_kv, seqused_cmp_kv, |
| 236 | + cmp_residual_kv); | ||
| 211 | 237 | ||
| 212 | // AIC Process | 238 | // AIC Process |
| 213 | if ASCEND_IS_AIC { | 239 | if ASCEND_IS_AIC { |
| @@ -222,16 +248,23 @@ __aicore__ inline void SparseFlashMlaGrad<SMLAGT>::Process( | |||
| 222 | int32_t s1BasicAccum = 0; | 248 | int32_t s1BasicAccum = 0; |
| 223 | for (int32_t j = 0; j < s1Loop; j++) { | 249 | for (int32_t j = 0; j < s1Loop; j++) { |
| 224 | bool changeB = s1Index + (curS1Basic - s1BasicAccum) > curS1; | 250 | bool changeB = s1Index + (curS1Basic - s1BasicAccum) > curS1; |
| 225 | - curLoopS1Basic = changeB ? curS1 - s1Index : (curS1Basic - s1BasicAccum); | 251 | + int64_t curLoopS1Physical = changeB ? curS1 - s1Index : (curS1Basic - s1BasicAccum); |
| 226 | - for (n2Index = 0; n2Index < dimN2; n2Index++) { | 252 | + curLoopS1Basic = curLoopS1Physical; |
| 227 | - GetActualSelCount(t1Index, n2Index, s2Loop); | 253 | + if constexpr (HAS_SEQUSED) { |
| 228 | - for (int32_t loop = 0; loop < s2Loop; loop++) { | 254 | + // EOD: 槽位内 [usedS1, curS1) 为 padding 行,仅计算有效区;物理轴推进保持不变 |
| 229 | - UpdateGmOffset(task, loop); | 255 | + curLoopS1Basic = Min(curLoopS1Physical, usedS1 - s1Index); |
| 230 | - CubeCompute(cubeOp); | 256 | + } |
| 231 | - task++; | 257 | + if (curLoopS1Basic > 0) { |
| 258 | + for (n2Index = 0; n2Index < dimN2; n2Index++) { | ||
| 259 | + GetActualSelCount(t1Index, n2Index, s2Loop); | ||
| 260 | + for (int32_t loop = 0; loop < s2Loop; loop++) { | ||
| 261 | + UpdateGmOffset(task, loop); | ||
| 262 | + CubeCompute(cubeOp); | ||
| 263 | + task++; | ||
| 264 | + } | ||
| 232 | } | 265 | } |
| 233 | } | 266 | } |
| 234 | - s1BasicAccum += curLoopS1Basic; | 267 | + s1BasicAccum += curLoopS1Physical; |
| 235 | if (changeB) { | 268 | if (changeB) { |
| 236 | ChangeBatchUpdate(); | 269 | ChangeBatchUpdate(); |
| 237 | } | 270 | } |
| @@ -261,16 +294,23 @@ __aicore__ inline void SparseFlashMlaGrad<SMLAGT>::Process( | |||
| 261 | int32_t s1BasicAccum = 0; | 294 | int32_t s1BasicAccum = 0; |
| 262 | for (int32_t j = 0; j < s1Loop; j++) { | 295 | for (int32_t j = 0; j < s1Loop; j++) { |
| 263 | bool changeB = s1Index + (curS1Basic - s1BasicAccum) > curS1; | 296 | bool changeB = s1Index + (curS1Basic - s1BasicAccum) > curS1; |
| 264 | - curLoopS1Basic = changeB ? curS1 - s1Index : (curS1Basic - s1BasicAccum); | 297 | + int64_t curLoopS1Physical = changeB ? curS1 - s1Index : (curS1Basic - s1BasicAccum); |
| 265 | - for (n2Index = 0; n2Index < dimN2; n2Index++) { | 298 | + curLoopS1Basic = curLoopS1Physical; |
| 266 | - GetActualSelCount(t1Index, n2Index, s2Loop); | 299 | + if constexpr (HAS_SEQUSED) { |
| 267 | - for (int32_t loop = 0; loop < s2Loop; loop++) { | 300 | + // EOD: 槽位内 [usedS1, curS1) 为 padding 行,仅计算有效区;物理轴推进保持不变 |
| 268 | - UpdateGmOffset(task, loop); | 301 | + curLoopS1Basic = Min(curLoopS1Physical, usedS1 - s1Index); |
| 269 | - VecCompute(vecOp); | 302 | + } |
| 270 | - task++; | 303 | + if (curLoopS1Basic > 0) { |
| 304 | + for (n2Index = 0; n2Index < dimN2; n2Index++) { | ||
| 305 | + GetActualSelCount(t1Index, n2Index, s2Loop); | ||
| 306 | + for (int32_t loop = 0; loop < s2Loop; loop++) { | ||
| 307 | + UpdateGmOffset(task, loop); | ||
| 308 | + VecCompute(vecOp); | ||
| 309 | + task++; | ||
| 310 | + } | ||
| 271 | } | 311 | } |
| 272 | } | 312 | } |
| 273 | - s1BasicAccum += curLoopS1Basic; | 313 | + s1BasicAccum += curLoopS1Physical; |
| 274 | if (changeB) { | 314 | if (changeB) { |
| 275 | ChangeBatchUpdate(); | 315 | ChangeBatchUpdate(); |
| 276 | } | 316 | } |
| @@ -348,7 +388,7 @@ __aicore__ inline void SparseFlashMlaGrad<SMLAGT>::UpdateGmOffset(int64_t task, | |||
| 348 | } | 388 | } |
| 349 | if constexpr (MODE == SMLAG_CFA_MODE) { | 389 | if constexpr (MODE == SMLAG_CFA_MODE) { |
| 350 | cmpKeyGmOffset = t3Offset * (dimN2 * dimDqk) + n2Index * dimDqk; | 390 | cmpKeyGmOffset = t3Offset * (dimN2 * dimDqk) + n2Index * dimDqk; |
| 351 | - runInfo[mmPingPongIdx].curS3 = curS3; | 391 | + runInfo[mmPingPongIdx].curS3 = usedS3; |
| 352 | } | 392 | } |
| 353 | runInfo[mmPingPongIdx].isOri = loop < oriS2Loop; | 393 | runInfo[mmPingPongIdx].isOri = loop < oriS2Loop; |
| 354 | selectedKGmOffset = runInfo[mmPingPongIdx].isOri ? oriKeyGmOffset + (oriWinStart + blkCntOffset) * dimN2 * dimDqk : | 394 | selectedKGmOffset = runInfo[mmPingPongIdx].isOri ? oriKeyGmOffset + (oriWinStart + blkCntOffset) * dimN2 * dimDqk : |
| @@ -370,8 +410,8 @@ __aicore__ inline void SparseFlashMlaGrad<SMLAGT>::UpdateGmOffset(int64_t task, | |||
| 370 | runInfo[mmPingPongIdx].lastBlockSize = 1; | 410 | runInfo[mmPingPongIdx].lastBlockSize = 1; |
| 371 | runInfo[mmPingPongIdx].isLastBasicBlock = false; | 411 | runInfo[mmPingPongIdx].isLastBasicBlock = false; |
| 372 | runInfo[mmPingPongIdx].s1Index = s1Index; | 412 | runInfo[mmPingPongIdx].s1Index = s1Index; |
| 373 | - runInfo[mmPingPongIdx].curS1 = curS1; | 413 | + runInfo[mmPingPongIdx].curS1 = usedS1; |
| 374 | - runInfo[mmPingPongIdx].curS2 = curS2; | 414 | + runInfo[mmPingPongIdx].curS2 = usedS2; |
| 375 | runInfo[mmPingPongIdx].oriWinStart = oriWinStart; | 415 | runInfo[mmPingPongIdx].oriWinStart = oriWinStart; |
| 376 | runInfo[mmPingPongIdx].oriWinEnd = oriWinEnd; | 416 | runInfo[mmPingPongIdx].oriWinEnd = oriWinEnd; |
| 377 | runInfo[mmPingPongIdx].selectedKGmOffset = selectedKGmOffset; | 417 | runInfo[mmPingPongIdx].selectedKGmOffset = selectedKGmOffset; |
| @@ -390,6 +430,25 @@ __aicore__ inline void SparseFlashMlaGrad<SMLAGT>::SaveLastInfo() | |||
| 390 | loopCnt++; | 430 | loopCnt++; |
| 391 | } | 431 | } |
| 392 | 432 | ||
| 433 | +template <typename SMLAGT> | ||
| 434 | +__aicore__ inline void SparseFlashMlaGrad<SMLAGT>::UpdateUsedSeqLen(int64_t batchIdx) | ||
| 435 | +{ | ||
| 436 | + usedS1 = curS1; | ||
| 437 | + usedS2 = curS2; | ||
| 438 | + usedS3 = curS3; | ||
| 439 | + if constexpr (HAS_SEQUSED) { | ||
| 440 | + if (hasUsedSeqQ) { | ||
| 441 | + usedS1 = ((__gm__ int32_t *)seqused_q)[batchIdx]; | ||
| 442 | + } | ||
| 443 | + if (hasUsedSeqOriKV) { | ||
| 444 | + usedS2 = ((__gm__ int32_t *)seqused_ori_kv)[batchIdx]; | ||
| 445 | + } | ||
| 446 | + if (hasUsedSeqCmpKV) { | ||
| 447 | + usedS3 = ((__gm__ int32_t *)seqused_cmp_kv)[batchIdx]; | ||
| 448 | + } | ||
| 449 | + } | ||
| 450 | +} | ||
| 451 | + | ||
| 393 | template <typename SMLAGT> | 452 | template <typename SMLAGT> |
| 394 | __aicore__ inline void SparseFlashMlaGrad<SMLAGT>::ChangeBatchUpdate() | 453 | __aicore__ inline void SparseFlashMlaGrad<SMLAGT>::ChangeBatchUpdate() |
| 395 | { | 454 | { |
| @@ -405,12 +464,14 @@ __aicore__ inline void SparseFlashMlaGrad<SMLAGT>::ChangeBatchUpdate() | |||
| 405 | curS3 = (((__gm__ int32_t *)cu_seqlens_cmp_kv)[bIndex] - ((__gm__ int32_t *)cu_seqlens_cmp_kv)[bIndex - 1]); | 464 | curS3 = (((__gm__ int32_t *)cu_seqlens_cmp_kv)[bIndex] - ((__gm__ int32_t *)cu_seqlens_cmp_kv)[bIndex - 1]); |
| 406 | residual = ((__gm__ int32_t *)cmp_residual_kv)[bIndex - 1]; | 465 | residual = ((__gm__ int32_t *)cmp_residual_kv)[bIndex - 1]; |
| 407 | } | 466 | } |
| 467 | + UpdateUsedSeqLen(bIndex - 1); | ||
| 408 | } else { | 468 | } else { |
| 409 | t1Offset = bIndex * curS1; | 469 | t1Offset = bIndex * curS1; |
| 410 | t2Offset = bIndex * curS2; | 470 | t2Offset = bIndex * curS2; |
| 411 | if constexpr (MODE == SMLAG_CFA_MODE) { | 471 | if constexpr (MODE == SMLAG_CFA_MODE) { |
| 412 | t3Offset = bIndex * curS3; | 472 | t3Offset = bIndex * curS3; |
| 413 | } | 473 | } |
| 474 | + UpdateUsedSeqLen(bIndex); | ||
| 414 | } | 475 | } |
| 415 | } | 476 | } |
| 416 | 477 | ||
| @@ -435,6 +496,8 @@ __aicore__ inline void SparseFlashMlaGrad<SMLAGT>::GetTndSeqLen(const int64_t t1 | |||
| 435 | residual = ((__gm__ int32_t *)cmp_residual_kv)[bIdx - 1]; | 496 | residual = ((__gm__ int32_t *)cmp_residual_kv)[bIdx - 1]; |
| 436 | } | 497 | } |
| 437 | 498 | ||
| 499 | + UpdateUsedSeqLen(bIdx - 1); | ||
| 500 | + | ||
| 438 | s1Index = t1Idx - t1Offset; | 501 | s1Index = t1Idx - t1Offset; |
| 439 | curS1Basic = t1Idx + s1BasicSize <= dimS1 ? s1BasicSize : dimS1 - t1Idx; | 502 | curS1Basic = t1Idx + s1BasicSize <= dimS1 ? s1BasicSize : dimS1 - t1Idx; |
| 440 | 503 | ||
| @@ -452,6 +515,7 @@ __aicore__ inline void SparseFlashMlaGrad<SMLAGT>::GetTndSeqLen(const int64_t t1 | |||
| 452 | if constexpr (MODE == SMLAG_CFA_MODE) { | 515 | if constexpr (MODE == SMLAG_CFA_MODE) { |
| 453 | t3Offset = bIdx * curS3; | 516 | t3Offset = bIdx * curS3; |
| 454 | } | 517 | } |
| 518 | + UpdateUsedSeqLen(bIdx); | ||
| 455 | curS1Basic = t1Idx + s1BasicSize <= dimB * dimS1 ? s1BasicSize : dimB * dimS1 - t1Idx; | 519 | curS1Basic = t1Idx + s1BasicSize <= dimB * dimS1 ? s1BasicSize : dimB * dimS1 - t1Idx; |
| 456 | 520 | ||
| 457 | int64_t bIndexTmp = bIdx; | 521 | int64_t bIndexTmp = bIdx; |
| @@ -467,14 +531,15 @@ template <typename SMLAGT> | |||
| 467 | __aicore__ inline void SparseFlashMlaGrad<SMLAGT>::GetActualSelCount(const int64_t t1Idx, const int64_t n2Idx, | 531 | __aicore__ inline void SparseFlashMlaGrad<SMLAGT>::GetActualSelCount(const int64_t t1Idx, const int64_t n2Idx, |
| 468 | int32_t &curS2Loop) | 532 | int32_t &curS2Loop) |
| 469 | { | 533 | { |
| 470 | - oriWinDiagOffset = curS2 - curS1; | 534 | + // EOD 下 usedS* 为槽位内有效长度(非 EOD 时等于 curS*),因果对齐与窗口上界都必须按有效长度计算 |
| 471 | - oriWinEnd = Min(s1Index + (curLoopS1Basic - 1) + oriWinRight + 1 + oriWinDiagOffset, curS2); | 535 | + oriWinDiagOffset = usedS2 - usedS1; |
| 536 | + oriWinEnd = Min(s1Index + (curLoopS1Basic - 1) + oriWinRight + 1 + oriWinDiagOffset, usedS2); | ||
| 472 | oriWinEnd = Max(oriWinEnd, 0); | 537 | oriWinEnd = Max(oriWinEnd, 0); |
| 473 | oriWinStart = Max(s1Index - oriWinLeft + oriWinDiagOffset, 0); | 538 | oriWinStart = Max(s1Index - oriWinLeft + oriWinDiagOffset, 0); |
| 474 | oriSelectedCount = oriWinEnd - oriWinStart; | 539 | oriSelectedCount = oriWinEnd - oriWinStart; |
| 475 | 540 | ||
| 476 | if constexpr (MODE == SMLAG_CFA_MODE) { | 541 | if constexpr (MODE == SMLAG_CFA_MODE) { |
| 477 | - cmpDiagOffset = curS3 * cmpRatio + residual - curS1; | 542 | + cmpDiagOffset = usedS3 * cmpRatio + residual - usedS1; |
| 478 | curMaxS3 = Max((cmpDiagOffset + s1Index + (curLoopS1Basic - 1) + 1) / cmpRatio, 0); | 543 | curMaxS3 = Max((cmpDiagOffset + s1Index + (curLoopS1Basic - 1) + 1) / cmpRatio, 0); |
| 479 | cmpSelectedCount = curMaxS3; | 544 | cmpSelectedCount = curMaxS3; |
| 480 | } | 545 | } |
| @@ -29,16 +29,15 @@ using namespace AscendC; | |||
| 29 | #if __CCE_AICORE__ == 310 | 29 | #if __CCE_AICORE__ == 310 |
| 30 | template <uint8_t inputDType, bool isTnd, uint16_t gTemplateType, uint16_t s2TemplateType, uint16_t dTemplateType, | 30 | template <uint8_t inputDType, bool isTnd, uint16_t gTemplateType, uint16_t s2TemplateType, uint16_t dTemplateType, |
| 31 | bool isOriKVExist, bool isCmpKVExist, bool isOriKVSparse, bool isCmpKVSparse, bool deterministic> | 31 | bool isOriKVExist, bool isCmpKVExist, bool isOriKVSparse, bool isCmpKVSparse, bool deterministic> |
| 32 | -__global__ __aicore__ void | 32 | +__global__ __aicore__ void sparse_flash_mla_grad( |
| 33 | -sparse_flash_mla_grad(__gm__ uint8_t *query, __gm__ uint8_t *d_out, __gm__ uint8_t *out, __gm__ uint8_t *lse, | 33 | + __gm__ uint8_t *query, __gm__ uint8_t *d_out, __gm__ uint8_t *out, __gm__ uint8_t *lse, __gm__ uint8_t *ori_kv, |
| 34 | - __gm__ uint8_t *ori_kv, __gm__ uint8_t *cmp_kv, __gm__ uint8_t *ori_sparse_indices, | 34 | + __gm__ uint8_t *cmp_kv, __gm__ uint8_t *ori_sparse_indices, __gm__ uint8_t *cmp_sparse_indices, |
| 35 | - __gm__ uint8_t *cmp_sparse_indices, __gm__ uint8_t *cu_seqlens_q, | 35 | + __gm__ uint8_t *cu_seqlens_q, __gm__ uint8_t *cu_seqlens_ori_kv, __gm__ uint8_t *cu_seqlens_cmp_kv, |
| 36 | - __gm__ uint8_t *cu_seqlens_ori_kv, __gm__ uint8_t *cu_seqlens_cmp_kv, __gm__ uint8_t *seqused_q, | 36 | + __gm__ uint8_t *seqused_q, __gm__ uint8_t *seqused_ori_kv, __gm__ uint8_t *seqused_cmp_kv, |
| 37 | - __gm__ uint8_t *seqused_ori_kv, __gm__ uint8_t *seqused_cmp_kv, __gm__ uint8_t *cmp_residual_kv, | 37 | + __gm__ uint8_t *cmp_residual_kv, __gm__ uint8_t *ori_topk_length, __gm__ uint8_t *cmp_topk_length, |
| 38 | - __gm__ uint8_t *ori_topk_length, __gm__ uint8_t *cmp_topk_length, __gm__ uint8_t *sinks, | 38 | + __gm__ uint8_t *sinks, __gm__ uint8_t *metadata, __gm__ uint8_t *d_query, __gm__ uint8_t *d_ori_kv, |
| 39 | - __gm__ uint8_t *metadata, __gm__ uint8_t *d_query, __gm__ uint8_t *d_ori_kv, | 39 | + __gm__ uint8_t *d_cmp_kv, __gm__ uint8_t *d_sinks, __gm__ uint8_t *ori_softmax_l1_norm, |
| 40 | - __gm__ uint8_t *d_cmp_kv, __gm__ uint8_t *d_sinks, __gm__ uint8_t *ori_softmax_l1_norm, | 40 | + __gm__ uint8_t *cmp_softmax_l1_norm, __gm__ uint8_t *workspace, __gm__ uint8_t *tiling_data) |
| 41 | - __gm__ uint8_t *cmp_softmax_l1_norm, __gm__ uint8_t *workspace, __gm__ uint8_t *tiling_data) | ||
| 42 | { | 41 | { |
| 43 | REGISTER_TILING_DEFAULT(optiling::smlag::SparseFlashMlaGradTilingDataRegbase); | 42 | REGISTER_TILING_DEFAULT(optiling::smlag::SparseFlashMlaGradTilingDataRegbase); |
| 44 | RegbaseSFAG<inputDType, isTnd, gTemplateType, s2TemplateType, dTemplateType, isOriKVExist, isCmpKVExist, | 43 | RegbaseSFAG<inputDType, isTnd, gTemplateType, s2TemplateType, dTemplateType, isOriKVExist, isCmpKVExist, |
| @@ -50,62 +49,63 @@ sparse_flash_mla_grad(__gm__ uint8_t *query, __gm__ uint8_t *d_out, __gm__ uint8 | |||
| 50 | } | 49 | } |
| 51 | 50 | ||
| 52 | #else | 51 | #else |
| 53 | -#define INVOKE_SMLAG_BASIC_IMPL(templateClass, ...) \ | 52 | +#define INVOKE_SMLAG_BASIC_IMPL(templateClass, ...) \ |
| 54 | - do { \ | 53 | + do { \ |
| 55 | - __gm__ uint8_t *user = GetUserWorkspace(workspace); \ | 54 | + __gm__ uint8_t *user = GetUserWorkspace(workspace); \ |
| 56 | GET_TILING_DATA_WITH_STRUCT(SparseFlashMlaGradTilingData, tiling_data_in, tiling_data); \ | 55 | GET_TILING_DATA_WITH_STRUCT(SparseFlashMlaGradTilingData, tiling_data_in, tiling_data); \ |
| 57 | - const SparseFlashMlaGradTilingData *__restrict tilingData = &tiling_data_in; \ | 56 | + const SparseFlashMlaGradTilingData *__restrict tilingData = &tiling_data_in; \ |
| 58 | - templateClass<SMLAG_BASIC::SMLAG_TYPE<SparseFlashMlaGradTilingData, __VA_ARGS__>> op; \ | 57 | + templateClass<SMLAG_BASIC::SMLAG_TYPE<SparseFlashMlaGradTilingData, __VA_ARGS__>> op; \ |
| 59 | - op.Process(query, ori_kv, cmp_kv, out, d_out, lse, cmp_sparse_indices, \ | 58 | + op.Process(query, ori_kv, cmp_kv, out, d_out, lse, cmp_sparse_indices, cu_seqlens_q, cu_seqlens_ori_kv, \ |
| 60 | - cu_seqlens_q, cu_seqlens_ori_kv, cu_seqlens_cmp_kv, cmp_residual_kv, \ | 59 | + cu_seqlens_cmp_kv, seqused_q, seqused_ori_kv, seqused_cmp_kv, cmp_residual_kv, sinks, d_query, \ |
| 61 | - sinks, d_query, d_ori_kv, d_cmp_kv, d_sinks, cmp_softmax_l1_norm, user, tilingData);\ | 60 | + d_ori_kv, d_cmp_kv, d_sinks, cmp_softmax_l1_norm, user, tilingData); \ |
| 62 | } while (0) | 61 | } while (0) |
| 63 | 62 | ||
| 64 | -template<int LAYOUT, int MODE> | 63 | +template <int LAYOUT, int MODE, bool HAS_SEQUSED> |
| 65 | -__global__ __aicore__ void | 64 | +__global__ __aicore__ void sparse_flash_mla_grad( |
| 66 | -sparse_flash_mla_grad(__gm__ uint8_t *query, __gm__ uint8_t *d_out, __gm__ uint8_t *out, __gm__ uint8_t *lse, | 65 | + __gm__ uint8_t *query, __gm__ uint8_t *d_out, __gm__ uint8_t *out, __gm__ uint8_t *lse, __gm__ uint8_t *ori_kv, |
| 67 | - __gm__ uint8_t *ori_kv, __gm__ uint8_t *cmp_kv, | 66 | + __gm__ uint8_t *cmp_kv, __gm__ uint8_t *ori_sparse_indices, __gm__ uint8_t *cmp_sparse_indices, |
| 68 | - __gm__ uint8_t *ori_sparse_indices, __gm__ uint8_t *cmp_sparse_indices, | 67 | + __gm__ uint8_t *cu_seqlens_q, __gm__ uint8_t *cu_seqlens_ori_kv, __gm__ uint8_t *cu_seqlens_cmp_kv, |
| 69 | - __gm__ uint8_t *cu_seqlens_q, __gm__ uint8_t *cu_seqlens_ori_kv, __gm__ uint8_t *cu_seqlens_cmp_kv, | 68 | + __gm__ uint8_t *seqused_q, __gm__ uint8_t *seqused_ori_kv, __gm__ uint8_t *seqused_cmp_kv, |
| 70 | - __gm__ uint8_t *seqused_q, __gm__ uint8_t *seqused_ori_kv, __gm__ uint8_t *seqused_cmp_kv, | 69 | + __gm__ uint8_t *cmp_residual_kv, __gm__ uint8_t *ori_topk_length, __gm__ uint8_t *cmp_topk_length, |
| 71 | - __gm__ uint8_t *cmp_residual_kv, __gm__ uint8_t *ori_topk_length, __gm__ uint8_t *cmp_topk_length, | 70 | + __gm__ uint8_t *sinks, __gm__ uint8_t *metadata, __gm__ uint8_t *d_query, __gm__ uint8_t *d_ori_kv, |
| 72 | - __gm__ uint8_t *sinks, __gm__ uint8_t *metadata, | 71 | + __gm__ uint8_t *d_cmp_kv, __gm__ uint8_t *d_sinks, __gm__ uint8_t *ori_softmax_l1_norm, |
| 73 | - __gm__ uint8_t *d_query, __gm__ uint8_t *d_ori_kv, __gm__ uint8_t *d_cmp_kv, | 72 | + __gm__ uint8_t *cmp_softmax_l1_norm, __gm__ uint8_t *workspace, __gm__ uint8_t *tiling_data) |
| 74 | - __gm__ uint8_t *d_sinks, __gm__ uint8_t *ori_softmax_l1_norm, __gm__ uint8_t *cmp_softmax_l1_norm, | ||
| 75 | - __gm__ uint8_t *workspace, __gm__ uint8_t *tiling_data) | ||
| 76 | { | 73 | { |
| 77 | KERNEL_TASK_TYPE_DEFAULT(KERNEL_TYPE_MIX_AIC_1_2); | 74 | KERNEL_TASK_TYPE_DEFAULT(KERNEL_TYPE_MIX_AIC_1_2); |
| 78 | 75 | ||
| 79 | if constexpr (ORIG_DTYPE_QUERY == DT_FLOAT16) { | 76 | if constexpr (ORIG_DTYPE_QUERY == DT_FLOAT16) { |
| 80 | if (MODE == SMLAG_SCFA_MODE) { | 77 | if (MODE == SMLAG_SCFA_MODE) { |
| 81 | if (LAYOUT == SMLAG_LAYOUT_BSND) { | 78 | if (LAYOUT == SMLAG_LAYOUT_BSND) { |
| 82 | - INVOKE_SMLAG_BASIC_IMPL(SMLAG_BASIC::SelectedAttentionGradBasic, half, true); | 79 | + INVOKE_SMLAG_BASIC_IMPL(SMLAG_BASIC::SelectedAttentionGradBasic, half, true, SMLAG_SCFA_MODE, |
| 80 | + HAS_SEQUSED); | ||
| 83 | } else { | 81 | } else { |
| 84 | - INVOKE_SMLAG_BASIC_IMPL(SMLAG_BASIC::SelectedAttentionGradBasic, half, false); | 82 | + INVOKE_SMLAG_BASIC_IMPL(SMLAG_BASIC::SelectedAttentionGradBasic, half, false, SMLAG_SCFA_MODE, |
| 83 | + HAS_SEQUSED); | ||
| 85 | } | 84 | } |
| 86 | } else { | 85 | } else { |
| 87 | if (LAYOUT == SMLAG_LAYOUT_BSND) { | 86 | if (LAYOUT == SMLAG_LAYOUT_BSND) { |
| 88 | - INVOKE_SMLAG_BASIC_IMPL(SMLAG_BASIC::SparseFlashMlaGrad, half, true, MODE); | 87 | + INVOKE_SMLAG_BASIC_IMPL(SMLAG_BASIC::SparseFlashMlaGrad, half, true, MODE, HAS_SEQUSED); |
| 89 | } else { | 88 | } else { |
| 90 | - INVOKE_SMLAG_BASIC_IMPL(SMLAG_BASIC::SparseFlashMlaGrad, half, false, MODE); | 89 | + INVOKE_SMLAG_BASIC_IMPL(SMLAG_BASIC::SparseFlashMlaGrad, half, false, MODE, HAS_SEQUSED); |
| 91 | } | 90 | } |
| 92 | } | 91 | } |
| 93 | } | 92 | } |
| 94 | if constexpr (ORIG_DTYPE_QUERY == DT_BF16) { | 93 | if constexpr (ORIG_DTYPE_QUERY == DT_BF16) { |
| 95 | if (MODE == SMLAG_SCFA_MODE) { | 94 | if (MODE == SMLAG_SCFA_MODE) { |
| 96 | if (LAYOUT == SMLAG_LAYOUT_BSND) { | 95 | if (LAYOUT == SMLAG_LAYOUT_BSND) { |
| 97 | - INVOKE_SMLAG_BASIC_IMPL(SMLAG_BASIC::SelectedAttentionGradBasic, bfloat16_t, true); | 96 | + INVOKE_SMLAG_BASIC_IMPL(SMLAG_BASIC::SelectedAttentionGradBasic, bfloat16_t, true, SMLAG_SCFA_MODE, |
| 97 | + HAS_SEQUSED); | ||
| 98 | } else { | 98 | } else { |
| 99 | - INVOKE_SMLAG_BASIC_IMPL(SMLAG_BASIC::SelectedAttentionGradBasic, bfloat16_t, false); | 99 | + INVOKE_SMLAG_BASIC_IMPL(SMLAG_BASIC::SelectedAttentionGradBasic, bfloat16_t, false, SMLAG_SCFA_MODE, |
| 100 | + HAS_SEQUSED); | ||
| 100 | } | 101 | } |
| 101 | } else { | 102 | } else { |
| 102 | if (LAYOUT == SMLAG_LAYOUT_BSND) { | 103 | if (LAYOUT == SMLAG_LAYOUT_BSND) { |
| 103 | - INVOKE_SMLAG_BASIC_IMPL(SMLAG_BASIC::SparseFlashMlaGrad, bfloat16_t, true, MODE); | 104 | + INVOKE_SMLAG_BASIC_IMPL(SMLAG_BASIC::SparseFlashMlaGrad, bfloat16_t, true, MODE, HAS_SEQUSED); |
| 104 | } else { | 105 | } else { |
| 105 | - INVOKE_SMLAG_BASIC_IMPL(SMLAG_BASIC::SparseFlashMlaGrad, bfloat16_t, false, MODE); | 106 | + INVOKE_SMLAG_BASIC_IMPL(SMLAG_BASIC::SparseFlashMlaGrad, bfloat16_t, false, MODE, HAS_SEQUSED); |
| 106 | } | 107 | } |
| 107 | } | 108 | } |
| 108 | } | 109 | } |
| 109 | } | 110 | } |
| 110 | #endif | 111 | #endif |
| 111 | - | ||
| @@ -30,13 +30,14 @@ ASCENDC_TPL_ARGS_DECL(SparseFlashMlaGrad, // 算子OpType | |||
| 30 | ASCENDC_TPL_UINT_DECL(LAYOUT, ASCENDC_TPL_4_BW, ASCENDC_TPL_UI_LIST, SMLAG_LAYOUT_BSND, | 30 | ASCENDC_TPL_UINT_DECL(LAYOUT, ASCENDC_TPL_4_BW, ASCENDC_TPL_UI_LIST, SMLAG_LAYOUT_BSND, |
| 31 | SMLAG_LAYOUT_TND), | 31 | SMLAG_LAYOUT_TND), |
| 32 | ASCENDC_TPL_UINT_DECL(MODE, ASCENDC_TPL_4_BW, ASCENDC_TPL_UI_LIST, SMLAG_SWA_MODE, SMLAG_CFA_MODE, | 32 | ASCENDC_TPL_UINT_DECL(MODE, ASCENDC_TPL_4_BW, ASCENDC_TPL_UI_LIST, SMLAG_SWA_MODE, SMLAG_CFA_MODE, |
| 33 | - SMLAG_SCFA_MODE), ); | 33 | + SMLAG_SCFA_MODE), |
| 34 | + ASCENDC_TPL_BOOL_DECL(HAS_SEQUSED, 0, 1), ); | ||
| 34 | 35 | ||
| 35 | // 支持的模板参数组合 | 36 | // 支持的模板参数组合 |
| 36 | // 用于调用GET_TPL_TILING_KEY获取TilingKey时,接口内部校验TilingKey是否合法 | 37 | // 用于调用GET_TPL_TILING_KEY获取TilingKey时,接口内部校验TilingKey是否合法 |
| 37 | -ASCENDC_TPL_SEL(ASCENDC_TPL_ARGS_SEL(ASCENDC_TPL_UINT_SEL(LAYOUT, ASCENDC_TPL_UI_LIST, SMLAG_LAYOUT_BSND, | 38 | +ASCENDC_TPL_SEL(ASCENDC_TPL_ARGS_SEL( |
| 38 | - SMLAG_LAYOUT_TND), | 39 | + ASCENDC_TPL_UINT_SEL(LAYOUT, ASCENDC_TPL_UI_LIST, SMLAG_LAYOUT_BSND, SMLAG_LAYOUT_TND), |
| 39 | - ASCENDC_TPL_UINT_SEL(MODE, ASCENDC_TPL_UI_LIST, SMLAG_SWA_MODE, SMLAG_CFA_MODE, | 40 | + ASCENDC_TPL_UINT_SEL(MODE, ASCENDC_TPL_UI_LIST, SMLAG_SWA_MODE, SMLAG_CFA_MODE, SMLAG_SCFA_MODE), |
| 40 | - SMLAG_SCFA_MODE), ), ); | 41 | + ASCENDC_TPL_BOOL_SEL(HAS_SEQUSED, 0, 1), ), ); |
| 41 | 42 | ||
| 42 | #endif // TEMPLATE_TILING_KEY | 43 | #endif // TEMPLATE_TILING_KEY |