[CPU] Enable CPU plugin cache for DepthToSpace. (#9492)
* Enable CPU plugin RT cache for DepthToSpace. * Applied review comments. * Applied review comments. * Apply reivew comments.
This commit is contained in:
parent
4546df5091
commit
84bf5fa178
@ -4,14 +4,16 @@
|
||||
|
||||
#include "mkldnn_depth_to_space_node.h"
|
||||
|
||||
#include <cpu/x64/jit_generator.hpp>
|
||||
#include <mkldnn_extension_utils.h>
|
||||
#include "common/blocked_desc_creator.h"
|
||||
#include <utils/general_utils.h>
|
||||
#include <ngraph/opsets/opset1.hpp>
|
||||
|
||||
#include <string>
|
||||
#include <cmath>
|
||||
#include <common/primitive_hashing_utils.hpp>
|
||||
#include <cpu/x64/jit_generator.hpp>
|
||||
#include <ngraph/opsets/opset1.hpp>
|
||||
#include <string>
|
||||
|
||||
#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<const ngraph::Node>& op, std::string& errorMessage) noexcept {
|
||||
try {
|
||||
auto depthToSpace = ov::as_type_ptr<const ngraph::opset1::DepthToSpace>(op);
|
||||
@ -157,7 +184,17 @@ void MKLDNNDepthToSpaceNode::createPrimitive() {
|
||||
|
||||
void MKLDNNDepthToSpaceNode::prepareParams() {
|
||||
attrs.srcBlockedDims = getParentEdgeAt(0)->getMemoryPtr()->GetDescWithType<BlockedMemoryDesc>()->getBlockDims();
|
||||
execPtr = std::make_shared<DepthToSpaceExecutor>(attrs);
|
||||
auto builder = [](const DepthToSpaceAttrs& key) -> std::shared_ptr<DepthToSpaceExecutor> {
|
||||
return std::make_shared<DepthToSpaceExecutor>(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) {
|
||||
|
@ -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);
|
||||
|
@ -209,35 +209,37 @@ INSTANTIATE_TEST_SUITE_P(smoke_CPUDepthToSpaceStaticBS3_5D, DepthToSpaceLayerCPU
|
||||
} // namespace static_shapes
|
||||
/* *========================* *==================* *========================* */
|
||||
|
||||
|
||||
/* *========================* Dynamic Shapes Tests *========================* */
|
||||
namespace dynamic_shapes {
|
||||
|
||||
const std::vector<InputShape> inputShapes4D = {
|
||||
{{-1, -1, -1, -1}, // dynamic
|
||||
{{2, 36, 1, 1}, {1, 36, 3, 1}, {1, 72, 1, 4}}}, // target
|
||||
{{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}, {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
|
||||
{{3, 36, 4, 4}, {1, 36, 16, 12}, {3, 72, 8, 8}, {1, 36, 16, 12}}}, // target
|
||||
};
|
||||
|
||||
const std::vector<InputShape> inputShapes5D = {
|
||||
{{-1, -1, -1, -1, -1}, // dynamic
|
||||
{{2, 216, 1, 1, 1}, {1, 216, 3, 1, 2}, {1, 432, 2, 3, 1}}}, // target
|
||||
{{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
|
||||
{{3, 216, 2, 2, 2}, {1, 432, 1, 1, 1}, {3, 216, 2, 2, 2}}}, // target
|
||||
};
|
||||
|
||||
const std::vector<InputShape> 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}, {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, 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,
|
||||
|
Loading…
Reference in New Issue
Block a user