Merged
fix(moe_gating_top_k): sigmoid除法改为默认模式,对齐aclnnSigmoid舍入口径 #14971
CPZhouAdd on 10 days ago
fix(moe_gating_top_k): sigmoid除法改为默认模式,对齐aclnnSigmoid舍入口径 #14971
Merged
Total: 3 files changed+5-9
| @@ -25,8 +25,6 @@ namespace MoeGatingTopK { | |||
| 25 | using namespace AscendC; | 25 | using namespace AscendC; |
| 26 | using Reg::RegTensor; | 26 | using Reg::RegTensor; |
| 27 | 27 | ||
| 28 | -constexpr Reg::DivSpecificMode EK_DIV_MODE = {Reg::MaskMergeMode::ZEROING, true}; | ||
| 29 | - | ||
| 30 | template <typename T> | 28 | template <typename T> |
| 31 | class MoeGatingTopKEKFullloadRegbase { | 29 | class MoeGatingTopKEKFullloadRegbase { |
| 32 | public: | 30 | public: |
| @@ -163,7 +161,7 @@ __aicore__ inline void MoeGatingTopKEKFullloadRegbase<T>::ComputeX() | |||
| 163 | Reg::Muls(vreg1, vregInFp32, static_cast<float>(-1), preg0); | 161 | Reg::Muls(vreg1, vregInFp32, static_cast<float>(-1), preg0); |
| 164 | Reg::Exp(vreg2, vreg1, preg0); | 162 | Reg::Exp(vreg2, vreg1, preg0); |
| 165 | Reg::Adds(vreg3, vreg2, static_cast<float>(1), preg0); | 163 | Reg::Adds(vreg3, vreg2, static_cast<float>(1), preg0); |
| 166 | - Reg::Div<float, &EK_DIV_MODE>(vregSigmoidResult, vregOne, vreg3, preg0); | 164 | + Reg::Div(vregSigmoidResult, vregOne, vreg3, preg0); |
C | |||
| 167 | Reg::Add(vregBiasResult, vregSigmoidResult, vregBiasFp32, preg0); | 165 | Reg::Add(vregBiasResult, vregSigmoidResult, vregBiasFp32, preg0); |
| 168 | Reg::Arange(vregIndex, static_cast<int32_t>(i * VL_FLOAT_SIZE)); | 166 | Reg::Arange(vregIndex, static_cast<int32_t>(i * VL_FLOAT_SIZE)); |
| 169 | Reg::StoreAlign(sigmoidOutAddr + i * VL_FLOAT_SIZE, vregSigmoidResult, preg0); | 167 | Reg::StoreAlign(sigmoidOutAddr + i * VL_FLOAT_SIZE, vregSigmoidResult, preg0); |
| @@ -29,7 +29,6 @@ constexpr int32_t CONSTANT_TWO = 2; | |||
| 29 | constexpr int32_t CONSTANT_THREE = 3; | 29 | constexpr int32_t CONSTANT_THREE = 3; |
| 30 | constexpr int32_t CONSTANT_FOUR = 4; | 30 | constexpr int32_t CONSTANT_FOUR = 4; |
| 31 | constexpr int32_t CONSTANT_EIGHT = 8; | 31 | constexpr int32_t CONSTANT_EIGHT = 8; |
| 32 | -constexpr Reg::DivSpecificMode mode = {Reg::MaskMergeMode::ZEROING, true}; | ||
| 33 | 32 | ||
| 34 | template <typename T, typename U1 = int32_t, typename U2 = int32_t> | 33 | template <typename T, typename U1 = int32_t, typename U2 = int32_t> |
| 35 | class MoeGatingTopKRegbase { | 34 | class MoeGatingTopKRegbase { |
| @@ -401,7 +400,7 @@ __aicore__ inline void MoeGatingTopKRegbase<T, U1, U2>::SigmoidWithBias(LocalTen | |||
| 401 | Reg::Muls(vreg1, vregInFp32, static_cast<float>(-1), preg0); | 400 | Reg::Muls(vreg1, vregInFp32, static_cast<float>(-1), preg0); |
| 402 | Reg::Exp(vreg2, vreg1, preg0); | 401 | Reg::Exp(vreg2, vreg1, preg0); |
| 403 | Reg::Adds(vreg3, vreg2, static_cast<float>(1), preg0); | 402 | Reg::Adds(vreg3, vreg2, static_cast<float>(1), preg0); |
| 404 | - Reg::Div<float, &mode>(vregSigmoidResult, vregOne, vreg3, preg0); | 403 | + Reg::Div(vregSigmoidResult, vregOne, vreg3, preg0); |
| 405 | Reg::Add(vregBiasResult, vregSigmoidResult, vregBiasFp32, preg0); | 404 | Reg::Add(vregBiasResult, vregSigmoidResult, vregBiasFp32, preg0); |
| 406 | Reg::Arange(vregIndex, static_cast<int32_t>(i * VL_FLOAT_SIZE)); | 405 | Reg::Arange(vregIndex, static_cast<int32_t>(i * VL_FLOAT_SIZE)); |
| 407 | Reg::StoreAlign(sigmoidOutAddr + i * VL_FLOAT_SIZE, vregSigmoidResult, preg0); | 406 | Reg::StoreAlign(sigmoidOutAddr + i * VL_FLOAT_SIZE, vregSigmoidResult, preg0); |
| @@ -446,7 +445,7 @@ __aicore__ inline void MoeGatingTopKRegbase<T, U1, U2>::SigmoidWithoutBias(Local | |||
| 446 | Reg::Muls(vreg1, vregInFp32, static_cast<float>(-1), preg0); | 445 | Reg::Muls(vreg1, vregInFp32, static_cast<float>(-1), preg0); |
| 447 | Reg::Exp(vreg2, vreg1, preg0); | 446 | Reg::Exp(vreg2, vreg1, preg0); |
| 448 | Reg::Adds(vreg3, vreg2, static_cast<float>(1), preg0); | 447 | Reg::Adds(vreg3, vreg2, static_cast<float>(1), preg0); |
| 449 | - Reg::Div<float, &mode>(vregSigmoidResult, vregOne, vreg3, preg0); | 448 | + Reg::Div(vregSigmoidResult, vregOne, vreg3, preg0); |
| 450 | Reg::Arange(vregIndex, static_cast<int32_t>(i * VL_FLOAT_SIZE)); | 449 | Reg::Arange(vregIndex, static_cast<int32_t>(i * VL_FLOAT_SIZE)); |
| 451 | Reg::StoreAlign(sigmoidOutAddr + i * VL_FLOAT_SIZE, vregSigmoidResult, preg0); | 450 | Reg::StoreAlign(sigmoidOutAddr + i * VL_FLOAT_SIZE, vregSigmoidResult, preg0); |
| 452 | Reg::StoreAlign(addBiasOutAddr + i * VL_FLOAT_SIZE, vregSigmoidResult, preg0); | 451 | Reg::StoreAlign(addBiasOutAddr + i * VL_FLOAT_SIZE, vregSigmoidResult, preg0); |
| @@ -31,7 +31,6 @@ constexpr int32_t WG_CONSTANT_TWO = 2; | |||
| 31 | constexpr int32_t WG_CONSTANT_TEN = 10; | 31 | constexpr int32_t WG_CONSTANT_TEN = 10; |
| 32 | constexpr int64_t DEFAULT_BATCH_ROWS = 4; | 32 | constexpr int64_t DEFAULT_BATCH_ROWS = 4; |
| 33 | constexpr int64_t SINGLE_EXPERT_FALLBACK_BATCH = 512; | 33 | constexpr int64_t SINGLE_EXPERT_FALLBACK_BATCH = 512; |
| 34 | -constexpr Reg::DivSpecificMode WG_DIV_MODE = {Reg::MaskMergeMode::ZEROING, true}; | ||
| 35 | 34 | ||
| 36 | template <typename T> | 35 | template <typename T> |
| 37 | class MoeGatingTopKWithoutGroupRegbase { | 36 | class MoeGatingTopKWithoutGroupRegbase { |
| @@ -191,7 +190,7 @@ __aicore__ inline void MoeGatingTopKWithoutGroupRegbase<T>::ComputeNormSigmoid(_ | |||
| 191 | Reg::Muls(vregNegInput, vregIn, static_cast<float>(-1), preg0); | 190 | Reg::Muls(vregNegInput, vregIn, static_cast<float>(-1), preg0); |
| 192 | Reg::Exp(vregExpNeg, vregNegInput, preg0); | 191 | Reg::Exp(vregExpNeg, vregNegInput, preg0); |
| 193 | Reg::Adds(vregExpPlusOne, vregExpNeg, static_cast<float>(1), preg0); | 192 | Reg::Adds(vregExpPlusOne, vregExpNeg, static_cast<float>(1), preg0); |
| 194 | - Reg::Div<float, &WG_DIV_MODE>(vregNorm, vregOne, vregExpPlusOne, preg0); | 193 | + Reg::Div(vregNorm, vregOne, vregExpPlusOne, preg0); |
| 195 | Reg::StoreAlign(xNormAddr + i * VL_FLOAT_SIZE, vregNorm, preg0); | 194 | Reg::StoreAlign(xNormAddr + i * VL_FLOAT_SIZE, vregNorm, preg0); |
| 196 | } | 195 | } |
| 197 | } | 196 | } |
| @@ -708,7 +707,7 @@ __aicore__ inline void MoeGatingTopKWithoutGroupRegbase<T>::ProcessSingleExpertS | |||
| 708 | Reg::Muls(vregTmp1, vregIn, static_cast<float>(-1), preg0); | 707 | Reg::Muls(vregTmp1, vregIn, static_cast<float>(-1), preg0); |
| 709 | Reg::Exp(vregTmp2, vregTmp1, preg0); | 708 | Reg::Exp(vregTmp2, vregTmp1, preg0); |
| 710 | Reg::Adds(vregTmp3, vregTmp2, static_cast<float>(1), preg0); | 709 | Reg::Adds(vregTmp3, vregTmp2, static_cast<float>(1), preg0); |
| 711 | - Reg::Div<float, &WG_DIV_MODE>(vregNorm, vregOne, vregTmp3, preg0); | 710 | + Reg::Div(vregNorm, vregOne, vregTmp3, preg0); |
| 712 | if constexpr (NEED_RENORM) { | 711 | if constexpr (NEED_RENORM) { |
| 713 | Reg::Adds(vregSumBcast, vregNorm, eps_, preg0); | 712 | Reg::Adds(vregSumBcast, vregNorm, eps_, preg0); |
| 714 | Reg::Div(vregOut, vregNorm, vregSumBcast, preg0); | 713 | Reg::Div(vregOut, vregNorm, vregSumBcast, preg0); |
其余gatingTopK & v2算子是否涉及