LCOV - code coverage report
Current view: top level - ut/activation/ge_glu_grad_v2/op_host - ge_glu_grad_v2_tiling.cpp Coverage Total Hit
Test: CHG Lines: 100.0 % 1 1
Test Date: 2026-08-26 12:09:40
Legend: Lines: hit not hit

            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 ge_glu_grad_v2_tiling.cpp
      13              :  * \brief
      14              :  */
      15              : #include <map>
      16              : #include "register/tilingdata_base.h"
      17              : #include "register/op_impl_registry.h"
      18              : #include "log/log.h"
      19              : #include "util/math_util.h"
      20              : #include "ge_glu_grad_v2_tiling.h"
      21              : #include "op_host/tiling_util.h"
      22              : 
      23              : namespace optiling {
      24              : using namespace Ops::NN::OpTiling;
      25              : 
      26              : constexpr char NODE_NAME[] = "GeGluGradV2";
      27              : 
      28              : constexpr uint32_t DY_INDEX = 0;
      29              : constexpr uint32_t X_INDEX = 1;
      30              : constexpr uint32_t GELU_INDEX = 2;
      31              : constexpr uint32_t DX_INDEX = 0;
      32              : 
      33              : constexpr uint32_t DIM_ATTR_INDEX = 0;
      34              : constexpr uint32_t APPROXIMATE_ATTR_INDEX = 1;
      35              : constexpr uint32_t ACTIVATE_LEFT_ATTR_INDEX = 2;
      36              : 
      37              : constexpr uint32_t BATCH_MODE = 1;
      38              : 
      39              : /* Tanh */
      40              : constexpr int32_t TANH_BUF_CNT_FP16 = 5 * 2 + 6;
      41              : constexpr int32_t TANH_BUF_CNT_BFP16 = 7 * 2 + 4;
      42              : constexpr int32_t TANH_BUF_CNT_FP32 = 11;
      43              : 
      44              : constexpr int32_t TANH_BUF_CNT_FP16_950 = 5 * 2 + 6 * 2;
      45              : constexpr int32_t TANH_BUF_CNT_BFP16_950 = 5 * 2 + 2 * 2 * 2 + 4 * 2;
      46              : constexpr int32_t TANH_BUF_CNT_FP32_950 = 5 + 6 * 2;
      47              : 
      48              : /* Erf */
      49              : constexpr int32_t ERF_BUF_CNT_FP16 = 5 * 2 + 6;
      50              : constexpr int32_t ERF_BUF_CNT_BFP16 = 7 * 2 + 4;
      51              : constexpr int32_t ERF_BUF_CNT_FP32 = 11;
      52              : 
      53              : constexpr int32_t ERF_BUF_CNT_FP16_950 = 3 * 2 + 20;  // 转fp32,调用Ascendc erf接口,3*fp32的buf保留
      54              : constexpr int32_t ERF_BUF_CNT_BFP16_950 = 3 * 2 + 20; // 转fp32,调用Ascendc erf接口,3*fp32的buf保留
      55              : constexpr int32_t ERF_BUF_CNT_FP32_950 = 3 + 16;      // 调用Ascendc erf接口,3*fp32的buf保留
      56              : 
      57              : constexpr int32_t BLOCK_SIZE = 32;
      58              : constexpr int32_t TRANSPOSE_REPEAT_SIZE = 512;
      59              : constexpr int32_t WORK_SPACE_SIZE = 16 * 1024 * 1024;
      60              : constexpr int32_t REGBASE_CCEC_RESERVE_SIZE = 8 * 1024;
      61              : constexpr int32_t DOUBLE_BUFFER = 2;
      62              : constexpr int32_t NUM_ONE = 1;
      63              : constexpr int32_t NUM_TWO = 2;
      64              : constexpr int32_t NUM_HUNDRED = 100;
      65              : 
      66              : static const std::map<ge::DataType, int32_t> DTYPE_BUF_CNT_MAP_TANH = {
      67              :     {ge::DT_BF16, TANH_BUF_CNT_BFP16}, {ge::DT_FLOAT16, TANH_BUF_CNT_FP16}, {ge::DT_FLOAT, TANH_BUF_CNT_FP32}};
      68              : static const std::map<ge::DataType, int32_t> DTYPE_BUF_CNT_MAP_TANH_950 = {{ge::DT_BF16, TANH_BUF_CNT_BFP16_950},
      69              :                                                                            {ge::DT_FLOAT16, TANH_BUF_CNT_FP16_950},
      70              :                                                                            {ge::DT_FLOAT, TANH_BUF_CNT_FP32_950}};
      71              : 
      72              : static const std::map<ge::DataType, int32_t> DTYPE_BUF_CNT_MAP_ERF = {
      73              :     {ge::DT_BF16, ERF_BUF_CNT_BFP16}, {ge::DT_FLOAT16, ERF_BUF_CNT_FP16}, {ge::DT_FLOAT, ERF_BUF_CNT_FP32}};
      74              : static const std::map<ge::DataType, int32_t> DTYPE_BUF_CNT_MAP_ERF_950 = {
      75              :     {ge::DT_BF16, ERF_BUF_CNT_BFP16_950}, {ge::DT_FLOAT16, ERF_BUF_CNT_FP16_950}, {ge::DT_FLOAT, ERF_BUF_CNT_FP32_950}};
      76              : 
      77              : class GeGluGradV2Tiling {
      78              : public:
      79           15 :     explicit GeGluGradV2Tiling(gert::TilingContext* context) : tilingContext(context) {};
      80              :     ge::graphStatus RunTiling4GeGluGradV2();
      81              : 
      82              : private:
      83              :     ge::graphStatus Init();
      84              :     ge::graphStatus CheckParams();
      85              :     void FillTilingData();
      86              : 
      87              :     template <typename T1, typename T2>
      88              :     inline auto AlignA2B(T1 a, T2 b) const -> T1
      89              :     {
      90              :         a = int64_t(a);
      91              :         b = int64_t(b);
      92              :         return T1(b == 0 ? a : (a / b) * b);
      93              :     };
      94              : 
      95              :     void CalcValueNM();
      96              :     ge::graphStatus CaclMaxProcessCount();
      97              :     void ProcessTilingCore();
      98              : 
      99              : private:
     100              :     GeGluGradV2TilingData tilingData;
     101              :     GeGluGradV2TilingKey tilingKey = GeGluGradV2TilingKey::TILING_KEY_TANH_101;
     102              :     gert::TilingContext* tilingContext = nullptr;
     103              :     const GeGluGradV2CompileInfo* ptrCompileInfo = nullptr;
     104              : 
     105              :     // input output infos
     106              :     gert::Shape dyShape;
     107              :     gert::Shape xShape;
     108              :     gert::Shape geluShape;
     109              :     gert::Shape dxShape;
     110              :     int64_t dimAttr = -1L;
     111              :     int64_t approximateAttr = 1;
     112              :     bool activateLeftAttr = false;
     113              : 
     114              :     /**
     115              :      * The meanings of valueN and valueM are as follows:
     116              :      * Shape(A, B, C) of input x, dim=1 ==> valueN=A, valueM=B*C//2
     117              :      * Shape(A, B, C) of input x, dim=-1 ==> valueN=A*B, valueM=C//2
     118              :      * Shape(A, B, C, D) of input x, dim=2 ==> valueN=A*B, valueM=C*D//2
     119              :      */
     120              :     int64_t valueN = 1;
     121              :     int64_t valueM = 1;
     122              :     ge::DataType dyDtype = ge::DT_UNDEFINED;
     123              :     int32_t dtypeSize = 0;
     124              : 
     125              :     // tiling params
     126              :     int64_t maxProcCount = 0;
     127              :     int32_t needCoreNum = 0;
     128              :     int64_t loopNumPerCore = 0;
     129              :     int64_t tailCoreIndex = 0;
     130              :     int64_t tailUbLoopNum = 0;
     131              :     int64_t groupNum = 0;
     132              :     uint64_t ubSizePlatForm_ = 0;
     133              : };
     134              : 
     135              : ge::graphStatus GeGluGradV2Tiling::RunTiling4GeGluGradV2()
     136              : {
     137              :     ptrCompileInfo = tilingContext->GetCompileInfo<GeGluGradV2CompileInfo>();
     138              :     OP_CHECK_NULL_WITH_CONTEXT(tilingContext, ptrCompileInfo);
     139              :     ubSizePlatForm_ = ptrCompileInfo->ubSizePlatForm;
     140              : 
     141              :     OP_CHECK_IF(Init() != ge::GRAPH_SUCCESS, OP_LOGE(NODE_NAME, "Init failed."), return ge::GRAPH_FAILED);
     142              :     OP_CHECK_IF(CheckParams() != ge::GRAPH_SUCCESS, OP_LOGE(NODE_NAME, "CheckParams failed."), return ge::GRAPH_FAILED);
     143              :     CalcValueNM();
     144              :     OP_LOGD(NODE_NAME, "Platform info, ubSizePlatForm:%lu, totalCoreNum:%d, curSocVersion:%u.", ubSizePlatForm_,
     145              :             ptrCompileInfo->totalCoreNum, static_cast<int32_t>(ptrCompileInfo->curSocVersion));
     146              :     OP_CHECK_IF(CaclMaxProcessCount() != ge::GRAPH_SUCCESS, OP_LOGE(NODE_NAME, "CaclMaxProcessCount failed."),
     147              :                 return ge::GRAPH_FAILED);
     148              : 
     149              :     ProcessTilingCore();
     150              : 
     151              :     tilingContext->SetBlockDim(needCoreNum);
     152              :     tilingContext->SetTilingKey(static_cast<uint64_t>(tilingKey));
     153              :     FillTilingData();
     154              :     size_t* workspaces = tilingContext->GetWorkspaceSizes(1);
     155              :     OP_CHECK_NULL_WITH_CONTEXT(tilingContext, workspaces);
     156              :     workspaces[0] = static_cast<size_t>(WORK_SPACE_SIZE + ptrCompileInfo->totalCoreNum * BLOCK_SIZE);
     157              :     return ge::GRAPH_SUCCESS;
     158              : }
     159              : 
     160              : ge::graphStatus GeGluGradV2Tiling::Init()
     161              : {
     162              :     auto inputDy = tilingContext->GetInputTensor(DY_INDEX);
     163              :     OP_CHECK_NULL_WITH_CONTEXT(tilingContext, inputDy);
     164              :     dyShape = inputDy->GetStorageShape();
     165              :     dyDtype = tilingContext->GetInputDesc(DY_INDEX)->GetDataType();
     166              : 
     167              :     auto inputX = tilingContext->GetInputTensor(X_INDEX);
     168              :     OP_CHECK_NULL_WITH_CONTEXT(tilingContext, inputX);
     169              :     xShape = inputX->GetStorageShape();
     170              : 
     171              :     auto inputYgelu = tilingContext->GetInputTensor(GELU_INDEX);
     172              :     OP_CHECK_NULL_WITH_CONTEXT(tilingContext, inputYgelu);
     173              :     geluShape = inputYgelu->GetStorageShape();
     174              : 
     175              :     auto outputDx = tilingContext->GetOutputShape(DX_INDEX);
     176              :     OP_CHECK_NULL_WITH_CONTEXT(tilingContext, outputDx);
     177              :     dxShape = outputDx->GetStorageShape();
     178              : 
     179              :     auto attrs = tilingContext->GetAttrs();
     180              :     OP_CHECK_NULL_WITH_CONTEXT(tilingContext, attrs);
     181              :     const int64_t* ptrDim = attrs->GetAttrPointer<int64_t>(DIM_ATTR_INDEX);
     182              :     OP_CHECK_NULL_WITH_CONTEXT(tilingContext, ptrDim);
     183              :     dimAttr = *ptrDim;
     184              :     const int64_t* ptrApproximate = attrs->GetAttrPointer<int64_t>(APPROXIMATE_ATTR_INDEX);
     185              :     // 310P donot support bfloat16 and erf mode
     186              :     const bool is310p = ptrCompileInfo->curSocVersion == NpuArch::DAV_2002;
     187              :     OP_CHECK_NULL_WITH_CONTEXT(tilingContext, ptrApproximate);
     188              :     approximateAttr = *ptrApproximate;
     189              :     OP_CHECK_IF(approximateAttr == 0 && is310p,
     190              :                 OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(tilingContext->GetNodeName(), "approximate",
     191              :                                                       std::to_string(approximateAttr),
     192              :                                                       "If the platform is 310P, parameter approximate must be 1(Tanh)"),
     193              :                 return ge::GRAPH_FAILED);
     194              :     const bool* ptrActivateLeft = attrs->GetAttrPointer<bool>(ACTIVATE_LEFT_ATTR_INDEX);
     195              :     OP_CHECK_NULL_WITH_CONTEXT(tilingContext, ptrActivateLeft);
     196              :     activateLeftAttr = *ptrActivateLeft;
     197              : 
     198              :     OP_LOGD(NODE_NAME, "Attr info: dimAttr: %ld, approximateAttr: %ld, activateLeftAttr: %s, dyDtype: %d.", dimAttr,
     199              :             approximateAttr, activateLeftAttr ? "true" : "false", static_cast<int32_t>(dyDtype));
     200              : 
     201              :     return ge::GRAPH_SUCCESS;
     202              : }
     203              : 
     204              : ge::graphStatus GeGluGradV2Tiling::CheckParams()
     205              : {
     206              :     OP_CHECK_IF(dyDtype != ge::DT_BF16 && dyDtype != ge::DT_FLOAT16 && dyDtype != ge::DT_FLOAT,
     207              :                 OP_LOGE_FOR_INVALID_DTYPE_WITH_REASON(tilingContext->GetNodeName(), "dy",
     208              :                                                       ge::TypeUtils::DataTypeToSerialString(dyDtype),
     209              :                                                       "The dtype of dy must be DT_FLOAT16, DT_BF16, or DT_FLOAT"),
     210              :                 return ge::GRAPH_FAILED);
     211              : 
     212              :     // 310P donot support bfloat16 and erf mode
     213              :     const bool is310p = ptrCompileInfo->curSocVersion == NpuArch::DAV_2002;
     214              :     OP_CHECK_IF(dyDtype == ge::DT_BF16 && is310p,
     215              :                 OP_LOGE_FOR_INVALID_DTYPE_WITH_REASON(tilingContext->GetNodeName(), "dy",
     216              :                                                       ge::TypeUtils::DataTypeToSerialString(dyDtype),
     217              :                                                       "The dtype of dy must not be DT_BF16 on 310P"),
     218              :                 return ge::GRAPH_FAILED);
     219              :     dtypeSize = ge::GetSizeByDataType(dyDtype);
     220              :     OP_CHECK_IF(dtypeSize <= 0,
     221              :                 OP_LOGE_FOR_INVALID_DTYPE_WITH_REASON(tilingContext->GetNodeName(), "dy",
     222              :                                                       ge::TypeUtils::DataTypeToSerialString(dyDtype),
     223              :                                                       "The dtype of dy must be DT_FLOAT16, DT_BF16, or DT_FLOAT"),
     224              :                 return ge::GRAPH_FAILED);
     225              : 
     226              :     auto xDtype = tilingContext->GetInputDesc(X_INDEX)->GetDataType();
     227              :     auto geluDtype = tilingContext->GetInputDesc(GELU_INDEX)->GetDataType();
     228              :     auto dxDtype = tilingContext->GetInputDesc(DX_INDEX)->GetDataType();
     229              :     OP_CHECK_IF(dyDtype != geluDtype || xDtype != dxDtype || dyDtype != xDtype,
     230              :                 OP_LOGE_FOR_INVALID_DTYPES_WITH_REASON(tilingContext->GetNodeName(), "dy, x, gelu, dx",
     231              :                                                        ge::TypeUtils::DataTypeToSerialString(dyDtype) + ", " +
     232              :                                                            ge::TypeUtils::DataTypeToSerialString(xDtype) + ", " +
     233              :                                                            ge::TypeUtils::DataTypeToSerialString(geluDtype) + ", " +
     234              :                                                            ge::TypeUtils::DataTypeToSerialString(dxDtype),
     235              :                                                        "The dtypes of dy, x, gelu, and dx must be the same"),
     236              :                 return ge::GRAPH_FAILED);
     237              : 
     238              :     size_t xDimNum = xShape.GetDimNum();
     239              :     dimAttr = dimAttr < 0 ? static_cast<int64_t>(xDimNum) + dimAttr : dimAttr;
     240              :     if (dimAttr < 0 || dimAttr >= static_cast<int64_t>(xDimNum)) {
     241              :         OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(
     242              :             tilingContext->GetNodeName(), "dim", std::to_string(dimAttr),
     243              :             "The value of dim must be in the range [0, " + std::to_string(xDimNum) + ")");
     244              :         return ge::GRAPH_FAILED;
     245              :     }
     246              : 
     247              :     size_t dyDimNum = dyShape.GetDimNum();
     248              :     size_t geluDimNum = geluShape.GetDimNum();
     249              :     OP_CHECK_IF(dyDimNum != xDimNum || geluDimNum != xDimNum,
     250              :                 OP_LOGE_FOR_INVALID_SHAPEDIMS_WITH_REASON(
     251              :                     tilingContext->GetNodeName(), "dy, x, gelu",
     252              :                     std::to_string(dyDimNum) + ", " + std::to_string(xDimNum) + ", " + std::to_string(geluDimNum),
     253              :                     "The shape dims of dy, x, and gelu must be the same"),
     254              :                 return ge::GRAPH_FAILED);
     255              : 
     256              :     int64_t xShapeSize = xShape.GetShapeSize();
     257              :     OP_CHECK_IF(xShapeSize == 0,
     258              :                 OP_LOGE_FOR_INVALID_SHAPESIZE_WITH_REASON(tilingContext->GetNodeName(), "x", "0",
     259              :                                                           "x does not support empty tensor"),
     260              :                 return ge::GRAPH_FAILED);
     261              : 
     262              :     gert::Shape tempShape = dyShape;
     263              :     tempShape.SetDim(dimAttr, NUM_TWO * dyShape.GetDim(dimAttr));
     264              :     if (dyShape != geluShape || xShape != dxShape || tempShape != xShape) {
     265              :         OP_LOGE_FOR_INVALID_SHAPES_WITH_REASON(tilingContext->GetNodeName(), "dy, gelu, x, dx",
     266              :                                                Ops::Base::ToString(dyShape) + ", " + Ops::Base::ToString(geluShape) +
     267              :                                                    ", " + Ops::Base::ToString(xShape) + ", " +
     268              :                                                    Ops::Base::ToString(dxShape),
     269              :                                                "These parameters must meet the following conditions:the shapes of dy, "
     270              :                                                "gelu, x, and dx must satisfy the operator constraint");
     271              :         return ge::GRAPH_FAILED;
     272              :     }
     273              : 
     274              :     return ge::GRAPH_SUCCESS;
     275              : }
     276              : 
     277              : void GeGluGradV2Tiling::FillTilingData()
     278              : {
     279              :     tilingData.set_approximate(static_cast<int32_t>(approximateAttr));
     280              :     tilingData.set_activateLeft(static_cast<int32_t>(activateLeftAttr));
     281              :     tilingData.set_maxProcCount(maxProcCount);
     282              :     tilingData.set_valueN(valueN);
     283              :     tilingData.set_valueM(valueM);
     284              :     tilingData.set_needCoreNum(needCoreNum);
     285              :     tilingData.set_loopNumPerCore(loopNumPerCore);
     286              :     tilingData.set_tailCoreIndex(tailCoreIndex);
     287              :     tilingData.set_tailUbLoopNum(tailUbLoopNum);
     288              :     tilingData.set_groupNum(groupNum);
     289              : 
     290              :     tilingData.SaveToBuffer(tilingContext->GetRawTilingData()->GetData(),
     291              :                             tilingContext->GetRawTilingData()->GetCapacity());
     292              :     tilingContext->GetRawTilingData()->SetDataSize(tilingData.GetDataSize());
     293              :     OP_LOGD(NODE_NAME,
     294              :             "Tiling data is maxProcCount:%ld, valueN:%ld, valueM:%ld, needCoreNum:%ld, loopNumPerCore:%ld, "
     295              :             "tailCoreIndex:%ld, tailUbLoopNum:%ld, groupNum:%ld, tilingKey:%lu.",
     296              :             tilingData.get_maxProcCount(), tilingData.get_valueN(), tilingData.get_valueM(),
     297              :             tilingData.get_needCoreNum(), tilingData.get_loopNumPerCore(), tilingData.get_tailCoreIndex(),
     298              :             tilingData.get_tailUbLoopNum(), tilingData.get_groupNum(), static_cast<uint64_t>(tilingKey));
     299              : }
     300              : 
     301              : void GeGluGradV2Tiling::CalcValueNM()
     302              : {
     303              :     for (int64_t i = 0; i < dimAttr; ++i) {
     304              :         valueN *= dyShape.GetDim(i);
     305              :     }
     306              :     for (int64_t i = dimAttr; i < int64_t(dyShape.GetDimNum()); ++i) {
     307              :         valueM *= dyShape.GetDim(i);
     308              :     }
     309              : }
     310              : 
     311              : ge::graphStatus GeGluGradV2Tiling::CaclMaxProcessCount()
     312              : {
     313              :     if (approximateAttr == NUM_ONE) {
     314              :         const auto iter = ptrCompileInfo->isRegbase ? DTYPE_BUF_CNT_MAP_TANH_950.find(dyDtype) :
     315              :                                                       DTYPE_BUF_CNT_MAP_TANH.find(dyDtype);
     316              :         maxProcCount = AlignA2B(ubSizePlatForm_ / iter->second, BLOCK_SIZE) / dtypeSize;
     317              :         tilingKey = GeGluGradV2TilingKey::TILING_KEY_TANH_101;
     318              :     } else {
     319              :         const auto iter = ptrCompileInfo->isRegbase ? DTYPE_BUF_CNT_MAP_ERF_950.find(dyDtype) :
     320              :                                                       DTYPE_BUF_CNT_MAP_ERF.find(dyDtype);
     321              :         maxProcCount = AlignA2B(ubSizePlatForm_ / iter->second, BLOCK_SIZE) / dtypeSize;
     322              :         tilingKey = GeGluGradV2TilingKey::TILING_KEY_ERF_701;
     323              :     }
     324              : 
     325              :     if (dyDtype == ge::DT_FLOAT16) {
     326              :         tilingKey = static_cast<GeGluGradV2TilingKey>(static_cast<int32_t>(tilingKey) + NUM_HUNDRED);
     327              :     } else if (dyDtype == ge::DT_FLOAT) {
     328              :         tilingKey = static_cast<GeGluGradV2TilingKey>(static_cast<int32_t>(tilingKey) + NUM_TWO * NUM_HUNDRED);
     329              :     }
     330              : 
     331              :     return ge::GRAPH_SUCCESS;
     332              : }
     333              : 
     334              : void GeGluGradV2Tiling::ProcessTilingCore()
     335              : {
     336              :     int64_t ubLoopNum = 0;
     337              :     int64_t repeatDataCount = static_cast<int64_t>(TRANSPOSE_REPEAT_SIZE / dtypeSize);
     338              :     int64_t maxPerfCount = maxProcCount / repeatDataCount;
     339              :     if ((ptrCompileInfo->curSocVersion == NpuArch::DAV_2201 || ptrCompileInfo->isRegbase) && valueM <= maxPerfCount) {
     340              :         tilingKey = static_cast<GeGluGradV2TilingKey>(static_cast<int32_t>(tilingKey) + NUM_TWO);
     341              :         groupNum = AlignA2B(maxProcCount / valueM, repeatDataCount);
     342              :         ubLoopNum = Ops::Base::CeilDiv(valueN, groupNum);
     343              :         tailUbLoopNum = groupNum == 0 ? valueN : valueN % groupNum;
     344              :     } else if (valueM <= maxProcCount) {
     345              :         int64_t alignValueM = Ops::Base::CeilDiv(valueM, static_cast<int64_t>((BLOCK_SIZE / dtypeSize))) *
     346              :                               (BLOCK_SIZE / dtypeSize);
     347              :         groupNum = maxProcCount / alignValueM;
     348              :         ubLoopNum = Ops::Base::CeilDiv(valueN, groupNum);
     349              :         tailUbLoopNum = groupNum == 0 ? valueN : valueN % groupNum;
     350              :     } else {
     351              :         groupNum = Ops::Base::CeilDiv(valueM, maxProcCount);
     352              :         ubLoopNum = valueN * groupNum;
     353              :         tilingKey = static_cast<GeGluGradV2TilingKey>(static_cast<int32_t>(tilingKey) + NUM_ONE);
     354              :     }
     355              : 
     356              :     needCoreNum = ubLoopNum < ptrCompileInfo->totalCoreNum ? ubLoopNum : ptrCompileInfo->totalCoreNum;
     357              :     if (needCoreNum < ptrCompileInfo->totalCoreNum) {
     358              :         loopNumPerCore = 0;
     359              :         tailCoreIndex = tailUbLoopNum != 0 ? needCoreNum - 1 : needCoreNum;
     360              :     } else {
     361              :         loopNumPerCore = ubLoopNum / ptrCompileInfo->totalCoreNum;
     362              :         int64_t modValue = ubLoopNum % ptrCompileInfo->totalCoreNum;
     363              :         if (modValue != 0) {
     364              :             tailCoreIndex = tailUbLoopNum != 0 ? modValue - 1 : modValue;
     365              :         } else {
     366              :             loopNumPerCore -= 1;
     367              :             tailCoreIndex = tailUbLoopNum != 0 ? ptrCompileInfo->totalCoreNum - 1 : ptrCompileInfo->totalCoreNum;
     368              :         }
     369              :     }
     370              : }
     371              : 
     372              : ge::graphStatus Tiling4GeGluGradV2(gert::TilingContext* context)
     373              : {
     374              :     context->SetScheduleMode(BATCH_MODE);
     375              :     GeGluGradV2Tiling tilingObject(context);
     376              :     OP_CHECK_IF(tilingObject.RunTiling4GeGluGradV2() != ge::GRAPH_SUCCESS,
     377              :                 OP_LOGE(context->GetNodeName(), "RunTiling4GeGluGradV2 failed."), return ge::GRAPH_FAILED);
     378              :     return ge::GRAPH_SUCCESS;
     379              : }
     380              : 
     381              : ge::graphStatus TilingPrepare4GeGluGradV2(gert::TilingParseContext* context)
     382              : {
     383              :     auto compileInfo = context->GetCompiledInfo<GeGluGradV2CompileInfo>();
     384              :     OP_CHECK_NULL_WITH_CONTEXT(context, compileInfo);
     385              :     auto platformInfo = context->GetPlatformInfo();
     386              :     OP_CHECK_NULL_WITH_CONTEXT(context, platformInfo);
     387              :     auto ascendcPlatform = platform_ascendc::PlatformAscendC(platformInfo);
     388              :     compileInfo->totalCoreNum = ascendcPlatform.GetCoreNumAiv();
     389              :     OP_CHECK_IF((compileInfo->totalCoreNum <= 0), OP_LOGE(NODE_NAME, "TilingPrepare4GeGluGradV2 get core num failed."),
     390              :                 return ge::GRAPH_FAILED);
     391              : 
     392              :     uint64_t ubSizePlatForm;
     393              :     ascendcPlatform.GetCoreMemSize(platform_ascendc::CoreMemType::UB, ubSizePlatForm);
     394              :     compileInfo->ubSizePlatForm = static_cast<int64_t>(ubSizePlatForm);
     395              :     OP_CHECK_IF((compileInfo->ubSizePlatForm <= 0), OP_LOGE(NODE_NAME, "TilingPrepare4GeGluGradV2 get ub size failed."),
     396              :                 return ge::GRAPH_FAILED);
     397              : 
     398              :     compileInfo->curSocVersion = ascendcPlatform.GetCurNpuArch();
     399              :     compileInfo->isRegbase = IsRegbaseSocVersion(context);
     400              : 
     401              :     return ge::GRAPH_SUCCESS;
     402              : }
     403              : 
     404              : IMPL_OP_OPTILING(GeGluGradV2).Tiling(Tiling4GeGluGradV2).TilingParse<GeGluGradV2CompileInfo>(TilingPrepare4GeGluGradV2);
     405              : 
     406              : } // namespace optiling
        

Generated by: LCOV version 2.0-1