LCOV - code coverage report
Current view: top level - ut/activation/relu/op_host/arch35 - relu_tiling_arch35.cpp Coverage Total Hit
Test: CHG Lines: 100.0 % 1 1
Test Date: 2026-08-26 16:41:30
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 relu_tiling_arch35.cpp
      13              :  * \brief
      14              :  */
      15              : #include "relu_tiling_arch35.h"
      16              : #include <iostream>
      17              : #include <graph/utils/type_utils.h>
      18              : #include "tiling/platform/platform_ascendc.h"
      19              : #include "register/op_impl_registry.h"
      20              : #include "log/log.h"
      21              : #include "register/tilingdata_base.h"
      22              : #include "activation/relu/op_kernel/arch35/relu_dag.h"
      23              : #include "atvoss/elewise/elewise_base_struct.h"
      24              : 
      25              : namespace optiling {
      26              : using namespace ge;
      27              : using namespace Ops::Base;
      28              : 
      29              : constexpr uint64_t SYS_WORKSPACE = 16777216; // 16M
      30              : constexpr uint64_t RELU_TILING_KEY_ELEMENTWISE_FP16 = 101;
      31              : constexpr uint64_t RELU_TILING_KEY_ELEMENTWISE_BF16 = 102;
      32              : constexpr uint64_t RELU_TILING_KEY_ELEMENTWISE_FP32 = 103;
      33              : constexpr uint64_t RELU_TILING_KEY_ELEMENTWISE_INT8 = 104;
      34              : constexpr uint64_t RELU_TILING_KEY_ELEMENTWISE_INT32 = 105;
      35              : constexpr uint64_t RELU_TILING_KEY_ELEMENTWISE_INT64 = 106;
      36              : 
      37              : ge::graphStatus ReluTiling::CalcOutputDtype()
      38              : {
      39              :     auto inputDesc = tilingContext->GetInputDesc(0);
      40              :     OP_CHECK_NULL_WITH_CONTEXT(tilingContext, inputDesc);
      41              :     ge::DataType inputDtype = inputDesc->GetDataType();
      42              : 
      43              :     auto outputDesc = tilingContext->GetOutputDesc(0);
      44              :     OP_CHECK_NULL_WITH_CONTEXT(tilingContext, outputDesc);
      45              :     this->outputDtype = outputDesc->GetDataType();
      46              : 
      47              :     OP_CHECK_IF(inputDtype != this->outputDtype,
      48              :                 OP_LOGE_FOR_INVALID_DTYPES_WITH_REASON(tilingContext->GetNodeName(), "x, y",
      49              :                                                        ge::TypeUtils::DataTypeToSerialString(inputDtype) + ", " +
      50              :                                                            ge::TypeUtils::DataTypeToSerialString(this->outputDtype),
      51              :                                                        "The dtypes of x and y must be the same"),
      52              :                 return ge::GRAPH_FAILED);
      53              :     return ge::GRAPH_SUCCESS;
      54              : }
      55              : 
      56              : ge::graphStatus ReluTiling::RunTiling()
      57              : {
      58              :     auto tiling = tilingContext->GetTilingData<Ops::Base::EleBaseTilingData16B>();
      59              :     ElewiseBaseTiling elewiseBaseTiling(tilingContext);
      60              :     OP_CHECK_IF(CalcOutputDtype() == ge::GRAPH_FAILED, OP_LOGE(tilingContext, "get output dtype failed"),
      61              :                 return ge::GRAPH_FAILED);
      62              :     ge::graphStatus res = ge::GRAPH_FAILED;
      63              :     if (this->outputDtype == ge::DT_FLOAT16) {
      64              :         res = elewiseBaseTiling.DoTiling<ReluOp::GraphRelu<half, half>::OpDag>(*tiling);
      65              :     } else if (this->outputDtype == ge::DT_FLOAT) {
      66              :         res = elewiseBaseTiling.DoTiling<ReluOp::GraphRelu<float, float>::OpDag>(*tiling);
      67              :     } else if (this->outputDtype == ge::DT_BF16) {
      68              :         res = elewiseBaseTiling.DoTiling<ReluOp::GraphRelu<half, float>::OpDag>(*tiling);
      69              :     } else if (this->outputDtype == ge::DT_INT8) {
      70              :         res = elewiseBaseTiling.DoTiling<ReluOp::GraphRelu<int8_t, half>::OpDag>(*tiling);
      71              :     } else if (this->outputDtype == ge::DT_INT32) {
      72              :         res = elewiseBaseTiling.DoTiling<ReluOp::GraphRelu<int32_t, int32_t>::OpDag>(*tiling);
      73              :     } else if (this->outputDtype == ge::DT_INT64) {
      74              :         res = elewiseBaseTiling.DoTiling<ReluOp::GraphReluMax<int64_t>::OpDag>(*tiling);
      75              :     } else {
      76              :         OP_LOGE_FOR_INVALID_DTYPE(tilingContext->GetNodeName(), "y",
      77              :                                   ge::TypeUtils::DataTypeToSerialString(this->outputDtype),
      78              :                                   "DT_FLOAT16, DT_BF16, DT_FLOAT, DT_INT8, DT_INT32, DT_INT64");
      79              :         return ge::GRAPH_FAILED;
      80              :     }
      81              : 
      82           10 :     OP_CHECK_IF(res == ge::GRAPH_FAILED,
      83              :                 OP_LOGE(tilingContext->GetNodeName(), "DoTiling failed, output dtype: %s.",
      84              :                         ge::TypeUtils::DataTypeToSerialString(this->outputDtype).c_str()),
      85              :                 return ge::GRAPH_FAILED);
      86              : 
      87              :     size_t* currentWorkspace = tilingContext->GetWorkspaceSizes(1);
      88              :     OP_CHECK_NULL_WITH_CONTEXT(tilingContext, currentWorkspace);
      89              :     currentWorkspace[0] = SYS_WORKSPACE;
      90              :     if (this->outputDtype == ge::DT_FLOAT16) {
      91              :         tilingContext->SetTilingKey(RELU_TILING_KEY_ELEMENTWISE_FP16);
      92              :     } else if (this->outputDtype == ge::DT_BF16) {
      93              :         tilingContext->SetTilingKey(RELU_TILING_KEY_ELEMENTWISE_BF16);
      94              :     } else if (this->outputDtype == ge::DT_FLOAT) {
      95              :         tilingContext->SetTilingKey(RELU_TILING_KEY_ELEMENTWISE_FP32);
      96              :     } else if (this->outputDtype == ge::DT_INT8) {
      97              :         tilingContext->SetTilingKey(RELU_TILING_KEY_ELEMENTWISE_INT8);
      98              :     } else if (this->outputDtype == ge::DT_INT32) {
      99              :         tilingContext->SetTilingKey(RELU_TILING_KEY_ELEMENTWISE_INT32);
     100              :     } else if (this->outputDtype == ge::DT_INT64) {
     101              :         tilingContext->SetTilingKey(RELU_TILING_KEY_ELEMENTWISE_INT64);
     102              :     }
     103              : 
     104              :     tilingContext->SetBlockDim(elewiseBaseTiling.GetBlockDim());
     105              :     return ge::GRAPH_SUCCESS;
     106              : }
     107              : 
     108              : static ge::graphStatus Tiling4Relu(gert::TilingContext* context)
     109              : {
     110              :     OP_LOGD("ReluTiling", "Enter Tiling4Relu");
     111              :     if (context == nullptr) {
     112              :         OP_LOGE("ReluTiling", "Tiling context is null");
     113              :         return ge::GRAPH_FAILED;
     114              :     }
     115              : 
     116              :     auto compileInfo = context->GetCompileInfo<ReluCompileInfo>();
     117              :     OP_CHECK_NULL_WITH_CONTEXT(context, compileInfo);
     118              :     ReluTiling tiling(context);
     119              :     return tiling.RunTiling();
     120              : }
     121              : 
     122              : ge::graphStatus TilingPrepareForRelu(gert::TilingParseContext* context)
     123              : {
     124              :     auto compileInfoPtr = context->GetCompiledInfo<ReluCompileInfo>();
     125              :     OP_CHECK_NULL_WITH_CONTEXT(context, compileInfoPtr);
     126              :     fe::PlatFormInfos* platformInfoPtr = context->GetPlatformInfo();
     127              :     OP_CHECK_NULL_WITH_CONTEXT(context, platformInfoPtr);
     128              :     auto ascendcPlatform = platform_ascendc::PlatformAscendC(platformInfoPtr);
     129              :     compileInfoPtr->coreNum = ascendcPlatform.GetCoreNumAiv();
     130              :     ascendcPlatform.GetCoreMemSize(platform_ascendc::CoreMemType::UB, compileInfoPtr->ubSize);
     131              :     return ge::GRAPH_SUCCESS;
     132              : }
     133              : 
     134              : IMPL_OP_OPTILING(Relu).Tiling(Tiling4Relu).TilingParse<ReluCompileInfo>(TilingPrepareForRelu);
     135              : } // namespace optiling
        

Generated by: LCOV version 2.0-1