Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / src / inference_engine / shape_infer / const_infer / ie_concat_const_infer.hpp
1 // Copyright (C) 2019 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
3 //
4
5 #pragma once
6
7 #include <ie_blob.h>
8 #include <map>
9 #include <memory>
10 #include <string>
11 #include <vector>
12 #include <ie_layers.h>
13 #include <ie_memcpy.h>
14 #include "ie_const_infer_impl.hpp"
15
16 namespace InferenceEngine {
17 namespace ShapeInfer {
18
19 /**
20  *@brief Implementation of Const inference for Tile layer
21  */
22 class ConcatConstInfer : public ConstInferImpl {
23 public:
24     explicit ConcatConstInfer(const std::string& type) : ConstInferImpl(type) {}
25
26     void inferImpl(const std::vector<Blob::CPtr>& inData,
27                    const std::map<std::string, std::string>& params,
28                    const std::map<std::string, Blob::Ptr>& blobs,
29                    std::vector<Blob::Ptr>& outData) override {
30         LayerParams lp{};
31         ConcatLayer layer(lp);
32         layer.params = params;
33         layer.type = _type;
34         _validator->parseParams(&layer);
35
36         auto outBlob = *outData.begin();
37         SizeVector outShape = outBlob->getTensorDesc().getDims();
38         auto* outBuffer = outBlob->buffer().as<float*>();
39
40         size_t outerSize = 1;
41         for (int i = 0; i < layer._axis; i++)
42             outerSize *= outShape[i];
43
44         size_t outIdx = 0;
45         for (size_t osIdx = 0; osIdx < outerSize; osIdx++) {
46             for (auto& inBlob : inData) {
47                 const auto* inBuffer = inBlob->cbuffer().as<float*>();
48                 size_t innerSize = inBlob->size() / outerSize;
49
50                 for (size_t j = 0; j < innerSize; j++, outIdx++) {
51                     outBuffer[outIdx] = inBuffer[osIdx * innerSize + j];
52                 }
53             }
54         }
55     }
56 };
57
58 }  // namespace ShapeInfer
59 }  // namespace InferenceEngine