diff --git a/src/plugins/intel_cpu/src/nodes/mkldnn_depth_to_space_node.cpp b/src/plugins/intel_cpu/src/nodes/mkldnn_depth_to_space_node.cpp index 41b8983d362..ba9a30495c8 100644 --- a/src/plugins/intel_cpu/src/nodes/mkldnn_depth_to_space_node.cpp +++ b/src/plugins/intel_cpu/src/nodes/mkldnn_depth_to_space_node.cpp @@ -4,14 +4,16 @@ #include "mkldnn_depth_to_space_node.h" -#include #include -#include "common/blocked_desc_creator.h" #include -#include -#include #include +#include +#include +#include +#include + +#include "common/blocked_desc_creator.h" #define THROW_ERROR IE_THROW() << "DepthToSpace layer with name '" << getName() << "' " @@ -19,6 +21,31 @@ using namespace MKLDNNPlugin; using namespace InferenceEngine; using namespace mkldnn::impl; +size_t MKLDNNDepthToSpaceNode::DepthToSpaceAttrs::hash() const { + using namespace dnnl::impl; + using namespace dnnl::impl::primitive_hashing; + + size_t seed = 0; + seed = hash_combine(seed, layoutType); + seed = hash_combine(seed, mode); + seed = hash_combine(seed, blockSize); + seed = hash_combine(seed, blockStep); + seed = hash_combine(seed, dataSize); + seed = hash_combine(seed, nSpatialDims); + seed = get_vector_hash(seed, srcBlockedDims); + + return seed; +} + +bool MKLDNNDepthToSpaceNode::DepthToSpaceAttrs::operator==(const DepthToSpaceAttrs& rhs) const { + bool result = layoutType == rhs.layoutType && mode == rhs.mode && + blockSize == rhs.blockSize && blockStep == rhs.blockStep && + dataSize == rhs.dataSize && nSpatialDims == rhs.nSpatialDims && + srcBlockedDims == rhs.srcBlockedDims; + + return result; +} + bool MKLDNNDepthToSpaceNode::isSupportedOperation(const std::shared_ptr& op, std::string& errorMessage) noexcept { try { auto depthToSpace = ov::as_type_ptr(op); @@ -157,7 +184,17 @@ void MKLDNNDepthToSpaceNode::createPrimitive() { void MKLDNNDepthToSpaceNode::prepareParams() { attrs.srcBlockedDims = getParentEdgeAt(0)->getMemoryPtr()->GetDescWithType()->getBlockDims(); - execPtr = std::make_shared(attrs); + auto builder = [](const DepthToSpaceAttrs& key) -> std::shared_ptr { + return std::make_shared(key); + }; + + auto cache = getRuntimeCache(); + auto result = cache->getOrCreate(attrs, builder); + if (!result.first) { + IE_THROW() << "DepthToSpaceExecutor was not found for node " << getName() << "."; + } + + execPtr = result.first; } MKLDNNDepthToSpaceNode::DepthToSpaceExecutor::DepthToSpaceExecutor(const DepthToSpaceAttrs& attrs) { diff --git a/src/plugins/intel_cpu/src/nodes/mkldnn_depth_to_space_node.h b/src/plugins/intel_cpu/src/nodes/mkldnn_depth_to_space_node.h index f32a540cdc9..df4f1ab3eb2 100644 --- a/src/plugins/intel_cpu/src/nodes/mkldnn_depth_to_space_node.h +++ b/src/plugins/intel_cpu/src/nodes/mkldnn_depth_to_space_node.h @@ -24,15 +24,7 @@ public: void prepareParams() override; -protected: - void executeDynamicImpl(mkldnn::stream strm) override; - -private: - enum Mode { - BLOCKS_FIRST = 0, - DEPTH_FIRST = 1 - }; - + enum Mode { BLOCKS_FIRST = 0, DEPTH_FIRST = 1 }; struct DepthToSpaceAttrs { LayoutType layoutType; Mode mode; @@ -41,8 +33,15 @@ private: size_t dataSize = 1lu; size_t nSpatialDims = 0lu; VectorDims srcBlockedDims; - } attrs; + size_t hash() const; + bool operator==(const DepthToSpaceAttrs& rhs) const; + }; +protected: + void executeDynamicImpl(mkldnn::stream strm) override; + +private: + DepthToSpaceAttrs attrs; struct DepthToSpaceExecutor { DepthToSpaceExecutor(const DepthToSpaceAttrs& attrs); void exec(MKLDNNMemoryPtr& srcMemPtr, MKLDNNMemoryPtr& dstMemPtr, const int MB); diff --git a/src/tests/functional/plugin/cpu/single_layer_tests/depth_to_space.cpp b/src/tests/functional/plugin/cpu/single_layer_tests/depth_to_space.cpp index 7485eab36dd..286a563f9de 100644 --- a/src/tests/functional/plugin/cpu/single_layer_tests/depth_to_space.cpp +++ b/src/tests/functional/plugin/cpu/single_layer_tests/depth_to_space.cpp @@ -209,35 +209,37 @@ INSTANTIATE_TEST_SUITE_P(smoke_CPUDepthToSpaceStaticBS3_5D, DepthToSpaceLayerCPU } // namespace static_shapes /* *========================* *==================* *========================* */ - /* *========================* Dynamic Shapes Tests *========================* */ namespace dynamic_shapes { const std::vector inputShapes4D = { - {{-1, -1, -1 , -1}, // dynamic - {{2, 36, 1, 1}, {1, 36, 3, 1}, {1, 72, 1, 4}}}, // target + {{-1, -1, -1, -1}, // dynamic + {{2, 36, 1, 1}, {1, 36, 3, 1}, {2, 36, 1, 1}, {1, 36, 3, 1}}}, // target - {{-1, 576, -1 , -1}, // dynamic - {{1, 576, 1, 1}, {1, 576, 2, 2}, {3, 576, 4, 1}}}, // target + {{-1, 576, -1, -1}, // dynamic + {{1, 576, 1, 1}, {1, 576, 2, 2}, {3, 576, 4, 1}, {1, 576, 1, 1}}}, // target - {{{1, 5}, {36, 72}, {1, 16}, {1, 16}}, // dynamic - {{3, 36, 4, 4}, {1, 36, 16, 12}, {3, 72, 8, 8}}}, // target + {{{1, 5}, {36, 72}, {1, 16}, {1, 16}}, // dynamic + {{3, 36, 4, 4}, {1, 36, 16, 12}, {3, 72, 8, 8}, {1, 36, 16, 12}}}, // target }; const std::vector inputShapes5D = { - {{-1, -1, -1, -1, -1}, // dynamic - {{2, 216, 1, 1, 1}, {1, 216, 3, 1, 2}, {1, 432, 2, 3, 1}}}, // target + {{-1, -1, -1, -1, -1}, // dynamic + {{2, 216, 1, 1, 1}, + {1, 216, 3, 1, 2}, + {1, 432, 2, 3, 1}, + {2, 216, 1, 1, 1}}}, // target - {{{1, 3}, {216, 432}, {1, 4}, {1, 4}, {1, 4}}, // dynamic - {{3, 216, 2, 2, 2}, {1, 432, 1, 1, 1}}}, // target + {{{1, 3}, {216, 432}, {1, 4}, {1, 4}, {1, 4}}, // dynamic + {{3, 216, 2, 2, 2}, {1, 432, 1, 1, 1}, {3, 216, 2, 2, 2}}}, // target }; const std::vector inputShapesBlocked5D = { - {{-1, 256, -1, -1, -1}, // dynamic - {{1, 256, 1, 1, 1}, {1, 256, 2, 1, 4}, {3, 256, 4, 1, 2}}}, // target + {{-1, 256, -1, -1, -1}, // dynamic + {{1, 256, 1, 1, 1}, {1, 256, 2, 1, 4}, {3, 256, 4, 1, 2}, {1, 256, 1, 1, 1}}}, // target - {{{1, 3}, 256, {1, 3}, {1, 3}, {1, 3}}, // dynamic - {{1, 256, 1, 1, 1}, {1, 256, 2, 1, 3}, {3, 256, 3, 1, 2}}}, // target + {{{1, 3}, 256, {1, 3}, {1, 3}, {1, 3}}, // dynamic + {{1, 256, 1, 1, 1}, {1, 256, 2, 1, 3}, {3, 256, 3, 1, 2}, {1, 256, 2, 1, 3}}}, // target }; INSTANTIATE_TEST_SUITE_P(smoke_CPUDepthToSpaceDynamic4D, DepthToSpaceLayerCPUTest, @@ -285,7 +287,7 @@ INSTANTIATE_TEST_SUITE_P(smoke_CPUDepthToSpaceDynamicCPUSpecific5D, DepthToSpace testing::ValuesIn(filterCPUInfoForDevice(CPUParamsBlocked5D))), DepthToSpaceLayerCPUTest::getTestCaseName); -} // namespace dynamic_shapes +} // namespace dynamic_shapes /* *========================* *==================* *========================* */ } // namespace