From 057dcdbad522a8f297d978502bfc66bec8f0c723 Mon Sep 17 00:00:00 2001 From: fary86 Date: Thu, 14 May 2020 15:44:56 +0800 Subject: [PATCH] Fix bug of log interface 1.GLOG_v can not control log level of MindData 2.Sub module ids of some source files under directory `kernel` and `device` are incorrect 3.GLOG_v can not control log level when using dlog --- mindspore/ccsrc/dataset/CMakeLists.txt | 3 +- mindspore/ccsrc/device/CMakeLists.txt | 3 +- mindspore/ccsrc/gvar/logging_level.cc | 24 ++++++++++++++ mindspore/ccsrc/kernel/CMakeLists.txt | 3 +- mindspore/ccsrc/mindrecord/CMakeLists.txt | 2 +- mindspore/ccsrc/utils/log_adapter.cc | 38 +++++++---------------- mindspore/ccsrc/utils/log_adapter.h | 7 +++-- 7 files changed, 45 insertions(+), 35 deletions(-) create mode 100644 mindspore/ccsrc/gvar/logging_level.cc diff --git a/mindspore/ccsrc/dataset/CMakeLists.txt b/mindspore/ccsrc/dataset/CMakeLists.txt index c60ff6460..0895c8c33 100644 --- a/mindspore/ccsrc/dataset/CMakeLists.txt +++ b/mindspore/ccsrc/dataset/CMakeLists.txt @@ -82,11 +82,10 @@ set_target_properties(_c_dataengine PROPERTIES ###################################################################### ################# Link with external libraries ######################## +target_link_libraries(_c_dataengine PRIVATE mindspore mindspore_gvar) if (${CMAKE_SYSTEM_NAME} MATCHES "Windows") - target_link_libraries(_c_dataengine PRIVATE mindspore) target_link_libraries(_c_dataengine PRIVATE mindspore::pybind11_module ${PYTHON_LIBRARIES} mindspore::protobuf ${SECUREC_LIBRARY}) else() - target_link_libraries(_c_dataengine PRIVATE mindspore mindspore_gvar) target_link_libraries(_c_dataengine PRIVATE mindspore::pybind11_module -ldl mindspore::protobuf ${SECUREC_LIBRARY}) endif() target_link_libraries(_c_dataengine PUBLIC mindspore::jpeg_turbo mindspore::opencv_core mindspore::opencv_imgcodecs diff --git a/mindspore/ccsrc/device/CMakeLists.txt b/mindspore/ccsrc/device/CMakeLists.txt index b56d6acc8..fba0b2071 100644 --- a/mindspore/ccsrc/device/CMakeLists.txt +++ b/mindspore/ccsrc/device/CMakeLists.txt @@ -47,5 +47,6 @@ if (ENABLE_GPU) # add_library(_mindspore_device_cuda_obj OBJECT ${CUDA_SRC_LIST}) endif () -set_property(SOURCE ${DEVICE_SRC_LIST} PROPERTY COMPILE_DEFINITIONS SUBMODULE_ID=mindspore::SubModuleId::SM_DEVICE) +set_property(SOURCE ${DEVICE_SRC_LIST} ${D_SRC_LIST} ${CPU_SRC_LIST} + PROPERTY COMPILE_DEFINITIONS SUBMODULE_ID=mindspore::SubModuleId::SM_DEVICE) add_library(_mindspore_device_obj OBJECT ${DEVICE_SRC_LIST} ${D_SRC_LIST} ${CPU_SRC_LIST}) diff --git a/mindspore/ccsrc/gvar/logging_level.cc b/mindspore/ccsrc/gvar/logging_level.cc new file mode 100644 index 000000000..158c5c8ce --- /dev/null +++ b/mindspore/ccsrc/gvar/logging_level.cc @@ -0,0 +1,24 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "utils/log_adapter.h" + +namespace mindspore { + +// set default log level to WARNING for all sub modules +int g_ms_submodule_log_levels[NUM_SUBMODUES] = {WARNING}; + +} // namespace mindspore diff --git a/mindspore/ccsrc/kernel/CMakeLists.txt b/mindspore/ccsrc/kernel/CMakeLists.txt index 1d49f13fd..112a25890 100644 --- a/mindspore/ccsrc/kernel/CMakeLists.txt +++ b/mindspore/ccsrc/kernel/CMakeLists.txt @@ -43,5 +43,6 @@ if (ENABLE_GPU) # add_library(_mindspore_kernel_cuda_obj OBJECT ${CUDA_SRC_LIST}) endif() -set_property(SOURCE ${KERNEL_SRC_LIST} PROPERTY COMPILE_DEFINITIONS SUBMODULE_ID=mindspore::SubModuleId::SM_KERNEL) +set_property(SOURCE ${KERNEL_SRC_LIST} ${CPU_SRC_LIST} ${GPU_SRC_LIST} ${D_SRC_LIST} + PROPERTY COMPILE_DEFINITIONS SUBMODULE_ID=mindspore::SubModuleId::SM_KERNEL) add_library(_mindspore_kernel_obj OBJECT ${KERNEL_SRC_LIST} ${CPU_SRC_LIST} ${GPU_SRC_LIST} ${D_SRC_LIST}) diff --git a/mindspore/ccsrc/mindrecord/CMakeLists.txt b/mindspore/ccsrc/mindrecord/CMakeLists.txt index b49ad7179..4b2a30c9f 100644 --- a/mindspore/ccsrc/mindrecord/CMakeLists.txt +++ b/mindspore/ccsrc/mindrecord/CMakeLists.txt @@ -28,7 +28,7 @@ set_target_properties(_c_mindrecord PROPERTIES # add link library if (${CMAKE_SYSTEM_NAME} MATCHES "Windows") - target_link_libraries(_c_mindrecord PRIVATE mindspore::sqlite mindspore mindspore::protobuf) + target_link_libraries(_c_mindrecord PRIVATE mindspore::sqlite mindspore mindspore_gvar mindspore::protobuf) else() target_link_libraries(_c_mindrecord PRIVATE mindspore::sqlite ${PYTHON_LIB} ${SECUREC_LIBRARY} mindspore mindspore_gvar mindspore::protobuf) endif() diff --git a/mindspore/ccsrc/utils/log_adapter.cc b/mindspore/ccsrc/utils/log_adapter.cc index ffbb95216..cd248acda 100644 --- a/mindspore/ccsrc/utils/log_adapter.cc +++ b/mindspore/ccsrc/utils/log_adapter.cc @@ -241,28 +241,6 @@ static std::string GetEnv(const std::string &envvar) { return std::string(value); } -#ifndef USE_GLOG -// set default log warning to WARNING -int g_mslog_level = WARNING; - -static void InitMsLogLevel() { - int log_level = WARNING; // set default log level to WARNING - auto str_level = GetEnv("GLOG_v"); - if (str_level.size() == 1) { - int ch = str_level.c_str()[0]; - ch = ch - '0'; // substract ASCII code of '0', which is 48 - if (ch >= DEBUG && ch <= ERROR) { - log_level = ch; - } - } - g_mslog_level = log_level; -} - -#endif - -// set default log level to WARNING for all sub modules -int g_ms_submodule_log_levels[NUM_SUBMODUES] = {WARNING}; - enum LogConfigToken { INVALID, // indicate invalid token LEFT_BRACE, // '{' @@ -449,7 +427,16 @@ static MsLogLevel GetGlobalLogLevel() { #ifdef USE_GLOG return static_cast(FLAGS_v); #else - return static_cast(g_mslog_level); + int log_level = WARNING; // set default log level to WARNING + auto str_level = GetEnv("GLOG_v"); + if (str_level.size() == 1) { + int ch = str_level.c_str()[0]; + ch = ch - '0'; // substract ASCII code of '0', which is 48 + if (ch >= DEBUG && ch <= ERROR) { + log_level = ch; + } + } + return static_cast(log_level); #endif } @@ -521,10 +508,7 @@ void mindspore_log_init(void) { FLAGS_logtostderr = true; MS_LOG(WARNING) << "`GLOG_log_dir` is not set, output log to screen."; } - - mindspore::InitSubModulesLogLevel(); -#else - mindspore::InitMsLogLevel(); #endif + mindspore::InitSubModulesLogLevel(); } } diff --git a/mindspore/ccsrc/utils/log_adapter.h b/mindspore/ccsrc/utils/log_adapter.h index a572cfa21..dfd463ee1 100644 --- a/mindspore/ccsrc/utils/log_adapter.h +++ b/mindspore/ccsrc/utils/log_adapter.h @@ -125,10 +125,11 @@ enum SubModuleId : int { #define SUBMODULE_ID mindspore::SubModuleId::SM_ME #endif -#ifndef USE_GLOG -extern int g_mslog_level; -#endif +#if defined(_WIN32) || defined(_WIN64) +extern int g_ms_submodule_log_levels[] __attribute__((dllexport)); +#else extern int g_ms_submodule_log_levels[] __attribute__((visibility("default"))); +#endif class LogWriter { public: -- GitLab