diff --git a/inference-engine/src/vpu/graph_transformer/include/vpu/middleend/allocator/allocator.hpp b/inference-engine/src/vpu/graph_transformer/include/vpu/middleend/allocator/allocator.hpp index 359ea80e248..0b4afd90ee6 100644 --- a/inference-engine/src/vpu/graph_transformer/include/vpu/middleend/allocator/allocator.hpp +++ b/inference-engine/src/vpu/graph_transformer/include/vpu/middleend/allocator/allocator.hpp @@ -126,6 +126,8 @@ private: DataMap _memChunksPerData; + std::map, int> _staticShapeOffsets; + int _blobMemOffset = 0; int _inputMemOffset = 0; int _outputMemOffset = 0; diff --git a/inference-engine/src/vpu/graph_transformer/include/vpu/model/data_desc.hpp b/inference-engine/src/vpu/graph_transformer/include/vpu/model/data_desc.hpp index f200a16d73e..f713faecb0c 100644 --- a/inference-engine/src/vpu/graph_transformer/include/vpu/model/data_desc.hpp +++ b/inference-engine/src/vpu/graph_transformer/include/vpu/model/data_desc.hpp @@ -338,8 +338,8 @@ public: if (_flags[ind] != other._flags[ind]) { return !_flags[ind]; } - if (_flags[ind] && _values[ind].second < other._values[ind].second) { - return true; + if (_flags[ind] && _values[ind].second != other._values[ind].second) { + return _values[ind].second < other._values[ind].second; } } return false; diff --git a/inference-engine/src/vpu/graph_transformer/src/middleend/allocator/allocator.cpp b/inference-engine/src/vpu/graph_transformer/src/middleend/allocator/allocator.cpp index 4ac2a762c8a..12f86885665 100644 --- a/inference-engine/src/vpu/graph_transformer/src/middleend/allocator/allocator.cpp +++ b/inference-engine/src/vpu/graph_transformer/src/middleend/allocator/allocator.cpp @@ -316,8 +316,18 @@ ShapeLocation Allocator::allocateShape(const Data& data) { } else { // Static allocation shapeLocation.dimsLocation = Location::Blob; - shapeLocation.dimsOffset = _blobMemOffset; - _blobMemOffset += dimsByteSize; + + // Prevent allocation of same shapes multiple times + auto dimOrder = data->desc().dimsOrder().toPermutation(); + auto dimValues = data->desc().dims(); + auto itr = _staticShapeOffsets.find({dimOrder, dimValues}); + if (itr != _staticShapeOffsets.end()) { + shapeLocation.dimsOffset = itr->second; + } else { + shapeLocation.dimsOffset = _blobMemOffset; + _blobMemOffset += dimsByteSize; + _staticShapeOffsets.insert({{dimOrder, dimValues}, shapeLocation.dimsOffset}); + } }