diff --git a/mindspore/ccsrc/backend/kernel_compiler/cpu/embedding_look_up_cpu_kernel.cc b/mindspore/ccsrc/backend/kernel_compiler/cpu/embedding_look_up_cpu_kernel.cc index ccd83c96ad9..578ab4b9636 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/cpu/embedding_look_up_cpu_kernel.cc +++ b/mindspore/ccsrc/backend/kernel_compiler/cpu/embedding_look_up_cpu_kernel.cc @@ -23,7 +23,7 @@ namespace mindspore { namespace kernel { namespace { template -void LookUpTableTask(const float *input_addr, const T *indices_addr, float *output_addr, float *output_max_addr, +void LookUpTableTask(const float *input_addr, const T *indices_addr, const float *output_max_addr, float *output_addr, size_t indices_lens, size_t outer_dim_size, T offset, size_t first_dim_size) { size_t lens = outer_dim_size * sizeof(float); for (size_t i = 0; i < indices_lens; ++i) { @@ -82,9 +82,9 @@ void EmbeddingLookUpCPUKernel::LaunchKernel(const std::vector, input_addr, indices_addr + task_offset, - output_addr + task_offset * outer_dim_size_, output_addr + outputs[0]->size, - task_proc_lens, outer_dim_size_, offset_, first_dim_size_); + threads[i] = std::thread(LookUpTableTask, input_addr, indices_addr + task_offset, output_addr + outputs[0]->size, + output_addr + task_offset * outer_dim_size_, task_proc_lens, outer_dim_size_, offset_, + first_dim_size_); task_offset += task_proc_lens; if (task_offset + task_proc_lens > indices_lens_) { task_proc_lens = indices_lens_ - task_offset; diff --git a/mindspore/ccsrc/backend/optimizer/ascend/buffer_fusion/conv2dbackprop_eltwise_eltwise_fusion_pass.cc b/mindspore/ccsrc/backend/optimizer/ascend/buffer_fusion/conv2dbackprop_eltwise_eltwise_fusion_pass.cc index 66a76f027dc..0c61e1a84d6 100644 --- a/mindspore/ccsrc/backend/optimizer/ascend/buffer_fusion/conv2dbackprop_eltwise_eltwise_fusion_pass.cc +++ b/mindspore/ccsrc/backend/optimizer/ascend/buffer_fusion/conv2dbackprop_eltwise_eltwise_fusion_pass.cc @@ -30,12 +30,10 @@ void Conv2DBackpropEltwiseEltwiseFusionPass::MatchConv2DBackpropInputEltwiseEltw const CNodePtr &cnode, const session::KernelGraph &kernel_graph, FusedNodeRecord *candidate_fusion) { MS_EXCEPTION_IF_NULL(cnode); MS_EXCEPTION_IF_NULL(candidate_fusion); - auto manager = kernel_graph.manager(); - MS_EXCEPTION_IF_NULL(manager); std::unordered_set record{cnode}; auto eltwise_input = cnode->input(1); MS_EXCEPTION_IF_NULL(eltwise_input); - if (CheckDoubleInEltWiseNode(manager.get(), eltwise_input)) { + if (CheckDoubleInEltWiseNode(kernel_graph, eltwise_input)) { (void)record.insert(eltwise_input); } else { return; diff --git a/mindspore/ccsrc/backend/optimizer/ascend/buffer_fusion/conv_double_in_fusion_pass.cc b/mindspore/ccsrc/backend/optimizer/ascend/buffer_fusion/conv_double_in_fusion_pass.cc index f9fdd35994d..3e6ca6663a6 100644 --- a/mindspore/ccsrc/backend/optimizer/ascend/buffer_fusion/conv_double_in_fusion_pass.cc +++ b/mindspore/ccsrc/backend/optimizer/ascend/buffer_fusion/conv_double_in_fusion_pass.cc @@ -30,12 +30,10 @@ void ConvDoubleInFusionPass::MatchConvDoubleInEltwise(const CNodePtr &cnode, con FusedNodeRecord *candidate_fusion) { MS_EXCEPTION_IF_NULL(cnode); MS_EXCEPTION_IF_NULL(candidate_fusion); - auto manager = kernel_graph.manager(); - MS_EXCEPTION_IF_NULL(manager); std::unordered_set record{cnode}; auto eltwise_input = cnode->input(1); MS_EXCEPTION_IF_NULL(eltwise_input); - if (CheckDoubleInEltWiseNode(manager.get(), eltwise_input)) { + if (CheckDoubleInEltWiseNode(kernel_graph, eltwise_input)) { (void)record.insert(eltwise_input); } else { return; diff --git a/mindspore/ccsrc/backend/optimizer/ascend/buffer_fusion/conv_single_in_fusion_pass.cc b/mindspore/ccsrc/backend/optimizer/ascend/buffer_fusion/conv_single_in_fusion_pass.cc index 9416028374c..debf1c9a784 100644 --- a/mindspore/ccsrc/backend/optimizer/ascend/buffer_fusion/conv_single_in_fusion_pass.cc +++ b/mindspore/ccsrc/backend/optimizer/ascend/buffer_fusion/conv_single_in_fusion_pass.cc @@ -30,11 +30,9 @@ void ConvSingleInFusionPass::MatchConvSingleInEltwise(const CNodePtr &cnode, con FusedNodeRecord *candidate_fusion) { MS_EXCEPTION_IF_NULL(cnode); MS_EXCEPTION_IF_NULL(candidate_fusion); - auto manager = kernel_graph.manager(); - MS_EXCEPTION_IF_NULL(manager); std::unordered_set record{cnode}; auto eltwise_input = cnode->input(1); - while (CheckEltWiseNode(manager.get(), eltwise_input)) { + while (CheckEltWiseNode(kernel_graph, eltwise_input)) { (void)record.insert(eltwise_input); auto input_cnode = eltwise_input->cast(); MS_EXCEPTION_IF_NULL(input_cnode); diff --git a/mindspore/ccsrc/backend/optimizer/ascend/buffer_fusion/eltwise_fusion_pass.cc b/mindspore/ccsrc/backend/optimizer/ascend/buffer_fusion/eltwise_fusion_pass.cc index 4d7941c8cce..f486e8dc9ce 100644 --- a/mindspore/ccsrc/backend/optimizer/ascend/buffer_fusion/eltwise_fusion_pass.cc +++ b/mindspore/ccsrc/backend/optimizer/ascend/buffer_fusion/eltwise_fusion_pass.cc @@ -30,12 +30,10 @@ void EltwiseFusionPass::MatchEltwise(const CNodePtr &cnode, const session::Kerne FusedNodeRecord *candidate_fusion) { MS_EXCEPTION_IF_NULL(cnode); MS_EXCEPTION_IF_NULL(candidate_fusion); - auto manager = kernel_graph.manager(); - MS_EXCEPTION_IF_NULL(manager); std::unordered_set record{cnode}; auto eltwise_input = cnode->input(1); MS_EXCEPTION_IF_NULL(eltwise_input); - while (CheckEltWiseNode(manager.get(), eltwise_input)) { + while (CheckEltWiseNode(kernel_graph, eltwise_input)) { (void)record.insert(eltwise_input); if (record.size() == MAX_ELTWISE_SIZE) { break; diff --git a/mindspore/ccsrc/backend/optimizer/ascend/buffer_fusion/fusion_base_pass.cc b/mindspore/ccsrc/backend/optimizer/ascend/buffer_fusion/fusion_base_pass.cc index f66dbeda99c..343e79477e4 100644 --- a/mindspore/ccsrc/backend/optimizer/ascend/buffer_fusion/fusion_base_pass.cc +++ b/mindspore/ccsrc/backend/optimizer/ascend/buffer_fusion/fusion_base_pass.cc @@ -23,7 +23,8 @@ namespace mindspore { namespace opt { -bool FusionBasePass::CheckEltWiseNode(FuncGraphManager *manager, const AnfNodePtr &node) { +bool FusionBasePass::CheckEltWiseNode(const session::KernelGraph &kernel_graph, const AnfNodePtr &node) { + auto manager = kernel_graph.manager(); MS_EXCEPTION_IF_NULL(manager); MS_EXCEPTION_IF_NULL(node); if (!node->isa() || !AnfAlgo::IsRealCNodeKernel(node) || fusion_id_allocator->HasFusionIdAttr(node)) { @@ -37,7 +38,8 @@ bool FusionBasePass::CheckEltWiseNode(FuncGraphManager *manager, const AnfNodePt cnode->inputs().size() == ELTWISE_INPUT_SIZE; } -bool FusionBasePass::CheckDoubleInEltWiseNode(FuncGraphManager *manager, const AnfNodePtr &node) { +bool FusionBasePass::CheckDoubleInEltWiseNode(const session::KernelGraph &kernel_graph, const AnfNodePtr &node) { + auto manager = kernel_graph.manager(); MS_EXCEPTION_IF_NULL(manager); MS_EXCEPTION_IF_NULL(node); if (!node->isa() || !AnfAlgo::IsRealCNodeKernel(node) || fusion_id_allocator->HasFusionIdAttr(node)) { @@ -51,7 +53,8 @@ bool FusionBasePass::CheckDoubleInEltWiseNode(FuncGraphManager *manager, const A cnode->inputs().size() == ELTWISE_DOUBLE_IN_INPUT_SIZE; } -bool FusionBasePass::CheckMultiOutputEltWiseNode(FuncGraphManager *manager, const AnfNodePtr &node) { +bool FusionBasePass::CheckMultiOutputEltWiseNode(const session::KernelGraph &kernel_graph, const AnfNodePtr &node) { + auto manager = kernel_graph.manager(); MS_EXCEPTION_IF_NULL(manager); MS_EXCEPTION_IF_NULL(node); if (!node->isa() || !AnfAlgo::IsRealCNodeKernel(node) || fusion_id_allocator->HasFusionIdAttr(node)) { diff --git a/mindspore/ccsrc/backend/optimizer/ascend/buffer_fusion/fusion_base_pass.h b/mindspore/ccsrc/backend/optimizer/ascend/buffer_fusion/fusion_base_pass.h index c78e93cd97c..ff86b1c1e71 100644 --- a/mindspore/ccsrc/backend/optimizer/ascend/buffer_fusion/fusion_base_pass.h +++ b/mindspore/ccsrc/backend/optimizer/ascend/buffer_fusion/fusion_base_pass.h @@ -61,9 +61,9 @@ class FusionBasePass : public Pass { virtual void MatchSingleFusionPattern(const session::KernelGraph &kernel_graph, FusedNodeRecord *candidate_fusion) = 0; void SetRecordFusionId(const std::unordered_set &record); - bool CheckEltWiseNode(FuncGraphManager *manager, const AnfNodePtr &node); - bool CheckDoubleInEltWiseNode(FuncGraphManager *manager, const AnfNodePtr &node); - bool CheckMultiOutputEltWiseNode(FuncGraphManager *manager, const AnfNodePtr &node); + bool CheckEltWiseNode(const session::KernelGraph &kernel_graph, const AnfNodePtr &node); + bool CheckDoubleInEltWiseNode(const session::KernelGraph &kernel_graph, const AnfNodePtr &node); + bool CheckMultiOutputEltWiseNode(const session::KernelGraph &kernel_graph, const AnfNodePtr &node); FusionIdAllocatorPtr fusion_id_allocator; }; } // namespace opt diff --git a/mindspore/ccsrc/backend/optimizer/ascend/buffer_fusion/multi_output_fusion_pass.cc b/mindspore/ccsrc/backend/optimizer/ascend/buffer_fusion/multi_output_fusion_pass.cc index 0a12edc59b1..05f6d773d15 100644 --- a/mindspore/ccsrc/backend/optimizer/ascend/buffer_fusion/multi_output_fusion_pass.cc +++ b/mindspore/ccsrc/backend/optimizer/ascend/buffer_fusion/multi_output_fusion_pass.cc @@ -35,7 +35,7 @@ void MultiOutputFusionPass::MatchMultiOutputEltwise(const CNodePtr &cnode, const std::unordered_set record{cnode}; auto eltwise_input = cnode->input(1); MS_EXCEPTION_IF_NULL(eltwise_input); - if (CheckMultiOutputEltWiseNode(manager.get(), eltwise_input)) { + if (CheckMultiOutputEltWiseNode(kernel_graph, eltwise_input)) { std::vector output_used_num{SizeToInt(manager->node_users()[eltwise_input].size())}; AnfAlgo::SetNodeAttr(kAttrOutputUsedNum, MakeValue(output_used_num), eltwise_input); (void)record.insert(eltwise_input); @@ -45,7 +45,7 @@ void MultiOutputFusionPass::MatchMultiOutputEltwise(const CNodePtr &cnode, const } else { return; } - while (CheckEltWiseNode(manager.get(), eltwise_input)) { + while (CheckEltWiseNode(kernel_graph, eltwise_input)) { (void)record.insert(eltwise_input); if (record.size() == MULTI_ELTWISE_SIZE) { break; diff --git a/mindspore/ccsrc/backend/optimizer/ascend/buffer_fusion/reduce_eltwise_fusion_pass.cc b/mindspore/ccsrc/backend/optimizer/ascend/buffer_fusion/reduce_eltwise_fusion_pass.cc index f9d414ed132..8c9fe78df9c 100644 --- a/mindspore/ccsrc/backend/optimizer/ascend/buffer_fusion/reduce_eltwise_fusion_pass.cc +++ b/mindspore/ccsrc/backend/optimizer/ascend/buffer_fusion/reduce_eltwise_fusion_pass.cc @@ -31,11 +31,9 @@ void ReduceEltwiseFusionPass::MatchReduceEltwise(const CNodePtr &cnode, const se FusedNodeRecord *candidate_fusion) { MS_EXCEPTION_IF_NULL(cnode); MS_EXCEPTION_IF_NULL(candidate_fusion); - auto manager = kernel_graph.manager(); - MS_EXCEPTION_IF_NULL(manager); std::unordered_set record{cnode}; auto eltwise_input = cnode->input(1); - while (CheckEltWiseNode(manager.get(), eltwise_input)) { + while (CheckEltWiseNode(kernel_graph, eltwise_input)) { (void)record.insert(eltwise_input); auto input_cnode = eltwise_input->cast(); MS_EXCEPTION_IF_NULL(input_cnode); @@ -56,7 +54,7 @@ void ReduceEltwiseFusionPass::MatchReduceEltwise(const CNodePtr &cnode, const se MS_EXCEPTION_IF_NULL(previous_input_cnode); auto previous_eltwise_input = previous_input_cnode->input(1); auto previous_size = record.size(); - while (CheckEltWiseNode(manager.get(), previous_eltwise_input)) { + while (CheckEltWiseNode(kernel_graph, previous_eltwise_input)) { (void)record.insert(previous_eltwise_input); auto previous_node = previous_eltwise_input->cast(); MS_EXCEPTION_IF_NULL(previous_node); diff --git a/mindspore/ccsrc/backend/optimizer/ascend/buffer_fusion/segment_eltwise_fusion_pass.cc b/mindspore/ccsrc/backend/optimizer/ascend/buffer_fusion/segment_eltwise_fusion_pass.cc index b226986217c..6fcb5a4a2f6 100644 --- a/mindspore/ccsrc/backend/optimizer/ascend/buffer_fusion/segment_eltwise_fusion_pass.cc +++ b/mindspore/ccsrc/backend/optimizer/ascend/buffer_fusion/segment_eltwise_fusion_pass.cc @@ -30,11 +30,9 @@ void SegmentEltwiseFusionPass::MatchSegmentEltwise(const CNodePtr &cnode, const FusedNodeRecord *candidate_fusion) { MS_EXCEPTION_IF_NULL(cnode); MS_EXCEPTION_IF_NULL(candidate_fusion); - auto manager = kernel_graph.manager(); - MS_EXCEPTION_IF_NULL(manager); std::unordered_set record{cnode}; auto eltwise_input = cnode->input(1); - while (CheckEltWiseNode(manager.get(), eltwise_input)) { + while (CheckEltWiseNode(kernel_graph, eltwise_input)) { (void)record.insert(eltwise_input); auto input_cnode = eltwise_input->cast(); MS_EXCEPTION_IF_NULL(input_cnode); @@ -55,7 +53,7 @@ void SegmentEltwiseFusionPass::MatchSegmentEltwise(const CNodePtr &cnode, const MS_EXCEPTION_IF_NULL(previous_input_cnode); auto previous_eltwise_input = previous_input_cnode->input(1); auto previous_size = record.size(); - while (CheckEltWiseNode(manager.get(), previous_eltwise_input)) { + while (CheckEltWiseNode(kernel_graph, previous_eltwise_input)) { (void)record.insert(previous_eltwise_input); auto previous_node = previous_eltwise_input->cast(); MS_EXCEPTION_IF_NULL(previous_node); diff --git a/mindspore/ccsrc/backend/optimizer/ascend/buffer_fusion/stridedread_conv_stridedwrite_fusion_pass.cc b/mindspore/ccsrc/backend/optimizer/ascend/buffer_fusion/stridedread_conv_stridedwrite_fusion_pass.cc index 6732d849e7a..10d1db0cd6d 100644 --- a/mindspore/ccsrc/backend/optimizer/ascend/buffer_fusion/stridedread_conv_stridedwrite_fusion_pass.cc +++ b/mindspore/ccsrc/backend/optimizer/ascend/buffer_fusion/stridedread_conv_stridedwrite_fusion_pass.cc @@ -33,11 +33,9 @@ void StridedReadConvStridedWriteFusionPass::MatchStridedReadConvStridedWrite(con FusedNodeRecord *candidate_fusion) { MS_EXCEPTION_IF_NULL(cnode); MS_EXCEPTION_IF_NULL(candidate_fusion); - auto manager = kernel_graph.manager(); - MS_EXCEPTION_IF_NULL(manager); std::unordered_set record{cnode}; auto write_input = cnode->input(1); - if (CheckEltWiseNode(manager.get(), write_input)) { + if (CheckEltWiseNode(kernel_graph, write_input)) { (void)record.insert(write_input); auto input_cnode = write_input->cast(); MS_EXCEPTION_IF_NULL(input_cnode);