Merged
fix: resolve coding standard findings in norm operators #12931
rkAdd on 25 days ago
fix: resolve coding standard findings in norm operators #12931
Merged
Merged fromwangpengbo26/ops-nncpp_rule_2610intocann/ops-nnmaster
Total: 14 files changed+60-45
Mnorm/add_rms_norm_hi_f4_quant/op_host/op_tiling/arch92/add_rms_norm_hi_f4_quant_tiling_base.cpp+5-5
| @@ -147,7 +147,6 @@ ge::graphStatus AddRmsNormHiF4QuantRegbaseTilingBase::CheckOutputDtype() | |||
| 147 | OP_LOGD(context_->GetNodeName(), "Enter CheckOutputDtype."); | 147 | OP_LOGD(context_->GetNodeName(), "Enter CheckOutputDtype."); |
| 148 | OP_CHECK_NULL_WITH_CONTEXT(context_, context_->GetOutputDesc(Y_INDEX)); | 148 | OP_CHECK_NULL_WITH_CONTEXT(context_, context_->GetOutputDesc(Y_INDEX)); |
| 149 | ge::DataType yDtype = context_->GetOutputDesc(Y_INDEX)->GetDataType(); | 149 | ge::DataType yDtype = context_->GetOutputDesc(Y_INDEX)->GetDataType(); |
| 150 | - | ||
| 151 | if (yDtype != Ops::NN::DT_HIFLOAT4) { | 150 | if (yDtype != Ops::NN::DT_HIFLOAT4) { |
| 152 | OP_LOGE(context_->GetNodeName(), "Output y dtype should be HIFLOAT4."); | 151 | OP_LOGE(context_->GetNodeName(), "Output y dtype should be HIFLOAT4."); |
| 153 | return ge::GRAPH_FAILED; | 152 | return ge::GRAPH_FAILED; |
| @@ -217,9 +216,10 @@ ge::graphStatus AddRmsNormHiF4QuantRegbaseTilingBase::CheckOutputShapeValue() | |||
| 217 | } | 216 | } |
| 218 | 217 | ||
| 219 | uint64_t expectedLastDim = Ops::Base::CeilDiv(numCol_, static_cast<uint64_t>(HIF4_BLOCK_SIZE)); | 218 | uint64_t expectedLastDim = Ops::Base::CeilDiv(numCol_, static_cast<uint64_t>(HIF4_BLOCK_SIZE)); |
| 220 | - if (scaleShape.GetDim(scaleRank - 2) != static_cast<int64_t>(expectedLastDim)) { | 219 | + if (scaleShape.GetDim(scaleRank - NUM_TWO) != static_cast<int64_t>(expectedLastDim)) { |
| 221 | - OP_LOGE(context_->GetNodeName(), "scale dim[%zu]=%ld should be CeilDiv(R=%ld, 64) = %ld.", scaleRank - 2, | 220 | + OP_LOGE(context_->GetNodeName(), "scale dim[%zu]=%ld should be CeilDiv(R=%ld, 64) = %ld.", scaleRank - NUM_TWO, |
| 222 | - scaleShape.GetDim(scaleRank - 2), static_cast<int64_t>(numCol_), static_cast<int64_t>(expectedLastDim)); | 221 | + scaleShape.GetDim(scaleRank - NUM_TWO), static_cast<int64_t>(numCol_), |
| 222 | + static_cast<int64_t>(expectedLastDim)); | ||
| 223 | return ge::GRAPH_FAILED; | 223 | return ge::GRAPH_FAILED; |
| 224 | } | 224 | } |
| 225 | 225 | ||
| @@ -375,7 +375,7 @@ ge::graphStatus AddRmsNormHiF4QuantRegbaseTilingBase::GetPlatformInfo() | |||
| 375 | OP_LOGD(context_->GetNodeName(), "Enter GetPlatformInfo."); | 375 | OP_LOGD(context_->GetNodeName(), "Enter GetPlatformInfo."); |
| 376 | 376 | ||
| 377 | auto platformInfo = context_->GetPlatformInfo(); | 377 | auto platformInfo = context_->GetPlatformInfo(); |
| 378 | - auto compileInfoPtr = reinterpret_cast<const AddRmsNormHiF4QuantCompileInfo*>(context_->GetCompileInfo()); | 378 | + auto compileInfoPtr = static_cast<const AddRmsNormHiF4QuantCompileInfo*>(context_->GetCompileInfo()); |
| 379 | if (compileInfoPtr != nullptr) { | 379 | if (compileInfoPtr != nullptr) { |
| 380 | totalCoreNum_ = compileInfoPtr->totalCoreNum; | 380 | totalCoreNum_ = compileInfoPtr->totalCoreNum; |
| 381 | maxUbSize_ = compileInfoPtr->totalUbSize; | 381 | maxUbSize_ = compileInfoPtr->totalUbSize; |
| @@ -61,7 +61,13 @@ constexpr int64_t DQ_HIFP4_SCALETMP_ALIGN = 256; | |||
| 61 | constexpr int64_t DQ_HIFP4_BLOCK_BYTE = 32; | 61 | constexpr int64_t DQ_HIFP4_BLOCK_BYTE = 32; |
| 62 | constexpr int64_t DQ_HIFP4_CAST_COPYOUT_PACK4_NUM = 4; | 62 | constexpr int64_t DQ_HIFP4_CAST_COPYOUT_PACK4_NUM = 4; |
| 63 | 63 | ||
| 64 | -constexpr static uint32_t VL_F32 = platform::GetVRegSize() / sizeof(float); | 64 | +constexpr int64_t HIF4_MAX_PER4_ELEMENTS_PER_GROUP = 16; |
| 65 | +constexpr int64_t HIF4_MAX_PER8_ELEMENTS_PER_GROUP = 8; | ||
| 66 | +constexpr int64_t HIF4_TMP_SCALE_ELEMENTS_PER_GROUP = 32; | ||
| 67 | +constexpr int64_t HIF4_DEINTERLEAVE_REGISTERS_PER_LOAD = 2; | ||
| 68 | + | ||
| 69 | +constexpr static uint32_t VECTOR_LENGTH = platform::GetVRegSize(); | ||
| 70 | +constexpr static uint32_t VL_F32 = VECTOR_LENGTH / sizeof(float); | ||
| 65 | constexpr static uint32_t BLOCK_F32_ALIGN_NUM = Ops::Base::GetUbBlockSize() / sizeof(float); | 71 | constexpr static uint32_t BLOCK_F32_ALIGN_NUM = Ops::Base::GetUbBlockSize() / sizeof(float); |
| 66 | constexpr static uint32_t UB_BLOCK_SIZE = Ops::Base::GetUbBlockSize(); | 72 | constexpr static uint32_t UB_BLOCK_SIZE = Ops::Base::GetUbBlockSize(); |
| 67 | 73 | ||
| @@ -114,9 +114,9 @@ public: | |||
| 114 | pPipe->InitBuffer(bufE8_, bufE8Buffer_ * sizeof(int16_t)); | 114 | pPipe->InitBuffer(bufE8_, bufE8Buffer_ * sizeof(int16_t)); |
| 115 | pPipe->InitBuffer(buf1E8_, buf1E8Buffer_ * sizeof(int32_t)); | 115 | pPipe->InitBuffer(buf1E8_, buf1E8Buffer_ * sizeof(int32_t)); |
| 116 | pPipe->InitBuffer(buf1E16_, buf1E16Buffer_ * sizeof(int16_t)); | 116 | pPipe->InitBuffer(buf1E16_, buf1E16Buffer_ * sizeof(int16_t)); |
| 117 | - pPipe->InitBuffer(bufMaxPer4_, maxPer4Buffer_ * 16 * sizeof(int16_t)); | 117 | + pPipe->InitBuffer(bufMaxPer4_, maxPer4Buffer_ * HIF4_MAX_PER4_ELEMENTS_PER_GROUP * sizeof(int16_t)); |
| 118 | - pPipe->InitBuffer(bufMaxPer8_, maxPer8Buffer_ * 8 * sizeof(int16_t)); | 118 | + pPipe->InitBuffer(bufMaxPer8_, maxPer8Buffer_ * HIF4_MAX_PER8_ELEMENTS_PER_GROUP * sizeof(int16_t)); |
| 119 | - pPipe->InitBuffer(bufTmpScale_, tmpScaleBuffer_ * 32 * sizeof(int16_t)); | 119 | + pPipe->InitBuffer(bufTmpScale_, tmpScaleBuffer_ * HIF4_TMP_SCALE_ELEMENTS_PER_GROUP * sizeof(int16_t)); |
| 120 | 120 | ||
| 121 | uint64_t quantYBufSize = CeilAlign(CeilDiv(numColAlign_ * rowFactor_ / DIGIT_TWO, MX_STEP_PROCESS_NUM), | 121 | uint64_t quantYBufSize = CeilAlign(CeilDiv(numColAlign_ * rowFactor_ / DIGIT_TWO, MX_STEP_PROCESS_NUM), |
| 122 | DIGIT_FOUR) * | 122 | DIGIT_FOUR) * |
| @@ -125,8 +125,8 @@ public: | |||
| 125 | pPipe->InitBuffer(outQueueQuantY, DOUBLE_BUFFER_NUM, quantYBufSize); | 125 | pPipe->InitBuffer(outQueueQuantY, DOUBLE_BUFFER_NUM, quantYBufSize); |
| 126 | pPipe->InitBuffer(outQueueScale, DOUBLE_BUFFER_NUM, alignTo256UbFormer * sizeof(float)); | 126 | pPipe->InitBuffer(outQueueScale, DOUBLE_BUFFER_NUM, alignTo256UbFormer * sizeof(float)); |
| 127 | 127 | ||
| 128 | - sysRegLen_ = 256; | 128 | + sysRegLen_ = VECTOR_LENGTH; |
| 129 | - gmCopyInRegStep_ = sysRegLen_ / sizeof(float) * 2; | 129 | + gmCopyInRegStep_ = sysRegLen_ / sizeof(float) * HIF4_DEINTERLEAVE_REGISTERS_PER_LOAD; |
| 130 | gmCopyOutRegStep_ = sysRegLen_ / sizeof(int32_t) / DQ_HIFP4_CAST_COPYOUT_PACK4_NUM; | 130 | gmCopyOutRegStep_ = sysRegLen_ / sizeof(int32_t) / DQ_HIFP4_CAST_COPYOUT_PACK4_NUM; |
| 131 | gmCopyOutScaleRegStep_ = sysRegLen_ / sizeof(float); | 131 | gmCopyOutScaleRegStep_ = sysRegLen_ / sizeof(float); |
| 132 | gmCopyInRegStep2_ = sysRegLen_ / sizeof(T_X); | 132 | gmCopyInRegStep2_ = sysRegLen_ / sizeof(T_X); |
| @@ -855,7 +855,7 @@ private: | |||
| 855 | uint32_t vlForHalfNumber; | 855 | uint32_t vlForHalfNumber; |
| 856 | uint16_t elementAfterReduce; | 856 | uint16_t elementAfterReduce; |
| 857 | 857 | ||
| 858 | - int64_t sysRegLen_ = 256; | 858 | + int64_t sysRegLen_ = VECTOR_LENGTH; |
| 859 | int64_t gmCopyInRegStep_ = 0; | 859 | int64_t gmCopyInRegStep_ = 0; |
| 860 | int64_t gmCopyOutRegStep_ = 0; | 860 | int64_t gmCopyOutRegStep_ = 0; |
| 861 | int64_t gmCopyOutScaleRegStep_ = 0; | 861 | int64_t gmCopyOutScaleRegStep_ = 0; |
| @@ -113,12 +113,12 @@ public: | |||
| 113 | pPipe->InitBuffer(bufE8_, bufE8Buffer_ * sizeof(int16_t)); | 113 | pPipe->InitBuffer(bufE8_, bufE8Buffer_ * sizeof(int16_t)); |
| 114 | pPipe->InitBuffer(buf1E8_, buf1E8Buffer_ * sizeof(int32_t)); | 114 | pPipe->InitBuffer(buf1E8_, buf1E8Buffer_ * sizeof(int32_t)); |
| 115 | pPipe->InitBuffer(buf1E16_, buf1E16Buffer_ * sizeof(int16_t)); | 115 | pPipe->InitBuffer(buf1E16_, buf1E16Buffer_ * sizeof(int16_t)); |
| 116 | - pPipe->InitBuffer(bufMaxPer4_, maxPer4Buffer_ * 16 * sizeof(int16_t)); | 116 | + pPipe->InitBuffer(bufMaxPer4_, maxPer4Buffer_ * HIF4_MAX_PER4_ELEMENTS_PER_GROUP * sizeof(int16_t)); |
| 117 | - pPipe->InitBuffer(bufMaxPer8_, maxPer8Buffer_ * 8 * sizeof(int16_t)); | 117 | + pPipe->InitBuffer(bufMaxPer8_, maxPer8Buffer_ * HIF4_MAX_PER8_ELEMENTS_PER_GROUP * sizeof(int16_t)); |
| 118 | - pPipe->InitBuffer(bufTmpScale_, tmpScaleBuffer_ * 32 * sizeof(int16_t)); | 118 | + pPipe->InitBuffer(bufTmpScale_, tmpScaleBuffer_ * HIF4_TMP_SCALE_ELEMENTS_PER_GROUP * sizeof(int16_t)); |
| 119 | 119 | ||
| 120 | - sysRegLen_ = 256; | 120 | + sysRegLen_ = VECTOR_LENGTH; |
| 121 | - gmCopyInRegStep_ = sysRegLen_ / sizeof(float) * 2; | 121 | + gmCopyInRegStep_ = sysRegLen_ / sizeof(float) * HIF4_DEINTERLEAVE_REGISTERS_PER_LOAD; |
| 122 | gmCopyOutRegStep_ = sysRegLen_ / sizeof(int32_t) / DQ_HIFP4_CAST_COPYOUT_PACK4_NUM; | 122 | gmCopyOutRegStep_ = sysRegLen_ / sizeof(int32_t) / DQ_HIFP4_CAST_COPYOUT_PACK4_NUM; |
| 123 | gmCopyOutScaleRegStep_ = sysRegLen_ / sizeof(float); | 123 | gmCopyOutScaleRegStep_ = sysRegLen_ / sizeof(float); |
| 124 | gmCopyInRegStep2_ = sysRegLen_ / sizeof(T_X); | 124 | gmCopyInRegStep2_ = sysRegLen_ / sizeof(T_X); |
| @@ -723,7 +723,7 @@ private: | |||
| 723 | 723 | ||
| 724 | int64_t innerLoopEle_, max8LoopEle_, scaleLoopEle_, outLoopEle_; | 724 | int64_t innerLoopEle_, max8LoopEle_, scaleLoopEle_, outLoopEle_; |
| 725 | 725 | ||
| 726 | - int64_t sysRegLen_ = 256; | 726 | + int64_t sysRegLen_ = VECTOR_LENGTH; |
| 727 | int64_t gmCopyInRegStep_ = 0; | 727 | int64_t gmCopyInRegStep_ = 0; |
| 728 | int64_t gmCopyOutRegStep_ = 0; | 728 | int64_t gmCopyOutRegStep_ = 0; |
| 729 | int64_t gmCopyOutScaleRegStep_ = 0; | 729 | int64_t gmCopyOutScaleRegStep_ = 0; |
| @@ -87,7 +87,7 @@ ge::graphStatus BatchNormGradV3InferTiling::DoOpTiling() | |||
| 87 | aInner = factorMax <= aFactorMax ? factorMax : aFactorMax; | 87 | aInner = factorMax <= aFactorMax ? factorMax : aFactorMax; |
| 88 | // 初始容量按 aInner=1 估算,gamma/runningVar 队列实际按最终 aInner 分配。 | 88 | // 初始容量按 aInner=1 估算,gamma/runningVar 队列实际按最终 aInner 分配。 |
| 89 | // 按四组双缓冲队列对齐后的总字节数复核容量,必要时减小 aInner。 | 89 | // 按四组双缓冲队列对齐后的总字节数复核容量,必要时减小 aInner。 |
| 90 | - auto ubUsed = [&](int64_t a) { | 90 | + auto ubUsed = [this, &b1Inner, &b0Inner](int64_t a) { |
| 91 | auto alignUp = [this](int64_t byteCount) { return Ops::Base::CeilAlign(byteCount, blockSize_); }; | 91 | auto alignUp = [this](int64_t byteCount) { return Ops::Base::CeilAlign(byteCount, blockSize_); }; |
| 92 | return DOUBLE_BUFFER * (alignUp(a * bytesPerWeight_) + alignUp(a * bytesPerRunningVar_)) + | 92 | return DOUBLE_BUFFER * (alignUp(a * bytesPerWeight_) + alignUp(a * bytesPerRunningVar_)) + |
| 93 | DOUBLE_BUFFER * INPUT_OUTPUT_NUM * alignUp(b1Inner * aTileBase_ * a * b0Inner * bytesPerDy_); | 93 | DOUBLE_BUFFER * INPUT_OUTPUT_NUM * alignUp(b1Inner * aTileBase_ * a * b0Inner * bytesPerDy_); |
| @@ -145,10 +145,11 @@ ge::graphStatus BatchNormGradV3TilingRASplitR::DoOpTiling() | |||
| 145 | dyTypeSize_ = ge::GetSizeByDataType(dyDtype); | 145 | dyTypeSize_ = ge::GetSizeByDataType(dyDtype); |
| 146 | // Select the existing internal layout after Split-R admission succeeds. | 146 | // Select the existing internal layout after Split-R admission succeeds. |
| 147 | packed_ = CanUsePackedRASplitR(r1Dim, aDim, coreNum, dyDtype); | 147 | packed_ = CanUsePackedRASplitR(r1Dim, aDim, coreNum, dyDtype); |
| 148 | + constexpr int PACKED_GROUP_GROWTH_FACTOR = 2; | ||
| 148 | rowsPerGroup_ = 1; | 149 | rowsPerGroup_ = 1; |
| 149 | if (packed_) { | 150 | if (packed_) { |
| 150 | - while (rowsPerGroup_ * 2 * aDim <= RC_PACKED_VECTOR_ELEMENTS) { | 151 | + while (rowsPerGroup_ * PACKED_GROUP_GROWTH_FACTOR * aDim <= RC_PACKED_VECTOR_ELEMENTS) { |
| 151 | - rowsPerGroup_ *= 2; | 152 | + rowsPerGroup_ *= PACKED_GROUP_GROWTH_FACTOR; |
| 152 | } | 153 | } |
| 153 | } | 154 | } |
| 154 | blockFactor_ = CalcBlockFactor(); | 155 | blockFactor_ = CalcBlockFactor(); |
| @@ -338,7 +338,7 @@ __aicore__ inline void PackedFoldChannels(Reg::RegTensor<float>& value, uint32_t | |||
| 338 | Reg::RegTensor<uint32_t> index; | 338 | Reg::RegTensor<uint32_t> index; |
| 339 | Reg::RegTensor<float> right; | 339 | Reg::RegTensor<float> right; |
| 340 | Reg::Arange(seq, 0); | 340 | Reg::Arange(seq, 0); |
| 341 | - for (uint16_t half = k / 2; half != 0; half /= 2) { | 341 | + for (uint16_t half = k / TWO; half != 0; half /= TWO) { |
| 342 | uint32_t count = half * channels; | 342 | uint32_t count = half * channels; |
| 343 | Reg::MaskReg valid = Reg::UpdateMask<float>(count); | 343 | Reg::MaskReg valid = Reg::UpdateMask<float>(count); |
| 344 | Reg::Adds<uint32_t, uint32_t, Reg::MaskMergeMode::ZEROING>(index, (Reg::RegTensor<uint32_t>&)seq, | 344 | Reg::Adds<uint32_t, uint32_t, Reg::MaskMergeMode::ZEROING>(index, (Reg::RegTensor<uint32_t>&)seq, |
| @@ -355,7 +355,7 @@ __aicore__ inline void PackedBroadcastChannels(Reg::RegTensor<float>& value, uin | |||
| 355 | Reg::RegTensor<float> next; | 355 | Reg::RegTensor<float> next; |
| 356 | Reg::Arange(seq, 0); | 356 | Reg::Arange(seq, 0); |
| 357 | Reg::MaskReg all = Reg::CreateMask<float, Reg::MaskPattern::ALL>(); | 357 | Reg::MaskReg all = Reg::CreateMask<float, Reg::MaskPattern::ALL>(); |
| 358 | - for (uint16_t copies = 1; copies < k; copies *= 2) { | 358 | + for (uint16_t copies = 1; copies < k; copies *= TWO) { |
| 359 | uint32_t count = copies * channels; | 359 | uint32_t count = copies * channels; |
| 360 | Reg::MaskReg low = Reg::UpdateMask<float>(count); | 360 | Reg::MaskReg low = Reg::UpdateMask<float>(count); |
| 361 | Reg::Adds(index, seq, -static_cast<int32_t>(copies * channels), all); | 361 | Reg::Adds(index, seq, -static_cast<int32_t>(copies * channels), all); |
| @@ -243,7 +243,8 @@ public: | |||
| 243 | uint32_t factor = aLength; | 243 | uint32_t factor = aLength; |
| 244 | uint16_t reductionRows = rLoopFactor; | 244 | uint16_t reductionRows = rLoopFactor; |
| 245 | uint16_t recursionTimes = 0; | 245 | uint16_t recursionTimes = 0; |
| 246 | - for (int64_t rows = rLoopFactor; rows > 2; rows /= 2) { | 246 | + constexpr int FINAL_REDUCTION_ROWS = 2; |
| 247 | + for (int64_t rows = rLoopFactor; rows > FINAL_REDUCTION_ROWS; rows /= TWO) { | ||
| 247 | ++recursionTimes; | 248 | ++recursionTimes; |
| 248 | } | 249 | } |
| 249 | __VEC_SCOPE__ | 250 | __VEC_SCOPE__ |
| @@ -56,8 +56,8 @@ public: | |||
| 56 | int64_t offset = blockIdx_ * tilingData_->blockFactor * tilingData_->aDim; | 56 | int64_t offset = blockIdx_ * tilingData_->blockFactor * tilingData_->aDim; |
| 57 | aFactorAlign_ = tilingData_->aFactorAlign; | 57 | aFactorAlign_ = tilingData_->aFactorAlign; |
| 58 | if constexpr (MODE == MODE_PACKED) { | 58 | if constexpr (MODE == MODE_PACKED) { |
| 59 | - while (rowsPerGroup_ * 2 * tilingData_->aDim <= VL_FP32) { | 59 | + while (rowsPerGroup_ * TWO * tilingData_->aDim <= VL_FP32) { |
| 60 | - rowsPerGroup_ *= 2; | 60 | + rowsPerGroup_ *= TWO; |
| 61 | } | 61 | } |
| 62 | } | 62 | } |
| 63 | if (blockIdx_ == (tilingData_->usedCoreNum - 1)) { | 63 | if (blockIdx_ == (tilingData_->usedCoreNum - 1)) { |
| @@ -69,7 +69,8 @@ ge::graphStatus RmsNormDynamicMxQuantFullLoadTiling::DoOpTiling() | |||
| 69 | // Match every InitBuffer allocation, including complete unmasked load tiles. | 69 | // Match every InitBuffer allocation, including complete unmasked load tiles. |
| 70 | // This total is monotonic in m, so a binary search retains the largest tile | 70 | // This total is monotonic in m, so a binary search retains the largest tile |
| 71 | // that fits instead of relying on a linear estimate plus a fixed reserve. | 71 | // that fits instead of relying on a linear estimate plus a fixed reserve. |
| 72 | - const auto getUbSize = [&](int64_t m) { | 72 | + const auto getUbSize = [this, &nMxblockAligned, &binAddOutBufLen, &nMxblockNumAlignedTwo, |
| 73 | + &gammaBetaUbSize](int64_t m) { | ||
| 73 | int64_t xSize = m * nMxblockAligned * FP16_BYTES; | 74 | int64_t xSize = m * nMxblockAligned * FP16_BYTES; |
| 74 | int64_t normSize = Ops::Base::CeilAlign(m * nMxblockAligned, vlFp32_ * CONST_FOUR) * FP16_BYTES; | 75 | int64_t normSize = Ops::Base::CeilAlign(m * nMxblockAligned, vlFp32_ * CONST_FOUR) * FP16_BYTES; |
| 75 | int64_t reduceTmpCount = m * binAddOutBufLen; | 76 | int64_t reduceTmpCount = m * binAddOutBufLen; |
| @@ -129,7 +129,6 @@ ge::graphStatus RmsNormHiF4QuantRegbaseTilingBase::CheckOutputDtype() | |||
| 129 | OP_LOGD(context_->GetNodeName(), "Enter CheckOutputDtype."); | 129 | OP_LOGD(context_->GetNodeName(), "Enter CheckOutputDtype."); |
| 130 | OP_CHECK_NULL_WITH_CONTEXT(context_, context_->GetOutputDesc(Y_INDEX)); | 130 | OP_CHECK_NULL_WITH_CONTEXT(context_, context_->GetOutputDesc(Y_INDEX)); |
| 131 | ge::DataType yDtype = context_->GetOutputDesc(Y_INDEX)->GetDataType(); | 131 | ge::DataType yDtype = context_->GetOutputDesc(Y_INDEX)->GetDataType(); |
| 132 | - | ||
| 133 | if (yDtype != Ops::NN::DT_HIFLOAT4) { | 132 | if (yDtype != Ops::NN::DT_HIFLOAT4) { |
| 134 | OP_LOGE(context_->GetNodeName(), "Output y dtype should be HIFLOAT4."); | 133 | OP_LOGE(context_->GetNodeName(), "Output y dtype should be HIFLOAT4."); |
| 135 | return ge::GRAPH_FAILED; | 134 | return ge::GRAPH_FAILED; |
| @@ -193,9 +192,10 @@ ge::graphStatus RmsNormHiF4QuantRegbaseTilingBase::CheckOutputShapeValue() | |||
| 193 | } | 192 | } |
| 194 | 193 | ||
| 195 | uint64_t expectedLastDim = Ops::Base::CeilDiv(numCol_, static_cast<uint64_t>(HIF4_BLOCK_SIZE)); | 194 | uint64_t expectedLastDim = Ops::Base::CeilDiv(numCol_, static_cast<uint64_t>(HIF4_BLOCK_SIZE)); |
| 196 | - if (scaleShape.GetDim(scaleRank - 2) != static_cast<int64_t>(expectedLastDim)) { | 195 | + if (scaleShape.GetDim(scaleRank - NUM_TWO) != static_cast<int64_t>(expectedLastDim)) { |
| 197 | - OP_LOGE(context_->GetNodeName(), "scale dim[%zu]=%ld should be CeilDiv(R=%ld, 64) = %ld.", scaleRank - 2, | 196 | + OP_LOGE(context_->GetNodeName(), "scale dim[%zu]=%ld should be CeilDiv(R=%ld, 64) = %ld.", scaleRank - NUM_TWO, |
| 198 | - scaleShape.GetDim(scaleRank - 2), static_cast<int64_t>(numCol_), static_cast<int64_t>(expectedLastDim)); | 197 | + scaleShape.GetDim(scaleRank - NUM_TWO), static_cast<int64_t>(numCol_), |
| 198 | + static_cast<int64_t>(expectedLastDim)); | ||
| 199 | return ge::GRAPH_FAILED; | 199 | return ge::GRAPH_FAILED; |
| 200 | } | 200 | } |
| 201 | 201 | ||
| @@ -344,7 +344,7 @@ ge::graphStatus RmsNormHiF4QuantRegbaseTilingBase::GetPlatformInfo() | |||
| 344 | OP_LOGD(context_->GetNodeName(), "Enter GetPlatformInfo."); | 344 | OP_LOGD(context_->GetNodeName(), "Enter GetPlatformInfo."); |
| 345 | 345 | ||
| 346 | auto platformInfo = context_->GetPlatformInfo(); | 346 | auto platformInfo = context_->GetPlatformInfo(); |
| 347 | - auto compileInfoPtr = reinterpret_cast<const RmsNormHiF4QuantCompileInfo*>(context_->GetCompileInfo()); | 347 | + auto compileInfoPtr = static_cast<const RmsNormHiF4QuantCompileInfo*>(context_->GetCompileInfo()); |
| 348 | if (compileInfoPtr != nullptr) { | 348 | if (compileInfoPtr != nullptr) { |
| 349 | totalCoreNum_ = compileInfoPtr->totalCoreNum; | 349 | totalCoreNum_ = compileInfoPtr->totalCoreNum; |
| 350 | maxUbSize_ = compileInfoPtr->totalUbSize; | 350 | maxUbSize_ = compileInfoPtr->totalUbSize; |
| @@ -61,7 +61,13 @@ constexpr int64_t DQ_HIFP4_SCALETMP_ALIGN = 256; | |||
| 61 | constexpr int64_t DQ_HIFP4_BLOCK_BYTE = 32; | 61 | constexpr int64_t DQ_HIFP4_BLOCK_BYTE = 32; |
| 62 | constexpr int64_t DQ_HIFP4_CAST_COPYOUT_PACK4_NUM = 4; | 62 | constexpr int64_t DQ_HIFP4_CAST_COPYOUT_PACK4_NUM = 4; |
| 63 | 63 | ||
| 64 | -constexpr static uint32_t VL_F32 = platform::GetVRegSize() / sizeof(float); | 64 | +constexpr int64_t HIF4_MAX_PER4_ELEMENTS_PER_GROUP = 16; |
| 65 | +constexpr int64_t HIF4_MAX_PER8_ELEMENTS_PER_GROUP = 8; | ||
| 66 | +constexpr int64_t HIF4_TMP_SCALE_ELEMENTS_PER_GROUP = 32; | ||
| 67 | +constexpr int64_t HIF4_DEINTERLEAVE_REGISTERS_PER_LOAD = 2; | ||
| 68 | + | ||
| 69 | +constexpr static uint32_t VECTOR_LENGTH = platform::GetVRegSize(); | ||
| 70 | +constexpr static uint32_t VL_F32 = VECTOR_LENGTH / sizeof(float); | ||
| 65 | constexpr static uint32_t BLOCK_F32_ALIGN_NUM = Ops::Base::GetUbBlockSize() / sizeof(float); | 71 | constexpr static uint32_t BLOCK_F32_ALIGN_NUM = Ops::Base::GetUbBlockSize() / sizeof(float); |
| 66 | constexpr static uint32_t UB_BLOCK_SIZE = Ops::Base::GetUbBlockSize(); | 72 | constexpr static uint32_t UB_BLOCK_SIZE = Ops::Base::GetUbBlockSize(); |
| 67 | 73 | ||
| @@ -110,9 +110,9 @@ public: | |||
| 110 | pPipe->InitBuffer(bufE8_, bufE8Buffer_ * sizeof(int16_t)); | 110 | pPipe->InitBuffer(bufE8_, bufE8Buffer_ * sizeof(int16_t)); |
| 111 | pPipe->InitBuffer(buf1E8_, buf1E8Buffer_ * sizeof(int32_t)); | 111 | pPipe->InitBuffer(buf1E8_, buf1E8Buffer_ * sizeof(int32_t)); |
| 112 | pPipe->InitBuffer(buf1E16_, buf1E16Buffer_ * sizeof(int16_t)); | 112 | pPipe->InitBuffer(buf1E16_, buf1E16Buffer_ * sizeof(int16_t)); |
| 113 | - pPipe->InitBuffer(bufMaxPer4_, maxPer4Buffer_ * 16 * sizeof(int16_t)); | 113 | + pPipe->InitBuffer(bufMaxPer4_, maxPer4Buffer_ * HIF4_MAX_PER4_ELEMENTS_PER_GROUP * sizeof(int16_t)); |
| 114 | - pPipe->InitBuffer(bufMaxPer8_, maxPer8Buffer_ * 8 * sizeof(int16_t)); | 114 | + pPipe->InitBuffer(bufMaxPer8_, maxPer8Buffer_ * HIF4_MAX_PER8_ELEMENTS_PER_GROUP * sizeof(int16_t)); |
| 115 | - pPipe->InitBuffer(bufTmpScale_, tmpScaleBuffer_ * 32 * sizeof(int16_t)); | 115 | + pPipe->InitBuffer(bufTmpScale_, tmpScaleBuffer_ * HIF4_TMP_SCALE_ELEMENTS_PER_GROUP * sizeof(int16_t)); |
| 116 | 116 | ||
| 117 | uint64_t quantYBufSize = CeilAlign(CeilDiv(numColAlign_ * rowFactor_ / DIGIT_TWO, MX_STEP_PROCESS_NUM), | 117 | uint64_t quantYBufSize = CeilAlign(CeilDiv(numColAlign_ * rowFactor_ / DIGIT_TWO, MX_STEP_PROCESS_NUM), |
| 118 | DIGIT_FOUR) * | 118 | DIGIT_FOUR) * |
| @@ -121,8 +121,8 @@ public: | |||
| 121 | pPipe->InitBuffer(outQueueQuantY, DOUBLE_BUFFER_NUM, quantYBufSize); | 121 | pPipe->InitBuffer(outQueueQuantY, DOUBLE_BUFFER_NUM, quantYBufSize); |
| 122 | pPipe->InitBuffer(outQueueScale, DOUBLE_BUFFER_NUM, alignTo256UbFormer * sizeof(float)); | 122 | pPipe->InitBuffer(outQueueScale, DOUBLE_BUFFER_NUM, alignTo256UbFormer * sizeof(float)); |
| 123 | 123 | ||
| 124 | - sysRegLen_ = 256; | 124 | + sysRegLen_ = VECTOR_LENGTH; |
| 125 | - gmCopyInRegStep_ = sysRegLen_ / sizeof(float) * 2; | 125 | + gmCopyInRegStep_ = sysRegLen_ / sizeof(float) * HIF4_DEINTERLEAVE_REGISTERS_PER_LOAD; |
| 126 | gmCopyOutRegStep_ = sysRegLen_ / sizeof(int32_t) / DQ_HIFP4_CAST_COPYOUT_PACK4_NUM; | 126 | gmCopyOutRegStep_ = sysRegLen_ / sizeof(int32_t) / DQ_HIFP4_CAST_COPYOUT_PACK4_NUM; |
| 127 | gmCopyOutScaleRegStep_ = sysRegLen_ / sizeof(float); | 127 | gmCopyOutScaleRegStep_ = sysRegLen_ / sizeof(float); |
| 128 | gmCopyInRegStep2_ = sysRegLen_ / sizeof(T_X); | 128 | gmCopyInRegStep2_ = sysRegLen_ / sizeof(T_X); |
| @@ -825,7 +825,7 @@ private: | |||
| 825 | uint32_t vlForHalfNumber; | 825 | uint32_t vlForHalfNumber; |
| 826 | uint16_t elementAfterReduce; | 826 | uint16_t elementAfterReduce; |
| 827 | 827 | ||
| 828 | - int64_t sysRegLen_ = 256; | 828 | + int64_t sysRegLen_ = VECTOR_LENGTH; |
| 829 | int64_t gmCopyInRegStep_ = 0; | 829 | int64_t gmCopyInRegStep_ = 0; |
| 830 | int64_t gmCopyOutRegStep_ = 0; | 830 | int64_t gmCopyOutRegStep_ = 0; |
| 831 | int64_t gmCopyOutScaleRegStep_ = 0; | 831 | int64_t gmCopyOutScaleRegStep_ = 0; |
| @@ -111,12 +111,12 @@ public: | |||
| 111 | pPipe->InitBuffer(bufE8_, bufE8Buffer_ * sizeof(int16_t)); | 111 | pPipe->InitBuffer(bufE8_, bufE8Buffer_ * sizeof(int16_t)); |
| 112 | pPipe->InitBuffer(buf1E8_, buf1E8Buffer_ * sizeof(int32_t)); | 112 | pPipe->InitBuffer(buf1E8_, buf1E8Buffer_ * sizeof(int32_t)); |
| 113 | pPipe->InitBuffer(buf1E16_, buf1E16Buffer_ * sizeof(int16_t)); | 113 | pPipe->InitBuffer(buf1E16_, buf1E16Buffer_ * sizeof(int16_t)); |
| 114 | - pPipe->InitBuffer(bufMaxPer4_, maxPer4Buffer_ * 16 * sizeof(int16_t)); | 114 | + pPipe->InitBuffer(bufMaxPer4_, maxPer4Buffer_ * HIF4_MAX_PER4_ELEMENTS_PER_GROUP * sizeof(int16_t)); |
| 115 | - pPipe->InitBuffer(bufMaxPer8_, maxPer8Buffer_ * 8 * sizeof(int16_t)); | 115 | + pPipe->InitBuffer(bufMaxPer8_, maxPer8Buffer_ * HIF4_MAX_PER8_ELEMENTS_PER_GROUP * sizeof(int16_t)); |
| 116 | - pPipe->InitBuffer(bufTmpScale_, tmpScaleBuffer_ * 32 * sizeof(int16_t)); | 116 | + pPipe->InitBuffer(bufTmpScale_, tmpScaleBuffer_ * HIF4_TMP_SCALE_ELEMENTS_PER_GROUP * sizeof(int16_t)); |
| 117 | 117 | ||
| 118 | - sysRegLen_ = 256; | 118 | + sysRegLen_ = VECTOR_LENGTH; |
| 119 | - gmCopyInRegStep_ = sysRegLen_ / sizeof(float) * 2; | 119 | + gmCopyInRegStep_ = sysRegLen_ / sizeof(float) * HIF4_DEINTERLEAVE_REGISTERS_PER_LOAD; |
| 120 | gmCopyOutRegStep_ = sysRegLen_ / sizeof(int32_t) / DQ_HIFP4_CAST_COPYOUT_PACK4_NUM; | 120 | gmCopyOutRegStep_ = sysRegLen_ / sizeof(int32_t) / DQ_HIFP4_CAST_COPYOUT_PACK4_NUM; |
| 121 | gmCopyOutScaleRegStep_ = sysRegLen_ / sizeof(float); | 121 | gmCopyOutScaleRegStep_ = sysRegLen_ / sizeof(float); |
| 122 | gmCopyInRegStep2_ = sysRegLen_ / sizeof(T_X); | 122 | gmCopyInRegStep2_ = sysRegLen_ / sizeof(T_X); |
| @@ -710,7 +710,7 @@ private: | |||
| 710 | int64_t innerLoopEle_, max8LoopEle_, scaleLoopEle_, outLoopEle_, alignGroupNum_; | 710 | int64_t innerLoopEle_, max8LoopEle_, scaleLoopEle_, outLoopEle_, alignGroupNum_; |
| 711 | int64_t innerLoopTail_, max8LoopTail_, scaleLoopTail_, outLoopTail_; | 711 | int64_t innerLoopTail_, max8LoopTail_, scaleLoopTail_, outLoopTail_; |
| 712 | 712 | ||
| 713 | - int64_t sysRegLen_ = 256; | 713 | + int64_t sysRegLen_ = VECTOR_LENGTH; |
| 714 | int64_t gmCopyInRegStep_ = 0; | 714 | int64_t gmCopyInRegStep_ = 0; |
| 715 | int64_t gmCopyOutRegStep_ = 0; | 715 | int64_t gmCopyOutRegStep_ = 0; |
| 716 | int64_t gmCopyOutScaleRegStep_ = 0; | 716 | int64_t gmCopyOutScaleRegStep_ = 0; |