已合并
fix: fix op splitV no_task attribute #4690
lushiming0创建于 9 天前
fix: fix op splitV no_task attribute #4690
已合并
lushiming0创建于 9 天前
11 个文件变更+3922-3839
@@ -18,8 +18,27 @@ const int kNDimIndex = 1;
18const int kRealDimNchwTo5Hd = 0;18const int kRealDimNchwTo5Hd = 0;
19const int kInputShapeLimit = 4;19const int kInputShapeLimit = 4;
20const int kValidNcDimSize = 2;20const int kValidNcDimSize = 2;
21+const int kSplitvInput2 = 2;
22+ 
23+bool SplitCToNOptimizer::CheckSplitDim(const ge::NodePtr &node, const ge::OpDescPtr &op_desc) const {
24+ if (op_desc->GetType() == fe::SPLITV) {
25+ auto in_nodes = node->GetInDataNodes();
26+ if (in_nodes.size() >= 3U) {
27+ std::string op_type1;
28+ std::string op_type2;
29+ if (ge::NodeUtils::GetConstOpType(in_nodes.at(1), op_type1) &&
30+ ge::NodeUtils::GetConstOpType(in_nodes.at(kSplitvInput2), op_type2)) {
31+ ge::GeTensorDescPtr input_tensor = op_desc->MutableInputDesc(0);
32+ if (input_tensor == nullptr || input_tensor->GetFormat() != ge::FORMAT_NCHW) {
33+ FE_LOGD("[%s] is SplitV but input0 format is not NCHW, cannot optimize.", op_desc->GetName().c_str());
34+ return false;
35+ }
36+ FE_LOGD("[%s] is SplitV with const input1 and input2, skip split_dim check.", op_desc->GetName().c_str());
37+ return true;
38+ }
39+ }
40+ }
21 41 
22-bool SplitCToNOptimizer::CheckSplitDim(const ge::OpDescPtr &op_desc) const {
23 int64_t split_dim = -1;42 int64_t split_dim = -1;
24 (void)ge::AttrUtils::GetInt(op_desc, SPLIT_DIM, split_dim);43 (void)ge::AttrUtils::GetInt(op_desc, SPLIT_DIM, split_dim);
25 ge::GeTensorDescPtr input_tensor = op_desc->MutableInputDesc(0);44 ge::GeTensorDescPtr input_tensor = op_desc->MutableInputDesc(0);
@@ -88,7 +107,8 @@ bool SplitCToNOptimizer::CheckAxis(const ge::OpDescPtr &op_desc) const {
88 107 
89bool SplitCToNOptimizer::CheckCommonCondition(const ge::ComputeGraph &graph, const ge::NodePtr &node,108bool SplitCToNOptimizer::CheckCommonCondition(const ge::ComputeGraph &graph, const ge::NodePtr &node,
90 const ge::OpDescPtr &op_desc) const {109 const ge::OpDescPtr &op_desc) const {
91- bool is_not_split = op_desc->GetType() != fe::SPLITD && op_desc->GetType() != fe::SPLITVD;110+ bool is_not_split =
111+ op_desc->GetType() != fe::SPLITD && op_desc->GetType() != fe::SPLITVD && op_desc->GetType() != fe::SPLITV;
92 string node_name = op_desc->GetName();112 string node_name = op_desc->GetName();
93 if (is_not_split) {113 if (is_not_split) {
94 return false;114 return false;
@@ -134,7 +154,7 @@ bool SplitCToNOptimizer::NeedSkip(const ge::ComputeGraph &graph, const ge::NodeP
134 bool condition_nd_nz = (input_orinal_format == ge::FORMAT_ND && input_format == ge::FORMAT_FRACTAL_NZ);154 bool condition_nd_nz = (input_orinal_format == ge::FORMAT_ND && input_format == ge::FORMAT_FRACTAL_NZ);
135 bool condition_nchw_5hd = (input_orinal_format == ge::FORMAT_NCHW && input_format == ge::FORMAT_NC1HWC0);155 bool condition_nchw_5hd = (input_orinal_format == ge::FORMAT_NCHW && input_format == ge::FORMAT_NC1HWC0);
136 156 
137- if (CheckSplitDim(op_desc) && CheckAxis(op_desc) &&157+ if (CheckSplitDim(node, op_desc) && CheckAxis(op_desc) &&
138 ((input_orinal_format == input_format) || (condition_nd_nz && MeetDimNumConditionFromNDToNZ(op_desc)) ||158 ((input_orinal_format == input_format) || (condition_nd_nz && MeetDimNumConditionFromNDToNZ(op_desc)) ||
139 (condition_nchw_5hd && MeetAlignmentConditionFromNCHWTo5HD(op_desc))) &&159 (condition_nchw_5hd && MeetAlignmentConditionFromNCHWTo5HD(op_desc))) &&
140 CheckCommonCondition(graph, node, op_desc)) {160 CheckCommonCondition(graph, node, op_desc)) {
@@ -20,7 +20,7 @@ class SplitCToNOptimizer {
20 20 
21 private:21 private:
22 bool NeedSkip(const ge::ComputeGraph &graph, const ge::NodePtr &node, const ge::OpDescPtr &op_desc) const;22 bool NeedSkip(const ge::ComputeGraph &graph, const ge::NodePtr &node, const ge::OpDescPtr &op_desc) const;
23- bool CheckSplitDim(const ge::OpDescPtr &op_desc) const;23+ bool CheckSplitDim(const ge::NodePtr &node, const ge::OpDescPtr &op_desc) const;
24 bool CheckCommonCondition(const ge::ComputeGraph &graph, const ge::NodePtr &node, const ge::OpDescPtr &op_desc) const;24 bool CheckCommonCondition(const ge::ComputeGraph &graph, const ge::NodePtr &node, const ge::OpDescPtr &op_desc) const;
25 bool CheckAxis(const ge::OpDescPtr &op_desc) const;25 bool CheckAxis(const ge::OpDescPtr &op_desc) const;
26 bool MeetAlignmentConditionFromNCHWTo5HD(const ge::OpDescPtr &op_desc) const;26 bool MeetAlignmentConditionFromNCHWTo5HD(const ge::OpDescPtr &op_desc) const;
@@ -57,40 +57,57 @@ void SplitNOptimizer::GetRealSplitDimFromOriginalFormatToFormat(const ge::OpDesc
57 FE_LOGD("GetRealSplitDim end node:%s, splitdim: %ld.", op_desc->GetName().c_str(), split_dim);57 FE_LOGD("GetRealSplitDim end node:%s, splitdim: %ld.", op_desc->GetName().c_str(), split_dim);
58}58}
59 59 
60+bool SplitNOptimizer::IsInvalidInputNode(const ge::NodePtr &in_node, bool is_splitv, size_t index) {
61+ std::string op_type;
62+ if (ge::NodeUtils::GetConstOpType(in_node, op_type)) {
63+ if (is_splitv && index > 0U) {
64+ return false;
65+ }
66+ FE_LOGD("In node %s of type %s cannot be optimized.", in_node->GetName().c_str(), op_type.c_str());
67+ return true;
68+ }
69+ if ((in_node->GetType() == TRANSDATA || in_node->GetType() == RESHAPE) &&
70+ (in_node->GetAllInDataAnchors().size() != 0)) {
71+ FE_CHECK_NOTNULL(in_node->GetInDataAnchor(0));
72+ auto peerOutAnchor = in_node->GetInDataAnchor(0)->GetPeerOutAnchor();
73+ if (peerOutAnchor == nullptr) {
74+ FE_LOGD("The first peer of in_node[%s] in the anchor is null.", in_node->GetName().c_str());
75+ return true;
76+ }
77+ auto pre_in_node = peerOutAnchor->GetOwnerNode();
78+ if (pre_in_node != nullptr && IsRootGraphData(pre_in_node->GetType())) {
79+ FE_LOGD("Data->TransData/Reshape->split. Data: pre_in_node[%s] cannot be optimized.",
80+ pre_in_node->GetName().c_str());
81+ return true;
82+ }
83+ }
84+ bool is_no_task = false;
85+ (void)ge::AttrUtils::GetBool(in_node->GetOpDesc(), ge::ATTR_NAME_NOTASK, is_no_task);
86+ if (is_no_task) {
87+ FE_LOGD("In node %s has no_task attribute, cannot be optimized.", in_node->GetName().c_str());
88+ return true;
89+ }
90+ vector<int64_t> output_index;
91+ (void)ge::AttrUtils::GetListInt(in_node->GetOpDesc(), ge::ATOMIC_ATTR_OUTPUT_INDEX, output_index);
92+ if (!output_index.empty()) {
93+ FE_LOGD("Node [%s] has atomic_output attribute, cannot be optimized.", in_node->GetName().c_str());
94+ return true;
95+ }
96+ return false;
97+}
98+ 
60bool SplitNOptimizer::InputCheck(ge::NodePtr split_node) const {99bool SplitNOptimizer::InputCheck(ge::NodePtr split_node) const {
61- for (auto in_node : split_node->GetInDataNodes()) {100+ if (split_node == nullptr) {
62- std::string op_type;101+ return false;
63- if (ge::NodeUtils::GetConstOpType(in_node, op_type)) {102+ }
64- FE_LOGD("In node %s of type %s, %s cannot be optimized.", in_node->GetName().c_str(), op_type.c_str(),103+ auto op_desc = split_node->GetOpDesc();
65- split_node->GetName().c_str());104+ if (op_desc == nullptr) {
66- return false;105+ return false;
67- }106+ }
68- if ((in_node->GetType() == TRANSDATA || in_node->GetType() == RESHAPE) &&107+ bool is_splitv = (op_desc->GetType() == fe::SPLITV);
69- (in_node->GetAllInDataAnchors().size() != 0)) {108+ const auto in_nodes = split_node->GetInDataNodes();
70- FE_CHECK_NOTNULL(in_node->GetInDataAnchor(0));109+ for (size_t i = 0U; i < in_nodes.size(); i++) {
71- auto peerOutAnchor = in_node->GetInDataAnchor(0)->GetPeerOutAnchor();110+ if (IsInvalidInputNode(in_nodes.at(i), is_splitv, i)) {
72- if (peerOutAnchor == nullptr) {
73- FE_LOGD("The first peer of in_node[%s] in the anchor is null.", in_node->GetName().c_str());
74- return false;
75- }
76- auto pre_in_node = peerOutAnchor->GetOwnerNode();
77- if (pre_in_node != nullptr && IsRootGraphData(pre_in_node->GetType())) {
78- FE_LOGD("Data->TransData/Reshape->split. Data: pre_in_node[%s], %s cannot be optimized.",
79- pre_in_node->GetName().c_str(), split_node->GetName().c_str());
80- return false;
81- }
82- }
83- bool is_no_task = false;
84- (void)ge::AttrUtils::GetBool(in_node->GetOpDesc(), ge::ATTR_NAME_NOTASK, is_no_task);
85- if (is_no_task) {
86- FE_LOGD("In node %s, the presence of the no_task attribute means that %s cannot be optimized.",
87- in_node->GetName().c_str(), split_node->GetName().c_str());
88- return false;
89- }
90- vector<int64_t> output_index;
91- (void)ge::AttrUtils::GetListInt(in_node->GetOpDesc(), ge::ATOMIC_ATTR_OUTPUT_INDEX, output_index);
92- if (!output_index.empty()) {
93- FE_LOGD("Node [%s] has an atomic_output attribute and cannot be optimized.", in_node->GetName().c_str());
94 return false;111 return false;
95 }112 }
96 }113 }
@@ -42,6 +42,7 @@ class SplitNOptimizer {
42 void GetRealSplitDimFromOriginalFormatToFormat(const ge::OpDescPtr &op_desc, int64_t &split_dim) const;42 void GetRealSplitDimFromOriginalFormatToFormat(const ge::OpDescPtr &op_desc, int64_t &split_dim) const;
43 static bool InvalidNodeType(const string &node_type);43 static bool InvalidNodeType(const string &node_type);
44 static bool InvalidNodeAttr(const ge::OpDescPtr &node_desc);44 static bool InvalidNodeAttr(const ge::OpDescPtr &node_desc);
45+ static bool IsInvalidInputNode(const ge::NodePtr &in_node, bool is_splitv, size_t index);
45};46};
46} // namespace fe47} // namespace fe
47#endif // FUSION_ENGINE_FUSION_GRAPH_OPTIMIZER_NODE_OPTIMIZER_SPLIT_N_OPTIMIZER_H_48#endif // FUSION_ENGINE_FUSION_GRAPH_OPTIMIZER_NODE_OPTIMIZER_SPLIT_N_OPTIMIZER_H_
@@ -490,9 +490,28 @@ Status NodeCheckerUtils::CheckPhonySplitInputSize(const Node *const node) {
490 if (!MemLayoutConflictUtil::IsNoPaddingContinuousOutput(node)) {490 if (!MemLayoutConflictUtil::IsNoPaddingContinuousOutput(node)) {
491 return SUCCESS;491 return SUCCESS;
492 }492 }
493- GE_ASSERT_TRUE(node->GetOpDescBarePtr()->GetInputsSize() == 1U,493+ const auto op_desc = node->GetOpDescBarePtr();
494+ GE_ASSERT_NOTNULL(op_desc);
495+ if (op_desc->GetType() == "SplitV") {
496+ const auto in_nodes = node->GetInDataNodes();
497+ GE_ASSERT_TRUE(in_nodes.size() >= 3U,
498+ "node %s is SplitV with nopadding continuous output, should have 3 data inputs, but actual: %zu",
499+ NodeCheckerUtils::NodeName(node).c_str(), in_nodes.size());
500+ std::string const_op_type;
501+ GE_ASSERT_TRUE(!ge::NodeUtils::GetConstOpType(in_nodes.at(0U), const_op_type),
502+ "node %s is SplitV, input0 (x) should be non-const", NodeCheckerUtils::NodeName(node).c_str());
503+ GE_ASSERT_TRUE(ge::NodeUtils::GetConstOpType(in_nodes.at(1U), const_op_type),
504+ "node %s is SplitV, input1 (size_splits) should be const", NodeCheckerUtils::NodeName(node).c_str());
505+ GE_ASSERT_TRUE(ge::NodeUtils::GetConstOpType(in_nodes.at(2U), const_op_type),
506+ "node %s is SplitV, input2 (split_dim) should be const", NodeCheckerUtils::NodeName(node).c_str());
507+ const auto input_desc = op_desc->GetInputDesc(0U);
508+ GE_ASSERT_TRUE(input_desc.GetFormat() == ge::FORMAT_NCHW, "node %s is SplitV, input0 (x) format should be NCHW",
509+ NodeCheckerUtils::NodeName(node).c_str());
510+ return SUCCESS;
511+ }
512+ GE_ASSERT_TRUE(op_desc->GetInputsSize() == 1U,
494 "node %s need nopadding continuous output, should only has one input, but actual input size: %zu",513 "node %s need nopadding continuous output, should only has one input, but actual input size: %zu",
495- NodeCheckerUtils::NodeName(node).c_str(), node->GetOpDescBarePtr()->GetInputsSize());514+ NodeCheckerUtils::NodeName(node).c_str(), op_desc->GetInputsSize());
496 return SUCCESS;515 return SUCCESS;
497}516}
498 517 
@@ -169,6 +169,8 @@ add_executable(ut_fe_graph_optimizer
169 ${CMAKE_CURRENT_LIST_DIR}/testcase/fusion_engine/graph_fusion/graph_fusion_ut.cc169 ${CMAKE_CURRENT_LIST_DIR}/testcase/fusion_engine/graph_fusion/graph_fusion_ut.cc
170 ${CMAKE_CURRENT_LIST_DIR}/testcase/fusion_engine/graph_optimizer/fusion_engine_coverage.cc170 ${CMAKE_CURRENT_LIST_DIR}/testcase/fusion_engine/graph_optimizer/fusion_engine_coverage.cc
171 ${CMAKE_CURRENT_LIST_DIR}/testcase/fusion_engine/graph_optimizer/fusion_engine_fe_graph_optimizer_unittest.cc171 ${CMAKE_CURRENT_LIST_DIR}/testcase/fusion_engine/graph_optimizer/fusion_engine_fe_graph_optimizer_unittest.cc
172+ ${CMAKE_CURRENT_LIST_DIR}/testcase/fusion_engine/graph_optimizer/fusion_engine_fe_graph_optimizer_misc_unittest.cc
173+ ${CMAKE_CURRENT_LIST_DIR}/testcase/fusion_engine/graph_optimizer/fusion_engine_fe_graph_optimizer_fixture.cc
172 ${CMAKE_CURRENT_LIST_DIR}/testcase/fusion_engine/graph_optimizer/check_graph_cycle_unittest.cc174 ${CMAKE_CURRENT_LIST_DIR}/testcase/fusion_engine/graph_optimizer/check_graph_cycle_unittest.cc
173)175)
174target_link_libraries(ut_fe_graph_optimizer PRIVATE -Wl,--whole-archive fe_ut_common -Wl,--no-whole-archive)176target_link_libraries(ut_fe_graph_optimizer PRIVATE -Wl,--whole-archive fe_ut_common -Wl,--no-whole-archive)
@@ -0,0 +1,2215 @@
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+#include "fusion_engine_fe_graph_optimizer_unittest.h"
12+ 
13+NodePtr UTEST_fusion_engine_fe_graph_optimizer::MakeNode(const ComputeGraphPtr &graph, uint32_t in_num,
14+ uint32_t out_num, string name, string type) {
15+ GeTensorDesc test_desc(GeShape(), FORMAT_NCHW, DT_FLOAT);
16+ auto op_desc = std::make_shared<OpDesc>(name, type);
17+ for (auto i = 0; i < in_num; ++i) {
18+ op_desc->AddInputDesc(test_desc);
19+ }
20+ for (auto i = 0; i < out_num; ++i) {
21+ op_desc->AddOutputDesc(test_desc);
22+ }
23+ return graph->AddNode(op_desc);
24+}
25+ 
26+void UTEST_fusion_engine_fe_graph_optimizer::SetUpTestCase() {
27+ std::string soc_version = "Ascend310P3";
28+ PlatformInfoManager::Instance().opti_compilation_info_.soc_version = soc_version;
29+ PlatformInfoManager::Instance().opti_compilation_infos_.SetSocVersion(soc_version);
30+ PlatformUtils::Instance().soc_version_ = soc_version;
31+ Configuration::Instance(AI_CORE_NAME).InitLibPath();
32+}
33+ 
34+void UTEST_fusion_engine_fe_graph_optimizer::SetUp() {
35+ reflection_builder_ptr_ = std::make_shared<ge::RefRelations>();
36+ ops_info_store = std::make_shared<FEOpsKernelInfoStore>();
37+ sub_ops_store_ptr = make_shared<fe::SubOpsStore>(fe::AI_CORE_NAME);
38+ tbe_adapter_ptr = std::dynamic_pointer_cast<TbeOpStoreAdapter>(
39+ OpStoreAdapterManager::Instance(AI_CORE_NAME).GetOpStoreAdapter(EN_IMPL_HW_TBE));
40+ 
41+ OptimizeUtilityUTStub *optimize_utility_utub = new OptimizeUtilityUTStub();
42+ 
43+ ops_kernel_info_store_ptr_ = std::make_shared<FEOpsKernelInfoStore>(fe::AI_CORE_NAME);
44+ ops_kernel_info_store_ptr_->tbe_info_assembler_ptr_ = std::make_shared<TbeInfoAssembler>();
45+ ops_kernel_info_store_ptr_->tbe_info_assembler_ptr_->Initialize();
46+ FusionRuleManagerPtr fusion_rule_mgr_ptr_ = std::make_shared<FusionRuleManager>(ops_kernel_info_store_ptr_);
47+ FusionPriorityMgrPtr fusion_priority_mgr_ptr_ =
48+ std::make_shared<FusionPriorityManager>(fe::AI_CORE_NAME, fusion_rule_mgr_ptr_);
49+ fusion_priority_mgr_ptr_->Initialize();
50+ lx_fusion_optimizer_ = std::make_shared<LxFusionOptimizer>(fusion_priority_mgr_ptr_, ops_kernel_info_store_ptr_);
51+ lx_fusion_optimizer_->Initialize();
52+ graph_fusion_ptr_ =
53+ std::make_shared<GraphFusion>(fusion_rule_mgr_ptr_, ops_kernel_info_store_ptr_, fusion_priority_mgr_ptr_);
54+ graph_fusion_ptr_->SetEngineName(fe::AI_CORE_NAME);
55+ fe_graph_optimizer_ = make_shared<FEGraphOptimizer>(ops_kernel_info_store_ptr_, fe::AI_CORE_NAME);
56+ std::map<std::string, std::string> options;
57+ fe_graph_optimizer_->Initialize(options, optimize_utility_utub);
58+ fe_graph_optimizer_->graph_fusion_ptr_ = graph_fusion_ptr_;
59+ 
60+ FEOpsStoreInfo TBE_OPINFO_STUB = {
61+ 6, "tbe-builtin", EN_IMPL_HW_TBE,
62+ GetCodeDir() + "/tests/engines/nn_engine/ut/testcase/fusion_engine/ops_kernel_store/fe_config/heavy_opinfo", ""};
63+ 
64+ sub_ops_store_ptr->SetSubStoreInfo(TBE_OPINFO_STUB);
65+ sub_ops_store_ptr->InitializeSubStore();
66+ 
67+ vector<FEOpsStoreInfo> store_info;
68+ store_info.emplace_back(TBE_OPINFO_STUB);
69+ Configuration::Instance(fe::AI_CORE_NAME).ops_store_info_vector_ = (store_info);
70+ 
71+ sub_ops_kernel_ptr = std::make_shared<fe::SubOpInfoStore>(TBE_OPINFO_STUB);
72+ sub_ops_kernel_ptr->Initialize(fe::AI_CORE_NAME);
73+ OpsKernelManager::Instance(fe::AI_CORE_NAME).sub_ops_kernel_map_.emplace("tbe-builtin", sub_ops_kernel_ptr);
74+ 
75+ options.insert(std::pair<std::string, std::string>("ge.shape_generalized_build_mode", SHAPE_GENERALIZED));
76+ options.emplace(ge::PRECISION_MODE, ALLOW_FP32_TO_FP16);
77+ ge::GetThreadLocalContext().SetGlobalOption(options);
78+ 
79+ std::map<std::string, std::string> options1;
80+ OpsKernelManager::Instance(fe::AI_CORE_NAME).Finalize();
81+ ops_info_store->Initialize(options1);
82+ ops_kernel_info_store_ptr_->Initialize(options);
83+}
84+ 
85+void UTEST_fusion_engine_fe_graph_optimizer::TearDown() {
86+ sub_ops_store_ptr->FinalizeSubStore();
87+ sub_ops_store_ptr.reset();
88+ sub_ops_kernel_ptr->Finalize();
89+ sub_ops_kernel_ptr.reset();
90+ ops_info_store->Finalize();
91+ 
92+ PlatformUtils::Instance().soc_version_ = "Ascend910B1";
93+ PlatformUtils::Instance().short_soc_version_ = "Ascend910B";
94+}
95+ 
96+void UTEST_fusion_engine_fe_graph_optimizer::CreateConv2dGraph(ComputeGraphPtr graph) {
97+ OpDescPtr conv2d = std::make_shared<OpDesc>("conv2d", CONV2D);
98+ OpDescPtr data = std::make_shared<OpDesc>("DATA0", fe::DATA);
99+ OpDescPtr reduceSum = std::make_shared<OpDesc>("reduceSum", "ReduceSum");
100+ 
101+ // add descriptor
102+ vector<int64_t> dims = {1, 3, 32, 32};
103+ GeShape shape(dims);
104+ 
105+ GeTensorDesc in_desc2(shape);
106+ in_desc2.SetFormat(FORMAT_NHWC);
107+ in_desc2.SetOriginFormat(FORMAT_NHWC);
108+ in_desc2.SetDataType(DT_FLOAT16);
109+ conv2d->AddInputDesc("x", in_desc2);
110+ data->AddOutputDesc("x", in_desc2);
111+ reduceSum->AddInputDesc("x", in_desc2);
112+ 
113+ vector<int64_t> dims1 = {1, 1, 3, 32, 32};
114+ GeShape shape1(dims1);
115+ GeTensorDesc out_desc1(shape1);
116+ out_desc1.SetFormat(FORMAT_NC1HWC0);
117+ out_desc1.SetOriginFormat(FORMAT_NC1HWC0);
118+ out_desc1.SetDataType(DT_FLOAT16);
119+ conv2d->AddOutputDesc("y", out_desc1);
120+ std::vector<bool> is_in_const_vec = {false};
121+ conv2d->SetIsInputConst(is_in_const_vec);
122+ GeTensorDesc out_desc2(shape);
123+ out_desc2.SetFormat(FORMAT_NHWC);
124+ out_desc2.SetOriginFormat(FORMAT_NHWC);
125+ out_desc2.SetDataType(DT_FLOAT16);
126+ reduceSum->AddOutputDesc("y", out_desc2);
127+ 
128+ ge::AttrUtils::SetInt(conv2d, FE_IMPLY_TYPE, static_cast<int>(EN_IMPL_HW_TBE));
129+ ge::AttrUtils::SetBool(conv2d, ge::ATTR_NAME_NOTASK, true);
130+ NodePtr bn_node = graph->AddNode(conv2d);
131+ NodePtr data_node = graph->AddNode(data);
132+ NodePtr reduceSum_node = graph->AddNode(reduceSum);
133+ GraphUtils::AddEdge(data_node->GetOutDataAnchor(0), bn_node->GetInDataAnchor(0));
134+ GraphUtils::AddEdge(bn_node->GetOutDataAnchor(0), reduceSum_node->GetInDataAnchor(0));
135+}
136+ 
137+void UTEST_fusion_engine_fe_graph_optimizer::CreateBatchNormGraph(ComputeGraphPtr graph) {
138+ OpDescPtr bn_op = std::make_shared<OpDesc>("batchnormal", "BatchNorm");
139+ OpDescPtr data = std::make_shared<OpDesc>("DATA0", fe::DATA);
140+ 
141+ // add descriptor
142+ vector<int64_t> dims = {1, 2, 3, 32};
143+ GeShape shape(dims);
144+ 
145+ GeTensorDesc in_desc2(shape);
146+ in_desc2.SetFormat(FORMAT_FRACTAL_Z);
147+ in_desc2.SetOriginFormat(FORMAT_FRACTAL_Z);
148+ in_desc2.SetDataType(DT_FLOAT16);
149+ bn_op->AddInputDesc("x", in_desc2);
150+ data->AddOutputDesc("x", in_desc2);
151+ 
152+ GeTensorDesc out_desc2(shape);
153+ out_desc2.SetFormat(FORMAT_NHWC);
154+ out_desc2.SetOriginFormat(FORMAT_NHWC);
155+ out_desc2.SetDataType(DT_FLOAT16);
156+ bn_op->AddOutputDesc("y", out_desc2);
157+ std::vector<bool> is_in_const_vec = {false};
158+ bn_op->SetIsInputConst(is_in_const_vec);
159+ uint32_t thread_scope_id = 2;
160+ (void)ge::AttrUtils::SetInt(bn_op, kThreadScopeId, thread_scope_id);
161+ ge::AttrUtils::SetInt(bn_op, FE_IMPLY_TYPE, static_cast<int>(EN_IMPL_HW_TBE));
162+ ge::AttrUtils::SetBool(bn_op, ge::ATTR_NAME_NOTASK, true);
163+ NodePtr bn_node = graph->AddNode(bn_op);
164+ NodePtr data_node = graph->AddNode(data);
165+ GraphUtils::AddEdge(data_node->GetOutDataAnchor(0), bn_node->GetInDataAnchor(0));
166+}
167+ 
168+ComputeGraphPtr UTEST_fusion_engine_fe_graph_optimizer::CreateMultiThreadGraph() {
169+ ComputeGraphPtr graph = std::make_shared<ComputeGraph>("test");
170+ CreateConv2dGraph(graph);
171+ vector<int64_t> dim(4, 1);
172+ GeShape shape(dim);
173+ GeTensorDesc out_desc(shape, FORMAT_NCHW, DT_FLOAT);
174+ out_desc.SetOriginFormat(FORMAT_NCHW);
175+ out_desc.SetOriginDataType(DT_FLOAT);
176+ out_desc.SetOriginShape(shape);
177+ OpDescPtr relu_op2 = std::make_shared<OpDesc>("relu2", "Relu");
178+ OpDescPtr relu_op3 = std::make_shared<OpDesc>("relu3", "Relu");
179+ OpDescPtr relu_op4 = std::make_shared<OpDesc>("relu4", "Relu");
180+ OpDescPtr relu_op5 = std::make_shared<OpDesc>("relu5", "Relu");
181+ OpDescPtr relu_op6 = std::make_shared<OpDesc>("relu6", "Relu");
182+ OpDescPtr relu_op7 = std::make_shared<OpDesc>("relu7", "Relu");
183+ 
184+ relu_op2->AddInputDesc("x", out_desc);
185+ relu_op2->AddOutputDesc("y", out_desc);
186+ relu_op3->AddInputDesc("x", out_desc);
187+ relu_op3->AddOutputDesc("y", out_desc);
188+ relu_op4->AddInputDesc("x", out_desc);
189+ relu_op4->AddOutputDesc("y", out_desc);
190+ relu_op5->AddInputDesc("x", out_desc);
191+ relu_op5->AddOutputDesc("y", out_desc);
192+ relu_op6->AddInputDesc("x", out_desc);
193+ relu_op6->AddOutputDesc("y", out_desc);
194+ relu_op7->AddInputDesc("x", out_desc);
195+ relu_op7->AddOutputDesc("y", out_desc);
196+ 
197+ NodePtr relu_node2 = graph->AddNode(relu_op2);
198+ NodePtr relu_node3 = graph->AddNode(relu_op3);
199+ NodePtr relu_node4 = graph->AddNode(relu_op4);
200+ NodePtr relu_node5 = graph->AddNode(relu_op5);
201+ NodePtr relu_node6 = graph->AddNode(relu_op6);
202+ NodePtr relu_node7 = graph->AddNode(relu_op7);
203+ return graph;
204+}
205+ 
206+void UTEST_fusion_engine_fe_graph_optimizer::CreateSubGraph(ComputeGraphPtr graph, ComputeGraphPtr subgraph) {
207+ OpDescPtr bn_op = std::make_shared<OpDesc>("batchnormal", "BatchNorm");
208+ OpDescPtr data = std::make_shared<OpDesc>("DATA0", fe::DATA);
209+ 
210+ // add descriptor
211+ vector<int64_t> dims = {1, 2, 3, 32};
212+ GeShape shape(dims);
213+ 
214+ GeTensorDesc in_desc2(shape);
215+ in_desc2.SetFormat(FORMAT_FRACTAL_Z);
216+ in_desc2.SetOriginFormat(FORMAT_FRACTAL_Z);
217+ in_desc2.SetDataType(DT_FLOAT16);
218+ bn_op->AddInputDesc("x", in_desc2);
219+ data->AddOutputDesc("x", in_desc2);
220+ 
221+ GeTensorDesc out_desc2(shape);
222+ out_desc2.SetFormat(FORMAT_NHWC);
223+ out_desc2.SetOriginFormat(FORMAT_NHWC);
224+ out_desc2.SetDataType(DT_FLOAT16);
225+ bn_op->AddOutputDesc("y", out_desc2);
226+ std::vector<bool> is_in_const_vec = {false};
227+ bn_op->SetIsInputConst(is_in_const_vec);
228+ 
229+ ge::AttrUtils::SetInt(bn_op, FE_IMPLY_TYPE, static_cast<int>(EN_IMPL_HW_TBE));
230+ ge::AttrUtils::SetBool(bn_op, ge::ATTR_NAME_NOTASK, true);
231+ NodePtr bn_node = graph->AddNode(bn_op);
232+ NodePtr data_node = graph->AddNode(data);
233+ GraphUtils::AddEdge(data_node->GetOutDataAnchor(0), bn_node->GetInDataAnchor(0));
234+ subgraph->SetParentNode(bn_node);
235+ subgraph->SetParentGraph(graph);
236+ graph->AddSubgraph(subgraph->GetName(), subgraph);
237+}
238+ 
239+void UTEST_fusion_engine_fe_graph_optimizer::CreateSimpleGraphDescs(OpDescPtr &op_desc_ptr) {
240+ ge::DataType set_dtype = ge::DT_FLOAT16;
241+ std::vector<int64_t> shape_vec{256, 256, 512};
242+ ge::GeShape shape_desc = ge::GeShape(shape_vec);
243+ 
244+ vector<std::pair<int64_t, int64_t>> range({{1, 512}, {256, 256}, {512, 512}});
245+ 
246+ shared_ptr<ge::GeTensorDesc> input0_desc_ptr = make_shared<ge::GeTensorDesc>();
247+ input0_desc_ptr->SetDataType(set_dtype);
248+ input0_desc_ptr->SetShape(shape_desc);
249+ input0_desc_ptr->SetOriginShape(shape_desc);
250+ input0_desc_ptr->SetOriginShapeRange(range);
251+ input0_desc_ptr->SetValueRange(range);
252+ op_desc_ptr->AddInputDesc("x", input0_desc_ptr->Clone());
253+ 
254+ shared_ptr<ge::GeTensorDesc> input1_desc_ptr = make_shared<ge::GeTensorDesc>();
255+ input1_desc_ptr->SetDataType(set_dtype);
256+ input1_desc_ptr->SetOriginShape(shape_desc);
257+ input1_desc_ptr->SetShape(shape_desc);
258+ input1_desc_ptr->SetOriginShapeRange(range);
259+ input1_desc_ptr->SetValueRange(range);
260+ op_desc_ptr->AddInputDesc("y", input1_desc_ptr->Clone());
261+ 
262+ shared_ptr<ge::GeTensorDesc> output_desc_ptr = make_shared<ge::GeTensorDesc>();
263+ output_desc_ptr->SetDataType(set_dtype);
264+ output_desc_ptr->SetShape(shape_desc);
265+ output_desc_ptr->SetOriginShape(shape_desc);
266+ output_desc_ptr->SetOriginShapeRange(range);
267+ output_desc_ptr->SetValueRange(range);
268+ op_desc_ptr->AddOutputDesc("z", output_desc_ptr->Clone());
269+}
270+ 
271+void UTEST_fusion_engine_fe_graph_optimizer::CreateSimpleGraph(ComputeGraphPtr graph) {
272+ shared_ptr<ge::OpDesc> op_desc_ptr = make_shared<ge::OpDesc>("tbe_conv2d", "conv");
273+ 
274+ int64_t int_value = 1;
275+ float float_value = 2.0;
276+ bool bool_value = false;
277+ string str_value = "abc";
278+ vector<int64_t> int_vec{1, 2, 3};
279+ vector<int64_t> rint_vec;
280+ vector<float> float_vec{4.0, 5.0, 6.0};
281+ vector<float> rfloat_vec;
282+ vector<bool> bool_vec{false, true, true};
283+ vector<bool> rbool_vec;
284+ std::vector<string> str_vec{"a", "b", "c"};
285+ AttrUtils::SetInt(op_desc_ptr, "transposX", int_value);
286+ AttrUtils::SetFloat(op_desc_ptr, "transposY", float_value);
287+ AttrUtils::SetBool(op_desc_ptr, "attrBool", bool_value);
288+ AttrUtils::SetStr(op_desc_ptr, "attrStr", str_value);
289+ AttrUtils::SetListInt(op_desc_ptr, "attrListInt", int_vec);
290+ AttrUtils::SetListFloat(op_desc_ptr, "attrListFloat", float_vec);
291+ AttrUtils::SetListBool(op_desc_ptr, "attrListBool", bool_vec);
292+ AttrUtils::SetListStr(op_desc_ptr, "attrListStr", str_vec);
293+ CreateSimpleGraphDescs(op_desc_ptr);
294+ 
295+ std::vector<bool> is_input_const;
296+ is_input_const.emplace_back(false);
297+ is_input_const.emplace_back(true);
298+ op_desc_ptr->SetIsInputConst(is_input_const);
299+ 
300+ AttrUtils::SetInt(op_desc_ptr, "imply_type", EN_IMPL_HW_TBE);
301+ NodePtr conv_node = graph->AddNode(op_desc_ptr);
302+ op_desc_ptr->SetName("conv2");
303+ NodePtr conv_next_node = graph->AddNode(op_desc_ptr);
304+ GraphUtils::AddEdge(conv_node->GetOutDataAnchor(0), conv_next_node->GetInDataAnchor(0));
305+}
306+ 
307+void UTEST_fusion_engine_fe_graph_optimizer::CreateSingleNodeGraph(ComputeGraphPtr graph) {
308+ OpDescPtr relu_op = std::make_shared<OpDesc>("relu", "Activation");
309+ OpDescPtr data = std::make_shared<OpDesc>("DATA0", fe::DATA);
310+ vector<int64_t> dims = {1, 2, 3, 4};
311+ GeShape shape(dims);
312+ 
313+ shared_ptr<ge::GeTensorDesc> in_desc1 = make_shared<ge::GeTensorDesc>();
314+ in_desc1->SetDataType(DT_FLOAT16);
315+ in_desc1->SetFormat(FORMAT_NCHW);
316+ in_desc1->SetShape(shape);
317+ relu_op->AddInputDesc("x", in_desc1->Clone());
318+ data->AddOutputDesc("x", in_desc1->Clone());
319+ data->AddInputDesc("x", in_desc1->Clone());
320+ 
321+ shared_ptr<ge::GeTensorDesc> out_desc1 = make_shared<ge::GeTensorDesc>();
322+ out_desc1->SetDataType(DT_FLOAT16);
323+ out_desc1->SetFormat(FORMAT_NCHW);
324+ out_desc1->SetShape(shape);
325+ relu_op->AddOutputDesc("y", out_desc1->Clone());
326+ 
327+ ge::AttrUtils::SetInt(relu_op, FE_IMPLY_TYPE, static_cast<int>(EN_IMPL_HW_GENERAL_CCE));
328+ NodePtr relu_node = graph->AddNode(relu_op);
329+ NodePtr data_node = graph->AddNode(data);
330+ GraphUtils::AddEdge(data_node->GetOutDataAnchor(0), relu_node->GetInDataAnchor(0));
331+}
332+ 
333+void UTEST_fusion_engine_fe_graph_optimizer::CreateSingleNodeGraph2(ComputeGraphPtr graph) {
334+ OpDescPtr max_pool_op = std::make_shared<OpDesc>("maxpool", "MaxPoolV3");
335+ OpDescPtr data = std::make_shared<OpDesc>("DATA0", fe::DATA);
336+ vector<int64_t> dims = {1, 2, 3, 4};
337+ GeShape shape(dims);
338+ 
339+ shared_ptr<ge::GeTensorDesc> in_desc1 = make_shared<ge::GeTensorDesc>();
340+ in_desc1->SetDataType(DT_FLOAT16);
341+ in_desc1->SetFormat(FORMAT_NCHW);
342+ in_desc1->SetShape(shape);
343+ max_pool_op->AddInputDesc("x", in_desc1->Clone());
344+ data->AddOutputDesc("x", in_desc1->Clone());
345+ data->AddInputDesc("x", in_desc1->Clone());
346+ 
347+ shared_ptr<ge::GeTensorDesc> out_desc1 = make_shared<ge::GeTensorDesc>();
348+ out_desc1->SetDataType(DT_FLOAT16);
349+ out_desc1->SetFormat(FORMAT_NCHW);
350+ out_desc1->SetShape(shape);
351+ max_pool_op->AddOutputDesc("y", out_desc1->Clone());
352+ 
353+ ge::AttrUtils::SetInt(max_pool_op, FE_IMPLY_TYPE, static_cast<int>(EN_IMPL_HW_GENERAL_CCE));
354+ NodePtr relu_node = graph->AddNode(max_pool_op);
355+ NodePtr data_node = graph->AddNode(data);
356+ GraphUtils::AddEdge(data_node->GetOutDataAnchor(0), relu_node->GetInDataAnchor(0));
357+}
358+ 
359+void UTEST_fusion_engine_fe_graph_optimizer::CreateTwoOpDescGraphDescs(OpDescPtr &bn_op, OpDescPtr &relu_op,
360+ OpDescPtr &max_op, OpDescPtr &const_op) {
361+ bn_op = std::make_shared<OpDesc>("batchnormal", "BatchNorm");
362+ relu_op = std::make_shared<OpDesc>("relu", "Activation");
363+ max_op = std::make_shared<OpDesc>("max", "Maximum");
364+ const_op = std::make_shared<OpDesc>("const", "Const");
365+ vector<int64_t> dims = {1, 2, 3, 4};
366+ GeShape shape(dims);
367+ 
368+ GeTensorDesc in_desc1(shape);
369+ in_desc1.SetFormat(FORMAT_NCHW);
370+ in_desc1.SetDataType(DT_FLOAT16);
371+ relu_op->AddInputDesc("x", in_desc1);
372+ 
373+ GeTensorDesc out_desc1(shape);
374+ out_desc1.SetFormat(FORMAT_HWCN);
375+ out_desc1.SetDataType(DT_FLOAT16);
376+ relu_op->AddOutputDesc("y", out_desc1);
377+ 
378+ GeTensorDesc in_desc2(shape);
379+ in_desc2.SetFormat(FORMAT_FRACTAL_Z);
380+ in_desc2.SetDataType(DT_FLOAT16);
381+ bn_op->AddInputDesc("x", in_desc2);
382+ 
383+ GeTensorDesc out_desc2(shape);
384+ out_desc2.SetFormat(FORMAT_NHWC);
385+ out_desc2.SetDataType(DT_FLOAT16);
386+ bn_op->AddOutputDesc("y", out_desc2);
387+ 
388+ GeTensorDesc in_desc3(shape);
389+ in_desc3.SetFormat(FORMAT_FRACTAL_Z);
390+ in_desc3.SetDataType(DT_FLOAT16);
391+ max_op->AddInputDesc("x", in_desc3);
392+ 
393+ GeTensorDesc in_desc4(shape);
394+ in_desc4.SetFormat(FORMAT_FRACTAL_Z);
395+ in_desc4.SetDataType(DT_FLOAT16);
396+ max_op->AddInputDesc("y", in_desc4);
397+ 
398+ GeTensorDesc out_desc3(shape);
399+ out_desc3.SetFormat(FORMAT_NHWC);
400+ out_desc3.SetDataType(DT_FLOAT16);
401+ max_op->AddOutputDesc("z", out_desc3);
402+ 
403+ GeTensorDesc out_desc4(shape);
404+ out_desc4.SetFormat(FORMAT_NHWC);
405+ out_desc4.SetDataType(DT_FLOAT16);
406+ const_op->AddOutputDesc("z", out_desc4);
407+}
408+ 
409+void UTEST_fusion_engine_fe_graph_optimizer::CreateTwoOpDescGraph(ComputeGraphPtr graph, bool set_fusion_scope_flag) {
410+ OpDescPtr bn_op;
411+ OpDescPtr relu_op;
412+ OpDescPtr max_op;
413+ OpDescPtr const_op;
414+ CreateTwoOpDescGraphDescs(bn_op, relu_op, max_op, const_op);
415+ 
416+ std::vector<bool> is_in_const_vec = {false};
417+ bn_op->SetIsInputConst(is_in_const_vec);
418+ 
419+ ge::AttrUtils::SetInt(bn_op, FE_IMPLY_TYPE, static_cast<int>(EN_IMPL_HW_TBE));
420+ ge::AttrUtils::SetInt(relu_op, FE_IMPLY_TYPE, static_cast<int>(EN_IMPL_HW_TBE));
421+ ge::AttrUtils::SetInt(max_op, FE_IMPLY_TYPE, static_cast<int>(EN_IMPL_HW_TBE));
422+ 
423+ NodePtr bn_node = graph->AddNode(bn_op);
424+ NodePtr relu_node = graph->AddNode(relu_op);
425+ NodePtr const_node = graph->AddNode(const_op);
426+ NodePtr max_node = graph->AddNode(max_op);
427+ 
428+ GraphUtils::AddEdge(bn_node->GetOutDataAnchor(0), relu_node->GetInDataAnchor(0));
429+ GraphUtils::AddEdge(relu_node->GetOutDataAnchor(0), max_node->GetInDataAnchor(0));
430+ GraphUtils::AddEdge(const_node->GetOutDataAnchor(0), max_node->GetInDataAnchor(1));
431+ if (set_fusion_scope_flag) {
432+ ge::AttrUtils::SetInt(bn_op, "fusion_scope", -1);
433+ ge::AttrUtils::SetInt(relu_op, "fusion_scope", -2);
434+ ge::AttrUtils::SetInt(max_op, "fusion_scope", -3);
435+ }
436+}
437+ 
438+void UTEST_fusion_engine_fe_graph_optimizer::CreateTwoOpDescGraph2(ComputeGraphPtr graph) {
439+ OpDescPtr bn_op = std::make_shared<OpDesc>("batchnormal", "BatchNorm");
440+ // add descriptor
441+ vector<int64_t> dims1 = {0, 2, 3, 4};
442+ GeShape shape1(dims1);
443+ vector<int64_t> dims2 = {1, 2, 3, 4};
444+ GeShape shape2(dims2);
445+ vector<int64_t> dims3 = {1, 2, 3, 4};
446+ GeShape shape3(dims3);
447+ vector<int64_t> dims4 = {1, 2, 3, 4};
448+ GeShape shape4(dims4);
449+ 
450+ GeTensorDesc in_desc1(shape1);
451+ in_desc1.SetFormat(FORMAT_NCHW);
452+ in_desc1.SetDataType(DT_FLOAT16);
453+ bn_op->AddInputDesc("x1", in_desc1);
454+ 
455+ GeTensorDesc in_desc2(shape2);
456+ in_desc2.SetFormat(FORMAT_NCHW);
457+ in_desc2.SetDataType(DT_FLOAT16);
458+ bn_op->AddInputDesc("x2", in_desc2);
459+ 
460+ GeTensorDesc out_desc1(shape3);
461+ out_desc1.SetFormat(FORMAT_NCHW);
462+ out_desc1.SetDataType(DT_FLOAT16);
463+ bn_op->AddOutputDesc("y1", out_desc1);
464+ 
465+ GeTensorDesc out_desc2(shape4);
466+ out_desc2.SetFormat(FORMAT_NCHW);
467+ out_desc2.SetDataType(DT_FLOAT16);
468+ bn_op->AddOutputDesc("y2", out_desc2);
469+ 
470+ ge::AttrUtils::SetInt(bn_op, FE_IMPLY_TYPE, static_cast<int>(EN_IMPL_HW_TBE));
471+ 
472+ NodePtr bn_node = graph->AddNode(bn_op);
473+}
474+ 
475+void UTEST_fusion_engine_fe_graph_optimizer::CreateUnknownShapeGraph(ComputeGraphPtr graph) {
476+ OpDescPtr bn_op = std::make_shared<OpDesc>("batchnormal", "BatchNorm");
477+ // add descriptor
478+ vector<int64_t> dims1 = {0, -1, 3, 4};
479+ GeShape shape1(dims1);
480+ vector<int64_t> dims2 = {1, -1, 3, 4};
481+ GeShape shape2(dims2);
482+ vector<int64_t> dims3 = {1, 2, -1, 4};
483+ GeShape shape3(dims3);
484+ vector<int64_t> dims4 = {1, 2, 3, -1};
485+ GeShape shape4(dims4);
486+ 
487+ GeTensorDesc in_desc1(shape1);
488+ in_desc1.SetFormat(FORMAT_NCHW);
489+ in_desc1.SetDataType(DT_FLOAT16);
490+ bn_op->AddInputDesc("x1", in_desc1);
491+ 
492+ GeTensorDesc in_desc2(shape2);
493+ in_desc2.SetFormat(FORMAT_NCHW);
494+ in_desc2.SetDataType(DT_FLOAT16);
495+ bn_op->AddInputDesc("x2", in_desc2);
496+ 
497+ GeTensorDesc out_desc1(shape3);
498+ out_desc1.SetFormat(FORMAT_NCHW);
499+ out_desc1.SetDataType(DT_FLOAT16);
500+ bn_op->AddOutputDesc("y1", out_desc1);
501+ 
502+ GeTensorDesc out_desc2(shape4);
503+ out_desc2.SetFormat(FORMAT_NCHW);
504+ out_desc2.SetDataType(DT_FLOAT16);
505+ bn_op->AddOutputDesc("y2", out_desc2);
506+ 
507+ ge::AttrUtils::SetInt(bn_op, FE_IMPLY_TYPE, static_cast<int>(EN_IMPL_HW_TBE));
508+ 
509+ NodePtr bn_node = graph->AddNode(bn_op);
510+}
511+ 
512+void UTEST_fusion_engine_fe_graph_optimizer::CreateTwoOpDescGraph3(ComputeGraphPtr graph) {
513+ OpDescPtr bn_op = std::make_shared<OpDesc>("batchnormal", "BatchNorm");
514+ // add descriptor
515+ vector<int64_t> dims1 = {1, 2, 3, 4};
516+ GeShape shape1(dims1);
517+ vector<int64_t> dims2 = {0, 2, 3, 4};
518+ GeShape shape2(dims2);
519+ vector<int64_t> dims3 = {1, 2, 3, 4};
520+ GeShape shape3(dims3);
521+ vector<int64_t> dims4 = {1, 2, 3, 4};
522+ GeShape shape4(dims4);
523+ 
524+ GeTensorDesc in_desc1(shape1);
525+ in_desc1.SetFormat(FORMAT_NCHW);
526+ in_desc1.SetDataType(DT_FLOAT16);
527+ bn_op->AddInputDesc("x1", in_desc1);
528+ 
529+ GeTensorDesc in_desc2(shape2);
530+ in_desc2.SetFormat(FORMAT_NCHW);
531+ in_desc2.SetDataType(DT_FLOAT16);
532+ bn_op->AddInputDesc("x2", in_desc2);
533+ 
534+ GeTensorDesc out_desc1(shape3);
535+ out_desc1.SetFormat(FORMAT_NCHW);
536+ out_desc1.SetDataType(DT_FLOAT16);
537+ bn_op->AddOutputDesc("y1", out_desc1);
538+ 
539+ GeTensorDesc out_desc2(shape4);
540+ out_desc2.SetFormat(FORMAT_NCHW);
541+ out_desc2.SetDataType(DT_FLOAT16);
542+ bn_op->AddOutputDesc("y2", out_desc2);
543+ 
544+ ge::AttrUtils::SetInt(bn_op, FE_IMPLY_TYPE, static_cast<int>(EN_IMPL_HW_TBE));
545+ 
546+ NodePtr bn_node = graph->AddNode(bn_op);
547+}
548+ 
549+void UTEST_fusion_engine_fe_graph_optimizer::CreateTwoOpDescGraph4(ComputeGraphPtr graph) {
550+ OpDescPtr bn_op = std::make_shared<OpDesc>("batchnormal", "BatchNorm");
551+ // add descriptor
552+ vector<int64_t> dims1 = {1, 2, 3, 4};
553+ GeShape shape1(dims1);
554+ vector<int64_t> dims2 = {1, 2, 3, 4};
555+ GeShape shape2(dims2);
556+ vector<int64_t> dims3 = {0, 2, 3, 4};
557+ GeShape shape3(dims3);
558+ vector<int64_t> dims4 = {1, 2, 3, 4};
559+ GeShape shape4(dims4);
560+ 
561+ GeTensorDesc in_desc1(shape1);
562+ in_desc1.SetFormat(FORMAT_NCHW);
563+ in_desc1.SetDataType(DT_FLOAT16);
564+ bn_op->AddInputDesc("x1", in_desc1);
565+ 
566+ GeTensorDesc in_desc2(shape2);
567+ in_desc2.SetFormat(FORMAT_NCHW);
568+ in_desc2.SetDataType(DT_FLOAT16);
569+ bn_op->AddInputDesc("x2", in_desc2);
570+ 
571+ GeTensorDesc out_desc1(shape3);
572+ out_desc1.SetFormat(FORMAT_NCHW);
573+ out_desc1.SetDataType(DT_FLOAT16);
574+ bn_op->AddOutputDesc("y1", out_desc1);
575+ 
576+ GeTensorDesc out_desc2(shape4);
577+ out_desc2.SetFormat(FORMAT_NCHW);
578+ out_desc2.SetDataType(DT_FLOAT16);
579+ bn_op->AddOutputDesc("y2", out_desc2);
580+ 
581+ ge::AttrUtils::SetInt(bn_op, FE_IMPLY_TYPE, static_cast<int>(EN_IMPL_HW_TBE));
582+ 
583+ NodePtr bn_node = graph->AddNode(bn_op);
584+}
585+ 
586+void UTEST_fusion_engine_fe_graph_optimizer::CreateTwoOpDescGraph5(ComputeGraphPtr graph) {
587+ OpDescPtr bn_op = std::make_shared<OpDesc>("batchnormal", "BatchNorm");
588+ // add descriptor
589+ vector<int64_t> dims1 = {1, 2, 3, 4};
590+ GeShape shape1(dims1);
591+ vector<int64_t> dims2 = {1, 2, 3, 4};
592+ GeShape shape2(dims2);
593+ vector<int64_t> dims3 = {1, 2, 3, 4};
594+ GeShape shape3(dims3);
595+ vector<int64_t> dims4 = {0, 2, 3, 4};
596+ GeShape shape4(dims4);
597+ 
598+ GeTensorDesc in_desc1(shape1);
599+ in_desc1.SetFormat(FORMAT_NCHW);
600+ in_desc1.SetDataType(DT_FLOAT16);
601+ bn_op->AddInputDesc("x1", in_desc1);
602+ 
603+ GeTensorDesc in_desc2(shape2);
604+ in_desc2.SetFormat(FORMAT_NCHW);
605+ in_desc2.SetDataType(DT_FLOAT16);
606+ bn_op->AddInputDesc("x2", in_desc2);
607+ 
608+ GeTensorDesc out_desc1(shape3);
609+ out_desc1.SetFormat(FORMAT_NCHW);
610+ out_desc1.SetDataType(DT_FLOAT16);
611+ bn_op->AddOutputDesc("y1", out_desc1);
612+ 
613+ GeTensorDesc out_desc2(shape4);
614+ out_desc2.SetFormat(FORMAT_NCHW);
615+ out_desc2.SetDataType(DT_FLOAT16);
616+ bn_op->AddOutputDesc("y2", out_desc2);
617+ 
618+ ge::AttrUtils::SetInt(bn_op, FE_IMPLY_TYPE, static_cast<int>(EN_IMPL_HW_TBE));
619+ 
620+ NodePtr bn_node = graph->AddNode(bn_op);
621+}
622+ 
623+void UTEST_fusion_engine_fe_graph_optimizer::CreateTwoOpDescGraph6(ComputeGraphPtr graph) {
624+ OpDescPtr bn_op = std::make_shared<OpDesc>("batchnormal", "BatchNorm");
625+ // add descriptor
626+ vector<int64_t> dims1 = {1, 2, 3, 4};
627+ GeShape shape1(dims1);
628+ vector<int64_t> dims2 = {1, 0, 3, 4};
629+ GeShape shape2(dims2);
630+ vector<int64_t> dims3 = {1, 2, 3, 4};
631+ GeShape shape3(dims3);
632+ vector<int64_t> dims4 = {1, 2, 3, 4};
633+ GeShape shape4(dims4);
634+ 
635+ GeTensorDesc in_desc1(shape1);
636+ in_desc1.SetFormat(FORMAT_NCHW);
637+ in_desc1.SetDataType(DT_FLOAT16);
638+ bn_op->AddInputDesc("x1", in_desc1);
639+ 
640+ GeTensorDesc in_desc2(shape2);
641+ in_desc2.SetFormat(FORMAT_NCHW);
642+ in_desc2.SetDataType(DT_FLOAT16);
643+ bn_op->AddInputDesc("x2", in_desc2);
644+ 
645+ GeTensorDesc out_desc1(shape3);
646+ out_desc1.SetFormat(FORMAT_NCHW);
647+ out_desc1.SetDataType(DT_FLOAT16);
648+ bn_op->AddOutputDesc("y1", out_desc1);
649+ 
650+ GeTensorDesc out_desc2(shape4);
651+ out_desc2.SetFormat(FORMAT_NCHW);
652+ out_desc2.SetDataType(DT_FLOAT16);
653+ bn_op->AddOutputDesc("y2", out_desc2);
654+ 
655+ ge::AttrUtils::SetInt(bn_op, FE_IMPLY_TYPE, static_cast<int>(EN_IMPL_HW_TBE));
656+ 
657+ NodePtr bn_node = graph->AddNode(bn_op);
658+}
659+ 
660+void UTEST_fusion_engine_fe_graph_optimizer::CreateTwoOpDescGraph7(ComputeGraphPtr graph) {
661+ OpDescPtr bn_op = std::make_shared<OpDesc>("batchnormal", "BatchNorm");
662+ // add descriptor
663+ vector<int64_t> dims1 = {1, 2, 3, 4};
664+ GeShape shape1(dims1);
665+ vector<int64_t> dims2 = {1, 2, 3, 4};
666+ GeShape shape2(dims2);
667+ vector<int64_t> dims3 = {1, 2, 3, 4};
668+ GeShape shape3(dims3);
669+ vector<int64_t> dims4 = {1, 0, 3, 4};
670+ GeShape shape4(dims4);
671+ 
672+ GeTensorDesc in_desc1(shape1);
673+ in_desc1.SetFormat(FORMAT_NCHW);
674+ in_desc1.SetDataType(DT_FLOAT16);
675+ bn_op->AddInputDesc("x1", in_desc1);
676+ 
677+ GeTensorDesc in_desc2(shape2);
678+ in_desc2.SetFormat(FORMAT_NCHW);
679+ in_desc2.SetDataType(DT_FLOAT16);
680+ bn_op->AddInputDesc("x2", in_desc2);
681+ 
682+ GeTensorDesc out_desc1(shape3);
683+ out_desc1.SetFormat(FORMAT_NCHW);
684+ out_desc1.SetDataType(DT_FLOAT16);
685+ bn_op->AddOutputDesc("y1", out_desc1);
686+ 
687+ GeTensorDesc out_desc2(shape4);
688+ out_desc2.SetFormat(FORMAT_NCHW);
689+ out_desc2.SetDataType(DT_FLOAT16);
690+ bn_op->AddOutputDesc("y2", out_desc2);
691+ 
692+ ge::AttrUtils::SetInt(bn_op, FE_IMPLY_TYPE, static_cast<int>(EN_IMPL_HW_TBE));
693+ 
694+ NodePtr bn_node = graph->AddNode(bn_op);
695+}
696+ 
697+void UTEST_fusion_engine_fe_graph_optimizer::CreateSplitOpDescGraph(ComputeGraphPtr graph) {
698+ OpDescPtr bn_op = std::make_shared<OpDesc>("batchnormal", "BatchNorm");
699+ OpDescPtr split_op = std::make_shared<OpDesc>("split", "SplitD");
700+ OpDescPtr relu_op = std::make_shared<OpDesc>("relu", "Relu");
701+ // add descriptor
702+ vector<int64_t> dims = {1, 2};
703+ GeShape shape(dims);
704+ 
705+ GeTensorDesc in_desc1(shape);
706+ in_desc1.SetFormat(FORMAT_FRACTAL_NZ);
707+ in_desc1.SetOriginFormat(FORMAT_ND);
708+ in_desc1.SetOriginShape(shape);
709+ in_desc1.SetDataType(DT_FLOAT16);
710+ split_op->AddInputDesc("x", in_desc1);
711+ 
712+ GeTensorDesc out_desc1(shape);
713+ out_desc1.SetFormat(FORMAT_HWCN);
714+ out_desc1.SetOriginShape(shape);
715+ out_desc1.SetDataType(DT_FLOAT16);
716+ split_op->AddOutputDesc("y", out_desc1);
717+ 
718+ GeTensorDesc in_desc2(shape);
719+ in_desc2.SetFormat(FORMAT_FRACTAL_Z);
720+ in_desc2.SetOriginShape(shape);
721+ in_desc2.SetDataType(DT_FLOAT16);
722+ bn_op->AddInputDesc("x", in_desc2);
723+ 
724+ GeTensorDesc out_desc2(shape);
725+ out_desc2.SetFormat(FORMAT_NHWC);
726+ out_desc2.SetOriginShape(shape);
727+ out_desc2.SetDataType(DT_FLOAT16);
728+ bn_op->AddOutputDesc("y", out_desc2);
729+ 
730+ GeTensorDesc in_desc4(shape);
731+ in_desc4.SetFormat(FORMAT_NCHW);
732+ in_desc4.SetOriginShape(shape);
733+ in_desc4.SetDataType(DT_FLOAT16);
734+ relu_op->AddInputDesc("x", in_desc4);
735+ 
736+ GeTensorDesc out_desc4(shape);
737+ out_desc4.SetFormat(FORMAT_HWCN);
738+ out_desc4.SetOriginShape(shape);
739+ out_desc4.SetDataType(DT_FLOAT16);
740+ relu_op->AddOutputDesc("y", out_desc4);
741+ 
742+ std::vector<bool> is_in_const_vec = {false};
743+ bn_op->SetIsInputConst(is_in_const_vec);
744+ 
745+ ge::AttrUtils::SetInt(bn_op, FE_IMPLY_TYPE, static_cast<int>(EN_IMPL_HW_TBE));
746+ ge::AttrUtils::SetInt(split_op, FE_IMPLY_TYPE, static_cast<int>(EN_IMPL_HW_GENERAL_CCE));
747+ (void)ge::AttrUtils::SetInt(split_op, SPLIT_DIM, -4);
748+ NodePtr bn_node = graph->AddNode(bn_op);
749+ NodePtr split_node = graph->AddNode(split_op);
750+ NodePtr relu_node = graph->AddNode(relu_op);
751+ GraphUtils::AddEdge(bn_node->GetOutDataAnchor(0), split_node->GetInDataAnchor(0));
752+ GraphUtils::AddEdge(split_node->GetOutDataAnchor(0), relu_node->GetInDataAnchor(0));
753+}
754+ 
755+void UTEST_fusion_engine_fe_graph_optimizer::CreateConstSplitOpDescGraph(ComputeGraphPtr graph) {
756+ OpDescPtr const_op = std::make_shared<OpDesc>("const", "Const");
757+ OpDescPtr split_op = std::make_shared<OpDesc>("split", "SplitD");
758+ OpDescPtr relu_op = std::make_shared<OpDesc>("relu", "Relu");
759+ // add descriptor
760+ vector<int64_t> dims = {1, 2};
761+ GeShape shape(dims);
762+ 
763+ GeTensorDesc in_desc1(shape);
764+ in_desc1.SetFormat(FORMAT_NCHW);
765+ in_desc1.SetOriginFormat(FORMAT_NCHW);
766+ in_desc1.SetOriginShape(shape);
767+ in_desc1.SetDataType(DT_FLOAT16);
768+ split_op->AddInputDesc("x", in_desc1);
769+ 
770+ GeTensorDesc out_desc1(shape);
771+ out_desc1.SetFormat(FORMAT_NCHW);
772+ out_desc1.SetOriginShape(shape);
773+ out_desc1.SetDataType(DT_FLOAT16);
774+ split_op->AddOutputDesc("y", out_desc1);
775+ 
776+ GeTensorDesc out_desc2(shape);
777+ out_desc2.SetFormat(FORMAT_NCHW);
778+ out_desc2.SetOriginShape(shape);
779+ out_desc2.SetDataType(DT_FLOAT16);
780+ const_op->AddOutputDesc("y", out_desc2);
781+ 
782+ GeTensorDesc in_desc4(shape);
783+ in_desc4.SetFormat(FORMAT_NCHW);
784+ in_desc4.SetOriginShape(shape);
785+ in_desc4.SetDataType(DT_FLOAT16);
786+ relu_op->AddInputDesc("x", in_desc4);
787+ 
788+ GeTensorDesc out_desc4(shape);
789+ out_desc4.SetFormat(FORMAT_NCHW);
790+ out_desc4.SetOriginShape(shape);
791+ out_desc4.SetDataType(DT_FLOAT16);
792+ relu_op->AddOutputDesc("y", out_desc4);
793+ 
794+ ge::AttrUtils::SetInt(const_op, FE_IMPLY_TYPE, static_cast<int>(EN_IMPL_HW_TBE));
795+ ge::AttrUtils::SetInt(split_op, FE_IMPLY_TYPE, static_cast<int>(EN_IMPL_HW_GENERAL_CCE));
796+ (void)ge::AttrUtils::SetInt(split_op, SPLIT_DIM, 0);
797+ NodePtr const_node = graph->AddNode(const_op);
798+ NodePtr split_node = graph->AddNode(split_op);
799+ NodePtr relu_node = graph->AddNode(relu_op);
800+ GraphUtils::AddEdge(const_node->GetOutDataAnchor(0), split_node->GetInDataAnchor(0));
801+ GraphUtils::AddEdge(split_node->GetOutDataAnchor(0), relu_node->GetInDataAnchor(0));
802+}
803+ 
804+void UTEST_fusion_engine_fe_graph_optimizer::CreateDataSplitOpDescGraph(ComputeGraphPtr graph) {
805+ OpDescPtr data = std::make_shared<OpDesc>("data", DATA);
806+ OpDescPtr split = std::make_shared<OpDesc>("split", SPLITD);
807+ OpDescPtr relu1 = std::make_shared<OpDesc>("relu1", RELU);
808+ OpDescPtr relu2 = std::make_shared<OpDesc>("relu2", RELU);
809+ 
810+ ge::GeShape shape1({2, 4, 9, 16});
811+ GeTensorDesc tensor_desc1(shape1, ge::FORMAT_NCHW, ge::DT_FLOAT16);
812+ tensor_desc1.SetOriginFormat(ge::FORMAT_NCHW);
813+ tensor_desc1.SetOriginDataType(ge::DT_FLOAT16);
814+ tensor_desc1.SetOriginShape(shape1);
815+ data->AddOutputDesc(tensor_desc1);
816+ split->AddInputDesc(tensor_desc1);
817+ 
818+ ge::GeShape shape2({1, 4, 9, 16});
819+ GeTensorDesc tensor_desc2(shape2, ge::FORMAT_NCHW, ge::DT_FLOAT16);
820+ tensor_desc2.SetOriginFormat(ge::FORMAT_NCHW);
821+ tensor_desc2.SetOriginDataType(ge::DT_FLOAT16);
822+ tensor_desc2.SetOriginShape(shape2);
823+ split->AddOutputDesc(tensor_desc2);
824+ split->AddOutputDesc(tensor_desc2);
825+ relu1->AddInputDesc(tensor_desc2);
826+ relu2->AddInputDesc(tensor_desc2);
827+ 
828+ (void)ge::AttrUtils::SetInt(split, SPLIT_DIM, 0);
829+ (void)ge::AttrUtils::SetInt(relu1, ge::ATTR_NAME_IMPLY_TYPE, static_cast<int>(domi::ImplyType::TVM));
830+ (void)ge::AttrUtils::SetInt(relu2, ge::ATTR_NAME_IMPLY_TYPE, static_cast<int>(domi::ImplyType::TVM));
831+ 
832+ NodePtr data_node = graph->AddNode(data);
833+ NodePtr split_node = graph->AddNode(split);
834+ NodePtr relu1_node = graph->AddNode(relu1);
835+ NodePtr relu2_node = graph->AddNode(relu2);
836+ 
837+ ge::GraphUtils::AddEdge(data_node->GetOutDataAnchor(0), split_node->GetInDataAnchor(0));
838+ ge::GraphUtils::AddEdge(split_node->GetOutDataAnchor(0), relu1_node->GetInDataAnchor(0));
839+ ge::GraphUtils::AddEdge(split_node->GetOutDataAnchor(1), relu2_node->GetInDataAnchor(0));
840+}
841+ 
842+void UTEST_fusion_engine_fe_graph_optimizer::CreateConcatGraphDescs(OpDescPtr &bn_op, OpDescPtr &shape_op,
843+ OpDescPtr &concat_op, OpDescPtr &relu_op) {
844+ bn_op = std::make_shared<OpDesc>("batchnormal", "BatchNorm");
845+ shape_op = std::make_shared<OpDesc>("shape", "Shape");
846+ concat_op = std::make_shared<OpDesc>("concat", "ConcatD");
847+ relu_op = std::make_shared<OpDesc>("relu", "Relu");
848+ vector<int64_t> dims = {1, 2};
849+ GeShape shape(dims);
850+ GeTensorDesc in_desc1(shape, FORMAT_FRACTAL_NZ, DT_FLOAT16);
851+ in_desc1.SetOriginFormat(FORMAT_ND);
852+ in_desc1.SetOriginShape(shape);
853+ concat_op->AddInputDesc("x", in_desc1);
854+ GeTensorDesc in_desc11(shape, FORMAT_NCHW, DT_FLOAT16);
855+ in_desc11.SetOriginShape(shape);
856+ concat_op->AddInputDesc("z", in_desc11);
857+ GeTensorDesc out_desc1(shape, FORMAT_HWCN, DT_FLOAT16);
858+ out_desc1.SetOriginShape(shape);
859+ concat_op->AddOutputDesc("y", out_desc1);
860+ GeTensorDesc in_desc2(shape, FORMAT_FRACTAL_Z, DT_FLOAT16);
861+ in_desc2.SetOriginShape(shape);
862+ bn_op->AddInputDesc("x", in_desc2);
863+ GeTensorDesc out_desc2(shape, FORMAT_NHWC, DT_FLOAT16);
864+ out_desc2.SetOriginShape(shape);
865+ bn_op->AddOutputDesc("y", out_desc2);
866+ GeTensorDesc in_desc3(shape, FORMAT_NCHW, DT_FLOAT16);
867+ in_desc3.SetOriginShape(shape);
868+ shape_op->AddInputDesc("x", in_desc3);
869+ GeTensorDesc out_desc3(shape, FORMAT_HWCN, DT_FLOAT16);
870+ out_desc3.SetOriginShape(shape);
871+ shape_op->AddOutputDesc("y", out_desc3);
872+ GeTensorDesc in_desc4(shape, FORMAT_NCHW, DT_FLOAT16);
873+ in_desc4.SetOriginShape(shape);
874+ relu_op->AddInputDesc("x", in_desc4);
875+ GeTensorDesc out_desc4(shape, FORMAT_HWCN, DT_FLOAT16);
876+ out_desc4.SetOriginShape(shape);
877+ relu_op->AddOutputDesc("y", out_desc4);
878+}
879+ 
880+void UTEST_fusion_engine_fe_graph_optimizer::CreateConcatOpDescGraph(ComputeGraphPtr graph) {
881+ OpDescPtr bn_op;
882+ OpDescPtr shape_op;
883+ OpDescPtr concat_op;
884+ OpDescPtr relu_op;
885+ CreateConcatGraphDescs(bn_op, shape_op, concat_op, relu_op);
886+ 
887+ std::vector<bool> is_in_const_vec = {false};
888+ bn_op->SetIsInputConst(is_in_const_vec);
889+ 
890+ ge::AttrUtils::SetInt(bn_op, FE_IMPLY_TYPE, static_cast<int>(EN_IMPL_HW_TBE));
891+ ge::AttrUtils::SetInt(concat_op, FE_IMPLY_TYPE, static_cast<int>(EN_IMPL_HW_GENERAL_CCE));
892+ (void)ge::AttrUtils::SetInt(concat_op, CONCAT_DIM, -4);
893+ NodePtr bn_node = graph->AddNode(bn_op);
894+ NodePtr concat_node = graph->AddNode(concat_op);
895+ NodePtr shape_node = graph->AddNode(shape_op);
896+ NodePtr relu_node = graph->AddNode(relu_op);
897+ 
898+ GraphUtils::AddEdge(bn_node->GetOutDataAnchor(0), concat_node->GetInDataAnchor(0));
899+ GraphUtils::AddEdge(shape_node->GetOutDataAnchor(0), concat_node->GetInDataAnchor(1));
900+ GraphUtils::AddEdge(concat_node->GetOutDataAnchor(0), relu_node->GetInDataAnchor(0));
901+}
902+ 
903+void UTEST_fusion_engine_fe_graph_optimizer::CreateConcatOpDescGraph2(ComputeGraphPtr graph) {
904+ OpDescPtr placeholder_op = std::make_shared<OpDesc>("placeholder", "PlaceHolder");
905+ OpDescPtr shape_op = std::make_shared<OpDesc>("shape", "Shape");
906+ OpDescPtr concat_op = std::make_shared<OpDesc>("concat", "ConcatD");
907+ 
908+ // add descriptor
909+ vector<int64_t> dims = {1, 2};
910+ GeShape shape(dims);
911+ 
912+ GeTensorDesc in_desc1(shape);
913+ in_desc1.SetFormat(FORMAT_FRACTAL_NZ);
914+ in_desc1.SetOriginShape(shape);
915+ in_desc1.SetDataType(DT_FLOAT16);
916+ concat_op->AddInputDesc("x", in_desc1);
917+ 
918+ GeTensorDesc in_desc11(shape);
919+ in_desc11.SetFormat(FORMAT_FRACTAL_NZ);
920+ in_desc1.SetOriginShape(shape);
921+ in_desc11.SetDataType(DT_FLOAT16);
922+ concat_op->AddInputDesc("z", in_desc11);
923+ 
924+ GeTensorDesc out_desc1(shape);
925+ out_desc1.SetFormat(FORMAT_HWCN);
926+ out_desc1.SetDataType(DT_FLOAT16);
927+ concat_op->AddOutputDesc("y", out_desc1);
928+ 
929+ GeTensorDesc in_desc2(shape);
930+ in_desc2.SetFormat(FORMAT_FRACTAL_Z);
931+ in_desc2.SetDataType(DT_FLOAT16);
932+ placeholder_op->AddInputDesc("x", in_desc2);
933+ 
934+ GeTensorDesc out_desc2(shape);
935+ out_desc2.SetFormat(FORMAT_NHWC);
936+ out_desc2.SetDataType(DT_FLOAT16);
937+ placeholder_op->AddOutputDesc("y", out_desc2);
938+ 
939+ GeTensorDesc in_desc3(shape);
940+ in_desc3.SetFormat(FORMAT_NCHW);
941+ in_desc3.SetDataType(DT_FLOAT16);
942+ shape_op->AddInputDesc("x", in_desc3);
943+ 
944+ GeTensorDesc out_desc3(shape);
945+ out_desc3.SetFormat(FORMAT_HWCN);
946+ out_desc3.SetDataType(DT_FLOAT16);
947+ shape_op->AddOutputDesc("y", out_desc3);
948+ 
949+ std::vector<bool> is_in_const_vec = {false};
950+ placeholder_op->SetIsInputConst(is_in_const_vec);
951+ 
952+ ge::AttrUtils::SetInt(placeholder_op, FE_IMPLY_TYPE, static_cast<int>(EN_IMPL_HW_TBE));
953+ ge::AttrUtils::SetInt(concat_op, FE_IMPLY_TYPE, static_cast<int>(EN_IMPL_HW_GENERAL_CCE));
954+ (void)ge::AttrUtils::SetInt(concat_op, CONCAT_DIM, 1);
955+ NodePtr placeholder_node = graph->AddNode(placeholder_op);
956+ NodePtr concat_node = graph->AddNode(concat_op);
957+ NodePtr shape_node = graph->AddNode(shape_op);
958+ GraphUtils::AddEdge(placeholder_node->GetOutDataAnchor(0), concat_node->GetInDataAnchor(0));
959+ GraphUtils::AddEdge(shape_node->GetOutDataAnchor(0), concat_node->GetInDataAnchor(1));
960+}
961+ 
962+void UTEST_fusion_engine_fe_graph_optimizer::CreateConcatOpDescGraph3(ComputeGraphPtr graph) {
963+ OpDescPtr bn_op = std::make_shared<OpDesc>("batchnormal", "BatchNorm");
964+ OpDescPtr shape_op = std::make_shared<OpDesc>("shape", "Shape");
965+ OpDescPtr concat_op = std::make_shared<OpDesc>("concat", "ConcatD");
966+ 
967+ // add descriptor
968+ vector<int64_t> dims = {1, 2, 3, 32};
969+ GeShape shape(dims);
970+ 
971+ GeTensorDesc in_desc1(shape);
972+ in_desc1.SetFormat(FORMAT_NCHW);
973+ in_desc1.SetDataType(DT_FLOAT16);
974+ concat_op->AddInputDesc("x", in_desc1);
975+ 
976+ GeTensorDesc in_desc11(shape);
977+ in_desc11.SetFormat(FORMAT_NCHW);
978+ in_desc11.SetDataType(DT_FLOAT16);
979+ concat_op->AddInputDesc("z", in_desc11);
980+ 
981+ GeTensorDesc out_desc1(shape);
982+ out_desc1.SetFormat(FORMAT_HWCN);
983+ out_desc1.SetDataType(DT_FLOAT16);
984+ concat_op->AddOutputDesc("y", out_desc1);
985+ 
986+ GeTensorDesc in_desc2(shape);
987+ in_desc2.SetFormat(FORMAT_FRACTAL_Z);
988+ in_desc2.SetDataType(DT_FLOAT16);
989+ bn_op->AddInputDesc("x", in_desc2);
990+ 
991+ GeTensorDesc out_desc2(shape);
992+ out_desc2.SetFormat(FORMAT_NHWC);
993+ out_desc2.SetDataType(DT_FLOAT16);
994+ bn_op->AddOutputDesc("y", out_desc2);
995+ 
996+ GeTensorDesc in_desc3(shape);
997+ in_desc3.SetFormat(FORMAT_NCHW);
998+ in_desc3.SetDataType(DT_FLOAT16);
999+ shape_op->AddInputDesc("x", in_desc3);
1000+ 
1001+ GeTensorDesc out_desc3(shape);
1002+ out_desc3.SetFormat(FORMAT_HWCN);
1003+ out_desc3.SetDataType(DT_FLOAT16);
1004+ shape_op->AddOutputDesc("y", out_desc3);
1005+ 
1006+ std::vector<bool> is_in_const_vec = {false};
1007+ bn_op->SetIsInputConst(is_in_const_vec);
1008+ 
1009+ ge::AttrUtils::SetInt(bn_op, FE_IMPLY_TYPE, static_cast<int>(EN_IMPL_HW_TBE));
1010+ ge::AttrUtils::SetInt(concat_op, FE_IMPLY_TYPE, static_cast<int>(EN_IMPL_HW_GENERAL_CCE));
1011+ (void)ge::AttrUtils::SetInt(concat_op, CONCAT_DIM, 0);
1012+ ge::AttrUtils::SetBool(bn_op, ge::ATTR_NAME_CONTINUOUS_INPUT, true);
1013+ NodePtr bn_node = graph->AddNode(bn_op);
1014+ NodePtr concat_node = graph->AddNode(concat_op);
1015+ NodePtr shape_node = graph->AddNode(shape_op);
1016+ GraphUtils::AddEdge(bn_node->GetOutDataAnchor(0), concat_node->GetInDataAnchor(0));
1017+ GraphUtils::AddEdge(shape_node->GetOutDataAnchor(0), concat_node->GetInDataAnchor(1));
1018+}
1019+ 
1020+void UTEST_fusion_engine_fe_graph_optimizer::CreateConcatOpDescGraph4(ComputeGraphPtr graph) {
1021+ OpDescPtr bn_op = std::make_shared<OpDesc>("batchnormal", "BatchNorm");
1022+ OpDescPtr shape_op = std::make_shared<OpDesc>("shape", "Shape");
1023+ OpDescPtr concat_op = std::make_shared<OpDesc>("concat", "ConcatD");
1024+ 
1025+ // add descriptor
1026+ vector<int64_t> dims = {1, 2, 3, 32};
1027+ GeShape shape(dims);
1028+ 
1029+ GeTensorDesc in_desc1(shape);
1030+ in_desc1.SetFormat(FORMAT_NCHW);
1031+ in_desc1.SetDataType(DT_FLOAT16);
1032+ concat_op->AddInputDesc("x", in_desc1);
1033+ 
1034+ GeTensorDesc in_desc11(shape);
1035+ in_desc11.SetFormat(FORMAT_NCHW);
1036+ in_desc11.SetDataType(DT_FLOAT16);
1037+ concat_op->AddInputDesc("z", in_desc11);
1038+ 
1039+ GeTensorDesc out_desc1(shape);
1040+ out_desc1.SetFormat(FORMAT_HWCN);
1041+ out_desc1.SetDataType(DT_FLOAT16);
1042+ concat_op->AddOutputDesc("y", out_desc1);
1043+ 
1044+ GeTensorDesc in_desc2(shape);
1045+ in_desc2.SetFormat(FORMAT_FRACTAL_Z);
1046+ in_desc2.SetDataType(DT_FLOAT16);
1047+ bn_op->AddInputDesc("x", in_desc2);
1048+ 
1049+ GeTensorDesc out_desc2(shape);
1050+ out_desc2.SetFormat(FORMAT_NHWC);
1051+ out_desc2.SetDataType(DT_FLOAT16);
1052+ bn_op->AddOutputDesc("y", out_desc2);
1053+ 
1054+ GeTensorDesc in_desc3(shape);
1055+ in_desc3.SetFormat(FORMAT_NCHW);
1056+ in_desc3.SetDataType(DT_FLOAT16);
1057+ shape_op->AddInputDesc("x", in_desc3);
1058+ 
1059+ GeTensorDesc out_desc3(shape);
1060+ out_desc3.SetFormat(FORMAT_HWCN);
1061+ out_desc3.SetDataType(DT_FLOAT16);
1062+ shape_op->AddOutputDesc("y", out_desc3);
1063+ 
1064+ std::vector<bool> is_in_const_vec = {false};
1065+ bn_op->SetIsInputConst(is_in_const_vec);
1066+ 
1067+ ge::AttrUtils::SetInt(bn_op, FE_IMPLY_TYPE, static_cast<int>(EN_IMPL_HW_TBE));
1068+ ge::AttrUtils::SetInt(concat_op, FE_IMPLY_TYPE, static_cast<int>(EN_IMPL_HW_GENERAL_CCE));
1069+ (void)ge::AttrUtils::SetInt(concat_op, CONCAT_DIM, 0);
1070+ ge::AttrUtils::SetBool(bn_op, ge::ATTR_NAME_CONTINUOUS_OUTPUT, true);
1071+ NodePtr bn_node = graph->AddNode(bn_op);
1072+ NodePtr concat_node = graph->AddNode(concat_op);
1073+ NodePtr shape_node = graph->AddNode(shape_op);
1074+ GraphUtils::AddEdge(bn_node->GetOutDataAnchor(0), concat_node->GetInDataAnchor(0));
1075+ GraphUtils::AddEdge(shape_node->GetOutDataAnchor(0), concat_node->GetInDataAnchor(1));
1076+}
1077+ 
1078+void UTEST_fusion_engine_fe_graph_optimizer::CreateConcatOpDescGraph5(ComputeGraphPtr graph) {
1079+ OpDescPtr bn_op = std::make_shared<OpDesc>("batchnormal", "BatchNorm");
1080+ OpDescPtr shape_op = std::make_shared<OpDesc>("shape", "Shape");
1081+ OpDescPtr concat_op = std::make_shared<OpDesc>("concat", "ConcatD");
1082+ 
1083+ // add descriptor
1084+ vector<int64_t> dims = {1, 2, 3, 32};
1085+ GeShape shape(dims);
1086+ 
1087+ GeTensorDesc in_desc1(shape);
1088+ in_desc1.SetFormat(FORMAT_NCHW);
1089+ in_desc1.SetDataType(DT_FLOAT16);
1090+ concat_op->AddInputDesc("x", in_desc1);
1091+ 
1092+ GeTensorDesc in_desc11(shape);
1093+ in_desc11.SetFormat(FORMAT_NCHW);
1094+ in_desc11.SetDataType(DT_FLOAT16);
1095+ concat_op->AddInputDesc("z", in_desc11);
1096+ 
1097+ GeTensorDesc out_desc1(shape);
1098+ out_desc1.SetFormat(FORMAT_HWCN);
1099+ out_desc1.SetDataType(DT_FLOAT16);
1100+ concat_op->AddOutputDesc("y", out_desc1);
1101+ 
1102+ GeTensorDesc in_desc2(shape);
1103+ in_desc2.SetFormat(FORMAT_FRACTAL_Z);
1104+ in_desc2.SetDataType(DT_FLOAT16);
1105+ bn_op->AddInputDesc("x", in_desc2);
1106+ 
1107+ GeTensorDesc out_desc2(shape);
1108+ out_desc2.SetFormat(FORMAT_NHWC);
1109+ out_desc2.SetDataType(DT_FLOAT16);
1110+ bn_op->AddOutputDesc("y", out_desc2);
1111+ 
1112+ GeTensorDesc in_desc3(shape);
1113+ in_desc3.SetFormat(FORMAT_NCHW);
1114+ in_desc3.SetDataType(DT_FLOAT16);
1115+ shape_op->AddInputDesc("x", in_desc3);
1116+ 
1117+ GeTensorDesc out_desc3(shape);
1118+ out_desc3.SetFormat(FORMAT_HWCN);
1119+ out_desc3.SetDataType(DT_FLOAT16);
1120+ shape_op->AddOutputDesc("y", out_desc3);
1121+ 
1122+ std::vector<bool> is_in_const_vec = {false};
1123+ bn_op->SetIsInputConst(is_in_const_vec);
1124+ 
1125+ ge::AttrUtils::SetInt(bn_op, FE_IMPLY_TYPE, static_cast<int>(EN_IMPL_HW_TBE));
1126+ ge::AttrUtils::SetInt(concat_op, FE_IMPLY_TYPE, static_cast<int>(EN_IMPL_HW_GENERAL_CCE));
1127+ (void)ge::AttrUtils::SetInt(concat_op, CONCAT_DIM, 0);
1128+ ge::AttrUtils::SetBool(bn_op, ge::ATTR_NAME_REFERENCE, true);
1129+ NodePtr bn_node = graph->AddNode(bn_op);
1130+ NodePtr concat_node = graph->AddNode(concat_op);
1131+ NodePtr shape_node = graph->AddNode(shape_op);
1132+ GraphUtils::AddEdge(bn_node->GetOutDataAnchor(0), concat_node->GetInDataAnchor(0));
1133+ GraphUtils::AddEdge(shape_node->GetOutDataAnchor(0), concat_node->GetInDataAnchor(1));
1134+}
1135+ 
1136+void UTEST_fusion_engine_fe_graph_optimizer::CreateConcat6GraphDescs(OpDescPtr &bn_op, OpDescPtr &shape_op,
1137+ OpDescPtr &concat_op, OpDescPtr &relu_op) {
1138+ bn_op = std::make_shared<OpDesc>("batchnormal", "BatchNorm");
1139+ shape_op = std::make_shared<OpDesc>("shape", "Shape");
1140+ concat_op = std::make_shared<OpDesc>("concat", "ConcatD");
1141+ relu_op = std::make_shared<OpDesc>("relu", "Relu");
1142+ vector<int64_t> dims = {1, 2, 3, 32};
1143+ GeShape shape(dims);
1144+ GeTensorDesc in_desc1(shape);
1145+ in_desc1.SetFormat(FORMAT_NCHW);
1146+ in_desc1.SetDataType(DT_FLOAT16);
1147+ concat_op->AddInputDesc("x", in_desc1);
1148+ GeTensorDesc in_desc11(shape);
1149+ in_desc11.SetFormat(FORMAT_NCHW);
1150+ in_desc11.SetDataType(DT_FLOAT16);
1151+ concat_op->AddInputDesc("z", in_desc11);
1152+ GeTensorDesc out_desc1(shape);
1153+ out_desc1.SetFormat(FORMAT_HWCN);
1154+ out_desc1.SetDataType(DT_FLOAT16);
1155+ concat_op->AddOutputDesc("y", out_desc1);
1156+ GeTensorDesc in_desc2(shape);
1157+ in_desc2.SetFormat(FORMAT_FRACTAL_Z);
1158+ in_desc2.SetDataType(DT_FLOAT16);
1159+ bn_op->AddInputDesc("x", in_desc2);
1160+ GeTensorDesc out_desc2(shape);
1161+ out_desc2.SetFormat(FORMAT_NHWC);
1162+ out_desc2.SetDataType(DT_FLOAT16);
1163+ bn_op->AddOutputDesc("y", out_desc2);
1164+ GeTensorDesc in_desc3(shape);
1165+ in_desc3.SetFormat(FORMAT_NCHW);
1166+ in_desc3.SetDataType(DT_FLOAT16);
1167+ shape_op->AddInputDesc("x", in_desc3);
1168+ GeTensorDesc out_desc3(shape);
1169+ out_desc3.SetFormat(FORMAT_HWCN);
1170+ out_desc3.SetDataType(DT_FLOAT16);
1171+ shape_op->AddOutputDesc("y", out_desc3);
1172+ GeTensorDesc in_desc4(shape);
1173+ in_desc4.SetFormat(FORMAT_NCHW);
1174+ in_desc4.SetDataType(DT_FLOAT16);
1175+ relu_op->AddInputDesc("x", in_desc4);
1176+ GeTensorDesc out_desc4(shape);
1177+ out_desc4.SetFormat(FORMAT_HWCN);
1178+ out_desc4.SetDataType(DT_FLOAT16);
1179+ relu_op->AddOutputDesc("y", out_desc4);
1180+}
1181+ 
1182+void UTEST_fusion_engine_fe_graph_optimizer::CreateConcatOpDescGraph6(ComputeGraphPtr graph) {
1183+ OpDescPtr bn_op;
1184+ OpDescPtr shape_op;
1185+ OpDescPtr concat_op;
1186+ OpDescPtr relu_op;
1187+ CreateConcat6GraphDescs(bn_op, shape_op, concat_op, relu_op);
1188+ 
1189+ std::vector<bool> is_in_const_vec = {false};
1190+ bn_op->SetIsInputConst(is_in_const_vec);
1191+ 
1192+ ge::AttrUtils::SetInt(bn_op, FE_IMPLY_TYPE, static_cast<int>(EN_IMPL_HW_TBE));
1193+ ge::AttrUtils::SetInt(concat_op, FE_IMPLY_TYPE, static_cast<int>(EN_IMPL_HW_GENERAL_CCE));
1194+ (void)ge::AttrUtils::SetInt(concat_op, CONCAT_DIM, 0);
1195+ ge::AttrUtils::SetBool(bn_op, ge::ATTR_NAME_NOTASK, true);
1196+ NodePtr bn_node = graph->AddNode(bn_op);
1197+ NodePtr concat_node = graph->AddNode(concat_op);
1198+ NodePtr shape_node = graph->AddNode(shape_op);
1199+ NodePtr relu_node = graph->AddNode(relu_op);
1200+ GraphUtils::AddEdge(bn_node->GetOutDataAnchor(0), concat_node->GetInDataAnchor(0));
1201+ GraphUtils::AddEdge(shape_node->GetOutDataAnchor(0), concat_node->GetInDataAnchor(1));
1202+ GraphUtils::AddEdge(concat_node->GetOutDataAnchor(0), relu_node->GetInDataAnchor(0));
1203+}
1204+ 
1205+void UTEST_fusion_engine_fe_graph_optimizer::CreateConcatOpDescGraph7(ComputeGraphPtr graph) {
1206+ OpDescPtr bn_op = std::make_shared<OpDesc>("batchnormal", "BatchNorm");
1207+ OpDescPtr concat_op = std::make_shared<OpDesc>("concat", "ConcatD");
1208+ OpDescPtr relu_op = std::make_shared<OpDesc>("relu", "Relu");
1209+ // add descriptor
1210+ vector<int64_t> dims = {1, 2, 3, 32};
1211+ GeShape shape(dims);
1212+ 
1213+ GeTensorDesc in_desc1(shape);
1214+ in_desc1.SetFormat(FORMAT_NCHW);
1215+ in_desc1.SetDataType(DT_FLOAT16);
1216+ concat_op->AddInputDesc("x", in_desc1);
1217+ 
1218+ GeTensorDesc out_desc1(shape);
1219+ out_desc1.SetFormat(FORMAT_HWCN);
1220+ out_desc1.SetDataType(DT_FLOAT16);
1221+ concat_op->AddOutputDesc("y", out_desc1);
1222+ 
1223+ GeTensorDesc in_desc2(shape);
1224+ in_desc2.SetFormat(FORMAT_FRACTAL_Z);
1225+ in_desc2.SetDataType(DT_FLOAT16);
1226+ bn_op->AddInputDesc("x", in_desc2);
1227+ 
1228+ GeTensorDesc out_desc2(shape);
1229+ out_desc2.SetFormat(FORMAT_NHWC);
1230+ out_desc2.SetDataType(DT_FLOAT16);
1231+ bn_op->AddOutputDesc("y", out_desc2);
1232+ std::vector<bool> is_in_const_vec = {false};
1233+ bn_op->SetIsInputConst(is_in_const_vec);
1234+ GeTensorDesc in_desc4(shape);
1235+ in_desc4.SetFormat(FORMAT_NCHW);
1236+ in_desc4.SetDataType(DT_FLOAT16);
1237+ relu_op->AddInputDesc("x", in_desc4);
1238+ 
1239+ GeTensorDesc out_desc4(shape);
1240+ out_desc4.SetFormat(FORMAT_HWCN);
1241+ out_desc4.SetDataType(DT_FLOAT16);
1242+ relu_op->AddOutputDesc("y", out_desc4);
1243+ 
1244+ ge::AttrUtils::SetInt(bn_op, FE_IMPLY_TYPE, static_cast<int>(EN_IMPL_HW_TBE));
1245+ ge::AttrUtils::SetInt(concat_op, FE_IMPLY_TYPE, static_cast<int>(EN_IMPL_HW_GENERAL_CCE));
1246+ (void)ge::AttrUtils::SetInt(concat_op, CONCAT_DIM, 0);
1247+ NodePtr bn_node = graph->AddNode(bn_op);
1248+ NodePtr concat_node = graph->AddNode(concat_op);
1249+ NodePtr relu_node = graph->AddNode(relu_op);
1250+ GraphUtils::AddEdge(bn_node->GetOutDataAnchor(0), concat_node->GetInDataAnchor(0));
1251+ GraphUtils::AddEdge(concat_node->GetOutDataAnchor(0), relu_node->GetInDataAnchor(0));
1252+}
1253+ 
1254+void UTEST_fusion_engine_fe_graph_optimizer::CreateConcatOpDescGraph8(ComputeGraphPtr graph) {
1255+ OpDescPtr bn_op = std::make_shared<OpDesc>("batchnormal", "BatchNorm");
1256+ OpDescPtr shape_op = std::make_shared<OpDesc>("shape", "Shape");
1257+ OpDescPtr concat_op = std::make_shared<OpDesc>("concat", "ConcatD");
1258+ 
1259+ // add descriptor
1260+ vector<int64_t> dims = {1, 2, 3, 32};
1261+ GeShape shape(dims);
1262+ 
1263+ GeTensorDesc in_desc1(shape);
1264+ in_desc1.SetFormat(FORMAT_NCHW);
1265+ in_desc1.SetDataType(DT_FLOAT16);
1266+ concat_op->AddInputDesc("x", in_desc1);
1267+ 
1268+ GeTensorDesc in_desc11(shape);
1269+ in_desc11.SetFormat(FORMAT_NCHW);
1270+ in_desc11.SetDataType(DT_FLOAT16);
1271+ concat_op->AddInputDesc("z", in_desc11);
1272+ 
1273+ GeTensorDesc out_desc1(shape);
1274+ out_desc1.SetFormat(FORMAT_HWCN);
1275+ out_desc1.SetDataType(DT_FLOAT16);
1276+ concat_op->AddOutputDesc("y", out_desc1);
1277+ 
1278+ GeTensorDesc in_desc2(shape);
1279+ in_desc2.SetFormat(FORMAT_FRACTAL_Z);
1280+ in_desc2.SetDataType(DT_FLOAT16);
1281+ bn_op->AddInputDesc("x", in_desc2);
1282+ 
1283+ GeTensorDesc out_desc2(shape);
1284+ out_desc2.SetFormat(FORMAT_NHWC);
1285+ out_desc2.SetDataType(DT_FLOAT16);
1286+ bn_op->AddOutputDesc("y", out_desc2);
1287+ 
1288+ GeTensorDesc in_desc3(shape);
1289+ in_desc3.SetFormat(FORMAT_NCHW);
1290+ in_desc3.SetDataType(DT_FLOAT16);
1291+ shape_op->AddInputDesc("x", in_desc3);
1292+ 
1293+ GeTensorDesc out_desc3(shape);
1294+ out_desc3.SetFormat(FORMAT_HWCN);
1295+ out_desc3.SetDataType(DT_FLOAT16);
1296+ shape_op->AddOutputDesc("y", out_desc3);
1297+ 
1298+ std::vector<bool> is_in_const_vec = {false};
1299+ bn_op->SetIsInputConst(is_in_const_vec);
1300+ 
1301+ ge::AttrUtils::SetInt(bn_op, FE_IMPLY_TYPE, static_cast<int>(EN_IMPL_HW_TBE));
1302+ ge::AttrUtils::SetInt(concat_op, FE_IMPLY_TYPE, static_cast<int>(EN_IMPL_HW_GENERAL_CCE));
1303+ (void)ge::AttrUtils::SetInt(concat_op, CONCAT_DIM, 1);
1304+ NodePtr bn_node = graph->AddNode(bn_op);
1305+ NodePtr concat_node = graph->AddNode(concat_op);
1306+ NodePtr shape_node = graph->AddNode(shape_op);
1307+ GraphUtils::AddEdge(bn_node->GetOutDataAnchor(0), concat_node->GetInDataAnchor(0));
1308+ GraphUtils::AddEdge(shape_node->GetOutDataAnchor(0), concat_node->GetInDataAnchor(1));
1309+}
1310+ 
1311+void UTEST_fusion_engine_fe_graph_optimizer::CreateConcatOpDescGraph9(ComputeGraphPtr graph) {
1312+ OpDescPtr bn_op = std::make_shared<OpDesc>("batchnormal", "BatchNorm");
1313+ OpDescPtr shape_op = std::make_shared<OpDesc>("shape", "Shape");
1314+ OpDescPtr concat_op = std::make_shared<OpDesc>("concat", "ConcatD");
1315+ 
1316+ // add descriptor
1317+ vector<int64_t> dims = {1, 2, 3, 32};
1318+ GeShape shape(dims);
1319+ 
1320+ GeTensorDesc in_desc1(shape);
1321+ in_desc1.SetFormat(FORMAT_NCHW);
1322+ in_desc1.SetDataType(DT_FLOAT16);
1323+ concat_op->AddInputDesc("x", in_desc1);
1324+ 
1325+ GeTensorDesc in_desc11(shape);
1326+ in_desc11.SetFormat(FORMAT_NCHW);
1327+ in_desc11.SetDataType(DT_FLOAT16);
1328+ concat_op->AddInputDesc("z", in_desc11);
1329+ 
1330+ GeTensorDesc out_desc1(shape);
1331+ out_desc1.SetFormat(FORMAT_HWCN);
1332+ out_desc1.SetDataType(DT_FLOAT16);
1333+ concat_op->AddOutputDesc("y", out_desc1);
1334+ 
1335+ GeTensorDesc in_desc2(shape);
1336+ in_desc2.SetFormat(FORMAT_FRACTAL_Z);
1337+ in_desc2.SetDataType(DT_FLOAT16);
1338+ bn_op->AddInputDesc("x", in_desc2);
1339+ 
1340+ GeTensorDesc out_desc2(shape);
1341+ out_desc2.SetFormat(FORMAT_NHWC);
1342+ out_desc2.SetDataType(DT_FLOAT16);
1343+ bn_op->AddOutputDesc("y", out_desc2);
1344+ 
1345+ GeTensorDesc in_desc3(shape);
1346+ in_desc3.SetFormat(FORMAT_NCHW);
1347+ in_desc3.SetDataType(DT_FLOAT16);
1348+ shape_op->AddInputDesc("x", in_desc3);
1349+ 
1350+ GeTensorDesc out_desc3(shape);
1351+ out_desc3.SetFormat(FORMAT_HWCN);
1352+ out_desc3.SetDataType(DT_FLOAT16);
1353+ shape_op->AddOutputDesc("y", out_desc3);
1354+ 
1355+ std::vector<bool> is_in_const_vec = {false};
1356+ bn_op->SetIsInputConst(is_in_const_vec);
1357+ 
1358+ ge::AttrUtils::SetInt(bn_op, FE_IMPLY_TYPE, static_cast<int>(EN_IMPL_HW_TBE));
1359+ ge::AttrUtils::SetInt(concat_op, FE_IMPLY_TYPE, static_cast<int>(EN_IMPL_HW_GENERAL_CCE));
1360+ (void)ge::AttrUtils::SetInt(concat_op, CONCAT_DIM, 0);
1361+ vector<int64_t> output_index;
1362+ output_index.push_back(0);
1363+ (void)ge::AttrUtils::SetListInt(bn_op, ge::ATOMIC_ATTR_OUTPUT_INDEX, output_index);
1364+ NodePtr bn_node = graph->AddNode(bn_op);
1365+ NodePtr concat_node = graph->AddNode(concat_op);
1366+ NodePtr shape_node = graph->AddNode(shape_op);
1367+ GraphUtils::AddEdge(bn_node->GetOutDataAnchor(0), concat_node->GetInDataAnchor(0));
1368+ GraphUtils::AddEdge(shape_node->GetOutDataAnchor(0), concat_node->GetInDataAnchor(1));
1369+}
1370+ 
1371+void UTEST_fusion_engine_fe_graph_optimizer::CreateConcatOpDescGraph10(ComputeGraphPtr graph) {
1372+ OpDescPtr bn_op = std::make_shared<OpDesc>("batchnormal", "BatchNorm");
1373+ OpDescPtr concat_op = std::make_shared<OpDesc>("concat", "ConcatD");
1374+ 
1375+ // add descriptor
1376+ vector<int64_t> dims = {1, 2, 3, 32};
1377+ GeShape shape(dims);
1378+ 
1379+ GeTensorDesc in_desc1(shape);
1380+ in_desc1.SetFormat(FORMAT_NCHW);
1381+ in_desc1.SetDataType(DT_FLOAT16);
1382+ concat_op->AddInputDesc("x", in_desc1);
1383+ 
1384+ GeTensorDesc out_desc1(shape);
1385+ out_desc1.SetFormat(FORMAT_HWCN);
1386+ out_desc1.SetDataType(DT_FLOAT16);
1387+ concat_op->AddOutputDesc("y", out_desc1);
1388+ 
1389+ GeTensorDesc in_desc2(shape);
1390+ in_desc2.SetFormat(FORMAT_FRACTAL_Z);
1391+ in_desc2.SetDataType(DT_FLOAT16);
1392+ bn_op->AddInputDesc("x", in_desc2);
1393+ 
1394+ GeTensorDesc out_desc2(shape);
1395+ out_desc2.SetFormat(FORMAT_NHWC);
1396+ out_desc2.SetDataType(DT_FLOAT16);
1397+ bn_op->AddOutputDesc("y", out_desc2);
1398+ std::vector<bool> is_in_const_vec = {false};
1399+ bn_op->SetIsInputConst(is_in_const_vec);
1400+ 
1401+ ge::AttrUtils::SetInt(bn_op, FE_IMPLY_TYPE, static_cast<int>(EN_IMPL_HW_TBE));
1402+ ge::AttrUtils::SetInt(concat_op, FE_IMPLY_TYPE, static_cast<int>(EN_IMPL_HW_GENERAL_CCE));
1403+ (void)ge::AttrUtils::SetInt(concat_op, CONCAT_DIM, 0);
1404+ ge::AttrUtils::SetBool(bn_op, ge::ATTR_NAME_NOTASK, true);
1405+ NodePtr bn_node = graph->AddNode(bn_op);
1406+ NodePtr concat_node = graph->AddNode(concat_op);
1407+ GraphUtils::AddEdge(bn_node->GetOutDataAnchor(0), concat_node->GetInDataAnchor(0));
1408+}
1409+ 
1410+void UTEST_fusion_engine_fe_graph_optimizer::CreateConcatOpDescGraph11(ComputeGraphPtr graph) {
1411+ OpDescPtr bn_op = std::make_shared<OpDesc>("batchnormal", "BatchNorm");
1412+ OpDescPtr shape_op = std::make_shared<OpDesc>("shape", "Shape");
1413+ OpDescPtr concat_op = std::make_shared<OpDesc>("concat", "ConcatD");
1414+ 
1415+ // add descriptor
1416+ vector<int64_t> dims = {1, 2, 3, 32};
1417+ GeShape shape(dims);
1418+ 
1419+ GeTensorDesc in_desc1(shape);
1420+ in_desc1.SetFormat(FORMAT_NCHW);
1421+ in_desc1.SetDataType(DT_FLOAT16);
1422+ concat_op->AddInputDesc("x", in_desc1);
1423+ 
1424+ GeTensorDesc in_desc11(shape);
1425+ in_desc11.SetFormat(FORMAT_NCHW);
1426+ in_desc11.SetDataType(DT_FLOAT16);
1427+ concat_op->AddInputDesc("z", in_desc11);
1428+ 
1429+ GeTensorDesc out_desc1(shape);
1430+ out_desc1.SetFormat(FORMAT_HWCN);
1431+ out_desc1.SetDataType(DT_FLOAT16);
1432+ concat_op->AddOutputDesc("y", out_desc1);
1433+ 
1434+ GeTensorDesc in_desc2(shape);
1435+ in_desc2.SetFormat(FORMAT_FRACTAL_Z);
1436+ in_desc2.SetDataType(DT_FLOAT16);
1437+ bn_op->AddInputDesc("x", in_desc2);
1438+ 
1439+ GeTensorDesc out_desc2(shape);
1440+ out_desc2.SetFormat(FORMAT_NHWC);
1441+ out_desc2.SetDataType(DT_FLOAT16);
1442+ bn_op->AddOutputDesc("y", out_desc2);
1443+ 
1444+ GeTensorDesc in_desc3(shape);
1445+ in_desc3.SetFormat(FORMAT_NCHW);
1446+ in_desc3.SetDataType(DT_FLOAT16);
1447+ shape_op->AddInputDesc("x", in_desc3);
1448+ 
1449+ GeTensorDesc out_desc3(shape);
1450+ out_desc3.SetFormat(FORMAT_HWCN);
1451+ out_desc3.SetDataType(DT_FLOAT16);
1452+ shape_op->AddOutputDesc("y", out_desc3);
1453+ 
1454+ std::vector<bool> is_in_const_vec = {false};
1455+ bn_op->SetIsInputConst(is_in_const_vec);
1456+ 
1457+ ge::AttrUtils::SetInt(bn_op, FE_IMPLY_TYPE, static_cast<int>(EN_IMPL_HW_TBE));
1458+ ge::AttrUtils::SetInt(concat_op, FE_IMPLY_TYPE, static_cast<int>(EN_IMPL_HW_GENERAL_CCE));
1459+ (void)ge::AttrUtils::SetInt(concat_op, CONCAT_DIM, 0);
1460+ ge::AttrUtils::SetBool(shape_op, ge::ATTR_NAME_REFERENCE, true);
1461+ NodePtr bn_node = graph->AddNode(bn_op);
1462+ NodePtr concat_node = graph->AddNode(concat_op);
1463+ NodePtr shape_node = graph->AddNode(shape_op);
1464+ GraphUtils::AddEdge(bn_node->GetOutDataAnchor(0), concat_node->GetInDataAnchor(0));
1465+ GraphUtils::AddEdge(shape_node->GetOutDataAnchor(0), concat_node->GetInDataAnchor(1));
1466+}
1467+ 
1468+void UTEST_fusion_engine_fe_graph_optimizer::CreateConcatOpDescGraph12(ComputeGraphPtr graph) {
1469+ OpDescPtr bn_op = std::make_shared<OpDesc>("batchnormal", "BatchNorm");
1470+ OpDescPtr shape_op = std::make_shared<OpDesc>("shape", "Shape");
1471+ OpDescPtr concat_op = std::make_shared<OpDesc>("concat", "ConcatD");
1472+ 
1473+ // add descriptor
1474+ vector<int64_t> dims = {1, 2, 3, 32};
1475+ GeShape shape(dims);
1476+ 
1477+ GeTensorDesc in_desc1(shape);
1478+ in_desc1.SetFormat(FORMAT_NCHW);
1479+ in_desc1.SetDataType(DT_FLOAT16);
1480+ concat_op->AddInputDesc("x", in_desc1);
1481+ 
1482+ GeTensorDesc in_desc11(shape);
1483+ in_desc11.SetFormat(FORMAT_NCHW);
1484+ in_desc11.SetDataType(DT_FLOAT16);
1485+ concat_op->AddInputDesc("z", in_desc11);
1486+ 
1487+ GeTensorDesc in_desc111(shape);
1488+ in_desc111.SetFormat(FORMAT_NCHW);
1489+ in_desc111.SetDataType(DT_FLOAT16);
1490+ concat_op->AddInputDesc("w", in_desc111);
1491+ 
1492+ GeTensorDesc out_desc1(shape);
1493+ out_desc1.SetFormat(FORMAT_HWCN);
1494+ out_desc1.SetDataType(DT_FLOAT16);
1495+ concat_op->AddOutputDesc("y", out_desc1);
1496+ 
1497+ GeTensorDesc in_desc2(shape);
1498+ in_desc2.SetFormat(FORMAT_FRACTAL_Z);
1499+ in_desc2.SetDataType(DT_FLOAT16);
1500+ bn_op->AddInputDesc("x", in_desc2);
1501+ 
1502+ GeTensorDesc out_desc2(shape);
1503+ out_desc2.SetFormat(FORMAT_NHWC);
1504+ out_desc2.SetDataType(DT_FLOAT16);
1505+ bn_op->AddOutputDesc("y", out_desc2);
1506+ 
1507+ GeTensorDesc in_desc3(shape);
1508+ in_desc3.SetFormat(FORMAT_NCHW);
1509+ in_desc3.SetDataType(DT_FLOAT16);
1510+ shape_op->AddInputDesc("x", in_desc3);
1511+ 
1512+ GeTensorDesc out_desc3(shape);
1513+ out_desc3.SetFormat(FORMAT_HWCN);
1514+ out_desc3.SetDataType(DT_FLOAT16);
1515+ shape_op->AddOutputDesc("y", out_desc3);
1516+ 
1517+ std::vector<bool> is_in_const_vec = {false};
1518+ bn_op->SetIsInputConst(is_in_const_vec);
1519+ 
1520+ ge::AttrUtils::SetInt(bn_op, FE_IMPLY_TYPE, static_cast<int>(EN_IMPL_HW_TBE));
1521+ ge::AttrUtils::SetInt(concat_op, FE_IMPLY_TYPE, static_cast<int>(EN_IMPL_HW_GENERAL_CCE));
1522+ (void)ge::AttrUtils::SetInt(concat_op, CONCAT_DIM, 0);
1523+ NodePtr bn_node = graph->AddNode(bn_op);
1524+ NodePtr concat_node = graph->AddNode(concat_op);
1525+ NodePtr shape_node = graph->AddNode(shape_op);
1526+ GraphUtils::AddEdge(bn_node->GetOutDataAnchor(0), concat_node->GetInDataAnchor(0));
1527+ GraphUtils::AddEdge(shape_node->GetOutDataAnchor(0), concat_node->GetInDataAnchor(1));
1528+ GraphUtils::AddEdge(shape_node->GetOutDataAnchor(0), concat_node->GetInDataAnchor(2));
1529+}
1530+ 
1531+void UTEST_fusion_engine_fe_graph_optimizer::CreateConcatOpDescGraph13(ComputeGraphPtr graph) {
1532+ OpDescPtr bn_op = std::make_shared<OpDesc>("batchnormal", "BatchNorm");
1533+ OpDescPtr shape_op = std::make_shared<OpDesc>("shape", "Shape");
1534+ OpDescPtr concat_op = std::make_shared<OpDesc>("concat", "ConcatD");
1535+ 
1536+ // add descriptor
1537+ vector<int64_t> dims = {1, 2, 3, 4};
1538+ GeShape shape(dims);
1539+ 
1540+ GeTensorDesc in_desc1(shape);
1541+ in_desc1.SetFormat(FORMAT_NCHW);
1542+ in_desc1.SetDataType(DT_FLOAT16);
1543+ concat_op->AddInputDesc("x", in_desc1);
1544+ 
1545+ GeTensorDesc in_desc11(shape);
1546+ in_desc11.SetFormat(FORMAT_NCHW);
1547+ in_desc11.SetDataType(DT_FLOAT16);
1548+ concat_op->AddInputDesc("z", in_desc11);
1549+ 
1550+ GeTensorDesc out_desc1(shape);
1551+ out_desc1.SetFormat(FORMAT_HWCN);
1552+ out_desc1.SetDataType(DT_FLOAT16);
1553+ concat_op->AddOutputDesc("y", out_desc1);
1554+ 
1555+ GeTensorDesc in_desc2(shape);
1556+ in_desc2.SetFormat(FORMAT_FRACTAL_Z);
1557+ in_desc2.SetDataType(DT_FLOAT16);
1558+ bn_op->AddInputDesc("x", in_desc2);
1559+ 
1560+ GeTensorDesc out_desc2(shape);
1561+ out_desc2.SetFormat(FORMAT_NHWC);
1562+ out_desc2.SetDataType(DT_FLOAT16);
1563+ bn_op->AddOutputDesc("y", out_desc2);
1564+ 
1565+ GeTensorDesc in_desc3(shape);
1566+ in_desc3.SetFormat(FORMAT_NCHW);
1567+ in_desc3.SetDataType(DT_FLOAT16);
1568+ shape_op->AddInputDesc("x", in_desc3);
1569+ 
1570+ GeTensorDesc out_desc3(shape);
1571+ out_desc3.SetFormat(FORMAT_HWCN);
1572+ out_desc3.SetDataType(DT_FLOAT16);
1573+ shape_op->AddOutputDesc("y", out_desc3);
1574+ 
1575+ std::vector<bool> is_in_const_vec = {false};
1576+ bn_op->SetIsInputConst(is_in_const_vec);
1577+ 
1578+ ge::AttrUtils::SetInt(bn_op, FE_IMPLY_TYPE, static_cast<int>(EN_IMPL_HW_TBE));
1579+ ge::AttrUtils::SetInt(concat_op, FE_IMPLY_TYPE, static_cast<int>(EN_IMPL_HW_GENERAL_CCE));
1580+ (void)ge::AttrUtils::SetInt(concat_op, CONCAT_DIM, 0);
1581+ NodePtr bn_node = graph->AddNode(bn_op);
1582+ NodePtr concat_node = graph->AddNode(concat_op);
1583+ NodePtr shape_node = graph->AddNode(shape_op);
1584+ GraphUtils::AddEdge(bn_node->GetOutDataAnchor(0), concat_node->GetInDataAnchor(0));
1585+ GraphUtils::AddEdge(shape_node->GetOutDataAnchor(0), concat_node->GetInDataAnchor(1));
1586+}
1587+ 
1588+void UTEST_fusion_engine_fe_graph_optimizer::CreateConcatOpDescGraph14(ComputeGraphPtr graph) {
1589+ OpDescPtr bn_op = std::make_shared<OpDesc>("batchnormal", "BatchNorm");
1590+ OpDescPtr shape_op = std::make_shared<OpDesc>("shape", "Shape");
1591+ OpDescPtr concat_op = std::make_shared<OpDesc>("concat", "ConcatD");
1592+ 
1593+ // add descriptor
1594+ vector<int64_t> dims = {1, 2, 3, 32};
1595+ GeShape shape(dims);
1596+ 
1597+ GeTensorDesc in_desc1(shape);
1598+ in_desc1.SetFormat(FORMAT_NCHW);
1599+ in_desc1.SetDataType(DT_FLOAT16);
1600+ concat_op->AddInputDesc("x", in_desc1);
1601+ 
1602+ GeTensorDesc in_desc11(shape);
1603+ in_desc11.SetFormat(FORMAT_NCHW);
1604+ in_desc11.SetDataType(DT_FLOAT16);
1605+ concat_op->AddInputDesc("z", in_desc11);
1606+ 
1607+ GeTensorDesc out_desc1(shape);
1608+ out_desc1.SetFormat(FORMAT_HWCN);
1609+ out_desc1.SetDataType(DT_FLOAT16);
1610+ concat_op->AddOutputDesc("y", out_desc1);
1611+ 
1612+ GeTensorDesc in_desc2(shape);
1613+ in_desc2.SetFormat(FORMAT_FRACTAL_Z);
1614+ in_desc2.SetDataType(DT_FLOAT16);
1615+ bn_op->AddInputDesc("x", in_desc2);
1616+ 
1617+ GeTensorDesc out_desc2(shape);
1618+ out_desc2.SetFormat(FORMAT_NHWC);
1619+ out_desc2.SetDataType(DT_FLOAT16);
1620+ bn_op->AddOutputDesc("y", out_desc2);
1621+ 
1622+ GeTensorDesc in_desc3(shape);
1623+ in_desc3.SetFormat(FORMAT_NCHW);
1624+ in_desc3.SetDataType(DT_FLOAT16);
1625+ shape_op->AddInputDesc("x", in_desc3);
1626+ 
1627+ GeTensorDesc out_desc3(shape);
1628+ out_desc3.SetFormat(FORMAT_HWCN);
1629+ out_desc3.SetDataType(DT_FLOAT16);
1630+ shape_op->AddOutputDesc("y", out_desc3);
1631+ 
1632+ std::vector<bool> is_in_const_vec = {false};
1633+ bn_op->SetIsInputConst(is_in_const_vec);
1634+ 
1635+ ge::AttrUtils::SetInt(bn_op, FE_IMPLY_TYPE, static_cast<int>(EN_IMPL_HW_TBE));
1636+ ge::AttrUtils::SetInt(concat_op, FE_IMPLY_TYPE, static_cast<int>(EN_IMPL_HW_GENERAL_CCE));
1637+ (void)ge::AttrUtils::SetInt(concat_op, CONCAT_DIM, 0);
1638+ NodePtr bn_node = graph->AddNode(bn_op);
1639+ NodePtr concat_node = graph->AddNode(concat_op);
1640+ NodePtr shape_node = graph->AddNode(shape_op);
1641+ GraphUtils::AddEdge(bn_node->GetOutDataAnchor(0), concat_node->GetInDataAnchor(0));
1642+ GraphUtils::AddEdge(shape_node->GetOutDataAnchor(0), concat_node->GetInDataAnchor(1));
1643+ GraphUtils::AddEdge(shape_node->GetOutControlAnchor(), concat_node->GetInControlAnchor());
1644+}
1645+ 
1646+void UTEST_fusion_engine_fe_graph_optimizer::CreateConcat15GraphDescs(OpDescPtr &bn_op, OpDescPtr &shape_op,
1647+ OpDescPtr &concat_op, OpDescPtr &end_op) {
1648+ bn_op = std::make_shared<OpDesc>("batchnormal", "BatchNorm");
1649+ shape_op = std::make_shared<OpDesc>("shape", "Shape");
1650+ concat_op = std::make_shared<OpDesc>("concat", "ConcatD");
1651+ end_op = std::make_shared<OpDesc>("end", "End");
1652+ vector<int64_t> dims = {1, 2, 3, 32};
1653+ GeShape shape(dims);
1654+ GeTensorDesc in_desc1(shape);
1655+ in_desc1.SetFormat(FORMAT_NCHW);
1656+ in_desc1.SetDataType(DT_FLOAT16);
1657+ concat_op->AddInputDesc("x", in_desc1);
1658+ GeTensorDesc in_desc11(shape);
1659+ in_desc11.SetFormat(FORMAT_NCHW);
1660+ in_desc11.SetDataType(DT_FLOAT16);
1661+ concat_op->AddInputDesc("z", in_desc11);
1662+ GeTensorDesc out_desc1(shape);
1663+ out_desc1.SetFormat(FORMAT_HWCN);
1664+ out_desc1.SetDataType(DT_FLOAT16);
1665+ concat_op->AddOutputDesc("y", out_desc1);
1666+ GeTensorDesc in_desc2(shape);
1667+ in_desc2.SetFormat(FORMAT_FRACTAL_Z);
1668+ in_desc2.SetDataType(DT_FLOAT16);
1669+ bn_op->AddInputDesc("x", in_desc2);
1670+ GeTensorDesc out_desc2(shape);
1671+ out_desc2.SetFormat(FORMAT_NHWC);
1672+ out_desc2.SetDataType(DT_FLOAT16);
1673+ bn_op->AddOutputDesc("y", out_desc2);
1674+ GeTensorDesc in_desc3(shape);
1675+ in_desc3.SetFormat(FORMAT_NCHW);
1676+ in_desc3.SetDataType(DT_FLOAT16);
1677+ shape_op->AddInputDesc("x", in_desc3);
1678+ GeTensorDesc out_desc3(shape);
1679+ out_desc3.SetFormat(FORMAT_HWCN);
1680+ out_desc3.SetDataType(DT_FLOAT16);
1681+ shape_op->AddOutputDesc("y", out_desc3);
1682+ GeTensorDesc in_desc4(shape);
1683+ in_desc4.SetFormat(FORMAT_NCHW);
1684+ in_desc4.SetDataType(DT_FLOAT16);
1685+ end_op->AddInputDesc("x", in_desc4);
1686+ GeTensorDesc out_desc4(shape);
1687+ out_desc4.SetFormat(FORMAT_HWCN);
1688+ out_desc4.SetDataType(DT_FLOAT16);
1689+ end_op->AddOutputDesc("y", out_desc4);
1690+}
1691+ 
1692+void UTEST_fusion_engine_fe_graph_optimizer::CreateConcatOpDescGraph15(ComputeGraphPtr graph) {
1693+ OpDescPtr bn_op;
1694+ OpDescPtr shape_op;
1695+ OpDescPtr concat_op;
1696+ OpDescPtr end_op;
1697+ CreateConcat15GraphDescs(bn_op, shape_op, concat_op, end_op);
1698+ 
1699+ std::vector<bool> is_in_const_vec = {false};
1700+ bn_op->SetIsInputConst(is_in_const_vec);
1701+ 
1702+ ge::AttrUtils::SetInt(bn_op, FE_IMPLY_TYPE, static_cast<int>(EN_IMPL_HW_TBE));
1703+ ge::AttrUtils::SetInt(concat_op, FE_IMPLY_TYPE, static_cast<int>(EN_IMPL_HW_GENERAL_CCE));
1704+ (void)ge::AttrUtils::SetInt(concat_op, CONCAT_DIM, 0);
1705+ ge::AttrUtils::SetBool(bn_op, ge::ATTR_NAME_NOTASK, true);
1706+ ge::AttrUtils::SetStr(end_op, "parentOpType", "NetOutput");
1707+ NodePtr bn_node = graph->AddNode(bn_op);
1708+ NodePtr concat_node = graph->AddNode(concat_op);
1709+ NodePtr shape_node = graph->AddNode(shape_op);
1710+ NodePtr end_node = graph->AddNode(end_op);
1711+ GraphUtils::AddEdge(bn_node->GetOutDataAnchor(0), concat_node->GetInDataAnchor(0));
1712+ GraphUtils::AddEdge(shape_node->GetOutDataAnchor(0), concat_node->GetInDataAnchor(1));
1713+ GraphUtils::AddEdge(concat_node->GetOutDataAnchor(0), end_node->GetInDataAnchor(0));
1714+}
1715+ 
1716+void UTEST_fusion_engine_fe_graph_optimizer::CreateConcat16GraphDescs(OpDescPtr &bn_op, OpDescPtr &shape_op,
1717+ OpDescPtr &reshape_op1, OpDescPtr &concat_op,
1718+ OpDescPtr &reshape_op2, OpDescPtr &end_op) {
1719+ bn_op = std::make_shared<OpDesc>("batchnormal", "BatchNorm");
1720+ shape_op = std::make_shared<OpDesc>("shape", "Shape");
1721+ reshape_op1 = std::make_shared<OpDesc>("reshape1", "Reshape");
1722+ concat_op = std::make_shared<OpDesc>("concat", "ConcatD");
1723+ reshape_op2 = std::make_shared<OpDesc>("reshape2", "Reshape");
1724+ end_op = std::make_shared<OpDesc>("end", "End");
1725+ GeShape shape(vector<int64_t>{1, 2, 3, 32});
1726+ GeTensorDesc in_desc1(shape);
1727+ in_desc1.SetFormat(FORMAT_NCHW);
1728+ in_desc1.SetDataType(DT_FLOAT16);
1729+ concat_op->AddInputDesc("x", in_desc1);
1730+ GeTensorDesc in_desc11(shape);
1731+ in_desc11.SetFormat(FORMAT_NCHW);
1732+ in_desc11.SetDataType(DT_FLOAT16);
1733+ concat_op->AddInputDesc("z", in_desc11);
1734+ GeTensorDesc out_desc1(shape);
1735+ out_desc1.SetFormat(FORMAT_NCHW);
1736+ out_desc1.SetDataType(DT_FLOAT16);
1737+ concat_op->AddOutputDesc("y", out_desc1);
1738+ GeTensorDesc in_desc2(shape);
1739+ in_desc2.SetFormat(FORMAT_NCHW);
1740+ in_desc2.SetDataType(DT_FLOAT16);
1741+ bn_op->AddInputDesc("x", in_desc2);
1742+ GeTensorDesc out_desc2(shape);
1743+ out_desc2.SetFormat(FORMAT_NCHW);
1744+ out_desc2.SetDataType(DT_FLOAT16);
1745+ bn_op->AddOutputDesc("y", out_desc2);
1746+ GeTensorDesc in_desc3(shape);
1747+ in_desc3.SetFormat(FORMAT_NCHW);
1748+ in_desc3.SetDataType(DT_FLOAT16);
1749+ shape_op->AddInputDesc("x", in_desc3);
1750+ reshape_op1->AddInputDesc("x", in_desc3);
1751+ GeTensorDesc out_desc3(shape);
1752+ out_desc3.SetFormat(FORMAT_NCHW);
1753+ out_desc3.SetDataType(DT_FLOAT16);
1754+ shape_op->AddOutputDesc("y", out_desc3);
1755+ reshape_op1->AddOutputDesc("y", out_desc3);
1756+ GeTensorDesc in_desc4(shape);
1757+ in_desc4.SetFormat(FORMAT_NCHW);
1758+ in_desc4.SetDataType(DT_FLOAT16);
1759+ end_op->AddInputDesc("x", in_desc4);
1760+ reshape_op2->AddInputDesc("x", in_desc4);
1761+ GeTensorDesc out_desc4(shape);
1762+ out_desc4.SetFormat(FORMAT_NCHW);
1763+ out_desc4.SetDataType(DT_FLOAT16);
1764+ end_op->AddOutputDesc("y", out_desc4);
1765+ reshape_op2->AddOutputDesc("y", out_desc4);
1766+}
1767+ 
1768+void UTEST_fusion_engine_fe_graph_optimizer::CreateConcatOpDescGraph16(ComputeGraphPtr graph) {
1769+ OpDescPtr bn_op;
1770+ OpDescPtr shape_op;
1771+ OpDescPtr reshape_op1;
1772+ OpDescPtr concat_op;
1773+ OpDescPtr reshape_op2;
1774+ OpDescPtr end_op;
1775+ CreateConcat16GraphDescs(bn_op, shape_op, reshape_op1, concat_op, reshape_op2, end_op);
1776+ 
1777+ std::vector<bool> is_in_const_vec = {false};
1778+ bn_op->SetIsInputConst(is_in_const_vec);
1779+ 
1780+ ge::AttrUtils::SetInt(bn_op, FE_IMPLY_TYPE, static_cast<int>(EN_IMPL_HW_TBE));
1781+ ge::AttrUtils::SetInt(shape_op, FE_IMPLY_TYPE, static_cast<int>(EN_IMPL_HW_TBE));
1782+ ge::AttrUtils::SetInt(reshape_op1, FE_IMPLY_TYPE, static_cast<int>(EN_IMPL_HW_TBE));
1783+ ge::AttrUtils::SetInt(reshape_op2, FE_IMPLY_TYPE, static_cast<int>(EN_IMPL_HW_TBE));
1784+ ge::AttrUtils::SetInt(concat_op, FE_IMPLY_TYPE, static_cast<int>(EN_IMPL_HW_TBE));
1785+ (void)ge::AttrUtils::SetInt(concat_op, CONCAT_DIM, 0);
1786+ ge::AttrUtils::SetStr(end_op, "parentOpType", "NetOutput");
1787+ NodePtr bn_node = graph->AddNode(bn_op);
1788+ NodePtr concat_node = graph->AddNode(concat_op);
1789+ NodePtr shape_node = graph->AddNode(shape_op);
1790+ NodePtr reshape_node1 = graph->AddNode(reshape_op1);
1791+ NodePtr end_node = graph->AddNode(end_op);
1792+ NodePtr reshape_node2 = graph->AddNode(reshape_op2);
1793+ GraphUtils::AddEdge(bn_node->GetOutDataAnchor(0), concat_node->GetInDataAnchor(0));
1794+ GraphUtils::AddEdge(shape_node->GetOutDataAnchor(0), reshape_node1->GetInDataAnchor(0));
1795+ GraphUtils::AddEdge(reshape_node1->GetOutDataAnchor(0), concat_node->GetInDataAnchor(1));
1796+ GraphUtils::AddEdge(concat_node->GetOutDataAnchor(0), reshape_node2->GetInDataAnchor(0));
1797+ GraphUtils::AddEdge(reshape_node2->GetOutDataAnchor(0), end_node->GetInDataAnchor(0));
1798+}
1799+ 
1800+void UTEST_fusion_engine_fe_graph_optimizer::CreateCastReluCast6Descs(
1801+ OpDescPtr &op_desc_cast1, OpDescPtr &op_desc_cast3, OpDescPtr &op_desc_cast4, OpDescPtr &op_desc_relu,
1802+ OpDescPtr &op_desc_cast2, OpDescPtr &op_desc_output, OpDescPtr &op_desc_input) {
1803+ op_desc_cast1 = std::make_shared<OpDesc>("cast1", "Cast");
1804+ op_desc_cast3 = std::make_shared<OpDesc>("cast3", "Cast");
1805+ op_desc_cast4 = std::make_shared<OpDesc>(
1806+ "loss_scale/gradients/fp32_vars/conv2d_15/Conv2D_grad/Conv2DBackpropInput_dilation", "Cast");
1807+ op_desc_relu = std::make_shared<OpDesc>("relu", "Relu");
1808+ op_desc_cast2 = std::make_shared<OpDesc>(
1809+ "loss_scale/gradients/fp32_vars/conv2d_15/Conv2D_grad/Conv2DBackpropInput_dilation", "Cast");
1810+ op_desc_output = std::make_shared<OpDesc>("output", "NetOutput");
1811+ op_desc_input = std::make_shared<OpDesc>("other", "Other");
1812+ vector<int64_t> dim_a = {8, 4, 16, 16};
1813+ GeShape shape_a(dim_a);
1814+ GeTensorDesc tensor_desc_a(shape_a);
1815+ tensor_desc_a.SetFormat(FORMAT_NCHW);
1816+ tensor_desc_a.SetOriginFormat(FORMAT_NCHW);
1817+ tensor_desc_a.SetDataType(DT_FLOAT16);
1818+ tensor_desc_a.SetOriginDataType(DT_FLOAT);
1819+ vector<int64_t> dim_b = {1, 4, 64, 64};
1820+ GeShape shape_b(dim_b);
1821+ GeTensorDesc tensor_desc_b(shape_b);
1822+ tensor_desc_b.SetFormat(FORMAT_NCHW);
1823+ tensor_desc_b.SetOriginFormat(FORMAT_NCHW);
1824+ tensor_desc_b.SetDataType(DT_FLOAT);
1825+ tensor_desc_b.SetOriginDataType(DT_FLOAT);
1826+ vector<int64_t> dim_c = {1, 4, 64, 64};
1827+ GeShape shape_c(dim_c);
1828+ GeTensorDesc tensor_desc_c(shape_c);
1829+ tensor_desc_c.SetFormat(FORMAT_NCHW);
1830+ tensor_desc_c.SetOriginFormat(FORMAT_NCHW);
1831+ tensor_desc_c.SetDataType(DT_FLOAT);
1832+ tensor_desc_c.SetOriginDataType(DT_FLOAT);
1833+ GeShape shape_d(dim_a);
1834+ GeTensorDesc tensor_desc_d(shape_d);
1835+ tensor_desc_d.SetFormat(FORMAT_NCHW);
1836+ tensor_desc_d.SetOriginFormat(FORMAT_NCHW);
1837+ tensor_desc_d.SetDataType(DT_FLOAT16);
1838+ tensor_desc_d.SetOriginDataType(DT_FLOAT);
1839+ op_desc_input->AddOutputDesc(tensor_desc_a);
1840+ op_desc_cast1->AddInputDesc(tensor_desc_a);
1841+ op_desc_cast1->AddOutputDesc(tensor_desc_b);
1842+ op_desc_cast3->AddInputDesc(tensor_desc_c);
1843+ op_desc_cast3->AddOutputDesc(tensor_desc_d);
1844+ op_desc_cast4->AddInputDesc(tensor_desc_c);
1845+ op_desc_cast4->AddOutputDesc(tensor_desc_c);
1846+ op_desc_relu->AddInputDesc(tensor_desc_b);
1847+ op_desc_relu->AddOutputDesc(tensor_desc_c);
1848+ op_desc_cast2->AddInputDesc(tensor_desc_c);
1849+ op_desc_cast2->AddOutputDesc(tensor_desc_d);
1850+ op_desc_output->AddInputDesc(tensor_desc_d);
1851+ op_desc_output->AddInputDesc(tensor_desc_d);
1852+ op_desc_output->AddInputDesc(tensor_desc_c);
1853+}
1854+ 
1855+ComputeGraphPtr UTEST_fusion_engine_fe_graph_optimizer::CreateCastReluCastGraph6() {
1856+ ComputeGraphPtr graph = std::make_shared<ComputeGraph>("test1");
1857+ OpDescPtr op_desc_cast1;
1858+ OpDescPtr op_desc_cast3;
1859+ OpDescPtr op_desc_cast4;
1860+ OpDescPtr op_desc_relu;
1861+ OpDescPtr op_desc_cast2;
1862+ OpDescPtr op_desc_output;
1863+ OpDescPtr op_desc_input;
1864+ CreateCastReluCast6Descs(op_desc_cast1, op_desc_cast3, op_desc_cast4, op_desc_relu, op_desc_cast2, op_desc_output,
1865+ op_desc_input);
1866+ NodePtr node_cast1 = graph->AddNode(op_desc_cast1);
1867+ NodePtr node_cast3 = graph->AddNode(op_desc_cast3);
1868+ NodePtr node_cast4 = graph->AddNode(op_desc_cast4);
1869+ NodePtr node_relu = graph->AddNode(op_desc_relu);
1870+ NodePtr node_cast2 = graph->AddNode(op_desc_cast2);
1871+ NodePtr node_netoutput = graph->AddNode(op_desc_output);
1872+ NodePtr node_other = graph->AddNode(op_desc_input);
1873+ (void)ge::AttrUtils::SetInt(node_cast1->GetOpDesc(), kThreadScopeId, 1);
1874+ (void)ge::AttrUtils::SetInt(node_cast3->GetOpDesc(), kThreadScopeId, 2);
1875+ GraphUtils::AddEdge(node_other->GetOutDataAnchor(0), node_cast1->GetInDataAnchor(0));
1876+ GraphUtils::AddEdge(node_cast1->GetOutDataAnchor(0), node_relu->GetInDataAnchor(0));
1877+ GraphUtils::AddEdge(node_relu->GetOutDataAnchor(0), node_cast2->GetInDataAnchor(0));
1878+ GraphUtils::AddEdge(node_relu->GetOutDataAnchor(0), node_cast3->GetInDataAnchor(0));
1879+ GraphUtils::AddEdge(node_relu->GetOutDataAnchor(0), node_cast4->GetInDataAnchor(0));
1880+ GraphUtils::AddEdge(node_cast2->GetOutDataAnchor(0), node_netoutput->GetInDataAnchor(0));
1881+ GraphUtils::AddEdge(node_cast3->GetOutDataAnchor(0), node_netoutput->GetInDataAnchor(1));
1882+ GraphUtils::AddEdge(node_cast4->GetOutDataAnchor(0), node_netoutput->GetInDataAnchor(2));
1883+ return graph;
1884+}
1885+ 
1886+void UTEST_fusion_engine_fe_graph_optimizer::CreateConv2dFixpipeGraph(ComputeGraphPtr graph) {
1887+ OpDescPtr data = std::make_shared<OpDesc>("DATA0", fe::DATA);
1888+ OpDescPtr conv2d = std::make_shared<OpDesc>("conv2d", CONV2D);
1889+ OpDescPtr fixpipe = std::make_shared<OpDesc>("fixpipe", "FixPipe");
1890+ OpDescPtr out = std::make_shared<OpDesc>("out", "NetOutput");
1891+ 
1892+ // add descriptor
1893+ vector<int64_t> dims = {1, 2, 3, 3};
1894+ GeShape shape(dims);
1895+ 
1896+ GeTensorDesc in_desc2(shape);
1897+ in_desc2.SetFormat(FORMAT_NHWC);
1898+ in_desc2.SetOriginFormat(FORMAT_NHWC);
1899+ in_desc2.SetDataType(DT_FLOAT16);
1900+ data->AddOutputDesc("x", in_desc2);
1901+ conv2d->AddInputDesc("x", in_desc2);
1902+ conv2d->AddOutputDesc("y", in_desc2);
1903+ fixpipe->AddInputDesc("x", in_desc2);
1904+ fixpipe->AddOutputDesc("y", in_desc2);
1905+ out->AddInputDesc("x", in_desc2);
1906+ 
1907+ ge::AttrUtils::SetInt(conv2d, FE_IMPLY_TYPE, static_cast<int>(EN_IMPL_HW_TBE));
1908+ ge::AttrUtils::SetInt(fixpipe, FE_IMPLY_TYPE, static_cast<int>(EN_IMPL_HW_TBE));
1909+ NodePtr data_node = graph->AddNode(data);
1910+ NodePtr conv2d_node = graph->AddNode(conv2d);
1911+ NodePtr fixpipe_node = graph->AddNode(fixpipe);
1912+ NodePtr out_node = graph->AddNode(out);
1913+ GraphUtils::AddEdge(data_node->GetOutDataAnchor(0), conv2d_node->GetInDataAnchor(0));
1914+ GraphUtils::AddEdge(conv2d_node->GetOutDataAnchor(0), fixpipe_node->GetInDataAnchor(0));
1915+ GraphUtils::AddEdge(fixpipe_node->GetOutDataAnchor(0), out_node->GetInDataAnchor(0));
1916+}
1917+ 
1918+UTEST_fusion_engine_fe_graph_optimizer::CMOMultiStreamNodes
1919+UTEST_fusion_engine_fe_graph_optimizer::CreateCMOMultiStreamNodes(ComputeGraphPtr graph) {
1920+ OpDescPtr data, a, b, c, d, e, f, g, h, j, out, send, recv;
1921+ CreateCMOMultiStreamOpDescs(data, a, b, c, d, e, f, g, h, j, out, send, recv);
1922+ GeTensorDesc in_desc2(GeShape(vector<int64_t>{1, 16, 16, 32}));
1923+ data->AddOutputDesc("x", in_desc2);
1924+ a->AddInputDesc("x", in_desc2);
1925+ a->AddOutputDesc("y", in_desc2);
1926+ b->AddInputDesc("x", in_desc2);
1927+ b->AddOutputDesc("y", in_desc2);
1928+ c->AddInputDesc("x", in_desc2);
1929+ c->AddOutputDesc("y", in_desc2);
1930+ d->AddInputDesc("x", in_desc2);
1931+ d->AddOutputDesc("y", in_desc2);
1932+ e->AddInputDesc("x", in_desc2);
1933+ e->AddOutputDesc("y", in_desc2);
1934+ f->AddInputDesc("x", in_desc2);
1935+ f->AddOutputDesc("y", in_desc2);
1936+ g->AddInputDesc("x", in_desc2);
1937+ g->AddOutputDesc("y", in_desc2);
1938+ h->AddInputDesc("x", in_desc2);
1939+ h->AddOutputDesc("y", in_desc2);
1940+ j->AddInputDesc("x", in_desc2);
1941+ j->AddOutputDesc("y", in_desc2);
1942+ out->AddInputDesc("x1", in_desc2);
1943+ out->AddInputDesc("x2", in_desc2);
1944+ ge::AttrUtils::SetInt(a, FE_IMPLY_TYPE, static_cast<int>(EN_IMPL_HW_TBE));
1945+ ge::AttrUtils::SetInt(b, FE_IMPLY_TYPE, static_cast<int>(EN_IMPL_HW_TBE));
1946+ ge::AttrUtils::SetInt(c, FE_IMPLY_TYPE, static_cast<int>(EN_IMPL_HW_TBE));
1947+ ge::AttrUtils::SetInt(d, FE_IMPLY_TYPE, static_cast<int>(EN_IMPL_HW_TBE));
1948+ ge::AttrUtils::SetInt(e, FE_IMPLY_TYPE, static_cast<int>(EN_IMPL_HW_TBE));
1949+ ge::AttrUtils::SetInt(f, FE_IMPLY_TYPE, static_cast<int>(EN_IMPL_HW_TBE));
1950+ ge::AttrUtils::SetInt(g, FE_IMPLY_TYPE, static_cast<int>(EN_IMPL_HW_TBE));
1951+ ge::AttrUtils::SetInt(h, FE_IMPLY_TYPE, static_cast<int>(EN_IMPL_HW_TBE));
1952+ ge::AttrUtils::SetInt(j, FE_IMPLY_TYPE, static_cast<int>(EN_IMPL_HW_TBE));
1953+ ge::AttrUtils::SetInt(send, "event_id", 1);
1954+ ge::AttrUtils::SetInt(recv, "event_id", 1);
1955+ CMOMultiStreamNodes nodes{graph->AddNode(data), graph->AddNode(a), graph->AddNode(b), graph->AddNode(c),
1956+ graph->AddNode(d), graph->AddNode(e), graph->AddNode(f), graph->AddNode(g),
1957+ graph->AddNode(h), graph->AddNode(j), graph->AddNode(out), graph->AddNode(send),
1958+ graph->AddNode(recv)};
1959+ return nodes;
1960+}
1961+ 
1962+void UTEST_fusion_engine_fe_graph_optimizer::CreateCMOMultiStreamGraph(ComputeGraphPtr graph) {
1963+ CMOMultiStreamNodes nodes = CreateCMOMultiStreamNodes(graph);
1964+ GraphUtils::AddEdge(nodes.data->GetOutDataAnchor(0), nodes.a->GetInDataAnchor(0));
1965+ GraphUtils::AddEdge(nodes.a->GetOutDataAnchor(0), nodes.b->GetInDataAnchor(0));
1966+ GraphUtils::AddEdge(nodes.b->GetOutDataAnchor(0), nodes.c->GetInDataAnchor(0));
1967+ GraphUtils::AddEdge(nodes.b->GetOutControlAnchor(), nodes.send->GetInControlAnchor());
1968+ GraphUtils::AddEdge(nodes.c->GetOutDataAnchor(0), nodes.d->GetInDataAnchor(0));
1969+ GraphUtils::AddEdge(nodes.data->GetOutDataAnchor(0), nodes.e->GetInDataAnchor(0));
1970+ GraphUtils::AddEdge(nodes.recv->GetOutControlAnchor(), nodes.e->GetInControlAnchor());
1971+ GraphUtils::AddEdge(nodes.e->GetOutDataAnchor(0), nodes.f->GetInDataAnchor(0));
1972+ GraphUtils::AddEdge(nodes.f->GetOutDataAnchor(0), nodes.g->GetInDataAnchor(0));
1973+ GraphUtils::AddEdge(nodes.g->GetOutDataAnchor(0), nodes.h->GetInDataAnchor(0));
1974+ GraphUtils::AddEdge(nodes.h->GetOutDataAnchor(0), nodes.j->GetInDataAnchor(0));
1975+ GraphUtils::AddEdge(nodes.d->GetOutDataAnchor(0), nodes.out->GetInDataAnchor(0));
1976+ GraphUtils::AddEdge(nodes.j->GetOutDataAnchor(0), nodes.out->GetInDataAnchor(1));
1977+}
1978+ 
1979+void UTEST_fusion_engine_fe_graph_optimizer::CreateSwitchMergeFixpipeGraph(ComputeGraphPtr graph) {
1980+ OpDescPtr data = std::make_shared<OpDesc>("DATA0", fe::DATA);
1981+ OpDescPtr conv2d = std::make_shared<OpDesc>("conv2d", CONV2D);
1982+ OpDescPtr switch_op = std::make_shared<OpDesc>("switch", "Switch");
1983+ OpDescPtr merge = std::make_shared<OpDesc>("merge", "Merge");
1984+ OpDescPtr fixpipe = std::make_shared<OpDesc>("fixpipe", "FixPipe");
1985+ OpDescPtr out = std::make_shared<OpDesc>("out", "NetOutput");
1986+ vector<int64_t> dims = {1, 2, 3, 3};
1987+ GeShape shape(dims);
1988+ GeTensorDesc in_desc2(shape);
1989+ in_desc2.SetFormat(FORMAT_NHWC);
1990+ in_desc2.SetOriginFormat(FORMAT_NHWC);
1991+ in_desc2.SetDataType(DT_FLOAT16);
1992+ data->AddOutputDesc("x", in_desc2);
1993+ conv2d->AddInputDesc("x", in_desc2);
1994+ conv2d->AddOutputDesc("y", in_desc2);
1995+ switch_op->AddInputDesc("x", in_desc2);
1996+ switch_op->AddOutputDesc("y", in_desc2);
1997+ merge->AddInputDesc("x", in_desc2);
1998+ merge->AddOutputDesc("y", in_desc2);
1999+ fixpipe->AddInputDesc("x", in_desc2);
2000+ fixpipe->AddOutputDesc("y", in_desc2);
2001+ out->AddInputDesc("x", in_desc2);
2002+ ge::AttrUtils::SetInt(conv2d, FE_IMPLY_TYPE, static_cast<int>(EN_IMPL_HW_TBE));
2003+ ge::AttrUtils::SetInt(fixpipe, FE_IMPLY_TYPE, static_cast<int>(EN_IMPL_HW_TBE));
2004+ ge::AttrUtils::SetInt(switch_op, FE_IMPLY_TYPE, static_cast<int>(EN_IMPL_HW_TBE));
2005+ ge::AttrUtils::SetInt(merge, FE_IMPLY_TYPE, static_cast<int>(EN_IMPL_HW_TBE));
2006+ NodePtr data_node = graph->AddNode(data);
2007+ NodePtr conv2d_node = graph->AddNode(conv2d);
2008+ NodePtr switch_node = graph->AddNode(switch_op);
2009+ NodePtr merge_node = graph->AddNode(merge);
2010+ NodePtr fixpipe_node = graph->AddNode(fixpipe);
2011+ NodePtr out_node = graph->AddNode(out);
2012+ GraphUtils::AddEdge(data_node->GetOutDataAnchor(0), switch_node->GetInDataAnchor(0));
2013+ GraphUtils::AddEdge(switch_node->GetOutDataAnchor(0), conv2d_node->GetInDataAnchor(0));
2014+ GraphUtils::AddEdge(conv2d_node->GetOutDataAnchor(0), merge_node->GetInDataAnchor(0));
2015+ GraphUtils::AddEdge(merge_node->GetOutDataAnchor(0), fixpipe_node->GetInDataAnchor(0));
2016+ GraphUtils::AddEdge(fixpipe_node->GetOutDataAnchor(0), out_node->GetInDataAnchor(0));
2017+}
2018+ 
2019+ge::ComputeGraphPtr UTEST_fusion_engine_fe_graph_optimizer::CreateInceptionV3NetGraph() {
2020+ ge::ComputeGraphPtr graph = std::make_shared<ge::ComputeGraph>("inceptionv3");
2021+ string network_path = GetNetworkPath("inceptionv3_aipp_int8_16batch.txt");
2022+ (void)ge::GraphUtils::LoadGEGraph(network_path.c_str(), graph);
2023+ return graph;
2024+}
2025+ 
2026+void UTEST_fusion_engine_fe_graph_optimizer::CreateSwitchMergeFixpipe2Descs(OpDescPtr &data, OpDescPtr &conv2d,
2027+ OpDescPtr &switch_op, OpDescPtr &merge,
2028+ OpDescPtr &fixpipe, OpDescPtr &out,
2029+ OpDescPtr &quant, OpDescPtr &bias,
2030+ OpDescPtr &const_op, OpDescPtr &transdata) {
2031+ data = std::make_shared<OpDesc>("DATA0", fe::DATA);
2032+ conv2d = std::make_shared<OpDesc>("conv2d", CONV2D);
2033+ switch_op = std::make_shared<OpDesc>("switch", "Switch");
2034+ merge = std::make_shared<OpDesc>("merge", "Merge");
2035+ fixpipe = std::make_shared<OpDesc>("fixpipe", "FixPipe");
2036+ out = std::make_shared<OpDesc>("out", "NetOutput");
2037+ quant = std::make_shared<OpDesc>("quant", "AscendQuant");
2038+ bias = std::make_shared<OpDesc>("bias", "QuantBiasOptimization");
2039+ const_op = std::make_shared<OpDesc>("cosnt", "Const");
2040+ transdata = std::make_shared<OpDesc>("trans", "TransData");
2041+ vector<int64_t> dims = {1, 2, 3, 3};
2042+ GeShape shape(dims);
2043+ vector<int64_t> dims1 = {1, 2, 3, 3, 1};
2044+ GeShape shape1(dims1);
2045+ GeTensorDesc in_desc1(shape1);
2046+ GeTensorDesc in_desc2(shape);
2047+ in_desc2.SetFormat(FORMAT_NHWC);
2048+ in_desc2.SetOriginFormat(FORMAT_NHWC);
2049+ in_desc2.SetDataType(DT_FLOAT16);
2050+ in_desc1.SetFormat(FORMAT_NC1HWC0);
2051+ in_desc1.SetFormat(FORMAT_NHWC);
2052+ in_desc1.SetDataType(DT_FLOAT16);
2053+ out->AddInputDesc("x", in_desc2);
2054+ data->AddOutputDesc("x", in_desc2);
2055+ conv2d->AddInputDesc("x1", in_desc2);
2056+ conv2d->AddInputDesc("x2", in_desc2);
2057+ conv2d->AddInputDesc("x3", in_desc2);
2058+ conv2d->AddOutputDesc("y", in_desc2);
2059+ switch_op->AddInputDesc("x", in_desc2);
2060+ switch_op->AddOutputDesc("y", in_desc1);
2061+ merge->AddInputDesc("x", in_desc2);
2062+ merge->AddOutputDesc("y", in_desc2);
2063+ fixpipe->AddInputDesc("x", in_desc2);
2064+ fixpipe->AddOutputDesc("y", in_desc2);
2065+ quant->AddInputDesc("x", in_desc2);
2066+ quant->AddOutputDesc("y", in_desc2);
2067+ bias->AddInputDesc("x", in_desc2);
2068+ bias->AddOutputDesc("y", in_desc2);
2069+ const_op->AddOutputDesc("y", in_desc2);
2070+ transdata->AddInputDesc("x", in_desc1);
2071+ transdata->AddOutputDesc("y", in_desc2);
2072+}
2073+ 
2074+void UTEST_fusion_engine_fe_graph_optimizer::CreateSwitchMergeFixpipeGraph2(ComputeGraphPtr graph) {
2075+ OpDescPtr data, conv2d, switch_op, merge, fixpipe, out, quant, bias, const_op, transdata;
2076+ CreateSwitchMergeFixpipe2Descs(data, conv2d, switch_op, merge, fixpipe, out, quant, bias, const_op, transdata);
2077+ ge::AttrUtils::SetInt(conv2d, FE_IMPLY_TYPE, static_cast<int>(EN_IMPL_HW_TBE));
2078+ ge::AttrUtils::SetInt(fixpipe, FE_IMPLY_TYPE, static_cast<int>(EN_IMPL_HW_TBE));
2079+ ge::AttrUtils::SetInt(switch_op, FE_IMPLY_TYPE, static_cast<int>(EN_IMPL_HW_TBE));
2080+ ge::AttrUtils::SetInt(merge, FE_IMPLY_TYPE, static_cast<int>(EN_IMPL_HW_TBE));
2081+ ge::AttrUtils::SetInt(transdata, FE_IMPLY_TYPE, static_cast<int>(EN_IMPL_HW_TBE));
2082+ ge::AttrUtils::SetInt(bias, FE_IMPLY_TYPE, static_cast<int>(EN_IMPL_HW_TBE));
2083+ ge::AttrUtils::SetInt(quant, FE_IMPLY_TYPE, static_cast<int>(EN_IMPL_HW_TBE));
2084+ NodePtr data_node = graph->AddNode(data);
2085+ NodePtr conv2d_node = graph->AddNode(conv2d);
2086+ NodePtr switch_node = graph->AddNode(switch_op);
2087+ NodePtr merge_node = graph->AddNode(merge);
2088+ NodePtr fixpipe_node = graph->AddNode(fixpipe);
2089+ NodePtr out_node = graph->AddNode(out);
2090+ NodePtr quant_node = graph->AddNode(quant);
2091+ NodePtr bias_node = graph->AddNode(bias);
2092+ NodePtr const_node = graph->AddNode(const_op);
2093+ NodePtr transdata_node = graph->AddNode(transdata);
2094+ GraphUtils::AddEdge(data_node->GetOutDataAnchor(0), quant_node->GetInDataAnchor(0));
2095+ GraphUtils::AddEdge(conv2d_node->GetOutDataAnchor(0), merge_node->GetInDataAnchor(0));
2096+ GraphUtils::AddEdge(quant_node->GetOutDataAnchor(0), conv2d_node->GetInDataAnchor(0));
2097+ GraphUtils::AddEdge(switch_node->GetOutDataAnchor(0), transdata_node->GetInDataAnchor(0));
2098+ GraphUtils::AddEdge(transdata_node->GetOutDataAnchor(0), conv2d_node->GetInDataAnchor(1));
2099+ GraphUtils::AddEdge(const_node->GetOutDataAnchor(0), bias_node->GetInDataAnchor(0));
2100+ GraphUtils::AddEdge(bias_node->GetOutDataAnchor(0), conv2d_node->GetInDataAnchor(2));
2101+ GraphUtils::AddEdge(merge_node->GetOutDataAnchor(0), fixpipe_node->GetInDataAnchor(0));
2102+ GraphUtils::AddEdge(fixpipe_node->GetOutDataAnchor(0), out_node->GetInDataAnchor(0));
2103+}
2104+ 
2105+FEGraphOptimizerPtr UTEST_fusion_engine_fe_graph_optimizer::CreateOptimizerForBlockedProcess() {
2106+ FEOpsKernelInfoStorePtr local_ops_store;
2107+ auto optimizer = std::make_shared<FEGraphOptimizer>(local_ops_store);
2108+ optimizer->format_dtype_setter_ptr_ = std::make_shared<FormatDtypeSetter>(AI_CORE_NAME);
2109+ optimizer->op_impl_type_judge_ptr_ = std::make_shared<OpImplTypeJudge>(AI_CORE_NAME, ops_kernel_info_store_ptr_);
2110+ optimizer->op_axis_update_desc_ptr_ = std::make_shared<OpAxisUpdateDesc>(AI_CORE_NAME);
2111+ FusionRuleManagerPtr fusion_rule_mgr = std::make_shared<FusionRuleManager>(ops_kernel_info_store_ptr_);
2112+ optimizer->fusion_priority_mgr_ptr_ = std::make_shared<FusionPriorityManager>(fe::AI_CORE_NAME, fusion_rule_mgr);
2113+ optimizer->fusion_priority_mgr_ptr_->Initialize();
2114+ Configuration::Instance(fe::AI_CORE_NAME).content_map_["fusion.config.built-in.file"] = "fusion_config1.json";
2115+ Configuration::Instance(fe::AI_CORE_NAME).ascend_ops_path_ =
2116+ GetCodeDir() + "/tests/engines/nn_engine/st/testcase/fusion_config_manager/builtin_config/";
2117+ ge::GetThreadLocalContext().graph_options_[ge::FUSION_SWITCH_FILE] =
2118+ GetCodeDir() + "/tests/engines/nn_engine/st/testcase/fusion_config_manager/custom_config/fusion_config.json";
2119+ std::string all_str = "ALL";
2120+ Configuration::Instance(fe::AI_CORE_NAME)
2121+ .config_str_param_vec_[static_cast<size_t>(CONFIG_STR_PARAM::FusionLicense)] = all_str;
2122+ optimizer->fusion_priority_mgr_ptr_->Initialize();
2123+ optimizer->ops_kernel_info_store_ptr_ = std::make_shared<FEOpsKernelInfoStore>(fe::AI_CORE_NAME);
2124+ optimizer->graph_fusion_ptr_ =
2125+ std::make_shared<GraphFusion>(fusion_rule_mgr, ops_kernel_info_store_ptr_, optimizer->fusion_priority_mgr_ptr_);
2126+ optimizer->space_size_calculator_ptr_ = std::make_shared<SpaceSizeCalculator>();
2127+ optimizer->op_setter_ptr_ = std::make_shared<OpSetter>(AI_CORE_NAME);
2128+ std::string switch_file_path =
2129+ GetCodeDir() + "/tests/engines/nn_engine/ut/testcase/fusion_engine/graph_optimizer/fusion_switch_file.json";
2130+ if (RealPath(switch_file_path).empty()) {
2131+ switch_file_path =
2132+ "../../../../../tests/engines/nn_engine/ut/testcase/fusion_engine/graph_optimizer/fusion_switch_file.json";
2133+ }
2134+ std::map<std::string, std::string> context_maps;
2135+ context_maps.insert(std::make_pair("ge.fusionSwitchFile", switch_file_path));
2136+ context_maps.insert(std::make_pair("ge.build_inner_model", "false"));
2137+ ge::GetThreadLocalContext().SetGraphOption(context_maps);
2138+ optimizer->fusion_priority_mgr_ptr_->Initialize();
2139+ return optimizer;
2140+}
2141+ 
2142+void UTEST_fusion_engine_fe_graph_optimizer::CreateSkpGraphOpDescs(OpDescPtr &data1_op, OpDescPtr &conv_op,
2143+ OpDescPtr &relu_op, OpDescPtr &const_op,
2144+ OpDescPtr &softmax_op, OpDescPtr &sigmoid_op,
2145+ OpDescPtr &slice_op,
2146+ const ge::GeTensorDesc &tensor_desc) {
2147+ data1_op = std::make_shared<OpDesc>("data1", "PlaceHolder");
2148+ conv_op = std::make_shared<OpDesc>("conv", "Conv2D");
2149+ relu_op = std::make_shared<OpDesc>("relu", "Relu");
2150+ const_op = std::make_shared<OpDesc>("const", "Const");
2151+ softmax_op = std::make_shared<OpDesc>("softmax", "SoftmaxV2");
2152+ sigmoid_op = std::make_shared<OpDesc>("sigmoid", "Sigmoid");
2153+ slice_op = std::make_shared<OpDesc>("strided_sliced", "StridedSliceD");
2154+ data1_op->AddOutputDesc(tensor_desc);
2155+ const_op->AddOutputDesc(tensor_desc);
2156+ conv_op->AddInputDesc(tensor_desc);
2157+ conv_op->AddInputDesc(tensor_desc);
2158+ conv_op->AddInputDesc(tensor_desc);
2159+ conv_op->AddOutputDesc(tensor_desc);
2160+ relu_op->AddInputDesc(tensor_desc);
2161+ relu_op->AddOutputDesc(tensor_desc);
2162+ sigmoid_op->AddInputDesc(tensor_desc);
2163+ sigmoid_op->AddOutputDesc(tensor_desc);
2164+ softmax_op->AddInputDesc(tensor_desc);
2165+ softmax_op->AddOutputDesc(tensor_desc);
2166+ slice_op->AddInputDesc(tensor_desc);
2167+ slice_op->AddOutputDesc(tensor_desc);
2168+}
2169+ 
2170+ComputeGraphPtr UTEST_fusion_engine_fe_graph_optimizer::CreateSkpGraph(int64_t sigmoid_block_dim) {
2171+ PlatformUtils::Instance().short_soc_version_ = "Ascend035";
2172+ PlatformUtils::Instance().pm_item_vec_[static_cast<size_t>(PlatformUtils::PlatformInfoItem::SpecifiedMemBase)] = 1;
2173+ Configuration::Instance(AI_CORE_NAME).content_map_["superkernel_plus.enable"] = "true";
2174+ vector<int64_t> dims = {3, 4, 5, 6};
2175+ ge::GeShape shape(dims);
2176+ ge::GeTensorDesc tensor_desc(shape, ge::FORMAT_NCHW, ge::DT_FLOAT);
2177+ tensor_desc.SetOriginShape(shape);
2178+ tensor_desc.SetOriginDataType(ge::DT_FLOAT);
2179+ tensor_desc.SetOriginFormat(ge::FORMAT_NCHW);
2180+ OpDescPtr data1_op, conv_op, relu_op, const_op, softmax_op, sigmoid_op, slice_op;
2181+ CreateSkpGraphOpDescs(data1_op, conv_op, relu_op, const_op, softmax_op, sigmoid_op, slice_op, tensor_desc);
2182+ for (auto *op : {conv_op.get(), relu_op.get(), sigmoid_op.get(), softmax_op.get(), slice_op.get()}) {
2183+ AttrUtils::SetInt(op, "_fe_imply_type", 6);
2184+ AttrUtils::SetInt(op, ge::TVM_ATTR_NAME_BLOCKDIM, 1);
2185+ }
2186+ AttrUtils::SetInt(sigmoid_op, ge::TVM_ATTR_NAME_BLOCKDIM, sigmoid_block_dim);
2187+ ComputeGraphPtr graph = std::make_shared<ComputeGraph>("test");
2188+ NodePtr data1_node = graph->AddNode(data1_op);
2189+ NodePtr const_node = graph->AddNode(const_op);
2190+ NodePtr conv_node = graph->AddNode(conv_op);
2191+ NodePtr relu_node = graph->AddNode(relu_op);
2192+ NodePtr sigmoid_node = graph->AddNode(sigmoid_op);
2193+ NodePtr softmax_node = graph->AddNode(softmax_op);
2194+ NodePtr slice_node = graph->AddNode(slice_op);
2195+ GraphUtils::AddEdge(data1_node->GetOutDataAnchor(0), conv_node->GetInDataAnchor(0));
2196+ GraphUtils::AddEdge(const_node->GetOutDataAnchor(0), conv_node->GetInDataAnchor(1));
2197+ GraphUtils::AddEdge(conv_node->GetOutDataAnchor(0), relu_node->GetInDataAnchor(0));
2198+ GraphUtils::AddEdge(relu_node->GetOutDataAnchor(0), sigmoid_node->GetInDataAnchor(0));
2199+ GraphUtils::AddEdge(sigmoid_node->GetOutDataAnchor(0), softmax_node->GetInDataAnchor(0));
2200+ GraphUtils::AddEdge(softmax_node->GetOutDataAnchor(0), slice_node->GetInDataAnchor(0));
2201+ return graph;
2202+}
2203+ 
2204+size_t UTEST_fusion_engine_fe_graph_optimizer::CountSkpScopes(const ComputeGraphPtr &graph) {
2205+ auto fe_graph_optimizer_ptr = std::make_shared<FEGraphOptimizer>(nullptr, AI_CORE_NAME);
2206+ fe_graph_optimizer_ptr->MatchSuperkernelPlusNodes(*graph);
2207+ set<int64_t> scope_set;
2208+ for (auto &node : graph->GetDirectNode()) {
2209+ int64_t scope_id = -1;
2210+ if (ScopeAllocator::GetSkpScopeAttr(node->GetOpDesc(), scope_id)) {
2211+ scope_set.emplace(scope_id);
2212+ }
2213+ }
2214+ return scope_set.size();
2215+}