[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:
Luwei Zhou authored and GitHub committed 2022-01-12 11:43:24 +03:00
1 parent 4546df5091
commit 84bf5fa178
3 files changed
+69 -31

No files matched your search

@@ -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);