From 836f0355aca5253b1df857d3fc3b708e738bf76e Mon Sep 17 00:00:00 2001 From: zhoufeng Date: Thu, 2 Feb 2023 15:45:43 +0800 Subject: [PATCH] fix windows gpu Signed-off-by: zhoufeng --- cmake/package_win.cmake | 3 +- mindspore/ccsrc/kernel/CMakeLists.txt | 1 + .../kernel_factory.cc} | 20 ++++++++++--- .../kernel_factory.h} | 29 ++++++++++++------- .../ascend/kernel/bisheng/CMakeLists.txt | 2 +- .../kernel/bisheng/add_bisheng_kernel.cc | 1 - .../kernel/bisheng/bisheng_kernel_build.cc | 6 ++-- .../ascend/kernel/bisheng/bisheng_op_info.h | 7 +++-- mindspore/ccsrc/plugin/factory/ms_factory.h | 19 +++++++----- .../hardware/device_context_manager.cc | 2 +- mindspore/lite/src/extendrt/CMakeLists.txt | 1 + mindspore/lite/tools/converter/CMakeLists.txt | 1 + .../mindspore/run_check/_check_version.py | 12 ++++---- 13 files changed, 65 insertions(+), 39 deletions(-) rename mindspore/ccsrc/{plugin/device/ascend/kernel/bisheng/bisheng_kernel_factory.cc => kernel/kernel_factory.cc} (56%) rename mindspore/ccsrc/{plugin/device/ascend/kernel/bisheng/bisheng_kernel_factory.h => kernel/kernel_factory.h} (57%) diff --git a/cmake/package_win.cmake b/cmake/package_win.cmake index 7874a35f69f..447e35b56bb 100644 --- a/cmake/package_win.cmake +++ b/cmake/package_win.cmake @@ -199,10 +199,9 @@ if(ENABLE_GPU) COMPONENT mindspore ) install( - TARGETS mindspore_gpu LIBRARY + TARGETS mindspore_gpu DESTINATION ${INSTALL_PLUGIN_DIR} COMPONENT mindspore - NAMELINK_SKIP ) endif() diff --git a/mindspore/ccsrc/kernel/CMakeLists.txt b/mindspore/ccsrc/kernel/CMakeLists.txt index b6bb4e50063..35c78ff3d43 100644 --- a/mindspore/ccsrc/kernel/CMakeLists.txt +++ b/mindspore/ccsrc/kernel/CMakeLists.txt @@ -1,4 +1,5 @@ file(GLOB_RECURSE KERNEL_SRC_LIST RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} + "kernel_factory.cc" "kernel_build_info.cc" "kernel.cc" "common_utils.cc" diff --git a/mindspore/ccsrc/plugin/device/ascend/kernel/bisheng/bisheng_kernel_factory.cc b/mindspore/ccsrc/kernel/kernel_factory.cc similarity index 56% rename from mindspore/ccsrc/plugin/device/ascend/kernel/bisheng/bisheng_kernel_factory.cc rename to mindspore/ccsrc/kernel/kernel_factory.cc index eb4765ebaa7..3386b838f04 100644 --- a/mindspore/ccsrc/plugin/device/ascend/kernel/bisheng/bisheng_kernel_factory.cc +++ b/mindspore/ccsrc/kernel/kernel_factory.cc @@ -14,11 +14,23 @@ * limitations under the License. */ -#include "plugin/device/ascend/kernel/bisheng/bisheng_kernel_factory.h" +#include "kernel/kernel_factory.h" namespace mindspore::kernel { -BiShengKernelFactory &BiShengKernelFactory::GetInstance() { - static BiShengKernelFactory instance; - return instance; +FactoryBase *FactoryBase::GetInstance(const std::string &name) { + auto iter = Map().find(name); + if (iter != Map().end()) { + return iter->second.get(); + } + return nullptr; +} + +void FactoryBase::CreateFactory(const std::string &name, std::unique_ptr &&factory) { + Map().emplace(name, std::move(factory)); +} + +std::map> &FactoryBase::Map() { + static std::map> map; + return map; } } // namespace mindspore::kernel diff --git a/mindspore/ccsrc/plugin/device/ascend/kernel/bisheng/bisheng_kernel_factory.h b/mindspore/ccsrc/kernel/kernel_factory.h similarity index 57% rename from mindspore/ccsrc/plugin/device/ascend/kernel/bisheng/bisheng_kernel_factory.h rename to mindspore/ccsrc/kernel/kernel_factory.h index 9224d20d65d..9a7e60cf6c6 100644 --- a/mindspore/ccsrc/plugin/device/ascend/kernel/bisheng/bisheng_kernel_factory.h +++ b/mindspore/ccsrc/kernel/kernel_factory.h @@ -1,5 +1,5 @@ /** - * Copyright 2023 Huawei Technologies Co., Ltd + * Copyright 2022-2023 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. @@ -14,25 +14,32 @@ * limitations under the License. */ -#ifndef MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_ASCEND_BISHENG_KERNEL_FACTORY_H -#define MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_ASCEND_BISHENG_KERNEL_FACTORY_H +#ifndef MINDSPORE_CCSRC_KERNEL_KERNEL_FACTORY_H_ +#define MINDSPORE_CCSRC_KERNEL_KERNEL_FACTORY_H_ -#include +#include #include -#include #include #include +#include +#include +#include #include "include/backend/visible.h" -#include "plugin/factory/ms_factory.h" +#include "utils/log_adapter.h" namespace mindspore { namespace kernel { -class BiShengKernelMod; - -class BACKEND_EXPORT BiShengKernelFactory : public Factory { +class BACKEND_EXPORT FactoryBase { public: - static BiShengKernelFactory &GetInstance(); + virtual ~FactoryBase() = default; + + protected: + static FactoryBase *GetInstance(const std::string &name); + static void CreateFactory(const std::string &name, std::unique_ptr &&factory); + + private: + static std::map> &Map(); }; } // namespace kernel } // namespace mindspore -#endif // MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_ASCEND_BISHENG_KERNEL_FACTORY_H +#endif // MINDSPORE_CCSRC_KERNEL_KERNEL_FACTORY_H_ diff --git a/mindspore/ccsrc/plugin/device/ascend/kernel/bisheng/CMakeLists.txt b/mindspore/ccsrc/plugin/device/ascend/kernel/bisheng/CMakeLists.txt index 867029ca1a7..b67bd1481ff 100644 --- a/mindspore/ccsrc/plugin/device/ascend/kernel/bisheng/CMakeLists.txt +++ b/mindspore/ccsrc/plugin/device/ascend/kernel/bisheng/CMakeLists.txt @@ -17,7 +17,7 @@ if(${try_result}) message("Bisheng toolchain seems to work.") add_subdirectory(impl) file(GLOB SRC_LIST RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.cc") - list(REMOVE_ITEM SRC_LIST "bisheng_kernel_build.cc" "custom_bisheng_kernel.cc" "bisheng_kernel_factory.cc") + list(REMOVE_ITEM SRC_LIST "bisheng_kernel_build.cc" "custom_bisheng_kernel.cc") add_library(bisheng_kernels SHARED ${SRC_LIST}) target_link_libraries(bisheng_kernels PRIVATE mindspore_ascend bisheng_kernels_impl) set_target_properties(bisheng_kernels PROPERTIES INSTALL_RPATH $ORIGIN) diff --git a/mindspore/ccsrc/plugin/device/ascend/kernel/bisheng/add_bisheng_kernel.cc b/mindspore/ccsrc/plugin/device/ascend/kernel/bisheng/add_bisheng_kernel.cc index 342f8f83c1d..26ccc056b58 100644 --- a/mindspore/ccsrc/plugin/device/ascend/kernel/bisheng/add_bisheng_kernel.cc +++ b/mindspore/ccsrc/plugin/device/ascend/kernel/bisheng/add_bisheng_kernel.cc @@ -16,7 +16,6 @@ #include "plugin/device/ascend/kernel/bisheng/add_bisheng_kernel.h" #include -#include "plugin/device/ascend/kernel/bisheng/bisheng_kernel_factory.h" #include "plugin/device/ascend/kernel/bisheng/bisheng_op_info.h" #include "plugin/device/ascend/kernel/bisheng/impl/add.h" diff --git a/mindspore/ccsrc/plugin/device/ascend/kernel/bisheng/bisheng_kernel_build.cc b/mindspore/ccsrc/plugin/device/ascend/kernel/bisheng/bisheng_kernel_build.cc index 625e7e84e30..ccb126d68c3 100644 --- a/mindspore/ccsrc/plugin/device/ascend/kernel/bisheng/bisheng_kernel_build.cc +++ b/mindspore/ccsrc/plugin/device/ascend/kernel/bisheng/bisheng_kernel_build.cc @@ -22,7 +22,7 @@ #include #include "plugin/device/ascend/kernel/bisheng/custom_bisheng_kernel.h" #include "plugin/device/ascend/kernel/bisheng/bisheng_kernel_mod.h" -#include "plugin/device/ascend/kernel/bisheng/bisheng_kernel_factory.h" +#include "plugin/factory/ms_factory.h" #include "include/common/utils/anfalgo.h" #include "utils/dlopen_macro.h" @@ -54,7 +54,7 @@ KernelModPtr BiShengOpBuild(const AnfNodePtr &anf_node) { auto cnode = anf_node->cast(); MS_EXCEPTION_IF_NULL(cnode); const auto &kernel_name = common::AnfAlgo::GetCNodeName(cnode); - if (!BiShengKernelFactory::GetInstance().IsRegistered(kernel_name)) { + if (!Factory::Instance().IsRegistered(kernel_name)) { MS_LOG(INFO) << "Bisheng custom op " << kernel_name; auto kernel_mod_ptr = std::make_shared(cnode); MS_EXCEPTION_IF_NULL(kernel_mod_ptr); @@ -66,7 +66,7 @@ KernelModPtr BiShengOpBuild(const AnfNodePtr &anf_node) { } MS_LOG(INFO) << "Bisheng internal op " << kernel_name; - auto kernel_mod = BiShengKernelFactory::GetInstance().Create(kernel_name); + auto kernel_mod = Factory::Instance().Create(kernel_name); auto args = AbstractArgsFromCNode(cnode, false); auto inputs_tensor_map = std::map(); SetInputsByConstInputs(cnode, &inputs_tensor_map); diff --git a/mindspore/ccsrc/plugin/device/ascend/kernel/bisheng/bisheng_op_info.h b/mindspore/ccsrc/plugin/device/ascend/kernel/bisheng/bisheng_op_info.h index 8a283a4147f..8c2bc61ff00 100644 --- a/mindspore/ccsrc/plugin/device/ascend/kernel/bisheng/bisheng_op_info.h +++ b/mindspore/ccsrc/plugin/device/ascend/kernel/bisheng/bisheng_op_info.h @@ -25,7 +25,7 @@ #include "include/api/format.h" #include "include/api/data_type.h" #include "kernel/oplib/opinfo.h" -#include "plugin/device/ascend/kernel/bisheng/bisheng_kernel_factory.h" +#include "plugin/factory/ms_factory.h" namespace cl::sycl::detail::half_impl { class half; @@ -33,6 +33,7 @@ class half; namespace mindspore::kernel { using half = cl::sycl::detail::half_impl::half; +class BiShengKernelMod; #define REG(Clazz) const BishengOpInfoRegister Clazz::reg_ = BishengOpInfoRegister() @@ -380,8 +381,8 @@ class BishengOpInfoRegister : public BishengOpInfoRegisterHelper { BishengOpInfoRegister() : BishengOpInfoRegisterHelper(), func_list_(T::func_list_) {} const BishengOpInfoRegister &End() { BishengOpInfoRegisterHelper::End(); - BiShengKernelFactory::GetInstance().Register(op_info_->op_name(), - std::move([]() { return std::make_shared(); })); + Factory::Instance().Register(op_info_->op_name(), + std::move([]() { return std::make_shared(); })); return *this; } BishengOpInfoRegister &OpName(const std::string &name) { diff --git a/mindspore/ccsrc/plugin/factory/ms_factory.h b/mindspore/ccsrc/plugin/factory/ms_factory.h index cf3674c24e4..0826469e0a9 100644 --- a/mindspore/ccsrc/plugin/factory/ms_factory.h +++ b/mindspore/ccsrc/plugin/factory/ms_factory.h @@ -24,22 +24,28 @@ #include #include #include -#include "include/backend/visible.h" +#include "kernel/kernel_factory.h" #include "utils/log_adapter.h" namespace mindspore { namespace kernel { template -class BACKEND_EXPORT Factory { +class Factory : public FactoryBase { using CreatorFunc = std::function()>; public: Factory(const Factory &) = delete; void operator=(const Factory &) = delete; - static Factory &Instance() { - static Factory instance; - return instance; + static Factory &Instance() { + std::string key = typeid(C).name(); + FactoryBase *instance = FactoryBase::GetInstance(key); + if (instance == nullptr) { + FactoryBase::CreateFactory(key, std::make_unique>()); + instance = FactoryBase::GetInstance(key); + } + MS_EXCEPTION_IF_NULL(instance); + return *static_cast *>(instance); } void Register(const std::string &name, CreatorFunc &&creator) { @@ -71,7 +77,6 @@ class BACKEND_EXPORT Factory { return false; } - protected: Factory() = default; ~Factory() = default; @@ -80,7 +85,7 @@ class BACKEND_EXPORT Factory { }; template -class BACKEND_EXPORT KernelRegistrar { +class KernelRegistrar { public: explicit KernelRegistrar(const std::string &name, std::function()> creator) noexcept { Factory::Instance().Register(name, std::move(creator)); diff --git a/mindspore/ccsrc/runtime/hardware/device_context_manager.cc b/mindspore/ccsrc/runtime/hardware/device_context_manager.cc index 6dd69fda072..6920f92ac56 100644 --- a/mindspore/ccsrc/runtime/hardware/device_context_manager.cc +++ b/mindspore/ccsrc/runtime/hardware/device_context_manager.cc @@ -319,7 +319,7 @@ bool PluginLoader::GetPluginPath(std::string *file_path) { #ifndef _WIN32 auto plugin_so_path = cur_so_path.substr(0, pos) + "/plugin"; #else - auto plugin_so_path = cur_so_path.substr(0, pos) + "\\bin"; + auto plugin_so_path = cur_so_path.substr(0, pos); #endif if (plugin_so_path.size() >= PATH_MAX) { MS_LOG(INFO) << "Current path [" << plugin_so_path << "] is invalid."; diff --git a/mindspore/lite/src/extendrt/CMakeLists.txt b/mindspore/lite/src/extendrt/CMakeLists.txt index 2da27c1bd78..d89e01c8ad9 100644 --- a/mindspore/lite/src/extendrt/CMakeLists.txt +++ b/mindspore/lite/src/extendrt/CMakeLists.txt @@ -113,6 +113,7 @@ if(MSLITE_ENABLE_CLOUD_FUSION_INFERENCE OR MSLITE_ENABLE_CLOUD_INFERENCE) ${CCSRC_DIR}/runtime/hardware/device_type.cc ${CCSRC_DIR}/kernel/kernel_build_info.cc ${CCSRC_DIR}/kernel/common_utils.cc + ${CCSRC_DIR}/kernel/kernel_factory.cc ${CCSRC_DIR}/kernel/kernel.cc ${CCSRC_DIR}/kernel/kash/kernel_pack.cc ${CCSRC_DIR}/kernel/oplib/oplib.cc diff --git a/mindspore/lite/tools/converter/CMakeLists.txt b/mindspore/lite/tools/converter/CMakeLists.txt index 74c03690956..f2b7099dac9 100644 --- a/mindspore/lite/tools/converter/CMakeLists.txt +++ b/mindspore/lite/tools/converter/CMakeLists.txt @@ -13,6 +13,7 @@ set(CCSRC_SRC ${CCSRC_DIR}/backend/common/optimizer/visit.cc ${CCSRC_DIR}/backend/common/optimizer/graph_optimizer.cc ${CCSRC_DIR}/backend/operator/ops_backend_infer_function.cc + ${CCSRC_DIR}/kernel/kernel_factory.cc ) if(NOT WIN32) diff --git a/mindspore/python/mindspore/run_check/_check_version.py b/mindspore/python/mindspore/run_check/_check_version.py index a3f0b9154cc..53f7c42a507 100644 --- a/mindspore/python/mindspore/run_check/_check_version.py +++ b/mindspore/python/mindspore/run_check/_check_version.py @@ -520,12 +520,12 @@ def check_version_and_env_config(): logger.warning("Pre-Load Lirary libgomp.so.1 failed, which might cause TLS memory allocation failure. If " "the failure occurs, you can find a solution in FAQ in " "https://www.mindspore.cn/docs/en/master/faq/installation.html.") - if not os.getenv("MS_DEV_CLOSE_VERSION_CHECK") is None: - return - MSContext.get_instance().register_check_env_callback(check_env) - MSContext.get_instance().register_set_env_callback(set_env) - MSContext.get_instance().set_param(ms_ctx_param.device_target, - MSContext.get_instance().get_param(ms_ctx_param.device_target)) + if not os.getenv("MS_DEV_CLOSE_VERSION_CHECK") is None: + return + MSContext.get_instance().register_check_env_callback(check_env) + MSContext.get_instance().register_set_env_callback(set_env) + MSContext.get_instance().set_param(ms_ctx_param.device_target, + MSContext.get_instance().get_param(ms_ctx_param.device_target)) def _set_pb_env():