From 45add5b50dabbc9933268fc35c810d77d5220542 Mon Sep 17 00:00:00 2001 From: qiaolili Date: Wed, 29 Oct 2025 17:09:23 +0800 Subject: [PATCH 1/2] SetGCoreType llt err --- tests/matmul/test_matmul_channel_split.cpp | 8 ++++++-- tests/matmul/test_matmul_triangular.cpp | 8 ++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/tests/matmul/test_matmul_channel_split.cpp b/tests/matmul/test_matmul_channel_split.cpp index eef8b045..db9126c3 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 82fd851f..772a37f3 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, \ -- Gitee From d27b6ad101421f867e1946ee75172fecbf91628d Mon Sep 17 00:00:00 2001 From: qiaolili Date: Thu, 6 Nov 2025 15:00:29 +0800 Subject: [PATCH 2/2] IterateBatch DB perf err --- impl/matmul/kfc/matmul_server.h | 51 +--------------------- impl/matmul/kfc/matmul_server_impl_c310.h | 17 +++----- impl/matmul/kfc/matmul_server_utils.h | 6 --- tests/matmul/test_matmul_channel_split.cpp | 2 +- tests/matmul/test_matmul_triangular.cpp | 2 +- tests/pad/pad/test_operator_pad.cpp | 4 +- 6 files changed, 10 insertions(+), 72 deletions(-) diff --git a/impl/matmul/kfc/matmul_server.h b/impl/matmul/kfc/matmul_server.h index 3ee4c22c..d6469de5 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 a5f7054e..a0042d3c 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 fe0000b7..cdd9a967 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 db9126c3..f36face0 100644 --- a/tests/matmul/test_matmul_channel_split.cpp +++ b/tests/matmul/test_matmul_channel_split.cpp @@ -262,7 +262,7 @@ class TEST_KERNEL_MATMUL_CHANNEL_SPLIT : public testing::Test { protected: void SetUp() { AscendC::SetGCoreType(1); - } + } void TearDown() { AscendC::SetGCoreType(0); } diff --git a/tests/matmul/test_matmul_triangular.cpp b/tests/matmul/test_matmul_triangular.cpp index 772a37f3..f0345726 100644 --- a/tests/matmul/test_matmul_triangular.cpp +++ b/tests/matmul/test_matmul_triangular.cpp @@ -214,7 +214,7 @@ class TEST_KERNEL_TRIAN_MATMUL : public testing::Test { protected: void SetUp() { AscendC::SetGCoreType(1); - } + } void TearDown() { AscendC::SetGCoreType(0); } diff --git a/tests/pad/pad/test_operator_pad.cpp b/tests/pad/pad/test_operator_pad.cpp index f7e4e51c..48b75a9d 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() { -- Gitee