diff --git a/impl/matmul/kfc/matmul_server.h b/impl/matmul/kfc/matmul_server.h index f022f96c093c2e8196e506a623c2ebe23e0e9a54..faf2723109b17f966673639d1455c676e36663ac 100644 --- a/impl/matmul/kfc/matmul_server.h +++ b/impl/matmul/kfc/matmul_server.h @@ -18,6 +18,7 @@ #include "matmul_server_utils.h" #include "../utils/matmul_config_utils.h" +#include "../utils/matmul_utils.h" namespace AscendC { @@ -132,56 +133,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 5ba19ec983575aba090931147ffa71ab9cec2d84..47ea92898ffa7794354707971e0f8bfd445aac1e 100644 --- a/impl/matmul/kfc/matmul_server_impl_c310.h +++ b/impl/matmul/kfc/matmul_server_impl_c310.h @@ -191,22 +191,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 48bbf2321f388d27be1248161a4fb7f131acd9c5..3a66918b58b709413aeabab2931d4397c6a40f1d 100644 --- a/impl/matmul/kfc/matmul_server_utils.h +++ b/impl/matmul/kfc/matmul_server_utils.h @@ -4,8 +4,8 @@ * This file is a part of the CANN Open Software. * Licensed under CANN Open Software License Agreement Version 2.0 (the "License"). * Please refer to the License for details. You may not use this file except in compliance with the License. - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, - * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING + * BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. * See LICENSE in the root of the software repository for the full text of the License. */ @@ -56,12 +56,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() {