Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into old_api_map_trans…
Browse files Browse the repository at this point in the history
…poses_insertion
  • Loading branch information
popovaan committed Oct 7, 2021
2 parents a44c65b + ec126c6 commit a3d36a8
Show file tree
Hide file tree
Showing 188 changed files with 10,078 additions and 2,058 deletions.
2 changes: 0 additions & 2 deletions .ci/azure/linux_coverity.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,6 @@ jobs:
-DENABLE_PYTHON=ON
-DPYTHON_EXECUTABLE=/usr/bin/python3.8
-DENABLE_WHEEL=ON
# Skipping tests from static analysis
# -DENABLE_TESTS=ON
-DNGRAPH_ONNX_FRONTEND_ENABLE=ON
-DENABLE_FASTER_BUILD=ON
-DENABLE_STRICT_DEPENDENCIES=OFF
Expand Down
13 changes: 1 addition & 12 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ inference-engine/report
docs/template_plugin/html/
CMakeLists.txt.user
docs/IE_PLUGIN_DG/html/
inference-engine/ie_bridges/python/wheel/.env

*.project
*.cproject
Expand Down Expand Up @@ -57,15 +58,3 @@ __pycache__
/model-optimizer/*.mapping
/model-optimizer/*.dat
/model-optimizer/*.svg

# ngraph
ngraph/src/CPackConfig.cmake
ngraph/src/CPackSourceConfig.cmake
ngraph/src/VERSION
ngraph/src/gtest/
ngraph/src/json/
ngraph/src/ngraphConfig.cmake
ngraph/src/ngraphConfigVersion.cmake
ngraph/src/protobuf/
ngraph/src/src/
ngraph/src/test/
368 changes: 368 additions & 0 deletions docs/template_plugin/tests/functional/op_reference/if.cpp

Large diffs are not rendered by default.

1,007 changes: 1,007 additions & 0 deletions docs/template_plugin/tests/functional/op_reference/scatter_update.cpp

Large diffs are not rendered by default.

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions inference-engine/cmake/vpu_dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ include_guard(GLOBAL)

set(VPU_SUPPORTED_FIRMWARES usb-ma2x8x pcie-ma2x8x)
set(VPU_SUPPORTED_FIRMWARES_HASH
"54a732b5fb17a0124652bc5113fa628c718a5af40621bca309471cb5ffd9271b"
"5750b2831c77ef54b8e243d3840c5ed1c9509681d55aee7e369d558cef628735")
"bd0a40b82b1e024f99a175c0c967a61647d790a42a546b3f0ce8562107dc13dc"
"74efa0bb416ead2238878862aeca2f80d91268efb4859e09594536ef15908d0e")

#
# Default packages
#

set(FIRMWARE_PACKAGE_VERSION 1717)
set(FIRMWARE_PACKAGE_VERSION 1774)
set(VPU_CLC_MA2X8X_VERSION "movi-cltools-20.09.2")

#
Expand Down
4 changes: 0 additions & 4 deletions inference-engine/src/gna_plugin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,6 @@ target_compile_definitions(${TARGET_NAME}

ie_add_api_validator_post_build_step(TARGET ${TARGET_NAME})

if(CMAKE_COMPILER_IS_GNUCXX AND NOT CMAKE_CROSSCOMPILING)
target_link_options(${TARGET_NAME} PRIVATE -Wl,--unresolved-symbols=ignore-all)
endif()

#
# Static version for tests
#
Expand Down
64 changes: 33 additions & 31 deletions inference-engine/src/gna_plugin/backend/am_intel_dnn.cpp

Large diffs are not rendered by default.

15 changes: 11 additions & 4 deletions inference-engine/src/gna_plugin/frontend/layer_quantizer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -653,11 +653,18 @@ class DataQuantizer<Desc, InferenceEngine::WeightableLayer *> : public DataQuant

void operator()(InferenceEngine::WeightableLayer *wl, const FakeQuant&) const {
auto quantData = InferenceEngine::getInjectedData<QuantizedLayerParams>(*wl);
IE_ASSERT(quantData->_weights_quant.IsStatsSet());
if (quantData->_weights_quant.GetLevels() <= std::numeric_limits<uint8_t>::max()) {
quantizeWeightsBiases<FakeQuantI8>(FakeQuantI8(), wl, Quant<FakeQuantI8>());
if (quantData->_weights_quant.IsStatsSet()) {
if (quantData->_weights_quant.GetLevels() <= std::numeric_limits<uint8_t>::max()) {
quantizeWeightsBiases<FakeQuantI8>(FakeQuantI8(), wl, Quant<FakeQuantI8>());
} else {
quantizeWeightsBiases<FakeQuantI16>(FakeQuantI16(), wl, Quant<FakeQuantI16>());
}
} else {
quantizeWeightsBiases<FakeQuantI16>(FakeQuantI16(), wl, Quant<FakeQuantI16>());
if (std::is_same<typename Desc::OptionalType, FakeQuant>()) {
THROW_GNA_EXCEPTION << "Infinite recursion. The type Desc::OptionalType is equal FakeQuant.";
}

(*this)(wl, typename Desc::OptionalType());
}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1354,6 +1354,12 @@ class ScaleFactorCalculator {
} else {
return frontend::FakeQuantI16().getWeightsPrecision().size();
}
} else {
if (!info.isSynthetic()) {
gnawarn() << "The layer (" << ptr->name << ") has not quantization statistics\n";
}

return GetOptionalWeightsBytesSize();
}
}

Expand Down
4 changes: 4 additions & 0 deletions inference-engine/src/gna_plugin/layers/gna_layer_info.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,10 @@ class LayerInfo {
return isConcatAlignFilter() || isSyntheticScaleShift() || isCropAffined();
}

bool isSynthetic() const noexcept {
return isConcatAlignFilter() || isSyntheticScaleShift() || isConvolutionFilter() || isAffineFilter();
}

size_t paddingSize() const {
static InferenceEngine::details::caseless_set<std::string> layersWithPossiblePadding = {"FullyConnected",
"InnerProduct",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ static bool InsertReshape(
const std::shared_ptr<ngraph::Node>& matmul2,
const std::shared_ptr<ngraph::Node>& add1 = nullptr,
const std::shared_ptr<ngraph::Node>& add2 = nullptr,
const std::shared_ptr<ngraph::Node>& fake_quantize2 = nullptr,
const std::shared_ptr<ngraph::Node>& fake_quantize = nullptr,
const std::shared_ptr<ngraph::Node>& transpose = nullptr) {
const auto& pattern_map = matcher.get_pattern_value_map();
size_t matmul_input_index = 1;
Expand All @@ -41,38 +41,58 @@ static bool InsertReshape(
}

std::shared_ptr<ngraph::Node> matmul_node = iter->second.get_node_shared_ptr();
auto matmul_node_shape = matmul_node->get_output_shape(0);
if ((iter = pattern_map.find(input)) == std::end(pattern_map)) {
return false;
}

std::shared_ptr<ngraph::Node> first_node = iter->second.get_node_shared_ptr();
auto first_node = iter->second.get_node_shared_ptr();
std::vector<std::shared_ptr<ngraph::Node>> nodes = { matmul_node };
for (auto node : {add2, add1, fake_quantize, transpose}) {
iter = pattern_map.find(node);
if (iter != pattern_map.end()) {
nodes.push_back(iter->second.get_node_shared_ptr());
}
}

auto last_node_shape = nodes.back()->get_output_shape(0);
auto reshape_input_node = std::dynamic_pointer_cast<ngraph::opset8::Reshape>(first_node);
bool need_reshape_before = !reshape_input_node || reshape_input_node->get_output_shape(0).size() != 2;
if (need_reshape_before) {
auto input_shape = first_node->get_output_shape(0);
std::vector<size_t> before_shape(2, 1);
std::copy_if(input_shape.begin(), input_shape.end(), before_shape.begin(), [](size_t e) { return e > 1; });
std::vector<int> before_shape = {-1, static_cast<int>(first_node->get_output_shape(0).back())};
auto reshape_before_node = std::make_shared<ngraph::opset8::Reshape>(first_node,
std::make_shared<ngraph::opset8::Constant>(ngraph::element::Type_t::i64, ngraph::Shape{before_shape.size()}, before_shape), false);
reshape_before_node->set_friendly_name(matmul_node->get_friendly_name() + "/reshape_before_matmul");
ngraph::copy_runtime_info(first_node, reshape_before_node);
matmul_node->input(matmul_input_index).replace_source_output(reshape_before_node->output(0));
}
if (auto transpose_node = std::dynamic_pointer_cast<ngraph::opset8::Transpose>(nodes.back())) {
nodes.pop_back();
std::reverse(nodes.begin(), nodes.end());
while (!nodes.empty()) {
auto node_copy = nodes.back()->clone_with_new_inputs(nodes.back()->input_values());
ngraph::copy_runtime_info(nodes.back(), node_copy);
ngraph::replace_node(nodes.back(), node_copy);
nodes.pop_back();
}

std::shared_ptr<ngraph::Node> last_node;
iter = pattern_map.find(transpose);
if (iter == pattern_map.end() &&
(iter = pattern_map.find(fake_quantize2)) == pattern_map.end() &&
(iter = pattern_map.find(add1)) == pattern_map.end() &&
(iter = pattern_map.find(add2)) == pattern_map.end()) {
last_node = matmul_node;
} else {
last_node = iter->second.get_node_shared_ptr();
auto transpose_input_shape = transpose_node->input_values()[0].get_node_shared_ptr()->get_output_shape(0);
auto transpose_constant_shape = transpose_node->input_values()[1].get_node_shared_ptr()->get_output_shape(0);
if (std::count_if(transpose_input_shape.begin(), transpose_input_shape.end(), [](size_t n) { return n > 1; }) > 2) {
THROW_GNA_EXCEPTION << "The number of dimensions that are greater than 1 is greater than 2"
<< " for Transpose layer (" << transpose_node->get_friendly_name() << ")."
<< " For this reason, there is no way to determine permutation shape.";
}
std::vector<int> permutation_shape = {1, 0};
auto transpose_node_copy = transpose_node->clone_with_new_inputs(
{transpose_node->input_values()[0],
std::make_shared<ngraph::opset8::Constant>(ngraph::element::Type_t::i64,
ngraph::Shape{permutation_shape.size()}, permutation_shape)});
ngraph::copy_runtime_info(transpose_node, transpose_node_copy);
ngraph::replace_node(transpose_node, transpose_node_copy);
nodes.push_back(transpose_node_copy);
}
}

auto consumers = last_node->output(0).get_target_inputs();
auto last_node_shape = last_node->get_output_shape(0);
auto consumers = nodes.back()->output(0).get_target_inputs();
bool need_reshape_after = false;
for (auto consumer : consumers) {
auto reshape_output_node = dynamic_cast<ngraph::opset8::Reshape*>(consumer.get_node());
Expand All @@ -83,10 +103,11 @@ static bool InsertReshape(
}

if (need_reshape_after) {
auto reshape_after_node = std::make_shared<ngraph::opset8::Reshape>(last_node,
std::make_shared<ngraph::opset8::Constant>(ngraph::element::Type_t::i64, ngraph::Shape{last_node_shape.size()}, last_node_shape), false);
reshape_after_node->set_friendly_name(last_node->get_friendly_name());
ngraph::copy_runtime_info(last_node, reshape_after_node);
auto reshape_after_node = std::make_shared<ngraph::opset8::Reshape>(nodes.back(),
std::make_shared<ngraph::opset8::Constant>(ngraph::element::Type_t::i64,
ngraph::Shape{last_node_shape.size()}, last_node_shape), false);
reshape_after_node->set_friendly_name(nodes.back()->get_friendly_name());
ngraph::copy_runtime_info(nodes.back(), reshape_after_node);
for (auto consumer : consumers) {
consumer.replace_source_output(reshape_after_node);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "ngraph/ngraph.hpp"
#include "ngraph/pass/constant_folding.hpp"
#include "ngraph/pass/manager.hpp"
#include "openvino/core/except.hpp"
#include "transformations/serialize.hpp"
#include "transformations/smart_reshape/set_batch_size.hpp"
#include "transformations/smart_reshape/smart_reshape.hpp"
Expand Down Expand Up @@ -109,6 +110,20 @@ void CNNNetworkNGraphImpl::validateFunctionNames() const {
}
}

ngraph::element::Type details::toLegacyType(const ngraph::element::Type& ngraph_type, bool input) {
if (input) {
return ngraph_type == ngraph::element::f16 ? ngraph::element::f32 : ngraph_type;
} else {
if (ngraph_type == ngraph::element::i64 || ngraph_type == ngraph::element::i32) {
return ngraph::element::i32;
} else if (ngraph_type != ngraph::element::f32) {
return ngraph::element::f32;
}
}

return ngraph_type;
}

CNNNetworkNGraphImpl::CNNNetworkNGraphImpl(const std::shared_ptr<Function>& nGraph,
const std::vector<IExtensionPtr>& exts,
bool newAPI)
Expand All @@ -128,7 +143,7 @@ CNNNetworkNGraphImpl::CNNNetworkNGraphImpl(const std::shared_ptr<Function>& nGra
? Precision::I16
: prc == Precision::FP16 ? Precision::FP32 : static_cast<Precision::ePrecision>(prc);

info->setPrecision(prc);
info->setPrecision(details::convertPrecision(toLegacyType(details::convertPrecision(prc), true)));
}

network.setInputInfo(info);
Expand All @@ -155,12 +170,8 @@ CNNNetworkNGraphImpl::CNNNetworkNGraphImpl(const std::shared_ptr<Function>& nGra
if (!_new_api) {
for (auto& output : _outputData) {
// Convert precision into native format. Be consistent with possible conversion to CNNNetwork later.
if (output.second->getPrecision() == Precision::I64) {
output.second->setPrecision(Precision::I32);
} else if (output.second->getPrecision() != Precision::FP32 &&
output.second->getPrecision() != Precision::I32) {
output.second->setPrecision(Precision::FP32);
}
output.second->setPrecision(details::convertPrecision(
toLegacyType(details::convertPrecision(output.second->getPrecision()), false)));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,13 @@
#include "ngraph/attribute_visitor.hpp"
#include "ngraph/function.hpp"
#include "ngraph/node.hpp"
#include "ngraph/type/element_type.hpp"

namespace InferenceEngine {
namespace details {

ngraph::element::Type toLegacyType(const ngraph::element::Type& ngraph_type, bool input);

IE_SUPPRESS_DEPRECATED_START

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,16 +226,16 @@ void IInferencePlugin::SetExeNetworkInfo(const std::shared_ptr<IExecutableNetwor
exeNetwork->setNetworkInputs(copyInfo(constMapCast(inputs)));
exeNetwork->setNetworkOutputs(copyInfo(constMapCast(outputs)));

ngraph::ParameterVector parameters;
ngraph::ResultVector results;
ov::ParameterVector parameters;
ov::ResultVector results;
std::vector<ngraph::Output<ngraph::Node>> node_outputs;

for (auto&& input : inputs) {
auto tensor_desc = input.second->getTensorDesc();
auto dims = tensor_desc.getDims();
parameters.push_back(
std::make_shared<ngraph::op::v0::Parameter>(details::convertPrecision(tensor_desc.getPrecision()),
std::vector<ov::Dimension>{dims.begin(), dims.end()}));
std::make_shared<ov::op::v0::Parameter>(details::convertPrecision(tensor_desc.getPrecision()),
std::vector<ov::Dimension>{dims.begin(), dims.end()}));
parameters.back()->set_friendly_name(input.first);
node_outputs.push_back(parameters.back()->output(0));
}
Expand All @@ -261,16 +261,16 @@ void IInferencePlugin::SetExeNetworkInfo(const std::shared_ptr<IExecutableNetwor
IE_ASSERT(exeNetwork != nullptr);
IE_ASSERT(function != nullptr);

ngraph::ParameterVector parameters;
ngraph::ResultVector results;
ngraph::NodeVector nodes;
ov::ParameterVector parameters;
ov::ResultVector results;
ov::NodeVector nodes;

std::map<ngraph::Output<ngraph::Node>, ngraph::Output<ngraph::Node>> output_map;

for (auto&& node : function->get_ordered_ops()) {
ngraph::Node* new_node = nullptr;
if (ngraph::is_type<ngraph::op::Parameter>(node)) {
parameters.push_back(std::static_pointer_cast<ngraph::op::v0::Parameter>(node->clone_with_new_inputs({})));
if (ngraph::is_type<ov::op::v0::Parameter>(node)) {
parameters.push_back(std::static_pointer_cast<ov::op::v0::Parameter>(node->clone_with_new_inputs({})));
for (std::size_t i = 0; i < node->outputs().size(); ++i) {
output_map.emplace(node->output(i), parameters.back()->output(i));
}
Expand All @@ -280,7 +280,7 @@ void IInferencePlugin::SetExeNetworkInfo(const std::shared_ptr<IExecutableNetwor
for (auto&& input : node->inputs()) {
outputs.emplace_back(output_map.at(input.get_source_output()));
}
if (ngraph::is_type<ngraph::op::Result>(node)) {
if (ngraph::is_type<ov::op::v0::Result>(node)) {
results.push_back(
std::static_pointer_cast<ngraph::op::v0::Result>(node->clone_with_new_inputs(outputs)));
new_node = results.back().get();
Expand Down
20 changes: 2 additions & 18 deletions inference-engine/src/inference_engine/src/ie_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -450,28 +450,12 @@ class CoreImpl : public ie::ICore, public std::enable_shared_from_this<ie::ICore

ie::CNNNetwork ReadNetwork(const std::string& modelPath, const std::string& binPath) const override {
OV_ITT_SCOPE(FIRST_INFERENCE, ov::itt::domains::IE_RT, "CoreImpl::ReadNetwork from file");
auto cnnNet = InferenceEngine::details::ReadNetwork(modelPath, binPath, extensions);
OPENVINO_ASSERT(cnnNet.getFunction() || !newAPI, "Cannot read IR v7 from OpenVINO 2.0 API");
if (!newAPI)
return cnnNet;

return InferenceEngine::CNNNetwork(std::make_shared<InferenceEngine::details::CNNNetworkNGraphImpl>(
cnnNet.getFunction(),
std::vector<InferenceEngine::IExtensionPtr>{},
newAPI));
return InferenceEngine::details::ReadNetwork(modelPath, binPath, extensions, newAPI);
}

ie::CNNNetwork ReadNetwork(const std::string& model, const ie::Blob::CPtr& weights) const override {
OV_ITT_SCOPE(FIRST_INFERENCE, ov::itt::domains::IE_RT, "CoreImpl::ReadNetwork from memory");
auto cnnNet = InferenceEngine::details::ReadNetwork(model, weights, extensions);
OPENVINO_ASSERT(cnnNet.getFunction() || !newAPI, "Cannot read IR v7 from OpenVINO 2.0 API");
if (!newAPI)
return cnnNet;

return InferenceEngine::CNNNetwork(std::make_shared<InferenceEngine::details::CNNNetworkNGraphImpl>(
cnnNet.getFunction(),
std::vector<InferenceEngine::IExtensionPtr>{},
newAPI));
return InferenceEngine::details::ReadNetwork(model, weights, extensions, newAPI);
}

// TODO: In future this method can be added to ICore interface
Expand Down
Loading

0 comments on commit a3d36a8

Please sign in to comment.