diff --git a/mindspore/ccsrc/backend/optimizer/ascend/mindir/sparse_softmax_cross_entropy_with_logits_unify_mindir.cc b/mindspore/ccsrc/backend/optimizer/ascend/mindir/sparse_softmax_cross_entropy_with_logits_unify_mindir.cc index aae47143c6e..484974d19df 100644 --- a/mindspore/ccsrc/backend/optimizer/ascend/mindir/sparse_softmax_cross_entropy_with_logits_unify_mindir.cc +++ b/mindspore/ccsrc/backend/optimizer/ascend/mindir/sparse_softmax_cross_entropy_with_logits_unify_mindir.cc @@ -419,8 +419,9 @@ const BaseRef GradSparseSoftmaxCrossEntropyWithLogitsUnifyMindIR::DefinePattern( VarPtr x1 = std::make_shared(); VarPtr x2 = std::make_shared(); VarPtr x3 = std::make_shared(); + VarPtr x4 = std::make_shared(); VectorRef sparse_softmax_cross_entropy_with_logits_grad({prim::kPrimSparseSoftmaxCrossEntropyWithLogits, x1, x2}); - VectorRef sparse_softmax_cross_entropy_with_logits({prim::kPrimSparseSoftmaxCrossEntropyWithLogits, x1, x2}); + VectorRef sparse_softmax_cross_entropy_with_logits({prim::kPrimSparseSoftmaxCrossEntropyWithLogits, x1, x4}); VectorRef depend( {prim::kPrimDepend, sparse_softmax_cross_entropy_with_logits_grad, sparse_softmax_cross_entropy_with_logits}); return VectorRef({prim::kPrimMul, depend, x3}); @@ -518,19 +519,21 @@ const AnfNodePtr PynativeSparseSoftmaxCrossEntropyWithLogitsUnifyMindIR::Process MS_EXCEPTION_IF_NULL(sparse_softmax_node); CheckCNodeInputSize(sparse_softmax_node, kSparseSoftmaxCrossEntropyWithLogitsInputTensorNum); - if (AnfAlgo::HasNodeAttr(kAttrIsGrad, sparse_softmax_node) && - AnfAlgo::GetNodeAttr(sparse_softmax_node, kAttrIsGrad)) { - return nullptr; - } - CNodePtr softmax_node; auto one_hot_node = CreateOneHot(graph, sparse_softmax_node, true); softmax_node = CreateSoftmaxCrossEntropyWithLogits(graph, sparse_softmax_node, one_hot_node); std::vector softmax_node_outputs; CreateMultipleOutputsOfAnfNode(graph, softmax_node, kSoftmaxCrossEntropyWithLogitsOutputNum, &softmax_node_outputs); - auto reduce_node = CreateReduceMean(graph, sparse_softmax_node, softmax_node_outputs[0], true); - return reduce_node; + // Both of the forward loss function and the backward loss function from cangjie will match this pattern, + // the true branch is for the backward loss function, and the false branch is for the other one. + if (AnfAlgo::HasNodeAttr(kAttrIsGrad, sparse_softmax_node) && + AnfAlgo::GetNodeAttr(sparse_softmax_node, kAttrIsGrad)) { + return softmax_node_outputs[1]; + } else { + auto reduce_node = CreateReduceMean(graph, sparse_softmax_node, softmax_node_outputs[0], true); + return reduce_node; + } } const BaseRef PynativeGradSparseSoftmaxCrossEntropyWithLogitsUnifyMindIR::DefinePattern() const { diff --git a/mindspore/ccsrc/backend/session/ascend_session.cc b/mindspore/ccsrc/backend/session/ascend_session.cc index f60d8817aae..6c6779edc4f 100644 --- a/mindspore/ccsrc/backend/session/ascend_session.cc +++ b/mindspore/ccsrc/backend/session/ascend_session.cc @@ -294,8 +294,10 @@ void AscendSession::UnifyMindIR(const KernelGraphPtr &graph) { unify_mindir_pm->AddPass(std::make_shared()); unify_mindir_pm->AddPass(std::make_shared()); } else { - unify_mindir_pm->AddPass(std::make_shared()); + // Add PynativeGradSparseSoftmaxCrossEntropyWithLogitsUnifyMindIR pass first to avoid the backward loss function + // from the python frontend matching the pattern defined in PynativeSparseSoftmaxCrossEntropyWithLogitsUnifyMindIR. unify_mindir_pm->AddPass(std::make_shared()); + unify_mindir_pm->AddPass(std::make_shared()); } unify_mindir_pm->AddPass(std::make_shared()); unify_mindir_pm->AddPass(std::make_shared()); diff --git a/mindspore/ccsrc/backend/session/session_basic.h b/mindspore/ccsrc/backend/session/session_basic.h index 607a07abfbc..3a75c43b63e 100644 --- a/mindspore/ccsrc/backend/session/session_basic.h +++ b/mindspore/ccsrc/backend/session/session_basic.h @@ -300,9 +300,6 @@ class SessionBasic : public std::enable_shared_from_this { #if !defined(_WIN32) && !defined(_WIN64) std::shared_ptr debugger_; #endif -#if (ENABLE_CPU && !_WIN32) - bool initialized_ps_cache_{false}; -#endif }; using SessionPtr = std::shared_ptr; diff --git a/mindspore/ccsrc/pipeline/jit/CMakeLists.txt b/mindspore/ccsrc/pipeline/jit/CMakeLists.txt index f587bbc0398..2829aad6069 100644 --- a/mindspore/ccsrc/pipeline/jit/CMakeLists.txt +++ b/mindspore/ccsrc/pipeline/jit/CMakeLists.txt @@ -26,4 +26,9 @@ if(ENABLE_GE OR ENABLE_D) list(APPEND _PIPELINE_SRC_FILES ${_PIPELINE_GE_SRC_FILES}) endif() +if("${ENABLE_HIDDEN}" STREQUAL "OFF") + string(REPLACE " -Werror " " " CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") + string(REPLACE " -fvisibility=hidden" " -fvisibility=default" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") +endif() + add_library(_mindspore_pipeline_jit_obj OBJECT ${_PIPELINE_SRC_FILES}) diff --git a/mindspore/ccsrc/runtime/device/kernel_runtime_manager.cc b/mindspore/ccsrc/runtime/device/kernel_runtime_manager.cc index f347e1936b7..6289fb4c723 100644 --- a/mindspore/ccsrc/runtime/device/kernel_runtime_manager.cc +++ b/mindspore/ccsrc/runtime/device/kernel_runtime_manager.cc @@ -51,6 +51,11 @@ void KernelRuntimeManager::ClearGraphResource(uint32_t graph_id, const std::vect } } +KernelRuntimeManager &KernelRuntimeManager::Instance() { + static KernelRuntimeManager instance{}; + return instance; +} + void KernelRuntimeManager::Register(const std::string &device_name, KernelRuntimeCreator &&runtime_creator) { if (runtime_creators_.find(device_name) == runtime_creators_.end()) { (void)runtime_creators_.emplace(device_name, runtime_creator); diff --git a/mindspore/ccsrc/runtime/device/kernel_runtime_manager.h b/mindspore/ccsrc/runtime/device/kernel_runtime_manager.h index 416f0759279..df3fe6fe4b2 100644 --- a/mindspore/ccsrc/runtime/device/kernel_runtime_manager.h +++ b/mindspore/ccsrc/runtime/device/kernel_runtime_manager.h @@ -32,10 +32,7 @@ using KernelRuntimeCreator = std::function()>; class KernelRuntimeManager { public: - static KernelRuntimeManager &Instance() { - static KernelRuntimeManager instance; - return instance; - } + static KernelRuntimeManager &Instance(); void Register(const std::string &device_name, KernelRuntimeCreator &&runtime_creator); KernelRuntime *GetKernelRuntime(const std::string &device_name, uint32_t device_id); KernelRuntime *GetCurrentKernelRuntime(); diff --git a/mindspore/core/utils/ms_utils.cc b/mindspore/core/utils/ms_utils.cc index 3905f8fbc29..683f37bd86e 100644 --- a/mindspore/core/utils/ms_utils.cc +++ b/mindspore/core/utils/ms_utils.cc @@ -17,9 +17,11 @@ namespace mindspore { namespace common { +namespace { const int CACHED_STR_NUM = 1 << 8; const int CACHED_STR_MASK = CACHED_STR_NUM - 1; std::vector STR_HOLDER(CACHED_STR_NUM); +} // namespace const char *SafeCStr(const std::string &&str) { static std::atomic index{0}; uint32_t cur_index = index++;