From ae1f2be763a1e378f75a783a65968a07a0756fa9 Mon Sep 17 00:00:00 2001 From: Gorokhov Dmitriy Date: Tue, 10 Nov 2020 10:56:22 +0300 Subject: [PATCH] [CPU] Fixed Eltwise node endless loop in case nthreads = 1 (#3008) --- .../nodes/mkldnn_eltwise_node.cpp | 7 ++-- .../single_layer_tests/eltwise.cpp | 32 +++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_eltwise_node.cpp b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_eltwise_node.cpp index 2bffe173695..f8150684a3f 100644 --- a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_eltwise_node.cpp +++ b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_eltwise_node.cpp @@ -1213,13 +1213,17 @@ void MKLDNNEltwiseNode::createPrimitive() { fullWorkAmount *= dims_out[i]; } + isDynBatchEnabled = config.dynBatchSupport; + size_t minimalConcurrency = parallel_get_max_threads(); size_t minimalJitWorkAmount = 256; size_t currentJitWorkAmount = dims_out[dims_out.size() - 1]; int collapsedDims = 0; if (canUseOptimizedImpl) { bool hasDifferentDims = false; - while (currentJitWorkAmount < minimalJitWorkAmount) { + while (currentJitWorkAmount < minimalJitWorkAmount && currentJitWorkAmount < fullWorkAmount && + // we shouldn't collapse batch dimension in case dynamic batch is enabled + (!isDynBatchEnabled || (config.outConfs[0].desc.getBlockingDesc().getBlockDims().size() - collapsedDims > 2))) { if (dims_out.size() - collapsedDims - 2 < 0) break; @@ -1271,7 +1275,6 @@ void MKLDNNEltwiseNode::createPrimitive() { } } - isDynBatchEnabled = config.dynBatchSupport; batchDimIdx = tensorRank - config.outConfs[0].desc.getBlockingDesc().getBlockDims().size() + collapsedDims; schedulerWorkAmount = fullWorkAmount / dims_out[dims_out.size() - 1]; diff --git a/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/single_layer_tests/eltwise.cpp b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/single_layer_tests/eltwise.cpp index 9b20c89e1eb..75ada843f02 100644 --- a/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/single_layer_tests/eltwise.cpp +++ b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/single_layer_tests/eltwise.cpp @@ -64,4 +64,36 @@ const auto multiply_params = ::testing::Combine( ::testing::Values(additional_config)); INSTANTIATE_TEST_CASE_P(smoke_CompareWithRefs, EltwiseLayerTest, multiply_params, EltwiseLayerTest::getTestCaseName); + + +std::vector>> inShapesSingleThread = { + {{1, 2, 3, 4}}, + {{2, 2, 2, 2}}, + {{2, 1, 2, 1, 2, 2}} +}; + +std::vector eltwiseOpTypesSingleThread = { + ngraph::helpers::EltwiseTypes::ADD, + ngraph::helpers::EltwiseTypes::POWER, +}; + +std::map additional_config_single_thread = { + {"CPU_THREADS_NUM", "1"} +}; + +const auto single_thread_params = ::testing::Combine( + ::testing::ValuesIn(inShapesSingleThread), + ::testing::ValuesIn(eltwiseOpTypesSingleThread), + ::testing::ValuesIn(secondaryInputTypes), + ::testing::ValuesIn(opTypes), + ::testing::ValuesIn(netPrecisions), + ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), + ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), + ::testing::Values(InferenceEngine::Layout::ANY), + ::testing::Values(CommonTestUtils::DEVICE_CPU), + ::testing::Values(additional_config_single_thread)); + +INSTANTIATE_TEST_CASE_P(smoke_SingleThread, EltwiseLayerTest, single_thread_params, EltwiseLayerTest::getTestCaseName); + + } // namespace \ No newline at end of file