已合并
add GradientAcc membar #8382
add GradientAcc membar #8382
已合并
liuchuangdev创建于 8月7日
共 1 个文件变更+13-1
@@ -211,12 +211,24 @@ __aicore__ inline void MaxPoolGradWithArgmaxV3NCHWScalar<T1, T2>::ProcessPerLoop
211 if (isTailBlock_) {211 if (isTailBlock_) {
212 currentInnerLoop = tilingData_.argmaxInnerLoopTail;212 currentInnerLoop = tilingData_.argmaxInnerLoopTail;
213 }213 }
214+ // Precise sync, deferred until just before the first Scalar accumulation writes
215+ // yLocal: the Vector zero-fill (Duplicate) must complete before Scalar reads yLocal,
216+ // otherwise UB may hold stale data (occasional error). Deferring lets the Vector
217+ // zero-fill overlap the preceding setup/CopyIn work.
218+ event_t eventVSToCompute = static_cast<event_t>(GetTPipePtr()->FetchEventID(HardEvent::V_S));
219+ SetFlag<HardEvent::V_S>(eventVSToCompute);
220+ WaitFlag<HardEvent::V_S>(eventVSToCompute);
214 for (int64_t i = 0; i < currentInnerLoop; i++) {221 for (int64_t i = 0; i < currentInnerLoop; i++) {
215 ComputeActualOffset(i, argmaxNcActual, argmaxHActual, argmaxWActual, argmaxGmOffset, argmaxNcIndex);222 ComputeActualOffset(i, argmaxNcActual, argmaxHActual, argmaxWActual, argmaxGmOffset, argmaxNcIndex);
216 CopyInArgmaxGrad(argmaxNcActual, argmaxHActual, argmaxWActual, argmaxGmOffset);223 CopyInArgmaxGrad(argmaxNcActual, argmaxHActual, argmaxWActual, argmaxGmOffset);
217 Compute(yLocal, argmaxNcActual, argmaxHActual, argmaxWActual, argmaxNcIndex);224 Compute(yLocal, argmaxNcActual, argmaxHActual, argmaxWActual, argmaxNcIndex);
218 }225 }
219 if constexpr (std::negation<std::is_same<T1, float>>::value) {226 if constexpr (std::negation<std::is_same<T1, float>>::value) {
227+ // Precise sync: the Scalar accumulation writes to yLocal must complete before
228+ // the Vector Cast reads yLocal, otherwise the cast may consume stale data.
229+ event_t eventSVToCast = static_cast<event_t>(GetTPipePtr()->FetchEventID(HardEvent::S_V));
230+ SetFlag<HardEvent::S_V>(eventSVToCast);
231+ WaitFlag<HardEvent::S_V>(eventSVToCast);
220 Cast(yLocal.ReinterpretCast<T1>(), yLocal, RoundMode::CAST_RINT, calCount);232 Cast(yLocal.ReinterpretCast<T1>(), yLocal, RoundMode::CAST_RINT, calCount);
221 }233 }
222 outputQue_.EnQue(yLocal);234 outputQue_.EnQue(yLocal);
@@ -323,4 +335,4 @@ __aicore__ inline uint32_t MaxPoolGradWithArgmaxV3NCHWScalar<T1, T2>::ConvertInd
323 return ubIndex;335 return ubIndex;
324}336}
325} // namespace MaxPoolGradWithArgmaxV3NCHWScalarNameSpace337} // namespace MaxPoolGradWithArgmaxV3NCHWScalarNameSpace
326-#endif338+#endif