Skip to content

Commit

Permalink
Review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
vladislav-volkov committed May 25, 2021
1 parent bdadc3e commit 10f6c7c
Show file tree
Hide file tree
Showing 9 changed files with 120 additions and 177 deletions.
2 changes: 1 addition & 1 deletion inference-engine/src/mkldnn_plugin/mkldnn_graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ void MKLDNNGraph::AllocateWithReuse() {
&& edge->getParent()->isConstant()) {
if (edge->getParent()->getType() == Input) {
auto constNode = std::static_pointer_cast<MKLDNNInputNode>(edge->getParent());
edge->reuse(constNode->getMemoryPtr());
edge->reuse(std::const_pointer_cast<MKLDNNMemory>(constNode->getMemoryPtr()));
} else {
edge->externalAllocate(weightsCache);
}
Expand Down
8 changes: 4 additions & 4 deletions inference-engine/src/mkldnn_plugin/mkldnn_graph_optimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -478,11 +478,11 @@ void MKLDNNGraphOptimizer::FuseConvolutionAndZeroPoints(MKLDNNGraph &graph) {
if (zeroPointsConstant == nullptr)
IE_THROW() << "Cannot cast to Input node";

auto zeroPointsBlob = dynamic_cast<const TBlob<uint8_t>*>(zeroPointsConstant->getConstBlob().get());
auto zeroPointsBlob = zeroPointsConstant->getMemoryPtr();
if (zeroPointsBlob == nullptr)
IE_THROW() << "Cannot cast to TBlob internal zero points blob";

auto zeroPointsData = zeroPointsBlob->cbuffer().as<uint8_t*>();
auto zeroPointsData = static_cast<const uint8_t*>(zeroPointsBlob->GetPtr());
if (zeroPointsData == nullptr)
IE_THROW() << "zeroPointsBlob has not allocated buffer";

Expand Down Expand Up @@ -515,11 +515,11 @@ void MKLDNNGraphOptimizer::FuseConvolutionAndZeroPoints(MKLDNNGraph &graph) {
if (!weightsConstant || !weightsConstant->isConstant())
return;

auto weightsBlob = dynamic_cast<const TBlob<int8_t>*>(weightsConstant->getConstBlob().get());
auto weightsBlob = weightsConstant->getMemoryPtr();
if (weightsBlob == nullptr)
IE_THROW() << "Cannot cast to TBlob internal weights blob";

auto weightsPtr = weightsBlob->cbuffer().as<int8_t*>();
auto weightsPtr = static_cast<const int8_t*>(weightsBlob->GetPtr());
if (weightsPtr == nullptr)
IE_THROW() << "weightsBlob has not allocated buffer";

Expand Down
1 change: 1 addition & 0 deletions inference-engine/src/mkldnn_plugin/mkldnn_memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,5 +172,6 @@ class MKLDNNMemory {
};

using MKLDNNMemoryPtr = std::shared_ptr<MKLDNNMemory>;
using MKLDNNMemoryCPtr = std::shared_ptr<const MKLDNNMemory>;

} // namespace MKLDNNPlugin
12 changes: 8 additions & 4 deletions inference-engine/src/mkldnn_plugin/mkldnn_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1345,10 +1345,14 @@ void MKLDNNNode::fillScalesAndShifts(const MKLDNNNode *parentNode, std::vector<f
shifts.clear();
const auto fillValuesFrom = [&](const MKLDNNNodePtr& constInput, std::vector<float>& buffer) {
auto *constInputNode = dynamic_cast<MKLDNNInputNode *>(constInput.get());
auto constBlob = constInputNode->getConstBlob();
auto srtPtr = constBlob->cbuffer().as<int8_t *>();
buffer.resize(constBlob->size());
cpu_convert(srtPtr, &buffer[0], constBlob->getTensorDesc().getPrecision(), Precision::FP32, constBlob->size());
auto constBlob = constInputNode->getMemoryPtr();
auto const elementsCount = constBlob->GetElementsCount();
buffer.resize(elementsCount);
cpu_convert(constBlob->GetPtr(),
&buffer[0],
MKLDNNExtensionUtils::DataTypeToIEPrecision(constBlob->GetDataType()),
Precision::FP32,
elementsCount);
};

const size_t constPort = getParentEdgesAtPort(0)[0]->getParent().get() == parentNode ? 1 : 0;
Expand Down
10 changes: 6 additions & 4 deletions inference-engine/src/mkldnn_plugin/nodes/mkldnn_deconv_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,12 @@ InferenceEngine::Blob::Ptr MKLDNNDeconvolutionNode::createWeiBlobAsIO(InferenceE
auto constNode = std::dynamic_pointer_cast<MKLDNNInputNode>(getParentEdgeAt(1)->getParent());
if (!constNode)
IE_THROW() << "Cannot cast const input node for node " << getName() << ".";
auto blb = constNode->getConstBlob();
auto blb = constNode->getMemoryPtr();
if (!blb)
IE_THROW() << "Cannot get const weights blob for node " << getName() << ".";

auto const blbSize = blb->GetSize();

// WA: In int8 case, we are processing weights using internal blob.
// So we disconnect constant node containing weights from the graph and then don't use it.
if (getParentEdges().size() == 3) {
Expand All @@ -123,7 +125,7 @@ InferenceEngine::Blob::Ptr MKLDNNDeconvolutionNode::createWeiBlobAsIO(InferenceE
orderForBlockedDesc.push_back(i);

BlockingDesc blkDesc(dimsForBlockedDesc, orderForBlockedDesc);
InferenceEngine::TensorDesc tensorDesc(blb->getTensorDesc().getPrecision(), dims, blkDesc);
InferenceEngine::TensorDesc tensorDesc(MKLDNNExtensionUtils::DataTypeToIEPrecision(blb->GetDataType()), dims, blkDesc);

Blob::Ptr internalBlob = InferenceEngine::make_shared_blob<int8_t>(tensorDesc);
internalBlob->allocate();
Expand All @@ -132,11 +134,11 @@ InferenceEngine::Blob::Ptr MKLDNNDeconvolutionNode::createWeiBlobAsIO(InferenceE
IE_THROW(NotAllocated) << "Internal blob was not allocated for node " << getName() << ".";
size_t intBuffSize = internalBlob->byteSize();

size_t offset = blb->byteSize();
size_t offset = blbSize;
if (intBuffSize < offset) {
IE_THROW() << "Cannot create internal buffer. Buffer can be overrun.";
}
cpu_memcpy_s(data, intBuffSize, blb->cbuffer(), blb->byteSize());
cpu_memcpy_s(data, intBuffSize, blb->GetPtr(), blbSize);

return internalBlob;
}
Expand Down
Loading

0 comments on commit 10f6c7c

Please sign in to comment.