diff --git a/mindspore/ccsrc/CMakeLists.txt b/mindspore/ccsrc/CMakeLists.txt index 8d3818a7771..fb348ebbd29 100644 --- a/mindspore/ccsrc/CMakeLists.txt +++ b/mindspore/ccsrc/CMakeLists.txt @@ -116,6 +116,7 @@ foreach (_comp ${SUB_COMP}) endif () endforeach () +set_property(SOURCE ${SUB_OBJECTS_SRC} PROPERTY COMPILE_DEFINITIONS SUBMODULE_ID=mindspore::SubModuleId::SM_ME) add_library(mindspore STATIC ${SUB_OBJECTS_SRC}) target_link_libraries(mindspore proto_input) target_link_libraries(mindspore securec mindspore::flatbuffers) diff --git a/mindspore/ccsrc/common/CMakeLists.txt b/mindspore/ccsrc/common/CMakeLists.txt index 3d9634280d3..6673af4b70f 100644 --- a/mindspore/ccsrc/common/CMakeLists.txt +++ b/mindspore/ccsrc/common/CMakeLists.txt @@ -1,2 +1,3 @@ file(GLOB_RECURSE _COMMON_ALL_SRC_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.cc") +set_property(SOURCE ${_COMMON_ALL_SRC_FILES} PROPERTY COMPILE_DEFINITIONS SUBMODULE_ID=mindspore::SubModuleId::SM_COMMON) add_library(_mindspore_common_obj OBJECT ${_COMMON_ALL_SRC_FILES}) diff --git a/mindspore/ccsrc/dataset/api/CMakeLists.txt b/mindspore/ccsrc/dataset/api/CMakeLists.txt index bf575e12c92..194aeed4572 100644 --- a/mindspore/ccsrc/dataset/api/CMakeLists.txt +++ b/mindspore/ccsrc/dataset/api/CMakeLists.txt @@ -1,3 +1,5 @@ +file(GLOB_RECURSE _CURRENT_SRC_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.cc") +set_property(SOURCE ${_CURRENT_SRC_FILES} PROPERTY COMPILE_DEFINITIONS SUBMODULE_ID=mindspore::SubModuleId::SM_MD) add_library(APItoPython OBJECT de_pipeline.cc python_bindings.cc diff --git a/mindspore/ccsrc/dataset/core/CMakeLists.txt b/mindspore/ccsrc/dataset/core/CMakeLists.txt index e49ce7ff263..8141009bf62 100644 --- a/mindspore/ccsrc/dataset/core/CMakeLists.txt +++ b/mindspore/ccsrc/dataset/core/CMakeLists.txt @@ -1,3 +1,5 @@ +file(GLOB_RECURSE _CURRENT_SRC_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.cc") +set_property(SOURCE ${_CURRENT_SRC_FILES} PROPERTY COMPILE_DEFINITIONS SUBMODULE_ID=mindspore::SubModuleId::SM_MD) add_library(core OBJECT client.cc config_manager.cc diff --git a/mindspore/ccsrc/dataset/engine/CMakeLists.txt b/mindspore/ccsrc/dataset/engine/CMakeLists.txt index c7277de8def..99a07e8699a 100644 --- a/mindspore/ccsrc/dataset/engine/CMakeLists.txt +++ b/mindspore/ccsrc/dataset/engine/CMakeLists.txt @@ -3,6 +3,8 @@ if (ENABLE_TDTQUE) add_subdirectory(tdt) endif () +file(GLOB_RECURSE _CURRENT_SRC_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.cc") +set_property(SOURCE ${_CURRENT_SRC_FILES} PROPERTY COMPILE_DEFINITIONS SUBMODULE_ID=mindspore::SubModuleId::SM_MD) add_library(engine OBJECT execution_tree.cc data_buffer.cc diff --git a/mindspore/ccsrc/dataset/engine/datasetops/CMakeLists.txt b/mindspore/ccsrc/dataset/engine/datasetops/CMakeLists.txt index 9e8272d5133..dedba4a4e7b 100644 --- a/mindspore/ccsrc/dataset/engine/datasetops/CMakeLists.txt +++ b/mindspore/ccsrc/dataset/engine/datasetops/CMakeLists.txt @@ -1,5 +1,7 @@ add_subdirectory(source) +file(GLOB_RECURSE _CURRENT_SRC_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.cc") +set_property(SOURCE ${_CURRENT_SRC_FILES} PROPERTY COMPILE_DEFINITIONS SUBMODULE_ID=mindspore::SubModuleId::SM_MD) add_library(engine-datasetops OBJECT dataset_op.cc parallel_op.cc diff --git a/mindspore/ccsrc/dataset/engine/datasetops/source/CMakeLists.txt b/mindspore/ccsrc/dataset/engine/datasetops/source/CMakeLists.txt index b29c11226d6..b909a76ee12 100644 --- a/mindspore/ccsrc/dataset/engine/datasetops/source/CMakeLists.txt +++ b/mindspore/ccsrc/dataset/engine/datasetops/source/CMakeLists.txt @@ -1,6 +1,8 @@ ms_protobuf_generate(EXAMPLE_SRCS EXAMPLE_HDRS example.proto) ms_protobuf_generate(FEATURE_SRCS FEATURE_HDRS feature.proto) add_subdirectory(sampler) +file(GLOB_RECURSE _CURRENT_SRC_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.cc") +set_property(SOURCE ${_CURRENT_SRC_FILES} PROPERTY COMPILE_DEFINITIONS SUBMODULE_ID=mindspore::SubModuleId::SM_MD) add_library(engine-datasetops-source OBJECT generator_op.cc io_block.cc diff --git a/mindspore/ccsrc/dataset/engine/datasetops/source/sampler/CMakeLists.txt b/mindspore/ccsrc/dataset/engine/datasetops/source/sampler/CMakeLists.txt index b084e1c1254..5209d9ba4ad 100644 --- a/mindspore/ccsrc/dataset/engine/datasetops/source/sampler/CMakeLists.txt +++ b/mindspore/ccsrc/dataset/engine/datasetops/source/sampler/CMakeLists.txt @@ -1,3 +1,5 @@ +file(GLOB_RECURSE _CURRENT_SRC_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.cc") +set_property(SOURCE ${_CURRENT_SRC_FILES} PROPERTY COMPILE_DEFINITIONS SUBMODULE_ID=mindspore::SubModuleId::SM_MD) add_library(engine-datasetops-source-sampler OBJECT distributed_sampler.cc pk_sampler.cc diff --git a/mindspore/ccsrc/dataset/engine/tdt/CMakeLists.txt b/mindspore/ccsrc/dataset/engine/tdt/CMakeLists.txt index 9c6ec4b3881..1ced7b96b0c 100644 --- a/mindspore/ccsrc/dataset/engine/tdt/CMakeLists.txt +++ b/mindspore/ccsrc/dataset/engine/tdt/CMakeLists.txt @@ -1,3 +1,5 @@ +file(GLOB_RECURSE _CURRENT_SRC_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.cc") +set_property(SOURCE ${_CURRENT_SRC_FILES} PROPERTY COMPILE_DEFINITIONS SUBMODULE_ID=mindspore::SubModuleId::SM_MD) add_library(engine-tdt OBJECT tdt_plugin.cc ${EXAMPLE_SRCS} diff --git a/mindspore/ccsrc/dataset/kernels/CMakeLists.txt b/mindspore/ccsrc/dataset/kernels/CMakeLists.txt index 4ffb279df5c..2ebdd15e3c9 100644 --- a/mindspore/ccsrc/dataset/kernels/CMakeLists.txt +++ b/mindspore/ccsrc/dataset/kernels/CMakeLists.txt @@ -1,5 +1,7 @@ add_subdirectory(image) add_subdirectory(data) +file(GLOB_RECURSE _CURRENT_SRC_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.cc") +set_property(SOURCE ${_CURRENT_SRC_FILES} PROPERTY COMPILE_DEFINITIONS SUBMODULE_ID=mindspore::SubModuleId::SM_MD) add_library(kernels OBJECT py_func_op.cc tensor_op.cc) diff --git a/mindspore/ccsrc/dataset/kernels/data/CMakeLists.txt b/mindspore/ccsrc/dataset/kernels/data/CMakeLists.txt index a654de381ae..8472ab51929 100644 --- a/mindspore/ccsrc/dataset/kernels/data/CMakeLists.txt +++ b/mindspore/ccsrc/dataset/kernels/data/CMakeLists.txt @@ -1,3 +1,5 @@ +file(GLOB_RECURSE _CURRENT_SRC_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.cc") +set_property(SOURCE ${_CURRENT_SRC_FILES} PROPERTY COMPILE_DEFINITIONS SUBMODULE_ID=mindspore::SubModuleId::SM_MD) add_library(kernels-data OBJECT data_utils.cc one_hot_op.cc diff --git a/mindspore/ccsrc/dataset/kernels/image/CMakeLists.txt b/mindspore/ccsrc/dataset/kernels/image/CMakeLists.txt index 17931f8cc3b..583a732f7d1 100644 --- a/mindspore/ccsrc/dataset/kernels/image/CMakeLists.txt +++ b/mindspore/ccsrc/dataset/kernels/image/CMakeLists.txt @@ -1,3 +1,5 @@ +file(GLOB_RECURSE _CURRENT_SRC_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.cc") +set_property(SOURCE ${_CURRENT_SRC_FILES} PROPERTY COMPILE_DEFINITIONS SUBMODULE_ID=mindspore::SubModuleId::SM_MD) add_library(kernels-image OBJECT center_crop_op.cc cut_out_op.cc diff --git a/mindspore/ccsrc/dataset/util/CMakeLists.txt b/mindspore/ccsrc/dataset/util/CMakeLists.txt index b0630f40051..b36d612435a 100644 --- a/mindspore/ccsrc/dataset/util/CMakeLists.txt +++ b/mindspore/ccsrc/dataset/util/CMakeLists.txt @@ -1,3 +1,5 @@ +file(GLOB_RECURSE _CURRENT_SRC_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.cc") +set_property(SOURCE ${_CURRENT_SRC_FILES} PROPERTY COMPILE_DEFINITIONS SUBMODULE_ID=mindspore::SubModuleId::SM_MD) add_library(utils OBJECT arena.cc circular_pool.cc diff --git a/mindspore/ccsrc/debug/CMakeLists.txt b/mindspore/ccsrc/debug/CMakeLists.txt index c8c50dd4716..881eb7f1f8b 100644 --- a/mindspore/ccsrc/debug/CMakeLists.txt +++ b/mindspore/ccsrc/debug/CMakeLists.txt @@ -13,4 +13,5 @@ if (ENABLE_DUMP_E2E) list(APPEND _DEBUG_SRC_LIST "${CMAKE_CURRENT_SOURCE_DIR}/e2e_dump.cc") endif (ENABLE_DUMP_E2E) +set_property(SOURCE ${_DEBUG_SRC_LIST} PROPERTY COMPILE_DEFINITIONS SUBMODULE_ID=mindspore::SubModuleId::SM_DEBUG) add_library(_mindspore_debug_obj OBJECT ${_DEBUG_SRC_LIST}) diff --git a/mindspore/ccsrc/device/CMakeLists.txt b/mindspore/ccsrc/device/CMakeLists.txt index 0a6514f65ab..b56d6acc89e 100644 --- a/mindspore/ccsrc/device/CMakeLists.txt +++ b/mindspore/ccsrc/device/CMakeLists.txt @@ -47,4 +47,5 @@ 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) add_library(_mindspore_device_obj OBJECT ${DEVICE_SRC_LIST} ${D_SRC_LIST} ${CPU_SRC_LIST}) diff --git a/mindspore/ccsrc/gvar/CMakeLists.txt b/mindspore/ccsrc/gvar/CMakeLists.txt index 552ba742f1d..3ee91098326 100644 --- a/mindspore/ccsrc/gvar/CMakeLists.txt +++ b/mindspore/ccsrc/gvar/CMakeLists.txt @@ -1,4 +1,5 @@ file(GLOB_RECURSE MS_GVAR_SRC_LIST RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cc) +set_property(SOURCE ${MS_GVAR_SRC_LIST} PROPERTY COMPILE_DEFINITIONS SUBMODULE_ID=mindspore::SubModuleId::SM_COMMON) add_library(mindspore_gvar SHARED ${MS_GVAR_SRC_LIST}) if (APPLE) set_target_properties(mindspore_gvar PROPERTIES MACOSX_RPATH ON) diff --git a/mindspore/ccsrc/ir/CMakeLists.txt b/mindspore/ccsrc/ir/CMakeLists.txt index 2b17eecbed3..77bc1b7661a 100644 --- a/mindspore/ccsrc/ir/CMakeLists.txt +++ b/mindspore/ccsrc/ir/CMakeLists.txt @@ -1,2 +1,3 @@ file(GLOB_RECURSE _IR_SRC_LIST ./*.cc dtype/*.cc) +set_property(SOURCE ${_IR_SRC_LIST} PROPERTY COMPILE_DEFINITIONS SUBMODULE_ID=mindspore::SubModuleId::SM_IR) add_library(_mindspore_ir_obj OBJECT ${_IR_SRC_LIST}) diff --git a/mindspore/ccsrc/kernel/CMakeLists.txt b/mindspore/ccsrc/kernel/CMakeLists.txt index a3a5077a1a7..1d49f13fd93 100644 --- a/mindspore/ccsrc/kernel/CMakeLists.txt +++ b/mindspore/ccsrc/kernel/CMakeLists.txt @@ -43,4 +43,5 @@ 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) 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 f523eae5693..b49ad7179c7 100644 --- a/mindspore/ccsrc/mindrecord/CMakeLists.txt +++ b/mindspore/ccsrc/mindrecord/CMakeLists.txt @@ -18,6 +18,7 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-sign-compare") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=default") # add shared link library +set_property(SOURCE ${DIR_LIB_SRCS} PROPERTY COMPILE_DEFINITIONS SUBMODULE_ID=mindspore::SubModuleId::SM_MD) add_library(_c_mindrecord SHARED ${DIR_LIB_SRCS}) set_target_properties(_c_mindrecord PROPERTIES diff --git a/mindspore/ccsrc/onnx/CMakeLists.txt b/mindspore/ccsrc/onnx/CMakeLists.txt index 78884b5d051..a65ea6d450a 100644 --- a/mindspore/ccsrc/onnx/CMakeLists.txt +++ b/mindspore/ccsrc/onnx/CMakeLists.txt @@ -1,2 +1,3 @@ file(GLOB_RECURSE _ONNX_SRC_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.cc") +set_property(SOURCE ${_ONNX_SRC_FILES} PROPERTY COMPILE_DEFINITIONS SUBMODULE_ID=mindspore::SubModuleId::SM_ONNX) add_library(_mindspore_onnx_obj OBJECT ${_ONNX_SRC_FILES}) diff --git a/mindspore/ccsrc/operator/CMakeLists.txt b/mindspore/ccsrc/operator/CMakeLists.txt index 9a54ec047c1..88bcf0e532b 100644 --- a/mindspore/ccsrc/operator/CMakeLists.txt +++ b/mindspore/ccsrc/operator/CMakeLists.txt @@ -1,2 +1,3 @@ file(GLOB_RECURSE _OPERATOR_SRC_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.cc") +set_property(SOURCE ${_OPERATOR_SRC_FILES} PROPERTY COMPILE_DEFINITIONS SUBMODULE_ID=mindspore::SubModuleId::SM_ANALYZER) add_library(_mindspore_operator_obj OBJECT ${_OPERATOR_SRC_FILES}) diff --git a/mindspore/ccsrc/optimizer/CMakeLists.txt b/mindspore/ccsrc/optimizer/CMakeLists.txt index 197ece85053..44af01735ac 100644 --- a/mindspore/ccsrc/optimizer/CMakeLists.txt +++ b/mindspore/ccsrc/optimizer/CMakeLists.txt @@ -1,2 +1,3 @@ file(GLOB_RECURSE _OPTIMIZER_SRC_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.cc") +set_property(SOURCE ${_OPTIMIZER_SRC_FILES} PROPERTY COMPILE_DEFINITIONS SUBMODULE_ID=mindspore::SubModuleId::SM_OPTIMIZER) add_library(_mindspore_optimizer_obj OBJECT ${_OPTIMIZER_SRC_FILES}) diff --git a/mindspore/ccsrc/parallel/CMakeLists.txt b/mindspore/ccsrc/parallel/CMakeLists.txt index 0280266e401..940b1ed1d85 100644 --- a/mindspore/ccsrc/parallel/CMakeLists.txt +++ b/mindspore/ccsrc/parallel/CMakeLists.txt @@ -3,4 +3,5 @@ if (ENABLE_DUMP_PROTO) list(REMOVE_ITEM _PARALLEL_SRC_FILES "parallel/strategy_checkpoint/parallel_strategy_checkpoint.cc") endif () +set_property(SOURCE ${_PARALLEL_SRC_FILES} PROPERTY COMPILE_DEFINITIONS SUBMODULE_ID=mindspore::SubModuleId::SM_PARALLEL) add_library(_mindspore_parallel_obj OBJECT ${_PARALLEL_SRC_FILES}) diff --git a/mindspore/ccsrc/pipeline/CMakeLists.txt b/mindspore/ccsrc/pipeline/CMakeLists.txt index 630eb510fe4..39664d717dd 100644 --- a/mindspore/ccsrc/pipeline/CMakeLists.txt +++ b/mindspore/ccsrc/pipeline/CMakeLists.txt @@ -9,6 +9,16 @@ file(GLOB_RECURSE _PIPELINE_SRC_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "static_analysis/*.cc" ) + +file(GLOB PIPELINE_SRC_FILES "*.cc") +set_property(SOURCE ${PIPELINE_SRC_FILES} PROPERTY COMPILE_DEFINITIONS SUBMODULE_ID=mindspore::SubModuleId::SM_PIPELINE) + +file(GLOB_RECURSE PARSER_SRC_FILES "parse/*.cc") +set_property(SOURCE ${PARSER_SRC_FILES} PROPERTY COMPILE_DEFINITIONS SUBMODULE_ID=mindspore::SubModuleId::SM_PARSER) + +file(GLOB_RECURSE ANALYZER_SRC_FILES "static_analysis/*.cc") +set_property(SOURCE ${ANALYZER_SRC_FILES} PROPERTY COMPILE_DEFINITIONS SUBMODULE_ID=mindspore::SubModuleId::SM_ANALYZER) + if (ENABLE_GE OR ENABLE_D) file(GLOB_RECURSE _PIPELINE_GE_SRC_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "pipeline_ge.cc") list(APPEND _PIPELINE_SRC_FILES ${_PIPELINE_GE_SRC_FILES}) diff --git a/mindspore/ccsrc/pre_activate/CMakeLists.txt b/mindspore/ccsrc/pre_activate/CMakeLists.txt index 611b5de4e25..239757fb177 100644 --- a/mindspore/ccsrc/pre_activate/CMakeLists.txt +++ b/mindspore/ccsrc/pre_activate/CMakeLists.txt @@ -10,4 +10,5 @@ if (ENABLE_D) list(APPEND _PREACTIVATE_SRC_LIST ${_D_SRC_LIST}) endif () -add_library(_mindspore_pre_activate_obj OBJECT ${_PREACTIVATE_SRC_LIST}) \ No newline at end of file +set_property(SOURCE ${_PREACTIVATE_SRC_LIST} PROPERTY COMPILE_DEFINITIONS SUBMODULE_ID=mindspore::SubModuleId::SM_PRE_ACT) +add_library(_mindspore_pre_activate_obj OBJECT ${_PREACTIVATE_SRC_LIST}) diff --git a/mindspore/ccsrc/pybind_api/CMakeLists.txt b/mindspore/ccsrc/pybind_api/CMakeLists.txt index d04d173f600..7f32b723551 100644 --- a/mindspore/ccsrc/pybind_api/CMakeLists.txt +++ b/mindspore/ccsrc/pybind_api/CMakeLists.txt @@ -1,2 +1,3 @@ file(GLOB_RECURSE _PYBIND_API_SRC_LIST RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.cc") -add_library(_mindspore_pybind_api_obj OBJECT ${_PYBIND_API_SRC_LIST}) \ No newline at end of file +set_property(SOURCE ${_PYBIND_API_SRC_LIST} PROPERTY COMPILE_DEFINITIONS SUBMODULE_ID=mindspore::SubModuleId::SM_COMMON) +add_library(_mindspore_pybind_api_obj OBJECT ${_PYBIND_API_SRC_LIST}) diff --git a/mindspore/ccsrc/pynative/CMakeLists.txt b/mindspore/ccsrc/pynative/CMakeLists.txt index 95369861475..5139160774a 100644 --- a/mindspore/ccsrc/pynative/CMakeLists.txt +++ b/mindspore/ccsrc/pynative/CMakeLists.txt @@ -5,4 +5,5 @@ if (ENABLE_GE) list(APPEND _PYNATIVE_SRC_LIST ${_GE_SRC_LIST}) endif () +set_property(SOURCE ${_PYNATIVE_SRC_LIST} PROPERTY COMPILE_DEFINITIONS SUBMODULE_ID=mindspore::SubModuleId::SM_PYNATIVE) add_library(_mindspore_pynative_obj OBJECT ${_PYNATIVE_SRC_LIST}) diff --git a/mindspore/ccsrc/session/CMakeLists.txt b/mindspore/ccsrc/session/CMakeLists.txt index 56a7327e800..8143c0a34e4 100644 --- a/mindspore/ccsrc/session/CMakeLists.txt +++ b/mindspore/ccsrc/session/CMakeLists.txt @@ -26,4 +26,5 @@ if (ENABLE_D) list(APPEND _SESSION_SRC_LIST ${_D_SRC_LIST}) endif () -add_library(_mindspore_session_obj OBJECT ${_SESSION_SRC_LIST}) \ No newline at end of file +set_property(SOURCE ${_SESSION_SRC_LIST} PROPERTY COMPILE_DEFINITIONS SUBMODULE_ID=mindspore::SubModuleId::SM_SESSION) +add_library(_mindspore_session_obj OBJECT ${_SESSION_SRC_LIST}) diff --git a/mindspore/ccsrc/transform/CMakeLists.txt b/mindspore/ccsrc/transform/CMakeLists.txt index d1b70c000d8..c783cc00601 100644 --- a/mindspore/ccsrc/transform/CMakeLists.txt +++ b/mindspore/ccsrc/transform/CMakeLists.txt @@ -1,5 +1,6 @@ if (ENABLE_GE OR ENABLE_D) file(GLOB_RECURSE _TRANSFORM_SRC_LIST RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.cc") + set_property(SOURCE ${_TRANSFORM_SRC_LIST} PROPERTY COMPILE_DEFINITIONS SUBMODULE_ID=mindspore::SubModuleId::SM_GE_ADPT) add_library(_mindspore_transform_obj OBJECT ${_TRANSFORM_SRC_LIST}) if (NOT ENABLE_GE) diff --git a/mindspore/ccsrc/utils/CMakeLists.txt b/mindspore/ccsrc/utils/CMakeLists.txt index 52d03c3723b..71d68729b95 100644 --- a/mindspore/ccsrc/utils/CMakeLists.txt +++ b/mindspore/ccsrc/utils/CMakeLists.txt @@ -5,4 +5,5 @@ if (NOT ENABLE_GE) list(REMOVE_ITEM _UTILS_SRC_LIST ${_UTILS_GE_SRC_FILES}) endif () +set_property(SOURCE ${_UTILS_SRC_LIST} PROPERTY COMPILE_DEFINITIONS SUBMODULE_ID=mindspore::SubModuleId::SM_UTILS) add_library(_mindspore_utils_obj OBJECT ${_UTILS_SRC_LIST}) diff --git a/mindspore/ccsrc/utils/contract.h b/mindspore/ccsrc/utils/contract.h index 6ef99282418..bffcb06e891 100644 --- a/mindspore/ccsrc/utils/contract.h +++ b/mindspore/ccsrc/utils/contract.h @@ -56,7 +56,7 @@ class Ensures : public EnsuresAccess { if (!R::Check(value_)) { LogStream contract_stream; contract_stream << "contract error: " << signatory.extra_info << R::Desc(); - LogWriter(signatory.location_info, EXCEPTION, ArgumentError) ^ contract_stream; + LogWriter(signatory.location_info, EXCEPTION, SUBMODULE_ID, ArgumentError) ^ contract_stream; } } template >> diff --git a/mindspore/ccsrc/utils/log_adapter.cc b/mindspore/ccsrc/utils/log_adapter.cc index 74a66f44d75..ffbb95216a1 100644 --- a/mindspore/ccsrc/utils/log_adapter.cc +++ b/mindspore/ccsrc/utils/log_adapter.cc @@ -17,8 +17,8 @@ #include "utils/log_adapter.h" #include +#include #include "pybind11/pybind11.h" - #include "debug/trace.h" // namespace to support utils module definition @@ -155,14 +155,44 @@ static std::string ExceptionTypeToString(ExceptionType type) { return std::string(type_names[type]); } +static const char *GetSubModuleName(SubModuleId module_id) { + static const char *sub_module_names[NUM_SUBMODUES] = { + "UNKNOWN", // SM_UNKNOWN + "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 + "ONNX", // SM_ONNX + "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 + }; + + return sub_module_names[module_id % NUM_SUBMODUES]; +} + void LogWriter::OutputLog(const std::ostringstream &msg) const { #ifdef USE_GLOG + auto submodule_name = GetSubModuleName(submodule_); google::LogMessage("", 0, GetGlogLevel(log_level_)).stream() - << "[" << GetLogLevel(log_level_) << "] ME(" << getpid() << "," << GetProcName() << "):" << GetTime() << " " + << "[" << GetLogLevel(log_level_) << "] " << submodule_name << "(" << getpid() << "," << GetProcName() + << "):" << GetTime() << " " << "[" << location_.file_ << ":" << location_.line_ << "] " << location_.func_ << "] " << msg.str() << std::endl; #else auto str_msg = msg.str(); - Dlog(static_cast(ME), GetSlogLevel(log_level_), "[%s:%d] %s] %s", location_.file_, location_.line_, + auto slog_module_id = (submodule_ == SM_MD ? MD : ME); + Dlog(static_cast(slog_module_id), GetSlogLevel(log_level_), "[%s:%d] %s] %s", location_.file_, location_.line_, location_.func_, str_msg.c_str()); #endif } @@ -230,6 +260,231 @@ static void InitMsLogLevel() { #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, // '{' + RIGHT_BRACE, // '}' + VARIABLE, // '[A-Za-z][A-Za-z0-9_]*' + NUMBER, // [0-9]+ + COMMA, // ',' + COLON, // ';' + EOS, // End Of String, '\0' +}; + +static inline bool IsAlpha(char ch) { return (ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z'); } + +static inline bool IsDigit(char ch) { return ch >= '0' && ch <= '9'; } + +class LogConfigLexer { + public: + explicit LogConfigLexer(const std::string &text) : buffer_(text) { + cur_idx_ = 0; + cur_token_ = LogConfigToken::INVALID; + } + ~LogConfigLexer() = default; + + // skip white space, and return the first char after white space + char SkipWhiteSpace() { + while (cur_idx_ < buffer_.size()) { + char ch = buffer_[cur_idx_]; + if (ch == ' ' || ch == '\t') { + ++cur_idx_; + continue; + } + return ch; + } + return '\0'; + } + + LogConfigToken GetNext(std::string *ptr) { +#ifdef DEBUG + std::string text; + auto tok = GetNextInner(&text); + MS_LOG(DEBUG) << "Got token " << tok << " with value [" << text << "]"; + if (ptr != nullptr) { + *ptr = text; + } + return tok; + } + + LogConfigToken GetNextInner(std::string *ptr) { +#endif + char ch = SkipWhiteSpace(); + // clang-format off + static const std::map single_char_map = { + {'{', LogConfigToken::LEFT_BRACE}, + {'}', LogConfigToken::RIGHT_BRACE}, + {',', LogConfigToken::COMMA}, + {':', LogConfigToken::COLON}, + {'\0', LogConfigToken::EOS}, + }; + // clang-format on + + auto iter = single_char_map.find(ch); + if (iter != single_char_map.end()) { + if (ptr != nullptr) { + *ptr = std::string() + ch; + } + ++cur_idx_; + return iter->second; + } else if (IsAlpha(ch)) { + std::ostringstream oss; + do { + oss << ch; + ch = buffer_[++cur_idx_]; + } while (cur_idx_ < buffer_.size() && (IsAlpha(ch) || IsDigit(ch) || ch == '_')); + if (ptr != nullptr) { + *ptr = std::string(oss.str()); + } + return LogConfigToken::VARIABLE; + } else if (IsDigit(ch)) { + std::ostringstream oss; + do { + oss << ch; + ch = buffer_[++cur_idx_]; + } while (cur_idx_ < buffer_.size() && IsDigit(ch)); + if (ptr != nullptr) { + *ptr = std::string(oss.str()); + } + return LogConfigToken::NUMBER; + } + return LogConfigToken::INVALID; + } + + private: + std::string buffer_; + size_t cur_idx_; + + LogConfigToken cur_token_; + std::string cur_text_; +}; + +class LogConfigParser { + public: + explicit LogConfigParser(const std::string &cfg) : lexer(cfg) {} + + bool Expect(LogConfigToken expected, LogConfigToken tok) { + if (expected != tok) { + MS_LOG(ERROR) << "Expect " << expected << ", but got " << tok; + return false; + } + return true; + } + + // The text of config MS_SUBMODULE_LOG_v is in the form {submodule1:log_level1,submodule2:log_level2,...}. + // Valid values of log levels are: 0 - debug, 1 - info, 2 - warning, 3 - error + // e.g. MS_SUBMODULE_LOG_v={PARSER:0, ANALYZER:2, PIPELINE:1} + std::map Parse() { + std::map log_levels; + + bool flag_error = false; + std::string text; + auto tok = lexer.GetNext(&text); + + // empty string + if (tok == LogConfigToken::EOS) { + return log_levels; + } + + if (!Expect(LogConfigToken::LEFT_BRACE, tok)) { + return log_levels; + } + + do { + std::string key, val; + tok = lexer.GetNext(&key); + if (!Expect(LogConfigToken::VARIABLE, tok)) { + flag_error = true; + break; + } + + tok = lexer.GetNext(&text); + if (!Expect(LogConfigToken::COLON, tok)) { + flag_error = true; + break; + } + + tok = lexer.GetNext(&val); + if (!Expect(LogConfigToken::NUMBER, tok)) { + flag_error = true; + break; + } + + log_levels[key] = val; + tok = lexer.GetNext(&text); + } while (tok == LogConfigToken::COMMA); + + if (!flag_error && !Expect(LogConfigToken::RIGHT_BRACE, tok)) { + flag_error = true; + } + + if (flag_error) { + log_levels.clear(); + } + return log_levels; + } + + private: + LogConfigLexer lexer; +}; + +bool ParseLogLevel(const std::string &str_level, MsLogLevel *ptr_level) { + 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) { + if (ptr_level != nullptr) { + *ptr_level = static_cast(ch); + } + return true; + } + } + return false; +} + +static MsLogLevel GetGlobalLogLevel() { +#ifdef USE_GLOG + return static_cast(FLAGS_v); +#else + return static_cast(g_mslog_level); +#endif +} + +void InitSubModulesLogLevel() { + // initialize submodule's log level using global + auto global_log_level = GetGlobalLogLevel(); + for (int i = 0; i < NUM_SUBMODUES; ++i) { + g_ms_submodule_log_levels[i] = global_log_level; + } + + // set submodule's log level + auto submodule = GetEnv("MS_SUBMODULE_LOG_v"); + MS_LOG(INFO) << "MS_SUBMODULE_LOG_v=`" << submodule << "`"; + LogConfigParser parser(submodule); + auto configs = parser.Parse(); + for (const auto &cfg : configs) { + int mod_idx = -1; + for (int i = 0; i < NUM_SUBMODUES; ++i) { + if (cfg.first == GetSubModuleName(static_cast(i))) { + mod_idx = i; + break; + } + } + if (mod_idx < 0) { + MS_LOG(WARNING) << "Undefined module name " << cfg.first << ", ignore it"; + continue; + } + MsLogLevel submodule_log_level; + if (!ParseLogLevel(cfg.second, &submodule_log_level)) { + MS_LOG(WARNING) << "Illegal log level value " << cfg.second << " for " << cfg.first << ", ignore it."; + continue; + } + g_ms_submodule_log_levels[mod_idx] = submodule_log_level; + } +} } // namespace mindspore extern "C" { @@ -253,6 +508,7 @@ void mindspore_log_init(void) { if (mindspore::GetEnv("GLOG_v").empty()) { FLAGS_v = mindspore::WARNING; } + // set default log file mode to 0640 if (mindspore::GetEnv("GLOG_logfile_mode").empty()) { FLAGS_logfile_mode = 0640; @@ -265,6 +521,8 @@ 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 diff --git a/mindspore/ccsrc/utils/log_adapter.h b/mindspore/ccsrc/utils/log_adapter.h index d7d8eff23e8..a572cfa210a 100644 --- a/mindspore/ccsrc/utils/log_adapter.h +++ b/mindspore/ccsrc/utils/log_adapter.h @@ -97,14 +97,44 @@ constexpr std::ostream &operator<<(std::ostream &stream, const T &value) { enum MsLogLevel : int { DEBUG = 0, INFO, WARNING, ERROR, EXCEPTION }; +enum SubModuleId : int { + SM_UNKNOWN = 0, // unknown submodule + SM_ANALYZER, // static analyzer + SM_COMMON, // common + SM_DEBUG, // debug + SM_DEVICE, // device + SM_GE_ADPT, // ge adapter + SM_IR, // IR + SM_KERNEL, // kernel + SM_MD, // MindData + SM_ME, // MindExpression + SM_ONNX, // ONNX + SM_OPTIMIZER, // optimzer + SM_PARALLEL, // parallel + SM_PARSER, // parser + SM_PIPELINE, // ME pipeline + SM_PRE_ACT, // pre-activate + SM_PYNATIVE, // PyNative + SM_SESSION, // session + SM_UTILS, // utils + SM_VM, // VM + NUM_SUBMODUES // number of submodules +}; + +#ifndef SUBMODULE_ID +#define SUBMODULE_ID mindspore::SubModuleId::SM_ME +#endif + #ifndef USE_GLOG extern int g_mslog_level; #endif +extern int g_ms_submodule_log_levels[] __attribute__((visibility("default"))); class LogWriter { public: - LogWriter(const LocationInfo &location, MsLogLevel log_level, ExceptionType excp_type = NoExceptionType) - : location_(location), log_level_(log_level), exception_type_(excp_type) {} + LogWriter(const LocationInfo &location, MsLogLevel log_level, SubModuleId submodule, + ExceptionType excp_type = NoExceptionType) + : location_(location), log_level_(log_level), submodule_(submodule), exception_type_(excp_type) {} ~LogWriter() = default; void operator<(const LogStream &stream) const noexcept __attribute__((visibility("default"))); @@ -115,6 +145,7 @@ class LogWriter { LocationInfo location_; MsLogLevel log_level_; + SubModuleId submodule_; ExceptionType exception_type_; }; @@ -122,16 +153,13 @@ class LogWriter { static_cast(0), !(condition) \ ? void(0) \ : mindspore::LogWriter(mindspore::LocationInfo(FILE_NAME, __LINE__, __FUNCTION__), level, \ - excp_type) < mindspore::LogStream() -#define MSLOG_THROW(excp_type) \ - mindspore::LogWriter(mindspore::LocationInfo(FILE_NAME, __LINE__, __FUNCTION__), mindspore::EXCEPTION, excp_type) ^ \ + SUBMODULE_ID, excp_type) < mindspore::LogStream() +#define MSLOG_THROW(excp_type) \ + mindspore::LogWriter(mindspore::LocationInfo(FILE_NAME, __LINE__, __FUNCTION__), mindspore::EXCEPTION, SUBMODULE_ID, \ + excp_type) ^ \ mindspore::LogStream() -#ifdef USE_GLOG -#define IS_OUTPUT_ON(level) (level) >= FLAGS_v -#else -#define IS_OUTPUT_ON(level) (level) >= mindspore::g_mslog_level -#endif +#define IS_OUTPUT_ON(level) (level) >= mindspore::g_ms_submodule_log_levels[SUBMODULE_ID] #define MS_LOG(level) MS_LOG_##level diff --git a/mindspore/ccsrc/vm/CMakeLists.txt b/mindspore/ccsrc/vm/CMakeLists.txt index c5408e683e6..ac5c13cb11a 100644 --- a/mindspore/ccsrc/vm/CMakeLists.txt +++ b/mindspore/ccsrc/vm/CMakeLists.txt @@ -1,2 +1,3 @@ file(GLOB_RECURSE _VM_SRC_LIST RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.cc") +set_property(SOURCE ${_VM_SRC_LIST} PROPERTY COMPILE_DEFINITIONS SUBMODULE_ID=mindspore::SubModuleId::SM_VM) add_library(_mindspore_vm_obj OBJECT ${_VM_SRC_LIST}) diff --git a/tests/ut/cpp/common/test_main.cc b/tests/ut/cpp/common/test_main.cc index 57a2a49f537..f0cfc1778c3 100644 --- a/tests/ut/cpp/common/test_main.cc +++ b/tests/ut/cpp/common/test_main.cc @@ -19,7 +19,12 @@ #include "pipeline/pipeline.h" #include "pipeline/resource.h" +namespace mindspore { + extern void InitSubModulesLogLevel(); +} + GTEST_API_ int main(int argc, char** argv) { + mindspore::InitSubModulesLogLevel(); testing::InitGoogleTest(&argc, argv); int ret = RUN_ALL_TESTS(); mindspore::pipeline::ClearResAtexit();