From 61f2f19d9a57f03d71298b0ae61bf90ed37d2ceb Mon Sep 17 00:00:00 2001 From: luopengting Date: Wed, 21 Apr 2021 11:15:51 +0800 Subject: [PATCH] make GetSubModuleName() as common function Fix wrong module name of rdr files, make GetSubModuleName() as a common function. If rdr also has SUB_MODULE_NAMES, then if log_adapter modifies the name of the module, the module name obtained by the rdr module will be wrong. Mainly involves the following modifications: 1. move GetSubModuleName() from log_adapter.cc to log_adapter_common.cc 2. delete GetSubModuleName() in rdr module --- .../ccsrc/debug/rdr/running_data_recorder.cc | 34 ---------------- .../{get_time.cc => log_adapter_common.cc} | 4 ++ mindspore/core/utils/log_adapter.cc | 34 ---------------- mindspore/core/utils/log_adapter.h | 39 +++++++++++++++++++ 4 files changed, 43 insertions(+), 68 deletions(-) rename mindspore/core/gvar/{get_time.cc => log_adapter_common.cc} (92%) diff --git a/mindspore/ccsrc/debug/rdr/running_data_recorder.cc b/mindspore/ccsrc/debug/rdr/running_data_recorder.cc index b9f8997358..d91310fd75 100644 --- a/mindspore/ccsrc/debug/rdr/running_data_recorder.cc +++ b/mindspore/ccsrc/debug/rdr/running_data_recorder.cc @@ -29,40 +29,6 @@ #include "debug/rdr/task_debug_info_recorder.h" #endif // ENABLE_D namespace mindspore { -namespace { -static const char *GetSubModuleName(SubModuleId module_id) { - static const char *sub_module_names[NUM_SUBMODUES] = { - "UNKNOWN", // SM_UNKNOWN - "CORE", // SM_CORE - "ANALYZER", // SM_ANALYZER - "COMMON", // SM_COMMON - "DEBUG", // SM_DEBUG - "DEVICE", // SM_DEVICE - "GE_ADPT", // SM_GE_ADPT - "IR", // SM_IR - "KERNEL", // SM_KERNEL - "MD", // SM_MD - "ME", // SM_ME - "EXPRESS", // SM_EXPRESS - "OPTIMIZER", // SM_OPTIMIZER - "PARALLEL", // SM_PARALLEL - "PARSER", // SM_PARSER - "PIPELINE", // SM_PIPELINE - "PRE_ACT", // SM_PRE_ACT - "PYNATIVE", // SM_PYNATIVE - "SESSION", // SM_SESSION - "UTILS", // SM_UTILS - "VM", // SM_VM - "PROFILER", // SM_PROFILER - "PS", // SM_PS - "LITE", // SM_LITE - "HCCL_ADPT", // SM_HCCL_ADPT - "MINDQUANTUM" // SM_MINDQUANTUM - }; - - return sub_module_names[module_id % NUM_SUBMODUES]; -} -} // namespace namespace RDR { #ifdef ENABLE_D bool RecordTaskDebugInfo(SubModuleId module, const std::string &name, diff --git a/mindspore/core/gvar/get_time.cc b/mindspore/core/gvar/log_adapter_common.cc similarity index 92% rename from mindspore/core/gvar/get_time.cc rename to mindspore/core/gvar/log_adapter_common.cc index 7122e084da..bc9bae95cc 100644 --- a/mindspore/core/gvar/get_time.cc +++ b/mindspore/core/gvar/log_adapter_common.cc @@ -19,6 +19,10 @@ #include "utils/log_adapter.h" namespace mindspore { +const char *GetSubModuleName(SubModuleId module_id, const char **sub_module_names) { + return sub_module_names[module_id % NUM_SUBMODUES]; +} + // export GetTimeString for all sub modules std::string GetTimeString() { #define BUFLEN 80 diff --git a/mindspore/core/utils/log_adapter.cc b/mindspore/core/utils/log_adapter.cc index a1948a73e6..02744b9f09 100644 --- a/mindspore/core/utils/log_adapter.cc +++ b/mindspore/core/utils/log_adapter.cc @@ -112,40 +112,6 @@ static int GetSlogLevel(MsLogLevel level) { } #endif -static const char *GetSubModuleName(SubModuleId module_id) { - static const char *sub_module_names[NUM_SUBMODUES] = { - "UNKNOWN", // SM_UNKNOWN - "CORE", // SM_CORE - "ANALYZER", // SM_ANALYZER - "COMMON", // SM_COMMON - "DEBUG", // SM_DEBUG - "OFFLINE_DEBUG", // SM_OFFLINE_DEBUG - "DEVICE", // SM_DEVICE - "GE_ADPT", // SM_GE_ADPT - "IR", // SM_IR - "KERNEL", // SM_KERNEL - "MD", // SM_MD - "ME", // SM_ME - "EXPRESS", // SM_EXPRESS - "OPTIMIZER", // SM_OPTIMIZER - "PARALLEL", // SM_PARALLEL - "PARSER", // SM_PARSER - "PIPELINE", // SM_PIPELINE - "PRE_ACT", // SM_PRE_ACT - "PYNATIVE", // SM_PYNATIVE - "SESSION", // SM_SESSION - "UTILS", // SM_UTILS - "VM", // SM_VM - "PROFILER", // SM_PROFILER - "PS", // SM_PS - "LITE", // SM_LITE - "HCCL_ADPT", // SM_HCCL_ADPT - "MINDQUANTUM", // SM_MINDQUANTUM - "RUNTIME_FRAMEWORK" // SM_RUNTIME_FRAMEWORK - }; - - return sub_module_names[module_id % NUM_SUBMODUES]; -} void LogWriter::OutputLog(const std::ostringstream &msg) const { #ifdef USE_GLOG #define google mindspore_private diff --git a/mindspore/core/utils/log_adapter.h b/mindspore/core/utils/log_adapter.h index b64b125cb1..4f2d539f18 100644 --- a/mindspore/core/utils/log_adapter.h +++ b/mindspore/core/utils/log_adapter.h @@ -141,6 +141,45 @@ enum SubModuleId : int { #define SUBMODULE_ID mindspore::SubModuleId::SM_ME #endif +static const char *SUB_MODULE_NAMES[NUM_SUBMODUES] = { + "UNKNOWN", // SM_UNKNOWN + "CORE", // SM_CORE + "ANALYZER", // SM_ANALYZER + "COMMON", // SM_COMMON + "DEBUG", // SM_DEBUG + "OFFLINE_DEBUG", // SM_OFFLINE_DEBUG + "DEVICE", // SM_DEVICE + "GE_ADPT", // SM_GE_ADPT + "IR", // SM_IR + "KERNEL", // SM_KERNEL + "MD", // SM_MD + "ME", // SM_ME + "EXPRESS", // SM_EXPRESS + "OPTIMIZER", // SM_OPTIMIZER + "PARALLEL", // SM_PARALLEL + "PARSER", // SM_PARSER + "PIPELINE", // SM_PIPELINE + "PRE_ACT", // SM_PRE_ACT + "PYNATIVE", // SM_PYNATIVE + "SESSION", // SM_SESSION + "UTILS", // SM_UTILS + "VM", // SM_VM + "PROFILER", // SM_PROFILER + "PS", // SM_PS + "LITE", // SM_LITE + "HCCL_ADPT", // SM_HCCL_ADPT + "MINDQUANTUM", // SM_MINDQUANTUM + "RUNTIME_FRAMEWORK" // SM_RUNTIME_FRAMEWORK +}; + +#if defined(_WIN32) || defined(_WIN64) +extern const char *GetSubModuleName(SubModuleId module_id, const char **sub_module_names = SUB_MODULE_NAMES) + __attribute__((dllexport)); +#else +extern const char *GetSubModuleName(SubModuleId module_id, const char **sub_module_names = SUB_MODULE_NAMES) + __attribute__((visibility("default"))); +#endif + const char *EnumStrForMsLogLevel(MsLogLevel level); #if defined(_WIN32) || defined(_WIN64)