已合并
fix: 代码规范优化 - 精确头文件引用、const修饰、全局对象初始化顺序修复 #4854
yelongjian创建于 27 天前
fix: 代码规范优化 - 精确头文件引用、const修饰、全局对象初始化顺序修复 #4854
已合并
yelongjian创建于 27 天前
共 6 个文件变更+21-15
@@ -11,7 +11,7 @@
11#ifndef GE_GRAPH_BUILD_MEMORY_MEM_ASSIGNER_H_11#ifndef GE_GRAPH_BUILD_MEMORY_MEM_ASSIGNER_H_
12#define GE_GRAPH_BUILD_MEMORY_MEM_ASSIGNER_H_12#define GE_GRAPH_BUILD_MEMORY_MEM_ASSIGNER_H_
13 13 
14-#include "framework/common/ge_inner_error_codes.h"14+#include "external/ge_common/ge_common_api_types.h"
15 15 
16namespace ge {16namespace ge {
17static const int64_t kInvalidOffset = -1;17static const int64_t kInvalidOffset = -1;
@@ -25,10 +25,16 @@ const int32_t kReshapeDataIndex = 0;
25const int32_t kReshapeShapeIndex = 1;25const int32_t kReshapeShapeIndex = 1;
26enum class OpHashValue { kReshapeType = 0, kReformatType = 1, kOpNoDelete = -1 };26enum class OpHashValue { kReshapeType = 0, kReformatType = 1, kOpNoDelete = -1 };
27 27 
28-std::map<std::string, OpHashValue> kToBeDeleteOp = {{RESHAPE, OpHashValue::kReshapeType},28+const std::map<std::string, OpHashValue> &GetToBeDeleteOp() {
29- {REFORMAT, OpHashValue::kReformatType}};29+ static const std::map<std::string, OpHashValue> kToBeDeleteOp = {{RESHAPE, OpHashValue::kReshapeType},
30-// todo 临时方案,不应该判断节点类型,应该找到这类节点的共同点,或者最终把reshape全部删除30+ {REFORMAT, OpHashValue::kReformatType}};
31-const std::set<std::string> kInputShapeContinue = {GATHERSHAPES, GATHERND};31+ return kToBeDeleteOp;
32+}
33+ 
34+const std::set<std::string> &GetInputShapeContinue() {
35+ static const std::set<std::string> kInputShapeContinue = {GATHERSHAPES, GATHERND};
36+ return kInputShapeContinue;
37+}
32 38 
33bool EnablePass(const ge::NodePtr &node) {39bool EnablePass(const ge::NodePtr &node) {
34 // todo 临时方案,编译时不应该感知单算子40 // todo 临时方案,编译时不应该感知单算子
@@ -57,7 +63,7 @@ bool EnablePass(const ge::NodePtr &node) {
57 63 
58bool IsOutDataNodeRequireInputShapeContinuous(const ge::NodePtr &node) {64bool IsOutDataNodeRequireInputShapeContinuous(const ge::NodePtr &node) {
59 for (const auto &out_data_node : node->GetOutDataNodes()) {65 for (const auto &out_data_node : node->GetOutDataNodes()) {
60- if (kInputShapeContinue.count(out_data_node->GetType()) != 0U) {66+ if (GetInputShapeContinue().count(out_data_node->GetType()) != 0U) {
61 GELOGD("Node: %s, out data node: %s, type: %s, require input shape to be continuous.", node->GetName().c_str(),67 GELOGD("Node: %s, out data node: %s, type: %s, require input shape to be continuous.", node->GetName().c_str(),
62 out_data_node->GetName().c_str(), out_data_node->GetType().c_str());68 out_data_node->GetName().c_str(), out_data_node->GetType().c_str());
63 return true;69 return true;
@@ -90,8 +96,9 @@ bool IsOutputOfSubGraph(const ge::NodePtr &node) {
90Status ReshapeRemovePass::Run(NodePtr &node) {96Status ReshapeRemovePass::Run(NodePtr &node) {
91 GE_CHECK_NOTNULL(node);97 GE_CHECK_NOTNULL(node);
92 GE_CHECK_NOTNULL(node->GetOpDesc());98 GE_CHECK_NOTNULL(node->GetOpDesc());
93- const auto it = kToBeDeleteOp.find(node->GetType());99+ const auto &to_be_delete_op = GetToBeDeleteOp();
94- OpHashValue key = (it == kToBeDeleteOp.cend()) ? OpHashValue::kOpNoDelete : it->second;100+ const auto it = to_be_delete_op.find(node->GetType());
101+ OpHashValue key = (it == to_be_delete_op.cend()) ? OpHashValue::kOpNoDelete : it->second;
95 switch (key) {102 switch (key) {
96 case OpHashValue::kReshapeType: {103 case OpHashValue::kReshapeType: {
97 if (!EnablePass(node)) {104 if (!EnablePass(node)) {
@@ -239,7 +239,7 @@ Status VariableOpPass::Run(ge::ComputeGraphPtr graph) {
239 return SUCCESS;239 return SUCCESS;
240}240}
241 241 
242-Status VariableOpPass::DealFusion(const SameVarPtr &same_vars) {242+Status VariableOpPass::DealFusion(const SameVarPtr &same_vars) const {
243 for (const auto &var_node : same_vars->var_nodes) {243 for (const auto &var_node : same_vars->var_nodes) {
244 GE_CHECK_NOTNULL(var_node);244 GE_CHECK_NOTNULL(var_node);
245 GELOGD("Begin to fusion var %s with trans", var_node->GetName().c_str());245 GELOGD("Begin to fusion var %s with trans", var_node->GetName().c_str());
@@ -393,7 +393,7 @@ Status VariableOpPass::CheckSameAndTransOp(const SameVarPtr &same_vars, bool &is
393 return SUCCESS;393 return SUCCESS;
394}394}
395 395 
396-Status VariableOpPass::CheckVariableRefLegally(const SameVarPtr &same_vars, bool &is_var_ref_legally) {396+Status VariableOpPass::CheckVariableRefLegally(const SameVarPtr &same_vars, bool &is_var_ref_legally) const {
397 is_var_ref_legally = true;397 is_var_ref_legally = true;
398 auto var_ref_nodes = GetRefVars(same_vars);398 auto var_ref_nodes = GetRefVars(same_vars);
399 GELOGD("var name %s, ref var count %zu.", same_vars->var_name.c_str(), var_ref_nodes.size());399 GELOGD("var name %s, ref var count %zu.", same_vars->var_name.c_str(), var_ref_nodes.size());
@@ -34,9 +34,9 @@ class VariableOpPass : public GraphPass {
34 Status Run(ge::ComputeGraphPtr graph) override;34 Status Run(ge::ComputeGraphPtr graph) override;
35 35 
36 private:36 private:
37- Status DealFusion(const SameVarPtr &same_vars);37+ Status DealFusion(const SameVarPtr &same_vars) const;
38 38 
39- Status CheckVariableRefLegally(const SameVarPtr &same_vars, bool &is_var_ref_legally);39+ Status CheckVariableRefLegally(const SameVarPtr &same_vars, bool &is_var_ref_legally) const;
40 40 
41 Status UpdateVarAndRefOutputFormatInfo(const GeTensorDesc &final_output, const ge::NodePtr &node,41 Status UpdateVarAndRefOutputFormatInfo(const GeTensorDesc &final_output, const ge::NodePtr &node,
42 const SameVarPtr &same_vars);42 const SameVarPtr &same_vars);
@@ -13,8 +13,7 @@
13 13 
14#include <string>14#include <string>
15 15 
16-#include "ge/ge_api_error_codes.h"16+#include "external/ge_common/ge_common_api_types.h"
17-#include "ge/ge_api_types.h"
18#include "nlohmann/json.hpp"17#include "nlohmann/json.hpp"
19 18 
20namespace ge {19namespace ge {
@@ -12,7 +12,7 @@
12#define AIR_CXX_RUNTIME_V2_TASK_PRODUCER_H12#define AIR_CXX_RUNTIME_V2_TASK_PRODUCER_H
13 13 
14#include "core/executor/multi_thread_topological/executor/schedule/task/task_package.h"14#include "core/executor/multi_thread_topological/executor/schedule/task/task_package.h"
15-#include "ge/ge_api_types.h"15+#include "external/ge_common/ge_common_api_types.h"
16#include "ge/ge_api_error_codes.h"16#include "ge/ge_api_error_codes.h"
17 17 
18namespace gert {18namespace gert {