[IE][VPU]: Reduces memory consumption by temporary buffers (#2317)
authorAndrey Sokolov <andrey.sokolov@intel.com>
Thu, 24 Sep 2020 09:27:44 +0000 (12:27 +0300)
committerGitHub <noreply@github.com>
Thu, 24 Sep 2020 09:27:44 +0000 (12:27 +0300)
inference-engine/src/vpu/graph_transformer/include/vpu/model/model.hpp
inference-engine/src/vpu/graph_transformer/src/middleend/passes/sw_conv_adaptation.cpp
inference-engine/src/vpu/graph_transformer/src/model/model.cpp
inference-engine/src/vpu/graph_transformer/src/stages/custom.cpp
inference-engine/src/vpu/graph_transformer/src/stages/detection_output.cpp
inference-engine/src/vpu/graph_transformer/src/stages/proposal.cpp
inference-engine/src/vpu/graph_transformer/src/stages/rnn.cpp
inference-engine/src/vpu/graph_transformer/src/stages/roi_feature_extractor.cpp

index 72493f3a3d6ecd8c2c15676fd7359a1ce97a9da8..f102418d4ded7b4554729954c80c378dce070f65 100644 (file)
@@ -146,6 +146,10 @@ public:
             const Stage& stage,
             const DataDesc& desc);
 
+    StageTempBuffer addTempBuffer(
+            const Stage& stage,
+            size_t bufferSize);
+
     void replaceStageInput(
             const StageInput& edge,
             const Data& newInput);
index 340e2bd6dbbdb4c2dc5aa63e98910b2221c30fd4..5d3571059f39ee59e06a2423450d7e8333f223a5 100644 (file)
@@ -134,8 +134,8 @@ private:
                         std::make_shared<ConvIm2ColWeightsContent>(weights->content(), newWeightsDesc));
 
                     double im2ColBufSizeF = static_cast<double>(kernelSizeX) * kernelSizeY *
-                        output->desc().dim(Dim::W) * output->desc().dim(Dim::H) * input->desc().dim(Dim::C)
-                        + 32;
+                        output->desc().dim(Dim::W) * output->desc().dim(Dim::H) * input->desc().dim(Dim::C) * sizeof(int16_t)
+                        + 64;
 
                     if (im2ColBufSizeF >= std::numeric_limits<int>::max()) {
                         VPU_THROW_EXCEPTION << "stage: " << name() << ", im2col bufferSize cannot fit 32s: "
@@ -144,7 +144,7 @@ private:
                             << output->desc().dim(Dim::W) << "x" << output->desc().dim(Dim::H) << "x" << output->desc().dim(Dim::C) << ")";
                     }
 
-                    model()->addTempBuffer(this, DataDesc({static_cast<int>(im2ColBufSizeF)}));
+                    model()->addTempBuffer(this, static_cast<int>(im2ColBufSizeF));
                 }
 
                 weights->attrs().set<Data>("swWeights", swWeights);
index 7ea7c71716b9af913b365a6a82390905fd874c88..5ee74b01d5d4367e1d6c0000b460d2fa95129f62 100644 (file)
@@ -423,6 +423,13 @@ StageDependency ModelObj::addStageDependency(const Stage& stage, const Data& dat
     return edge;
 }
 
+StageTempBuffer ModelObj::addTempBuffer(
+        const Stage& stage,
+        size_t bufferSize) {
+    auto desc = DataDesc(DataType::U8, DimsOrder::C, {bufferSize});
+    return addTempBuffer(stage, desc);
+}
+
 StageTempBuffer ModelObj::addTempBuffer(
         const Stage& stage,
         const DataDesc& desc) {
index ef8f59cac8a0f4ac26e4f379ca977d82705a5812..cf71b2c6522a9c74634215b28863889f47c29646 100644 (file)
@@ -478,9 +478,7 @@ void FrontEnd::parseCustom(const Model& model, const ie::CNNLayerPtr& layer, con
         stage->attrs().set("outputOrders", std::move(outputOrders));
 
         int buffer_size = kernel.kernelBinary().length() + 1024;
-        model->addTempBuffer(
-            stage,
-            DataDesc({buffer_size}));
+        model->addTempBuffer(stage, buffer_size);
     }
 }
 
index 4ac7fbb5a30e8a527288de3c8bf693906fd74137..180a0ac8486c5bf8d08b9a1e72067a1189d889ad 100644 (file)
@@ -240,7 +240,7 @@ void FrontEnd::parseDetectionOutput(const Model& model, const ie::CNNLayerPtr& l
         size_num_priors_actual_buf +
         size_temp_data_buf;
 
-    model->addTempBuffer(stage, DataDesc({buffer_size}));
+    model->addTempBuffer(stage, buffer_size);
 }
 
 }  // namespace vpu
index f41a363a1f8833be8e61788579d63c302329f1de..103363dea89259290431d21f57741412d6371332 100644 (file)
@@ -183,9 +183,7 @@ void FrontEnd::parseProposal(const Model& model, const ie::CNNLayerPtr& layer, c
     const auto& env = CompileEnv::get();
     const int required_cmx_buffer_size = env.resources.numSHAVEs * required_cmx_size_per_shave;
 
-    model->addTempBuffer(
-        stage,
-        DataDesc({buffer_size + required_cmx_buffer_size}));
+    model->addTempBuffer(stage, buffer_size + required_cmx_buffer_size);
 }
 
 }  // namespace vpu
index e108a0eeaa2f95dff501e2a7cfee92a81d20614d..c5a21e89b60c7c79df81f27db4a507b390ff43ff 100644 (file)
@@ -211,7 +211,7 @@ void FrontEnd::parseRNN(const Model& model, const ie::CNNLayerPtr& _layer, const
         outputData);
 
     if (nCells > 1)
-        model->addTempBuffer(stage, DataDesc({stateSize}));
+        model->addTempBuffer(stage, sizeof(uint16_t) * stateSize);
 
     bool RNNForward = layer->direction == ie::RNNSequenceLayer::FWD;
     stage->attrs().set<bool>("RNNForward", RNNForward);
index 747aeddafae9658ad3b454b10f03b763411cd642..02df408f0627fb326b528702e8d0618bb82b6050 100644 (file)
@@ -149,7 +149,7 @@ void FrontEnd::parseROIFeatureExtractor(const Model& model, const ie::CNNLayerPt
                       size_dummy_mapping_buf +
                       size_repacked_buf;
 
-    model->addTempBuffer(stage, DataDesc({buffer_size}));
+    model->addTempBuffer(stage, buffer_size);
 }
 
 }  // namespace vpu