diff --git a/impl/kfc/kernel_kfc.h b/impl/kfc/kernel_kfc.h index 5f7ad2beeb46cdbb3281ae09c1f1245763a4b33b..a0a08b2b10848ea12fcaaadefe8bb39b1db5e73c 100644 --- a/impl/kfc/kernel_kfc.h +++ b/impl/kfc/kernel_kfc.h @@ -25,29 +25,10 @@ #include "lib/matmul/matmul_client.h" #include "../matmul/matmul_server.h" #endif -namespace AscendC { - constexpr uint16_t WORKSPACE_SYNC_ID = 15; - __aicore__ inline void clearWorkspace(__gm__ uint8_t* workspace) - { - AscendC::SetAtomicNone(); - #if __CCE_AICORE__ == 220 - if ASCEND_IS_AIC { - AscendC::SetMaskNorm(); - AscendC::SetLoadDataBoundary((uint64_t)0); - AscendC::SetLoadDataPaddingValue((uint64_t)0); - } else { - AscendC::AscendCUtils::SetMask((uint64_t)-1, (uint64_t)-1); - AscendC::SetMaskNorm(); - } - #endif - #ifdef __DAV_C220_CUBE__ - AscendC::ClearWorkspaceImpl(workspace); - AscendC::NotifyEvent(WORKSPACE_SYNC_ID); - #endif - } -} namespace AscendC { +__aicore__ inline void clearWorkspace(__gm__ uint8_t* workspace) {} + class KfcServer { // AIC side public: __aicore__ inline void Init(GM_ADDR workspaceGM) diff --git a/impl/kfc/kfc_register_obj.h b/impl/kfc/kfc_register_obj.h index 38a32c37f1184b2837c6c5680ec254b9748de9ac..6d744b547e84d87fd021e33c0ada7076c92b4086 100644 --- a/impl/kfc/kfc_register_obj.h +++ b/impl/kfc/kfc_register_obj.h @@ -17,6 +17,24 @@ #include "kernel_operator.h" namespace AscendC { +constexpr uint16_t WORKSPACE_SYNC_ID = 15; +__aicore__ inline void ClearWorkspace(__gm__ uint8_t *workspace) +{ +#if __CCE_AICORE__ == 220 + AscendC::SetAtomicNone(); + if ASCEND_IS_AIC { + AscendC::SetMaskNorm(); + AscendC::SetLoadDataBoundary((uint64_t)0); + AscendC::SetLoadDataPaddingValue((uint64_t)0); + AscendC::ClearWorkspaceImpl(workspace); + AscendC::NotifyEvent(WORKSPACE_SYNC_ID); + } else { + AscendC::AscendCUtils::SetMask((uint64_t)-1, (uint64_t)-1); + AscendC::SetMaskNorm(); + } +#endif +} + constexpr int8_t CUBEOBJ_MIX_MODE = 2; // 0 no, 1 all, 2 mix template struct CubeObjs {}; @@ -98,6 +116,7 @@ __aicore__ inline void InitCurObj(AscendC::TPipe* tpipe, T& a, Args&&... b) static_assert(asEnableMixDualMaster != AscendC::CUBEOBJ_MIX_MODE, \ "enableMixDualMaster must be consistent for all cube objects."); \ if ASCEND_IS_AIC { \ + AscendC::ClearWorkspace(reinterpret_cast<__gm__ uint8_t*>(workspace)); \ AscendC::KfcServer server; \ server.Init(workspace); \ server.InitObj(tpipe, __VA_ARGS__); \ @@ -115,6 +134,9 @@ __aicore__ inline void InitCurObj(AscendC::TPipe* tpipe, T& a, Args&&... b) AscendC::g_kfcClient = &__kfcClient__; \ } \ AscendC::SetMatrixKfc(tpipe, &__kfcClient__, 0, workspace, __VA_ARGS__); \ + if constexpr (!asEnableMixDualMaster) { \ + AscendC::WaitEvent(AscendC::WORKSPACE_SYNC_ID); \ + } \ } #endif @@ -148,6 +170,7 @@ __aicore__ inline void InitCurObj(AscendC::TPipe* tpipe, T& a, Args&&... b) constexpr int8_t asEnableMixDualMaster = ASCubeObjConfig::enableMixDualMasterValue; \ static_assert(asEnableMixDualMaster != AscendC::CUBEOBJ_MIX_MODE, \ "enableMixDualMaster must be consistent for all cube objects."); \ + AscendC::ClearWorkspace(reinterpret_cast<__gm__ uint8_t*>(workspace)); \ AscendC::KfcServer server; \ AscendC::AscendCTimeStamp(static_cast(AscendC::TimeStampId::TIME_STAMP_MATMUL_SERVER)); \ server.Init(workspace); \ @@ -170,6 +193,7 @@ __aicore__ inline void InitCurObj(AscendC::TPipe* tpipe, T& a, Args&&... b) constexpr int8_t asEnableMixDualMaster = ASCubeObjConfig::enableMixDualMasterValue; \ static_assert(asEnableMixDualMaster != AscendC::CUBEOBJ_MIX_MODE, \ "enableMixDualMaster must be consistent for all cube objects."); \ + AscendC::ClearWorkspace(reinterpret_cast<__gm__ uint8_t*>(workspace)); \ AscendC::KfcServer server; \ server.Init(workspace); \ server.InitObj(tpipe, __VA_ARGS__); \ @@ -205,7 +229,7 @@ __aicore__ inline void InitCurObj(AscendC::TPipe* tpipe, T& a, Args&&... b) AscendC::SetMatrixKfc(tpipe, &__kfcClient__, 0, workspace, __VA_ARGS__); \ AscendC::AscendCTimeStamp(static_cast(AscendC::TimeStampId::TIME_STAMP_MATMUL_MATRIX_KFC)); \ if constexpr (!asEnableMixDualMaster) { \ - AscendC::WaitEvent(AscendC::WORKSPACE_SYNC_ID); \ + AscendC::WaitEvent(AscendC::WORKSPACE_SYNC_ID); \ } \ AscendC::AscendCTimeStamp(static_cast(AscendC::TimeStampId::TIME_STAMP_MATMUL_WAIT_EVE)) @@ -224,7 +248,7 @@ __aicore__ inline void InitCurObj(AscendC::TPipe* tpipe, T& a, Args&&... b) } \ AscendC::SetMatrixKfc(tpipe, &__kfcClient__, 0, workspace, __VA_ARGS__); \ if constexpr (!asEnableMixDualMaster) { \ - AscendC::WaitEvent(AscendC::WORKSPACE_SYNC_ID); \ + AscendC::WaitEvent(AscendC::WORKSPACE_SYNC_ID); \ } #endif