diff --git a/impl/matmul/kfc/matmul_server.h b/impl/matmul/kfc/matmul_server.h index 3ee4c22c4cbf24de39a48a66f23f03f4ae196001..d6469de58e91245ed15e1f95d90dcd7566522411 100644 --- a/impl/matmul/kfc/matmul_server.h +++ b/impl/matmul/kfc/matmul_server.h @@ -17,6 +17,7 @@ #include "matmul_server_utils.h" #include "../utils/matmul_config_utils.h" +#include "../utils/matmul_utils.h" namespace AscendC { @@ -131,56 +132,6 @@ public: mul.SetBatchNum(body->batchA, body->batchB); } - __aicore__ inline void CalcBatchoffset(uint32_t batchA, uint32_t batchB, uint32_t batchC, BmmOffset& batchOffset) - { - if constexpr (A_TYPE::layout == LayoutMode::BNGS1S2 || A_TYPE::layout == LayoutMode::NORMAL) { - batchOffset.offA = tiling_.GetALayoutInfoD() * tiling_.GetALayoutInfoS() * batchA * sizeof(typename A_TYPE::T); - } else if constexpr (A_TYPE::layout == LayoutMode::SBNGD) { - batchOffset.offA = tiling_.GetALayoutInfoD() * batchA * sizeof(typename A_TYPE::T); - } - if constexpr (B_TYPE::layout == LayoutMode::BNGS1S2 || B_TYPE::layout == LayoutMode::NORMAL) { - batchOffset.offB = tiling_.GetBLayoutInfoD() * tiling_.GetBLayoutInfoS() * batchB * sizeof(typename B_TYPE::T); - } else { - batchOffset.offB = tiling_.GetBLayoutInfoD() * batchB * sizeof(typename B_TYPE::T); - } - - if constexpr (C_TYPE::layout == LayoutMode::BNGS1S2 || C_TYPE::layout == LayoutMode::NORMAL) { - batchOffset.offC = tiling_.GetCLayoutInfoS2() * tiling_.GetCLayoutInfoS1() * batchC * sizeof(typename C_TYPE::T); - } else { - batchOffset.offC = tiling_.GetCLayoutInfoS2() * batchC * sizeof(typename C_TYPE::T); - } - } - - __aicore__ inline void CalcNBatchoffset(uint32_t batchA, uint32_t batchB, uint32_t batchC, uint32_t loopIdx, BmmOffset batchOffset, BmmOffset& batchLoopOffset) - { - if constexpr (A_TYPE::layout == LayoutMode::BSNGD) { - uint64_t aLayoutBIdx = loopIdx * batchA / (tiling_.GetALayoutInfoN() * tiling_.GetALayoutInfoG()); - uint64_t aLayoutNGOff = loopIdx * batchA % (tiling_.GetALayoutInfoN() * tiling_.GetALayoutInfoG()); - batchLoopOffset.offA = (aLayoutBIdx * tiling_.GetALayoutInfoD() * tiling_.GetALayoutInfoS() * tiling_.GetALayoutInfoN() * tiling_.GetALayoutInfoG() + - aLayoutNGOff * tiling_.GetALayoutInfoD()) * sizeof(typename A_TYPE::T); - } else { - batchLoopOffset.offA = batchOffset.offA * loopIdx; - } - - if constexpr (B_TYPE::layout == LayoutMode::BSNGD) { - uint64_t bLayoutBIdx = loopIdx * batchB / (tiling_.GetBLayoutInfoN() * tiling_.GetBLayoutInfoG()); - uint64_t bLayoutNGOff = loopIdx * batchB % (tiling_.GetBLayoutInfoN() * tiling_.GetBLayoutInfoG()); - batchLoopOffset.offB = (bLayoutBIdx * tiling_.GetBLayoutInfoD() * tiling_.GetBLayoutInfoS() * tiling_.GetBLayoutInfoN() * tiling_.GetBLayoutInfoG() + - bLayoutNGOff * tiling_.GetBLayoutInfoD()) * sizeof(typename B_TYPE::T); - } else { - batchLoopOffset.offB = batchOffset.offB * loopIdx; - } - - if constexpr (C_TYPE::layout == LayoutMode::BSNGD) { - uint64_t cLayoutBIdx = loopIdx * batchC / (tiling_.GetCLayoutInfoN() * tiling_.GetCLayoutInfoG()); - uint64_t cLayoutNGOff = loopIdx * batchC % (tiling_.GetCLayoutInfoN() * tiling_.GetCLayoutInfoG()); - batchLoopOffset.offC = (cLayoutBIdx * tiling_.GetCLayoutInfoS2() * tiling_.GetCLayoutInfoS1() * tiling_.GetCLayoutInfoN() * tiling_.GetCLayoutInfoG() + - cLayoutNGOff * tiling_.GetCLayoutInfoS2()) * sizeof(typename C_TYPE::T); - } else { - batchLoopOffset.offC = batchOffset.offC * loopIdx; - } - } - #if defined(__DAV_C310__) __aicore__ inline void SetUserDefInfo(MSG_POS KfcMsg* msg) { diff --git a/impl/matmul/kfc/matmul_server_impl_c310.h b/impl/matmul/kfc/matmul_server_impl_c310.h index a5f7054e60331512c3d56275c65d035725f117d6..a0042d3c668a243f310fefde9b4ab8d9c0eccd59 100644 --- a/impl/matmul/kfc/matmul_server_impl_c310.h +++ b/impl/matmul/kfc/matmul_server_impl_c310.h @@ -190,22 +190,15 @@ __aicore__ inline void MatmulServicebatchA > body->batchB ? body->batchA : body->batchB; - bool layoutGCondition = tiling_.GetCLayoutInfoG() == 1 && - (tiling_.GetBLayoutInfoG() != 1 || tiling_.GetALayoutInfoG() != 1); - if (layoutGCondition) { - int32_t layoutG = tiling_.GetBLayoutInfoG() > tiling_.GetALayoutInfoG() ? tiling_.GetBLayoutInfoG() : tiling_.GetALayoutInfoG(); - batchC = batchC / layoutG; - } + uint32_t batchC = GetBatchCNum(body->batchA, body->batchB, tiling_.GetALayoutInfoG(), tiling_.GetBLayoutInfoG(), tiling_.GetCLayoutInfoG()); uint64_t batchOffsetBias = tiling_.GetCLayoutInfoS2() * batchC * sizeof(typename BIAS_TYPE::T); - - BmmOffset batchOffset; - CalcBatchoffset(body->batchA, body->batchB, batchC, batchOffset); - BmmOffset batchLoopOffset; for (uint32_t loopIdx = 0U; loopIdx < body->batchLoop; loopIdx++) { const uint64_t biasOffset = batchOffsetBias * loopIdx; - CalcNBatchoffset(body->batchA, body->batchB, batchC, loopIdx, batchOffset, batchLoopOffset); + batchLoopOffset.offA = CalcNBatchoffset(body->batchA, loopIdx, tiling_.GetALayoutInfoN(), tiling_.GetALayoutInfoG(), tiling_.GetALayoutInfoD(), tiling_.GetALayoutInfoS()); + batchLoopOffset.offB = CalcNBatchoffset(body->batchB, loopIdx, tiling_.GetBLayoutInfoN(), tiling_.GetBLayoutInfoG(), tiling_.GetBLayoutInfoD(), tiling_.GetBLayoutInfoS()); + batchLoopOffset.offC = CalcNBatchoffset(batchC, loopIdx, tiling_.GetCLayoutInfoN(), tiling_.GetCLayoutInfoG(), tiling_.GetCLayoutInfoS2(), tiling_.GetCLayoutInfoS1()); + IterateSetMessage(body, singleBatchASize, singleBatchBSize, batchLoopOffset.offA, batchLoopOffset.offB, biasOffset); GlobalTensor cGlobal; cGlobal.SetGlobalBuffer(reinterpret_cast<__gm__ DstT*>(body->cAddr + batchLoopOffset.offC), size); diff --git a/impl/matmul/kfc/matmul_server_utils.h b/impl/matmul/kfc/matmul_server_utils.h index fe0000b701208a1579bb12ea32bb4dfe26791d52..cdd9a9671221ccc6e19988e3ec9891c856bc7730 100644 --- a/impl/matmul/kfc/matmul_server_utils.h +++ b/impl/matmul/kfc/matmul_server_utils.h @@ -55,12 +55,6 @@ struct MatmulMsg { uint32_t orgKc; }; -struct BmmOffset { - uint64_t offA; - uint64_t offB; - uint64_t offC; -}; - struct ShareMatmulBase { __aicore__ inline ShareMatmulBase() {}; }; diff --git a/tests/matmul/test_matmul_channel_split.cpp b/tests/matmul/test_matmul_channel_split.cpp index eef8b04566532cfe7d36e543e1378f5c14bc2846..f36face05f90a160247a0c87a0fae06c6c66fedb 100644 --- a/tests/matmul/test_matmul_channel_split.cpp +++ b/tests/matmul/test_matmul_channel_split.cpp @@ -260,8 +260,12 @@ __aicore__ inline void main_kernel_matmul_channel_split(GM_ADDR aGM, GM_ADDR bGM class TEST_KERNEL_MATMUL_CHANNEL_SPLIT : public testing::Test { protected: - void SetUp() {} - void TearDown() {} + void SetUp() { + AscendC::SetGCoreType(1); + } + void TearDown() { + AscendC::SetGCoreType(0); + } }; #define KERNEL_MATMUL_TESTCASE(TEST_KERNEL_MATMUL_CHANNEL_SPLIT, tilingParams, A_Pos, B_Pos, C_Pos, BIAS_Pos, A_Format, B_Format, C_Format, BIAS_Format, \ diff --git a/tests/matmul/test_matmul_triangular.cpp b/tests/matmul/test_matmul_triangular.cpp index 82fd851f3c94728454bc890abe9afb3883d8fcbf..f03457260bddd143eba3789b26d414578dfd6397 100644 --- a/tests/matmul/test_matmul_triangular.cpp +++ b/tests/matmul/test_matmul_triangular.cpp @@ -212,8 +212,12 @@ __aicore__ inline void main_kernel_matmul(GM_ADDR aGM, GM_ADDR bGM, GM_ADDR cGM, class TEST_KERNEL_TRIAN_MATMUL : public testing::Test { protected: - void SetUp() {} - void TearDown() {} + void SetUp() { + AscendC::SetGCoreType(1); + } + void TearDown() { + AscendC::SetGCoreType(0); + } }; #define KERNEL_TRIAN_MATMUL_TESTCASE(TEST_KERNEL_TRIAN_MATMUL, tilingParams, A_Pos, B_Pos, C_Pos, BIAS_Pos, A_Format, B_Format, C_Format, BIAS_Format, \ diff --git a/tests/pad/pad/test_operator_pad.cpp b/tests/pad/pad/test_operator_pad.cpp index f7e4e51c3d5eaa455c5692b8e8ca9cb29ba107da..48b75a9d7df458fa969f8bd382bc8e018f6b13b6 100644 --- a/tests/pad/pad/test_operator_pad.cpp +++ b/tests/pad/pad/test_operator_pad.cpp @@ -156,7 +156,7 @@ class UnPadTestsuite : public testing::Test, protected: void SetUp() { - AscendC::SetGCoreType(1); + AscendC::SetGCoreType(2); } void TearDown() { @@ -354,7 +354,7 @@ class PadTestsuite : public testing::Test, protected: void SetUp() { - AscendC::SetGCoreType(1); + AscendC::SetGCoreType(2); } void TearDown() {