LCOV - code coverage report
Current view: top level - utils/include/utils - kernel_utils_mode_cpu.h (source / functions) Coverage Total Hit
Test: coverage.info_filtered Lines: 84.0 % 106 89
Test Date: 2026-07-27 14:41:20 Functions: 89.5 % 19 17

            Line data    Source code
       1              : /**
       2              :  * Copyright (c) 2025 Huawei Technologies Co., Ltd.
       3              :  * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
       4              :  * CANN Open Software License Agreement Version 2.0 (the "License").
       5              :  * Please refer to the License for details. You may not use this file except in compliance with the License.
       6              :  * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
       7              :  * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
       8              :  * See LICENSE in the root of the software repository for the full text of the License.
       9              :  */
      10              : 
      11              : /*!
      12              :  * \file kernel_utils_mode_cpu.h
      13              :  * \brief
      14              :  */
      15              : #ifndef ASCENDC_MODULE_UTILS_MODE_CPU_H
      16              : #define ASCENDC_MODULE_UTILS_MODE_CPU_H
      17              : #include "utils/kernel_utils_constants.h"
      18              : 
      19              : namespace AscendC {
      20              : class MaskSetter {
      21              : public:
      22          476 :     static MaskSetter& Instance()
      23              :     {
      24          482 :         static MaskSetter instance;
      25          476 :         return instance;
      26              :     };
      27              : 
      28          280 :     void SetMask(bool setMask) { isSetMask = setMask; }
      29              : 
      30          196 :     bool GetMask() const { return isSetMask; }
      31              : 
      32              : private:
      33            4 :     MaskSetter() {};
      34            4 :     ~MaskSetter() {};
      35              :     bool isSetMask = true;
      36              : };
      37              : 
      38              : class Int4Setter {
      39              : public:
      40          468 :     static Int4Setter& Instance()
      41              :     {
      42          468 :         static Int4Setter instance;
      43          468 :         return instance;
      44              :     };
      45              : 
      46            0 :     void SetInt4() { isInt4 = true; }
      47              : 
      48              :     void SetDstInt4() { isDstInt4 = true; }
      49              : 
      50              :     void SetSrcInt4() { isSrcInt4 = true; }
      51              : 
      52            0 :     void ResetInt4() { isInt4 = false; }
      53              : 
      54              :     void ResetDstSrcInt4()
      55              :     {
      56              :         isDstInt4 = false;
      57              :         isSrcInt4 = false;
      58              :     }
      59              : 
      60          428 :     bool GetInt4() const { return isInt4; }
      61              : 
      62           24 :     bool GetDstInt4() const { return isDstInt4; }
      63              : 
      64           16 :     bool GetSrcInt4() const { return isSrcInt4; }
      65              : 
      66              : private:
      67            4 :     Int4Setter() {};
      68            4 :     ~Int4Setter() {};
      69              : 
      70              :     bool isInt4 = false;
      71              :     bool isDstInt4 = false;
      72              :     bool isSrcInt4 = false;
      73              : };
      74              : 
      75              : enum class BlockMode : uint8_t {
      76              :     BLOCK_MODE_NORMAL = 0,
      77              :     BLOCK_MODE_MATRIX,
      78              :     BLOCK_MODE_VECTOR,
      79              :     BLOCK_MODE_SMALL_CHANNEL,
      80              :     BLOCK_MODE_DEPTHWISE,
      81              : };
      82              : 
      83              : #if defined(ASCENDC_CPU_DEBUG) && ASCENDC_CPU_DEBUG == 1
      84              : class ConstDefiner {
      85              : public:
      86         1872 :     static ConstDefiner& Instance()
      87              :     {
      88         1872 :         static ConstDefiner instance;
      89         1872 :         return instance;
      90              :     };
      91              : 
      92         1788 :     uint8_t* GetHardwareBaseAddr(Hardware hardPos)
      93              :     {
      94         1788 :         ASCENDC_ASSERT((hardwareCpuBufferMap.find(hardPos) != hardwareCpuBufferMap.end()), {
      95              :             KERNEL_LOG(KERNEL_ERROR, "illegal hardPos %d", static_cast<int>(hardPos));
      96              :         });
      97         1788 :         return hardwareCpuBufferMap[hardPos];
      98              :     }
      99              : 
     100              :     bool CheckAllocatorUsed(Hardware hardPos)
     101              :     {
     102              :         if (allocatorUsed.find(hardPos) != allocatorUsed.end()) {
     103              :             return true;
     104              :         }
     105              :         allocatorUsed.insert(hardPos);
     106              :         return false;
     107              :     }
     108              : 
     109              :     const std::map<uint8_t, std::string> logicNameMap{
     110              :         {static_cast<uint8_t>(TPosition::GM), "GM"},
     111              :         {static_cast<uint8_t>(TPosition::A1), "A1"},
     112              :         {static_cast<uint8_t>(TPosition::A2), "A2"},
     113              :         {static_cast<uint8_t>(TPosition::B1), "B1"},
     114              :         {static_cast<uint8_t>(TPosition::B2), "B2"},
     115              :         {static_cast<uint8_t>(TPosition::C1), "C1"},
     116              :         {static_cast<uint8_t>(TPosition::C2), "C2"},
     117              :         {static_cast<uint8_t>(TPosition::CO1), "CO1"},
     118              :         {static_cast<uint8_t>(TPosition::CO2), "CO2"},
     119              :         {static_cast<uint8_t>(TPosition::VECIN), "VECIN"},
     120              :         {static_cast<uint8_t>(TPosition::VECOUT), "VECOUT"},
     121              :         {static_cast<uint8_t>(TPosition::VECCALC), "VECCALC"},
     122              :         {static_cast<uint8_t>(TPosition::LCM), "LCM"},
     123              :         {static_cast<uint8_t>(TPosition::SPM), "SPM"},
     124              :         {static_cast<uint8_t>(TPosition::SHM), "SHM"},
     125              :         {static_cast<uint8_t>(TPosition::TSCM), "TSCM"},
     126              :         {static_cast<uint8_t>(TPosition::C2PIPE2GM), "C2PIPE2GM"},
     127              :         {static_cast<uint8_t>(TPosition::C2PIPE2LOCAL), "C2PIPE2LOCAL"},
     128              :         {static_cast<uint8_t>(TPosition::MAX), "MAX"},
     129              :     };
     130              : 
     131              :     const std::set<std::vector<Hardware>> quantDataCopy = {
     132              :         {Hardware::UB, Hardware::L0C}, {Hardware::L0C, Hardware::UB}};
     133              : 
     134              :     const std::set<std::vector<Hardware>> normalDataCopy = {{Hardware::L1, Hardware::UB}, {Hardware::GM, Hardware::L1},
     135              :                                                             {Hardware::GM, Hardware::UB}, {Hardware::UB, Hardware::L1},
     136              :                                                             {Hardware::UB, Hardware::GM}, {Hardware::UB, Hardware::UB},
     137              :                                                             {Hardware::L1, Hardware::GM}};
     138              : 
     139              :     const std::set<std::vector<Hardware>> biasDataCopy = {{Hardware::L1, Hardware::BIAS}};
     140              : 
     141              :     const std::set<std::vector<Hardware>> matDataCopy = {{Hardware::L1, Hardware::L0C}};
     142              : 
     143              :     const std::map<BlockMode, std::string> blockModeMap = {
     144              :         {BlockMode::BLOCK_MODE_NORMAL, ""},      {BlockMode::BLOCK_MODE_MATRIX, ""},
     145              :         {BlockMode::BLOCK_MODE_VECTOR, "V"},     {BlockMode::BLOCK_MODE_SMALL_CHANNEL, "SC"},
     146              :         {BlockMode::BLOCK_MODE_DEPTHWISE, "DP"},
     147              :     };
     148              : 
     149              :     const std::map<Hardware, std::string> hardwareMap = {
     150              :         {Hardware::GM, "OUT"},  {Hardware::L1, "L1"},     {Hardware::L0A, "L0A"},
     151              :         {Hardware::L0B, "L0B"}, {Hardware::L0C, "L0C"},   {Hardware::UB, "UB"},
     152              : #if defined(__NPU_ARCH__) &&                                                                                 \
     153              :     ((__NPU_ARCH__ == 2201) || (__NPU_ARCH__ == 3002) || (__NPU_ARCH__ == 3102) || (__NPU_ARCH__ == 3510) || \
     154              :      (__NPU_ARCH__ == 5102) || (__NPU_ARCH__ == 3003) || (__NPU_ARCH__ == 3103) || (__NPU_ARCH__ == 3113))
     155              :         {Hardware::BIAS, "BT"}, {Hardware::FIXBUF, "FB"},
     156              : #endif
     157              :     };
     158              : 
     159              :     const std::map<std::string, uint16_t> dstBurstLenUnitMap = {
     160              :         {"L0C16UB", 512},    {"L0C32UB", 1024},    {"UBL0C16", 512},   {"UBL0C32", 1024},
     161              :         {"L1L0C16", 512},    {"L1L0C32", 1024},    {"L0CV16UB", 32},   {"L0CV32UB", 64},
     162              :         {"UBL0CV16", 512},   {"UBL0CV32", 1024},   {"L0CSC32UB", 256}, {"UBL0CSC32", 256},
     163              :         {"L0CDPf16UB", 512}, {"L0CDPf32UB", 1024}, {"L1BT", 64},       {"L1FB", 128},
     164              :     };
     165              : #if defined(__NPU_ARCH__) && ((__NPU_ARCH__ == 3510) || (__NPU_ARCH__ == 5102))
     166              :     const std::map<std::string, uint16_t> srcBurstLenUnitMap{
     167              :         {"L0C16UB", 512},    {"L0C32UB", 1024},    {"UBL0C16", 512},   {"UBL0C32", 1024},
     168              :         {"L1L0C16", 512},    {"L1L0C32", 1024},    {"L0CV16UB", 512},  {"L0CV32UB", 1024},
     169              :         {"UBL0CV16", 32},    {"UBL0CV32", 64},     {"L0CSC32UB", 256}, {"UBL0CSC32", 256},
     170              :         {"L0CDPf16UB", 512}, {"L0CDPf32UB", 1024}, {"L1BT", 32},       {"L1FB", 64},
     171              :     };
     172              :     const std::map<std::string, uint16_t> dstStrideUnitMap{
     173              :         {"UBL0C16", 512},   {"UBL0C32", 1024},  {"L1L0C16", 512}, {"L1L0C32", 1024}, {"UBL0CV16", 512},
     174              :         {"UBL0CV32", 1024}, {"UBL0CSC32", 256}, {"L1BT", 32},     {"L1FB", 64},
     175              :     };
     176              : #else
     177              :     const std::map<std::string, uint16_t> srcBurstLenUnitMap = {
     178              :         {"L0C16UB", 512},    {"L0C32UB", 1024},    {"UBL0C16", 512},   {"UBL0C32", 1024},
     179              :         {"L1L0C16", 512},    {"L1L0C32", 1024},    {"L0CV16UB", 512},  {"L0CV32UB", 1024},
     180              :         {"UBL0CV16", 32},    {"UBL0CV32", 64},     {"L0CSC32UB", 256}, {"UBL0CSC32", 256},
     181              :         {"L0CDPf16UB", 512}, {"L0CDPf32UB", 1024}, {"L1BT", 64},       {"L1FB", 128},
     182              :     };
     183              : 
     184              :     const std::map<std::string, uint16_t> dstStrideUnitMap = {
     185              :         {"UBL0C16", 512},   {"UBL0C32", 1024},  {"L1L0C16", 512}, {"L1L0C32", 1024}, {"UBL0CV16", 512},
     186              :         {"UBL0CV32", 1024}, {"UBL0CSC32", 256}, {"L1BT", 64},     {"L1FB", 128},
     187              :     };
     188              : #endif
     189              :     const std::map<std::string, uint16_t> srcStrideUnitMap = {
     190              :         {"L1L0C16", 32},      {"L1L0C32", 32},    {"L0C16UB", 512},   {"L0C32UB", 1024},
     191              :         {"L0CV16UB", 512},    {"L0CV32UB", 1024}, {"L0CSC32UB", 256}, {"L0CDPf16UB", 512},
     192              :         {"L0CDPf32UB", 1024}, {"L1BT", 32},       {"L1FB", 32},
     193              :     };
     194              : 
     195              : #if defined(__NPU_ARCH__) && ((__NPU_ARCH__ == 3510) || (__NPU_ARCH__ == 5102))
     196              :     const std::map<TPosition, Hardware> positionHardMap = {
     197              :         {TPosition::GM, Hardware::GM},      {TPosition::A1, Hardware::L1},
     198              :         {TPosition::B1, Hardware::L1},      {TPosition::TSCM, Hardware::L1},
     199              :         {TPosition::VECIN, Hardware::UB},   {TPosition::VECOUT, Hardware::UB},
     200              :         {TPosition::VECCALC, Hardware::UB}, {TPosition::A2, Hardware::L0A},
     201              :         {TPosition::B2, Hardware::L0B},     {TPosition::C1, Hardware::L1},
     202              :         {TPosition::C2, Hardware::BIAS},    {TPosition::CO1, Hardware::L0C},
     203              :         {TPosition::CO2, Hardware::GM},     {TPosition::C2PIPE2GM, Hardware::FIXBUF},
     204              :     };
     205              : #elif defined(__NPU_ARCH__) && ((__NPU_ARCH__ == 1001) || (__NPU_ARCH__ == 2002))
     206              :     const std::map<TPosition, Hardware> positionHardMap = {
     207              :         {TPosition::GM, Hardware::GM},      {TPosition::A1, Hardware::L1},    {TPosition::B1, Hardware::L1},
     208              :         {TPosition::TSCM, Hardware::L1},    {TPosition::VECIN, Hardware::UB}, {TPosition::VECOUT, Hardware::UB},
     209              :         {TPosition::VECCALC, Hardware::UB}, {TPosition::A2, Hardware::L0A},   {TPosition::B2, Hardware::L0B},
     210              :         {TPosition::C1, Hardware::UB},      {TPosition::C2, Hardware::L0C},   {TPosition::CO1, Hardware::L0C},
     211              :         {TPosition::CO2, Hardware::UB},
     212              :     };
     213              : #elif __NPU_ARCH__ == 2201
     214              :     const std::map<TPosition, Hardware> positionHardMap = {
     215              :         {TPosition::GM, Hardware::GM},      {TPosition::A1, Hardware::L1},
     216              :         {TPosition::B1, Hardware::L1},      {TPosition::TSCM, Hardware::L1},
     217              :         {TPosition::VECIN, Hardware::UB},   {TPosition::VECOUT, Hardware::UB},
     218              :         {TPosition::VECCALC, Hardware::UB}, {TPosition::A2, Hardware::L0A},
     219              :         {TPosition::B2, Hardware::L0B},     {TPosition::C1, Hardware::L1},
     220              :         {TPosition::C2, Hardware::BIAS},    {TPosition::CO1, Hardware::L0C},
     221              :         {TPosition::CO2, Hardware::GM},     {TPosition::C2PIPE2GM, Hardware::FIXBUF},
     222              :     };
     223              : #elif __NPU_ARCH__ == 3002
     224              :     const std::map<TPosition, Hardware> positionHardMap = {
     225              :         {TPosition::GM, Hardware::GM},      {TPosition::A1, Hardware::L1},
     226              :         {TPosition::B1, Hardware::L1},      {TPosition::TSCM, Hardware::L1},
     227              :         {TPosition::VECIN, Hardware::UB},   {TPosition::VECOUT, Hardware::UB},
     228              :         {TPosition::VECCALC, Hardware::UB}, {TPosition::A2, Hardware::L0A},
     229              :         {TPosition::B2, Hardware::L0B},     {TPosition::C1, Hardware::L1},
     230              :         {TPosition::C2, Hardware::BIAS},    {TPosition::CO1, Hardware::L0C},
     231              :         {TPosition::CO2, Hardware::GM},     {TPosition::C2PIPE2GM, Hardware::FIXBUF},
     232              :     };
     233              : #elif __NPU_ARCH__ == 3102
     234              :     const std::map<TPosition, Hardware> positionHardMap = {
     235              :         {TPosition::GM, Hardware::GM},      {TPosition::A1, Hardware::L1},    {TPosition::B1, Hardware::L1},
     236              :         {TPosition::TSCM, Hardware::L1},    {TPosition::VECIN, Hardware::UB}, {TPosition::VECOUT, Hardware::UB},
     237              :         {TPosition::VECCALC, Hardware::UB}, {TPosition::A2, Hardware::L0A},   {TPosition::B2, Hardware::L0B},
     238              :         {TPosition::C1, Hardware::L1},      {TPosition::C2, Hardware::BIAS},  {TPosition::CO1, Hardware::L0C},
     239              :         {TPosition::CO2, Hardware::GM},
     240              :     };
     241              : #elif defined(__NPU_ARCH__) && (__NPU_ARCH__ == 2103)
     242              :     const std::map<TPosition, Hardware> positionHardMap = {
     243              :         {TPosition::GM, Hardware::GM},      {TPosition::A1, Hardware::L1},    {TPosition::B1, Hardware::L1},
     244              :         {TPosition::TSCM, Hardware::L1},    {TPosition::VECIN, Hardware::UB}, {TPosition::VECOUT, Hardware::UB},
     245              :         {TPosition::VECCALC, Hardware::UB}, {TPosition::A2, Hardware::L0A},   {TPosition::B2, Hardware::L0B},
     246              :         {TPosition::C1, Hardware::L1},      {TPosition::C2, Hardware::BIAS},  {TPosition::CO1, Hardware::L0C},
     247              :         {TPosition::CO2, Hardware::GM},
     248              :     };
     249              : #elif defined(__NPU_ARCH__) && ((__NPU_ARCH__ == 3103) || (__NPU_ARCH__ == 3113) || (__NPU_ARCH__ == 3003))
     250              :     const std::map<TPosition, Hardware> positionHardMap = {
     251              :         {TPosition::GM, Hardware::GM},      {TPosition::A1, Hardware::L1},    {TPosition::B1, Hardware::L1},
     252              :         {TPosition::TSCM, Hardware::L1},    {TPosition::VECIN, Hardware::UB}, {TPosition::VECOUT, Hardware::UB},
     253              :         {TPosition::VECCALC, Hardware::UB}, {TPosition::A2, Hardware::L0A},   {TPosition::B2, Hardware::L0B},
     254              :         {TPosition::C1, Hardware::L1},      {TPosition::C2, Hardware::BIAS},  {TPosition::CO1, Hardware::L0C},
     255              :         {TPosition::CO2, Hardware::GM},
     256              :     };
     257              : 
     258              : #endif
     259              : 
     260              : #if defined(__NPU_ARCH__) && ((__NPU_ARCH__ == 3510) || (__NPU_ARCH__ == 5102))
     261              :     const std::map<Hardware, uint32_t> bufferInitLen = {
     262              :         {Hardware::GM, 1024 * 1024}, {Hardware::UB, 1024 * 256},    {Hardware::L1, 1024 * 512},
     263              :         {Hardware::L0A, 1024 * 64},  {Hardware::L0B, 1024 * 64},    {Hardware::L0C, 1024 * 256},
     264              :         {Hardware::BIAS, 1024 * 4},  {Hardware::FIXBUF, 1024 * 16},
     265              :     };
     266              :     uint8_t* cpuL0AMx;
     267              :     uint8_t* cpuL0BMx;
     268              : #elif defined(__NPU_ARCH__) && ((__NPU_ARCH__ == 1001) || (__NPU_ARCH__ == 2002))
     269              :     const std::map<Hardware, uint32_t> bufferInitLen = {
     270              :         {Hardware::GM, 1024 * 1024}, {Hardware::UB, 1024 * 256},    {Hardware::L1, 1024 * 1024},
     271              :         {Hardware::L0A, 1024 * 64},  {Hardware::L0B, 1024 * 64},    {Hardware::L0C, 1024 * 256},
     272              :         {Hardware::BIAS, 1024 * 64}, {Hardware::FIXBUF, 1024 * 64},
     273              :     };
     274              : #elif (__NPU_ARCH__ == 2201)
     275              :     const std::map<Hardware, uint32_t> bufferInitLen = {
     276              :         {Hardware::GM, 1024 * 1024}, {Hardware::UB, 1024 * 192},   {Hardware::L1, 1024 * 512},
     277              :         {Hardware::L0A, 1024 * 64},  {Hardware::L0B, 1024 * 64},   {Hardware::L0C, 1024 * 128},
     278              :         {Hardware::BIAS, 1024 * 1},  {Hardware::FIXBUF, 1024 * 7},
     279              :     };
     280              : #elif (__NPU_ARCH__ == 3002)
     281              :     const std::map<Hardware, uint32_t> bufferInitLen = {
     282              :         {Hardware::GM, 1024 * 1024}, {Hardware::UB, 1024 * 256},   {Hardware::L1, 1024 * 1024},
     283              :         {Hardware::L0A, 1024 * 64},  {Hardware::L0B, 1024 * 64},   {Hardware::L0C, 1024 * 128},
     284              :         {Hardware::BIAS, 1024 * 1},  {Hardware::FIXBUF, 1024 * 7},
     285              :     };
     286              : #elif (__NPU_ARCH__ == 3003)
     287              :     const std::map<Hardware, uint32_t> bufferInitLen = {
     288              :         {Hardware::GM, 1024 * 1024}, {Hardware::UB, TOTAL_UB_SIZE}, {Hardware::L1, TOTAL_L1_SIZE},
     289              :         {Hardware::L0A, 1024 * 64},  {Hardware::L0B, 1024 * 64},    {Hardware::L0C, 1024 * 128},
     290              :         {Hardware::BIAS, 1024 * 1},  {Hardware::FIXBUF, 1024 * 6},
     291              :     };
     292              : #elif (__NPU_ARCH__ == 3102)
     293              :     const std::map<Hardware, uint32_t> bufferInitLen = {
     294              :         {Hardware::GM, 1024 * 1024}, {Hardware::UB, 1024 * 256},   {Hardware::L1, 1024 * 1024},
     295              :         {Hardware::L0A, 1024 * 64},  {Hardware::L0B, 1024 * 64},   {Hardware::L0C, 1024 * 128},
     296              :         {Hardware::BIAS, 1024 * 1},  {Hardware::FIXBUF, 1024 * 7},
     297              :     };
     298              : #elif defined(__NPU_ARCH__) && (__NPU_ARCH__ == 2103)
     299              :     const std::map<Hardware, uint32_t> bufferInitLen = {{Hardware::GM, 1024 * 1024}, {Hardware::UB, TOTAL_UB_SIZE}};
     300              : #elif defined(__NPU_ARCH__) && ((__NPU_ARCH__ == 3113))
     301              :     const std::map<Hardware, uint32_t> bufferInitLen = {
     302              :         {Hardware::GM, 1024 * 1024}, {Hardware::UB, TOTAL_UB_SIZE}, {Hardware::L1, TOTAL_L1_SIZE},
     303              :         {Hardware::L0A, 1024 * 32},  {Hardware::L0B, 1024 * 32},    {Hardware::L0C, 1024 * 64},
     304              :         {Hardware::BIAS, 1024 * 1},  {Hardware::FIXBUF, 1024 * 6},
     305              :     };
     306              : #elif defined(__NPU_ARCH__) && (__NPU_ARCH__ == 3103)
     307              :     const std::map<Hardware, uint32_t> bufferInitLen = {
     308              :         {Hardware::GM, 1024 * 1024}, {Hardware::UB, 1024 * 256},   {Hardware::L1, 1024 * 1024},
     309              :         {Hardware::L0A, 1024 * 64},  {Hardware::L0B, 1024 * 64},   {Hardware::L0C, 1024 * 128},
     310              :         {Hardware::BIAS, 1024 * 1},  {Hardware::FIXBUF, 1024 * 7},
     311              :     };
     312              : #endif
     313              :     uint8_t* cpuGM;
     314              :     uint8_t* cpuUB;
     315              :     uint8_t* cpuL1;
     316              :     uint8_t* cpuL0A;
     317              :     uint8_t* cpuL0B;
     318              :     uint8_t* cpuL0C;
     319              :     uint8_t* cpuBIAS;
     320              :     uint8_t* cpuFIXBUF;
     321              : #if defined(__NPU_ARCH__) && ((__NPU_ARCH__ == 3510) || (__NPU_ARCH__ == 5102))
     322              :     uint8_t* cpuSSbuf;
     323              : #endif
     324              :     std::map<Hardware, uint8_t*> hardwareCpuBufferMap;
     325              : 
     326              : private:
     327              :     std::set<Hardware> allocatorUsed;
     328              : #if defined(__NPU_ARCH__) && ((__NPU_ARCH__ == 5102) || (__NPU_ARCH__ == 2103) || (__NPU_ARCH__ == 3003) || \
     329              :                               (__NPU_ARCH__ == 3103) || (__NPU_ARCH__ == 3113) || (__NPU_ARCH__ == 3510))
     330              : 
     331              :     ConstDefiner()
     332              :     {
     333              :         cpuGM = new uint8_t[bufferInitLen.at(Hardware::GM)];
     334              :         cpuL0A = new uint8_t[bufferInitLen.at(Hardware::L0A)];
     335              :         cpuL0B = new uint8_t[bufferInitLen.at(Hardware::L0B)];
     336              :         cpuL0C = new uint8_t[bufferInitLen.at(Hardware::L0C)];
     337              :         cpuBIAS = new uint8_t[bufferInitLen.at(Hardware::BIAS)];
     338              :         cpuFIXBUF = new uint8_t[bufferInitLen.at(Hardware::FIXBUF)];
     339              : #if defined(__NPU_ARCH__) && ((__NPU_ARCH__ == 3510) || (__NPU_ARCH__ == 5102))
     340              :         cpuSSbuf = nullptr;
     341              :         if (g_kernelMode != KernelMode::MIX_MODE) {
     342              :             cpuUB = new uint8_t[bufferInitLen.at(Hardware::UB)];
     343              :             cpuL1 = new uint8_t[bufferInitLen.at(Hardware::L1)];
     344              :         } else {
     345              :             cpuUB = (uint8_t*)GmAlloc(bufferInitLen.at(Hardware::UB) * block_num * g_taskRation);
     346              :             cpuL1 = (uint8_t*)GmAlloc(bufferInitLen.at(Hardware::L1) * block_num);
     347              :             uint32_t aivNum = g_taskRation;
     348              :             uint32_t totalSSbufSize = 1024 * (aivNum + 1);
     349              :             cpuSSbuf = (uint8_t*)GmAlloc(totalSSbufSize * block_num);
     350              :             auto ptr = reinterpret_cast<uint32_t*>(cpuSSbuf);
     351              :             uint32_t msgNum = 8;
     352              :             uint32_t msgMatmulL1AddrSize = 32;
     353              :             uint32_t kfcMsgSize = 128;
     354              :             uint32_t tilingInfoSize = 200;
     355              :             uint32_t kfcSSbufSize = msgNum * aivNum * kfcMsgSize / sizeof(uint32_t);
     356              :             uint32_t l1MsgSize = 16 * msgMatmulL1AddrSize / sizeof(uint32_t); // sizeof(MsgMatmulL1Addr)
     357              :             uint32_t tilingSize = tilingInfoSize / sizeof(uint32_t);          // sizeof(TilingInfo)
     358              :             for (uint32_t i = 0; i < msgNum * aivNum; i++) {
     359              :                 *(ptr + i * kfcMsgSize / sizeof(uint32_t)) = 0;
     360              :                 *(ptr + kfcSSbufSize + i * msgMatmulL1AddrSize / sizeof(uint32_t)) = 0;
     361              :             }
     362              :             *(ptr + kfcSSbufSize + l1MsgSize) = 0;
     363              :             *(ptr + kfcSSbufSize + l1MsgSize + tilingSize) = 0;
     364              :         }
     365              :         cpuL0AMx = new uint8_t[4 * 1024]; // 4k
     366              :         cpuL0BMx = new uint8_t[4 * 1024]; // 4k
     367              : #elif defined(__NPU_ARCH__) && \
     368              :     ((__NPU_ARCH__ == 2103) || (__NPU_ARCH__ == 3003) || (__NPU_ARCH__ == 3103) || (__NPU_ARCH__ == 3113))
     369              :         cpuUB = new uint8_t[bufferInitLen.at(Hardware::UB)];
     370              :         cpuL1 = new uint8_t[bufferInitLen.at(Hardware::L1)];
     371              : #endif
     372              :         hardwareCpuBufferMap = {{Hardware::UB, cpuUB},        {Hardware::L1, cpuL1},   {Hardware::L0A, cpuL0A},
     373              :                                 {Hardware::L0B, cpuL0B},      {Hardware::L0C, cpuL0C}, {Hardware::BIAS, cpuBIAS},
     374              :                                 {Hardware::FIXBUF, cpuFIXBUF}};
     375              :     }
     376              : #else
     377            4 :     ConstDefiner()
     378            4 :         : cpuGM(new uint8_t[bufferInitLen.at(Hardware::GM)]),
     379            4 :           cpuUB(new uint8_t[bufferInitLen.at(Hardware::UB)]),
     380            4 :           cpuL1(new uint8_t[bufferInitLen.at(Hardware::L1)]),
     381            4 :           cpuL0A(new uint8_t[bufferInitLen.at(Hardware::L0A)]),
     382            4 :           cpuL0B(new uint8_t[bufferInitLen.at(Hardware::L0B)]),
     383            4 :           cpuL0C(new uint8_t[bufferInitLen.at(Hardware::L0C)]),
     384            4 :           cpuBIAS(new uint8_t[bufferInitLen.at(Hardware::BIAS)]),
     385            4 :           cpuFIXBUF(new uint8_t[bufferInitLen.at(Hardware::FIXBUF)]),
     386            8 :           hardwareCpuBufferMap({
     387            4 :               {Hardware::UB, cpuUB},
     388            4 :               {Hardware::L1, cpuL1},
     389            4 :               {Hardware::L0A, cpuL0A},
     390            4 :               {Hardware::L0B, cpuL0B},
     391            4 :               {Hardware::L0C, cpuL0C},
     392            4 :               {Hardware::BIAS, cpuBIAS},
     393            8 :               {Hardware::FIXBUF, cpuFIXBUF},
     394          520 :           })
     395            4 :     {}
     396              : #endif
     397            4 :     ~ConstDefiner()
     398           52 :     {
     399            4 :         if (cpuGM != nullptr) {
     400            4 :             delete[] cpuGM;
     401            4 :             cpuGM = nullptr;
     402              :         }
     403            4 :         if (cpuUB != nullptr) {
     404              : #if defined(__NPU_ARCH__) && ((__NPU_ARCH__ == 3510) || (__NPU_ARCH__ == 5102))
     405              :             if (g_kernelMode == KernelMode::MIX_MODE) {
     406              :                 if (g_coreType == AscendC::MIX && block_idx == 0 && sub_block_idx == 0) {
     407              :                     GmFree(cpuUB);
     408              :                 }
     409              :             } else {
     410              :                 delete[] cpuUB;
     411              :             }
     412              : #else
     413            4 :             delete[] cpuUB;
     414              : #endif
     415            4 :             cpuUB = nullptr;
     416              :         }
     417            4 :         if (cpuL1 != nullptr) {
     418              : #if defined(__NPU_ARCH__) && ((__NPU_ARCH__ == 3510) || (__NPU_ARCH__ == 5102))
     419              :             if (g_kernelMode == KernelMode::MIX_MODE) {
     420              :                 if (g_coreType == AscendC::MIX && block_idx == 0 && sub_block_idx == 0) {
     421              :                     GmFree(cpuL1);
     422              :                 }
     423              :             } else {
     424              :                 delete[] cpuL1;
     425              :             }
     426              : #else
     427            4 :             delete[] cpuL1;
     428              : #endif
     429            4 :             cpuL1 = nullptr;
     430              :         }
     431            4 :         if (cpuL0A != nullptr) {
     432            4 :             delete[] cpuL0A;
     433            4 :             cpuL0A = nullptr;
     434              :         }
     435            4 :         if (cpuL0B != nullptr) {
     436            4 :             delete[] cpuL0B;
     437            4 :             cpuL0B = nullptr;
     438              :         }
     439            4 :         if (cpuL0C != nullptr) {
     440            4 :             delete[] cpuL0C;
     441            4 :             cpuL0C = nullptr;
     442              :         }
     443            4 :         if (cpuBIAS != nullptr) {
     444            4 :             delete[] cpuBIAS;
     445            4 :             cpuBIAS = nullptr;
     446              :         }
     447            4 :         if (cpuFIXBUF != nullptr) {
     448            4 :             delete[] cpuFIXBUF;
     449            4 :             cpuFIXBUF = nullptr;
     450              :         }
     451              : #if defined(__NPU_ARCH__) && ((__NPU_ARCH__ == 3510) || (__NPU_ARCH__ == 5102))
     452              :         if (cpuSSbuf != nullptr) {
     453              :             if (g_kernelMode == KernelMode::MIX_MODE) {
     454              :                 if (g_coreType == AscendC::MIX && block_idx == 0 && sub_block_idx == 0) {
     455              :                     GmFree(cpuSSbuf);
     456              :                 }
     457              :             } else {
     458              :                 delete[] cpuSSbuf;
     459              :             }
     460              :             cpuSSbuf = nullptr;
     461              :         }
     462              :         if (cpuL0AMx != nullptr) {
     463              :             delete[] cpuL0AMx;
     464              :             cpuL0AMx = nullptr;
     465              :         }
     466              :         if (cpuL0B != nullptr) {
     467              :             delete[] cpuL0BMx;
     468              :             cpuL0BMx = nullptr;
     469              :         }
     470              : #endif
     471            4 :     }
     472              : };
     473              : 
     474          168 : inline std::string GetPositionDisplay(Hardware hardPos, const std::string& logicName)
     475              : {
     476          168 :     if (hardPos == Hardware::GM && logicName == "GM") {
     477            0 :         return "GM";
     478              :     }
     479              : 
     480          168 :     const char* hardName = "UNKNOWN";
     481          168 :     switch (hardPos) {
     482            0 :         case Hardware::GM:
     483            0 :             hardName = "GM";
     484            0 :             break;
     485           80 :         case Hardware::UB:
     486           80 :             hardName = "UB";
     487           80 :             break;
     488           80 :         case Hardware::L1:
     489           80 :             hardName = "L1 Buffer";
     490           80 :             break;
     491            4 :         case Hardware::L0A:
     492            4 :             hardName = "L0A Buffer";
     493            4 :             break;
     494            0 :         case Hardware::L0B:
     495            0 :             hardName = "L0B Buffer";
     496            0 :             break;
     497            4 :         case Hardware::L0C:
     498            4 :             hardName = "L0C Buffer";
     499            4 :             break;
     500            0 :         case Hardware::BIAS:
     501            0 :             hardName = "BiasTable Buffer";
     502            0 :             break;
     503            0 :         case Hardware::FIXBUF:
     504            0 :             hardName = "Fixpipe Buffer";
     505            0 :             break;
     506            0 :         default:
     507            0 :             break;
     508              :     }
     509          336 :     return std::string(hardName) + "(" + logicName + ")";
     510              : }
     511              : 
     512           84 : inline std::string GetPositionDisplay(TPosition pos)
     513              : {
     514           84 :     const auto& definer = ConstDefiner::Instance();
     515           84 :     const auto hardPos = definer.positionHardMap.find(pos);
     516           84 :     const Hardware hardware = hardPos == definer.positionHardMap.end() ? GetPhyType(pos) : hardPos->second;
     517           84 :     return GetPositionDisplay(hardware, definer.logicNameMap.at(static_cast<uint8_t>(pos)));
     518              : }
     519              : #endif
     520              : 
     521              : } // namespace AscendC
     522              : #endif // ASCENDC_MODULE_UTILS_MODE_H
        

Generated by: LCOV version 2.0-1