From 935549035e61da951f451c4035bc22e7a592d437 Mon Sep 17 00:00:00 2001 From: George Zlobin Date: Mon, 21 Dec 2020 15:21:19 +0300 Subject: [PATCH] [IE][VPU]: Shape compression (#3500) * This change prevents saving the same shapes in a blob. If more than one data have the same shapes, only one will be saved in the blob. --- .../include/vpu/middleend/allocator/allocator.hpp | 2 ++ .../include/vpu/model/data_desc.hpp | 4 ++-- .../src/middleend/allocator/allocator.cpp | 14 ++++++++++++-- 3 files changed, 16 insertions(+), 4 deletions(-) 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}); + } }