[CPU] Fixes for CpuBlockedMemoryDesc constructor and reorder availability checks (#10299)
This commit is contained in:
@@ -8,21 +8,15 @@
|
||||
|
||||
using namespace MKLDNNPlugin;
|
||||
|
||||
CpuBlockedMemoryDesc::CpuBlockedMemoryDesc(InferenceEngine::Precision prc, const Shape& shape) : MemoryDesc(shape, Blocked), precision(prc) {
|
||||
auto& dims = shape.getDims();
|
||||
order.resize(dims.size());
|
||||
std::iota(order.begin(), order.end(), 0);
|
||||
blockedDims = dims;
|
||||
offsetPadding = 0;
|
||||
offsetPaddingToData.resize(dims.size(), 0);
|
||||
strides.resize(order.size());
|
||||
// for empty tensor case we fill all strides with 0 values
|
||||
strides[strides.size() - 1] = shape.hasZeroDims() ? 0 : 1;
|
||||
for (size_t i = 2; i <= order.size(); i++) {
|
||||
strides[strides.size() - i] = strides[strides.size() - (i - 1)] * blockedDims[blockedDims.size() - (i - 1)];
|
||||
}
|
||||
static VectorDims makeRange(size_t size) {
|
||||
VectorDims retVec(size, 0);
|
||||
std::iota(retVec.begin(), retVec.end(), 0);
|
||||
return retVec;
|
||||
}
|
||||
|
||||
CpuBlockedMemoryDesc::CpuBlockedMemoryDesc(InferenceEngine::Precision prc, const Shape& shape) :
|
||||
CpuBlockedMemoryDesc(prc, shape, shape.getDims(), makeRange(shape.getDims().size())) {}
|
||||
|
||||
CpuBlockedMemoryDesc::CpuBlockedMemoryDesc(InferenceEngine::Precision prc, const Shape& shape, const VectorDims& blockedDims,
|
||||
const VectorDims& order, size_t offsetPadding, const VectorDims& offsetPaddingToData,
|
||||
const VectorDims& strides) : MemoryDesc(shape, Blocked), precision(prc) {
|
||||
|
||||
@@ -459,9 +459,13 @@ void MKLDNNGraph::ExecuteConstantNodesOnly() const {
|
||||
}
|
||||
}
|
||||
|
||||
static bool isReorderAvailable(const MemoryDesc& parentDesc, const MemoryDesc& childDesc, const mkldnn::engine& eng) {
|
||||
memory::desc dstMemDesc = MemoryDescUtils::convertToDnnlMemoryDesc(childDesc.clone())->getDnnlDesc();
|
||||
memory::desc srcMemDesc = MemoryDescUtils::convertToDnnlMemoryDesc(parentDesc.clone())->getDnnlDesc();
|
||||
static bool isReorderAvailable(const MemoryDescPtr& parentDesc, const MemoryDescPtr& childDesc, const mkldnn::engine& eng) {
|
||||
auto definedParentDesc = parentDesc->isDefined() ? parentDesc : MemoryDescUtils::makeDummyDesc(*parentDesc);
|
||||
memory::desc srcMemDesc = MemoryDescUtils::convertToDnnlMemoryDesc(definedParentDesc)->getDnnlDesc();
|
||||
|
||||
auto definedChildDesc = childDesc->isDefined() ? childDesc : MemoryDescUtils::makeDummyDesc(*childDesc);
|
||||
memory::desc dstMemDesc = MemoryDescUtils::convertToDnnlMemoryDesc(definedChildDesc)->getDnnlDesc();
|
||||
|
||||
mkldnn::primitive_attr attr;
|
||||
|
||||
dnnl_primitive_desc_t result = nullptr;
|
||||
@@ -513,7 +517,9 @@ void MKLDNNGraph::InitEdges() {
|
||||
MKLDNNEdge::ReorderStatus reorderStatusInternal = MKLDNNEdge::ReorderStatus::Regular;
|
||||
// Check if there is a reorder that needs the precision conversion
|
||||
if (edge->getInputDesc().getPrecision() != edge->getOutputDesc().getPrecision() &&
|
||||
!isReorderAvailable(edge->getInputDesc(), edge->getOutputDesc(), this->getEngine())) {
|
||||
!isReorderAvailable(edge->getInputPortDesc()->getMemDesc(),
|
||||
edge->getOutputPortDesc()->getMemDesc(),
|
||||
this->getEngine())) {
|
||||
// If we are here, then we need to insert Convert, because there are no reorders that support such type conversion
|
||||
const auto& inDesc = edge->getInputDesc();
|
||||
const auto& outDesc = edge->getOutputDesc();
|
||||
|
||||
Reference in New Issue
Block a user