diff --git a/cmake/package.cmake b/cmake/package.cmake index 0d386d606d..23c986b546 100644 --- a/cmake/package.cmake +++ b/cmake/package.cmake @@ -90,7 +90,7 @@ install( ) install( - TARGETS mindspore_gvar + TARGETS mindspore_core DESTINATION ${INSTALL_LIB_DIR} COMPONENT mindspore ) diff --git a/cmake/package_lite.cmake b/cmake/package_lite.cmake index db8ba9ed1a..5df5872eca 100644 --- a/cmake/package_lite.cmake +++ b/cmake/package_lite.cmake @@ -307,7 +307,7 @@ if(PLATFORM_ARM64) DESTINATION ${CONVERTER_ROOT_DIR}/lib COMPONENT ${RUNTIME_COMPONENT_NAME}) install(FILES ${glog_LIBPATH}/libglog.so.0.4.0 DESTINATION ${CONVERTER_ROOT_DIR}/lib RENAME libglog.so.0 COMPONENT ${RUNTIME_COMPONENT_NAME}) - + install(TARGETS mindspore_core DESTINATION ${CONVERTER_ROOT_DIR}/lib COMPONENT ${RUNTIME_COMPONENT_NAME}) install(FILES ${opencv_LIBPATH}/libopencv_core.so.4.5.2 DESTINATION ${CONVERTER_ROOT_DIR}/lib RENAME libopencv_core.so.4.5 COMPONENT ${RUNTIME_COMPONENT_NAME}) @@ -327,6 +327,8 @@ if(PLATFORM_ARM64) DESTINATION ${RUNTIME_LIB_DIR} COMPONENT ${RUNTIME_COMPONENT_NAME}) install(FILES ${glog_LIBPATH}/libglog.so.0.4.0 DESTINATION ${RUNTIME_LIB_DIR} RENAME libglog.so.0 COMPONENT ${RUNTIME_COMPONENT_NAME}) + install(TARGETS mindspore_core DESTINATION ${CONVERTER_ROOT_DIR}/lib + COMPONENT ${RUNTIME_COMPONENT_NAME}) endif() if(MSLITE_MINDDATA_IMPLEMENT STREQUAL "cloud" AND MSLITE_ENABLE_RUNTIME_CONVERT) file(GLOB DATA_ENGINE_LIB_LIST ${LITE_ACL_DIR}/_c_dataengine/*.so) @@ -517,6 +519,7 @@ elseif(WIN32) DESTINATION ${CONVERTER_ROOT_DIR}/lib COMPONENT ${RUNTIME_COMPONENT_NAME}) install(FILES ${glog_LIBPATH}/../bin/libglog.dll DESTINATION ${CONVERTER_ROOT_DIR}/lib COMPONENT ${RUNTIME_COMPONENT_NAME}) + install(TARGETS mindspore_core DESTINATION ${CONVERTER_ROOT_DIR}/lib COMPONENT ${RUNTIME_COMPONENT_NAME}) file(GLOB_RECURSE OPENCV_LIB_LIST ${opencv_LIBPATH}/../bin/libopencv_core* ${opencv_LIBPATH}/../bin/libopencv_imgcodecs* @@ -670,7 +673,7 @@ else() DESTINATION ${CONVERTER_ROOT_DIR}/lib COMPONENT ${RUNTIME_COMPONENT_NAME}) install(FILES ${glog_LIBPATH}/libglog.so.0.4.0 DESTINATION ${CONVERTER_ROOT_DIR}/lib RENAME libglog.so.0 COMPONENT ${RUNTIME_COMPONENT_NAME}) - + install(TARGETS mindspore_core DESTINATION ${CONVERTER_ROOT_DIR}/lib COMPONENT ${RUNTIME_COMPONENT_NAME}) install(FILES ${opencv_LIBPATH}/libopencv_core.so.4.5.2 DESTINATION ${CONVERTER_ROOT_DIR}/lib RENAME libopencv_core.so.4.5 COMPONENT ${RUNTIME_COMPONENT_NAME}) @@ -690,6 +693,7 @@ else() DESTINATION ${RUNTIME_LIB_DIR} COMPONENT ${RUNTIME_COMPONENT_NAME}) install(FILES ${glog_LIBPATH}/libglog.so.0.4.0 DESTINATION ${RUNTIME_LIB_DIR} RENAME libglog.so.0 COMPONENT ${RUNTIME_COMPONENT_NAME}) + install(TARGETS mindspore_core DESTINATION ${RUNTIME_LIB_DIR} COMPONENT ${RUNTIME_COMPONENT_NAME}) endif() if(MSLITE_MINDDATA_IMPLEMENT STREQUAL "cloud" AND MSLITE_ENABLE_RUNTIME_CONVERT) file(GLOB DATA_ENGINE_LIB_LIST ${LITE_ACL_DIR}/_c_dataengine/*.so) diff --git a/cmake/package_mac.cmake b/cmake/package_mac.cmake index 6d92a829d7..0c0077ca29 100644 --- a/cmake/package_mac.cmake +++ b/cmake/package_mac.cmake @@ -67,7 +67,7 @@ install( ) install( - TARGETS mindspore_gvar + TARGETS mindspore_core DESTINATION ${INSTALL_LIB_DIR} COMPONENT mindspore ) diff --git a/cmake/package_tar.cmake b/cmake/package_tar.cmake index 9d547973fc..189acb2110 100644 --- a/cmake/package_tar.cmake +++ b/cmake/package_tar.cmake @@ -27,7 +27,7 @@ install( ) install( - TARGETS mindspore_gvar + TARGETS mindspore_core DESTINATION ${INSTALL_LIB_DIR} COMPONENT mindspore ) diff --git a/cmake/package_win.cmake b/cmake/package_win.cmake index f23b6813b0..f3fa5f0dad 100644 --- a/cmake/package_win.cmake +++ b/cmake/package_win.cmake @@ -74,7 +74,7 @@ install( ) install( - TARGETS mindspore_gvar + TARGETS mindspore_core DESTINATION ${INSTALL_LIB_DIR} COMPONENT mindspore ) diff --git a/mindspore/ccsrc/CMakeLists.txt b/mindspore/ccsrc/CMakeLists.txt index 0a1b3cf589..12a293ea95 100644 --- a/mindspore/ccsrc/CMakeLists.txt +++ b/mindspore/ccsrc/CMakeLists.txt @@ -213,6 +213,11 @@ if(MODE_ASCEND_ALL) add_compile_definitions(ENABLE_D) endif() +# core/mindir.proto +file(GLOB_RECURSE CORE_PROTO_IN ${CMAKE_SOURCE_DIR}/mindspore/core/proto/*.proto) +ms_protobuf_generate(CORE_PROTO_SRC CORE_PROTO_HDR ${CORE_PROTO_IN}) +list(APPEND MINDSPORE_PROTO_LIST ${CORE_PROTO_SRC}) + if(MINDSPORE_PROTO_LIST) add_library(proto_input STATIC ${MINDSPORE_PROTO_LIST}) set_target_properties(proto_input PROPERTIES COMPILE_FLAGS "-Wno-unused-variable") @@ -250,21 +255,19 @@ 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 mindspore_core) - if(ENABLE_DEBUGGER) # debugger: link grpc if(CMAKE_SYSTEM_NAME MATCHES "Darwin") - target_link_libraries(mindspore mindspore::grpc++) + target_link_libraries(mindspore PUBLIC mindspore::grpc++) else() - target_link_libraries(mindspore -Wl,--no-as-needed mindspore::grpc++) + target_link_libraries(mindspore PUBLIC -Wl,--no-as-needed mindspore::grpc++) endif() endif() -target_link_libraries(mindspore securec mindspore::flatbuffers) +target_link_libraries(mindspore PUBLIC securec mindspore::flatbuffers) if(NOT WIN32) - target_link_libraries(mindspore dl) + target_link_libraries(mindspore PUBLIC dl) endif() if(MODE_ASCEND_ALL OR MODE_ASCEND_ACL) @@ -301,7 +304,7 @@ if(ENABLE_D) find_library(GE_RUNNER ge_runner ${ASCEND_RUNTIME_PATH} ${ASCEND_TOOLKIT_RUNTIME_PATH}) find_library(GRAPH graph ${ASCEND_RUNTIME_PATH} ${ASCEND_TOOLKIT_RUNTIME_PATH}) find_library(HCCL hccl ${ASCEND_RUNTIME_PATH} ${ASCEND_TOOLKIT_RUNTIME_PATH}) - target_link_libraries(mindspore ${GE_RUNNER} ${GRAPH} ${HCCL}) + target_link_libraries(mindspore PUBLIC ${GE_RUNNER} ${GRAPH} ${HCCL}) endif() if(MODE_ASCEND_ALL) @@ -326,16 +329,16 @@ if(MODE_ASCEND_ALL) find_library(OPT_FEATURE opt_feature ${ASCEND_RUNTIME_PATH} ${ASCEND_TOOLKIT_RUNTIME_PATH} ${ASCEND_RUNTIME_NEW_PATH} ${ASCEND_TOOLKIT_RUNTIME_NEW_PATH}) - target_link_libraries(mindspore ${RUNTIME_LIB} ${TSDCLIENT} ${DATATRANSFER} ${ERROR_MANAGER} -Wl,--no-as-needed - ${OPTILING} ${PLATFORM} ${ACL} ${ACL_TDT_CHANNEL} ${OPT_FEATURE} ${PROFILING}) - target_link_libraries(mindspore -Wl,--start-group proto_input mindspore::protobuf -Wl,--end-group) + target_link_libraries(mindspore PUBLIC ${RUNTIME_LIB} ${TSDCLIENT} ${DATATRANSFER} ${ERROR_MANAGER} + -Wl,--no-as-needed ${OPTILING} ${PLATFORM} ${ACL} ${ACL_TDT_CHANNEL} ${OPT_FEATURE} ${PROFILING}) + target_link_libraries(mindspore PUBLIC -Wl,--start-group proto_input mindspore::protobuf -Wl,--end-group) elseif(CMAKE_SYSTEM_NAME MATCHES "Windows") - target_link_libraries(mindspore -Wl,--start-group proto_input mindspore::protobuf mindspore::sentencepiece + target_link_libraries(mindspore PUBLIC -Wl,--start-group proto_input mindspore::protobuf mindspore::sentencepiece -Wl,--end-group) elseif(CMAKE_SYSTEM_NAME MATCHES "Darwin") - target_link_libraries(mindspore -Wl proto_input mindspore::protobuf mindspore::sentencepiece -Wl) + target_link_libraries(mindspore PUBLIC -Wl proto_input mindspore::protobuf mindspore::sentencepiece -Wl) else() - target_link_libraries(mindspore -Wl,--start-group proto_input mindspore::protobuf -Wl,--end-group) + target_link_libraries(mindspore PUBLIC -Wl,--start-group proto_input mindspore::protobuf -Wl,--end-group) endif() # set c_expression building @@ -375,29 +378,26 @@ set(MINDSPORE_RPATH ${ORIGIN_PATH}/lib:${MINDSPORE_RPATH}) set_target_properties(_c_expression PROPERTIES INSTALL_RPATH ${MINDSPORE_RPATH}) if(CMAKE_SYSTEM_NAME MATCHES "Windows") - target_link_libraries(mindspore mindspore::pybind11_module) - target_link_libraries(mindspore mindspore_gvar) - target_link_libraries(_c_expression PRIVATE -Wl,--whole-archive mindspore mindspore_core -Wl,--no-whole-archive) + target_link_libraries(mindspore PUBLIC mindspore::pybind11_module) + target_link_libraries(_c_expression PRIVATE -Wl,--whole-archive mindspore -Wl,--no-whole-archive mindspore_core) elseif(CMAKE_SYSTEM_NAME MATCHES "Darwin") - target_link_libraries(mindspore proto_input mindspore::protobuf + target_link_libraries(mindspore PUBLIC proto_input mindspore::protobuf mindspore::event mindspore::event_pthreads mindspore::event_openssl mindspore::eigen mindspore::json) - target_link_libraries(mindspore mindspore::event_core ps_cache) - target_link_libraries(_c_expression PRIVATE -Wl,-all_load mindspore mindspore_core proto_input -Wl,-noall_load) + target_link_libraries(mindspore PUBLIC mindspore::event_core ps_cache) + target_link_libraries(_c_expression PRIVATE -Wl,-all_load mindspore proto_input -Wl,-noall_load mindspore_core) target_link_libraries(_c_expression PRIVATE mindspore::pybind11_module) - target_link_libraries(_c_expression PRIVATE mindspore_gvar) else() if(ENABLE_CPU AND NOT WIN32) - target_link_libraries(mindspore proto_input mindspore::protobuf + target_link_libraries(mindspore PUBLIC proto_input mindspore::protobuf mindspore::event mindspore::event_pthreads mindspore::event_openssl mindspore::eigen mindspore::json) - target_link_libraries(mindspore -Wl,--no-as-needed mindspore::event_core ps_cache) + target_link_libraries(mindspore PUBLIC -Wl,--no-as-needed mindspore::event_core ps_cache) if(${ENABLE_IBVERBS} STREQUAL "ON") - target_link_libraries(mindspore ibverbs rdmacm) + target_link_libraries(mindspore PUBLIC ibverbs rdmacm) endif() endif() - target_link_libraries(_c_expression PRIVATE -Wl,--whole-archive mindspore mindspore_core - proto_input -Wl,--no-whole-archive) + target_link_libraries(_c_expression PRIVATE -Wl,--whole-archive mindspore proto_input -Wl,--no-whole-archive + mindspore_core) target_link_libraries(_c_expression PRIVATE mindspore::pybind11_module) - target_link_libraries(_c_expression PRIVATE mindspore_gvar) endif() if(USE_GLOG) @@ -405,7 +405,7 @@ if(USE_GLOG) endif() if(${CMAKE_SYSTEM_NAME} MATCHES "Linux") - target_link_libraries(mindspore mindspore::crypto mindspore::ssl) + target_link_libraries(mindspore PUBLIC mindspore::crypto mindspore::ssl) endif() if(ENABLE_GPU) diff --git a/mindspore/ccsrc/backend/kernel_compiler/cpu/cpu_kernel_factory.cc b/mindspore/ccsrc/backend/kernel_compiler/cpu/cpu_kernel_factory.cc index 3c060263f4..e70c31f253 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/cpu/cpu_kernel_factory.cc +++ b/mindspore/ccsrc/backend/kernel_compiler/cpu/cpu_kernel_factory.cc @@ -37,9 +37,6 @@ NativeCpuKernelModFactory &NativeCpuKernelModFactory::GetInstance() { void NativeCpuKernelModFactory::Register(const std::string &kernel_name, const KernelAttr &kernel_attr, NativeCpuKernelModCreator &&kernel_creator) { (void)name_to_attr_creator_[kernel_name].emplace_back(kernel_attr, kernel_creator); -#if !defined(_WIN32) && !defined(_WIN64) && !defined(__APPLE__) - MS_LOG(DEBUG) << "NativeCpuKernelModFactory register operator: " << kernel_name; -#endif } std::shared_ptr NativeCpuKernelModFactory::Create(const std::string &kernel_name, diff --git a/mindspore/ccsrc/backend/optimizer/cpu/insert_format_transform_op.cc b/mindspore/ccsrc/backend/optimizer/cpu/insert_format_transform_op.cc index 2524fb055a..3c60e4047f 100644 --- a/mindspore/ccsrc/backend/optimizer/cpu/insert_format_transform_op.cc +++ b/mindspore/ccsrc/backend/optimizer/cpu/insert_format_transform_op.cc @@ -172,7 +172,7 @@ void InsertTransformOpForOutput(const FuncGraphPtr &graph, const AnfNodePtr &nod } } // namespace -const mindspore::HashSet kChannelLastKernel = {prim::kPrimBiasAdd->name()}; +const mindspore::HashSet kChannelLastKernel = {prim::kBiasAdd}; bool InsertFormatTransformOpCPU::Run(const FuncGraphPtr &graph) { MS_EXCEPTION_IF_NULL(graph); diff --git a/mindspore/ccsrc/backend/optimizer/gpu/insert_cast_gpu.cc b/mindspore/ccsrc/backend/optimizer/gpu/insert_cast_gpu.cc index 50c94d6122..5630b8306e 100644 --- a/mindspore/ccsrc/backend/optimizer/gpu/insert_cast_gpu.cc +++ b/mindspore/ccsrc/backend/optimizer/gpu/insert_cast_gpu.cc @@ -27,10 +27,6 @@ namespace mindspore { namespace opt { -const mindspore::HashSet kConv3DKernel = {prim::kPrimConv3DBackpropInput->name(), - prim::kPrimConv3DBackpropFilter->name(), - prim::kPrimConv3D->name(), prim::kPrimConv3DTranspose->name()}; - void InsertCast(const FuncGraphPtr &graph, const AnfNodePtr &node, size_t i, const TypeId &src_type, const TypeId &cast_type) { MS_EXCEPTION_IF_NULL(graph); @@ -71,7 +67,9 @@ bool InsertCastGPU::Run(const FuncGraphPtr &graph) { if (node == nullptr || !node->isa() || !AnfUtils::IsRealKernel(node)) { continue; } - + static const mindspore::HashSet kConv3DKernel = { + prim::kPrimConv3DBackpropInput->name(), prim::kPrimConv3DBackpropFilter->name(), prim::kPrimConv3D->name(), + prim::kPrimConv3DTranspose->name()}; if (kConv3DKernel.find(AnfAlgo::GetCNodeName(node)) == kConv3DKernel.end()) { continue; } diff --git a/mindspore/ccsrc/backend/session/anf_runtime_algorithm.cc b/mindspore/ccsrc/backend/session/anf_runtime_algorithm.cc index abf038a1a5..ab0efdb93f 100644 --- a/mindspore/ccsrc/backend/session/anf_runtime_algorithm.cc +++ b/mindspore/ccsrc/backend/session/anf_runtime_algorithm.cc @@ -55,9 +55,7 @@ constexpr size_t kPartialFuncGraphPos = 1; constexpr size_t kSwitchLayerBranchPos = 2; constexpr size_t kSwitchTrueBranchPos = 2; constexpr size_t kMakeTupleInputStartPos = 1; -const std::set kNodeTupleOutSet = {prim::kPrimMakeTuple->name(), prim::kPrimGetNext->name()}; - -const PrimitiveSet follow_first_input_prims = {prim::kPrimDepend, prim::kPrimLoad}; +const std::set kNodeTupleOutSet = {prim::kMakeTuple, prim::kGetNext}; std::vector TransShapeToSizet(const abstract::ShapePtr &shape) { MS_EXCEPTION_IF_NULL(shape); @@ -367,6 +365,7 @@ KernelWithIndex AnfRuntimeAlgorithm::VisitKernelWithReturnType(const AnfNodePtr if (AnfAlgo::CheckPrimitiveType(cnode, prim::kPrimUpdateState)) { return VisitKernelWithReturnType(cnode->input(kUpdateStateStateInput), index, skip_nop_node, return_types); } + const PrimitiveSet follow_first_input_prims = {prim::kPrimDepend, prim::kPrimLoad}; if (IsOneOfPrimitiveCNode(cnode, follow_first_input_prims)) { return VisitKernelWithReturnType(cnode->input(kRealInputIndexInDepend), index, skip_nop_node, return_types); } diff --git a/mindspore/ccsrc/backend/session/kernel_graph.cc b/mindspore/ccsrc/backend/session/kernel_graph.cc index 2464cbb1d5..fb38ecc26e 100644 --- a/mindspore/ccsrc/backend/session/kernel_graph.cc +++ b/mindspore/ccsrc/backend/session/kernel_graph.cc @@ -37,8 +37,7 @@ namespace { constexpr auto kIsFeatureMapOutput = "IsFeatureMapOutput"; constexpr auto kIsFeatureMapInputList = "IsFeatureMapInputList"; constexpr size_t k5dDims = 5; -const std::set kOpAssignKernelNameList = {prim::kPrimAssign->name(), prim::kPrimAssignAdd->name(), - prim::kPrimAssignSub->name()}; +const std::set kOpAssignKernelNameList = {prim::kAssign, prim::kAssignAdd, prim::kAssignSub}; void PushNoVisitedNode(const AnfNodePtr &node, std::queue *que, mindspore::HashSet *visited_nodes) { diff --git a/mindspore/ccsrc/cxx_api/CMakeLists.txt b/mindspore/ccsrc/cxx_api/CMakeLists.txt index 180e27508e..7aa31f3b22 100644 --- a/mindspore/ccsrc/cxx_api/CMakeLists.txt +++ b/mindspore/ccsrc/cxx_api/CMakeLists.txt @@ -15,12 +15,6 @@ endif() # build mindspore_shared_lib include_directories(${CMAKE_SOURCE_DIR}/mindspore/ccsrc) include_directories(${CMAKE_SOURCE_DIR}/mindspore/ccsrc/minddata/dataset) -if(NOT BUILD_LITE) - set(LOAD_MINDIR_SRC - ${CMAKE_SOURCE_DIR}/mindspore/core/load_mindir/load_model.cc - ${CMAKE_SOURCE_DIR}/mindspore/core/load_mindir/anf_model_parser.cc - ) -endif() file(GLOB_RECURSE API_OPS_SRC ${CMAKE_CURRENT_SOURCE_DIR} "ops/*.cc") @@ -36,11 +30,6 @@ if(ENABLE_D OR ENABLE_ACL) "model/model_converter_utils/*.cc" "graph/acl/*.cc" ) - - if(NOT ENABLE_D) - list(APPEND API_ACL_SRC $) - list(APPEND API_ACL_SRC $) - endif() endif() if(ENABLE_D) @@ -79,25 +68,30 @@ if(BUILD_LITE) "${CMAKE_CURRENT_SOURCE_DIR}/types.cc" "${CMAKE_CURRENT_SOURCE_DIR}/model/model.cc" "${CMAKE_CURRENT_SOURCE_DIR}/model/model_impl.cc" - ${ACL_REMOVE_SRC} - $) + ${ACL_REMOVE_SRC}) endif() -add_library(mindspore_shared_lib SHARED ${MSLIB_SRC}) +add_library(mindspore_shared_lib_obj OBJECT ${MSLIB_SRC}) +add_library(mindspore_shared_lib SHARED $) +if(BUILD_LITE) + target_link_libraries(mindspore_shared_lib PRIVATE $) +elseif(ENABLE_ACL AND NOT ENABLE_D) + target_link_libraries(mindspore_shared_lib PRIVATE $ + $) +endif() if(NOT BUILD_LITE) set_target_properties(mindspore_shared_lib PROPERTIES OUTPUT_NAME mindspore) endif() if(ENABLE_D OR ENABLE_GPU) target_link_libraries(mindspore_shared_lib PRIVATE -Wl,--as-needed ${PYTHON_LIBRARIES} ${SECUREC_LIBRARY} - -Wl,--whole-archive mindspore -Wl,--no-whole-archive mindspore_core proto_input mindspore_gvar - mindspore::protobuf) + -Wl,--whole-archive mindspore -Wl,--no-whole-archive mindspore_core proto_input mindspore::protobuf) else() if(BUILD_LITE) target_link_libraries(mindspore_shared_lib PRIVATE ${SECUREC_LIBRARY}) else() target_link_libraries(mindspore_shared_lib PRIVATE ${PY3_LIBG} ${SECUREC_LIBRARY} - mindspore mindspore_core proto_input mindspore_gvar mindspore::protobuf) + mindspore mindspore_core proto_input mindspore::protobuf) endif() endif() diff --git a/mindspore/ccsrc/debug/CMakeLists.txt b/mindspore/ccsrc/debug/CMakeLists.txt index a382adf478..b57f3288bb 100644 --- a/mindspore/ccsrc/debug/CMakeLists.txt +++ b/mindspore/ccsrc/debug/CMakeLists.txt @@ -73,11 +73,17 @@ if(ENABLE_DEBUGGER) target_link_libraries(_mindspore_offline_debug PRIVATE mindspore::pybind11_module mindspore::glog - mindspore_gvar + mindspore_core ) set_target_properties(_mindspore_offline_debug PROPERTIES PREFIX "${PYTHON_MODULE_PREFIX}" SUFFIX "${PYTHON_MODULE_EXTENSION}" ) + if(CMAKE_SYSTEM_NAME MATCHES "Darwin") + set_target_properties(_mindspore_offline_debug PROPERTIES MACOSX_RPATH ON) + set_target_properties(_mindspore_offline_debug PROPERTIES INSTALL_RPATH @loader_path/lib) + else() + set_target_properties(_mindspore_offline_debug PROPERTIES INSTALL_RPATH $ORIGIN/lib) + endif() endif() endif() diff --git a/mindspore/ccsrc/minddata/dataset/CMakeLists.txt b/mindspore/ccsrc/minddata/dataset/CMakeLists.txt index c86f252863..c651197eb4 100644 --- a/mindspore/ccsrc/minddata/dataset/CMakeLists.txt +++ b/mindspore/ccsrc/minddata/dataset/CMakeLists.txt @@ -137,7 +137,7 @@ if(ENABLE_CACHE) add_dependencies(engine-cache-server core) endif() ################### Create _c_dataengine Library ###################### -set(submodules +set(dataengine_submodules $ $ $ @@ -170,36 +170,33 @@ set(submodules $ $ $ - $ - ) + $) if(ENABLE_ACL) - set(submodules - ${submodules} + set(dataengine_submodules + ${dataengine_submodules} $ $) endif() if(ENABLE_PYTHON) - set(submodules - ${submodules} + set(dataengine_submodules + ${dataengine_submodules} $) endif() if(ENABLE_TDTQUE) if(NOT ENABLE_SECURITY) - add_library(_c_dataengine SHARED ${submodules} $ $) - else() - add_library(_c_dataengine SHARED ${submodules} $) + set(dataengine_submodules ${dataengine_submodules} $) endif() + set(dataengine_submodules ${dataengine_submodules} $) else() if(NOT ENABLE_SECURITY) - add_library(_c_dataengine SHARED ${submodules} $) - else() - add_library(_c_dataengine SHARED ${submodules}) + set(dataengine_submodules ${dataengine_submodules} $) endif() endif() - +set(dataengine_submodules ${dataengine_submodules} CACHE INTERNAL "_c_dataengine objects") +add_library(_c_dataengine SHARED ${dataengine_submodules}) if(ENABLE_PYTHON) set_target_properties(_c_dataengine PROPERTIES PREFIX "${PYTHON_MODULE_PREFIX}" @@ -210,10 +207,8 @@ endif() ###################################################################### ################# Link with external libraries ######################## -if(MSLITE_ENABLE_CLOUD_MIND_DATA) - target_link_libraries(_c_dataengine PRIVATE mindspore_gvar) -else() - target_link_libraries(_c_dataengine PRIVATE mindspore mindspore_gvar) +if(NOT MSLITE_ENABLE_CLOUD_MIND_DATA) + target_link_libraries(_c_dataengine PRIVATE mindspore) endif() if(${CMAKE_SYSTEM_NAME} MATCHES "Windows") diff --git a/mindspore/ccsrc/minddata/dataset/engine/cache/CMakeLists.txt b/mindspore/ccsrc/minddata/dataset/engine/cache/CMakeLists.txt index 7a4b9dad27..1e9bc92be7 100644 --- a/mindspore/ccsrc/minddata/dataset/engine/cache/CMakeLists.txt +++ b/mindspore/ccsrc/minddata/dataset/engine/cache/CMakeLists.txt @@ -76,8 +76,8 @@ if(ENABLE_CACHE) _c_dataengine _c_mindrecord mindspore + mindspore_core mindspore::protobuf - mindspore_gvar ${CUDNN_LIBRARY_PATH} ${PYTHON_LIBRARIES} ${SECUREC_LIBRARY} @@ -91,8 +91,8 @@ if(ENABLE_CACHE) _c_dataengine _c_mindrecord mindspore + mindspore_core mindspore::protobuf - mindspore_gvar ${PYTHON_LIBRARIES} ${SECUREC_LIBRARY} pthread diff --git a/mindspore/ccsrc/minddata/dataset/engine/cache/perf/CMakeLists.txt b/mindspore/ccsrc/minddata/dataset/engine/cache/perf/CMakeLists.txt index df6fcee1d6..1913d0af44 100644 --- a/mindspore/ccsrc/minddata/dataset/engine/cache/perf/CMakeLists.txt +++ b/mindspore/ccsrc/minddata/dataset/engine/cache/perf/CMakeLists.txt @@ -10,7 +10,6 @@ if(ENABLE_CACHE) _c_mindrecord mindspore mindspore::protobuf - mindspore_gvar ${PYTHON_LIBRARIES} pthread) @@ -24,7 +23,6 @@ if(ENABLE_CACHE) _c_mindrecord mindspore mindspore::protobuf - mindspore_gvar ${PYTHON_LIBRARIES} pthread) diff --git a/mindspore/ccsrc/minddata/dataset/engine/datasetops/CMakeLists.txt b/mindspore/ccsrc/minddata/dataset/engine/datasetops/CMakeLists.txt index 7fb6088630..99169c8406 100644 --- a/mindspore/ccsrc/minddata/dataset/engine/datasetops/CMakeLists.txt +++ b/mindspore/ccsrc/minddata/dataset/engine/datasetops/CMakeLists.txt @@ -36,3 +36,4 @@ if(ENABLE_PYTHON) endif() add_library(engine-datasetops OBJECT ${DATASET_ENGINE_DATASETOPS_SRC_FILES}) +add_dependencies(engine-datasetops engine-cache-client) diff --git a/mindspore/ccsrc/minddata/mindrecord/CMakeLists.txt b/mindspore/ccsrc/minddata/mindrecord/CMakeLists.txt index fe64be38ed..85491083f0 100644 --- a/mindspore/ccsrc/minddata/mindrecord/CMakeLists.txt +++ b/mindspore/ccsrc/minddata/mindrecord/CMakeLists.txt @@ -23,7 +23,8 @@ 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}) +add_library(mindrecord_obj OBJECT ${DIR_LIB_SRCS}) +add_library(_c_mindrecord SHARED $) set_target_properties(_c_mindrecord PROPERTIES PREFIX "${PYTHON_MODULE_PREFIX}" @@ -32,15 +33,15 @@ 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_gvar mindspore::protobuf) + target_link_libraries(_c_mindrecord PRIVATE mindspore::sqlite mindspore mindspore::protobuf) else() target_link_libraries(_c_mindrecord PRIVATE mindspore::sqlite ${PYTHON_LIB} ${SECUREC_LIBRARY} - mindspore_gvar mindspore::protobuf) + mindspore::protobuf) if(NOT MSLITE_ENABLE_CLOUD_MIND_DATA) target_link_libraries(_c_mindrecord PRIVATE mindspore) endif() endif() - +target_link_libraries(_c_mindrecord PRIVATE mindspore_core) if(USE_GLOG) target_link_libraries(_c_mindrecord PRIVATE mindspore::glog) else() diff --git a/mindspore/ccsrc/runtime/device/ascend/ge_runtime/task/task_factory.h b/mindspore/ccsrc/runtime/device/ascend/ge_runtime/task/task_factory.h index 4dc284fc5f..aab4c41114 100644 --- a/mindspore/ccsrc/runtime/device/ascend/ge_runtime/task/task_factory.h +++ b/mindspore/ccsrc/runtime/device/ascend/ge_runtime/task/task_factory.h @@ -65,7 +65,6 @@ class TaskFactory { class Register { public: Register(const TaskInfoType &type, const TASK_CREATOR_FUN &func) { - MS_LOG(DEBUG) << "register type " << type; TaskFactory::GetInstance().RegisterCreator(type, func); } diff --git a/mindspore/ccsrc/runtime/framework/actor/data_prepare_actor.cc b/mindspore/ccsrc/runtime/framework/actor/data_prepare_actor.cc index 6d7b9677f7..c7a1c5f199 100644 --- a/mindspore/ccsrc/runtime/framework/actor/data_prepare_actor.cc +++ b/mindspore/ccsrc/runtime/framework/actor/data_prepare_actor.cc @@ -37,6 +37,7 @@ void SyncTensorData(const TensorPtr &host_tensor, const DeviceTensorPtr &device_ MS_EXCEPTION_IF_NULL(node); MS_EXCEPTION_IF_NULL(device_context); MS_EXCEPTION_IF_NULL(context); + if ((device_tensor->GetPtr() == nullptr) && (!device_context->AllocateMemory(device_tensor.get(), device_tensor->GetSize()))) { SET_OPCONTEXT_MEMORY_ALLOC_FAIL_BY_STRATEGY(strategy, *context, *device_context, node->fullname_with_scope(), diff --git a/mindspore/ccsrc/utils/convert_utils.h b/mindspore/ccsrc/utils/convert_utils.h index 324fadeb79..728330d6fe 100644 --- a/mindspore/ccsrc/utils/convert_utils.h +++ b/mindspore/ccsrc/utils/convert_utils.h @@ -84,23 +84,18 @@ size_t CountValueNum(const ValueTuplePtr &value_tuple); // to CNode{kPrimTupleGetItem, SparseTensor, int64_t(index)}, used // in backend common optimization pass: sparse_process.cc const mindspore::HashMap sparse_attr_map = { - {prim::kPrimCSRTensorGetIndptr->name(), 0}, {prim::kPrimCSRTensorGetIndices->name(), 1}, - {prim::kPrimCSRTensorGetValues->name(), 2}, {prim::kPrimCSRTensorGetDenseShape->name(), 3}, - {prim::kPrimCOOTensorGetIndices->name(), 0}, {prim::kPrimCOOTensorGetValues->name(), 1}, - {prim::kPrimCOOTensorGetDenseShape->name(), 2}}; + {prim::kCSRTensorGetIndptr, 0}, {prim::kCSRTensorGetIndices, 1}, {prim::kCSRTensorGetValues, 2}, + {prim::kCSRTensorGetDenseShape, 3}, {prim::kCOOTensorGetIndices, 0}, {prim::kCOOTensorGetValues, 1}, + {prim::kCOOTensorGetDenseShapes, 2}}; // make_sparse_set records all make_sparse primitives, and tries to replace // make_sparse to make_tuple, used in backend common optimization pass: // sparse_process.cc -const mindspore::HashSet make_sparse_set = {{prim::kPrimMakeCSRTensor->name()}, - {prim::kPrimMakeCOOTensor->name()}}; +const mindspore::HashSet make_sparse_set = {{prim::kMakeCSRTensor}, {prim::kMakeCOOTensor}}; // sparse_op_set records all sparse_compute operators, which takes sparsetensor // and (possibly) dense tensors, used in backend common optimization pass: // sparse_process.cc -const mindspore::HashSet sparse_op_set = {{prim::kPrimCOOTensorDenseMatmul->name()}, - {prim::kPrimCSRDenseMul->name()}, - {prim::kPrimCSRReduceSum->name()}, - {prim::kPrimCSRMV->name()}, - {prim::kPrimCSRMul->name()}}; +const mindspore::HashSet sparse_op_set = { + {prim::kSparseTensorDenseMatmul}, {prim::kCSRDenseMul}, {prim::kCSRReduceSum}, {prim::kCSRMV}, {prim::kCSRMul}}; bool IsCustomCSROP(const AnfNodePtr &cnode); } // namespace mindspore diff --git a/mindspore/core/CMakeLists.txt b/mindspore/core/CMakeLists.txt index e054c65a6a..20c814c85d 100644 --- a/mindspore/core/CMakeLists.txt +++ b/mindspore/core/CMakeLists.txt @@ -14,8 +14,6 @@ if(NOT(BUILD_LITE)) add_subdirectory(mindrt) endif() -message("************ build core ***************") - file(GLOB_RECURSE CORE_SRC_LIST RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "abstract/*.cc" "base/*.cc" @@ -48,9 +46,23 @@ elseif(CMAKE_SYSTEM_NAME MATCHES "Darwin") endif() set_property(SOURCE ${CORE_SRC_LIST} PROPERTY COMPILE_DEFINITIONS SUBMODULE_ID=mindspore::SubModuleId::SM_CORE) -set_property(SOURCE ${PROTO_SRCS} PROPERTY COMPILE_OPTIONS -Wno-array-bounds) -add_library(mindspore_core STATIC ${CORE_SRC_LIST} ${PROTO_SRCS}) -target_link_libraries(mindspore_core PRIVATE mindspore_gvar) +add_library(core_obj OBJECT ${CORE_SRC_LIST}) +add_library(core_proto_obj OBJECT ${PROTO_SRCS}) +add_library(mindspore_core SHARED $ $ + $) +target_link_libraries(mindspore_core PRIVATE mindspore::protobuf securec) + +if(CMAKE_SYSTEM_NAME MATCHES "Linux") + target_link_options(mindspore_core PRIVATE -Wl,-init,mindspore_log_init) +endif() + +if(CMAKE_SYSTEM_NAME MATCHES "Darwin") + set_target_properties(mindspore_core PROPERTIES MACOSX_RPATH ON) + set_target_properties(mindspore_core PROPERTIES INSTALL_RPATH @loader_path) +else() + set_target_properties(mindspore_core PROPERTIES INSTALL_RPATH $ORIGIN) +endif() + if(NOT(BUILD_LITE)) target_link_libraries(mindspore_core PRIVATE mindrt_mid) endif() @@ -65,3 +77,4 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Linux") add_compile_definitions(ENABLE_OPENSSL) endif() endif() + diff --git a/mindspore/core/abstract/abstract_value.cc b/mindspore/core/abstract/abstract_value.cc index c58a4d9f2a..c426f56c3a 100644 --- a/mindspore/core/abstract/abstract_value.cc +++ b/mindspore/core/abstract/abstract_value.cc @@ -92,6 +92,8 @@ static inline bool IsUndeterminedType(const TypePtr &type) { return (type != nullptr) && (type->type_id() == kObjectTypeUndeterminedType); } +AbstractBase::TraceNodeProvider AbstractBase::trace_node_provider_ = nullptr; + bool AbstractBase::operator==(const AbstractBase &other) const { if (this == &other) { // Same object. diff --git a/mindspore/core/abstract/abstract_value.h b/mindspore/core/abstract/abstract_value.h index bde9a6db4a..831161d1ea 100644 --- a/mindspore/core/abstract/abstract_value.h +++ b/mindspore/core/abstract/abstract_value.h @@ -151,7 +151,7 @@ class MS_CORE_API AbstractBase : public Base { trace_node_provider_ = trace_node_provider; } - inline static TraceNodeProvider trace_node_provider_ = nullptr; + static TraceNodeProvider trace_node_provider_; /// \brief Broaden the abstract. It will upgrade the abstract to a higher level. /// @@ -1580,7 +1580,7 @@ class MS_CORE_API AbstractCSRTensor : public AbstractUndetermined { }; using AbstractCSRTensorPtr = std::shared_ptr; -class AbstractMonad : public AbstractBase { +class MS_CORE_API AbstractMonad : public AbstractBase { public: ~AbstractMonad() override = default; MS_DECLARE_PARENT(AbstractMonad, AbstractBase) @@ -1600,7 +1600,7 @@ class AbstractMonad : public AbstractBase { }; using AbstractMonadPtr = std::shared_ptr; -class AbstractUMonad final : public AbstractMonad { +class MS_CORE_API AbstractUMonad final : public AbstractMonad { public: explicit AbstractUMonad(const ValuePtr &value = kUMonad) : AbstractMonad(value, kUMonadType) {} ~AbstractUMonad() override = default; @@ -1613,7 +1613,7 @@ class AbstractUMonad final : public AbstractMonad { }; using AbstractUMonadPtr = std::shared_ptr; -class AbstractIOMonad final : public AbstractMonad { +class MS_CORE_API AbstractIOMonad final : public AbstractMonad { public: explicit AbstractIOMonad(const ValuePtr &value = kIOMonad) : AbstractMonad(value, kIOMonadType) {} ~AbstractIOMonad() override = default; @@ -1627,10 +1627,11 @@ class AbstractIOMonad final : public AbstractMonad { using AbstractIOMonadPtr = std::shared_ptr; AnfNodePtr GetTraceNode(const AbstractBasePtr &abs); -std::string ExtractLoggingInfo(const std::string &info); -void SynchronizeSequenceElementsUseFlagsRecursively(const AbstractSequencePtr &lhs_sequence, - const AbstractSequencePtr &rhs_sequence); +MS_CORE_API std::string ExtractLoggingInfo(const std::string &info); + +MS_CORE_API void SynchronizeSequenceElementsUseFlagsRecursively(const AbstractSequencePtr &lhs_sequence, + const AbstractSequencePtr &rhs_sequence); } // namespace abstract } // namespace mindspore #endif // MINDSPORE_CORE_ABSTRACT_ABSTRACT_VALUE_H_ diff --git a/mindspore/core/abstract/analysis_context.h b/mindspore/core/abstract/analysis_context.h index 45e03fd03b..01a30bf707 100644 --- a/mindspore/core/abstract/analysis_context.h +++ b/mindspore/core/abstract/analysis_context.h @@ -27,6 +27,7 @@ #include "utils/hash_map.h" #include "abstract/abstract_value.h" #include "ir/meta_func_graph.h" +#include "utils/visible.h" namespace mindspore { namespace abstract { @@ -36,7 +37,7 @@ using ArgsSpecToAnalysisContextMap = std::unordered_map; // AnalysisContext will be stored in Config in AnalysisCache. -class AnalysisContext { +class MS_CORE_API AnalysisContext { public: AnalysisContext(const AnalysisContextPtr &parent, const FuncGraphPtr &fg, const AbstractBasePtrList &args_spec_list) : parent_(parent), func_graph_(fg), args_spec_list_(args_spec_list) { diff --git a/mindspore/core/abstract/dshape.cc b/mindspore/core/abstract/dshape.cc index f049b0f1ac..79df160c18 100644 --- a/mindspore/core/abstract/dshape.cc +++ b/mindspore/core/abstract/dshape.cc @@ -37,6 +37,7 @@ std::string ShapeVectorToStr(const std::vector &shp) { return buffer.str(); } } // namespace + // used for print BaseShape content std::ostream &operator<<(std::ostream &os, const BaseShape &bs) { os << bs.ToString(); @@ -128,24 +129,6 @@ BaseShapePtrList SequenceShape::ElementsClone() const { return ele_list; } -template -bool SequenceShape::SequenceEqual(const BaseShape &other) const { - if (tid() != other.tid()) { - return false; - } - auto other_shapes = static_cast(other).p_shapes_; - if (other_shapes.size() != p_shapes_.size()) { - return false; - } - for (uint64_t i = 0; i < p_shapes_.size(); ++i) { - MS_EXCEPTION_IF_NULL(p_shapes_[i]); - MS_EXCEPTION_IF_NULL(other_shapes[i]); - if (!(*p_shapes_[i] == *other_shapes[i])) { - return false; - } - } - return true; -} template bool SequenceShape::SequenceEqual(const BaseShape &) const; template bool SequenceShape::SequenceEqual(const BaseShape &) const; } // namespace abstract diff --git a/mindspore/core/abstract/dshape.h b/mindspore/core/abstract/dshape.h index ed48d0b3af..63a83ed24b 100644 --- a/mindspore/core/abstract/dshape.h +++ b/mindspore/core/abstract/dshape.h @@ -108,7 +108,7 @@ class MS_CORE_API NoShape final : public BaseShape { bool IsDimUnknown() const override { return false; } }; -inline const std::shared_ptr kNoShape = std::make_shared(); +MS_CORE_API inline const std::shared_ptr kNoShape = std::make_shared(); /// \brief Shape defines dimensions of tensor. class MS_CORE_API Shape final : public BaseShape { @@ -235,7 +235,23 @@ class MS_CORE_API SequenceShape : public BaseShape { /// \param[in] other Another SequenceShape object. /// \return True if current SequenceShape object is equal to another BaseShape object, otherwise false. template - bool SequenceEqual(const BaseShape &other) const; + bool SequenceEqual(const BaseShape &other) const { + if (tid() != other.tid()) { + return false; + } + auto other_shapes = static_cast(other).p_shapes_; + if (other_shapes.size() != p_shapes_.size()) { + return false; + } + for (uint64_t i = 0; i < p_shapes_.size(); ++i) { + MS_EXCEPTION_IF_NULL(p_shapes_[i]); + MS_EXCEPTION_IF_NULL(other_shapes[i]); + if (!(*p_shapes_[i] == *other_shapes[i])) { + return false; + } + } + return true; + } /// \brief Get all element-shapes. /// diff --git a/mindspore/core/abstract/param_validator.h b/mindspore/core/abstract/param_validator.h index aea03dbfeb..c088cdc08b 100644 --- a/mindspore/core/abstract/param_validator.h +++ b/mindspore/core/abstract/param_validator.h @@ -26,6 +26,7 @@ #include "abstract/utils.h" #include "utils/any.h" #include "ir/primitive.h" +#include "utils/visible.h" namespace mindspore { namespace abstract { @@ -45,10 +46,10 @@ void CheckShapeSame(const std::string &op, const AbstractTensorPtr &tensor_base, TypePtr CheckDtypeSame(const std::string &op, const AbstractTensorPtr &tensor_base, const AbstractTensorPtr &tensor); -int64_t CheckAxis(const std::string &op, const std::string &arg_name, const ValuePtr &axis, int64_t min, int64_t max, - const std::string &rank_name); +MS_CORE_API int64_t CheckAxis(const std::string &op, const std::string &arg_name, const ValuePtr &axis, int64_t min, + int64_t max, const std::string &rank_name); -void CheckArgsSize(const std::string &op, const AbstractBasePtrList &args_spec_list, size_t size_expect); +MS_CORE_API void CheckArgsSize(const std::string &op, const AbstractBasePtrList &args_spec_list, size_t size_expect); void CheckShapeAllPositive(const std::string &op, const ShapeVector &shape); diff --git a/mindspore/core/abstract/prim_statement.cc b/mindspore/core/abstract/prim_statement.cc index 800ee5d080..3eaa7cc58b 100644 --- a/mindspore/core/abstract/prim_statement.cc +++ b/mindspore/core/abstract/prim_statement.cc @@ -74,7 +74,7 @@ AbstractBasePtr InferImplSwitchLayer(const AnalysisEnginePtr &, const PrimitiveP abstract::CheckArgsSize(op_name, args_spec_list, kSwitchLayerInputNum); auto index = CheckArg(op_name, args_spec_list, 0); auto &input_shape = index->shape()->shape(); - if (!input_shape.empty()) { + if (!input_shape.empty() && (input_shape.size() != 1 || input_shape[0] != 1)) { MS_EXCEPTION(ValueError) << op_name << " index must be a 0 dimension tensor, but got a " << input_shape.size() << " dimension tensor"; } diff --git a/mindspore/core/abstract/primitive_infer_map.h b/mindspore/core/abstract/primitive_infer_map.h index 136032c262..91a9494f74 100644 --- a/mindspore/core/abstract/primitive_infer_map.h +++ b/mindspore/core/abstract/primitive_infer_map.h @@ -45,15 +45,15 @@ struct StandardPrimitiveImplReg { using PrimitiveEvalImplMap = mindspore::HashMap; -PrimitiveEvalImplMap &GetPrimitiveToEvalImplMap(); +MS_CORE_API PrimitiveEvalImplMap &GetPrimitiveToEvalImplMap(); -PrimitiveEvalImplMap &GetPrimitiveToBackendEvalImplMap(); +MS_CORE_API PrimitiveEvalImplMap &GetPrimitiveToBackendEvalImplMap(); -StandardPrimitiveImplReg GetPrimitiveInferImpl(const PrimitivePtr &primitive); +MS_CORE_API StandardPrimitiveImplReg GetPrimitiveInferImpl(const PrimitivePtr &primitive); -std::set GetDependsFormMap(const CNodePtr &cnode); +MS_CORE_API std::set GetDependsFormMap(const CNodePtr &cnode); -void RegisterStandardPrimitiveImpl(const PrimitivePtr &primitive, const StandardPrimitiveImplReg &impl_reg); +MS_CORE_API void RegisterStandardPrimitiveImpl(const PrimitivePtr &primitive, const StandardPrimitiveImplReg &impl_reg); class RegisterStandardPrimitiveEvalHelper { public: diff --git a/mindspore/core/abstract/utils.h b/mindspore/core/abstract/utils.h index 4fde320d83..207501a568 100644 --- a/mindspore/core/abstract/utils.h +++ b/mindspore/core/abstract/utils.h @@ -28,21 +28,22 @@ #include "utils/any.h" #include "utils/misc.h" #include "utils/shape_utils.h" +#include "utils/visible.h" namespace mindspore { namespace abstract { ValuePtr ValueJoin(const ValuePtr &value1, const ValuePtr &value2); -TypePtr TypeJoin(const TypePtr &type1, const TypePtr &type2); +MS_CORE_API TypePtr TypeJoin(const TypePtr &type1, const TypePtr &type2); ShapePtr ShapeJoin(const ShapePtr &shape1, const ShapePtr &shape2); -AbstractBasePtr AbstractJoin(const AbstractBasePtrList &args_spec_list); -AbstractBasePtrList AbstractJoin(const AbstractBasePtrList &spec1, const AbstractBasePtrList &spec2); +MS_CORE_API AbstractBasePtr AbstractJoin(const AbstractBasePtrList &args_spec_list); +MS_CORE_API AbstractBasePtrList AbstractJoin(const AbstractBasePtrList &spec1, const AbstractBasePtrList &spec2); // Return an abstract value for the sensitivity of x. // The sensitivity of a function is an Env // The sensitivity of J(x) is x // else self.Clone; -AbstractBasePtr SensitivityTransform(const AbstractBasePtr &spec); +MS_CORE_API AbstractBasePtr SensitivityTransform(const AbstractBasePtr &spec); ShapeVector BroadcastShape(ShapeVector shpx, ShapeVector shpy); @@ -56,8 +57,8 @@ T ShapeSize(const std::vector &shape) { void CheckMinMaxShape(const ShapeVector &shape, ShapeVector *min_shape, ShapeVector *max_shape); AbstractBasePtr MakeAbstract(const BaseShapePtr &base_shape, const TypePtr &type); -AbstractBasePtr MakeMonadAbstract(const MonadTypePtr &type); -AbstractBasePtr MakeAbstractTensor(const ShapePtr &shape, const TypePtr &type); +MS_CORE_API AbstractBasePtr MakeMonadAbstract(const MonadTypePtr &type); +MS_CORE_API AbstractBasePtr MakeAbstractTensor(const ShapePtr &shape, const TypePtr &type); } // namespace abstract } // namespace mindspore #endif // MINDSPORE_CORE_ABSTRACT_UTILS_H_ diff --git a/mindspore/core/base/base_ref.h b/mindspore/core/base/base_ref.h index a5253661b2..eaa1cbca88 100644 --- a/mindspore/core/base/base_ref.h +++ b/mindspore/core/base/base_ref.h @@ -52,7 +52,7 @@ using is_value = std::is_base_of>; template using is_base_ref = std::is_base_of>; -iterator ConstIteratorCast(std::vector *v, const_iterator iter); +MS_CORE_API iterator ConstIteratorCast(std::vector *v, const_iterator iter); inline std::shared_ptr MakeNode(const std::vector &elements) { return std::make_shared(elements); @@ -272,7 +272,7 @@ T cast(const BaseRef &handle) { } } // namespace utils -class VectorRef : public BaseRef { +class MS_CORE_API VectorRef : public BaseRef { public: using value_type = BaseRef; @@ -366,7 +366,7 @@ struct VectorRefHash { std::size_t operator()(const VectorRef &c) const { return c.hash(); } }; -class SetRef : public BaseRef { +class MS_CORE_API SetRef : public BaseRef { public: SetRef() {} explicit SetRef(const std::set &elements) : elements_(elements) {} @@ -411,7 +411,7 @@ class SetRef : public BaseRef { using SetRefPtr = std::shared_ptr; -class RunFunctionRef : public BaseRef { +class MS_CORE_API RunFunctionRef : public BaseRef { public: RunFunctionRef() {} explicit RunFunctionRef(const RunFuncPtr &ref_func) : func_(ref_func) {} diff --git a/mindspore/core/base/base_ref_utils.h b/mindspore/core/base/base_ref_utils.h index 0a5d5d4e94..7af0951440 100644 --- a/mindspore/core/base/base_ref_utils.h +++ b/mindspore/core/base/base_ref_utils.h @@ -22,6 +22,6 @@ #include "base/base_ref.h" namespace mindspore { -std::vector TransformVectorRefToMultiTensor(const VectorRef &base_ref); +MS_CORE_API std::vector TransformVectorRefToMultiTensor(const VectorRef &base_ref); } // namespace mindspore #endif // MINDSPORE_CORE_BASE_BASE_REF_UTILS_H diff --git a/mindspore/core/gvar/CMakeLists.txt b/mindspore/core/gvar/CMakeLists.txt index 0f14e0078d..677f74d0aa 100644 --- a/mindspore/core/gvar/CMakeLists.txt +++ b/mindspore/core/gvar/CMakeLists.txt @@ -1,23 +1,4 @@ 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) - -if(NOT MSVC) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_FORTIFY_SOURCE=2 -O2") - - if(CMAKE_SYSTEM_NAME MATCHES "Windows") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-attributes -DHAVE_SNPRINTF") - add_compile_definitions(BUILDING_DLL) - elseif(CMAKE_SYSTEM_NAME MATCHES "Darwin") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Wuser-defined-warnings -Winconsistent-missing-override") - endif() -endif() - -if(BUILD_LITE) - add_library(mindspore_gvar STATIC ${MS_GVAR_SRC_LIST}) -else() - add_library(mindspore_gvar SHARED ${MS_GVAR_SRC_LIST}) -endif() - -if(APPLE) - set_target_properties(mindspore_gvar PROPERTIES MACOSX_RPATH ON) -endif() \ No newline at end of file +add_library(mindspore_gvar OBJECT ${MS_GVAR_SRC_LIST}) +target_compile_definitions(mindspore_gvar PRIVATE BUILDING_DLL) diff --git a/mindspore/core/gvar/log_adapter_common.cc b/mindspore/core/gvar/log_adapter_common.cc index eff8798ffe..6f6402ea8e 100644 --- a/mindspore/core/gvar/log_adapter_common.cc +++ b/mindspore/core/gvar/log_adapter_common.cc @@ -20,42 +20,43 @@ #include "utils/log_adapter.h" namespace mindspore { -static const std::vector sub_module_names = { - "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 - "FL", // SM_FL - "DISTRIBUTED", // SM_DISTRIBUTED - "LITE", // SM_LITE - "ARMOUR", // SM_ARMOUR - "HCCL_ADPT", // SM_HCCL_ADPT - "RUNTIME_FRAMEWORK", // SM_RUNTIME_FRAMEWORK - "GE", // SM_GE - "API", // SM_API -}; - -const std::string GetSubModuleName(SubModuleId module_id) { return sub_module_names[(module_id % NUM_SUBMODUES)]; } +const std::string GetSubModuleName(SubModuleId module_id) { + static const std::vector sub_module_names = { + "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 + "FL", // SM_FL + "DISTRIBUTED", // SM_DISTRIBUTED + "LITE", // SM_LITE + "ARMOUR", // SM_ARMOUR + "HCCL_ADPT", // SM_HCCL_ADPT + "RUNTIME_FRAMEWORK", // SM_RUNTIME_FRAMEWORK + "GE", // SM_GE + "API", // SM_API + }; + return sub_module_names[(module_id % NUM_SUBMODUES)]; +} // export GetTimeString for all sub modules std::string GetTimeString() { diff --git a/mindspore/core/ir/anf.h b/mindspore/core/ir/anf.h index bb2f44bdd7..5e6d53845a 100644 --- a/mindspore/core/ir/anf.h +++ b/mindspore/core/ir/anf.h @@ -1076,16 +1076,16 @@ static S GetValue(const ValuePtr &value) { return v; } -std::string GetCNodeFuncName(CNodePtr cnode); +MS_CORE_API std::string GetCNodeFuncName(CNodePtr cnode); // used to get FuncGraphPtr from a cnode first input -FuncGraphPtr GetCNodeFuncGraph(const AnfNodePtr &node); +MS_CORE_API FuncGraphPtr GetCNodeFuncGraph(const AnfNodePtr &node); // used to check whether an AnfNode is a cnode with a kind of Primitive as first input -bool IsPrimitiveCNode(const AnfNodePtr &node, const PrimitivePtr &value = nullptr); +MS_CORE_API bool IsPrimitiveCNode(const AnfNodePtr &node, const PrimitivePtr &value = nullptr); // used to get PrimitivePtr from a cnode first input -PrimitivePtr GetCNodePrimitive(const AnfNodePtr &node); +MS_CORE_API PrimitivePtr GetCNodePrimitive(const AnfNodePtr &node); /// \brief Used to check whether the given node is a ValueNode with some Primitive value. /// @@ -1105,28 +1105,28 @@ bool IsOneOfPrimitive(const AnfNodePtr &node, const PrimitiveSet &prim_set); MS_CORE_API bool IsOneOfPrimitiveCNode(const AnfNodePtr &node, const PrimitiveSet &prim_set); // Check whether two primitives are same. -bool IsPrimitiveEquals(const PrimitivePtr &prim1, const PrimitivePtr &prim2); +MS_CORE_API bool IsPrimitiveEquals(const PrimitivePtr &prim1, const PrimitivePtr &prim2); // Get number of AbstractMonad -size_t GetAbstractMonadNum(const AbstractBasePtrList &args); +MS_CORE_API size_t GetAbstractMonadNum(const AbstractBasePtrList &args); // Check whether the given node has monad abstract. -bool HasAbstractMonad(const AnfNodePtr &node); +MS_CORE_API bool HasAbstractMonad(const AnfNodePtr &node); // Check whether the given node has U monad abstract. -bool HasAbstractUMonad(const AnfNodePtr &node); +MS_CORE_API bool HasAbstractUMonad(const AnfNodePtr &node); // Check whether the given node has IO monad abstract. -bool HasAbstractIOMonad(const AnfNodePtr &node); +MS_CORE_API bool HasAbstractIOMonad(const AnfNodePtr &node); // Gets primitive attribute value as a bool flag. -bool GetPrimitiveFlag(const PrimitivePtr &prim, const std::string &attr); +MS_CORE_API bool GetPrimitiveFlag(const PrimitivePtr &prim, const std::string &attr); // Gets effect info from a primitive by its attributes. -EffectInfo GetPrimEffectInfo(const PrimitivePtr &prim); +MS_CORE_API EffectInfo GetPrimEffectInfo(const PrimitivePtr &prim); // Check if monad state is equivalent for the connected two nodes, not strict but more faster. -bool IsStateEquivalent(const AnfNodePtr &outer, const AnfNodePtr &inner); +MS_CORE_API bool IsStateEquivalent(const AnfNodePtr &outer, const AnfNodePtr &inner); // used to check whether a ValueNode has some kind of value template @@ -1163,17 +1163,17 @@ inline S GetValueNode(const AnfNodePtr &node) { return s; } -size_t NewSeenGeneration(); +MS_CORE_API size_t NewSeenGeneration(); namespace id_generator { -std::string get_id(const AnfNodePtr &node); -void reset_id(); +MS_CORE_API std::string get_id(const AnfNodePtr &node); +MS_CORE_API void reset_id(); } // namespace id_generator using TaggedNodeMap = mindspore::HashMap; using TaggedGraph = std::pair; -std::string GetCNodeTarget(const AnfNodePtr &node); +MS_CORE_API std::string GetCNodeTarget(const AnfNodePtr &node); std::string GetOriginNodeTarget(const AnfNodePtr &node); -bool ContainMultiTarget(const std::vector &nodes); +MS_CORE_API bool ContainMultiTarget(const std::vector &nodes); struct GraphSegment { GraphSegment(const std::vector &nodes, bool is_cut) : nodes_(nodes), is_cut_(is_cut) {} void AddPreSegment(const std::shared_ptr &segment) { (void)pre_segments_.insert(segment); } @@ -1194,11 +1194,10 @@ inline void SetSequenceNodeElementsUseFlags(const AnfNodePtr &node, const std::s } // Set the sequence nodes' elements use flags to 'new_flag' at specific 'index' position. -void SetSequenceElementsUseFlags(const AbstractBasePtr &abs, std::size_t index, bool new_flag); +MS_CORE_API void SetSequenceElementsUseFlags(const AbstractBasePtr &abs, std::size_t index, bool new_flag); // Set the sequence nodes' elements use flags all to 'new_flag'. -void SetSequenceElementsUseFlags(const AbstractBasePtr &abs, bool new_flag); +MS_CORE_API void SetSequenceElementsUseFlags(const AbstractBasePtr &abs, bool new_flag); // Set the sequence nodes' elements use flags all to 'new_flag' recursively. -void SetSequenceElementsUseFlagsRecursively(const AbstractBasePtr &abs, bool new_flag); +MS_CORE_API void SetSequenceElementsUseFlagsRecursively(const AbstractBasePtr &abs, bool new_flag); } // namespace mindspore - #endif // MINDSPORE_CORE_IR_ANF_H_ diff --git a/mindspore/core/ir/dtype.h b/mindspore/core/ir/dtype.h index fd8536afa9..5c9052e82f 100644 --- a/mindspore/core/ir/dtype.h +++ b/mindspore/core/ir/dtype.h @@ -424,20 +424,20 @@ struct MS_CORE_API TypeListEqual { bool operator()(TypePtrList const &lhs, TypePtrList const &rhs) const; }; -inline const TypePtr kTypeExternal = std::make_shared(); -inline const TypePtr kTypeEnv = std::make_shared(); -inline const TypePtr kTypeType = std::make_shared(); -inline const TypePtr kString = std::make_shared(); -inline const TypePtr kList = std::make_shared(); -inline const TypePtr kTuple = std::make_shared(); -inline const TypePtr kDict = std::make_shared(); -inline const TypePtr kSlice = std::make_shared(); -inline const TypePtr kKeyword = std::make_shared(); -inline const TypePtr kTensorType = std::make_shared(); -inline const TypePtr kTensorTypeFP16 = std::make_shared(std::make_shared(16)); -inline const TypePtr kTensorTypeFP32 = std::make_shared(std::make_shared(32)); -inline const TypePtr kTensorTypeFP64 = std::make_shared(std::make_shared(64)); -inline const TypePtr kCSRTensorType = std::make_shared(); +MS_CORE_API inline const TypePtr kTypeExternal = std::make_shared(); +MS_CORE_API inline const TypePtr kTypeEnv = std::make_shared(); +MS_CORE_API inline const TypePtr kTypeType = std::make_shared(); +MS_CORE_API inline const TypePtr kString = std::make_shared(); +MS_CORE_API inline const TypePtr kList = std::make_shared(); +MS_CORE_API inline const TypePtr kTuple = std::make_shared(); +MS_CORE_API inline const TypePtr kDict = std::make_shared(); +MS_CORE_API inline const TypePtr kSlice = std::make_shared(); +MS_CORE_API inline const TypePtr kKeyword = std::make_shared(); +MS_CORE_API inline const TypePtr kTensorType = std::make_shared(); +MS_CORE_API inline const TypePtr kTensorTypeFP16 = std::make_shared(std::make_shared(16)); +MS_CORE_API inline const TypePtr kTensorTypeFP32 = std::make_shared(std::make_shared(32)); +MS_CORE_API inline const TypePtr kTensorTypeFP64 = std::make_shared(std::make_shared(64)); +MS_CORE_API inline const TypePtr kCSRTensorType = std::make_shared(); } // namespace mindspore #endif // MINDSPORE_CORE_IR_DTYPE_H_ diff --git a/mindspore/core/ir/dtype/empty.h b/mindspore/core/ir/dtype/empty.h index 327f4f37c4..00d1c66dcf 100644 --- a/mindspore/core/ir/dtype/empty.h +++ b/mindspore/core/ir/dtype/empty.h @@ -101,10 +101,10 @@ class MS_CORE_API TypeEllipsis : public Type { }; using TypeEllipsisPtr = std::shared_ptr; -inline const TypePtr kTypeNone = std::make_shared(); -inline const TypePtr kTypeNull = std::make_shared(); -inline const TypePtr kTypeEllipsis = std::make_shared(); -inline const TypePtr kAnyType = std::make_shared(); +MS_CORE_API inline const TypePtr kTypeNone = std::make_shared(); +MS_CORE_API inline const TypePtr kTypeNull = std::make_shared(); +MS_CORE_API inline const TypePtr kTypeEllipsis = std::make_shared(); +MS_CORE_API inline const TypePtr kAnyType = std::make_shared(); } // namespace mindspore #endif // MINDSPORE_CORE_IR_DTYPE_EMPTY_H_ diff --git a/mindspore/core/ir/dtype/monad_type.h b/mindspore/core/ir/dtype/monad_type.h index c76b583b27..b782a83d0c 100644 --- a/mindspore/core/ir/dtype/monad_type.h +++ b/mindspore/core/ir/dtype/monad_type.h @@ -63,8 +63,8 @@ class IOMonadType : public MonadType { }; using IOMonadTypePtr = std::shared_ptr; -extern const TypePtr kIOMonadType; -extern const TypePtr kUMonadType; +MS_CORE_API extern const TypePtr kIOMonadType; +MS_CORE_API extern const TypePtr kUMonadType; } // namespace mindspore #endif // MINDSPORE_CORE_IR_DTYPE_MONDA_H_ diff --git a/mindspore/core/ir/dtype/number.h b/mindspore/core/ir/dtype/number.h index 33930ae6b2..2ac6d4d420 100644 --- a/mindspore/core/ir/dtype/number.h +++ b/mindspore/core/ir/dtype/number.h @@ -228,24 +228,24 @@ class MS_CORE_API Complex : public Number { std::string DumpText() const override { return std::string("C") + std::to_string(nbits()); } }; -inline const TypePtr kBool = std::make_shared(); -inline const TypePtr kInt8 = std::make_shared(static_cast(BitsNum::eBits8)); -inline const TypePtr kInt16 = std::make_shared(static_cast(BitsNum::eBits16)); -inline const TypePtr kInt32 = std::make_shared(static_cast(BitsNum::eBits32)); -inline const TypePtr kInt64 = std::make_shared(static_cast(BitsNum::eBits64)); -inline const TypePtr kUInt8 = std::make_shared(static_cast(BitsNum::eBits8)); -inline const TypePtr kUInt16 = std::make_shared(static_cast(BitsNum::eBits16)); -inline const TypePtr kUInt32 = std::make_shared(static_cast(BitsNum::eBits32)); -inline const TypePtr kUInt64 = std::make_shared(static_cast(BitsNum::eBits64)); -inline const TypePtr kFloat16 = std::make_shared(static_cast(BitsNum::eBits16)); -inline const TypePtr kFloat32 = std::make_shared(static_cast(BitsNum::eBits32)); -inline const TypePtr kFloat64 = std::make_shared(static_cast(BitsNum::eBits64)); -inline const TypePtr kInt = std::make_shared(); -inline const TypePtr kUInt = std::make_shared(); -inline const TypePtr kFloat = std::make_shared(); -inline const TypePtr kNumber = std::make_shared(); -inline const TypePtr kComplex64 = std::make_shared(static_cast(BitsNum::eBits64)); -inline const TypePtr kComplex128 = std::make_shared(static_cast(BitsNum::eBits128)); +MS_CORE_API inline const TypePtr kBool = std::make_shared(); +MS_CORE_API inline const TypePtr kInt8 = std::make_shared(static_cast(BitsNum::eBits8)); +MS_CORE_API inline const TypePtr kInt16 = std::make_shared(static_cast(BitsNum::eBits16)); +MS_CORE_API inline const TypePtr kInt32 = std::make_shared(static_cast(BitsNum::eBits32)); +MS_CORE_API inline const TypePtr kInt64 = std::make_shared(static_cast(BitsNum::eBits64)); +MS_CORE_API inline const TypePtr kUInt8 = std::make_shared(static_cast(BitsNum::eBits8)); +MS_CORE_API inline const TypePtr kUInt16 = std::make_shared(static_cast(BitsNum::eBits16)); +MS_CORE_API inline const TypePtr kUInt32 = std::make_shared(static_cast(BitsNum::eBits32)); +MS_CORE_API inline const TypePtr kUInt64 = std::make_shared(static_cast(BitsNum::eBits64)); +MS_CORE_API inline const TypePtr kFloat16 = std::make_shared(static_cast(BitsNum::eBits16)); +MS_CORE_API inline const TypePtr kFloat32 = std::make_shared(static_cast(BitsNum::eBits32)); +MS_CORE_API inline const TypePtr kFloat64 = std::make_shared(static_cast(BitsNum::eBits64)); +MS_CORE_API inline const TypePtr kInt = std::make_shared(); +MS_CORE_API inline const TypePtr kUInt = std::make_shared(); +MS_CORE_API inline const TypePtr kFloat = std::make_shared(); +MS_CORE_API inline const TypePtr kNumber = std::make_shared(); +MS_CORE_API inline const TypePtr kComplex64 = std::make_shared(static_cast(BitsNum::eBits64)); +MS_CORE_API inline const TypePtr kComplex128 = std::make_shared(static_cast(BitsNum::eBits128)); } // namespace mindspore #endif // MINDSPORE_CORE_IR_DTYPE_NUMBER_H_ diff --git a/mindspore/core/ir/dtype/ref.h b/mindspore/core/ir/dtype/ref.h index a3304b090c..65a86f2742 100644 --- a/mindspore/core/ir/dtype/ref.h +++ b/mindspore/core/ir/dtype/ref.h @@ -65,8 +65,8 @@ class MS_CORE_API RefType final : public TensorType { }; using RefTypePtr = std::shared_ptr; -inline const TypePtr kRefKeyType = std::make_shared(); -inline const TypePtr kRefType = std::make_shared(); +MS_CORE_API inline const TypePtr kRefKeyType = std::make_shared(); +MS_CORE_API inline const TypePtr kRefType = std::make_shared(); } // namespace mindspore #endif // MINDSPORE_CORE_IR_DTYPE_REF_H_ diff --git a/mindspore/core/ir/dtype/type.h b/mindspore/core/ir/dtype/type.h index 44e1a28195..8937c5ccdd 100644 --- a/mindspore/core/ir/dtype/type.h +++ b/mindspore/core/ir/dtype/type.h @@ -48,9 +48,9 @@ TypeId ComplexBitsToTypeId(const int nbits); /// \param[in] v Define the input TypeId. /// \return The label of input TypeId. MS_CORE_API const std::string &TypeIdLabel(const TypeId &v); -TypeId NormalizeTypeId(const TypeId type_id); +MS_CORE_API TypeId NormalizeTypeId(const TypeId type_id); bool IsSameObjectType(const Type &lhs, const Type &rhs); -size_t GetTypeByte(const TypePtr &type_ptr); +MS_CORE_API size_t GetTypeByte(const TypePtr &type_ptr); enum class BitsNum : int { eBits8 = 8, @@ -166,14 +166,14 @@ class MS_CORE_API Type : public Value { /// \param[in] os The ostream to receive the description /// \param[in] type The Type object need to show the description /// \return The ostream with Type object description - friend std::ostream &operator<<(std::ostream &os, const Type &type); + MS_CORE_API friend std::ostream &operator<<(std::ostream &os, const Type &type); /// \brief Get Type object ToString description. /// /// \param[in] os The ostream to receive the description /// \param[in] type The TypePtr need to show the description /// \return The ostream with Type object description - friend std::ostream &operator<<(std::ostream &os, const TypePtr type); + MS_CORE_API friend std::ostream &operator<<(std::ostream &os, const TypePtr type); private: TypeId meta_type_; diff --git a/mindspore/core/ir/func_graph.cc b/mindspore/core/ir/func_graph.cc index a4dfca45b8..aed2152d0f 100644 --- a/mindspore/core/ir/func_graph.cc +++ b/mindspore/core/ir/func_graph.cc @@ -795,4 +795,6 @@ api::FuncGraphPtr api::FuncGraph::GetFuncGraphFromAnfNode(const AnfNodePtr &inpu auto fg = GetValueNode(input); return fg; } + +FuncGraph::Drawer FuncGraph::drawer_ = nullptr; } // namespace mindspore diff --git a/mindspore/core/ir/func_graph.h b/mindspore/core/ir/func_graph.h index 075fa74d1d..226c1307e7 100644 --- a/mindspore/core/ir/func_graph.h +++ b/mindspore/core/ir/func_graph.h @@ -42,6 +42,7 @@ #include "api/ir/func_graph.h" #include "ir/func_graph_transform.h" #include "ir/func_graph_base.h" +#include "utils/visible.h" namespace mindspore { using BaseRefCounterMap = OrderedMap; @@ -95,7 +96,7 @@ const char kFuncGraphFlagBackPropEntry[] = "BackPropEntry"; const char kFuncGraphFlagReAutoMonad[] = "ReAutoMonad"; const char kFuncGraphFlagRecursive[] = "Recursive"; -class FuncGraph : public deprecated::api::FuncGraph, public FuncGraphBase, public EffectInfoHolder { +class MS_CORE_API FuncGraph : public deprecated::api::FuncGraph, public FuncGraphBase, public EffectInfoHolder { public: using Drawer = std::function; @@ -435,7 +436,7 @@ class FuncGraph : public deprecated::api::FuncGraph, public FuncGraphBase, publi // CNode order which relates to origin code order. OrderedSet order_; bool stub_; - inline static Drawer drawer_ = nullptr; + static Drawer drawer_; // Design switch_input and switch_layer_input as a ptr to // share between derived backpropagator and cloned graphs. std::shared_ptr switch_input_; diff --git a/mindspore/core/ir/func_graph_base.h b/mindspore/core/ir/func_graph_base.h index 31f736fae0..5f84045837 100644 --- a/mindspore/core/ir/func_graph_base.h +++ b/mindspore/core/ir/func_graph_base.h @@ -25,7 +25,7 @@ namespace mindspore { class FuncGraphBase; using FuncGraphBasePtr = std::shared_ptr; -class FuncGraphLoopBreaker { +class MS_CORE_API FuncGraphLoopBreaker { public: ~FuncGraphLoopBreaker(); diff --git a/mindspore/core/ir/func_graph_cloner.h b/mindspore/core/ir/func_graph_cloner.h index 798c9d3c43..2732fed2dc 100644 --- a/mindspore/core/ir/func_graph_cloner.h +++ b/mindspore/core/ir/func_graph_cloner.h @@ -30,6 +30,7 @@ #include "ir/func_graph.h" #include "ir/manager.h" #include "utils/hashing.h" +#include "utils/visible.h" namespace mindspore { class Cloner; @@ -54,7 +55,7 @@ struct UpdateInfo { using UpdateInfoPtr = std::shared_ptr; -class Cloner { +class MS_CORE_API Cloner { public: explicit Cloner(const FuncGraphVector &func_graphs = {}, bool clone_all_valuenodes = false, bool clone_all_child_graphs = true, bool clone_all_used_graphs = false, @@ -134,17 +135,17 @@ class Cloner { mindspore::HashMap repl_func_graph_params_; }; -AnfNodePtr InlineClone(const FuncGraphPtr &func_graph, const FuncGraphPtr &target_func_graph, - const AnfNodePtrList &func_graph_args, const ScopePtr &scope = nullptr); +MS_CORE_API AnfNodePtr InlineClone(const FuncGraphPtr &func_graph, const FuncGraphPtr &target_func_graph, + const AnfNodePtrList &func_graph_args, const ScopePtr &scope = nullptr); -FuncGraphPtr LiftingClone(const FuncGraphPtr &func_graph); +MS_CORE_API FuncGraphPtr LiftingClone(const FuncGraphPtr &func_graph); -ClonerPtr SpecializerClone(const FuncGraphPtr &func_graph, const TraceInfoPtr &relation); +MS_CORE_API ClonerPtr SpecializerClone(const FuncGraphPtr &func_graph, const TraceInfoPtr &relation); -FuncGraphPtr TransformableClone(const FuncGraphPtr &func_graph, - const TraceInfoPtr &relation = std::make_shared()); -FuncGraphPtr BasicClone(const FuncGraphPtr &func_graph, bool clone_value_nodes = false, - const UpdateInfoPtr update_info = nullptr); +MS_CORE_API FuncGraphPtr TransformableClone(const FuncGraphPtr &func_graph, + const TraceInfoPtr &relation = std::make_shared()); +MS_CORE_API FuncGraphPtr BasicClone(const FuncGraphPtr &func_graph, bool clone_value_nodes = false, + const UpdateInfoPtr update_info = nullptr); } // namespace mindspore #endif // MINDSPORE_CORE_IR_FUNC_GRAPH_CLONER_H_ diff --git a/mindspore/core/ir/func_graph_transform.h b/mindspore/core/ir/func_graph_transform.h index f3d71f0c58..4ad37984f2 100644 --- a/mindspore/core/ir/func_graph_transform.h +++ b/mindspore/core/ir/func_graph_transform.h @@ -23,7 +23,7 @@ namespace mindspore { // ANF transform class. // Either a primitive or a func_graph. -class FuncGraphTransform { +class MS_CORE_API FuncGraphTransform { public: enum Type { kGtPrimitive, kGtFuncGraph }; diff --git a/mindspore/core/ir/graph_utils.h b/mindspore/core/ir/graph_utils.h index 83cd52b5f1..6d4e224377 100644 --- a/mindspore/core/ir/graph_utils.h +++ b/mindspore/core/ir/graph_utils.h @@ -34,6 +34,7 @@ #include "ir/scalar.h" #include "ir/tensor.h" #include "utils/label.h" +#include "utils/visible.h" namespace mindspore { enum IncludeType { FOLLOW, NOFOLLOW, EXCLUDE }; @@ -46,29 +47,31 @@ using MatchFunc = std::function; using NodeVisitFunc = std::function; std::vector SuccDeeper(const AnfNodePtr &node); -std::vector SuccDeeperSimple(const AnfNodePtr &node); -std::vector SuccIncoming(const AnfNodePtr &node); +MS_CORE_API std::vector SuccDeeperSimple(const AnfNodePtr &node); +MS_CORE_API std::vector SuccIncoming(const AnfNodePtr &node); std::vector SuccIncludeFV(const FuncGraphPtr &fg, const AnfNodePtr &node); -const std::vector &GetInputs(const AnfNodePtr &node); +MS_CORE_API const std::vector &GetInputs(const AnfNodePtr &node); inline IncludeType AlwaysInclude(const AnfNodePtr &) { return FOLLOW; } -IncludeType IncludeBelongGraph(const FuncGraphPtr &fg, const AnfNodePtr &node); +MS_CORE_API IncludeType IncludeBelongGraph(const FuncGraphPtr &fg, const AnfNodePtr &node); -std::vector DeepScopedGraphSearch(const AnfNodePtr &root, const IncludeFunc &include = AlwaysInclude); +MS_CORE_API std::vector DeepScopedGraphSearch(const AnfNodePtr &root, + const IncludeFunc &include = AlwaysInclude); -std::vector DeepLinkedGraphSearch(const AnfNodePtr &root, const IncludeFunc &include = AlwaysInclude); +MS_CORE_API std::vector DeepLinkedGraphSearch(const AnfNodePtr &root, + const IncludeFunc &include = AlwaysInclude); -std::vector DeepScopedGraphSearchWithFilter(const AnfNodePtr &root, const IncludeFunc &include, - const FilterFunc &filter); +MS_CORE_API std::vector DeepScopedGraphSearchWithFilter(const AnfNodePtr &root, const IncludeFunc &include, + const FilterFunc &filter); -std::vector TopoSort(const AnfNodePtr &root, const SuccFunc &succ = SuccIncoming, - const IncludeFunc &include = AlwaysInclude); +MS_CORE_API std::vector TopoSort(const AnfNodePtr &root, const SuccFunc &succ = SuccIncoming, + const IncludeFunc &include = AlwaysInclude); -std::vector BroadFirstSearchGraphCNodes(const CNodePtr &start); +MS_CORE_API std::vector BroadFirstSearchGraphCNodes(const CNodePtr &start); std::vector BroadFirstSearchGraphUsed(const FuncGraphPtr &root); -CNodePtr BroadFirstSearchFirstOf(const std::vector &starts, const MatchFunc &match_predicate); +MS_CORE_API CNodePtr BroadFirstSearchFirstOf(const std::vector &starts, const MatchFunc &match_predicate); } // namespace mindspore diff --git a/mindspore/core/ir/manager.h b/mindspore/core/ir/manager.h index e92480c391..8f95063a3e 100644 --- a/mindspore/core/ir/manager.h +++ b/mindspore/core/ir/manager.h @@ -66,11 +66,11 @@ using FuncGraphSetPtr = std::shared_ptr; // func_graph, be managed graph // manage: if true, created manager will be set in func_graph // FuncGraphManagerPtr: return created manager -FuncGraphManagerPtr Manage(FuncGraphPtr func_graph, bool manage = true); +MS_CORE_API FuncGraphManagerPtr Manage(FuncGraphPtr func_graph, bool manage = true); -FuncGraphManagerPtr Manage(const std::vector &func_graphs, bool manage = true); +MS_CORE_API FuncGraphManagerPtr Manage(const std::vector &func_graphs, bool manage = true); -FuncGraphManagerPtr MakeManager(const std::vector &func_graphs = {}, bool manage = true); +MS_CORE_API FuncGraphManagerPtr MakeManager(const std::vector &func_graphs = {}, bool manage = true); struct Signals { Signal InvalidateComputer; @@ -277,8 +277,8 @@ class FuncGraphJTotalComputer final : public DepComputer { bool SeekJ(const FuncGraphPtr &fg, size_t seen_num); }; -class FuncGraphManager : public std::enable_shared_from_this, - public deprecated::api::FuncGraphManager { +class MS_CORE_API FuncGraphManager : public std::enable_shared_from_this, + public deprecated::api::FuncGraphManager { public: explicit FuncGraphManager(const std::vector &roots, bool manage = true); ~FuncGraphManager() { @@ -376,7 +376,7 @@ class FuncGraphManager : public std::enable_shared_from_this, bool is_manage_; }; -class FuncGraphTransaction { +class MS_CORE_API FuncGraphTransaction { public: explicit FuncGraphTransaction(FuncGraphManager *manager) : manager_(manager) {} FuncGraphTransaction() : manager_(nullptr) {} diff --git a/mindspore/core/ir/meta_func_graph.h b/mindspore/core/ir/meta_func_graph.h index bacd8a4480..29d66b3a51 100644 --- a/mindspore/core/ir/meta_func_graph.h +++ b/mindspore/core/ir/meta_func_graph.h @@ -37,7 +37,7 @@ namespace mindspore { // Graph generator. // Can be called with a pipeline's resources and a list of argument types to // generate a graph corresponding to these types. -class MetaFuncGraph : public FuncGraphBase { +class MS_CORE_API MetaFuncGraph : public FuncGraphBase { public: explicit MetaFuncGraph(const std::string &name) : name_(name) { cache_.clear(); } diff --git a/mindspore/core/ir/named.h b/mindspore/core/ir/named.h index dbe1bac595..17aa9f9f84 100644 --- a/mindspore/core/ir/named.h +++ b/mindspore/core/ir/named.h @@ -121,7 +121,7 @@ class MS_CORE_API None final : public Named { MS_DECLARE_PARENT(None, Named); abstract::AbstractBasePtr ToAbstract() override; }; -inline const NamedPtr kNone = std::make_shared(); +MS_CORE_API inline const NamedPtr kNone = std::make_shared(); /// \beief Null defines interface for null data. class MS_CORE_API Null final : public Named { @@ -133,7 +133,7 @@ class MS_CORE_API Null final : public Named { MS_DECLARE_PARENT(Null, Named); abstract::AbstractBasePtr ToAbstract() override; }; -inline const NamedPtr kNull = std::make_shared(); +MS_CORE_API inline const NamedPtr kNull = std::make_shared(); /// \beief Ellipsis defines interface for ... data. class MS_CORE_API Ellipsis final : public Named { @@ -145,6 +145,7 @@ class MS_CORE_API Ellipsis final : public Named { MS_DECLARE_PARENT(Ellipsis, Named); abstract::AbstractBasePtr ToAbstract() override; }; -inline const NamedPtr kEllipsis = std::make_shared(); + +MS_CORE_API inline const NamedPtr kEllipsis = std::make_shared(); } // namespace mindspore #endif // MINDSPORE_CORE_IR_NAMED_H_ diff --git a/mindspore/core/ir/primal_attr.cc b/mindspore/core/ir/primal_attr.cc new file mode 100644 index 0000000000..ab3863a332 --- /dev/null +++ b/mindspore/core/ir/primal_attr.cc @@ -0,0 +1,24 @@ +/** + * Copyright 2022 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 "ir/primal_attr.h" + +namespace mindspore { +PrimalAttrManager &PrimalAttrManager::GetInstance() noexcept { + static PrimalAttrManager instance; + return instance; +} +} // namespace mindspore diff --git a/mindspore/core/ir/primal_attr.h b/mindspore/core/ir/primal_attr.h index ba366b38c7..bfe4c56e46 100644 --- a/mindspore/core/ir/primal_attr.h +++ b/mindspore/core/ir/primal_attr.h @@ -20,18 +20,15 @@ #include #include #include "utils/hash_map.h" -#include "ir/anf.h" +#include "utils/visible.h" namespace mindspore { class Value; using ValuePtr = std::shared_ptr; -class PrimalAttrManager { +class MS_CORE_API PrimalAttrManager { public: - static PrimalAttrManager &GetInstance() noexcept { - static PrimalAttrManager instance; - return instance; - } + static PrimalAttrManager &GetInstance() noexcept; PrimalAttrManager(const PrimalAttrManager &) = delete; PrimalAttrManager &operator=(const PrimalAttrManager &) = delete; ~PrimalAttrManager() = default; diff --git a/mindspore/core/ir/primal_debug_info.cc b/mindspore/core/ir/primal_debug_info.cc new file mode 100644 index 0000000000..c68d1f66cf --- /dev/null +++ b/mindspore/core/ir/primal_debug_info.cc @@ -0,0 +1,24 @@ +/** + * Copyright 2021 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 "ir/primal_debug_info.h" + +namespace mindspore { +PrimalDebugInfoManager &PrimalDebugInfoManager::GetInstance() noexcept { + static PrimalDebugInfoManager instance; + return instance; +} +} // namespace mindspore diff --git a/mindspore/core/ir/primal_debug_info.h b/mindspore/core/ir/primal_debug_info.h index ac88418704..c05456373e 100644 --- a/mindspore/core/ir/primal_debug_info.h +++ b/mindspore/core/ir/primal_debug_info.h @@ -23,14 +23,12 @@ #include #include "utils/hash_map.h" #include "utils/info.h" +#include "utils/visible.h" namespace mindspore { -class PrimalDebugInfoManager { +class MS_CORE_API PrimalDebugInfoManager { public: - static PrimalDebugInfoManager &GetInstance() noexcept { - static PrimalDebugInfoManager instance; - return instance; - } + static PrimalDebugInfoManager &GetInstance() noexcept; PrimalDebugInfoManager(const PrimalDebugInfoManager &) = delete; PrimalDebugInfoManager &operator=(const PrimalDebugInfoManager &) = delete; ~PrimalDebugInfoManager() = default; diff --git a/mindspore/core/ir/scope.cc b/mindspore/core/ir/scope.cc index 96b99e6eda..eb0481f61e 100644 --- a/mindspore/core/ir/scope.cc +++ b/mindspore/core/ir/scope.cc @@ -18,6 +18,11 @@ namespace mindspore { const ScopePtr kDefaultScope = std::make_shared("Default"); +ScopeManager &ScopeManager::GetInstance() noexcept { + static ScopeManager instance; + return instance; +} + void ScopeManager::EnterScope(const ScopePtr &scope) { if (scope != kDefaultScope) { scope_stack_.push(scope); diff --git a/mindspore/core/ir/scope.h b/mindspore/core/ir/scope.h index 1f58753f0b..abca2309ec 100644 --- a/mindspore/core/ir/scope.h +++ b/mindspore/core/ir/scope.h @@ -24,7 +24,7 @@ namespace mindspore { class Scope; using ScopePtr = std::shared_ptr; -extern const ScopePtr kDefaultScope; +MS_CORE_API extern const ScopePtr kDefaultScope; class MS_CORE_API Scope { public: @@ -50,10 +50,7 @@ class MS_CORE_API ScopeManager { /// \brief Get instance of ScopeManager. /// /// \return Instance of ScopeManager. - static ScopeManager &GetInstance() noexcept { - static ScopeManager instance; - return instance; - } + static ScopeManager &GetInstance() noexcept; /// \brief Disable the default constructor. ScopeManager(const ScopeManager &) = delete; diff --git a/mindspore/core/ir/value.h b/mindspore/core/ir/value.h index 5df149c25e..e6fea52ed1 100644 --- a/mindspore/core/ir/value.h +++ b/mindspore/core/ir/value.h @@ -488,7 +488,7 @@ class MS_CORE_API AnyValue : public Value { abstract::AbstractBasePtr ToAbstract() override; }; -inline const ValuePtr kAnyValue = std::make_shared(); +MS_CORE_API inline const ValuePtr kAnyValue = std::make_shared(); /// \brief Monad defines a Value class which is used in side effect. class MS_CORE_API Monad : public Value { @@ -535,7 +535,7 @@ class MS_CORE_API UMonad final : public Monad { std::string ToString() const override { return "U"; } }; using UMonadPtr = std::shared_ptr; -extern const ValuePtr kUMonad; +MS_CORE_API extern const ValuePtr kUMonad; /// \brief IOMonad defines a Value class which related to IO side effect. class MS_CORE_API IOMonad final : public Monad { @@ -564,7 +564,7 @@ class MS_CORE_API IOMonad final : public Monad { std::string ToString() const override { return "IO"; } }; using IOMonadPtr = std::shared_ptr; -extern const ValuePtr kIOMonad; +MS_CORE_API extern const ValuePtr kIOMonad; template <> inline const char *GetValue(const ValuePtr &value) { diff --git a/mindspore/core/ir/visitor.h b/mindspore/core/ir/visitor.h index c6accbefbb..95c9601c23 100644 --- a/mindspore/core/ir/visitor.h +++ b/mindspore/core/ir/visitor.h @@ -23,7 +23,7 @@ namespace mindspore { using VisitFuncType = std::function; using PredicateFuncType = std::function; -class AnfIrVisitor { +class MS_CORE_API AnfIrVisitor { public: virtual void Visit(const AnfNodePtr &); virtual void Visit(const CNodePtr &); diff --git a/mindspore/core/load_mindir/infer_mindir.h b/mindspore/core/load_mindir/infer_mindir.h index ee4d8f7231..cc4b5860c3 100644 --- a/mindspore/core/load_mindir/infer_mindir.h +++ b/mindspore/core/load_mindir/infer_mindir.h @@ -20,7 +20,6 @@ #include "ir/anf.h" namespace mindspore { -bool InferMindir(const FuncGraphPtr &root, const AbstractBasePtrList &args, bool raise_exception = false); +MS_CORE_API bool InferMindir(const FuncGraphPtr &root, const AbstractBasePtrList &args, bool raise_exception = false); } // namespace mindspore - #endif // MINDSPORE_CORE_LOAD_MINDIR_INFER_MINDIR_H diff --git a/mindspore/core/load_mindir/load_model.h b/mindspore/core/load_mindir/load_model.h index 7f0527e1fb..887c7c1792 100644 --- a/mindspore/core/load_mindir/load_model.h +++ b/mindspore/core/load_mindir/load_model.h @@ -55,7 +55,7 @@ class Layout { using LayoutPtr = std::shared_ptr; using LayoutMap = std::map; -class MindIRLoader { +class MS_CORE_API MindIRLoader { public: MindIRLoader() = default; MindIRLoader(bool is_lite, const unsigned char *dec_key, const size_t key_len, const std::string &dec_mode, @@ -90,6 +90,6 @@ class MindIRLoader { }; std::shared_ptr> ReadProtoFile(const std::string &file); -FuncGraphPtr ConvertStreamToFuncGraph(const char *buf, const size_t buf_size, bool is_lite = false); +MS_CORE_API FuncGraphPtr ConvertStreamToFuncGraph(const char *buf, const size_t buf_size, bool is_lite = false); } // namespace mindspore #endif // MINDSPORE_CORE_LOAD_MODEL_H diff --git a/mindspore/core/mindrt/include/actor/actor.h b/mindspore/core/mindrt/include/actor/actor.h index b25f1afbde..b61232a157 100644 --- a/mindspore/core/mindrt/include/actor/actor.h +++ b/mindspore/core/mindrt/include/actor/actor.h @@ -35,7 +35,7 @@ class ActorThreadPool; // should be at least greater than 1 constexpr uint32_t MAX_ACTOR_RECORD_SIZE = 3; -class ActorBase { +class MS_CORE_API ActorBase { public: inline const AID &GetAID() const { return id; } diff --git a/mindspore/core/mindrt/include/actor/aid.h b/mindspore/core/mindrt/include/actor/aid.h index 719a92100f..e0f9819e19 100644 --- a/mindspore/core/mindrt/include/actor/aid.h +++ b/mindspore/core/mindrt/include/actor/aid.h @@ -20,12 +20,13 @@ #include #include "actor/log.h" +#include "utils/visible.h" namespace mindspore { constexpr auto MINDRT_TCP = "tcp"; constexpr auto MINDRT_UDP = "udp"; -class AID { +class MS_CORE_API AID { public: AID() : name(), url() {} diff --git a/mindspore/core/mindrt/include/actor/op_actor.h b/mindspore/core/mindrt/include/actor/op_actor.h index 469dfe1615..826f7c5cff 100644 --- a/mindspore/core/mindrt/include/actor/op_actor.h +++ b/mindspore/core/mindrt/include/actor/op_actor.h @@ -22,6 +22,7 @@ #include #include #include "utils/hash_map.h" +#include "utils/visible.h" #include "actor/actor.h" #include "async/uuid_base.h" #include "async/future.h" @@ -48,13 +49,10 @@ struct OpData { int index_; }; -class RandInt { +class MS_CORE_API RandInt { public: int Get() { return rand(); } - static RandInt &Instance() { - static RandInt instance; - return instance; - } + static RandInt &Instance(); private: RandInt() { srand(time(NULL)); } diff --git a/mindspore/core/mindrt/src/actor/actormgr.h b/mindspore/core/mindrt/src/actor/actormgr.h index 6e8190e8d2..2352a1b017 100644 --- a/mindspore/core/mindrt/src/actor/actormgr.h +++ b/mindspore/core/mindrt/src/actor/actormgr.h @@ -33,7 +33,7 @@ namespace mindspore { class ActorBase; class IOMgr; -class ActorMgr { +class MS_CORE_API ActorMgr { public: static inline ActorMgr *GetActorMgrRef() { return &actorMgr; } diff --git a/mindspore/core/mindrt/src/actor/op_actor.cc b/mindspore/core/mindrt/src/actor/op_actor.cc new file mode 100644 index 0000000000..d5f0a15a0c --- /dev/null +++ b/mindspore/core/mindrt/src/actor/op_actor.cc @@ -0,0 +1,24 @@ +/** + * Copyright 2022 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 "actor/op_actor.h" + +namespace mindspore { +RandInt &RandInt::Instance() { + static RandInt instance; + return instance; +} +} // namespace mindspore diff --git a/mindspore/core/mindrt/src/thread/threadpool.h b/mindspore/core/mindrt/src/thread/threadpool.h index 167abb4631..4ca2fd8886 100644 --- a/mindspore/core/mindrt/src/thread/threadpool.h +++ b/mindspore/core/mindrt/src/thread/threadpool.h @@ -33,6 +33,8 @@ #include #endif #endif +#include "utils/visible.h" + namespace mindspore { constexpr int kDefaultSpinCount = 300000; constexpr int kMaxCount = 30000; @@ -122,7 +124,7 @@ class Worker { int max_spin_count_{kMinSpinCount}; }; -class ThreadPool { +class MS_CORE_API ThreadPool { public: static ThreadPool *CreateThreadPool(size_t thread_num, const std::vector &core_list = {}); virtual ~ThreadPool(); diff --git a/mindspore/core/ops/grad/maximum_grad.h b/mindspore/core/ops/grad/maximum_grad.h index 5f2f32203b..05f030caf1 100644 --- a/mindspore/core/ops/grad/maximum_grad.h +++ b/mindspore/core/ops/grad/maximum_grad.h @@ -25,7 +25,7 @@ namespace mindspore { namespace ops { constexpr auto kNameMaximumGrad = "MaximumGrad"; -class MaximumGrad : public PrimitiveC { +class MS_CORE_API MaximumGrad : public PrimitiveC { public: MaximumGrad() : PrimitiveC(kNameMaximumGrad) { InitIOName({"x1", "x2", "grads"}, {"y1", "y2"}); } ~MaximumGrad() = default; diff --git a/mindspore/core/ops/grad/minimum_grad.h b/mindspore/core/ops/grad/minimum_grad.h index 4624fb3c8f..1c495d08ca 100644 --- a/mindspore/core/ops/grad/minimum_grad.h +++ b/mindspore/core/ops/grad/minimum_grad.h @@ -25,7 +25,7 @@ namespace mindspore { namespace ops { constexpr auto kNameMinimumGrad = "MinimumGrad"; -class MinimumGrad : public PrimitiveC { +class MS_CORE_API MinimumGrad : public PrimitiveC { public: MinimumGrad() : PrimitiveC(kNameMinimumGrad) { InitIOName({"x1", "x2", "grads"}, {"y1", "y2"}); } ~MinimumGrad() = default; diff --git a/mindspore/core/utils/anf_utils.h b/mindspore/core/utils/anf_utils.h index ce9dad71d5..a988b27dcf 100644 --- a/mindspore/core/utils/anf_utils.h +++ b/mindspore/core/utils/anf_utils.h @@ -30,7 +30,7 @@ constexpr auto kInfer = "DS_Infer"; constexpr auto kInit = "DS_Init"; constexpr auto kUpdate = "DS_Update"; -class AbstractScope { +class MS_CORE_API AbstractScope { public: explicit AbstractScope(std::recursive_mutex *mu); AbstractScope(const AbstractScope &other) = delete; @@ -43,7 +43,7 @@ class AbstractScope { std::recursive_mutex *mu_; }; -class AnfUtils { +class MS_CORE_API AnfUtils { public: using CustomActorCallback = std::function; static bool IsDimUnknown(const abstract::ShapePtr &shape); diff --git a/mindspore/core/utils/any.h b/mindspore/core/utils/any.h index bf3e413228..e1c4399f04 100644 --- a/mindspore/core/utils/any.h +++ b/mindspore/core/utils/any.h @@ -37,7 +37,7 @@ std::string type(const T &t) { return demangle(typeid(t).name()); } -class Any { +class MS_CORE_API Any { public: // constructors Any() : m_ptr(nullptr), m_tpIndex(std::type_index(typeid(void))) {} diff --git a/mindspore/core/utils/check_convert_utils.h b/mindspore/core/utils/check_convert_utils.h index 2c5b07e97b..fb3f944552 100644 --- a/mindspore/core/utils/check_convert_utils.h +++ b/mindspore/core/utils/check_convert_utils.h @@ -103,7 +103,7 @@ const std::map> kCompareRangeT {kIncludeRight, {"in (", "]"}}, {kIncludeBoth, {"in [", "]"}}}; -class CheckAndConvertUtils { +class MS_CORE_API CheckAndConvertUtils { public: static std::vector CheckPositiveVector(const std::string &arg_name, const std::vector &arg_value, const std::string &prim_name); diff --git a/mindspore/core/utils/crypto.h b/mindspore/core/utils/crypto.h index ec7629c479..df400a67ef 100644 --- a/mindspore/core/utils/crypto.h +++ b/mindspore/core/utils/crypto.h @@ -19,6 +19,7 @@ #include #include +#include "utils/visible.h" typedef unsigned char Byte; namespace mindspore { @@ -26,13 +27,13 @@ constexpr size_t MAX_BLOCK_SIZE = 512 * 1024 * 1024; // Maximum ciphertext segm constexpr size_t RESERVED_BYTE_PER_BLOCK = 50; // Reserved byte per block to save addition info constexpr unsigned int MAGIC_NUM = 0x7F3A5ED8; // Magic number -std::unique_ptr Encrypt(size_t *encrypt_len, const Byte *plain_data, size_t plain_len, const Byte *key, - size_t key_len, const std::string &enc_mode); -std::unique_ptr Decrypt(size_t *decrypt_len, const std::string &encrypt_data_path, const Byte *key, - size_t key_len, const std::string &dec_mode); -std::unique_ptr Decrypt(size_t *decrypt_len, const Byte *model_data, size_t data_size, const Byte *key, - size_t key_len, const std::string &dec_mode); -bool IsCipherFile(const std::string &file_path); -bool IsCipherFile(const Byte *model_data); +MS_CORE_API std::unique_ptr Encrypt(size_t *encrypt_len, const Byte *plain_data, size_t plain_len, + const Byte *key, size_t key_len, const std::string &enc_mode); +MS_CORE_API std::unique_ptr Decrypt(size_t *decrypt_len, const std::string &encrypt_data_path, const Byte *key, + size_t key_len, const std::string &dec_mode); +MS_CORE_API std::unique_ptr Decrypt(size_t *decrypt_len, const Byte *model_data, size_t data_size, + const Byte *key, size_t key_len, const std::string &dec_mode); +MS_CORE_API bool IsCipherFile(const std::string &file_path); +MS_CORE_API bool IsCipherFile(const Byte *model_data); } // namespace mindspore #endif diff --git a/mindspore/core/utils/file_utils.h b/mindspore/core/utils/file_utils.h index 1d357ffc7d..a228b9ad6e 100644 --- a/mindspore/core/utils/file_utils.h +++ b/mindspore/core/utils/file_utils.h @@ -19,9 +19,10 @@ #include #include +#include "utils/visible.h" namespace mindspore { -class FileUtils { +class MS_CORE_API FileUtils { public: FileUtils() = default; ~FileUtils() = default; diff --git a/mindspore/core/utils/info.cc b/mindspore/core/utils/info.cc index 9e82c7530d..a268e597fb 100644 --- a/mindspore/core/utils/info.cc +++ b/mindspore/core/utils/info.cc @@ -26,6 +26,17 @@ #include "utils/file_utils.h" namespace mindspore { +namespace { +/// \brief Trace context stack for current thread. +thread_local std::vector trace_context_stack_; + +/// \brief Record a debug info for print. +thread_local DebugInfoPtr record_debug_info_ = nullptr; + +/// \brief A flag to decide whether record a debug info or not. +thread_local bool record_debug_info_flag_ = false; +} // namespace + std::string HighLightLine(const std::string &line, int col_begin, int col_end, SourceLineTip tip) { std::string temp_line = line; if (col_begin < col_end && col_begin != -1 && col_end <= SizeToLong(temp_line.length()) && @@ -136,6 +147,13 @@ LocationPtr GraphDebugInfo::location() const { void GraphDebugInfo::set_deco_location(const LocationPtr &deco_list_loc) { deco_loc_ = deco_list_loc; } +TraceContextPtr TraceManager::CurrentContextInfo() { + if (!trace_context_stack_.empty()) { + return &trace_context_stack_.back(); + } + return nullptr; +} + void TraceManager::DebugTrace(const std::string &func_name, const LocationPtr &location) { MS_EXCEPTION_IF_NULL(location); (void)trace_context_stack_.emplace_back(location, func_name); @@ -143,9 +161,9 @@ void TraceManager::DebugTrace(const std::string &func_name, const LocationPtr &l void TraceManager::DebugTrace(const LocationPtr &location) { MS_EXCEPTION_IF_NULL(location); - (void)TraceManager::trace_context_stack_.emplace_back(location); + (void)trace_context_stack_.emplace_back(location); if (record_debug_info_flag_) { - TraceManager::record_debug_info_ = std::make_shared(location); + record_debug_info_ = std::make_shared(location); } } @@ -153,9 +171,9 @@ void TraceManager::DebugTrace(const TraceInfoPtr &trace_info) { MS_EXCEPTION_IF_NULL(trace_info); auto &debug_info = trace_info->debug_info(); MS_EXCEPTION_IF_NULL(debug_info); - (void)TraceManager::trace_context_stack_.emplace_back(trace_info); + (void)trace_context_stack_.emplace_back(trace_info); if (record_debug_info_flag_) { - TraceManager::record_debug_info_ = debug_info; + record_debug_info_ = debug_info; } } @@ -164,12 +182,14 @@ void TraceManager::DebugTrace(const DebugInfoPtr &debug_info, const TraceInfoPtr MS_EXCEPTION_IF_NULL(trace_info); auto cloned_info = trace_info->clone(); cloned_info->set_debug_info(debug_info); - (void)TraceManager::trace_context_stack_.emplace_back(cloned_info); + (void)trace_context_stack_.emplace_back(cloned_info); } -DebugInfoPtr TraceManager::record_debug_info() { return TraceManager::record_debug_info_; } +void TraceManager::EndTrace() noexcept { trace_context_stack_.pop_back(); } + +DebugInfoPtr TraceManager::record_debug_info() { return record_debug_info_; } -void TraceManager::ClearParseOrResolveDebugInfo() { TraceManager::record_debug_info_ = nullptr; } +void TraceManager::ClearParseOrResolveDebugInfo() { record_debug_info_ = nullptr; } void TraceManager::CloseRecordDebugInfoFlag() { record_debug_info_flag_ = false; } @@ -177,12 +197,6 @@ void TraceManager::OpenRecordDebugInfoFlag() { record_debug_info_flag_ = true; } bool TraceManager::record_debug_info_flag() { return record_debug_info_flag_; } -thread_local std::vector TraceManager::trace_context_stack_; - -thread_local DebugInfoPtr TraceManager::record_debug_info_ = nullptr; - -thread_local bool TraceManager::record_debug_info_flag_ = false; - LocationPtr GetFirstLocation(const DebugInfoPtr &debug_info) { auto tmp = debug_info; while (tmp != nullptr) { diff --git a/mindspore/core/utils/info.h b/mindspore/core/utils/info.h index 3b3a3fc7dc..b62e18d440 100644 --- a/mindspore/core/utils/info.h +++ b/mindspore/core/utils/info.h @@ -84,12 +84,7 @@ class MS_CORE_API TraceManager { /// \brief Get current trace context. /// /// \return The current trace context. - static TraceContextPtr CurrentContextInfo() { - if (!trace_context_stack_.empty()) { - return &trace_context_stack_.back(); - } - return nullptr; - } + static TraceContextPtr CurrentContextInfo(); /// \brief Debug trace with the given function name and location. /// @@ -114,7 +109,7 @@ class MS_CORE_API TraceManager { static void DebugTrace(const DebugInfoPtr &debug_info, const TraceInfoPtr &trace_info); /// \brief End current debug trace. - static void EndTrace() noexcept { trace_context_stack_.pop_back(); } + static void EndTrace() noexcept; /// \brief Clear debug info for parse or resolve. static void ClearParseOrResolveDebugInfo(); @@ -134,16 +129,6 @@ class MS_CORE_API TraceManager { /// \brief Set the flag to true for recording a debug info. static void OpenRecordDebugInfoFlag(); - - private: - /// \brief Trace context stack for current thread. - thread_local static std::vector trace_context_stack_; - - /// \brief Record a debug info for print. - thread_local static DebugInfoPtr record_debug_info_; - - /// \brief A flag to decide whether record a debug info or not. - thread_local static bool record_debug_info_flag_; }; class TraceGuard { @@ -317,7 +302,7 @@ class MS_CORE_API NodeDebugInfo : public DebugInfo { using NodeDebugInfoPtr = std::shared_ptr; -class GraphDebugInfo : public DebugInfo { +class MS_CORE_API GraphDebugInfo : public DebugInfo { public: GraphDebugInfo() : DebugInfo() { auto top = TraceManager::CurrentContextInfo(); @@ -388,11 +373,11 @@ inline TraceContext::TraceContext(const LocationPtr &loc, const std::string &fun } } -struct DebugInfoCompare { +struct MS_CORE_API DebugInfoCompare { bool operator()(const DebugInfoPtr &left, const DebugInfoPtr &right) const; }; -void UpdateDebugInfo(const FuncGraphPtr &func_graph, const ScopePtr &scope, const DebugInfoPtr &debug_info); +MS_CORE_API void UpdateDebugInfo(const FuncGraphPtr &func_graph, const ScopePtr &scope, const DebugInfoPtr &debug_info); } // namespace mindspore #endif // MINDSPORE_CORE_UTILS_INFO_H_ diff --git a/mindspore/core/utils/interpret_node_recorder.cc b/mindspore/core/utils/interpret_node_recorder.cc new file mode 100644 index 0000000000..e112e047a9 --- /dev/null +++ b/mindspore/core/utils/interpret_node_recorder.cc @@ -0,0 +1,24 @@ +/** + * Copyright 2021 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/interpret_node_recorder.h" + +namespace mindspore { +InterpretNodeRecorder &InterpretNodeRecorder::GetInstance() { + static InterpretNodeRecorder instance; + return instance; +} +} // namespace mindspore diff --git a/mindspore/core/utils/interpret_node_recorder.h b/mindspore/core/utils/interpret_node_recorder.h index fe7813baec..9d3be4b501 100644 --- a/mindspore/core/utils/interpret_node_recorder.h +++ b/mindspore/core/utils/interpret_node_recorder.h @@ -18,18 +18,17 @@ #define MINDSPORE_CORE_UTILS_InterpretNodeRecorder_H_ #include +#include "utils/hash_set.h" +#include "utils/visible.h" namespace mindspore { -class InterpretNodeRecorder { +class MS_CORE_API InterpretNodeRecorder { public: explicit InterpretNodeRecorder(InterpretNodeRecorder &&) = delete; explicit InterpretNodeRecorder(const InterpretNodeRecorder &) = delete; void operator=(const InterpretNodeRecorder &) = delete; void operator=(const InterpretNodeRecorder &&) = delete; - static InterpretNodeRecorder &GetInstance() { - static InterpretNodeRecorder instance; - return instance; - } + static InterpretNodeRecorder &GetInstance(); void PushLineInfo(const std::string &line) { interpret_nodes_lines_.emplace(line); } diff --git a/mindspore/core/utils/label.h b/mindspore/core/utils/label.h index d25dd45792..904f05228c 100644 --- a/mindspore/core/utils/label.h +++ b/mindspore/core/utils/label.h @@ -26,8 +26,8 @@ namespace mindspore { namespace label_manage { enum class TraceLabelType { kShortSymbol, kFullName, kWithUniqueId }; -TraceLabelType GetGlobalTraceLabelType(); -std::string Label(const DebugInfoPtr &debug_info, TraceLabelType trace_type = TraceLabelType::kShortSymbol); +MS_CORE_API TraceLabelType GetGlobalTraceLabelType(); +MS_CORE_API std::string Label(const DebugInfoPtr &debug_info, TraceLabelType trace_type = TraceLabelType::kShortSymbol); } // namespace label_manage } // namespace mindspore diff --git a/mindspore/core/utils/log_adapter.cc b/mindspore/core/utils/log_adapter.cc index 53051f9439..fd5046e327 100644 --- a/mindspore/core/utils/log_adapter.cc +++ b/mindspore/core/utils/log_adapter.cc @@ -115,6 +115,14 @@ static int GetSlogLevel(MsLogLevel level) { } #endif +void LogWriter::set_exception_handler(const ExceptionHandler &exception_handler) { + exception_handler_ = exception_handler; +} + +void LogWriter::set_trace_provider(const TraceProvider &trace_provider) { trace_provider_ = trace_provider; } + +LogWriter::TraceProvider LogWriter::trace_provider() { return trace_provider_; } + void LogWriter::OutputLog(const std::ostringstream &msg) const { #ifdef USE_GLOG #define google mindspore_private @@ -424,9 +432,9 @@ void InitSubModulesLogLevel() { extern "C" { #if defined(_WIN32) || defined(_WIN64) || defined(__APPLE__) #ifdef _MSC_VER -void common_log_init(void) { +MS_CORE_API void common_log_init(void) { #else -__attribute__((constructor)) void common_log_init(void) { +__attribute__((constructor)) MS_CORE_API void common_log_init(void) { #endif #else MS_CORE_API void common_log_init(void) { diff --git a/mindspore/core/utils/log_adapter.h b/mindspore/core/utils/log_adapter.h index 0a9b1c2c13..5fff155911 100644 --- a/mindspore/core/utils/log_adapter.h +++ b/mindspore/core/utils/log_adapter.h @@ -156,6 +156,8 @@ enum SubModuleId : int { /// \return The sub-module name. MS_EXPORT const std::string GetSubModuleName(SubModuleId module_id); +MS_CORE_API void InitSubModulesLogLevel(); + /// \brief Get current time as a string. /// /// \return The string presents current time. @@ -187,7 +189,7 @@ class TryCatchGuard { #endif /// \brief LogWriter defines interface to write log. -class LogWriter { +class MS_CORE_API LogWriter { public: using ExceptionHandler = std::function; using TraceProvider = std::function; @@ -200,18 +202,16 @@ class LogWriter { /// \brief Output log message from the input log stream. /// /// \param[in] stream The input log stream. - MS_CORE_API void operator<(const LogStream &stream) const noexcept; + void operator<(const LogStream &stream) const noexcept; /// \brief Output log message from the input log stream and then throw exception. /// /// \param[in] stream The input log stream. - MS_CORE_API void operator^(const LogStream &stream) const __attribute__((noreturn)); + void operator^(const LogStream &stream) const __attribute__((noreturn)); - static void set_exception_handler(const ExceptionHandler &exception_handler) { - exception_handler_ = exception_handler; - } - static void set_trace_provider(const TraceProvider &trace_provider) { trace_provider_ = trace_provider; } - static TraceProvider trace_provider() { return trace_provider_; } + static void set_exception_handler(const ExceptionHandler &exception_handler); + static void set_trace_provider(const TraceProvider &trace_provider); + static TraceProvider trace_provider(); private: void OutputLog(const std::ostringstream &msg) const; @@ -225,18 +225,20 @@ class LogWriter { inline static TraceProvider trace_provider_ = nullptr; }; -#define MSLOG_IF(level, condition, excp_type) \ - static_cast(0), !(condition) \ - ? void(0) \ - : mindspore::LogWriter(mindspore::LocationInfo(FILE_NAME, __LINE__, __FUNCTION__), level, \ - SUBMODULE_ID, excp_type) < mindspore::LogStream() +#define MSLOG_IF(level, condition, excp_type) \ + !(condition) ? void(0) \ + : mindspore::LogWriter(mindspore::LocationInfo(FILE_NAME, __LINE__, __FUNCTION__), level, 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() -#define IS_OUTPUT_ON(level) \ - ((level) >= mindspore::g_ms_submodule_log_levels[SUBMODULE_ID] && (level) <= mindspore::this_thread_max_log_level) +inline bool IS_OUTPUT_ON(enum MsLogLevel level) { + return (static_cast(level) >= mindspore::g_ms_submodule_log_levels[SUBMODULE_ID] && + static_cast(level) <= static_cast(mindspore::this_thread_max_log_level)); +} #define MS_LOG(level) MS_LOG_##level diff --git a/mindspore/core/utils/misc.h b/mindspore/core/utils/misc.h index bf853ad073..98aed94b5d 100644 --- a/mindspore/core/utils/misc.h +++ b/mindspore/core/utils/misc.h @@ -25,10 +25,10 @@ #include "utils/log_adapter.h" namespace mindspore { -extern const int RET_SUCCESS; -extern const int RET_FAILED; -extern const int RET_CONTINUE; -extern const int RET_BREAK; +MS_CORE_API extern const int RET_SUCCESS; +MS_CORE_API extern const int RET_FAILED; +MS_CORE_API extern const int RET_CONTINUE; +MS_CORE_API extern const int RET_BREAK; /// \brief Demangle the name to make it human reablable. /// diff --git a/mindspore/core/utils/ms_context.cc b/mindspore/core/utils/ms_context.cc index 71f8f2e511..ffa6842229 100644 --- a/mindspore/core/utils/ms_context.cc +++ b/mindspore/core/utils/ms_context.cc @@ -26,6 +26,8 @@ namespace mindspore { std::atomic thread_1_must_end(false); +MsContext::DeviceSeter MsContext::seter_ = nullptr; +MsContext::DeviceTypeSeter MsContext::device_type_seter_ = nullptr; std::shared_ptr MsContext::inst_context_ = nullptr; std::map MsContext::policy_map_ = {{"ge", kMsBackendGePrior}, {"vm", kMsBackendVmOnly}, diff --git a/mindspore/core/utils/ms_context.h b/mindspore/core/utils/ms_context.h index a9e1ddcfec..929d3fb54a 100644 --- a/mindspore/core/utils/ms_context.h +++ b/mindspore/core/utils/ms_context.h @@ -141,7 +141,7 @@ enum MsCtxParam : unsigned { NUM_STRING_PARAMS = MS_CTX_TYPE_STRING_END - MS_CTX_TYPE_STRING_BEGIN }; -class MsContext { +class MS_CORE_API MsContext { public: MsContext(const std::string &backend_policy, const std::string &target); ~MsContext() = default; @@ -183,8 +183,8 @@ class MsContext { } private: - inline static DeviceSeter seter_ = nullptr; - inline static DeviceTypeSeter device_type_seter_ = nullptr; + static DeviceSeter seter_; + static DeviceTypeSeter device_type_seter_; static std::shared_ptr inst_context_; static std::map policy_map_; diff --git a/mindspore/core/utils/ms_exception.cc b/mindspore/core/utils/ms_exception.cc new file mode 100644 index 0000000000..f634d2a667 --- /dev/null +++ b/mindspore/core/utils/ms_exception.cc @@ -0,0 +1,29 @@ +/** + * Copyright 2022 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/ms_exception.h" + +namespace mindspore { +MsException &MsException::Instance() { + static MsException instance; + return instance; +} + +StaticAnalysisException &StaticAnalysisException::Instance() { + static StaticAnalysisException instance; + return instance; +} +} // namespace mindspore diff --git a/mindspore/core/utils/ms_exception.h b/mindspore/core/utils/ms_exception.h index 8ede766717..04a30ec447 100644 --- a/mindspore/core/utils/ms_exception.h +++ b/mindspore/core/utils/ms_exception.h @@ -18,7 +18,9 @@ #define MINDSPORE_CORE_UTILS_MS_EXCEPTION_H_ #include #include +#include #include "utils/ms_utils.h" +#include "utils/visible.h" namespace mindspore { class ExceptionListener { public: @@ -26,12 +28,9 @@ class ExceptionListener { virtual ~ExceptionListener() = default; }; -class MsException { +class MS_CORE_API MsException { public: - static MsException &Instance() { - static MsException instance; - return instance; - } + static MsException &Instance(); void SetException() { exception_ptr_ = std::current_exception(); @@ -60,12 +59,9 @@ class MsException { std::exception_ptr exception_ptr_{nullptr}; }; -class StaticAnalysisException { +class MS_CORE_API StaticAnalysisException { public: - static StaticAnalysisException &Instance() { - static StaticAnalysisException instance; - return instance; - } + static StaticAnalysisException &Instance(); void ClearException() { std::lock_guard lock(lock_); diff --git a/mindspore/core/utils/ms_utils.h b/mindspore/core/utils/ms_utils.h index c99c25cb9e..d869f5d988 100644 --- a/mindspore/core/utils/ms_utils.h +++ b/mindspore/core/utils/ms_utils.h @@ -22,6 +22,7 @@ #include #include #include +#include "utils/visible.h" #define DISABLE_COPY_AND_ASSIGN(ClassType) \ ClassType(const ClassType &) = delete; \ @@ -41,7 +42,7 @@ namespace common { // TODO(lzlang): delete constexpr auto kEnableAscendKernelByKernel = false; inline const char *SafeCStr(const std::string &str) { return str.c_str(); } -const char *SafeCStr(const std::string &&str); +MS_CORE_API const char *SafeCStr(const std::string &&str); static inline std::string GetEnv(const std::string &envvar) { const char *value = std::getenv(envvar.c_str()); diff --git a/mindspore/core/utils/parallel_node_check.h b/mindspore/core/utils/parallel_node_check.h index 86019fa1ef..98c2476324 100644 --- a/mindspore/core/utils/parallel_node_check.h +++ b/mindspore/core/utils/parallel_node_check.h @@ -20,9 +20,9 @@ #include "ir/primitive.h" namespace mindspore { -bool IsInParallelBlackList(const PrimitivePtr &); -bool IsInAllGatherNodeList(const CNodePtr &); -bool IsInTrivialNodeList(const CNodePtr &); -bool IsParallelConsiderCNode(const CNodePtr &); +MS_CORE_API bool IsInParallelBlackList(const PrimitivePtr &); +MS_CORE_API bool IsInAllGatherNodeList(const CNodePtr &); +MS_CORE_API bool IsInTrivialNodeList(const CNodePtr &); +MS_CORE_API bool IsParallelConsiderCNode(const CNodePtr &); } // namespace mindspore #endif // MINDSPORE_CORE_UTILS_PARALLEL_NODE_CHECK_H_ diff --git a/mindspore/core/utils/profile.cc b/mindspore/core/utils/profile.cc index 8b807baac3..0718126097 100644 --- a/mindspore/core/utils/profile.cc +++ b/mindspore/core/utils/profile.cc @@ -288,6 +288,11 @@ ProfTransaction::~ProfTransaction() { ctx_ = nullptr; } +DumpTime &DumpTime::GetInstance() { + static DumpTime instance; + return instance; +} + void DumpTime::Record(const std::string &step_name, const double time, const bool is_start) { file_ss_ << " {" << std::endl; file_ss_ << " \"name\": " diff --git a/mindspore/core/utils/profile.h b/mindspore/core/utils/profile.h index ba8a3c49f8..d302aa749b 100644 --- a/mindspore/core/utils/profile.h +++ b/mindspore/core/utils/profile.h @@ -28,7 +28,7 @@ namespace mindspore { struct TimeInfo; using TimeInfoMap = std::map; -extern double GetTime(); +MS_CORE_API double GetTime(); class ProfileBase; @@ -43,7 +43,7 @@ struct TimeInfo { }; // Utility class for Profile. -class ProfContext { +class MS_CORE_API ProfContext { friend class Profile; friend class ProfileBase; friend class ProfTransaction; @@ -66,7 +66,7 @@ class ProfContext { TimeInfo *time_info_; }; -class ProfileBase { +class MS_CORE_API ProfileBase { friend class ProfContext; friend class ProfTransaction; @@ -85,7 +85,7 @@ class ProfileBase { ProfContext *ctx_ptr_ = nullptr; }; -class Profile : public ProfileBase { +class MS_CORE_API Profile : public ProfileBase { public: Profile() = default; ~Profile() override = default; @@ -98,7 +98,7 @@ class Profile : public ProfileBase { void Pop(void) noexcept override; }; -class ProfTransaction { +class MS_CORE_API ProfTransaction { public: explicit ProfTransaction(const ProfileBase *prof); explicit ProfTransaction(ProfContext *const ctx) : ctx_(ctx) {} @@ -131,7 +131,7 @@ class NoProfTransaction { } }; -class DumpTime { +class MS_CORE_API DumpTime { public: ~DumpTime() { try { @@ -144,10 +144,7 @@ class DumpTime { } DumpTime(const DumpTime &) = delete; DumpTime &operator=(const DumpTime &) = delete; - static DumpTime &GetInstance() { - static DumpTime instance; - return instance; - } + static DumpTime &GetInstance(); void set_file_path(const std::string &save_path) { file_path_ = save_path; } void Record(const std::string &name, const double time, const bool is_start); void Save(); @@ -181,7 +178,7 @@ struct TimeStat { int count_; }; -class MsProfile { +class MS_CORE_API MsProfile { public: ~MsProfile() { Clear(); } diff --git a/mindspore/core/utils/system/crc32c.h b/mindspore/core/utils/system/crc32c.h index 40f57da2d2..774a39f5c0 100644 --- a/mindspore/core/utils/system/crc32c.h +++ b/mindspore/core/utils/system/crc32c.h @@ -33,7 +33,7 @@ static constexpr uint32 kMaskDelta = 0xa282ead8ul; static const int kRightShift = 15; static const int kLeftShift = (32 - kRightShift); // Provide the Crc32c function -class Crc32c { +class MS_CORE_API Crc32c { public: Crc32c() = default; ~Crc32c() = default; diff --git a/mindspore/core/utils/system/file_system.h b/mindspore/core/utils/system/file_system.h index 5879e28966..7f18f047fe 100644 --- a/mindspore/core/utils/system/file_system.h +++ b/mindspore/core/utils/system/file_system.h @@ -94,7 +94,7 @@ class WriteFile { #if defined(SYSTEM_ENV_POSIX) // File system of create or delete directory for posix system -class PosixFileSystem : public FileSystem { +class MS_CORE_API PosixFileSystem : public FileSystem { public: PosixFileSystem() = default; @@ -200,7 +200,7 @@ class PosixWriteFile : public WriteFile { #if defined(SYSTEM_ENV_WINDOWS) // File system of create or delete directory for windows system -class WinFileSystem : public FileSystem { +class MS_CORE_API WinFileSystem : public FileSystem { public: WinFileSystem() = default; diff --git a/mindspore/core/utils/system/sha256.h b/mindspore/core/utils/system/sha256.h index c9122be71e..c88c977716 100644 --- a/mindspore/core/utils/system/sha256.h +++ b/mindspore/core/utils/system/sha256.h @@ -18,6 +18,7 @@ #define MINDSPORE_CORE_UTILS_SYSTEM_SHA256_H_ #include +#include "utils/visible.h" namespace mindspore { namespace system { @@ -41,7 +42,7 @@ std::string Encrypt(const std::string &message); std::string GetHashFromString(const std::string &data); -std::string GetHashFromFile(const std::string &path); +MS_CORE_API std::string GetHashFromFile(const std::string &path); #ifndef _WIN32 std::string GetHashFromDir(const std::string &dir); diff --git a/mindspore/core/utils/tensor_construct_utils.h b/mindspore/core/utils/tensor_construct_utils.h index 33b1527173..aa65415509 100644 --- a/mindspore/core/utils/tensor_construct_utils.h +++ b/mindspore/core/utils/tensor_construct_utils.h @@ -27,7 +27,7 @@ void SetTensorData(void *data, T num, size_t data_length) { MS_EXCEPTION_IF_NULL(tensor_data); std::fill(tensor_data, tensor_data + data_length, num); } -class TensorConstructUtils { +class MS_CORE_API TensorConstructUtils { public: static tensor::TensorPtr CreateZerosTensor(const TypePtr &type, const std::vector &shape); static tensor::TensorPtr CreateOnesTensor(const TypePtr &type, const std::vector &shape); diff --git a/mindspore/core/utils/trace_base.h b/mindspore/core/utils/trace_base.h index ed41daaf18..ad9c97dfbd 100644 --- a/mindspore/core/utils/trace_base.h +++ b/mindspore/core/utils/trace_base.h @@ -32,14 +32,14 @@ namespace mindspore { namespace trace { constexpr auto kSectionPrefix = " - "; -std::string GetDebugInfo(const DebugInfoPtr &info, SourceLineTip tip = kSourceLineTipNextLine); -std::string GetDebugInfo(const DebugInfoPtr &info, const std::string &prefix, - SourceLineTip tip = kSourceLineTipNextLine); +MS_CORE_API std::string GetDebugInfo(const DebugInfoPtr &info, SourceLineTip tip = kSourceLineTipNextLine); +MS_CORE_API std::string GetDebugInfo(const DebugInfoPtr &info, const std::string &prefix, + SourceLineTip tip = kSourceLineTipNextLine); // Generate the call stack of python source code to a string -std::string DumpSourceLines(const AnfNodePtr &node); -std::string DumpSourceLines(AnfNode *node); +MS_CORE_API std::string DumpSourceLines(const AnfNodePtr &node); +MS_CORE_API std::string DumpSourceLines(AnfNode *node); // Generate the call stack of python source code to a vector -std::vector GetSourceLineList(const AnfNodePtr &node); +MS_CORE_API std::vector GetSourceLineList(const AnfNodePtr &node); // Get the locations of the call stack of python source code std::vector GetSourceLocationList(const AnfNodePtr &node); // Generate the call stack of python source code with relevant trace info diff --git a/mindspore/core/utils/visible.h b/mindspore/core/utils/visible.h index f12a6a1436..c4d7d5410b 100644 --- a/mindspore/core/utils/visible.h +++ b/mindspore/core/utils/visible.h @@ -31,5 +31,4 @@ #define MS_EXPORT __attribute__((visibility("default"))) #define MS_LOCAL __attribute__((visibility("hidden"))) #endif - #endif // MINDSPORE_CORE_UTILS_VISIBLE_H_ diff --git a/mindspore/lite/tools/converter/CMakeLists.txt b/mindspore/lite/tools/converter/CMakeLists.txt index 31715b542a..c6f0b68751 100644 --- a/mindspore/lite/tools/converter/CMakeLists.txt +++ b/mindspore/lite/tools/converter/CMakeLists.txt @@ -1,5 +1,6 @@ add_definitions(-DPRIMITIVE_WRITEABLE) add_definitions(-DUSE_GLOG) +set(USE_GLOG on) set(SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../src) @@ -233,7 +234,7 @@ target_link_libraries(converter_lite PRIVATE proto_mid ${SECUREC_LIBRARY} mindspore::json - -Wl,--whole-archive mindspore_core -Wl,--no-whole-archive + mindspore_core mslite_converter_plugin mindspore::glog mindspore::protobuf diff --git a/tests/st/cpp/CMakeLists.txt b/tests/st/cpp/CMakeLists.txt index 5ae2a78782..019cdde3d1 100644 --- a/tests/st/cpp/CMakeLists.txt +++ b/tests/st/cpp/CMakeLists.txt @@ -14,5 +14,6 @@ endif() file(GLOB_RECURSE CXX_ST_SRC RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cc) add_executable(st_tests ${CXX_ST_SRC}) target_link_libraries(st_tests PRIVATE mindspore_shared_lib _c_dataengine mindspore::gtest) +target_link_options(st_tests PRIVATE -Wl,--unresolved-symbols=ignore-all) set_target_properties(st_tests PROPERTIES SKIP_BUILD_RPATH TRUE RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) file(COPY ${gtest_LIBPATH}/libgtest${CMAKE_SHARED_LIBRARY_SUFFIX} DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}) \ No newline at end of file diff --git a/tests/ut/cpp/CMakeLists.txt b/tests/ut/cpp/CMakeLists.txt index 855a32adf9..a327c8d4ab 100644 --- a/tests/ut/cpp/CMakeLists.txt +++ b/tests/ut/cpp/CMakeLists.txt @@ -52,7 +52,6 @@ if(ENABLE_MINDDATA) ./base/*.cc ./dataset/*.cc ./ir/dtype/*.cc - ${CMAKE_SOURCE_DIR}/mindspore/ccsrc/minddata/dataset/kernels/image/lite_cv/*.cc ./device/*.cc ./ir/*.cc ./kernel/*.cc @@ -169,7 +168,6 @@ file(GLOB_RECURSE MINDSPORE_SRC_LIST RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "../../../mindspore/ccsrc/backend/session/kernel_graph.cc" "../../../mindspore/ccsrc/backend/session/session_basic.cc" "../../../mindspore/ccsrc/backend/session/executor.cc" - "../../../mindspore/core/ops/*.cc" "../../../mindspore/ccsrc/backend/session/executor_manager.cc" "../../../mindspore/ccsrc/backend/session/session_factory.cc" "../../../mindspore/ccsrc/backend/session/kernel_build_client.cc" @@ -191,12 +189,6 @@ file(GLOB_RECURSE MINDSPORE_SRC_LIST RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "../../../mindspore/ccsrc/backend/kernel_compiler/aicpu/aicpu_util.cc" ) -if(ENABLE_SECURITY) - file(GLOB_RECURSE _INFER_SUMMARY_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} - "../../../mindspore/core/ops/*_summary.cc" - ) - list(REMOVE_ITEM MINDSPORE_SRC_LIST ${_INFER_SUMMARY_FILES}) -endif() list(REMOVE_ITEM MINDSPORE_SRC_LIST "../../../mindspore/ccsrc/frontend/parallel/strategy_checkpoint/parallel_strategy_checkpoint.cc") list(REMOVE_ITEM MINDSPORE_SRC_LIST "../../../mindspore/ccsrc/ps/util.cc") @@ -238,8 +230,13 @@ add_library(_ut_mindspore_obj OBJECT ${MINDSPORE_SRC_LIST}) add_library(_ut_ut_obj OBJECT ${UT_SRCS}) add_dependencies(_ut_mindspore_obj graph) add_dependencies(_ut_ut_obj engine-cache-server graph) -add_executable(ut_tests $ - $) +set(ut_objects $ $ + $ $ $ + $ $) +if(ENABLE_MINDDATA) + set(ut_objects ${ut_objects} ${dataengine_submodules} $) +endif() +add_executable(ut_tests ${ut_objects}) include_directories("${CMAKE_BINARY_DIR}/backend/kernel_compiler/aicpu") file(GLOB_RECURSE PROTO_IN RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} @@ -266,21 +263,18 @@ endif() if(CMAKE_SYSTEM_NAME MATCHES "Linux") target_link_libraries(ut_tests PRIVATE mindspore::gtest mindspore::event mindspore::event_pthreads - mindspore::event_openssl mindspore_gvar ${PYTHON_LIBRARIES} pthread util dl) + mindspore::event_openssl ${PYTHON_LIBRARIES} pthread util dl) if(ENABLE_MINDDATA) - - # AUX_SOURCE_DIRECTORY(LITE_CV_FILES) - # message(STATUS "xxxxxxxxxxxxxxxxx"${LITE_CV_FILES} ) - # add_library(_live_cv OBJECT ${LITE_CV_FILES}) - - target_link_libraries(ut_tests PRIVATE _c_dataengine _c_mindrecord) + target_link_libraries(ut_tests PRIVATE mindspore::sqlite mindspore::jpeg_turbo mindspore::turbojpeg + mindspore::opencv_core mindspore::opencv_imgcodecs mindspore::opencv_imgproc mindspore::tinyxml2 + mindspore::sentencepiece mindspore::sentencepiece_train mindspore::icuuc mindspore::icudata + mindspore::icui18n) endif() else() - target_link_libraries(ut_tests PRIVATE mindspore::gtest mindspore_gvar ${PYTHON_LIBRARIES}) + target_link_libraries(ut_tests PRIVATE mindspore::gtest ${PYTHON_LIBRARIES}) endif() if(USE_GLOG) target_link_libraries(ut_tests PRIVATE mindspore::glog) endif() -target_link_libraries(mindspore mindspore_core) -target_link_libraries(ut_tests PRIVATE mindspore mindspore_shared_lib securec graph error_manager) +target_link_libraries(ut_tests PRIVATE mindspore securec graph error_manager) diff --git a/tests/ut/cpp/common/test_main.cc b/tests/ut/cpp/common/test_main.cc index fa456ed260..fc26b77b6f 100644 --- a/tests/ut/cpp/common/test_main.cc +++ b/tests/ut/cpp/common/test_main.cc @@ -19,12 +19,12 @@ #include "pipeline/jit/pipeline.h" #include "pipeline/jit/resource.h" -namespace mindspore { - extern void InitSubModulesLogLevel(); +extern "C" { +void common_log_init(void); } GTEST_API_ int main(int argc, char** argv) { - mindspore::InitSubModulesLogLevel(); + common_log_init(); testing::InitGoogleTest(&argc, argv); int ret = RUN_ALL_TESTS(); mindspore::pipeline::ClearResAtexit(); diff --git a/tests/ut/cpp/cxx_api/serialization_test.cc b/tests/ut/cpp/cxx_api/serialization_test.cc index d3dc8b9a6e..01f1cc70fa 100644 --- a/tests/ut/cpp/cxx_api/serialization_test.cc +++ b/tests/ut/cpp/cxx_api/serialization_test.cc @@ -90,12 +90,6 @@ TEST_F(TestCxxApiSerialization, test_load_no_encrpty_mindir_x1_SUCCESS) { ModelType::kMindIR, &graphs) == kSuccess); } -TEST_F(TestCxxApiSerialization, test_load_no_encrpty_mindir_x2_SUCCESS) { - std::vector graphs; - ASSERT_TRUE(Serialization::Load(std::vector(2, "./data/mindir/add_no_encrpty.mindir"), - ModelType::kMindIR, &graphs) == kSuccess); -} - TEST_F(TestCxxApiSerialization, test_load_file_not_exist_x2_FAILED) { std::vector graphs; auto status = Serialization::Load(std::vector(2, "./data/mindir/file_not_exist.mindir"), @@ -104,13 +98,4 @@ TEST_F(TestCxxApiSerialization, test_load_file_not_exist_x2_FAILED) { auto err_mst = status.GetErrDescription(); ASSERT_TRUE(err_mst.find("exist") != std::string::npos); } - -TEST_F(TestCxxApiSerialization, test_load_encrpty_mindir_without_key_x2_FAILED) { - std::vector graphs; - auto status = Serialization::Load( - std::vector(2, "./data/mindir/add_encrpty_key_0123456789ABCDEF.mindir"), ModelType::kMindIR, &graphs); - ASSERT_TRUE(status != kSuccess); - auto err_mst = status.GetErrDescription(); - ASSERT_TRUE(err_mst.find("be encrypted") != std::string::npos); -} } // namespace mindspore diff --git a/tests/ut/python/mindir/test_mindir_export_larger_than_2g.py b/tests/ut/python/mindir/test_mindir_export_larger_than_2g.py index 5f8ba50c32..c6f3a6643d 100644 --- a/tests/ut/python/mindir/test_mindir_export_larger_than_2g.py +++ b/tests/ut/python/mindir/test_mindir_export_larger_than_2g.py @@ -24,6 +24,7 @@ import numpy as np import mindspore as ms import mindspore.nn as nn import mindspore.ops as ops +from mindspore import context from mindspore import Parameter from mindspore.common.tensor import Tensor from mindspore.train.serialization import export, load @@ -63,6 +64,7 @@ def test_mindir_export_split(): Description: MindIR Export model is exceed TOTAL_SAVE should be split save as model file and data file Expectation: No exception. """ + context.set_context(mode=context.PYNATIVE_MODE) ms.train.serialization.TOTAL_SAVE = 0 class Net(nn.Cell): @@ -124,6 +126,7 @@ def test_mindir_export_larger_parameter_exceed_1t_mock(): it will be split to another file named data_0,data_1,data_2... Expectation: No exception. """ + context.set_context(mode=context.PYNATIVE_MODE) ms.train.serialization.TOTAL_SAVE = 0 ms.train.serialization.PARAMETER_SPLIT_SIZE = 129 / 1024 diff --git a/tests/ut/python/optimizer/test_bprop_mindir.py b/tests/ut/python/optimizer/test_bprop_mindir.py index 0b1690ff2c..640d7e8918 100644 --- a/tests/ut/python/optimizer/test_bprop_mindir.py +++ b/tests/ut/python/optimizer/test_bprop_mindir.py @@ -17,6 +17,7 @@ import numpy as np import mindspore.nn as nn +from mindspore import context from mindspore import Tensor, Parameter from mindspore.ops import operations as P import mindspore.ops.functional as F @@ -455,9 +456,6 @@ def test_stop_gradient(): """ class StopGradientNet(nn.Cell): - def __init__(self): - super(StopGradientNet, self).__init__() - def construct(self, x, y): c = x * y c_s = F.stop_gradient(c) @@ -476,11 +474,8 @@ def test_switch(): Description: Compile the backward graph for the switch op. Expectation: Load the bprop mindir successfully. """ - + context.set_context(mode=context.PYNATIVE_MODE) class SwitchNet(nn.Cell): - def __init__(self): - super(SwitchNet, self).__init__() - def construct(self, x, y): if x > y: return x diff --git a/tests/ut/python/optimizer/test_optimizer_with_loss_scale.py b/tests/ut/python/optimizer/test_optimizer_with_loss_scale.py index 7ecdb8892b..fbc8454c8c 100644 --- a/tests/ut/python/optimizer/test_optimizer_with_loss_scale.py +++ b/tests/ut/python/optimizer/test_optimizer_with_loss_scale.py @@ -28,9 +28,6 @@ from mindspore.train import Model from mindspore.train.loss_scale_manager import FixedLossScaleManager, DynamicLossScaleManager from ....dataset_mock import MindData -context.set_context(mode=context.GRAPH_MODE) - - class MindDataSet(MindData): def __init__(self, dataset_types, dataset_shapes): super(MindDataSet, self).__init__(size=2, batch_size=32, @@ -98,6 +95,7 @@ class MSELoss(nn.Cell): def test_momentum_compile(): + context.set_context(mode=context.GRAPH_MODE) inputs = Tensor(np.ones([15, 1]).astype(np.float32)) label = Tensor(np.zeros([15, 1]).astype(np.float32)) net = Net(1, 1) @@ -114,6 +112,7 @@ def test_momentum_compile(): def test_compile_fp16_not_overflow(): + context.set_context(mode=context.GRAPH_MODE) inputs = Tensor(np.ones([16, 16]).astype(np.float32)) label = Tensor(np.zeros([16, 16]).astype(np.float32)) net = NetFP16(16, 16) @@ -130,6 +129,7 @@ def test_compile_fp16_not_overflow(): def test_compile_fp16_lr_overflow(): + context.set_context(mode=context.GRAPH_MODE) inputs = Tensor(np.ones([16, 16]).astype(np.float32)) label = Tensor(np.zeros([16, 16]).astype(np.float32)) lr = Tensor(np.ones([1], np.float32) * 0.1) @@ -147,6 +147,7 @@ def test_compile_fp16_lr_overflow(): def test_compile_fp16_overflow(): + context.set_context(mode=context.GRAPH_MODE) inputs = Tensor(np.ones([16, 16]).astype(np.float32)) label = Tensor(np.zeros([16, 16]).astype(np.float32)) net = NetFP16(16, 16) @@ -163,6 +164,7 @@ def test_compile_fp16_overflow(): def test_compile_fp16_lr_overflow_with_lossscale_update(): + context.set_context(mode=context.GRAPH_MODE) inputs = Tensor(np.ones([16, 16]).astype(np.float32)) label = Tensor(np.zeros([16, 16]).astype(np.float32)) lr = Tensor(np.ones([1], np.float32) * 0.1) @@ -180,6 +182,7 @@ def test_compile_fp16_lr_overflow_with_lossscale_update(): def test_compile_f16_model_train(): + context.set_context(mode=context.GRAPH_MODE) dataset_types = (np.float32, np.float32) dataset_shapes = ((16, 16), (16, 16)) @@ -194,6 +197,7 @@ def test_compile_f16_model_train(): def test_compile_f16_model_train_fixed(): + context.set_context(mode=context.GRAPH_MODE) context.set_context(device_target='Ascend') dataset_types = (np.float32, np.float32) dataset_shapes = ((16, 16), (16, 16)) @@ -209,6 +213,7 @@ def test_compile_f16_model_train_fixed(): def test_compile_fp16_lr_overflow_fixed_feed(): + context.set_context(mode=context.GRAPH_MODE) inputs = Tensor(np.ones([16, 16]).astype(np.float32)) label = Tensor(np.zeros([16, 16]).astype(np.float32)) lr = Tensor(np.ones([1], np.float32) * 0.1) @@ -226,6 +231,7 @@ def test_compile_fp16_lr_overflow_fixed_feed(): def test_compile_fp16_lr_overflow_dynamic_feed(): + context.set_context(mode=context.GRAPH_MODE) inputs = Tensor(np.ones([16, 16]).astype(np.float32)) label = Tensor(np.zeros([16, 16]).astype(np.float32)) lr = Tensor(np.ones([1], np.float32) * 0.1) @@ -243,6 +249,7 @@ def test_compile_fp16_lr_overflow_dynamic_feed(): def test_compile_fp16_lr_overflow_fixed_graph(): + context.set_context(mode=context.GRAPH_MODE) inputs = Tensor(np.ones([16, 16]).astype(np.float32)) label = Tensor(np.zeros([16, 16]).astype(np.float32)) lr = Tensor(np.ones([1], np.float32) * 0.1) @@ -260,6 +267,7 @@ def test_compile_fp16_lr_overflow_fixed_graph(): def test_compile_fp16_lr_overflow_dynamic_graph(): + context.set_context(mode=context.GRAPH_MODE) inputs = Tensor(np.ones([16, 16]).astype(np.float32)) label = Tensor(np.zeros([16, 16]).astype(np.float32)) lr = Tensor(np.ones([1], np.float32) * 0.1) @@ -277,6 +285,7 @@ def test_compile_fp16_lr_overflow_dynamic_graph(): def adam_compile(loss_scale=1.0): + context.set_context(mode=context.GRAPH_MODE) inputs = Tensor(np.ones([15, 1]).astype(np.float32)) label = Tensor(np.zeros([15, 1]).astype(np.float32)) net = Net(1, 1) @@ -294,9 +303,11 @@ def adam_compile(loss_scale=1.0): def test_adam_compile(): + context.set_context(mode=context.GRAPH_MODE) adam_compile() def test_adam_loss_scale_compile(): """ test setting loss_scale to 1e-40 """ + context.set_context(mode=context.GRAPH_MODE) adam_compile(loss_scale=1e-40) diff --git a/tests/ut/python/optimizer/test_recompute.py b/tests/ut/python/optimizer/test_recompute.py index 698ae019d9..8811fd30bd 100644 --- a/tests/ut/python/optimizer/test_recompute.py +++ b/tests/ut/python/optimizer/test_recompute.py @@ -17,10 +17,8 @@ import pytest import mindspore.context as context import mindspore.nn as nn -context.set_context(mode=context.GRAPH_MODE) recompute_prefix = 'recompute_' - class Net(nn.Cell): def __init__(self): super(Net, self).__init__() @@ -32,21 +30,25 @@ class Net(nn.Cell): def test_set_recompute_true(): + context.set_context(mode=context.GRAPH_MODE) net = Net() net.pool.recompute() assert net.pool.get_scope() == recompute_prefix def test_set_recompute_true_with_mp_comm_recompute(): + context.set_context(mode=context.GRAPH_MODE) net = Net() net.pool.recompute(mp_comm_recompute=True) assert net.pool.get_scope() == recompute_prefix def test_set_recompute_true_with_mp_comm_recompute_false(): + context.set_context(mode=context.GRAPH_MODE) net = Net() net.pool.recompute(mp_comm_recompute=False) assert net.pool.get_scope() == recompute_prefix def test_set_recompute_true_twice(): + context.set_context(mode=context.GRAPH_MODE) net = Net() net.pool.recompute() with pytest.raises(RuntimeError): diff --git a/tests/ut/python/optimizer/test_tile_eliminate.py b/tests/ut/python/optimizer/test_tile_eliminate.py index b398bbc33c..c4a29e13bb 100644 --- a/tests/ut/python/optimizer/test_tile_eliminate.py +++ b/tests/ut/python/optimizer/test_tile_eliminate.py @@ -1,4 +1,5 @@ import numpy as np +from mindspore import context from mindspore import ms_function, ops, Tensor, dtype @@ -14,6 +15,7 @@ def test_tile_eliminate(): Description: All value of multiplier is '1' but length of multiplier is greater than tensor dims, can't do eliminate Expectation: success """ + context.set_context(mode=context.PYNATIVE_MODE) tensor_ = Tensor(np.ndarray([1, 448, 448]), dtype=dtype.float32) out = ops.tile(tensor_, (1, 1, 1)) assert out.shape == (1, 448, 448) diff --git a/tests/ut/python/optimizer/test_while_ScatterNdUpdate.py b/tests/ut/python/optimizer/test_while_ScatterNdUpdate.py index 147efc374f..abb29af9fb 100644 --- a/tests/ut/python/optimizer/test_while_ScatterNdUpdate.py +++ b/tests/ut/python/optimizer/test_while_ScatterNdUpdate.py @@ -17,9 +17,6 @@ from mindspore import context, nn, Tensor, Parameter from mindspore.common import dtype as mstype from mindspore.ops import operations as P - -context.set_context(mode=context.GRAPH_MODE) - class Net(nn.Cell): def __init__(self, data): super(Net, self).__init__() @@ -40,6 +37,7 @@ class Net(nn.Cell): def test_x(): + context.set_context(mode=context.GRAPH_MODE) x = Tensor(np.arange(10 * 2 * 3).reshape(10, 2, 3).astype(np.float32)) net = Net(x) net(x) diff --git a/tests/ut/python/pipeline/parse/test_debug_info.py b/tests/ut/python/pipeline/parse/test_debug_info.py index 6d55326ce4..1d769b55ac 100644 --- a/tests/ut/python/pipeline/parse/test_debug_info.py +++ b/tests/ut/python/pipeline/parse/test_debug_info.py @@ -52,6 +52,7 @@ def test_ms_function(): result = find_files("./ir_dump_path/*validate*.ir", "test_debug_info.py(46)/ return x + 1/") assert result == '2' remove_path("./ir_dump_path/") + context.set_context(save_graphs=False) @security_off_wrap @@ -67,9 +68,10 @@ def test_cell_ms_function(): input1 = np.random.randn(5, 5) net = Net() net(Tensor(input1, ms.float32)) - result = find_files("./ir_dump_path/*validate*.ir", "test_debug_info.py(63)/ return x/") + result = find_files("./ir_dump_path/*validate*.ir", "test_debug_info.py(64)/ return x/") assert result == '1' remove_path("./ir_dump_path/") + context.set_context(save_graphs=False) def test_parse_slice_location(): diff --git a/tests/ut/python/utils/test_serialize.py b/tests/ut/python/utils/test_serialize.py index 777ba51927..13907ae9c7 100644 --- a/tests/ut/python/utils/test_serialize.py +++ b/tests/ut/python/utils/test_serialize.py @@ -37,9 +37,6 @@ from mindspore.train.serialization import save_checkpoint, load_checkpoint, load from tests.security_utils import security_off_wrap from ..ut_filter import non_graph_engine -context.set_context(mode=context.GRAPH_MODE, print_file_path="print/print.pb") - - class Net(nn.Cell): """Net definition.""" @@ -74,7 +71,7 @@ def setup_module(): def test_save_graph(): """ test_exec_save_graph """ - + context.set_context(mode=context.GRAPH_MODE, print_file_path="print/print.pb") class Net1(nn.Cell): def __init__(self): super(Net1, self).__init__() @@ -100,6 +97,7 @@ def test_save_graph(): def test_save_checkpoint_for_list(): """ test save_checkpoint for list""" + context.set_context(mode=context.GRAPH_MODE, print_file_path="print/print.pb") parameter_list = [] one_param = {} param1 = {} @@ -128,6 +126,7 @@ def test_load_checkpoint_error_filename(): Description: Load checkpoint with error filename. Expectation: Raise value error for error filename. """ + context.set_context(mode=context.GRAPH_MODE, print_file_path="print/print.pb") ckpt_file_name = 1 with pytest.raises(ValueError): load_checkpoint(ckpt_file_name) @@ -139,6 +138,7 @@ def test_save_checkpoint_for_list_append_info_and_load_checkpoint(): Description: Save checkpoint for list append info and load checkpoint with list append info. Expectation: Checkpoint for list append info can be saved and reloaded. """ + context.set_context(mode=context.GRAPH_MODE, print_file_path="print/print.pb") parameter_list = [] one_param = {} param1 = {} @@ -170,6 +170,7 @@ def test_save_checkpoint_for_list_append_info_and_load_checkpoint(): def test_checkpoint_manager(): """ test_checkpoint_manager """ + context.set_context(mode=context.GRAPH_MODE, print_file_path="print/print.pb") ckp_mgr = _CheckpointManager() ckpt_file_name = os.path.join(_cur_dir, './test-1_1.ckpt') @@ -218,6 +219,7 @@ def test_checkpoint_manager(): def test_load_param_into_net_error_net(): + context.set_context(mode=context.GRAPH_MODE, print_file_path="print/print.pb") parameter_dict = {} one_param = Parameter(Tensor(np.ones(shape=(64, 3, 7, 7)), dtype=mstype.float32), name="conv1.weight") @@ -227,12 +229,14 @@ def test_load_param_into_net_error_net(): def test_load_param_into_net_error_dict(): + context.set_context(mode=context.GRAPH_MODE, print_file_path="print/print.pb") net = Net(10) with pytest.raises(TypeError): load_param_into_net(net, '') def test_load_param_into_net_erro_dict_param(): + context.set_context(mode=context.GRAPH_MODE, print_file_path="print/print.pb") net = Net(10) net.init_parameters_data() assert net.conv1.weight.data.asnumpy()[0][0][0][0] == 0 @@ -246,6 +250,7 @@ def test_load_param_into_net_erro_dict_param(): def test_load_param_into_net_has_more_param(): """ test_load_param_into_net_has_more_param """ + context.set_context(mode=context.GRAPH_MODE, print_file_path="print/print.pb") net = Net(10) net.init_parameters_data() assert net.conv1.weight.data.asnumpy()[0][0][0][0] == 0 @@ -262,6 +267,7 @@ def test_load_param_into_net_has_more_param(): def test_load_param_into_net_param_type_and_shape_error(): + context.set_context(mode=context.GRAPH_MODE, print_file_path="print/print.pb") net = Net(10) net.init_parameters_data() assert net.conv1.weight.data.asnumpy()[0][0][0][0] == 0 @@ -274,6 +280,7 @@ def test_load_param_into_net_param_type_and_shape_error(): def test_load_param_into_net_param_type_error(): + context.set_context(mode=context.GRAPH_MODE, print_file_path="print/print.pb") net = Net(10) net.init_parameters_data() assert net.conv1.weight.data.asnumpy()[0][0][0][0] == 0 @@ -287,6 +294,7 @@ def test_load_param_into_net_param_type_error(): def test_load_param_into_net_param_shape_error(): + context.set_context(mode=context.GRAPH_MODE, print_file_path="print/print.pb") net = Net(10) net.init_parameters_data() assert net.conv1.weight.data.asnumpy()[0][0][0][0] == 0 @@ -300,6 +308,7 @@ def test_load_param_into_net_param_shape_error(): def test_load_param_into_net(): + context.set_context(mode=context.GRAPH_MODE, print_file_path="print/print.pb") net = Net(10) net.init_parameters_data() assert net.conv1.weight.data.asnumpy()[0][0][0][0] == 0 @@ -314,6 +323,7 @@ def test_load_param_into_net(): def test_save_checkpoint_for_network(): """ test save_checkpoint for network""" + context.set_context(mode=context.GRAPH_MODE, print_file_path="print/print.pb") net = Net() loss = SoftmaxCrossEntropyWithLogits(sparse=True) opt = Momentum(net.trainable_params(), 0.0, 0.9, 0.0001, 1024) @@ -326,6 +336,7 @@ def test_save_checkpoint_for_network(): def test_load_checkpoint_empty_file(): + context.set_context(mode=context.GRAPH_MODE, print_file_path="print/print.pb") os.mknod("empty.ckpt") with pytest.raises(ValueError): load_checkpoint("empty.ckpt") @@ -333,6 +344,7 @@ def test_load_checkpoint_empty_file(): def test_save_and_load_checkpoint_for_network_with_encryption(): """ test save and checkpoint for network with encryption""" + context.set_context(mode=context.GRAPH_MODE, print_file_path="print/print.pb") net = Net() loss = SoftmaxCrossEntropyWithLogits(sparse=True) opt = Momentum(net.trainable_params(), 0.0, 0.9, 0.0001, 1024) @@ -377,6 +389,7 @@ class MYNET(nn.Cell): @non_graph_engine def test_export(): + context.set_context(mode=context.GRAPH_MODE, print_file_path="print/print.pb") net = MYNET() input_data = Tensor(np.random.randint(0, 255, [1, 3, 224, 224]).astype(np.float32)) with pytest.raises(ValueError): @@ -385,6 +398,7 @@ def test_export(): @non_graph_engine def test_mindir_export(): + context.set_context(mode=context.GRAPH_MODE, print_file_path="print/print.pb") net = MYNET() input_data = Tensor(np.random.randint(0, 255, [1, 3, 224, 224]).astype(np.float32)) export(net, input_data, file_name="./me_binary_export", file_format="MINDIR") @@ -392,6 +406,7 @@ def test_mindir_export(): @non_graph_engine def test_mindir_export_and_load_with_encryption(): + context.set_context(mode=context.GRAPH_MODE, print_file_path="print/print.pb") net = MYNET() input_data = Tensor(np.random.randint(0, 255, [1, 3, 224, 224]).astype(np.float32)) key = secrets.token_bytes(16) @@ -427,6 +442,7 @@ class PrintNet(nn.Cell): @security_off_wrap def test_print(): + context.set_context(mode=context.GRAPH_MODE, print_file_path="print/print.pb") print_net = PrintNet() int8 = Tensor(np.random.randint(100, size=(10, 10), dtype="int8")) uint8 = Tensor(np.random.randint(100, size=(10, 10), dtype="uint8"))