From 6b84149e2f1fb3176f220ee34f75f4e3c174c8eb Mon Sep 17 00:00:00 2001 From: tinazhang Date: Fri, 30 Apr 2021 10:32:28 -0400 Subject: [PATCH] Address ci alarm for master branch: pclint, CppCodeStyle and codex --- mindspore/ccsrc/debug/debug_services.cc | 37 +++++++++---------- mindspore/ccsrc/debug/debug_services.h | 30 +++++++-------- mindspore/ccsrc/debug/debugger/debugger.cc | 33 ++++++++--------- mindspore/ccsrc/debug/debugger/debugger.h | 22 +++++------ .../ccsrc/debug/debugger/proto_exporter.cc | 8 ++-- .../ccsrc/debug/debugger/proto_exporter.h | 7 ++-- .../ccsrc/debug/debugger/tensor_summary.cc | 10 ++--- .../ccsrc/debug/debugger/tensor_summary.h | 8 ++-- mindspore/ccsrc/debug/tensor_data.h | 6 +-- mindspore/ccsrc/debug/tensor_load.h | 10 ++--- 10 files changed, 83 insertions(+), 88 deletions(-) diff --git a/mindspore/ccsrc/debug/debug_services.cc b/mindspore/ccsrc/debug/debug_services.cc index e4aa29c3024..359fa9b94a9 100644 --- a/mindspore/ccsrc/debug/debug_services.cc +++ b/mindspore/ccsrc/debug/debug_services.cc @@ -29,11 +29,7 @@ #ifdef ONLINE_DBG_MODE namespace mindspore { #endif -DebugServices::DebugServices() { - tensor_loader_ = new TensorLoader(); - uint32_t iter_num = -1; - tensor_loader_->set_iter_num(iter_num); -} +DebugServices::DebugServices() { tensor_loader_ = std::make_shared(); } DebugServices::DebugServices(const DebugServices &other) { tensor_loader_ = other.tensor_loader_; @@ -48,8 +44,6 @@ DebugServices &DebugServices::operator=(const DebugServices &other) { return *this; } -DebugServices::~DebugServices() { delete tensor_loader_; } - void DebugServices::AddWatchpoint( unsigned int id, unsigned int watch_condition, float parameter, const std::vector> &check_node_list, const std::vector ¶meter_list, @@ -77,8 +71,9 @@ void DebugServices::RemoveWatchpoint(unsigned int id) { watchpoint_table.erase(id); } -std::unique_ptr GetSummaryPtr(const std::shared_ptr &tensor, void *previous_tensor_ptr, - uint32_t num_elements, int tensor_dtype) { +std::unique_ptr GetSummaryPtr(const std::shared_ptr &tensor, + void *const previous_tensor_ptr, uint32_t num_elements, + int tensor_dtype) { switch (tensor_dtype) { case DbgDataType::DT_UINT8: { return std::make_unique>(tensor->GetDataPtr(), previous_tensor_ptr, num_elements); @@ -156,8 +151,8 @@ void *DebugServices::GetPrevTensor(const std::shared_ptr &tensor, bo void DebugServices::AddWatchPointsToCheck(bool init_dbg_suspend, bool step_end, bool recheck, const std::string &tensor_name, const std::string &tensor_name_no_slot, - bool *previous_iter_tensor_needed, std::string *qualified_tensor_name, - std::vector *watchpoints_to_check) { + bool *previous_iter_tensor_needed, std::string *const qualified_tensor_name, + std::vector *const watchpoints_to_check) { for (auto w_table_item : watchpoint_table) { auto wp = std::get<1>(w_table_item); // check ONLY init conditions on initial suspended state. @@ -191,10 +186,11 @@ void DebugServices::AddAnalyzedTensorToCache(const bool recheck, const unsigned } } -void DebugServices::CheckWatchpoints(std::vector *name, std::vector *slot, - std::vector *condition, std::vector *watchpoint_id, - std::vector> *parameters, - std::vector *error_codes, const std::vector &op_overflows, +void DebugServices::CheckWatchpoints(std::vector *const name, std::vector *const slot, + std::vector *const condition, std::vector *const watchpoint_id, + std::vector> *const parameters, + std::vector *const error_codes, + const std::vector &op_overflows, const std::vector &async_file_pool, std::vector> *tensor_list, const bool init_dbg_suspend, const bool step_end, const bool recheck, std::vector *device_id, @@ -818,9 +814,10 @@ std::vector> DebugServices::ReadNeededDumpedTensors( } #endif -void DebugServices::ReadNodesTensors(std::vector name, std::vector *ret_name, - std::vector *data_ptr, std::vector *data_size, - std::vector *dtype, std::vector> *shape) { +void DebugServices::ReadNodesTensors(const std::vector &name, std::vector *const ret_name, + std::vector *const data_ptr, std::vector *const data_size, + std::vector *const dtype, + std::vector> *const shape) { std::vector>> result_list; tensor_loader_->SearchTensors(name, &result_list); @@ -929,10 +926,10 @@ std::vector> DebugServices::GetNodeTensor(const CNod } #endif -bool DebugServices::TensorExistsInCurrent(std::string tensor_name) { +bool DebugServices::TensorExistsInCurrent(const std::string &tensor_name) { return tensor_loader_->TensorExistsInCurrent(tensor_name); } -void DebugServices::MoveTensorCurrentToPrev(std::string tensor_name) { +void DebugServices::MoveTensorCurrentToPrev(const std::string &tensor_name) { tensor_loader_->MoveTensorCurrentToPrev(tensor_name); } diff --git a/mindspore/ccsrc/debug/debug_services.h b/mindspore/ccsrc/debug/debug_services.h index 524d6e5911e..d8d729372c4 100644 --- a/mindspore/ccsrc/debug/debug_services.h +++ b/mindspore/ccsrc/debug/debug_services.h @@ -52,7 +52,7 @@ class DebugServices { DebugServices &operator=(const DebugServices &other); - ~DebugServices(); + ~DebugServices() = default; enum CONDITION_TYPE { HAS_NAN, @@ -121,7 +121,7 @@ class DebugServices { std::vector parameter_list; size_t location = 0; - std::string FindQualifiedTensorName(const std::string &tensor_name) { + std::string FindQualifiedTensorName(const std::string &tensor_name) const { std::string node_name = tensor_name.substr(0, tensor_name.find_first_of(':')); for (auto check_node : check_node_list) { std::string w_name = std::get<0>(check_node); @@ -135,17 +135,17 @@ class DebugServices { return {}; } - bool is_gt_wp() { + bool is_gt_wp() const { return condition.type == MAX_GT || condition.type == MIN_GT || condition.type == MEAN_GT || condition.type == SD_GT || condition.type == MAX_MIN_GT; } - bool is_lt_wp() { + bool is_lt_wp() const { return condition.type == MAX_LT || condition.type == MIN_LT || condition.type == MEAN_LT || condition.type == SD_LT || condition.type == MAX_MIN_LT; } - bool min_max_enabled() { + bool min_max_enabled() const { return condition.type == MAX_LT || condition.type == MAX_GT || condition.type == MIN_LT || condition.type == MIN_GT || condition.type == MAX_MIN_LT || condition.type == MAX_MIN_GT || (condition.type == INIT && (!parameter_list[1].disabled || !parameter_list[2].disabled)) || @@ -153,7 +153,7 @@ class DebugServices { (condition.type == TOO_SMALL && (!parameter_list[1].disabled || !parameter_list[2].disabled)); } // inf or nan related condition set - bool inf_nan_enabled() { + bool inf_nan_enabled() const { return condition.type == HAS_INF || condition.type == HAS_NAN || condition.type == GENERAL_OVERFLOW; } // mean or sd related condition set @@ -166,7 +166,7 @@ class DebugServices { return (condition.type == TOO_LARGE && !parameter_list[0].disabled) || (condition.type == TOO_SMALL && !parameter_list[0].disabled); } - bool zero_percentage_enabled() { return condition.type == ALL_ZERO || condition.type == INIT; } + bool zero_percentage_enabled() const { return condition.type == ALL_ZERO || condition.type == INIT; } bool tensor_update_ratio_mean_enabled() const { return condition.type == CHANGE_TOO_LARGE || condition.type == CHANGE_TOO_SMALL; @@ -191,9 +191,9 @@ class DebugServices { void RemoveWatchpoint(unsigned int id); void CheckWatchpoints(std::vector *name, std::vector *slot, std::vector *condition, - std::vector *watchpoint_id, std::vector> *parameters, - std::vector *error_code, const std::vector &op_overflows, - const std::vector &async_file_pool, + std::vector *const watchpoint_id, + std::vector> *parameters, std::vector *error_code, + const std::vector &op_overflows, const std::vector &async_file_pool, std::vector> *tensor_list, bool init_dbg_suspend, const bool step_end, const bool recheck, std::vector *device_id = nullptr, std::vector *root_graph_id = nullptr); @@ -243,9 +243,9 @@ class DebugServices { const std::vector &async_file_pool, std::vector> *tensor_list); #endif - void ReadNodesTensors(std::vector name, std::vector *ret_name, + void ReadNodesTensors(const std::vector &name, std::vector *ret_name, std::vector *data_ptr, std::vector *data_size, - std::vector *dtype, std::vector> *shape); + std::vector *dtype, std::vector> *const shape); #ifdef ONLINE_DBG_MODE bool IsWatchPoint(const std::string &kernel_name, const CNodePtr &kernel = nullptr) const; @@ -282,9 +282,9 @@ class DebugServices { std::vector> GetNodeTensor(const CNodePtr &kernel); #endif - bool TensorExistsInCurrent(std::string tensor_name); + bool TensorExistsInCurrent(const std::string &tensor_name); - void MoveTensorCurrentToPrev(std::string tensor_name); + void MoveTensorCurrentToPrev(const std::string &tensor_name); void SetNetName(std::string net_name); @@ -308,7 +308,7 @@ class DebugServices { std::string dump_dir; bool is_sync_mode; - TensorLoader *tensor_loader_; + std::shared_ptr tensor_loader_; }; #ifdef ONLINE_DBG_MODE } // namespace mindspore diff --git a/mindspore/ccsrc/debug/debugger/debugger.cc b/mindspore/ccsrc/debug/debugger/debugger.cc index 008c23165ac..67c94749944 100644 --- a/mindspore/ccsrc/debug/debugger/debugger.cc +++ b/mindspore/ccsrc/debug/debugger/debugger.cc @@ -191,7 +191,7 @@ void Debugger::SetOpOverflowBinPath(uint32_t graph_id) { d = opendir(overflow_bin_path.c_str()); if (d != nullptr) { struct dirent *dir; - while ((dir = readdir(d)) != NULL) { + while ((dir = readdir(d)) != nullptr) { if (dir->d_type == DT_REG) { std::string file_path = overflow_bin_path; file_path.append(dir->d_name); @@ -225,7 +225,7 @@ void Debugger::CheckDatasetSinkMode() { } } -bool Debugger::CheckDebuggerDumpEnabled() { +bool Debugger::CheckDebuggerDumpEnabled() const { // see if dump is enabled if (device_target_ == kGPUDevice) { return device::KernelRuntime::DumpDataEnabled(); @@ -233,7 +233,7 @@ bool Debugger::CheckDebuggerDumpEnabled() { return false; } -bool Debugger::CheckDebuggerEnabled() { +bool Debugger::CheckDebuggerEnabled() const { // get env variables to configure debugger const char *env_enable_char = std::getenv("ENABLE_MS_DEBUGGER"); if (env_enable_char != nullptr) { @@ -259,7 +259,7 @@ void Debugger::CheckDebuggerEnabledParam() { } } -bool Debugger::CheckDebuggerPartialMemoryEnabled() { +bool Debugger::CheckDebuggerPartialMemoryEnabled() const { const char *env_partial_mem_str = std::getenv("MS_DEBUGGER_PARTIAL_MEM"); if (env_partial_mem_str != nullptr) { MS_LOG(INFO) << "Getenv MS_DEBUGGER_PARTIAL_MEM: " << env_partial_mem_str; @@ -270,7 +270,7 @@ bool Debugger::CheckDebuggerPartialMemoryEnabled() { return false; } -bool Debugger::DebuggerBackendEnabled() { return CheckDebuggerDumpEnabled() || CheckDebuggerEnabled(); } +bool Debugger::DebuggerBackendEnabled() const { return CheckDebuggerDumpEnabled() || CheckDebuggerEnabled(); } void Debugger::Reset() { // access lock for public method @@ -326,7 +326,7 @@ void Debugger::PreExecute(const KernelGraphPtr &graph_ptr, uint32_t graph_sum) { LoadParametersAndConst(); // revert graph ptr to original value graph_ptr_ = dbg_graph_ptr; - SendMultiGraphsAndSuspend(graph_proto_list_, graph_sum); + SendMultiGraphsAndSuspend(graph_proto_list_); graph_proto_list_.clear(); } else if (graph_id == rungraph_id_list_.front() && device_target_ == kGPUDevice) { // stop only when receive the first sub run graph for each step @@ -364,7 +364,7 @@ void Debugger::PostExecute() { } } -bool Debugger::ReadNodeDataRequired(const CNodePtr &kernel) { +bool Debugger::ReadNodeDataRequired(const CNodePtr &kernel) const { if (debugger_enabled_ && !is_dataset_graph_) { auto is_watchpoint = debug_services_->IsWatchPoint(cur_name_, kernel); // if node has a watchpoint on it, is next_to node, or continue_to node then read the kernel tensor data @@ -481,7 +481,7 @@ void Debugger::CheckDatasetGraph() { GraphProto Debugger::GetGraphProto(const KernelGraphPtr &graph_ptr) const { // convert kernel graph to debugger modelproto - ModelProto model = GetDebuggerFuncGraphProto(graph_ptr_); + ModelProto model = GetDebuggerFuncGraphProto(graph_ptr); return model.graph(); } @@ -539,7 +539,7 @@ bool Debugger::SendMetadata(bool version_check) { return ret; } -void Debugger::SendMultiGraphsAndSuspend(const std::list &graph_proto_list, uint32_t graph_sum) { +void Debugger::SendMultiGraphsAndSuspend(const std::list &graph_proto_list) { if (!SendMetadata(true)) { return; } @@ -730,7 +730,7 @@ void Debugger::ProcessKViewCMD(const EventReply &reply) { } } -void AddTensorProtoInfo(TensorProto *tensor_item, TensorProto tensor) { +void AddTensorProtoInfo(TensorProto *tensor_item, const TensorProto &tensor) { tensor_item->set_node_name(tensor.node_name()); tensor_item->set_slot(tensor.slot()); tensor_item->set_iter(tensor.iter()); @@ -1005,9 +1005,9 @@ std::string GetTensorFullName(const TensorProto &tensor) { bool GetMiVersionMatched(const EventReply &reply) { return reply.version_matched(); } -bool Debugger::partial_memory() { return partial_memory_; } +bool Debugger::partial_memory() const { return partial_memory_; } -void Debugger::SetCurNode(std::string cur_name) { +void Debugger::SetCurNode(const std::string &cur_name) { // access lock for public method std::lock_guard a_lock(access_lock_); cur_name_ = cur_name; @@ -1043,7 +1043,7 @@ std::vector Debugger::CheckOpOverflow() { MS_LOG(INFO) << "processing bin file path " << overflow_bin_path << ", graph id " << graph_id; if (d != nullptr) { struct dirent *dir = nullptr; - while ((dir = readdir(d)) != NULL) { + while ((dir = readdir(d)) != nullptr) { if (dir->d_type == DT_REG) { std::string file_path = overflow_bin_path; file_path.append(dir->d_name); @@ -1123,7 +1123,7 @@ bool Debugger::CheckPort(const char *port) { return true; } -bool Debugger::CheckIp(const char *host) { +bool Debugger::CheckIp(const char *host) const { std::regex reg_ip( "(25[0-4]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[1-9])" "[.](25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])" @@ -1134,7 +1134,7 @@ bool Debugger::CheckIp(const char *host) { return std::regex_match(host_str, smat, reg_ip); } -uint32_t Debugger::GetFirstRunGraphId() { return rungraph_id_list_.front(); } +uint32_t Debugger::GetFirstRunGraphId() const { return rungraph_id_list_.front(); } void Debugger::LoadSingleAnfnode(const AnfNodePtr &anf_node, const size_t output_index) { MS_EXCEPTION_IF_NULL(anf_node); @@ -1198,7 +1198,6 @@ void Debugger::LoadGraphOutputs() { int exec_order = 1; for (const auto &node : apply_kernels) { MS_EXCEPTION_IF_NULL(node); - auto node_name = AnfAlgo::GetCNodeName(node); std::string kernel_name = node->fullname_with_scope(); auto output_size = AnfAlgo::GetOutputTensorNum(node); if (partial_memory_) { @@ -1244,7 +1243,7 @@ void Debugger::ClearCurrentData() { if (device_target_ == kGPUDevice && (debugger_enabled_ || device::KernelRuntime::DumpDataEnabledIteration())) debug_services_->EmptyCurrentTensor(); } -bool Debugger::TensorExistsInCurrent(std::string tensor_name) { +bool Debugger::TensorExistsInCurrent(const std::string &tensor_name) { return debug_services_->TensorExistsInCurrent(tensor_name); } diff --git a/mindspore/ccsrc/debug/debugger/debugger.h b/mindspore/ccsrc/debug/debugger/debugger.h index db6eda97b27..50a41fa0deb 100644 --- a/mindspore/ccsrc/debug/debugger/debugger.h +++ b/mindspore/ccsrc/debug/debugger/debugger.h @@ -82,7 +82,7 @@ class Debugger : public std::enable_shared_from_this { // don't need a graph_ptr because it is saved during pre_execute void PostExecute(); - bool ReadNodeDataRequired(const CNodePtr &kernel); + bool ReadNodeDataRequired(const CNodePtr &kernel) const; void PostExecuteNode(const CNodePtr &kernel, bool last_kernel); @@ -107,9 +107,9 @@ class Debugger : public std::enable_shared_from_this { bool debugger_enabled() const; - bool partial_memory(); + bool partial_memory() const; - void SetCurNode(std::string cur_name); + void SetCurNode(const std::string &cur_name); std::string run_level() const; @@ -120,7 +120,7 @@ class Debugger : public std::enable_shared_from_this { void SetStreamTaskToOpnameMap(const std::map, std::string> &mapping); // check if any feature that uses the debugger backend is enabled - bool DebuggerBackendEnabled(); + bool DebuggerBackendEnabled() const; void SetTrainingDone(bool training_done); @@ -140,13 +140,13 @@ class Debugger : public std::enable_shared_from_this { void LoadGraphs(const KernelGraphPtr &graph_ptr); - uint32_t GetFirstRunGraphId(); + uint32_t GetFirstRunGraphId() const; void SetGraphPtr(const KernelGraphPtr &graph_ptr) { graph_ptr_ = graph_ptr; } std::list GetGraphPtrList() { return graph_ptr_list_; } - bool TensorExistsInCurrent(std::string tensor_name); + bool TensorExistsInCurrent(const std::string &tensor_name); private: // private constructor for singleton @@ -160,14 +160,14 @@ class Debugger : public std::enable_shared_from_this { void SetOpOverflowBinPath(uint32_t graph_id); // check if dump using debugger backend is enabled - bool CheckDebuggerDumpEnabled(); + bool CheckDebuggerDumpEnabled() const; // check if debugger enabled - bool CheckDebuggerEnabled(); + bool CheckDebuggerEnabled() const; void CheckDebuggerEnabledParam(); - bool CheckDebuggerPartialMemoryEnabled(); + bool CheckDebuggerPartialMemoryEnabled() const; // check and save graph pointer void CheckGraphPtr(const KernelGraphPtr &graph_ptr); @@ -181,7 +181,7 @@ class Debugger : public std::enable_shared_from_this { // send graph and enter command wait loop void SendGraphAndSuspend(const GraphProto &graph_proto); - void SendMultiGraphsAndSuspend(const std::list &graph_proto_list, uint32_t graph_sum); + void SendMultiGraphsAndSuspend(const std::list &graph_proto_list); // wait for command and process command // send command request and process reply in a loop @@ -223,7 +223,7 @@ class Debugger : public std::enable_shared_from_this { bool CheckPort(const char *port); // Check if the IP is valid - bool CheckIp(const char *host); + bool CheckIp(const char *host) const; void LoadSingleAnfnode(const AnfNodePtr &anf_node, const size_t output_index); diff --git a/mindspore/ccsrc/debug/debugger/proto_exporter.cc b/mindspore/ccsrc/debug/debugger/proto_exporter.cc index ead91dc7692..ad61588a638 100644 --- a/mindspore/ccsrc/debug/debugger/proto_exporter.cc +++ b/mindspore/ccsrc/debug/debugger/proto_exporter.cc @@ -336,7 +336,7 @@ debugger::ModelProto DebuggerProtoExporter::GetFuncGraphProto(const FuncGraphPtr return model_; } -void DebuggerProtoExporter::ExportFuncGraph(const FuncGraphPtr &func_graph, debugger::GraphProto *graph_proto, +void DebuggerProtoExporter::ExportFuncGraph(const FuncGraphPtr &func_graph, debugger::GraphProto *const graph_proto, LocDebugDumpMode dump_location) { if (func_graph == nullptr || graph_proto == nullptr) { return; @@ -378,7 +378,7 @@ void DebuggerProtoExporter::ExportParameters(const FuncGraphPtr &func_graph, deb } } -void DebuggerProtoExporter::ExportCNodes(const FuncGraphPtr &func_graph, debugger::GraphProto *graph_proto, +void DebuggerProtoExporter::ExportCNodes(const FuncGraphPtr &func_graph, debugger::GraphProto *const graph_proto, std::map *const_map_ptr, LocDebugDumpMode dump_location) { if (func_graph == nullptr || graph_proto == nullptr || const_map_ptr == nullptr) { return; @@ -402,8 +402,8 @@ void DebuggerProtoExporter::ExportCNodes(const FuncGraphPtr &func_graph, debugge void DebuggerProtoExporter::ExportCNode(const FuncGraphPtr &func_graph, const CNodePtr &node, std::map *apply_map_ptr, - std::map *const_map_ptr, debugger::GraphProto *graph_proto, - LocDebugDumpMode dump_location) { + std::map *const_map_ptr, + debugger::GraphProto *const graph_proto, LocDebugDumpMode dump_location) { if (func_graph == nullptr || node == nullptr || apply_map_ptr == nullptr || const_map_ptr == nullptr || graph_proto == nullptr) { return; diff --git a/mindspore/ccsrc/debug/debugger/proto_exporter.h b/mindspore/ccsrc/debug/debugger/proto_exporter.h index 31839f1ccb7..9e8942d6d3b 100644 --- a/mindspore/ccsrc/debug/debugger/proto_exporter.h +++ b/mindspore/ccsrc/debug/debugger/proto_exporter.h @@ -48,14 +48,13 @@ class DebuggerProtoExporter { void SetSequenceToProto(const ValueSequeuePtr &val, debugger::ValueProto *value_proto); void SetDictionaryToProto(const ValueDictionaryPtr &val, debugger::ValueProto *value_proto); void SetNodeOutputType(const AnfNodePtr &node, debugger::TypeProto *type_proto); - - void ExportFuncGraph(const FuncGraphPtr &func_graph, debugger::GraphProto *graph_proto, + void ExportFuncGraph(const FuncGraphPtr &func_graph, debugger::GraphProto *const graph_proto, LocDebugDumpMode dump_location = kDebugOff); void ExportParameters(const FuncGraphPtr &func_graph, debugger::GraphProto *graph_proto); - void ExportCNodes(const FuncGraphPtr &func_graph, debugger::GraphProto *graph_proto, + void ExportCNodes(const FuncGraphPtr &func_graph, debugger::GraphProto *const graph_proto, std::map *const_map_ptr, LocDebugDumpMode dump_location = kDebugOff); void ExportCNode(const FuncGraphPtr &func_graph, const CNodePtr &node, std::map *apply_map_ptr, - std::map *const_map_ptr, debugger::GraphProto *graph_proto, + std::map *const_map_ptr, debugger::GraphProto *const graph_proto, LocDebugDumpMode dump_location = kDebugOff); void ExportFuncGraphOutput(const FuncGraphPtr &func_graph, const CNodePtr &ret_node, const std::map &apply_map, std::map *const_map_ptr, diff --git a/mindspore/ccsrc/debug/debugger/tensor_summary.cc b/mindspore/ccsrc/debug/debugger/tensor_summary.cc index f480aa2cfd3..4d6a1945b86 100644 --- a/mindspore/ccsrc/debug/debugger/tensor_summary.cc +++ b/mindspore/ccsrc/debug/debugger/tensor_summary.cc @@ -58,7 +58,7 @@ void AllCloseCalculator::ProcessElement(double current, double previous) { result = result && (std::abs(current - previous) <= (atol + rtol * std::abs(previous))); } -bool AllCloseCalculator::IsAllClose() { return result; } +bool AllCloseCalculator::IsAllClose() const { return result; } MeanCalculator::MeanCalculator() : mean(0.0), count(0) {} @@ -68,7 +68,7 @@ void MeanCalculator::ProcessElement(double value) { mean += delta / count; } -double MeanCalculator::GetMean() { return mean; } +double MeanCalculator::GetMean() const { return mean; } VarianceAndMeanCalculator::VarianceAndMeanCalculator() : mean(0.0), count(0), m2(0.0) {} @@ -79,9 +79,9 @@ void VarianceAndMeanCalculator::ProcessElement(double value) { m2 += delta * (value - mean); } -double VarianceAndMeanCalculator::GetMean() { return mean; } +double VarianceAndMeanCalculator::GetMean() const { return mean; } -double VarianceAndMeanCalculator::GetVariance() { +double VarianceAndMeanCalculator::GetVariance() const { if (count > 1) { return m2 / (count - 1); } else { @@ -92,7 +92,7 @@ double VarianceAndMeanCalculator::GetVariance() { double VarianceAndMeanCalculator::GetStandardDeviation() { return sqrt(GetVariance()); } template -TensorSummary::TensorSummary(void *current_tensor_ptr, void *previous_tensor_ptr, uint32_t num_elements) +TensorSummary::TensorSummary(void *current_tensor_ptr, void *const previous_tensor_ptr, uint32_t num_elements) : current_tensor_ptr(reinterpret_cast(current_tensor_ptr)), prev_tensor_ptr(reinterpret_cast(previous_tensor_ptr)), num_elements(num_elements), diff --git a/mindspore/ccsrc/debug/debugger/tensor_summary.h b/mindspore/ccsrc/debug/debugger/tensor_summary.h index 5c853d7e25b..3cf093f915d 100644 --- a/mindspore/ccsrc/debug/debugger/tensor_summary.h +++ b/mindspore/ccsrc/debug/debugger/tensor_summary.h @@ -48,7 +48,7 @@ class AllCloseCalculator { AllCloseCalculator(); ~AllCloseCalculator() = default; void ProcessElement(double current, double previous); - bool IsAllClose(); + bool IsAllClose() const; void set_atol(double value) { atol = value; } void set_rtol(double value) { rtol = value; } @@ -63,7 +63,7 @@ class MeanCalculator { MeanCalculator(); ~MeanCalculator() = default; void ProcessElement(double value); - double GetMean(); + double GetMean() const; protected: double mean; @@ -76,8 +76,8 @@ class VarianceAndMeanCalculator { ~VarianceAndMeanCalculator() = default; void ProcessElement(double value); double GetStandardDeviation(); - double GetVariance(); - double GetMean(); + double GetVariance() const; + double GetMean() const; private: double mean; diff --git a/mindspore/ccsrc/debug/tensor_data.h b/mindspore/ccsrc/debug/tensor_data.h index c8a2dc747f5..1de07779a4f 100644 --- a/mindspore/ccsrc/debug/tensor_data.h +++ b/mindspore/ccsrc/debug/tensor_data.h @@ -178,11 +178,11 @@ class TensorData { ~TensorData() {} - std::string GetName() { return this->name; } + std::string GetName() const { return this->name; } - size_t GetSlot() { return this->slot; } + size_t GetSlot() const { return this->slot; } - int GetExecutionOrder() { return this->execution_order; } + int GetExecutionOrder() const { return this->execution_order; } void SetExecutionOrder(int execution_order) { this->execution_order = execution_order; } diff --git a/mindspore/ccsrc/debug/tensor_load.h b/mindspore/ccsrc/debug/tensor_load.h index 680bd39cd01..c0b32c2e864 100644 --- a/mindspore/ccsrc/debug/tensor_load.h +++ b/mindspore/ccsrc/debug/tensor_load.h @@ -47,12 +47,12 @@ class TensorLoader { void SwapCurrentPrev() { tensor_list_map.swap(prev_tensor_list_map); } - bool TensorExistsInCurrent(std::string tensor_name) { + bool TensorExistsInCurrent(std::string tensor_name) const { return tensor_list_map.find(tensor_name) != tensor_list_map.end(); } // only parameters will return true - bool PrevTensorExistsInCurrent(std::string tensor_name) { return TensorExistsInCurrent(tensor_name + ":prev"); } + bool PrevTensorExistsInCurrent(std::string tensor_name) const { return TensorExistsInCurrent(tensor_name + ":prev"); } void MoveParametersCurrentToPrev() { MS_LOG(INFO) << "Moving parameters from current map to previous map"; @@ -69,7 +69,7 @@ class TensorLoader { } } - bool IsPrevTensor(std::string tensor_name) { + bool IsPrevTensor(std::string tensor_name) const { const std::string suffix = ":prev"; if (tensor_name.length() <= suffix.length()) return false; return std::equal(suffix.rbegin(), suffix.rend(), tensor_name.rbegin()); @@ -100,13 +100,13 @@ class TensorLoader { return tensor_list; } - std::shared_ptr GetTensor(const std::string &tensor_name) { + std::shared_ptr GetTensor(const std::string &tensor_name) const { auto iter = tensor_list_map.find(tensor_name); if (iter != tensor_list_map.end()) return iter->second; return nullptr; } - uint32_t GetIterNum() { return iter_num; } + uint32_t GetIterNum() const { return iter_num; } std::map> GetTensorMap() { return tensor_list_map; }