已合并
【质量加固】为只读成员函数补充 const 修饰 #4615
WXQ123123创建于 10 天前
【质量加固】为只读成员函数补充 const 修饰 #4615
已合并
共 16 个文件变更+21-21
| @@ -939,7 +939,7 @@ void IsSymbolNodePreReuse(const Node *const node, const bool has_subgraph_data, | |||
| 939 | } | 939 | } |
| 940 | } | 940 | } |
| 941 | 941 | ||
| 942 | -bool BlockMemAssigner::GetOutputNodeReuseMemFlagByIndex(const int32_t index) { | 942 | +bool BlockMemAssigner::GetOutputNodeReuseMemFlagByIndex(const int32_t index) const { |
| 943 | if (output_index_to_reuse_mem_flag_.size() == 0U) { | 943 | if (output_index_to_reuse_mem_flag_.size() == 0U) { |
| 944 | return false; | 944 | return false; |
| 945 | } | 945 | } |
| @@ -949,7 +949,7 @@ bool BlockMemAssigner::GetOutputNodeReuseMemFlagByIndex(const int32_t index) { | |||
| 949 | : false; | 949 | : false; |
| 950 | } | 950 | } |
| 951 | 951 | ||
| 952 | -bool BlockMemAssigner::GetInputNodeReuseMemFlag(const NodePtr &n) { | 952 | +bool BlockMemAssigner::GetInputNodeReuseMemFlag(const NodePtr &n) const { |
| 953 | if (input_index_to_reuse_mem_flag_.size() == 0U) { | 953 | if (input_index_to_reuse_mem_flag_.size() == 0U) { |
| 954 | return false; | 954 | return false; |
| 955 | } | 955 | } |
| @@ -136,13 +136,13 @@ class BlockMemAssigner : public MemAssigner { | |||
| 136 | /// @brief check if input node reuse memory | 136 | /// @brief check if input node reuse memory |
| 137 | /// @param [in] n input node | 137 | /// @param [in] n input node |
| 138 | /// @return bool | 138 | /// @return bool |
| 139 | - bool GetInputNodeReuseMemFlag(const NodePtr &n); | 139 | + bool GetInputNodeReuseMemFlag(const NodePtr &n) const; |
| 140 | 140 | ||
| 141 | /// @ingroup GE | 141 | /// @ingroup GE |
| 142 | /// @brief check if a input of net output node reuse memory | 142 | /// @brief check if a input of net output node reuse memory |
| 143 | /// @param [in] index input index of netoutput node | 143 | /// @param [in] index input index of netoutput node |
| 144 | /// @return bool | 144 | /// @return bool |
| 145 | - bool GetOutputNodeReuseMemFlagByIndex(const int32_t index); | 145 | + bool GetOutputNodeReuseMemFlagByIndex(const int32_t index) const; |
| 146 | 146 | ||
| 147 | /// @ingroup GE | 147 | /// @ingroup GE |
| 148 | /// @brief Check pre_reuse flag & post_reuse glag for each symbol | 148 | /// @brief Check pre_reuse flag & post_reuse glag for each symbol |
| @@ -1203,7 +1203,7 @@ Status ge::EnginePartitioner::SplitSubGraphs(const ge::ComputeGraphPtr &compute_ | |||
| 1203 | 1203 | ||
| 1204 | /// before calling this function, the direct path between src and dst are already removed. | 1204 | /// before calling this function, the direct path between src and dst are already removed. |
| 1205 | /// return true if a second path is found | 1205 | /// return true if a second path is found |
| 1206 | -bool ge::EnginePartitioner::HasSecondPath(size_t src, size_t dst, size_t upper_bound) { | 1206 | +bool ge::EnginePartitioner::HasSecondPath(size_t src, size_t dst, size_t upper_bound) const { |
| 1207 | bool has_second = false; | 1207 | bool has_second = false; |
| 1208 | if (graph_info_.clusters_.at(src)->out_clu_.empty() || graph_info_.clusters_.at(dst)->in_clu_.empty()) { | 1208 | if (graph_info_.clusters_.at(src)->out_clu_.empty() || graph_info_.clusters_.at(dst)->in_clu_.empty()) { |
| 1209 | return has_second; | 1209 | return has_second; |
| @@ -1221,7 +1221,7 @@ bool ge::EnginePartitioner::HasSecondPath(size_t src, size_t dst, size_t upper_b | |||
| 1221 | size_t cluster = temp_stack.back(); | 1221 | size_t cluster = temp_stack.back(); |
| 1222 | second_path_ids.emplace_back(cluster); | 1222 | second_path_ids.emplace_back(cluster); |
| 1223 | temp_stack.pop_back(); | 1223 | temp_stack.pop_back(); |
| 1224 | - ClusterPtr cur_cluster = graph_info_.clusters_[cluster]; | 1224 | + ClusterPtr cur_cluster = graph_info_.clusters_.at(cluster); |
| 1225 | if (!visited.insert(cluster).second) { | 1225 | if (!visited.insert(cluster).second) { |
| 1226 | continue; | 1226 | continue; |
| 1227 | } | 1227 | } |
| @@ -162,7 +162,7 @@ class EnginePartitioner { | |||
| 162 | void MergeTwoClusters(size_t parent_cluster, size_t &child_cluster); | 162 | void MergeTwoClusters(size_t parent_cluster, size_t &child_cluster); |
| 163 | 163 | ||
| 164 | // Check if there's a second path between two clusters. The max path length is upper_bound | 164 | // Check if there's a second path between two clusters. The max path length is upper_bound |
| 165 | - bool HasSecondPath(size_t src, size_t dst, size_t upper_bound); | 165 | + bool HasSecondPath(size_t src, size_t dst, size_t upper_bound) const; |
| 166 | Status MarkClustersWithConsistantId(); | 166 | Status MarkClustersWithConsistantId(); |
| 167 | // Mark all clusters | 167 | // Mark all clusters |
| 168 | void MarkClusters(); | 168 | void MarkClusters(); |
| @@ -1220,7 +1220,7 @@ graphStatus TransOpWithoutReshapeFusionPass::InsertNewTransOp(const ComputeGraph | |||
| 1220 | return RelinkControlEdge(index, out_anchor, new_trans_nodes); | 1220 | return RelinkControlEdge(index, out_anchor, new_trans_nodes); |
| 1221 | } | 1221 | } |
| 1222 | 1222 | ||
| 1223 | -bool TransOpWithoutReshapeFusionPass::CheckIfHasSameOutControlEdge(const NodePtr node, const NodePtr out_node) { | 1223 | +bool TransOpWithoutReshapeFusionPass::CheckIfHasSameOutControlEdge(const NodePtr node, const NodePtr out_node) const { |
| 1224 | auto out_anchor = node->GetOutControlAnchor(); | 1224 | auto out_anchor = node->GetOutControlAnchor(); |
| 1225 | for (auto peer_in_anchor : out_anchor->GetPeerInControlAnchors()) { | 1225 | for (auto peer_in_anchor : out_anchor->GetPeerInControlAnchors()) { |
| 1226 | if (peer_in_anchor->GetOwnerNode() == out_node) { | 1226 | if (peer_in_anchor->GetOwnerNode() == out_node) { |
| @@ -27,7 +27,7 @@ class TransOpWithoutReshapeFusionPass : public GraphPass { | |||
| 27 | 27 | ||
| 28 | private: | 28 | private: |
| 29 | graphStatus AddControlEdgeForNewTransNode(const int32_t index, const std::vector<NodePtr> &new_trans_nodes); | 29 | graphStatus AddControlEdgeForNewTransNode(const int32_t index, const std::vector<NodePtr> &new_trans_nodes); |
| 30 | - bool CheckIfHasSameOutControlEdge(const NodePtr node, const NodePtr out_node); | 30 | + bool CheckIfHasSameOutControlEdge(const NodePtr node, const NodePtr out_node) const; |
| 31 | void SetRemainNode(const std::vector<std::pair<OutDataAnchorPtr, InDataAnchorPtr>> &nodes_anchor); | 31 | void SetRemainNode(const std::vector<std::pair<OutDataAnchorPtr, InDataAnchorPtr>> &nodes_anchor); |
| 32 | bool IsFormatContinuous(const OutDataAnchorPtr &out_anchor, const InDataAnchorPtr &in_anchor) const; | 32 | bool IsFormatContinuous(const OutDataAnchorPtr &out_anchor, const InDataAnchorPtr &in_anchor) const; |
| 33 | bool IsTransOpDataTypeContinuous(const OutDataAnchorPtr &out_anchor, const InDataAnchorPtr &in_anchor) const; | 33 | bool IsTransOpDataTypeContinuous(const OutDataAnchorPtr &out_anchor, const InDataAnchorPtr &in_anchor) const; |
| @@ -484,7 +484,7 @@ bool NotaskPassBase::IsPreNodeWithSubgraph(const ge::InDataAnchorPtr &in_anchor) | |||
| 484 | return (op_desc != nullptr) ? (!op_desc->GetSubgraphInstanceNames().empty()) : false; | 484 | return (op_desc != nullptr) ? (!op_desc->GetSubgraphInstanceNames().empty()) : false; |
| 485 | } | 485 | } |
| 486 | 486 | ||
| 487 | -bool NotaskPassBase::IsPreNodeTypeValid(const ge::InDataAnchorPtr &in_anchor) { | 487 | +bool NotaskPassBase::IsPreNodeTypeValid(const ge::InDataAnchorPtr &in_anchor) const { |
| 488 | ge::NodePtr node = nullptr; | 488 | ge::NodePtr node = nullptr; |
| 489 | 489 | ||
| 490 | GetFirstNotRefNode(in_anchor, node); | 490 | GetFirstNotRefNode(in_anchor, node); |
| @@ -528,7 +528,7 @@ bool NotaskPassBase::IsPreOutAnchorValidMultiRef(const ge::OutDataAnchorPtr out_ | |||
| 528 | return true; | 528 | return true; |
| 529 | } | 529 | } |
| 530 | 530 | ||
| 531 | -bool NotaskPassBase::IsPreNodeAttrValid(const ge::OpDescPtr &pre_op_desc) { | 531 | +bool NotaskPassBase::IsPreNodeAttrValid(const ge::OpDescPtr &pre_op_desc) const { |
| 532 | string pre_node_name = pre_op_desc->GetName(); | 532 | string pre_node_name = pre_op_desc->GetName(); |
| 533 | bool is_continous_input = false; | 533 | bool is_continous_input = false; |
| 534 | bool is_continous_output = false; | 534 | bool is_continous_output = false; |
| @@ -63,11 +63,11 @@ class NotaskPassBase : public GraphPass { | |||
| 63 | bool InputCheck(const ge::NodePtr &node); | 63 | bool InputCheck(const ge::NodePtr &node); |
| 64 | bool CheckTensorAlign(const ge::NodePtr &node, const size_t input_index) const; | 64 | bool CheckTensorAlign(const ge::NodePtr &node, const size_t input_index) const; |
| 65 | bool HasSameSourceAnchor(const ge::InDataAnchorPtr &in_anchor, std::set<ge::OutDataAnchorPtr> &src_anchors) const; | 65 | bool HasSameSourceAnchor(const ge::InDataAnchorPtr &in_anchor, std::set<ge::OutDataAnchorPtr> &src_anchors) const; |
| 66 | - bool IsPreNodeTypeValid(const ge::InDataAnchorPtr &in_anchor); | 66 | + bool IsPreNodeTypeValid(const ge::InDataAnchorPtr &in_anchor) const; |
| 67 | bool IsPreNodeWithSubgraph(const ge::InDataAnchorPtr &in_anchor) const; | 67 | bool IsPreNodeWithSubgraph(const ge::InDataAnchorPtr &in_anchor) const; |
| 68 | bool IsPreOutAnchorCanReuse(const ge::OutDataAnchorPtr out_anchor) const; | 68 | bool IsPreOutAnchorCanReuse(const ge::OutDataAnchorPtr out_anchor) const; |
| 69 | bool IsPreOutAnchorValidMultiRef(const ge::OutDataAnchorPtr out_anchor) const; | 69 | bool IsPreOutAnchorValidMultiRef(const ge::OutDataAnchorPtr out_anchor) const; |
| 70 | - bool IsPreNodeAttrValid(const ge::OpDescPtr &pre_op_desc); | 70 | + bool IsPreNodeAttrValid(const ge::OpDescPtr &pre_op_desc) const; |
| 71 | bool IsSameInputMemType(const ge::OpDescPtr &pre_op_desc, const size_t output_idx, | 71 | bool IsSameInputMemType(const ge::OpDescPtr &pre_op_desc, const size_t output_idx, |
| 72 | std::set<int64_t> &mem_types) const; | 72 | std::set<int64_t> &mem_types) const; |
| 73 | bool IsScalarInput(const ge::NodePtr &node, const size_t input_index) const; | 73 | bool IsScalarInput(const ge::NodePtr &node, const size_t input_index) const; |
| @@ -736,7 +736,7 @@ Status VariableOpPass::RenewVarDesc(uint64_t session_id, const NodePtr &node, co | |||
| 736 | return SUCCESS; | 736 | return SUCCESS; |
| 737 | } | 737 | } |
| 738 | 738 | ||
| 739 | -std::vector<NodePtr> VariableOpPass::GetRefVars(const SameVarPtr &same_vars) { | 739 | +std::vector<NodePtr> VariableOpPass::GetRefVars(const SameVarPtr &same_vars) const { |
| 740 | std::vector<NodePtr> nodes; | 740 | std::vector<NodePtr> nodes; |
| 741 | auto iter = var_and_var_ref_map_.find(same_vars); | 741 | auto iter = var_and_var_ref_map_.find(same_vars); |
| 742 | if (iter != var_and_var_ref_map_.end()) { | 742 | if (iter != var_and_var_ref_map_.end()) { |
| @@ -62,7 +62,7 @@ class VariableOpPass : public GraphPass { | |||
| 62 | Status RenewVarDesc(const ge::ComputeGraphPtr &graph) const; | 62 | Status RenewVarDesc(const ge::ComputeGraphPtr &graph) const; |
| 63 | Status RenewVarDesc(uint64_t session_id, const NodePtr &node, const VarTransRoad &fusion_road) const; | 63 | Status RenewVarDesc(uint64_t session_id, const NodePtr &node, const VarTransRoad &fusion_road) const; |
| 64 | 64 | ||
| 65 | - std::vector<NodePtr> GetRefVars(const SameVarPtr &same_vars); | 65 | + std::vector<NodePtr> GetRefVars(const SameVarPtr &same_vars) const; |
| 66 | std::map<SameVarPtr, std::set<NodePtr>> var_and_var_ref_map_; | 66 | std::map<SameVarPtr, std::set<NodePtr>> var_and_var_ref_map_; |
| 67 | 67 | ||
| 68 | GraphRebuildStateCtrl *var_accelerate_ctrl_; | 68 | GraphRebuildStateCtrl *var_accelerate_ctrl_; |
| @@ -184,7 +184,7 @@ FlowModelPtr DflowGraphManager::GetFlowModel(uint32_t graph_id) const { | |||
| 184 | return nullptr; | 184 | return nullptr; |
| 185 | } | 185 | } |
| 186 | 186 | ||
| 187 | -bool DflowGraphManager::GetOptionsRunGraphFlag() { | 187 | +bool DflowGraphManager::GetOptionsRunGraphFlag() const { |
| 188 | if (!is_initialized_) { | 188 | if (!is_initialized_) { |
| 189 | GELOGW("[Get][OptionsRunGraphFlag] DflowGraphManager not initialized."); | 189 | GELOGW("[Get][OptionsRunGraphFlag] DflowGraphManager not initialized."); |
| 190 | return false; | 190 | return false; |
| @@ -80,7 +80,7 @@ class DflowGraphManager { | |||
| 80 | 80 | ||
| 81 | /// @brief get flag of whether need load and run model or not | 81 | /// @brief get flag of whether need load and run model or not |
| 82 | /// @return True or False | 82 | /// @return True or False |
| 83 | - bool GetOptionsRunGraphFlag(); | 83 | + bool GetOptionsRunGraphFlag() const; |
| 84 | 84 | ||
| 85 | private: | 85 | private: |
| 86 | bool is_initialized_{false}; | 86 | bool is_initialized_{false}; |
| @@ -72,7 +72,7 @@ ge::Status L2MemPool::Finalize(bool no_log) { | |||
| 72 | return memory_pool_->Finalize(no_log); | 72 | return memory_pool_->Finalize(no_log); |
| 73 | } | 73 | } |
| 74 | 74 | ||
| 75 | -aclrtStream L2MemPool::GetStream() { | 75 | +aclrtStream L2MemPool::GetStream() const { |
| 76 | return stream_; | 76 | return stream_; |
| 77 | } | 77 | } |
| 78 | 78 | ||
| @@ -67,7 +67,7 @@ class L2MemPool : public ge::Allocator, public MemSynchronizer { | |||
| 67 | memory_pool_->GetId().c_str()); | 67 | memory_pool_->GetId().c_str()); |
| 68 | } | 68 | } |
| 69 | } | 69 | } |
| 70 | - aclrtStream GetStream(); | 70 | + aclrtStream GetStream() const; |
| 71 | void SetStream(aclrtStream stream); | 71 | void SetStream(aclrtStream stream); |
| 72 | ge::MemBlock *MoveL2ToL1(ge::MemBlock *block); | 72 | ge::MemBlock *MoveL2ToL1(ge::MemBlock *block); |
| 73 | 73 | ||
| @@ -110,7 +110,7 @@ void HostExecutorDumper::SetOpDescInfo(NodeDumpUnit &dump_unit, ge::OpDescPtr &o | |||
| 110 | } | 110 | } |
| 111 | } | 111 | } |
| 112 | 112 | ||
| 113 | -bool HostExecutorDumper::IsInDumpStep(const int64_t step_id, const std::string &dump_step) { | 113 | +bool HostExecutorDumper::IsInDumpStep(const int64_t step_id, const std::string &dump_step) const { |
| 114 | if (!dump_step.empty()) { | 114 | if (!dump_step.empty()) { |
| 115 | const auto step = step_set_.find(step_id); | 115 | const auto step = step_set_.find(step_id); |
| 116 | if (step != step_set_.end()) { | 116 | if (step != step_set_.end()) { |
| @@ -39,7 +39,7 @@ class HostExecutorDumper : public ExecutorDumper { | |||
| 39 | ge::Status HostDataDump(const Node *node, ExecutorEvent event); | 39 | ge::Status HostDataDump(const Node *node, ExecutorEvent event); |
| 40 | ge::Status DoHostDataDump(NodeDumpUnit &dump_unit, const ge::DumpProperties &dump_properties); | 40 | ge::Status DoHostDataDump(NodeDumpUnit &dump_unit, const ge::DumpProperties &dump_properties); |
| 41 | void ParseDumpStep(); | 41 | void ParseDumpStep(); |
| 42 | - bool IsInDumpStep(const int64_t step_id, const std::string &dump_step); | 42 | + bool IsInDumpStep(const int64_t step_id, const std::string &dump_step) const; |
| 43 | 43 | ||
| 44 | private: | 44 | private: |
| 45 | ge::Status OnUpdateDumpUnitForHostDump(const Node &node); | 45 | ge::Status OnUpdateDumpUnitForHostDump(const Node &node); |
🔴 Critical
变更行:engine_partitioner.h:165 为
HasSecondPath(size_t src, size_t dst, size_t upper_bound)增加了const修饰,对应的定义(engine_partitioner.cc:1206)也同步改为 const。受影响行为/契约:成员函数变为 const 后,函数体内
this为const EnginePartitioner*,因此成员graph_info_(GraphPartitionInfo,engine_partitioner.h:191)在函数内是 const 对象。失败模式:engine_partitioner.cc:1224
ClusterPtr cur_cluster = graph_info_.clusters_[cluster];对std::unordered_map<size_t, ClusterPtr>(engine_partitioner.h:95)调用operator[]。std::unordered_map::operator[]只有非 const 重载,对 const 容器调用属于编译错误("passing 'const unordered_map' as 'this' argument discards qualifiers" / "no matching operator[]"),导致 engine_partitioner 模块无法编译,属于构建失败。注意同函数第 1208 行用的clusters_.at(...)有 const 重载,可以正常编译。建议:将 engine_partitioner.cc:1224 的
graph_info_.clusters_[cluster]改为graph_info_.clusters_.at(cluster)(与第 1208 行一致);或撤销 engine_partitioner.h:165 的 const 修饰。二选一即可使模块恢复编译。