9615f22b0788277489eab88d8250952ab1caa1ef
[platform/upstream/dldt.git] / inference-engine / src / inference_engine / graph_tools.cpp
1 // Copyright (C) 2018 Intel Corporation
2 //
3 // SPDX-License-Identifier: Apache-2.0
4 //
5
6 #include "graph_tools.hpp"
7 #include "details/ie_cnn_network_tools.h"
8 #include <vector>
9
10 using namespace std;
11
12 namespace InferenceEngine {
13 namespace details {
14
15 std::vector<CNNLayerPtr> CNNNetSortTopologically(const ICNNNetwork & network) {
16     std::vector<CNNLayerPtr> stackOfVisited;
17     bool res = CNNNetForestDFS(CNNNetGetAllInputLayers(network), [&](CNNLayerPtr  current){
18         stackOfVisited.push_back(current);
19     }, false);
20
21     if (!res) {
22         THROW_IE_EXCEPTION << "Sorting not possible, due to existed loop.";
23     }
24
25     std::reverse(std::begin(stackOfVisited), std::end(stackOfVisited));
26
27     return stackOfVisited;
28 }
29
30 }   // namespace details
31 }  // namespace InferenceEngine