Cnnnetwork deprecated methods (#1077)
[platform/upstream/dldt.git] / inference-engine / src / gna_plugin / layers / gna_layer_type.cpp
1 // Copyright (C) 2018-2020 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
3 //
4
5 #include <string>
6 #include <unordered_set>
7 #include <ie_icnn_network.hpp>
8 #include <graph_tools.hpp>
9 #include "gna_layer_type.hpp"
10 #include "gna_layer_info.hpp"
11
12 GNAPluginNS::LayerType GNAPluginNS::LayerTypeFromStr(const std::string &str) {
13     auto it = LayerNameToType.find(str);
14     if (it != LayerNameToType.end())
15         return it->second;
16     else
17         return NO_TYPE;
18 }
19
20 bool GNAPluginNS::AreLayersSupported(InferenceEngine::ICNNNetwork& network, std::string& errMessage) {
21     IE_SUPPRESS_DEPRECATED_START
22     InferenceEngine::CNNLayerSet inputLayers;
23     InferenceEngine::InputsDataMap inputs;
24     std::unordered_set<InferenceEngine::CNNLayer *> allLayers;
25     network.getInputsInfo(inputs);
26     IE_ASSERT(!inputs.empty());
27     auto network_input_precision = inputs.begin()->second->getPrecision();
28     auto batch_size = network.getBatchSize();
29
30     if (network_input_precision != InferenceEngine::Precision::FP32 &&
31         network_input_precision != InferenceEngine::Precision::I16 &&
32         network_input_precision != InferenceEngine::Precision::U8) {
33         errMessage = "The plugin does not support input precision with " + std::string(network_input_precision.name()) + " format. Supported  input precisions "
34                                                                                                                          "FP32, I16, U8\n";
35         return false;
36     }
37
38     if (inputs.empty()) {
39         errMessage = "Network is empty (GNA)\n";
40         return false;
41     }
42
43     auto & secondLayers = inputs.begin()->second->getInputData()->getInputTo();
44     if (secondLayers.empty()) {
45         errMessage = "Network consists of input layer only (GNA)\n";
46         return false;
47     }
48
49     bool check_result = true;
50     InferenceEngine::details::UnorderedDFS(allLayers,
51                                            secondLayers.begin()->second,
52                                            [&](const InferenceEngine::CNNLayerPtr layer) {
53                                                if (LayerTypeFromStr(layer->type) == LayerType::NO_TYPE) {
54                                                    errMessage = "The plugin does not support layer: " + layer->name + ":" + layer->type + "\n";
55                                                    check_result =  false;
56                                                }
57                                                if (batch_size != 1 && LayerInfo::isBatchSizeConstrained(layer->type)) {
58                                                    errMessage = "topology with layer: " + layer->name + ", type: " + layer->type +
59                                                                 ", and batch size(" + std::to_string(batch_size) + ") != 1 not supported";
60                                                    check_result =  false;
61                                                }
62                                            }, false);
63     IE_SUPPRESS_DEPRECATED_END
64     return check_result;
65 }