Line data Source code
1 : /**
2 : * Copyright (c) 2026 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 p_relu_tiling_arch35.cpp
13 : * \brief
14 : */
15 :
16 : #include <graph/utils/type_utils.h>
17 : #include "log/log.h"
18 : #include "platform/platform_info.h"
19 : #include "atvoss/broadcast/broadcast_tiling.h"
20 : #include "activation/p_relu/op_kernel/arch35/p_relu_struct.h"
21 : #include "activation/p_relu/op_kernel/arch35/p_relu_dag.h"
22 : #include "register/op_impl_registry.h"
23 : #include "register/tilingdata_base.h"
24 : #include "op_host/tiling_templates_registry.h"
25 : #include "op_host/tiling_util.h"
26 : #include "error_util.h"
27 : #include "p_relu_tiling_arch35.h"
28 :
29 : using namespace AscendC;
30 : using namespace ge;
31 : using namespace PreluOp;
32 : using namespace Ops::NN::OpTiling;
33 :
34 : namespace optiling {
35 : static constexpr uint64_t PRELU_COMMON_TILING_PRIORITY = 0;
36 : const int64_t ASCEND_WORKSPACE = 16777216; // 16M
37 : static const int64_t DIM_NUM_NHWC = 4;
38 : static const int64_t DIM_NUM_NC1HWC0 = 5;
39 : static const int64_t NC1HWC0_DIM_INDEX_C0 = 4;
40 : static const int64_t DIM_NUM_NDC1HWC0 = 6;
41 : static const int64_t NDC1HWC0_DIM_INDEX_C0 = 5;
42 : static const int64_t NDC1HWC0_DIM_INDEX_C1 = 2;
43 :
44 : ge::graphStatus PreluTiling::GetShapeAttrsInfo() { return ge::GRAPH_SUCCESS; }
45 :
46 : bool PreluTiling::IsCapable() { return true; }
47 :
48 : ge::graphStatus PreluTiling::DoOpTiling()
49 : {
50 : auto xInputDesc = context_->GetInputDesc(0);
51 : OP_CHECK_NULL_WITH_CONTEXT(context_, xInputDesc);
52 : ge::DataType xInputDtype = xInputDesc->GetDataType();
53 : OP_CHECK_IF(
54 : xInputDtype != ge::DT_FLOAT16 && xInputDtype != ge::DT_BF16 && xInputDtype != ge::DT_FLOAT,
55 : OP_LOGE_FOR_INVALID_DTYPE(context_->GetNodeName(), "x", ge::TypeUtils::DataTypeToSerialString(xInputDtype),
56 : "DT_FLOAT16, DT_BF16, DT_FLOAT"),
57 : return ge::GRAPH_FAILED);
58 :
59 : auto weightInputDesc = context_->GetInputDesc(1);
60 : OP_CHECK_NULL_WITH_CONTEXT(context_, weightInputDesc);
61 : ge::DataType weightInputDtype = weightInputDesc->GetDataType();
62 : OP_CHECK_IF(xInputDtype != weightInputDtype,
63 : OP_LOGE_FOR_INVALID_DTYPES_WITH_REASON(context_->GetNodeName(), "weight, x",
64 : ge::TypeUtils::DataTypeToSerialString(xInputDtype) + ", " +
65 : ge::TypeUtils::DataTypeToSerialString(weightInputDtype),
66 : "The dtypes of weight and x must be the same"),
67 : return ge::GRAPH_FAILED);
68 :
69 : auto outputDesc = context_->GetOutputDesc(0);
70 : OP_CHECK_NULL_WITH_CONTEXT(context_, outputDesc);
71 : ge::DataType outputDtype = outputDesc->GetDataType();
72 : OP_CHECK_IF(outputDtype != xInputDtype,
73 : OP_LOGE_FOR_INVALID_DTYPES_WITH_REASON(context_->GetNodeName(), "y, x",
74 : ge::TypeUtils::DataTypeToSerialString(outputDtype) + ", " +
75 : ge::TypeUtils::DataTypeToSerialString(xInputDtype),
76 : "The dtypes of y and x must be the same"),
77 : return ge::GRAPH_FAILED);
78 :
79 : ge::graphStatus baseTilingResult = ge::GRAPH_FAILED;
80 : if (xInputDtype == ge::DT_FLOAT16) {
81 : BroadcastBaseTiling<PreluDAG<half>::OpDag> brcBaseTiling(context_);
82 : baseTilingResult = brcBaseTiling.DoTiling();
83 3 : OP_CHECK_IF(baseTilingResult == ge::GRAPH_FAILED,
84 : OPS_REPORT_VECTOR_INNER_ERR(context_->GetNodeName(), "BroadcastBaseTiling failed, x dtype: %s.",
85 : ge::TypeUtils::DataTypeToSerialString(xInputDtype).c_str()),
86 : return ge::GRAPH_FAILED);
87 : tilingKey = GET_TPL_TILING_KEY(brcBaseTiling.GetSchMode());
88 : } else if (xInputDtype == ge::DT_BF16) {
89 : BroadcastBaseTiling<PreluDAG<bfloat16_t>::OpDag> brcBaseTiling(context_);
90 : baseTilingResult = brcBaseTiling.DoTiling();
91 : OP_CHECK_IF(baseTilingResult == ge::GRAPH_FAILED,
92 : OPS_REPORT_VECTOR_INNER_ERR(context_->GetNodeName(), "BroadcastBaseTiling failed, x dtype: %s.",
93 : ge::TypeUtils::DataTypeToSerialString(xInputDtype).c_str()),
94 : return ge::GRAPH_FAILED);
95 : tilingKey = GET_TPL_TILING_KEY(brcBaseTiling.GetSchMode());
96 : } else if (xInputDtype == ge::DT_FLOAT) {
97 : BroadcastBaseTiling<PreluDAG<float>::OpDag> brcBaseTiling(context_);
98 : baseTilingResult = brcBaseTiling.DoTiling();
99 2 : OP_CHECK_IF(baseTilingResult == ge::GRAPH_FAILED,
100 : OPS_REPORT_VECTOR_INNER_ERR(context_->GetNodeName(), "BroadcastBaseTiling failed, x dtype: %s.",
101 : ge::TypeUtils::DataTypeToSerialString(xInputDtype).c_str()),
102 : return ge::GRAPH_FAILED);
103 : tilingKey = GET_TPL_TILING_KEY(brcBaseTiling.GetSchMode());
104 : } else {
105 : OP_LOGE_FOR_INVALID_DTYPE(context_->GetNodeName(), "x", ge::TypeUtils::DataTypeToSerialString(xInputDtype),
106 : "DT_FLOAT16, DT_BF16, DT_FLOAT");
107 : return ge::GRAPH_FAILED;
108 : }
109 :
110 : return ge::GRAPH_SUCCESS;
111 : }
112 :
113 : ge::graphStatus PreluTiling::DoLibApiTiling() { return ge::GRAPH_SUCCESS; }
114 :
115 : uint64_t PreluTiling::GetTilingKey() const { return tilingKey; }
116 :
117 : ge::graphStatus PreluTiling::GetWorkspaceSize() { return ge::GRAPH_SUCCESS; }
118 :
119 : ge::graphStatus PreluTiling::PostTiling() { return ge::GRAPH_SUCCESS; }
120 :
121 : ge::graphStatus PreluTiling::GetPlatformInfo() { return ge::GRAPH_SUCCESS; }
122 :
123 : ge::graphStatus Tiling4PRelu(gert::TilingContext* context)
124 : {
125 : OP_LOGD("PreluTiling", "Enter TilingForPrelu");
126 : if (context == nullptr) {
127 : OP_LOGE("PreluTiling", "Tiling context is null");
128 : return ge::GRAPH_FAILED;
129 : }
130 : auto compileInfo = context->GetCompileInfo<Ops::Base::BroadcastCompileInfo>();
131 : OP_CHECK_NULL_WITH_CONTEXT(context, compileInfo);
132 : PreluTiling tiling(context);
133 : return tiling.DoTiling();
134 : }
135 :
136 : ge::graphStatus TilingPrepare4PRelu(gert::TilingParseContext* context)
137 : {
138 : auto compileInfoPtr = context->GetCompiledInfo<Ops::Base::BroadcastCompileInfo>();
139 : OP_CHECK_NULL_WITH_CONTEXT(context, compileInfoPtr);
140 : fe::PlatFormInfos* platformInfoPtr = context->GetPlatformInfo();
141 : OP_CHECK_NULL_WITH_CONTEXT(context, platformInfoPtr);
142 : auto ascendcPlatform = platform_ascendc::PlatformAscendC(platformInfoPtr);
143 : compileInfoPtr->coreNum = ascendcPlatform.GetCoreNumAiv();
144 : ascendcPlatform.GetCoreMemSize(platform_ascendc::CoreMemType::UB, compileInfoPtr->ubSize);
145 : return ge::GRAPH_SUCCESS;
146 : }
147 :
148 : IMPL_OP_OPTILING(PRelu).Tiling(Tiling4PRelu).TilingParse<BroadcastCompileInfo>(TilingPrepare4PRelu);
149 : REGISTER_OPS_TILING_TEMPLATE(PRelu, PreluTiling, PRELU_COMMON_TILING_PRIORITY);
150 : } // namespace optiling
|