已合并
【bugfix】修复unfoldGrad的同步问题 #2967
majiajian_hw创建于 5月27日
【bugfix】修复unfoldGrad的同步问题 #2967
已合并
共 4 个文件变更+67-23
| @@ -93,6 +93,14 @@ public: | |||
| 93 | params.paramsOut = {blockCount, blockLenOut, 0, 0, 0}; | 93 | params.paramsOut = {blockCount, blockLenOut, 0, 0, 0}; |
| 94 | } | 94 | } |
| 95 | 95 | ||
| 96 | + template <AscendC::HardEvent hardEvent> | ||
| 97 | + __aicore__ inline void PipeSync() | ||
| 98 | + { | ||
| 99 | + int32_t eventID = static_cast<int32_t>(GetTPipePtr()->FetchEventID(hardEvent)); | ||
| 100 | + AscendC::SetFlag<hardEvent>(eventID); | ||
| 101 | + AscendC::WaitFlag<hardEvent>(eventID); | ||
| 102 | + } | ||
| 103 | + | ||
| 96 | __aicore__ inline void CopyToOutBigShapeOnePage(int64_t inPageIdx, int64_t outPageIdx, sDataCopyExtParams& params) | 104 | __aicore__ inline void CopyToOutBigShapeOnePage(int64_t inPageIdx, int64_t outPageIdx, sDataCopyExtParams& params) |
| 97 | { | 105 | { |
| 98 | int64_t inOffset = inPageIdx * workspaceLen_; | 106 | int64_t inOffset = inPageIdx * workspaceLen_; |
| @@ -111,15 +119,16 @@ public: | |||
| 111 | AscendC::Duplicate<T1>(zeroLocal, 0, zeroNum); | 119 | AscendC::Duplicate<T1>(zeroLocal, 0, zeroNum); |
| 112 | uint32_t blockLen = static_cast<uint32_t>(T2DstDataSize); | 120 | uint32_t blockLen = static_cast<uint32_t>(T2DstDataSize); |
| 113 | AscendC::DataCopyExtParams copyParams = {1, blockLen, 0, 0, 0}; | 121 | AscendC::DataCopyExtParams copyParams = {1, blockLen, 0, 0, 0}; |
| 114 | - AscendC::PipeBarrier<PIPE_ALL>(); | 122 | + PipeSync<AscendC::HardEvent::V_MTE3>(); |
| 115 | for (int i = 0; i < loop; i++) { | 123 | for (int i = 0; i < loop; i++) { |
| 116 | AscendC::DataCopyPad(dstGlobal[dstGlobalStart + i * zeroNum], zeroLocal, copyParams); | 124 | AscendC::DataCopyPad(dstGlobal[dstGlobalStart + i * zeroNum], zeroLocal, copyParams); |
| 125 | + AscendC::PipeBarrier<PIPE_MTE3>(); | ||
| 117 | } | 126 | } |
| 118 | if (tail > 0) { | 127 | if (tail > 0) { |
| 119 | copyParams.blockLen = static_cast<uint32_t>(tail * typeSizeT1); | 128 | copyParams.blockLen = static_cast<uint32_t>(tail * typeSizeT1); |
| 120 | AscendC::DataCopyPad(dstGlobal[dstGlobalStart + loop * zeroNum], zeroLocal, copyParams); | 129 | AscendC::DataCopyPad(dstGlobal[dstGlobalStart + loop * zeroNum], zeroLocal, copyParams); |
| 121 | } | 130 | } |
| 122 | - AscendC::PipeBarrier<PIPE_ALL>(); | 131 | + PipeSync<AscendC::HardEvent::MTE3_S>(); |
| 123 | computeOutQueueDst.FreeTensor(zeroLocal); | 132 | computeOutQueueDst.FreeTensor(zeroLocal); |
| 124 | } | 133 | } |
| 125 | 134 | ||
| @@ -132,15 +141,16 @@ public: | |||
| 132 | AscendC::Duplicate<T2>(zeroLocal, 0, zeroNum); | 141 | AscendC::Duplicate<T2>(zeroLocal, 0, zeroNum); |
| 133 | uint32_t blockLen = static_cast<uint32_t>(T2DstDataSize); | 142 | uint32_t blockLen = static_cast<uint32_t>(T2DstDataSize); |
| 134 | AscendC::DataCopyExtParams copyParams = {1, blockLen, 0, 0, 0}; | 143 | AscendC::DataCopyExtParams copyParams = {1, blockLen, 0, 0, 0}; |
| 135 | - AscendC::PipeBarrier<PIPE_ALL>(); | 144 | + PipeSync<AscendC::HardEvent::V_MTE3>(); |
| 136 | for (int i = 0; i < loop; i++) { | 145 | for (int i = 0; i < loop; i++) { |
| 137 | AscendC::DataCopyPad(workspaceT2SumRes[dstGlobalStart + i * zeroNum], zeroLocal, copyParams); | 146 | AscendC::DataCopyPad(workspaceT2SumRes[dstGlobalStart + i * zeroNum], zeroLocal, copyParams); |
| 147 | + AscendC::PipeBarrier<PIPE_MTE3>(); | ||
| 138 | } | 148 | } |
| 139 | if (tail > 0) { | 149 | if (tail > 0) { |
| 140 | copyParams.blockLen = static_cast<uint32_t>(tail * typeSizeT2); | 150 | copyParams.blockLen = static_cast<uint32_t>(tail * typeSizeT2); |
| 141 | AscendC::DataCopyPad(workspaceT2SumRes[dstGlobalStart + loop * zeroNum], zeroLocal, copyParams); | 151 | AscendC::DataCopyPad(workspaceT2SumRes[dstGlobalStart + loop * zeroNum], zeroLocal, copyParams); |
| 142 | } | 152 | } |
| 143 | - AscendC::PipeBarrier<PIPE_ALL>(); | 153 | + PipeSync<AscendC::HardEvent::MTE3_S>(); |
| 144 | computeOutQueueDst.FreeTensor(zeroLocal); | 154 | computeOutQueueDst.FreeTensor(zeroLocal); |
| 145 | } | 155 | } |
| 146 | 156 | ||
| @@ -171,22 +181,25 @@ public: | |||
| 171 | { | 181 | { |
| 172 | AscendC::DataCopyPadExtParams<T2> padParmsT2{false, 0, 0, 0}; | 182 | AscendC::DataCopyPadExtParams<T2> padParmsT2{false, 0, 0, 0}; |
| 173 | auto inLocalT2 = computeOutQueueDst.AllocTensor<T2>(); | 183 | auto inLocalT2 = computeOutQueueDst.AllocTensor<T2>(); |
| 174 | - AscendC::PipeBarrier<PIPE_ALL>(); | 184 | + PipeSync<AscendC::HardEvent::S_MTE2>(); |
| 185 | + PipeSync<AscendC::HardEvent::V_MTE2>(); | ||
| 186 | + PipeSync<AscendC::HardEvent::MTE3_MTE2>(); | ||
| 175 | AscendC::DataCopyPad(inLocalT2, srcGM[inCopyParams.offset], inCopyParams.dcParams, padParmsT2); | 187 | AscendC::DataCopyPad(inLocalT2, srcGM[inCopyParams.offset], inCopyParams.dcParams, padParmsT2); |
| 176 | - AscendC::PipeBarrier<PIPE_ALL>(); | 188 | + PipeSync<AscendC::HardEvent::MTE2_S>(); |
| 177 | computeOutQueueDst.EnQue(inLocalT2); | 189 | computeOutQueueDst.EnQue(inLocalT2); |
| 178 | 190 | ||
| 179 | inLocalT2 = computeOutQueueDst.DeQue<T2>(); | 191 | inLocalT2 = computeOutQueueDst.DeQue<T2>(); |
| 180 | auto inLocal = inQueueSrc.AllocTensor<T1>(); | 192 | auto inLocal = inQueueSrc.AllocTensor<T1>(); |
| 193 | + PipeSync<AscendC::HardEvent::MTE2_V>(); | ||
| 181 | AscendC::Cast(inLocal, inLocalT2, AscendC::RoundMode::CAST_RINT, inCopyParams.dcParams.blockLen / typeSizeT2); | 194 | AscendC::Cast(inLocal, inLocalT2, AscendC::RoundMode::CAST_RINT, inCopyParams.dcParams.blockLen / typeSizeT2); |
| 182 | inQueueSrc.EnQue(inLocal); | 195 | inQueueSrc.EnQue(inLocal); |
| 183 | computeOutQueueDst.FreeTensor(inLocalT2); | 196 | computeOutQueueDst.FreeTensor(inLocalT2); |
| 184 | 197 | ||
| 185 | inLocal = inQueueSrc.DeQue<T1>(); | 198 | inLocal = inQueueSrc.DeQue<T1>(); |
| 186 | - AscendC::PipeBarrier<PIPE_ALL>(); | 199 | + PipeSync<AscendC::HardEvent::V_MTE3>(); |
| 200 | + PipeSync<AscendC::HardEvent::S_MTE3>(); | ||
| 187 | AscendC::DataCopyPad(dstGM[outCopyParams.offset], inLocal, outCopyParams.dcParams); | 201 | AscendC::DataCopyPad(dstGM[outCopyParams.offset], inLocal, outCopyParams.dcParams); |
| 188 | inQueueSrc.FreeTensor(inLocal); | 202 | inQueueSrc.FreeTensor(inLocal); |
| 189 | - AscendC::PipeBarrier<PIPE_ALL>(); | ||
| 190 | } | 203 | } |
| 191 | 204 | ||
| 192 | __aicore__ inline void ParseTilingData(const UnfoldGradTilingData* tilingData) | 205 | __aicore__ inline void ParseTilingData(const UnfoldGradTilingData* tilingData) |
| @@ -43,6 +43,14 @@ public: | |||
| 43 | this->workspaceT2SumRes.SetGlobalBuffer(reinterpret_cast<__gm__ T2*>(workspace) + gradInBlockOffset); | 43 | this->workspaceT2SumRes.SetGlobalBuffer(reinterpret_cast<__gm__ T2*>(workspace) + gradInBlockOffset); |
| 44 | } | 44 | } |
| 45 | 45 | ||
| 46 | + template <AscendC::HardEvent hardEvent> | ||
| 47 | + __aicore__ inline void PipeSync() | ||
| 48 | + { | ||
| 49 | + int32_t eventID = static_cast<int32_t>(GetTPipePtr()->FetchEventID(hardEvent)); | ||
| 50 | + AscendC::SetFlag<hardEvent>(eventID); | ||
| 51 | + AscendC::WaitFlag<hardEvent>(eventID); | ||
| 52 | + } | ||
| 53 | + | ||
| 46 | __aicore__ inline void ProcessFinalAxes(int curSrcStart, int curDstStart) | 54 | __aicore__ inline void ProcessFinalAxes(int curSrcStart, int curDstStart) |
| 47 | { | 55 | { |
| 48 | this->tasksOnce = this->tasksOnceMaxPerCore; | 56 | this->tasksOnce = this->tasksOnceMaxPerCore; |
| @@ -78,7 +86,6 @@ public: | |||
| 78 | this->SetGMtoZero(this->outputNumPerCore, dstStart); | 86 | this->SetGMtoZero(this->outputNumPerCore, dstStart); |
| 79 | } | 87 | } |
| 80 | 88 | ||
| 81 | - AscendC::PipeBarrier<PIPE_ALL>(); // 尾轴情况 | ||
| 82 | ProcessFinalAxes(srcStart, dstStart); | 89 | ProcessFinalAxes(srcStart, dstStart); |
| 83 | 90 | ||
| 84 | if constexpr (ISCAST) { | 91 | if constexpr (ISCAST) { |
| @@ -86,7 +93,8 @@ public: | |||
| 86 | this->CalculateOutParms(params); | 93 | this->CalculateOutParms(params); |
| 87 | this->CopyToOutBigShapeOnePage(batchIdx, batchIdx, params); | 94 | this->CopyToOutBigShapeOnePage(batchIdx, batchIdx, params); |
| 88 | } | 95 | } |
| 89 | - AscendC::PipeBarrier<PIPE_ALL>(); | 96 | + PipeSync<AscendC::HardEvent::MTE3_V>(); |
| 97 | + PipeSync<AscendC::HardEvent::S_V>(); | ||
| 90 | } | 98 | } |
| 91 | } | 99 | } |
| 92 | 100 | ||
| @@ -97,6 +105,8 @@ private: | |||
| 97 | ISCAST ? this->inQueueSrc.template AllocTensor<T1>() : this->computeInQueueSrc.template AllocTensor<T1>(); | 105 | ISCAST ? this->inQueueSrc.template AllocTensor<T1>() : this->computeInQueueSrc.template AllocTensor<T1>(); |
| 98 | AscendC::DataCopyPadExtParams<T1> padParams{false, 0, 0, 0}; | 106 | AscendC::DataCopyPadExtParams<T1> padParams{false, 0, 0, 0}; |
| 99 | AscendC::PipeBarrier<PIPE_V>(); | 107 | AscendC::PipeBarrier<PIPE_V>(); |
| 108 | + PipeSync<AscendC::HardEvent::MTE3_V>(); | ||
| 109 | + PipeSync<AscendC::HardEvent::S_V>(); | ||
| 100 | T1 zeroVal(0.0); | 110 | T1 zeroVal(0.0); |
| 101 | int srcDataSize = ISCAST ? this->ubSizeT1 : this->T2SrcDataSize; | 111 | int srcDataSize = ISCAST ? this->ubSizeT1 : this->T2SrcDataSize; |
| 102 | AscendC::Duplicate<T1>(srcLocal, zeroVal, srcDataSize / this->typeSizeT1); | 112 | AscendC::Duplicate<T1>(srcLocal, zeroVal, srcDataSize / this->typeSizeT1); |
| @@ -109,7 +119,7 @@ private: | |||
| 109 | uint32_t srcStride = 0; | 119 | uint32_t srcStride = 0; |
| 110 | uint32_t dstStride = | 120 | uint32_t dstStride = |
| 111 | (colNumSpace - (colHandleNum * this->typeSizeT1 + BLOCK_SIZE - 1) / BLOCK_SIZE * BLOCK_SIZE) / BLOCK_SIZE; | 121 | (colNumSpace - (colHandleNum * this->typeSizeT1 + BLOCK_SIZE - 1) / BLOCK_SIZE * BLOCK_SIZE) / BLOCK_SIZE; |
| 112 | - AscendC::PipeBarrier<PIPE_ALL>(); | 122 | + PipeSync<AscendC::HardEvent::V_MTE2>(); |
| 113 | AscendC::DataCopyExtParams copyParamsIn{ | 123 | AscendC::DataCopyExtParams copyParamsIn{ |
| 114 | static_cast<uint16_t>(blockCount - 1), blockLen, srcStride, dstStride, 0}; | 124 | static_cast<uint16_t>(blockCount - 1), blockLen, srcStride, dstStride, 0}; |
| 115 | if (blockCount > 1) { | 125 | if (blockCount > 1) { |
| @@ -120,6 +130,7 @@ private: | |||
| 120 | padParams.paddingValue = 0; | 130 | padParams.paddingValue = 0; |
| 121 | AscendC::DataCopyPad( | 131 | AscendC::DataCopyPad( |
| 122 | srcLocal, this->srcGlobal[curSrcStart + index * this->tasksOnceMaxPerCore], copyParamsIn, padParams); | 132 | srcLocal, this->srcGlobal[curSrcStart + index * this->tasksOnceMaxPerCore], copyParamsIn, padParams); |
| 133 | + AscendC::PipeBarrier<PIPE_MTE2>(); | ||
| 123 | } | 134 | } |
| 124 | copyParamsIn.blockCount = 1; | 135 | copyParamsIn.blockCount = 1; |
| 125 | copyParamsIn.blockLen = (curHandleNum - (blockCount - 1) * colHandleNum) * this->typeSizeT1; | 136 | copyParamsIn.blockLen = (curHandleNum - (blockCount - 1) * colHandleNum) * this->typeSizeT1; |
| @@ -137,6 +148,7 @@ private: | |||
| 137 | // fp16转fp32 | 148 | // fp16转fp32 |
| 138 | srcLocal = this->inQueueSrc.template DeQue<T1>(); | 149 | srcLocal = this->inQueueSrc.template DeQue<T1>(); |
| 139 | AscendC::LocalTensor<T2> computeSrcLocal = this->computeInQueueSrc.template AllocTensor<T2>(); | 150 | AscendC::LocalTensor<T2> computeSrcLocal = this->computeInQueueSrc.template AllocTensor<T2>(); |
| 151 | + AscendC::PipeBarrier<PIPE_V>(); | ||
| 140 | AscendC::Cast( | 152 | AscendC::Cast( |
| 141 | computeSrcLocal, srcLocal, AscendC::RoundMode::CAST_NONE, colNumSpace * blockCount / this->typeSizeT1); | 153 | computeSrcLocal, srcLocal, AscendC::RoundMode::CAST_NONE, colNumSpace * blockCount / this->typeSizeT1); |
| 142 | this->computeInQueueSrc.template EnQue(computeSrcLocal); | 154 | this->computeInQueueSrc.template EnQue(computeSrcLocal); |
| @@ -174,6 +186,7 @@ private: | |||
| 174 | .GetPhyAddr()); | 186 | .GetPhyAddr()); |
| 175 | } | 187 | } |
| 176 | AscendC::TransDataTo5HD<T2>(dstLocalList, srcLocalList, transDataTo5HDParams.transDataParams); | 188 | AscendC::TransDataTo5HD<T2>(dstLocalList, srcLocalList, transDataTo5HDParams.transDataParams); |
| 189 | + AscendC::PipeBarrier<PIPE_V>(); | ||
| 177 | } | 190 | } |
| 178 | 191 | ||
| 179 | __aicore__ inline void TransDataForUnfold1( | 192 | __aicore__ inline void TransDataForUnfold1( |
| @@ -239,6 +252,7 @@ private: | |||
| 239 | .GetPhyAddr()); | 252 | .GetPhyAddr()); |
| 240 | } | 253 | } |
| 241 | AscendC::TransDataTo5HD<T2>(dstLocalList, srcLocalList, transDataTo5HDParams.transDataParams); | 254 | AscendC::TransDataTo5HD<T2>(dstLocalList, srcLocalList, transDataTo5HDParams.transDataParams); |
| 255 | + AscendC::PipeBarrier<PIPE_V>(); | ||
| 242 | } | 256 | } |
| 243 | 257 | ||
| 244 | __aicore__ inline void TransDataForUnfold2( | 258 | __aicore__ inline void TransDataForUnfold2( |
| @@ -302,6 +316,7 @@ private: | |||
| 302 | srcOffset = srcStart * TRANS_BLOCK; | 316 | srcOffset = srcStart * TRANS_BLOCK; |
| 303 | dstOffset = dstStart * TRANS_BLOCK; | 317 | dstOffset = dstStart * TRANS_BLOCK; |
| 304 | AscendC::Add<T2>(srcLocal[dstOffset], srcLocal[dstOffset], dstLocal[srcOffset], TRANS_BLOCK * this->size); | 318 | AscendC::Add<T2>(srcLocal[dstOffset], srcLocal[dstOffset], dstLocal[srcOffset], TRANS_BLOCK * this->size); |
| 319 | + AscendC::PipeBarrier<PIPE_V>(); | ||
| 305 | srcStart += this->size; | 320 | srcStart += this->size; |
| 306 | dstStart += this->step; | 321 | dstStart += this->step; |
| 307 | } | 322 | } |
| @@ -319,6 +334,7 @@ private: | |||
| 319 | AscendC::PipeBarrier<PIPE_V>(); | 334 | AscendC::PipeBarrier<PIPE_V>(); |
| 320 | T2 zeroVal(0.0); | 335 | T2 zeroVal(0.0); |
| 321 | AscendC::Duplicate<T2>(computeSrcLocal, zeroVal, this->T2SrcDataSize / this->typeSizeT2); | 336 | AscendC::Duplicate<T2>(computeSrcLocal, zeroVal, this->T2SrcDataSize / this->typeSizeT2); |
| 337 | + AscendC::PipeBarrier<PIPE_V>(); | ||
| 322 | 338 | ||
| 323 | // 累加计算 | 339 | // 累加计算 |
| 324 | AccumulateFinalAxes(computeSrcLocal, computeDstLocal, curHandleNum); | 340 | AccumulateFinalAxes(computeSrcLocal, computeDstLocal, curHandleNum); |
| @@ -42,6 +42,14 @@ public: | |||
| 42 | this->workspaceT2SumRes.SetGlobalBuffer(reinterpret_cast<__gm__ T2*>(workspace) + gradInBlockOffset); | 42 | this->workspaceT2SumRes.SetGlobalBuffer(reinterpret_cast<__gm__ T2*>(workspace) + gradInBlockOffset); |
| 43 | } | 43 | } |
| 44 | 44 | ||
| 45 | + template <AscendC::HardEvent hardEvent> | ||
| 46 | + __aicore__ inline void PipeSync() | ||
| 47 | + { | ||
| 48 | + int32_t eventID = static_cast<int32_t>(GetTPipePtr()->FetchEventID(hardEvent)); | ||
| 49 | + AscendC::SetFlag<hardEvent>(eventID); | ||
| 50 | + AscendC::WaitFlag<hardEvent>(eventID); | ||
| 51 | + } | ||
| 52 | + | ||
| 45 | __aicore__ inline void ProcessFinalAxeBigSize(int curSrcStart, int curDstStart) | 53 | __aicore__ inline void ProcessFinalAxeBigSize(int curSrcStart, int curDstStart) |
| 46 | { | 54 | { |
| 47 | this->tasksOnce = this->tasksOnceMaxPerCore; | 55 | this->tasksOnce = this->tasksOnceMaxPerCore; |
| @@ -65,7 +73,7 @@ public: | |||
| 65 | } | 73 | } |
| 66 | } | 74 | } |
| 67 | } | 75 | } |
| 68 | - | 76 | + |
| 69 | __aicore__ inline void Process() | 77 | __aicore__ inline void Process() |
| 70 | { | 78 | { |
| 71 | for (int batchIdx = 0; batchIdx < curCoreBatchNum; batchIdx++) { | 79 | for (int batchIdx = 0; batchIdx < curCoreBatchNum; batchIdx++) { |
| @@ -77,7 +85,6 @@ public: | |||
| 77 | this->SetGMtoZero(this->outputNumPerCore, dstStart); | 85 | this->SetGMtoZero(this->outputNumPerCore, dstStart); |
| 78 | } | 86 | } |
| 79 | 87 | ||
| 80 | - AscendC::PipeBarrier<PIPE_ALL>(); | ||
| 81 | ProcessFinalAxeBigSize(srcStart, dstStart); | 88 | ProcessFinalAxeBigSize(srcStart, dstStart); |
| 82 | 89 | ||
| 83 | if constexpr (ISCAST) { | 90 | if constexpr (ISCAST) { |
| @@ -85,24 +92,20 @@ public: | |||
| 85 | this->CalculateOutParms(params); | 92 | this->CalculateOutParms(params); |
| 86 | this->CopyToOutBigShapeOnePage(batchIdx, batchIdx, params); | 93 | this->CopyToOutBigShapeOnePage(batchIdx, batchIdx, params); |
| 87 | } | 94 | } |
| 88 | - AscendC::PipeBarrier<PIPE_ALL>(); | 95 | + PipeSync<AscendC::HardEvent::MTE3_V>(); |
| 96 | + PipeSync<AscendC::HardEvent::S_V>(); | ||
| 89 | } | 97 | } |
| 90 | } | 98 | } |
| 91 | 99 | ||
| 92 | private: | 100 | private: |
| 93 | - template <AscendC::HardEvent hardEvent> | ||
| 94 | - __aicore__ inline void PipeSync() | ||
| 95 | - { | ||
| 96 | - int32_t eventID = static_cast<int32_t>(GetTPipePtr()->FetchEventID(hardEvent)); | ||
| 97 | - AscendC::SetFlag<hardEvent>(eventID); | ||
| 98 | - AscendC::WaitFlag<hardEvent>(eventID); | ||
| 99 | - } | ||
| 100 | __aicore__ inline void CopyInFinalAxeBigSize(int64_t curSrcStart, int64_t index, int64_t curHandleNum) | 101 | __aicore__ inline void CopyInFinalAxeBigSize(int64_t curSrcStart, int64_t index, int64_t curHandleNum) |
| 101 | { | 102 | { |
| 102 | AscendC::LocalTensor<T1> srcLocal = | 103 | AscendC::LocalTensor<T1> srcLocal = |
| 103 | ISCAST ? this->inQueueSrc.template AllocTensor<T1>() : this->computeOutQueueDst.template AllocTensor<T1>(); | 104 | ISCAST ? this->inQueueSrc.template AllocTensor<T1>() : this->computeOutQueueDst.template AllocTensor<T1>(); |
| 104 | AscendC::DataCopyPadExtParams<T1> padParams{false, 0, 0, 0}; | 105 | AscendC::DataCopyPadExtParams<T1> padParams{false, 0, 0, 0}; |
| 105 | AscendC::PipeBarrier<PIPE_V>(); | 106 | AscendC::PipeBarrier<PIPE_V>(); |
| 107 | + PipeSync<AscendC::HardEvent::MTE3_V>(); | ||
| 108 | + PipeSync<AscendC::HardEvent::S_V>(); | ||
| 106 | T1 zeroVal(0.0); | 109 | T1 zeroVal(0.0); |
| 107 | int srcDataSize = ISCAST ? this->ubSizeT1 : this->T2SrcDataSize; | 110 | int srcDataSize = ISCAST ? this->ubSizeT1 : this->T2SrcDataSize; |
| 108 | AscendC::Duplicate<T1>(srcLocal, zeroVal, srcDataSize / this->typeSizeT1); | 111 | AscendC::Duplicate<T1>(srcLocal, zeroVal, srcDataSize / this->typeSizeT1); |
| @@ -130,6 +133,7 @@ private: | |||
| 130 | // fp16转fp32 | 133 | // fp16转fp32 |
| 131 | srcLocal = this->inQueueSrc.template DeQue<T1>(); | 134 | srcLocal = this->inQueueSrc.template DeQue<T1>(); |
| 132 | AscendC::LocalTensor<T2> computeDstLocal = this->computeOutQueueDst.template AllocTensor<T2>(); | 135 | AscendC::LocalTensor<T2> computeDstLocal = this->computeOutQueueDst.template AllocTensor<T2>(); |
| 136 | + AscendC::PipeBarrier<PIPE_V>(); | ||
| 133 | AscendC::Cast( | 137 | AscendC::Cast( |
| 134 | computeDstLocal, srcLocal, AscendC::RoundMode::CAST_NONE, srcDataSize / this->typeSizeT1); | 138 | computeDstLocal, srcLocal, AscendC::RoundMode::CAST_NONE, srcDataSize / this->typeSizeT1); |
| 135 | this->computeOutQueueDst.template EnQue(computeDstLocal); | 139 | this->computeOutQueueDst.template EnQue(computeDstLocal); |
| @@ -43,6 +43,14 @@ public: | |||
| 43 | this->workspaceT2SumRes.SetGlobalBuffer(reinterpret_cast<__gm__ T2*>(workspace) + gradInBlockOffset); | 43 | this->workspaceT2SumRes.SetGlobalBuffer(reinterpret_cast<__gm__ T2*>(workspace) + gradInBlockOffset); |
| 44 | } | 44 | } |
| 45 | 45 | ||
| 46 | + template <AscendC::HardEvent hardEvent> | ||
| 47 | + __aicore__ inline void PipeSync() | ||
| 48 | + { | ||
| 49 | + int32_t eventID = static_cast<int32_t>(GetTPipePtr()->FetchEventID(hardEvent)); | ||
| 50 | + AscendC::SetFlag<hardEvent>(eventID); | ||
| 51 | + AscendC::WaitFlag<hardEvent>(eventID); | ||
| 52 | + } | ||
| 53 | + | ||
| 46 | __aicore__ inline void ProcessFinalSecondAxes(int curSrcStart, int curDstStart) | 54 | __aicore__ inline void ProcessFinalSecondAxes(int curSrcStart, int curDstStart) |
| 47 | { | 55 | { |
| 48 | for (int k = 0; k < this->iterationNumPerCore; k++) { | 56 | for (int k = 0; k < this->iterationNumPerCore; k++) { |
| @@ -86,7 +94,6 @@ public: | |||
| 86 | this->SetGMtoZero(this->outputNumPerCore, dstStart); | 94 | this->SetGMtoZero(this->outputNumPerCore, dstStart); |
| 87 | } | 95 | } |
| 88 | 96 | ||
| 89 | - AscendC::PipeBarrier<PIPE_ALL>(); | ||
| 90 | ProcessFinalSecondAxes(srcStart, dstStart); | 97 | ProcessFinalSecondAxes(srcStart, dstStart); |
| 91 | 98 | ||
| 92 | if constexpr (ISCAST) { | 99 | if constexpr (ISCAST) { |
| @@ -94,7 +101,8 @@ public: | |||
| 94 | this->CalculateOutParms(params); | 101 | this->CalculateOutParms(params); |
| 95 | this->CopyToOutBigShapeOnePage(batchIdx, batchIdx, params); | 102 | this->CopyToOutBigShapeOnePage(batchIdx, batchIdx, params); |
| 96 | } | 103 | } |
| 97 | - AscendC::PipeBarrier<PIPE_ALL>(); | 104 | + PipeSync<AscendC::HardEvent::MTE3_V>(); |
| 105 | + PipeSync<AscendC::HardEvent::S_V>(); | ||
| 98 | } | 106 | } |
| 99 | } | 107 | } |
| 100 | 108 | ||
| @@ -107,6 +115,9 @@ private: | |||
| 107 | uint32_t blockLen = curHandleNum * this->size * this->typeSizeT1; | 115 | uint32_t blockLen = curHandleNum * this->size * this->typeSizeT1; |
| 108 | AscendC::DataCopyExtParams copyParamsIn{ | 116 | AscendC::DataCopyExtParams copyParamsIn{ |
| 109 | 1, blockLen, 0, 0, 0}; // 处理tasksOnce个数需要从srcGM中取((tasksOnce-1) * size + 1)个数 | 117 | 1, blockLen, 0, 0, 0}; // 处理tasksOnce个数需要从srcGM中取((tasksOnce-1) * size + 1)个数 |
| 118 | + PipeSync<AscendC::HardEvent::MTE3_MTE2>(); | ||
| 119 | + PipeSync<AscendC::HardEvent::S_MTE2>(); | ||
| 120 | + PipeSync<AscendC::HardEvent::V_MTE2>(); | ||
| 110 | AscendC::DataCopyPad( | 121 | AscendC::DataCopyPad( |
| 111 | srcLocal, this->srcGlobal[curSrcStart + index * this->tasksOnceMaxPerCore * this->size], copyParamsIn, | 122 | srcLocal, this->srcGlobal[curSrcStart + index * this->tasksOnceMaxPerCore * this->size], copyParamsIn, |
| 112 | padParams); // k * size * inputSizeLastDim + j + index * tasksOnceMaxPerCore * size | 123 | padParams); // k * size * inputSizeLastDim + j + index * tasksOnceMaxPerCore * size |