From cf24765b3d6ec6a141aafc6ff86edca8a24d97ad Mon Sep 17 00:00:00 2001 From: "Lyalin, Sergey" Date: Fri, 14 Aug 2020 16:23:30 +0300 Subject: [PATCH 01/64] Adjust common transformation flow to adopt to LPT --- .../include/ngraph_ops/fully_connected.hpp | 4 +++- .../src/ngraph_ops/fully_connected.cpp | 14 +++++++++++--- .../convert_matmul_to_fc_or_gemm.cpp | 6 ++++-- .../convert_opset1_to_legacy.cpp | 3 --- 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/inference-engine/src/transformations/include/ngraph_ops/fully_connected.hpp b/inference-engine/src/transformations/include/ngraph_ops/fully_connected.hpp index 4471e8a7cb5ffe..6eba99786326d4 100644 --- a/inference-engine/src/transformations/include/ngraph_ops/fully_connected.hpp +++ b/inference-engine/src/transformations/include/ngraph_ops/fully_connected.hpp @@ -29,7 +29,8 @@ class TRANSFORMATIONS_API FullyConnected : public Op { FullyConnected(const Output & A, const Output & B, const Output & C, - const Shape & output_shape); + const Shape & output_shape, + const element::Type output_type = element::undefined); void validate_and_infer_types() override; @@ -40,6 +41,7 @@ class TRANSFORMATIONS_API FullyConnected : public Op { private: size_t m_output_size = 0; Shape m_output_shape = {}; + element::Type m_output_type; }; } // namespace op diff --git a/inference-engine/src/transformations/src/ngraph_ops/fully_connected.cpp b/inference-engine/src/transformations/src/ngraph_ops/fully_connected.cpp index 40fdeab95228c0..23604cf7335a10 100644 --- a/inference-engine/src/transformations/src/ngraph_ops/fully_connected.cpp +++ b/inference-engine/src/transformations/src/ngraph_ops/fully_connected.cpp @@ -16,8 +16,13 @@ using namespace ngraph; constexpr NodeTypeInfo op::FullyConnected::type_info; -op::FullyConnected::FullyConnected(const Output& A, const Output& B, const Output& C, const Shape & output_shape) - : Op({A, B, C}), m_output_shape(output_shape) { +op::FullyConnected::FullyConnected( + const Output& A, + const Output& B, + const Output& C, + const Shape & output_shape, + const element::Type output_type) + : Op({A, B, C}), m_output_shape(output_shape), m_output_type(output_type) { constructor_validate_and_infer_types(); } @@ -30,5 +35,8 @@ void op::FullyConnected::validate_and_infer_types() { if (m_output_shape.size() < 2) throw ngraph_error("FullyConnected shape is incorrect"); m_output_size = m_output_shape.back(); - set_output_type(0, input_value(0).get_element_type(), m_output_shape); + set_output_type( + 0, + m_output_type == element::undefined ? input_value(0).get_element_type() : m_output_type, + m_output_shape); } diff --git a/inference-engine/src/transformations/src/transformations/convert_opset1_to_legacy/convert_matmul_to_fc_or_gemm.cpp b/inference-engine/src/transformations/src/transformations/convert_opset1_to_legacy/convert_matmul_to_fc_or_gemm.cpp index bd7f352116df8e..6ee345fbbd08fb 100644 --- a/inference-engine/src/transformations/src/transformations/convert_opset1_to_legacy/convert_matmul_to_fc_or_gemm.cpp +++ b/inference-engine/src/transformations/src/transformations/convert_opset1_to_legacy/convert_matmul_to_fc_or_gemm.cpp @@ -144,7 +144,9 @@ ngraph::pass::ConvertMatMulToFC::ConvertMatMulToFC() { std::vector bias_value(O, 0); auto fc_bias = opset1::Constant::create(matmul->get_input_element_type(0), Shape {O}, bias_value); - auto fc = std::make_shared(fc_input_a, fc_input_b, fc_bias, output_shape); + auto fc = std::make_shared( + fc_input_a, fc_input_b, fc_bias, + output_shape, matmul->get_output_element_type(0)); fc->set_friendly_name(matmul->get_friendly_name()); new_ops.push_back(fc); @@ -204,7 +206,7 @@ ngraph::pass::ConvertMatMulToGemm::ConvertMatMulToGemm() { new_ops.push_back(fc_input_b.get_node_shared_ptr()); } - auto gemm = std::make_shared(fc_input_a, fc_input_b, matmul->get_transpose_a(), matmul->get_transpose_b()); + auto gemm = matmul->copy_with_new_inputs({fc_input_a, fc_input_b}); new_ops.push_back(gemm); if (gemm->get_shape() != output_shape) { diff --git a/inference-engine/src/transformations/src/transformations/convert_opset1_to_legacy/convert_opset1_to_legacy.cpp b/inference-engine/src/transformations/src/transformations/convert_opset1_to_legacy/convert_opset1_to_legacy.cpp index a940e57ef84dcb..f22bbc47b9a506 100644 --- a/inference-engine/src/transformations/src/transformations/convert_opset1_to_legacy/convert_opset1_to_legacy.cpp +++ b/inference-engine/src/transformations/src/transformations/convert_opset1_to_legacy/convert_opset1_to_legacy.cpp @@ -73,9 +73,6 @@ bool ngraph::pass::ConvertOpSet1ToLegacy::run_on_function(std::shared_ptr(); - // LinOpSequenceFusion must be executed after all decompositions - manager.register_pass(); - // Convolution/Deconvolution/FullyConnected fusions auto fusion = manager.register_pass(); fusion->add_matcher(); From 845e74978da780031d5e790525dc773e2b3349b7 Mon Sep 17 00:00:00 2001 From: "Lyalin, Sergey" Date: Fri, 14 Aug 2020 22:31:46 +0300 Subject: [PATCH 02/64] Add missing CF before LinOp optimization --- .../common_optimizations/common_optimizations.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/inference-engine/src/transformations/src/transformations/common_optimizations/common_optimizations.cpp b/inference-engine/src/transformations/src/transformations/common_optimizations/common_optimizations.cpp index 6838be52e7f578..48da8862b4a999 100644 --- a/inference-engine/src/transformations/src/transformations/common_optimizations/common_optimizations.cpp +++ b/inference-engine/src/transformations/src/transformations/common_optimizations/common_optimizations.cpp @@ -68,6 +68,9 @@ bool ngraph::pass::CommonOptimizations::run_on_function(std::shared_ptradd_matcher(); decomp->add_matcher(); + // CF is required after all decompositions + manager.register_pass(); + // LinOpSequenceFusion must be executed after all decompositions manager.register_pass(); From eef6e45b38466f2f0f5cc3835499573789b129a3 Mon Sep 17 00:00:00 2001 From: "Lyalin, Sergey" Date: Fri, 14 Aug 2020 22:52:24 +0300 Subject: [PATCH 03/64] Removed accidentally committed file --- .../transformations/mul_add_verification.hpp | 83 ------------------- 1 file changed, 83 deletions(-) delete mode 100644 inference-engine/src/transformations/include/transformations/mul_add_verification.hpp diff --git a/inference-engine/src/transformations/include/transformations/mul_add_verification.hpp b/inference-engine/src/transformations/include/transformations/mul_add_verification.hpp deleted file mode 100644 index f491b66a640720..00000000000000 --- a/inference-engine/src/transformations/include/transformations/mul_add_verification.hpp +++ /dev/null @@ -1,83 +0,0 @@ -// Copyright (C) 2018-2020 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include - -#include - -#include "ngraph/pattern/matcher.hpp" -#include "ngraph/op/broadcast.hpp" -#include "ngraph/op/reshape.hpp" -#include "ngraph/op/add.hpp" - -#include "ngraph/op/group_conv.hpp" - -#include - -#include "mul_add_squence_fusion.hpp" -#include - -namespace ngraph { -namespace pass { - -class TRANSFORMATIONS_API MulAddVerification; - -} // namespace pass -} // namespace ngraph - -class ngraph::pass::MulAddVerification: public ngraph::pass::GraphRewrite { -public: - /* - * This transformation aligns all Multiply and Add operations to have the same order of inputs - * In case if one of inputs is Constant it should be placed to the second input - */ - MulAddVerification() : GraphRewrite() { - mul_add_verification(); - mul_add_verification(); - } - -private: - template - void mul_add_verification(); -}; - -template -void ngraph::pass::MulAddVerification::mul_add_verification() { - Shape shape{}; - using std::make_shared; - using std::dynamic_pointer_cast; - auto input1 = make_shared(element::f32, shape); - auto input2 = make_shared(element::f32, shape); - auto eltwise = make_shared(input1, input2); - - ngraph::graph_rewrite_callback callback = [](ngraph::pattern::Matcher &m) { - if (auto eltwise = dynamic_pointer_cast(m.get_match_root())) { - auto in0 = std::dynamic_pointer_cast(eltwise->input(0).get_source_output().get_node_shared_ptr()); - auto in1 = std::dynamic_pointer_cast(eltwise->input(1).get_source_output().get_node_shared_ptr()); - - auto attrs = make_shared(); - if (in0) { - attrs->set_const_input_id(0); - } - - if (in1) { - attrs->set_const_input_id(1); - } - - attrs->set_consumers_count(eltwise->output(0).get_target_inputs().size()); - - eltwise->set_op_annotations(attrs); - return true; - } - - return false; - }; - - auto m = std::make_shared(eltwise, "MulAddVerification"); - this->add_matcher(m, callback, PassProperty::CHANGE_DYNAMIC_STATE); -} From cdedc4af196d92611a56e238d4d8cb40563fd808 Mon Sep 17 00:00:00 2001 From: Svetlana Dolinina Date: Wed, 16 Sep 2020 11:29:05 +0300 Subject: [PATCH 04/64] added check to avoid IR generation in case of wrong input shape (#2127) * added check to avoid IR generation in case of wrong input shape * review changes --- model-optimizer/mo/ops/convolution.py | 12 ++++++--- model-optimizer/mo/ops/convolution_test.py | 29 ++++++++++++++++++++++ model-optimizer/mo/ops/pooling.py | 26 ++++++++++--------- model-optimizer/mo/ops/pooling_test.py | 24 ++++++++++++++++++ 4 files changed, 75 insertions(+), 16 deletions(-) diff --git a/model-optimizer/mo/ops/convolution.py b/model-optimizer/mo/ops/convolution.py index 31b469719f2450..95471b07318405 100644 --- a/model-optimizer/mo/ops/convolution.py +++ b/model-optimizer/mo/ops/convolution.py @@ -20,7 +20,6 @@ from mo.front.common.partial_infer.utils import int64_array, float_array, mark_input_bins, assign_dims_to_weights, \ tf_window_op_pad_infer -from mo.front.extractor import spatial_getter from mo.front.onnx.extractors.utils import get_backend_pad from mo.graph.graph import Node, Graph from mo.ops.op import Op, PermuteAttrs @@ -72,6 +71,11 @@ def calc_convolution(input_spatial_shape, stride_spatial_shape, pad_spatial_shap Verified to be applicable for both Caffe and ONNX. ''' spatial_val_wo_stride = input_spatial_shape + pad_spatial_shape - kernel_extent + + if np.any(spatial_val_wo_stride < 0): + raise Error("Data after padding has dimension less than window size. " + + "Possible reason of error is incorrectly specified model input shape(s).") + float_spatial_val_wo_stride = float_array(spatial_val_wo_stride) return float_spatial_val_wo_stride / stride_spatial_shape + 1 @@ -118,8 +122,8 @@ def infer(node: Node): log.error('Cannot reshape kernel due to not all required attrs was set to {} node'.format(node.id)) return # layout for Convolution weights is OIHW - kernel_shape = np.array([node.output, input_shape[node.channel_dims].item() / node.group, - *[node.kernel_spatial[i] for i in range(len(node.kernel_spatial))]], dtype=np.int64) + kernel_shape = int64_array([node.output, input_shape[node.channel_dims].item() / node.group, + *[node.kernel_spatial[i] for i in range(len(node.kernel_spatial))]]) if node.type == 'Deconvolution': # layout for Deconvolution weights is IOHW kernel_shape[[0, 1]] = kernel_shape[[1, 0]] #node.input_feature_channel, node.output_feature_channel = node.output_feature_channel, node.input_feature_channel @@ -163,7 +167,7 @@ def infer(node: Node): if not node.has_valid('stride'): node['stride'] = np.full([len(input_shape)], 1, dtype=np.int64) if not node.has_valid('pad'): - node['pad'] = np.array([[0, 0]] * len(input_shape), dtype=np.int64) + node['pad'] = int64_array([[0, 0]] * len(input_shape)) node['pad_spatial_shape'] = node.pad[node.spatial_dims] if not node.has_valid('output_padding'): diff --git a/model-optimizer/mo/ops/convolution_test.py b/model-optimizer/mo/ops/convolution_test.py index 0c612f805c0e8a..a9573cbc238a63 100644 --- a/model-optimizer/mo/ops/convolution_test.py +++ b/model-optimizer/mo/ops/convolution_test.py @@ -21,6 +21,7 @@ from mo.front.common.partial_infer.utils import int64_array from mo.graph.graph import Node from mo.ops.convolution import Convolution +from mo.utils.error import Error from mo.utils.unittest.extractors import FakeValue from mo.utils.unittest.graph import build_graph @@ -378,3 +379,31 @@ def test_conv_infer_3D_convolution(self): self.assertTrue(np.array_equal(int64_array([[0, 0], [0, 0], [0, 0]]), conv_node.pad_spatial_shape)) # Check resulting output shape self.assertTrue(np.array_equal(int64_array([1, 64, 16, 218, 218]), conv_output.shape)) + + def test_caffe_conv2d_infer_wrong_input_shape(self): + graph = build_graph(nodes_attributes, + [('conv_input', 'conv_node'), + ('conv_weights', 'conv_node'), + ('conv_node', 'conv_output'), + ('conv_output', 'op_output') + ], + {'conv_output': {'shape': None}, + 'conv_input': {'shape': np.array([1, 3, 1, 1])}, + 'conv_weights': {'shape': np.array([64, 3, 3, 3]), + 'dim_attrs': ['spatial_dims', 'channel_dims', 'batch_dims', 'axis']}, + 'conv_node': {'pad_spatial_shape': np.array([[0, 0], [0, 0]]), + 'conv_pad': np.array([[0, 0], [0, 0], [0, 0], [0, 0]]), + 'dilation': np.array([1, 1, 1, 1]), 'bias_addable': True, 'bias_term': False, + 'output_spatial_shape': None, 'output_shape': None, + 'stride': np.array([1, 1, 1, 1]), 'group': 1, + 'kernel_spatial_idx': np.array([2, 3]), + 'input_feature_channel': 1, + 'output_feature_channel': 0, + 'output': 64, 'kernel_spatial': np.array([3, 3]), + 'spatial_dims': np.array([2, 3]), 'channel_dims': np.array([1]), + 'batch_dims': np.array([0])} + }) + + conv_node = Node(graph, 'conv_node') + with self.assertRaises(Error): + Convolution.infer(conv_node) diff --git a/model-optimizer/mo/ops/pooling.py b/model-optimizer/mo/ops/pooling.py index 95ab11b85e4b78..0d65a9240e270f 100644 --- a/model-optimizer/mo/ops/pooling.py +++ b/model-optimizer/mo/ops/pooling.py @@ -16,13 +16,11 @@ import numpy as np -from mo.front.common.partial_infer.utils import tf_window_op_pad_infer -from mo.front.extractor import attr_getter -# from mo.front.common.partial_infer.pooling import pool_explicit_padding_infer -from mo.front.extractor import spatial_getter +from mo.front.common.partial_infer.utils import tf_window_op_pad_infer, int64_array, float_array from mo.front.onnx.extractors.utils import get_backend_pad from mo.graph.graph import Node, Graph from mo.ops.op import Op, PermuteAttrs +from mo.utils.error import Error class Pooling(Op): @@ -30,10 +28,10 @@ class Pooling(Op): def __init__(self, graph: Graph, attrs: dict): super().__init__(graph, { - 'type': __class__.op, - 'op': __class__.op, + 'type': self.op, + 'op': self.op, 'version': 'opset1', - 'infer': __class__.infer, + 'infer': self.infer, 'in_ports_count': 1, 'out_ports_count': 1, }, attrs) @@ -68,11 +66,11 @@ def infer(node: Node): # Setting default pad and stride attrs in case of None specified if not node.has_valid('pad'): - node['pad'] = np.array([[0, 0] for x in range(len(input_shape))], dtype=np.int64) + node['pad'] = int64_array([[0, 0] for x in range(len(input_shape))]) if not node.has_valid('pad_spatial_shape'): node['pad_spatial_shape'] = node.pad[node.spatial_dims] if not node.has_valid('stride'): - node['stride'] = np.array([1 for x in range(len(input_shape))], dtype=np.int64) + node['stride'] = int64_array([1 for x in range(len(input_shape))]) if node.has_and_set('global_pool'): node['window'] = np.zeros(len(input_shape), dtype=np.int64) @@ -96,9 +94,13 @@ def infer(node: Node): rounding = np.floor if node.soft_get('pooling_convention') == 'full' or node.soft_get('rounding_type') == 'ceil': rounding = np.ceil - output_spatial_shape = np.array(rounding( - np.array(input_spatial_shape + pad_spatial_shape - window_spatial_shape, - dtype=np.float) / stride_spatial), dtype=np.int64) + 1 + + padded_spatial_shape = input_spatial_shape + pad_spatial_shape - window_spatial_shape + if np.any(padded_spatial_shape < 0): + raise Error("Data after padding has dimension less than window size. " + + "Possible reason of error is incorrectly specified model input shape(s).") + + output_spatial_shape = int64_array(rounding(float_array(padded_spatial_shape) / stride_spatial)) + 1 original_pads = np.array([i[1] for i in node.pad_spatial_shape]) diff --git a/model-optimizer/mo/ops/pooling_test.py b/model-optimizer/mo/ops/pooling_test.py index 556859ce1098f1..456e31b92669b8 100644 --- a/model-optimizer/mo/ops/pooling_test.py +++ b/model-optimizer/mo/ops/pooling_test.py @@ -21,6 +21,7 @@ from mo.graph.graph import Node from mo.ops.pooling import Pooling from mo.utils.unittest.graph import build_graph +from mo.utils.error import Error nodes_attributes = {'node_1': {'value': None, 'kind': 'data'}, 'pool': {'type': 'Pooling', 'value': None, 'kind': 'op'}, @@ -129,3 +130,26 @@ def test_pooling_infer_no_shape(self): Pooling.infer(pool_node) res_shape = graph.node['node_2']['shape'] self.assertIsNone(res_shape) + + def test_pooling_infer_wrong_input_shape(self): + graph = build_graph(nodes_attributes, + [('node_1', 'pool'), + ('pool', 'node_2'), + ('node_2', 'op_output') + ], + {'node_2': {'shape': None}, + 'node_1': {'shape': np.array([1, 3, 1, 1])}, + 'pool': {'window': np.array([1, 1, 5, 5]), 'stride': np.array([1, 1, 2, 2]), + 'pad': np.array([[0, 0], [0, 0], [1, 1], [1, 1]]), + 'pad_spatial_shape': np.array([[1, 1], [1, 1]]), + 'pool_method': 'avg', 'exclude_pad': 'false', 'global_pool': 0, + 'output_spatial_shape': None, 'output_shape': None, + 'kernel_spatial': np.array([3, 3]), 'spatial_dims': np.array([2, 3]), + 'channel_dims': np.array([1]), 'batch_dims': np.array([0]), + 'pooling_convention': 'full'} + }) + + pool_node = Node(graph, 'pool') + + with self.assertRaises(Error): + Pooling.infer(pool_node) From d59014454538ac998b21ab3df30f0f749331972d Mon Sep 17 00:00:00 2001 From: Anton Potapov Date: Wed, 16 Sep 2020 12:41:14 +0300 Subject: [PATCH 05/64] [PP GAPI] Addded tests to cover exisiting precision conversions done by (#1976) some plugins - added shared parameterized tests - instantiated for template plugin - instantiated for cpu plugin - fixed CPU plugin to properly handle U16 input - fixed CPU reverse_sequence primitive to alolw input/oputput tensors to be in FP32 only - updated ngraph test_simple_computation_on_ndarrays to not expect failure on U16 input --- .../behavior/preprocessing.cpp | 29 +++++ .../mkldnn_plugin/mkldnn_infer_request.cpp | 24 ++-- .../src/mkldnn_plugin/nodes/base.hpp | 6 +- .../mkldnn_plugin/nodes/reverse_sequence.cpp | 4 +- .../behavior/preprocessing.cpp | 29 +++++ .../shared/include/behavior/preprocessing.hpp | 106 ++++++++++++++++++ ngraph/python/tests/test_ngraph/test_basic.py | 2 +- 7 files changed, 188 insertions(+), 12 deletions(-) create mode 100644 docs/template_plugin/tests/functional/shared_tests_instances/behavior/preprocessing.cpp create mode 100644 inference-engine/tests/functional/plugin/cpu/shared_tests_instances/behavior/preprocessing.cpp create mode 100644 inference-engine/tests/functional/plugin/shared/include/behavior/preprocessing.hpp diff --git a/docs/template_plugin/tests/functional/shared_tests_instances/behavior/preprocessing.cpp b/docs/template_plugin/tests/functional/shared_tests_instances/behavior/preprocessing.cpp new file mode 100644 index 00000000000000..747f286efbd962 --- /dev/null +++ b/docs/template_plugin/tests/functional/shared_tests_instances/behavior/preprocessing.cpp @@ -0,0 +1,29 @@ +// Copyright (C) 2020 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "multi-device/multi_device_config.hpp" + +#include "behavior/preprocessing.hpp" + +using namespace BehaviorTestsDefinitions; + +namespace { + +const std::vector inputPrecisions = { + InferenceEngine::Precision::U8, + InferenceEngine::Precision::FP32 +}; + +const std::vector> configs = { + {} +}; + +INSTANTIATE_TEST_CASE_P(PreprocessingPrecisionConvertTests, PreprocessingPrecisionConvertTest, + ::testing::Combine( + ::testing::ValuesIn(inputPrecisions), + ::testing::Values("TEMPLATE"), + ::testing::ValuesIn(configs)), + PreprocessingPrecisionConvertTest::getTestCaseName); + +} // namespace diff --git a/inference-engine/src/mkldnn_plugin/mkldnn_infer_request.cpp b/inference-engine/src/mkldnn_plugin/mkldnn_infer_request.cpp index 248bb47ca9fcdb..fb778e556fb0ef 100644 --- a/inference-engine/src/mkldnn_plugin/mkldnn_infer_request.cpp +++ b/inference-engine/src/mkldnn_plugin/mkldnn_infer_request.cpp @@ -57,8 +57,8 @@ void MKLDNNPlugin::MKLDNNInferRequest::pushInput(const std::string& inputName, I namespace { -template -void copyToFloat(float* dst, const InferenceEngine::Blob* src) { +template +void copyFrom(const InferenceEngine::Blob* src, DstT* dst) { if (!dst) { return; } @@ -75,6 +75,11 @@ void copyToFloat(float* dst, const InferenceEngine::Blob* src) { for (size_t i = 0; i < t_blob->size(); i++) dst[i] = srcPtr[i]; } +template +void copyToFloat(float* dst, const InferenceEngine::Blob* src) { + copyFrom(src, dst); +} + } // namespace void MKLDNNPlugin::MKLDNNInferRequest::InferImpl() { @@ -108,18 +113,19 @@ void MKLDNNPlugin::MKLDNNInferRequest::InferImpl() { case InferenceEngine::Precision::I8: pushInput(input.first, input.second); break; - case InferenceEngine::Precision::U16: - // U16 is unsupported by mkldnn, so here we convert the blob and send FP32 - iconv = InferenceEngine::make_shared_blob({InferenceEngine::Precision::FP32, + case InferenceEngine::Precision::U16: { + // U16 is unsupported by mkldnn, so here we convert the blob and send I32 + iconv = InferenceEngine::make_shared_blob({InferenceEngine::Precision::I32, input.second->getTensorDesc().getDims(), input.second->getTensorDesc().getLayout()}); convertedInputs.push_back(iconv); iconv->allocate(); - in_f = dynamic_cast *>(iconv.get()); - if (in_f == nullptr) + auto in = dynamic_cast *>(iconv.get()); + if (in == nullptr) THROW_IE_EXCEPTION << "Cannot get TBlob"; - copyToFloat(in_f->data(), input.second.get()); - pushInput(input.first, iconv); + copyFrom(input.second.get(), in->data()); + pushInput(input.first, iconv); + } break; case InferenceEngine::Precision::I16: if (graph->hasMeanImageFor(input.first)) { diff --git a/inference-engine/src/mkldnn_plugin/nodes/base.hpp b/inference-engine/src/mkldnn_plugin/nodes/base.hpp index c0adec071985d0..f31812e4cbd720 100644 --- a/inference-engine/src/mkldnn_plugin/nodes/base.hpp +++ b/inference-engine/src/mkldnn_plugin/nodes/base.hpp @@ -63,9 +63,13 @@ class ExtLayerBase: public ILayerExecImpl { DataConfigurator(ConfLayout l, bool constant, int inplace = -1): layout(l), constant(constant), inplace(inplace) {} + DataConfigurator(ConfLayout l, Precision::ePrecision prc): + layout(l), prc(prc) {} + ConfLayout layout; bool constant = false; int inplace = -1; + Precision::ePrecision prc = Precision::UNSPECIFIED; // by default use the layer precision }; void addConfig(const CNNLayer* layer, std::vector in_l, @@ -128,7 +132,7 @@ class ExtLayerBase: public ILayerExecImpl { // fixing of BF16 precisions where they are - layers naturally support only FP32 // if we see BF16, that means another floating point format which will be converted by reorder // added by current mkl-dnn cpu plugin when it figure out diff in data types on input and output of edges - InferenceEngine::Precision precision = data_desc.getPrecision(); + InferenceEngine::Precision precision = (conf.prc == Precision::UNSPECIFIED) ? data_desc.getPrecision() : Precision(conf.prc); if (precision == Precision::BF16) { precision = Precision::FP32; } diff --git a/inference-engine/src/mkldnn_plugin/nodes/reverse_sequence.cpp b/inference-engine/src/mkldnn_plugin/nodes/reverse_sequence.cpp index 52499d1d9737d5..a76a0d4ce3dcbe 100644 --- a/inference-engine/src/mkldnn_plugin/nodes/reverse_sequence.cpp +++ b/inference-engine/src/mkldnn_plugin/nodes/reverse_sequence.cpp @@ -59,7 +59,9 @@ class ReverseSequenceImpl: public ExtLayerBase { srcStrides = layer->insData[REVERSESEQUENCE_DATA].lock()->getTensorDesc().getBlockingDesc().getStrides(); work_amount_dst = srcStrides[0] * src_dims[0]; - addConfig(layer, { DataConfigurator(ConfLayout::PLN), DataConfigurator(ConfLayout::PLN) }, { DataConfigurator(ConfLayout::PLN) }); + addConfig(layer, + { DataConfigurator(ConfLayout::PLN, Precision::FP32), DataConfigurator(ConfLayout::PLN) }, + { DataConfigurator(ConfLayout::PLN, Precision::FP32) }); } catch (InferenceEngine::details::InferenceEngineException &ex) { errorMsg = ex.what(); } diff --git a/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/behavior/preprocessing.cpp b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/behavior/preprocessing.cpp new file mode 100644 index 00000000000000..769cf8fe0f8f21 --- /dev/null +++ b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/behavior/preprocessing.cpp @@ -0,0 +1,29 @@ +// Copyright (C) 2020 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "multi-device/multi_device_config.hpp" + +#include "behavior/preprocessing.hpp" + +using namespace BehaviorTestsDefinitions; + +namespace { + +const std::vector inputPrecisions = { + InferenceEngine::Precision::U16, + InferenceEngine::Precision::FP32 +}; + +const std::vector> configs = { + {} +}; + +INSTANTIATE_TEST_CASE_P(smoke_BehaviourPreprocessingTests, PreprocessingPrecisionConvertTest, + ::testing::Combine( + ::testing::ValuesIn(inputPrecisions), + ::testing::Values(CommonTestUtils::DEVICE_CPU), + ::testing::ValuesIn(configs)), + PreprocessingPrecisionConvertTest::getTestCaseName); + +} // namespace diff --git a/inference-engine/tests/functional/plugin/shared/include/behavior/preprocessing.hpp b/inference-engine/tests/functional/plugin/shared/include/behavior/preprocessing.hpp new file mode 100644 index 00000000000000..7d9e773bbc4bf3 --- /dev/null +++ b/inference-engine/tests/functional/plugin/shared/include/behavior/preprocessing.hpp @@ -0,0 +1,106 @@ +// Copyright (C) 2020 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include + +#include +#include "common_test_utils/test_assertions.hpp" +#include "common_test_utils/common_utils.hpp" +#include "functional_test_utils/plugin_cache.hpp" +#include "functional_test_utils/layer_test_utils.hpp" +#include "functional_test_utils/blob_utils.hpp" +#include "ie_preprocess.hpp" +#include "functional_test_utils/behavior_test_utils.hpp" + +namespace { +void setInputNetworkPrecision(InferenceEngine::CNNNetwork &network, InferenceEngine::InputsDataMap &inputs_info, + InferenceEngine::Precision input_precision) { + inputs_info = network.getInputsInfo(); + ASSERT_EQ(1u, inputs_info.size()); + inputs_info.begin()->second->setPrecision(input_precision); +} + +} + +namespace BehaviorTestsDefinitions { + +using PreprocessingPrecisionConvertParams = std::tuple< + InferenceEngine::Precision, // Input precision + std::string, // Device name + std::map // Config +>; + +struct PreprocessingPrecisionConvertTest : + public testing::WithParamInterface, + LayerTestsUtils::LayerTestsCommon { +public: + static std::string getTestCaseName(testing::TestParamInfo obj) { + InferenceEngine::Precision inPrc; + std::string targetDevice; + std::map configuration; + std::tie(inPrc, targetDevice, configuration) = obj.param; + std::ostringstream result; + result << "inPRC=" << inPrc.name() << "_"; + result << "targetDevice=" << targetDevice; + if (!configuration.empty()) { + for (auto& configItem : configuration) { + result << "configItem=" << configItem.first << "_" << configItem.second << "_"; + } + } + return result.str(); + } + + void SetUp() override { + // This test: + // - Strive to test the plugin internal preprocessing (precision conversion) only. + // Thus (logically) no-op graph is used. + // - Reference code mimic the preprocessing via extra ngraph Convert operation. + // - Create/uses two (different) graphs here : one to feed the the plugin and one calculate the reference result. + + SetRefMode(LayerTestsUtils::RefMode::INTERPRETER); + + std::tie(inPrc, targetDevice, configuration) = this->GetParam(); + + bool specialZero = true; + + std::vector inputShape {4, 4}; + + auto make_ngraph = [&](bool with_extra_conv) { + auto in_prec = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(with_extra_conv ? inPrc : decltype(inPrc)(InferenceEngine::Precision::FP32)); + auto paramsIn = ngraph::builder::makeParams(in_prec, {inputShape}); + auto paramIn = ngraph::helpers::convert2OutputVector( + ngraph::helpers::castOps2Nodes(paramsIn)); + + auto toF32 = std::make_shared(paramIn[0], ngraph::element::Type_t::f32); + + auto constNode = std::make_shared( + ngraph::element::Type_t::i64, ngraph::Shape{inputShape.size()}, inputShape); + auto reshape = std::dynamic_pointer_cast( + std::make_shared(with_extra_conv ? toF32 : paramIn[0], constNode, specialZero)); + ngraph::ResultVector results{std::make_shared(reshape)}; + return std::make_shared(results, paramsIn, "Reshape"); + }; + + function = make_ngraph(false); + reference_function = make_ngraph(true); //use extra ops to mimic the preprocessing + } + + void Validate() override { + //force the reference implementation to use graph with extra Convert operation + function = reference_function; + LayerTestsUtils::LayerTestsCommon::Validate(); + } + +public: + std::shared_ptr ie = PluginCache::get().ie(); + std::shared_ptr reference_function; +}; + + +TEST_P(PreprocessingPrecisionConvertTest, InternalPluginPrecisionConvert) { + // Skip test according to plugin specific disabledTestPatterns() (if any) + SKIP_IF_CURRENT_TEST_IS_DISABLED() + Run(); +} +} // namespace BehaviorTestsDefinitions diff --git a/ngraph/python/tests/test_ngraph/test_basic.py b/ngraph/python/tests/test_ngraph/test_basic.py index a86355cae3fde7..35f62fbfc4d126 100644 --- a/ngraph/python/tests/test_ngraph/test_basic.py +++ b/ngraph/python/tests/test_ngraph/test_basic.py @@ -71,7 +71,7 @@ def test_ngraph_function_api(): np.int32, pytest.param(np.int64, marks=xfail_issue_35926), pytest.param(np.uint8, marks=xfail_issue_36479), - pytest.param(np.uint16, marks=xfail_issue_36479), + np.uint16, pytest.param(np.uint32, marks=xfail_issue_36476), pytest.param(np.uint64, marks=xfail_issue_36478), ], From 18521f2dcb8ffafea3f548a882f8e0f1422052aa Mon Sep 17 00:00:00 2001 From: Andrew Bakalin Date: Wed, 16 Sep 2020 12:41:49 +0300 Subject: [PATCH 06/64] [VPU] Fix K propagation through Reshape (#2184) * [VPU][DTS] Fix K propagation through Reshape * [VPU] Add test cases --- .../subgraph_tests/topk_k_propagation.cpp | 107 ++++++++++++++++++ ngraph/core/src/validation_util.cpp | 4 +- 2 files changed, 110 insertions(+), 1 deletion(-) create mode 100644 inference-engine/tests/functional/plugin/myriad/subgraph_tests/topk_k_propagation.cpp diff --git a/inference-engine/tests/functional/plugin/myriad/subgraph_tests/topk_k_propagation.cpp b/inference-engine/tests/functional/plugin/myriad/subgraph_tests/topk_k_propagation.cpp new file mode 100644 index 00000000000000..c2c352cc8ad9f0 --- /dev/null +++ b/inference-engine/tests/functional/plugin/myriad/subgraph_tests/topk_k_propagation.cpp @@ -0,0 +1,107 @@ +// Copyright (C) 2020 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace { + +class DynamicToStaticTopKPropagation : public CommonTestUtils::TestsCommon, + public testing::WithParamInterface { +public: + void SetUp() override { + const auto& k = GetParam(); + + const auto data = std::make_shared(ngraph::element::i64, ngraph::Shape{1000}); + const auto realK = std::make_shared(ngraph::element::i32, ngraph::Shape{1}); + const auto maxK = ngraph::opset4::Constant::create(ngraph::element::i32, {1}, {k}); + + const auto concat = std::make_shared(ngraph::OutputVector{realK, maxK}, 0); + + const auto reduceMin = std::make_shared(concat, ngraph::opset4::Constant::create(ngraph::element::i32, {1}, {0}), false); + const auto builtSubgraph = buildSubgraph(reduceMin); + + const auto dsr = std::make_shared(data, realK); + const auto topK = std::make_shared(dsr, builtSubgraph, 0, "max", "value"); + + ngraph::ResultVector results{std::make_shared(topK->output(0)), + std::make_shared(topK->output(1))}; + const auto function = std::make_shared(results, ngraph::ParameterVector{data, realK}, "TopKPropagationOfK"); + topK->set_output_type(0, dsr->get_input_element_type(0), ngraph::PartialShape::dynamic(1)); + + const auto transformations = vpu::Transformations{{topK->type_info, vpu::dynamicToStaticShapeTopK}}; + ASSERT_NO_THROW(vpu::DynamicToStaticShape(transformations).run_on_function(function)); + + ngraph::ResultVector processedResults; + ASSERT_NO_THROW(processedResults = function->get_results()); + EXPECT_EQ(processedResults.size(), 2); + + const auto topKOutPartialShape = processedResults[0]->get_input_partial_shape(0); + EXPECT_TRUE(topKOutPartialShape.is_static()); + + const auto topKOutShape = topKOutPartialShape.get_shape(); + EXPECT_EQ(topKOutShape.size(), 1); + EXPECT_EQ(topKOutShape[0], k); + } + +protected: + virtual std::shared_ptr buildSubgraph(std::shared_ptr node) const { + return node; + } +}; + +const std::vector kVec = {0, 10, 100, 200, 500}; + +TEST_P(DynamicToStaticTopKPropagation, KPropagation) { +} + +INSTANTIATE_TEST_CASE_P(NGraph, DynamicToStaticTopKPropagation, ::testing::ValuesIn(kVec)); + +class DynamicToStaticTopKPropagationReshape : public DynamicToStaticTopKPropagation { +protected: + std::shared_ptr buildSubgraph(std::shared_ptr node) const override { + return std::make_shared(node, ngraph::opset4::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {0}), false); + } +}; + +TEST_P(DynamicToStaticTopKPropagationReshape, KPropagation) { +} + +INSTANTIATE_TEST_CASE_P(NGraph, DynamicToStaticTopKPropagationReshape, ::testing::ValuesIn(kVec)); + +class DynamicToStaticTopKPropagationSqueezeUnsqueeze : public DynamicToStaticTopKPropagation { +protected: + std::shared_ptr buildSubgraph(std::shared_ptr node) const override { + const auto unsqueeze = std::make_shared(node, ngraph::opset4::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {0})); + return std::make_shared(unsqueeze, ngraph::opset4::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {0})); + } +}; + +TEST_P(DynamicToStaticTopKPropagationSqueezeUnsqueeze, KPropagation) { +} + +INSTANTIATE_TEST_CASE_P(NGraph, DynamicToStaticTopKPropagationSqueezeUnsqueeze, ::testing::ValuesIn(kVec)); + +class DynamicToStaticTopKPropagationConvert : public DynamicToStaticTopKPropagation { +protected: + std::shared_ptr buildSubgraph(std::shared_ptr node) const override { + const auto convert = std::make_shared(node, ngraph::element::i32); + return std::make_shared(convert, ngraph::element::i64); + } +}; + +TEST_P(DynamicToStaticTopKPropagationConvert, KPropagation) { +} + +INSTANTIATE_TEST_CASE_P(NGraph, DynamicToStaticTopKPropagationConvert, ::testing::ValuesIn(kVec)); + +} // namespace diff --git a/ngraph/core/src/validation_util.cpp b/ngraph/core/src/validation_util.cpp index e6bd5926b678ea..245f3a889adf82 100644 --- a/ngraph/core/src/validation_util.cpp +++ b/ngraph/core/src/validation_util.cpp @@ -21,6 +21,7 @@ #include "ngraph/op/convert.hpp" #include "ngraph/op/min.hpp" #include "ngraph/op/minimum.hpp" +#include "ngraph/op/reshape.hpp" #include "ngraph/op/squeeze.hpp" #include "ngraph/op/unsqueeze.hpp" #include "ngraph/runtime/host_tensor.hpp" @@ -1096,7 +1097,8 @@ pair ngraph::maximum_value(const Output& value) {op::v1::Minimum::type_info, exec_minimum}, {op::v1::ReduceMin::type_info, exec_reduce_min}, {op::v0::Squeeze::type_info, exec_nop}, - {op::v0::Unsqueeze::type_info, exec_nop}}; + {op::v0::Unsqueeze::type_info, exec_nop}, + {op::v1::Reshape::type_info, exec_nop}}; Evaluator::value_map value_map; Evaluator evaluator(handlers, value_map); auto val = evaluator.evaluate(value); From 339cd5e49e1863e2ae320d56482e68a7045ca854 Mon Sep 17 00:00:00 2001 From: Evgeny Latkin Date: Wed, 16 Sep 2020 13:51:33 +0300 Subject: [PATCH 07/64] [IE][VPU]: update firmware 1378 (#2182) --- inference-engine/cmake/vpu_dependencies.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inference-engine/cmake/vpu_dependencies.cmake b/inference-engine/cmake/vpu_dependencies.cmake index 1fc996546b5264..4df5f49a73f8ac 100644 --- a/inference-engine/cmake/vpu_dependencies.cmake +++ b/inference-engine/cmake/vpu_dependencies.cmake @@ -19,7 +19,7 @@ set(VPU_SUPPORTED_FIRMWARES usb-ma2450 usb-ma2x8x pcie-ma248x) # Default packages # -set(FIRMWARE_PACKAGE_VERSION 1370) +set(FIRMWARE_PACKAGE_VERSION 1378) set(VPU_CLC_MA2X8X_VERSION "movi-cltools-20.09.1") # From 83e96891ca287bede3d0d481d6e5b3facabed346 Mon Sep 17 00:00:00 2001 From: Gorokhov Dmitriy Date: Wed, 16 Sep 2020 14:11:48 +0300 Subject: [PATCH 08/64] Revert "[IE TESTS] dynavic batch for mvn layer (#1010)" (#2257) This reverts commit 2e3378c50feb96df2bb8cb719bf0745705e35ad9. --- .../src/mkldnn_plugin/mkldnn_exec_network.cpp | 5 ++--- .../mkldnn_plugin/nodes/mkldnn_mvn_node.cpp | 3 +-- .../single_layer_tests/mvn.cpp | 18 +----------------- .../single_layer_tests/mvn.cpp | 8 +------- .../shared/include/single_layer_tests/mvn.hpp | 15 +++++++-------- .../shared/src/single_layer_tests/mvn.cpp | 13 ++++--------- .../functional_test_utils/layer_test_utils.cpp | 9 +-------- .../functional_test_utils/layer_test_utils.hpp | 1 + 8 files changed, 18 insertions(+), 54 deletions(-) diff --git a/inference-engine/src/mkldnn_plugin/mkldnn_exec_network.cpp b/inference-engine/src/mkldnn_plugin/mkldnn_exec_network.cpp index de08a67e73e189..36f2c0ec6697c1 100644 --- a/inference-engine/src/mkldnn_plugin/mkldnn_exec_network.cpp +++ b/inference-engine/src/mkldnn_plugin/mkldnn_exec_network.cpp @@ -97,7 +97,7 @@ MKLDNNExecNetwork::MKLDNNExecNetwork(const InferenceEngine::ICNNNetwork &network MKLDNNGraph::ApplyUnrollPasses(static_cast(*_clonedNetwork)); - if (_cfg.enableDynamicBatch) { + if (_cfg.batchLimit > 1) { // check topology for applicability if (!CanProcessDynBatch(*_clonedNetwork)) { THROW_IE_EXCEPTION << "MKLDNNGraph::CreateGraph: such topology cannot be compiled for dynamic batch!"; @@ -279,8 +279,7 @@ bool MKLDNNExecNetwork::CanProcessDynBatch(const InferenceEngine::ICNNNetwork &n type != Eltwise && type != Crop && type != BatchNormalization && - type != Copy && - type != MVN) { + type != Copy) { check_result = false; } }, false); diff --git a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_mvn_node.cpp b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_mvn_node.cpp index 99e89c0f4599a2..0605e71a1039c9 100644 --- a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_mvn_node.cpp +++ b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_mvn_node.cpp @@ -990,8 +990,7 @@ void MKLDNNMVNNode::mvn_blk(const in_data_t* src_data, out_data_t* dst_data, con std::vector mean_buffer(aux_buffer_size * threads_num); std::vector variance_buffer(aux_buffer_size * threads_num); - int actual_N = batchToProcess(); - for (size_t b = 0lu; b < actual_N; b++) { + for (size_t b = 0lu; b < N; b++) { size_t ccb = is_nhwc ? b * C2 : b * C3; if (across_channels) { // mean for this instance in batch diff --git a/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/single_layer_tests/mvn.cpp b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/single_layer_tests/mvn.cpp index 30548fb1c76f8f..cd789208ea5e5f 100644 --- a/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/single_layer_tests/mvn.cpp +++ b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/single_layer_tests/mvn.cpp @@ -38,30 +38,14 @@ const std::vector epsilon = { 0.000000001 }; -const std::vector> Configs = { - {} -}; - const auto MvnCases = ::testing::Combine( ::testing::ValuesIn(inputShapes), ::testing::Values(InferenceEngine::Precision::FP32), ::testing::ValuesIn(acrossChannels), ::testing::ValuesIn(normalizeVariance), ::testing::ValuesIn(epsilon), - ::testing::Values(CommonTestUtils::DEVICE_CPU), - ::testing::ValuesIn(Configs) + ::testing::Values(CommonTestUtils::DEVICE_CPU) ); INSTANTIATE_TEST_CASE_P(smoke_MKLDNN_TestsMVN, MvnLayerTest, MvnCases, MvnLayerTest::getTestCaseName); - -INSTANTIATE_TEST_CASE_P(smoke_MKLDNN_MvnLayerCheckDynBatch, MvnLayerTest, - ::testing::Combine( - ::testing::Values(std::vector({5, 8, 3, 5})), - ::testing::Values(InferenceEngine::Precision::FP32), - ::testing::ValuesIn(acrossChannels), - ::testing::ValuesIn(normalizeVariance), - ::testing::ValuesIn(epsilon), - ::testing::Values(CommonTestUtils::DEVICE_CPU), - ::testing::Values(std::map({{CONFIG_KEY(DYN_BATCH_ENABLED), CONFIG_VALUE(YES)}}))), - MvnLayerTest::getTestCaseName); \ No newline at end of file diff --git a/inference-engine/tests/functional/plugin/gpu/shared_tests_instances/single_layer_tests/mvn.cpp b/inference-engine/tests/functional/plugin/gpu/shared_tests_instances/single_layer_tests/mvn.cpp index d338554b24fbfd..8cbd56f53d9606 100644 --- a/inference-engine/tests/functional/plugin/gpu/shared_tests_instances/single_layer_tests/mvn.cpp +++ b/inference-engine/tests/functional/plugin/gpu/shared_tests_instances/single_layer_tests/mvn.cpp @@ -38,19 +38,13 @@ const std::vector epsilon = { 0.000000001 }; - -const std::vector> Configs = { - {} -}; - const auto MvnCases = ::testing::Combine( ::testing::ValuesIn(inputShapes), ::testing::Values(InferenceEngine::Precision::FP32), ::testing::ValuesIn(acrossChannels), ::testing::ValuesIn(normalizeVariance), ::testing::ValuesIn(epsilon), - ::testing::Values(CommonTestUtils::DEVICE_GPU), - ::testing::ValuesIn(Configs) + ::testing::Values(CommonTestUtils::DEVICE_GPU) ); INSTANTIATE_TEST_CASE_P(smoke_CLDNN_TestsMVN, MvnLayerTest, MvnCases, MvnLayerTest::getTestCaseName); diff --git a/inference-engine/tests/functional/plugin/shared/include/single_layer_tests/mvn.hpp b/inference-engine/tests/functional/plugin/shared/include/single_layer_tests/mvn.hpp index e47aa7a6ba9673..39870828a24c1e 100644 --- a/inference-engine/tests/functional/plugin/shared/include/single_layer_tests/mvn.hpp +++ b/inference-engine/tests/functional/plugin/shared/include/single_layer_tests/mvn.hpp @@ -13,18 +13,17 @@ namespace LayerTestsDefinitions { typedef std::tuple< - InferenceEngine::SizeVector, // Input shapes - InferenceEngine::Precision, // Input precision - bool, // Across channels - bool, // Normalize variance - double, // Epsilon - std::string, // Device name - std::map // Config - > mvnParams; + InferenceEngine::SizeVector, // Input shapes + InferenceEngine::Precision, // Input precision + bool, // Across channels + bool, // Normalize variance + double, // Epsilon + std::string> mvnParams; // Device name class MvnLayerTest : public testing::WithParamInterface, virtual public LayerTestsUtils::LayerTestsCommon { public: static std::string getTestCaseName(testing::TestParamInfo obj); + protected: void SetUp() override; }; diff --git a/inference-engine/tests/functional/plugin/shared/src/single_layer_tests/mvn.cpp b/inference-engine/tests/functional/plugin/shared/src/single_layer_tests/mvn.cpp index 23fab214625396..e21fd7732d653a 100644 --- a/inference-engine/tests/functional/plugin/shared/src/single_layer_tests/mvn.cpp +++ b/inference-engine/tests/functional/plugin/shared/src/single_layer_tests/mvn.cpp @@ -27,8 +27,7 @@ std::string MvnLayerTest::getTestCaseName(testing::TestParamInfo obj) bool acrossChannels, normalizeVariance; double eps; std::string targetDevice; - std::map configuration; - std::tie(inputShapes, inputPrecision, acrossChannels, normalizeVariance, eps, targetDevice, configuration) = obj.param; + std::tie(inputShapes, inputPrecision, acrossChannels, normalizeVariance, eps, targetDevice) = obj.param; std::ostringstream result; result << "IS=" << CommonTestUtils::vec2str(inputShapes) << "_"; result << "Precision=" << inputPrecision.name() << "_"; @@ -36,11 +35,6 @@ std::string MvnLayerTest::getTestCaseName(testing::TestParamInfo obj) result << "NormalizeVariance=" << (normalizeVariance ? "TRUE" : "FALSE") << "_"; result << "Epsilon=" << eps << "_"; result << "TargetDevice=" << targetDevice; - if (!configuration.empty()) { - for (auto& configItem : configuration) { - result << "configItem=" << configItem.first << "_" << configItem.second << "_"; - } - } return result.str(); } @@ -49,7 +43,7 @@ void MvnLayerTest::SetUp() { InferenceEngine::Precision inputPrecision; bool acrossChanels, normalizeVariance; double eps; - std::tie(inputShapes, inputPrecision, acrossChanels, normalizeVariance, eps, targetDevice, configuration) = this->GetParam(); + std::tie(inputShapes, inputPrecision, acrossChanels, normalizeVariance, eps, targetDevice) = this->GetParam(); auto inType = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(inputPrecision); auto param = ngraph::builder::makeParams(inType, {inputShapes}); auto paramOuts = ngraph::helpers::convert2OutputVector(ngraph::helpers::castOps2Nodes(param)); @@ -60,5 +54,6 @@ void MvnLayerTest::SetUp() { TEST_P(MvnLayerTest, CompareWithRefs) { Run(); -} +}; + } // namespace LayerTestsDefinitions \ No newline at end of file diff --git a/inference-engine/tests/ie_test_utils/functional_test_utils/layer_test_utils.cpp b/inference-engine/tests/ie_test_utils/functional_test_utils/layer_test_utils.cpp index b03361f7e5e213..06152180953a3b 100644 --- a/inference-engine/tests/ie_test_utils/functional_test_utils/layer_test_utils.cpp +++ b/inference-engine/tests/ie_test_utils/functional_test_utils/layer_test_utils.cpp @@ -42,14 +42,7 @@ void LayerTestsCommon::Compare(const std::vector &expected, const const auto actualBuffer = lockedMemory.as(); const auto &precision = actual->getTensorDesc().getPrecision(); - auto bufferSize = actual->size(); - // With dynamic batch, you need to size - if (configuration.count(InferenceEngine::PluginConfigParams::KEY_DYN_BATCH_ENABLED)) { - auto batchSize = actual->getTensorDesc().getDims()[0]; - auto halfBatchSize = batchSize > 1 ? batchSize/ 2 : 1; - bufferSize = (actual->size() * halfBatchSize / batchSize); - } - const auto &size = bufferSize; + const auto &size = actual->size(); switch (precision) { case InferenceEngine::Precision::FP32: Compare(reinterpret_cast(expectedBuffer), reinterpret_cast(actualBuffer), diff --git a/inference-engine/tests/ie_test_utils/functional_test_utils/layer_test_utils.hpp b/inference-engine/tests/ie_test_utils/functional_test_utils/layer_test_utils.hpp index ce86d00c5b980c..7fdbc75f46926d 100644 --- a/inference-engine/tests/ie_test_utils/functional_test_utils/layer_test_utils.hpp +++ b/inference-engine/tests/ie_test_utils/functional_test_utils/layer_test_utils.hpp @@ -113,6 +113,7 @@ class LayerTestsCommon : public CommonTestUtils::TestsCommon { float threshold; InferenceEngine::CNNNetwork cnnNetwork; std::shared_ptr core; + virtual void Validate(); virtual std::vector> CalculateRefs(); From ce9c171f462c7451323c8bbfb48c57b02417ea4c Mon Sep 17 00:00:00 2001 From: Ilya Churaev Date: Wed, 16 Sep 2020 15:33:23 +0300 Subject: [PATCH 09/64] Fixed KW warning and review issues (#2263) --- ngraph/core/include/ngraph/node.hpp | 4 +++- .../ngraph/runtime/reference/gather.hpp | 4 ++++ ngraph/core/src/node.cpp | 20 +++++++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/ngraph/core/include/ngraph/node.hpp b/ngraph/core/include/ngraph/node.hpp index 8a9c92aad564ea..31c2ca2e4cc0b7 100644 --- a/ngraph/core/include/ngraph/node.hpp +++ b/ngraph/core/include/ngraph/node.hpp @@ -155,9 +155,11 @@ namespace ngraph protected: /// \brief Construct an unitialized Node - Node() {} + Node() = default; /// \brief Copying a node Node(const Node&); + /// \brief Assignment operator + Node& operator=(const Node&); /// \brief Construct an unitialized Node /// \param output_size Number of outputs for this node diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/gather.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/gather.hpp index 4ad4aa91165fbf..3dbfecf836bf7e 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/gather.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/gather.hpp @@ -149,6 +149,8 @@ namespace ngraph auto out_outer_coord_iter = out_outer_transform.begin(); for (const Coordinate& params_outer_coord : params_outer_transform) { + if (out_outer_coord_iter == out_outer_transform.end()) + break; const T* params_prime = ¶ms[params_outer_transform.index(params_outer_coord)]; T* out_outer = &out[out_outer_transform.index(*out_outer_coord_iter)]; @@ -156,6 +158,8 @@ namespace ngraph auto out_inner_coord_iter = out_inner_transform.begin(); for (const Coordinate& indices_outer_coord : indices_outer_transform) { + if (out_inner_coord_iter == out_inner_transform.end()) + break; const U* indices_prime = &indices[indices_outer_transform.index(indices_outer_coord)]; T* out_prime = &out_outer[out_inner_transform.index(*out_inner_coord_iter)]; diff --git a/ngraph/core/src/node.cpp b/ngraph/core/src/node.cpp index dd66060207155c..487b410f35eb5a 100644 --- a/ngraph/core/src/node.cpp +++ b/ngraph/core/src/node.cpp @@ -55,6 +55,26 @@ Node::Node(const Node& node) } } +Node& Node::operator=(const Node& node) +{ + this->m_control_dependents = node.m_control_dependents; + this->m_control_dependencies = node.m_control_dependencies; + this->m_instance_id = m_next_instance_id.fetch_add(1); + this->m_friendly_name = node.m_friendly_name; + this->m_provenance_tags = node.m_provenance_tags; + this->m_provenance_group = node.m_provenance_group; + this->m_inputs = node.m_inputs; + this->m_op_annotations = node.m_op_annotations; + this->m_rt_info = node.m_rt_info; + // cannot do it without copying node.m_inputs first due to too limiting const qualifiers + for (auto& input : m_inputs) + { + input = descriptor::Input(this, input.get_index(), input.get_output()); + input.get_output().add_input(&input); + } + return *this; +} + Node::Node(size_t output_size) : Node() { From fe49d5743b16f312ba7a1b764be3dbb8bb6423d1 Mon Sep 17 00:00:00 2001 From: Alexey Suhov Date: Wed, 16 Sep 2020 16:13:41 +0300 Subject: [PATCH 10/64] update OpenCV version to 4.5.0 (#2254) * update OpenCV version to 4.5.0 * fix Azure pipelines --- azure-pipelines.yml | 4 ++-- build-instruction.md | 2 +- inference-engine/cmake/dependencies.cmake | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 1d8d23bad32145..35114337919c19 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -336,14 +336,14 @@ jobs: # Add for gtest-parallel, it hangs now (CVS-33386) #python $(BUILD_DIR)\gtest-parallel\gtest-parallel $(BIN_DIR)\MklDnnFunctionalTests --workers=$(WORKERS_NUMBER) --print_test_times --dump_json_test_results=MklDnnFunctionalTests.json -- --gtest_print_time=1 - script: | - set PATH=$(REPO_DIR)\inference-engine\temp\tbb\bin;$(REPO_DIR)\inference-engine\temp\opencv_4.3.0\opencv\bin;%PATH% + set PATH=$(REPO_DIR)\inference-engine\temp\tbb\bin;$(REPO_DIR)\inference-engine\temp\opencv_4.5.0\opencv\bin;%PATH% set DATA_PATH=$(BUILD_DIR)\testdata set MODELS_PATH=$(BUILD_DIR)\testdata $(BIN_DIR)\MklDnnFunctionalTests --gtest_print_time=1 displayName: 'MklDnnFunctionalTests' continueOnError: false - script: | - set PATH=$(REPO_DIR)\inference-engine\temp\tbb\bin;$(REPO_DIR)\inference-engine\temp\opencv_4.3.0\opencv\bin;%PATH% + set PATH=$(REPO_DIR)\inference-engine\temp\tbb\bin;$(REPO_DIR)\inference-engine\temp\opencv_4.5.0\opencv\bin;%PATH% set DATA_PATH=$(BUILD_DIR)\testdata set MODELS_PATH=$(BUILD_DIR)\testdata $(BIN_DIR)\InferenceEngineCAPITests diff --git a/build-instruction.md b/build-instruction.md index c9f5341cd79dd2..29aa48183caa49 100644 --- a/build-instruction.md +++ b/build-instruction.md @@ -382,7 +382,7 @@ cmake -G "Visual Studio 15 2017 Win64" -T "Intel C++ Compiler 18.0" ^ 6. Before running the samples, add paths to the TBB and OpenCV binaries used for the build to the `%PATH%` environment variable. By default, TBB binaries are downloaded by the CMake-based script to the `/inference-engine/temp/tbb/bin` - folder, OpenCV binaries to the `/inference-engine/temp/opencv_4.3.0/opencv/bin` + folder, OpenCV binaries to the `/inference-engine/temp/opencv_4.5.0/opencv/bin` folder. ### Additional Build Options diff --git a/inference-engine/cmake/dependencies.cmake b/inference-engine/cmake/dependencies.cmake index 4f0f1086ef8778..473648109f28c5 100644 --- a/inference-engine/cmake/dependencies.cmake +++ b/inference-engine/cmake/dependencies.cmake @@ -181,9 +181,9 @@ endif () if (ENABLE_OPENCV) reset_deps_cache(OpenCV_DIR) - set(OPENCV_VERSION "4.3.0") - set(OPENCV_BUILD "060") - set(OPENCV_BUILD_YOCTO "073") + set(OPENCV_VERSION "4.5.0") + set(OPENCV_BUILD "36") + set(OPENCV_BUILD_YOCTO "337") if (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "aarch64") if(DEFINED ENV{THIRDPARTY_SERVER_PATH}) From 1337997134d7e1af6cd89a6d8f442c22f1dfbc21 Mon Sep 17 00:00:00 2001 From: Piotr Szmelczynski Date: Wed, 16 Sep 2020 15:33:02 +0200 Subject: [PATCH 11/64] Test refactor (#2225) --- ngraph/test/backend/max.in.cpp | 408 +++++----------- ngraph/test/backend/min.in.cpp | 358 +++++--------- ngraph/test/backend/minimum.in.cpp | 61 +-- .../test/backend/quantize_dequantize.in.cpp | 458 +++++++----------- 4 files changed, 439 insertions(+), 846 deletions(-) diff --git a/ngraph/test/backend/max.in.cpp b/ngraph/test/backend/max.in.cpp index 81730e26ec5151..ce09f3c94b8137 100644 --- a/ngraph/test/backend/max.in.cpp +++ b/ngraph/test/backend/max.in.cpp @@ -16,14 +16,9 @@ #include "gtest/gtest.h" #include "ngraph/ngraph.hpp" -#include "ngraph/runtime/tensor.hpp" -#include "runtime/backend.hpp" -#include "util/all_close.hpp" -#include "util/all_close_f.hpp" -#include "util/known_element_types.hpp" -#include "util/ndarray.hpp" +#include "util/engine/test_engines.hpp" +#include "util/test_case.hpp" #include "util/test_control.hpp" -#include "util/test_tools.hpp" NGRAPH_SUPPRESS_DEPRECATED_START @@ -31,6 +26,7 @@ using namespace std; using namespace ngraph; static string s_manifest = "${MANIFEST}"; +using TestEngine = test::ENGINE_CLASS_NAME(${BACKEND_NAME}); // Trivial case with no reduced axes. NGRAPH_TEST(${BACKEND_NAME}, max_trivial) @@ -39,17 +35,12 @@ NGRAPH_TEST(${BACKEND_NAME}, max_trivial) auto A = make_shared(element::f32, shape); auto f = make_shared(make_shared(A, AxisSet{}), ParameterVector{A}); - auto backend = runtime::Backend::create("${BACKEND_NAME}"); + std::vector a{1, 2, 3, 4}; - // Create some tensors for input/output - auto a = backend->create_tensor(element::f32, shape); - copy_data(a, vector{1, 2, 3, 4}); - auto result = backend->create_tensor(element::f32, shape); - - auto handle = backend->compile(f); - handle->call_with_validate({result}, {a}); - EXPECT_TRUE(test::all_close_f( - (vector{1, 2, 3, 4}), read_vector(result), MIN_FLOAT_TOLERANCE_BITS)); + auto test_case = test::TestCase(f); + test_case.add_input({a}); + test_case.add_expected_output(shape, {1, 2, 3, 4}); + test_case.run(MIN_FLOAT_TOLERANCE_BITS); } NGRAPH_TEST(${BACKEND_NAME}, max_trivial_int8) @@ -58,16 +49,12 @@ NGRAPH_TEST(${BACKEND_NAME}, max_trivial_int8) auto A = make_shared(element::i8, shape); auto f = make_shared(make_shared(A, AxisSet{}), ParameterVector{A}); - auto backend = runtime::Backend::create("${BACKEND_NAME}"); - - // Create some tensors for input/output - auto a = backend->create_tensor(element::i8, shape); - copy_data(a, vector{1, 2, 3, 4}); - auto result = backend->create_tensor(element::i8, shape); + std::vector a{1, 2, 3, 4}; - auto handle = backend->compile(f); - handle->call_with_validate({result}, {a}); - EXPECT_EQ((vector{1, 2, 3, 4}), read_vector(result)); + auto test_case = test::TestCase(f); + test_case.add_input({a}); + test_case.add_expected_output(shape, {1, 2, 3, 4}); + test_case.run(); } // Failure has been reported at 5D for some reason @@ -77,20 +64,14 @@ NGRAPH_TEST(${BACKEND_NAME}, max_trivial_5d) auto A = make_shared(element::f32, shape); auto f = make_shared(make_shared(A, AxisSet{}), ParameterVector{A}); - auto backend = runtime::Backend::create("${BACKEND_NAME}"); + std::vector a{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; - // Create some tensors for input/output - auto a = backend->create_tensor(element::f32, shape); - copy_data(a, vector{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}); - auto result = backend->create_tensor(element::f32, shape); - - auto handle = backend->compile(f); - handle->call_with_validate({result}, {a}); - EXPECT_TRUE(test::all_close_f((vector{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}), - read_vector(result), - MIN_FLOAT_TOLERANCE_BITS)); + auto test_case = test::TestCase(f); + test_case.add_input({a}); + test_case.add_expected_output(shape, {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}); + test_case.run(MIN_FLOAT_TOLERANCE_BITS); } NGRAPH_TEST(${BACKEND_NAME}, max_trivial_5d_int32) @@ -99,19 +80,14 @@ NGRAPH_TEST(${BACKEND_NAME}, max_trivial_5d_int32) auto A = make_shared(element::i32, shape); auto f = make_shared(make_shared(A, AxisSet{}), ParameterVector{A}); - auto backend = runtime::Backend::create("${BACKEND_NAME}"); - - // Create some tensors for input/output - auto a = backend->create_tensor(element::i32, shape); - copy_data(a, vector{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}); - auto result = backend->create_tensor(element::i32, shape); + std::vector a{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; - auto handle = backend->compile(f); - handle->call_with_validate({result}, {a}); - EXPECT_EQ((vector{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}), - read_vector(result)); + auto test_case = test::TestCase(f); + test_case.add_input({a}); + test_case.add_expected_output(shape, {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}); + test_case.run(); } NGRAPH_TEST(${BACKEND_NAME}, max_to_scalar) @@ -120,21 +96,12 @@ NGRAPH_TEST(${BACKEND_NAME}, max_to_scalar) auto A = make_shared(element::f32, shape); auto f = make_shared(make_shared(A, AxisSet{0, 1}), ParameterVector{A}); - auto backend = runtime::Backend::create("${BACKEND_NAME}"); + std::vector a{1, 2, 3, 4}; - // Create some tensors for input/output - auto a = backend->create_tensor(element::f32, shape); - copy_data(a, vector{1, 2, 3, 4}); - auto result = backend->create_tensor(element::f32, Shape{}); - - auto handle = backend->compile(f); - handle->call_with_validate({result}, {a}); - EXPECT_TRUE(test::all_close_f((vector{4}), read_vector(result))); - - // For some reason I'm feeling extra paranoid about making sure reduction doesn't clobber the - // input tensors, so let's do this too. - EXPECT_TRUE(test::all_close_f( - (vector{1, 2, 3, 4}), read_vector(a), MIN_FLOAT_TOLERANCE_BITS)); + auto test_case = test::TestCase(f); + test_case.add_input(a); + test_case.add_expected_output(Shape{}, {4}); + test_case.run(); } NGRAPH_TEST(${BACKEND_NAME}, max_to_scalar_int8) @@ -143,16 +110,12 @@ NGRAPH_TEST(${BACKEND_NAME}, max_to_scalar_int8) auto A = make_shared(element::i8, shape); auto f = make_shared(make_shared(A, AxisSet{0, 1}), ParameterVector{A}); - auto backend = runtime::Backend::create("${BACKEND_NAME}"); + std::vector a{1, 2, 3, 4}; - // Create some tensors for input/output - auto a = backend->create_tensor(element::i8, shape); - copy_data(a, vector{1, 2, 3, 4}); - auto result = backend->create_tensor(element::i8, Shape{}); - - auto handle = backend->compile(f); - handle->call_with_validate({result}, {a}); - EXPECT_EQ((vector{4}), read_vector(result)); + auto test_case = test::TestCase(f); + test_case.add_input({a}); + test_case.add_expected_output(shape, {4}); + test_case.run(); } NGRAPH_TEST(${BACKEND_NAME}, max_matrix_columns) @@ -162,21 +125,12 @@ NGRAPH_TEST(${BACKEND_NAME}, max_matrix_columns) Shape shape_rt{2}; auto f = make_shared(make_shared(A, AxisSet{0}), ParameterVector{A}); - auto backend = runtime::Backend::create("${BACKEND_NAME}"); - - // Create some tensors for input/output - auto a = backend->create_tensor(element::f32, shape_a); - copy_data(a, vector{1, 2, 3, 4, 5, 6}); - auto result = backend->create_tensor(element::f32, shape_rt); + std::vector a{1, 2, 3, 4, 5, 6}; - auto handle = backend->compile(f); - handle->call_with_validate({result}, {a}); - EXPECT_TRUE(test::all_close_f((vector{5, 6}), read_vector(result))); - - // For some reason I'm feeling extra paranoid about making sure reduction doesn't clobber the - // input tensors, so let's do this too. - EXPECT_TRUE(test::all_close_f( - (vector{1, 2, 3, 4, 5, 6}), read_vector(a), MIN_FLOAT_TOLERANCE_BITS)); + auto test_case = test::TestCase(f); + test_case.add_input({a}); + test_case.add_expected_output(shape_rt, {5, 6}); + test_case.run(); } NGRAPH_TEST(${BACKEND_NAME}, max_matrix_rows) @@ -186,21 +140,12 @@ NGRAPH_TEST(${BACKEND_NAME}, max_matrix_rows) Shape shape_rt{3}; auto f = make_shared(make_shared(A, AxisSet{1}), ParameterVector{A}); - auto backend = runtime::Backend::create("${BACKEND_NAME}"); - - // Create some tensors for input/output - auto a = backend->create_tensor(element::f32, shape_a); - copy_data(a, vector{1, 2, 3, 4, 5, 6}); - auto result = backend->create_tensor(element::f32, shape_rt); + std::vector a{1, 2, 3, 4, 5, 6}; - auto handle = backend->compile(f); - handle->call_with_validate({result}, {a}); - EXPECT_TRUE(test::all_close_f((vector{2, 4, 6}), read_vector(result))); - - // For some reason I'm feeling extra paranoid about making sure reduction doesn't clobber the - // input tensors, so let's do this too. - EXPECT_TRUE(test::all_close_f( - (vector{1, 2, 3, 4, 5, 6}), read_vector(a), MIN_FLOAT_TOLERANCE_BITS)); + auto test_case = test::TestCase(f); + test_case.add_input({a}); + test_case.add_expected_output(shape_rt, {2, 4, 6}); + test_case.run(); } NGRAPH_TEST(${BACKEND_NAME}, max_matrix_rows_int32) @@ -210,20 +155,12 @@ NGRAPH_TEST(${BACKEND_NAME}, max_matrix_rows_int32) Shape shape_rt{3}; auto f = make_shared(make_shared(A, AxisSet{1}), ParameterVector{A}); - auto backend = runtime::Backend::create("${BACKEND_NAME}"); - - // Create some tensors for input/output - auto a = backend->create_tensor(element::i32, shape_a); - copy_data(a, vector{1, 2, 3, 4, 5, 6}); - auto result = backend->create_tensor(element::i32, shape_rt); + std::vector a{1, 2, 3, 4, 5, 6}; - auto handle = backend->compile(f); - handle->call_with_validate({result}, {a}); - EXPECT_EQ((vector{2, 4, 6}), read_vector(result)); - - // For some reason I'm feeling extra paranoid about making sure reduction doesn't clobber the - // input tensors, so let's do this too. - EXPECT_EQ((vector{1, 2, 3, 4, 5, 6}), read_vector(a)); + auto test_case = test::TestCase(f); + test_case.add_input({a}); + test_case.add_expected_output(shape_rt, {2, 4, 6}); + test_case.run(); } NGRAPH_TEST(${BACKEND_NAME}, max_matrix_rows_zero) @@ -233,25 +170,15 @@ NGRAPH_TEST(${BACKEND_NAME}, max_matrix_rows_zero) Shape shape_rt{3}; auto f = make_shared(make_shared(A, AxisSet{1}), ParameterVector{A}); - auto backend = runtime::Backend::create("${BACKEND_NAME}"); - - // Create some tensors for input/output - auto a = backend->create_tensor(element::f32, shape_a); - copy_data(a, vector{}); - auto result = backend->create_tensor(element::f32, shape_rt); - copy_data(result, vector({3, 3, 3})); - - auto handle = backend->compile(f); - handle->call_with_validate({result}, {a}); - EXPECT_EQ((vector{-std::numeric_limits::infinity(), - -std::numeric_limits::infinity(), - -std::numeric_limits::infinity()}), - read_vector(result)); - - // For some reason I'm feeling extra paranoid about making sure reduction doesn't clobber the - // input tensors, so let's do this too. - EXPECT_TRUE( - test::all_close_f((vector{}), read_vector(a), MIN_FLOAT_TOLERANCE_BITS)); + std::vector a{}; + + auto test_case = test::TestCase(f); + test_case.add_input({a}); + test_case.add_expected_output(shape_rt, + {-std::numeric_limits::infinity(), + -std::numeric_limits::infinity(), + -std::numeric_limits::infinity()}); + test_case.run(); } NGRAPH_TEST(${BACKEND_NAME}, max_matrix_rows_zero_int32) @@ -261,22 +188,16 @@ NGRAPH_TEST(${BACKEND_NAME}, max_matrix_rows_zero_int32) Shape shape_rt{3}; auto f = make_shared(make_shared(A, AxisSet{1}), ParameterVector{A}); - auto backend = runtime::Backend::create("${BACKEND_NAME}"); - - // Create some tensors for input/output - auto a = backend->create_tensor(element::i32, shape_a); - copy_data(a, vector{}); - auto result = backend->create_tensor(element::i32, shape_rt); - copy_data(result, vector({3, 3, 3})); + std::vector a{}; int32_t minval = std::numeric_limits::has_infinity ? -std::numeric_limits::infinity() : std::numeric_limits::min(); - auto handle = backend->compile(f); - handle->call_with_validate({result}, {a}); - EXPECT_EQ((vector{minval, minval, minval}), read_vector(result)); - EXPECT_EQ((vector{}), read_vector(a)); + auto test_case = test::TestCase(f); + test_case.add_input({a}); + test_case.add_expected_output(shape_rt, {minval, minval, minval}); + test_case.run(); } NGRAPH_TEST(${BACKEND_NAME}, max_matrix_cols_zero) @@ -287,24 +208,14 @@ NGRAPH_TEST(${BACKEND_NAME}, max_matrix_cols_zero) Shape shape_rt{2}; auto f = make_shared(make_shared(A, AxisSet{0}), ParameterVector{A}); - auto backend = runtime::Backend::create("${BACKEND_NAME}"); - - // Create some tensors for input/output - auto a = backend->create_tensor(element::f32, shape_a); - copy_data(a, vector{}); - auto result = backend->create_tensor(element::f32, shape_rt); - copy_data(result, vector({3, 3})); + std::vector a{}; - auto handle = backend->compile(f); - handle->call_with_validate({result}, {a}); - EXPECT_EQ((vector{-std::numeric_limits::infinity(), - -std::numeric_limits::infinity()}), - read_vector(result)); - - // For some reason I'm feeling extra paranoid about making sure reduction doesn't clobber the - // input tensors, so let's do this too. - EXPECT_TRUE( - test::all_close_f((vector{}), read_vector(a), MIN_FLOAT_TOLERANCE_BITS)); + auto test_case = test::TestCase(f); + test_case.add_input({a}); + test_case.add_expected_output( + shape_rt, + {-std::numeric_limits::infinity(), -std::numeric_limits::infinity()}); + test_case.run(); } NGRAPH_TEST(${BACKEND_NAME}, max_vector_zero) @@ -314,22 +225,12 @@ NGRAPH_TEST(${BACKEND_NAME}, max_vector_zero) Shape shape_rt{}; auto f = make_shared(make_shared(A, AxisSet{0}), ParameterVector{A}); - auto backend = runtime::Backend::create("${BACKEND_NAME}"); - - // Create some tensors for input/output - auto a = backend->create_tensor(element::f32, shape_a); - copy_data(a, vector{}); - auto result = backend->create_tensor(element::f32, shape_rt); - copy_data(result, vector({3})); + std::vector a{}; - auto handle = backend->compile(f); - handle->call_with_validate({result}, {a}); - EXPECT_EQ((vector{-std::numeric_limits::infinity()}), read_vector(result)); - - // For some reason I'm feeling extra paranoid about making sure reduction doesn't clobber the - // input tensors, so let's do this too. - EXPECT_TRUE( - test::all_close_f((vector{}), read_vector(a), MIN_FLOAT_TOLERANCE_BITS)); + auto test_case = test::TestCase(f); + test_case.add_input({a}); + test_case.add_expected_output(shape_rt, {-std::numeric_limits::infinity()}); + test_case.run(); } NGRAPH_TEST(${BACKEND_NAME}, max_matrix_to_scalar_zero_by_zero) @@ -339,22 +240,12 @@ NGRAPH_TEST(${BACKEND_NAME}, max_matrix_to_scalar_zero_by_zero) Shape shape_rt{}; auto f = make_shared(make_shared(A, AxisSet{0, 1}), ParameterVector{A}); - auto backend = runtime::Backend::create("${BACKEND_NAME}"); - - // Create some tensors for input/output - auto a = backend->create_tensor(element::f32, shape_a); - copy_data(a, vector{}); - auto result = backend->create_tensor(element::f32, shape_rt); - copy_data(result, vector({3})); + std::vector a{}; - auto handle = backend->compile(f); - handle->call_with_validate({result}, {a}); - EXPECT_EQ((vector{-std::numeric_limits::infinity()}), read_vector(result)); - - // For some reason I'm feeling extra paranoid about making sure reduction doesn't clobber the - // input tensors, so let's do this too. - EXPECT_TRUE( - test::all_close_f((vector{}), read_vector(a), MIN_FLOAT_TOLERANCE_BITS)); + auto test_case = test::TestCase(f); + test_case.add_input({a}); + test_case.add_expected_output(shape_rt, {-std::numeric_limits::infinity()}); + test_case.run(); } NGRAPH_TEST(${BACKEND_NAME}, max_3d_to_matrix_most_sig) @@ -364,19 +255,13 @@ NGRAPH_TEST(${BACKEND_NAME}, max_3d_to_matrix_most_sig) Shape shape_rt{3, 3}; auto f = make_shared(make_shared(A, AxisSet{0}), ParameterVector{A}); - auto backend = runtime::Backend::create("${BACKEND_NAME}"); - - // Create some tensors for input/output - auto a = backend->create_tensor(element::f32, shape_a); - copy_data(a, vector{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, - 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27}); - auto result = backend->create_tensor(element::f32, shape_rt); + std::vector a{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, + 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27}; - auto handle = backend->compile(f); - handle->call_with_validate({result}, {a}); - EXPECT_TRUE(test::all_close_f((vector{19, 20, 21, 22, 23, 24, 25, 26, 27}), - read_vector(result), - MIN_FLOAT_TOLERANCE_BITS)); + auto test_case = test::TestCase(f); + test_case.add_input({a}); + test_case.add_expected_output(shape_rt, {19, 20, 21, 22, 23, 24, 25, 26, 27}); + test_case.run(MIN_FLOAT_TOLERANCE_BITS); } NGRAPH_TEST(${BACKEND_NAME}, max_3d_to_matrix_least_sig) @@ -386,19 +271,13 @@ NGRAPH_TEST(${BACKEND_NAME}, max_3d_to_matrix_least_sig) Shape shape_rt{3, 3}; auto f = make_shared(make_shared(A, AxisSet{2}), ParameterVector{A}); - auto backend = runtime::Backend::create("${BACKEND_NAME}"); + std::vector a{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, + 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27}; - // Create some tensors for input/output - auto a = backend->create_tensor(element::f32, shape_a); - copy_data(a, vector{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, - 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27}); - auto result = backend->create_tensor(element::f32, shape_rt); - - auto handle = backend->compile(f); - handle->call_with_validate({result}, {a}); - EXPECT_TRUE(test::all_close_f((vector{3, 6, 9, 12, 15, 18, 21, 24, 27}), - read_vector(result), - MIN_FLOAT_TOLERANCE_BITS)); + auto test_case = test::TestCase(f); + test_case.add_input({a}); + test_case.add_expected_output(shape_rt, {3, 6, 9, 12, 15, 18, 21, 24, 27}); + test_case.run(MIN_FLOAT_TOLERANCE_BITS); } NGRAPH_TEST(${BACKEND_NAME}, max_3d_to_vector) @@ -407,20 +286,13 @@ NGRAPH_TEST(${BACKEND_NAME}, max_3d_to_vector) auto A = make_shared(element::f32, shape_a); Shape shape_rt{3}; auto f = make_shared(make_shared(A, AxisSet{0, 1}), ParameterVector{A}); + std::vector a{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, + 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27}; - auto backend = runtime::Backend::create("${BACKEND_NAME}"); - - // Create some tensors for input/output - auto a = backend->create_tensor(element::f32, shape_a); - copy_data(a, vector{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, - 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27}); - auto result = backend->create_tensor(element::f32, shape_rt); - - auto handle = backend->compile(f); - handle->call_with_validate({result}, {a}); - EXPECT_TRUE(test::all_close_f((vector{25.0f, 26.0f, 27.0f}), - read_vector(result), - MIN_FLOAT_TOLERANCE_BITS)); + auto test_case = test::TestCase(f); + test_case.add_input({a}); + test_case.add_expected_output(shape_rt, {25.0f, 26.0f, 27.0f}); + test_case.run(MIN_FLOAT_TOLERANCE_BITS); } NGRAPH_TEST(${BACKEND_NAME}, max_3d_to_scalar) @@ -430,18 +302,13 @@ NGRAPH_TEST(${BACKEND_NAME}, max_3d_to_scalar) Shape shape_rt{}; auto f = make_shared(make_shared(A, AxisSet{0, 1, 2}), ParameterVector{A}); - auto backend = runtime::Backend::create("${BACKEND_NAME}"); - - // Create some tensors for input/output - auto a = backend->create_tensor(element::f32, shape_a); - copy_data(a, vector{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1}); - auto result = backend->create_tensor(element::f32, shape_rt); + std::vector a{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, + 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1}; - auto handle = backend->compile(f); - handle->call_with_validate({result}, {a}); - EXPECT_TRUE(test::all_close_f( - (vector{14.0f}), read_vector(result), MIN_FLOAT_TOLERANCE_BITS)); + auto test_case = test::TestCase(f); + test_case.add_input({a}); + test_case.add_expected_output(shape_rt, {14.0f}); + test_case.run(MIN_FLOAT_TOLERANCE_BITS); } NGRAPH_TEST(${BACKEND_NAME}, max_3d_to_scalar_int32) @@ -451,17 +318,13 @@ NGRAPH_TEST(${BACKEND_NAME}, max_3d_to_scalar_int32) Shape shape_rt{}; auto f = make_shared(make_shared(A, AxisSet{0, 1, 2}), ParameterVector{A}); - auto backend = runtime::Backend::create("${BACKEND_NAME}"); + std::vector a{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, + 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1}; - // Create some tensors for input/output - auto a = backend->create_tensor(element::i32, shape_a); - copy_data(a, vector{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1}); - auto result = backend->create_tensor(element::i32, shape_rt); - - auto handle = backend->compile(f); - handle->call_with_validate({result}, {a}); - EXPECT_EQ((vector{14}), read_vector(result)); + auto test_case = test::TestCase(f); + test_case.add_input({a}); + test_case.add_expected_output(shape_rt, {14}); + test_case.run(); } NGRAPH_TEST(${BACKEND_NAME}, max_3d_to_scalar_double) @@ -471,17 +334,14 @@ NGRAPH_TEST(${BACKEND_NAME}, max_3d_to_scalar_double) Shape shape_rt{}; auto f = make_shared(make_shared(A, AxisSet{0, 1, 2}), ParameterVector{A}); - auto backend = runtime::Backend::create("${BACKEND_NAME}"); - - // Create some tensors for input/output - auto a = backend->create_tensor(element::f64, shape_a); - copy_data(a, vector{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1}); - auto result = backend->create_tensor(element::f64, shape_rt); +std: + vector a{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, + 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1}; - auto handle = backend->compile(f); - handle->call_with_validate({result}, {a}); - EXPECT_TRUE(test::all_close_f((vector{14}), read_vector(result))); + auto test_case = test::TestCase(f); + test_case.add_input({a}); + test_case.add_expected_output(shape_rt, {14}); + test_case.run(); } NGRAPH_TEST(${BACKEND_NAME}, max_3d_eliminate_zero_dim) @@ -491,20 +351,16 @@ NGRAPH_TEST(${BACKEND_NAME}, max_3d_eliminate_zero_dim) Shape shape_rt{3, 2}; auto f = make_shared(make_shared(A, AxisSet{1}), ParameterVector{A}); - auto backend = runtime::Backend::create("${BACKEND_NAME}"); - - // Create some tensors for input/output - auto a = backend->create_tensor(element::f32, shape_a); - copy_data(a, vector{}); - auto result = backend->create_tensor(element::f32, shape_rt); - - // Overwrite the initial result vector to make sure we're not just coincidentally getting the - // right value. - copy_data(result, vector{2112, 2112, 2112, 2112, 2112, 2112}); - - float mi = -std::numeric_limits::infinity(); - - auto handle = backend->compile(f); - handle->call_with_validate({result}, {a}); - EXPECT_EQ((vector{mi, mi, mi, mi, mi, mi}), read_vector(result)); + std::vector a{}; + + auto test_case = test::TestCase(f); + test_case.add_input({a}); + test_case.add_expected_output(shape_rt, + {-std::numeric_limits::infinity(), + -std::numeric_limits::infinity(), + -std::numeric_limits::infinity(), + -std::numeric_limits::infinity(), + -std::numeric_limits::infinity(), + -std::numeric_limits::infinity()}); + test_case.run(); } diff --git a/ngraph/test/backend/min.in.cpp b/ngraph/test/backend/min.in.cpp index 6080e6c890fc1c..a6cc47e63e79d4 100644 --- a/ngraph/test/backend/min.in.cpp +++ b/ngraph/test/backend/min.in.cpp @@ -16,14 +16,9 @@ #include "gtest/gtest.h" #include "ngraph/ngraph.hpp" -#include "ngraph/runtime/tensor.hpp" -#include "runtime/backend.hpp" -#include "util/all_close.hpp" -#include "util/all_close_f.hpp" -#include "util/known_element_types.hpp" -#include "util/ndarray.hpp" +#include "util/engine/test_engines.hpp" +#include "util/test_case.hpp" #include "util/test_control.hpp" -#include "util/test_tools.hpp" NGRAPH_SUPPRESS_DEPRECATED_START @@ -31,6 +26,7 @@ using namespace std; using namespace ngraph; static string s_manifest = "${MANIFEST}"; +using TestEngine = test::ENGINE_CLASS_NAME(${BACKEND_NAME}); // Trivial case with no reduced axes. NGRAPH_TEST(${BACKEND_NAME}, min_trivial) @@ -39,17 +35,12 @@ NGRAPH_TEST(${BACKEND_NAME}, min_trivial) auto A = make_shared(element::f32, shape); auto f = make_shared(make_shared(A, AxisSet{}), ParameterVector{A}); - auto backend = runtime::Backend::create("${BACKEND_NAME}"); + std::vector a{1, 2, 3, 4}; - // Create some tensors for input/output - auto a = backend->create_tensor(element::f32, shape); - copy_data(a, vector{1, 2, 3, 4}); - auto result = backend->create_tensor(element::f32, shape); - - auto handle = backend->compile(f); - handle->call_with_validate({result}, {a}); - EXPECT_TRUE(test::all_close_f( - (vector{1, 2, 3, 4}), read_vector(result), MIN_FLOAT_TOLERANCE_BITS)); + auto test_case = test::TestCase(f); + test_case.add_input({a}); + test_case.add_expected_output(shape, {1, 2, 3, 4}); + test_case.run(MIN_FLOAT_TOLERANCE_BITS); } // Failure has been reported at 5D for some reason @@ -58,21 +49,14 @@ NGRAPH_TEST(${BACKEND_NAME}, min_trivial_5d) Shape shape{2, 2, 2, 2, 2}; auto A = make_shared(element::f32, shape); auto f = make_shared(make_shared(A, AxisSet{}), ParameterVector{A}); - - auto backend = runtime::Backend::create("${BACKEND_NAME}"); - - // Create some tensors for input/output - auto a = backend->create_tensor(element::f32, shape); - copy_data(a, vector{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}); - auto result = backend->create_tensor(element::f32, shape); - - auto handle = backend->compile(f); - handle->call_with_validate({result}, {a}); - EXPECT_TRUE(test::all_close_f((vector{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}), - read_vector(result), - MIN_FLOAT_TOLERANCE_BITS)); + std::vector a{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; + + auto test_case = test::TestCase(f); + test_case.add_input({a}); + test_case.add_expected_output(shape, {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}); + test_case.run(MIN_FLOAT_TOLERANCE_BITS); } NGRAPH_TEST(${BACKEND_NAME}, min_trivial_5d_int32) @@ -81,19 +65,14 @@ NGRAPH_TEST(${BACKEND_NAME}, min_trivial_5d_int32) auto A = make_shared(element::i32, shape); auto f = make_shared(make_shared(A, AxisSet{}), ParameterVector{A}); - auto backend = runtime::Backend::create("${BACKEND_NAME}"); + std::vector a{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; - // Create some tensors for input/output - auto a = backend->create_tensor(element::i32, shape); - copy_data(a, vector{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}); - auto result = backend->create_tensor(element::i32, shape); - - auto handle = backend->compile(f); - handle->call_with_validate({result}, {a}); - EXPECT_EQ((vector{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}), - read_vector(result)); + auto test_case = test::TestCase(f); + test_case.add_input({a}); + test_case.add_expected_output(shape, {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}); + test_case.run(); } NGRAPH_TEST(${BACKEND_NAME}, min_to_scalar) @@ -102,22 +81,12 @@ NGRAPH_TEST(${BACKEND_NAME}, min_to_scalar) auto A = make_shared(element::f32, shape); auto f = make_shared(make_shared(A, AxisSet{0, 1}), ParameterVector{A}); - auto backend = runtime::Backend::create("${BACKEND_NAME}"); - - // Create some tensors for input/output - auto a = backend->create_tensor(element::f32, shape); - copy_data(a, vector{1, 2, 3, 4}); - auto result = backend->create_tensor(element::f32, Shape{}); + std::vector a{1, 2, 3, 4}; - auto handle = backend->compile(f); - handle->call_with_validate({result}, {a}); - EXPECT_TRUE(test::all_close_f( - (vector{1}), read_vector(result), MIN_FLOAT_TOLERANCE_BITS)); - - // For some reason I'm feeling extra paranoid about making sure reduction doesn't clobber the - // input tensors, so let's do this too. - EXPECT_TRUE(test::all_close_f( - (vector{1, 2, 3, 4}), read_vector(a), MIN_FLOAT_TOLERANCE_BITS)); + auto test_case = test::TestCase(f); + test_case.add_input({a}); + test_case.add_expected_output(Shape{}, {1}); + test_case.run(MIN_FLOAT_TOLERANCE_BITS); } NGRAPH_TEST(${BACKEND_NAME}, min_to_scalar_int8) @@ -126,20 +95,12 @@ NGRAPH_TEST(${BACKEND_NAME}, min_to_scalar_int8) auto A = make_shared(element::i8, shape); auto f = make_shared(make_shared(A, AxisSet{0, 1}), ParameterVector{A}); - auto backend = runtime::Backend::create("${BACKEND_NAME}"); - - // Create some tensors for input/output - auto a = backend->create_tensor(element::i8, shape); - copy_data(a, vector{1, 2, 3, 4}); - auto result = backend->create_tensor(element::i8, Shape{}); + std::vector a{1, 2, 3, 4}; - auto handle = backend->compile(f); - handle->call_with_validate({result}, {a}); - EXPECT_EQ((vector{1}), read_vector(result)); - - // For some reason I'm feeling extra paranoid about making sure reduction doesn't clobber the - // input tensors, so let's do this too. - EXPECT_EQ((vector{1, 2, 3, 4}), read_vector(a)); + auto test_case = test::TestCase(f); + test_case.add_input({a}); + test_case.add_expected_output(Shape{}, {1}); + test_case.run(); } NGRAPH_TEST(${BACKEND_NAME}, min_matrix_columns) @@ -149,22 +110,12 @@ NGRAPH_TEST(${BACKEND_NAME}, min_matrix_columns) Shape shape_rt{2}; auto f = make_shared(make_shared(A, AxisSet{0}), ParameterVector{A}); - auto backend = runtime::Backend::create("${BACKEND_NAME}"); - - // Create some tensors for input/output - auto a = backend->create_tensor(element::f32, shape_a); - copy_data(a, vector{1, 2, 3, 4, 5, 6}); - auto result = backend->create_tensor(element::f32, shape_rt); + std::vector a{1, 2, 3, 4, 5, 6}; - auto handle = backend->compile(f); - handle->call_with_validate({result}, {a}); - EXPECT_TRUE(test::all_close_f( - (vector{1, 2}), read_vector(result), MIN_FLOAT_TOLERANCE_BITS)); - - // For some reason I'm feeling extra paranoid about making sure reduction doesn't clobber the - // input tensors, so let's do this too. - EXPECT_TRUE(test::all_close_f( - (vector{1, 2, 3, 4, 5, 6}), read_vector(a), MIN_FLOAT_TOLERANCE_BITS)); + auto test_case = test::TestCase(f); + test_case.add_input({a}); + test_case.add_expected_output(shape_rt, {1, 2}); + test_case.run(MIN_FLOAT_TOLERANCE_BITS); } NGRAPH_TEST(${BACKEND_NAME}, min_matrix_rows) @@ -174,22 +125,12 @@ NGRAPH_TEST(${BACKEND_NAME}, min_matrix_rows) Shape shape_rt{3}; auto f = make_shared(make_shared(A, AxisSet{1}), ParameterVector{A}); - auto backend = runtime::Backend::create("${BACKEND_NAME}"); - - // Create some tensors for input/output - auto a = backend->create_tensor(element::f32, shape_a); - copy_data(a, vector{1, 2, 3, 4, 5, 6}); - auto result = backend->create_tensor(element::f32, shape_rt); + std::vector a{1, 2, 3, 4, 5, 6}; - auto handle = backend->compile(f); - handle->call_with_validate({result}, {a}); - EXPECT_TRUE(test::all_close_f( - (vector{1, 3, 5}), read_vector(result), MIN_FLOAT_TOLERANCE_BITS)); - - // For some reason I'm feeling extra paranoid about making sure reduction doesn't clobber the - // input tensors, so let's do this too. - EXPECT_TRUE(test::all_close_f( - (vector{1, 2, 3, 4, 5, 6}), read_vector(a), MIN_FLOAT_TOLERANCE_BITS)); + auto test_case = test::TestCase(f); + test_case.add_input({a}); + test_case.add_expected_output(shape_rt, {1, 3, 5}); + test_case.run(MIN_FLOAT_TOLERANCE_BITS); } NGRAPH_TEST(${BACKEND_NAME}, min_matrix_rows_int32) @@ -199,20 +140,12 @@ NGRAPH_TEST(${BACKEND_NAME}, min_matrix_rows_int32) Shape shape_rt{3}; auto f = make_shared(make_shared(A, AxisSet{1}), ParameterVector{A}); - auto backend = runtime::Backend::create("${BACKEND_NAME}"); - - // Create some tensors for input/output - auto a = backend->create_tensor(element::i32, shape_a); - copy_data(a, vector{1, 2, 3, 4, 5, 6}); - auto result = backend->create_tensor(element::i32, shape_rt); - - auto handle = backend->compile(f); - handle->call_with_validate({result}, {a}); - EXPECT_EQ((vector{1, 3, 5}), read_vector(result)); + std::vector a{1, 2, 3, 4, 5, 6}; - // For some reason I'm feeling extra paranoid about making sure reduction doesn't clobber the - // input tensors, so let's do this too. - EXPECT_EQ((vector{1, 2, 3, 4, 5, 6}), read_vector(a)); + auto test_case = test::TestCase(f); + test_case.add_input({a}); + test_case.add_expected_output(shape_rt, {1, 3, 5}); + test_case.run(); } NGRAPH_TEST(${BACKEND_NAME}, min_matrix_rows_zero) @@ -222,25 +155,15 @@ NGRAPH_TEST(${BACKEND_NAME}, min_matrix_rows_zero) Shape shape_rt{3}; auto f = make_shared(make_shared(A, AxisSet{1}), ParameterVector{A}); - auto backend = runtime::Backend::create("${BACKEND_NAME}"); - - // Create some tensors for input/output - auto a = backend->create_tensor(element::f32, shape_a); - copy_data(a, vector{}); - auto result = backend->create_tensor(element::f32, shape_rt); - copy_data(result, vector({3, 3, 3})); - - auto handle = backend->compile(f); - handle->call_with_validate({result}, {a}); - EXPECT_EQ((vector{std::numeric_limits::infinity(), - std::numeric_limits::infinity(), - std::numeric_limits::infinity()}), - read_vector(result)); - - // For some reason I'm feeling extra paranoid about making sure reduction doesn't clobber the - // input tensors, so let's do this too. - EXPECT_TRUE( - test::all_close_f((vector{}), read_vector(a), MIN_FLOAT_TOLERANCE_BITS)); + std::vector a{}; + + auto test_case = test::TestCase(f); + test_case.add_input({a}); + test_case.add_expected_output(shape_rt, + {std::numeric_limits::infinity(), + std::numeric_limits::infinity(), + std::numeric_limits::infinity()}); + test_case.run(); } NGRAPH_TEST(${BACKEND_NAME}, min_matrix_cols_zero) @@ -251,24 +174,13 @@ NGRAPH_TEST(${BACKEND_NAME}, min_matrix_cols_zero) Shape shape_rt{2}; auto f = make_shared(make_shared(A, AxisSet{0}), ParameterVector{A}); - auto backend = runtime::Backend::create("${BACKEND_NAME}"); - - // Create some tensors for input/output - auto a = backend->create_tensor(element::f32, shape_a); - copy_data(a, vector{}); - auto result = backend->create_tensor(element::f32, shape_rt); - copy_data(result, vector({3, 3})); + std::vector a{}; - auto handle = backend->compile(f); - handle->call_with_validate({result}, {a}); - EXPECT_EQ((vector{std::numeric_limits::infinity(), - std::numeric_limits::infinity()}), - read_vector(result)); - - // For some reason I'm feeling extra paranoid about making sure reduction doesn't clobber the - // input tensors, so let's do this too. - EXPECT_TRUE( - test::all_close_f((vector{}), read_vector(a), MIN_FLOAT_TOLERANCE_BITS)); + auto test_case = test::TestCase(f); + test_case.add_input({a}); + test_case.add_expected_output( + shape_rt, {std::numeric_limits::infinity(), std::numeric_limits::infinity()}); + test_case.run(); } NGRAPH_TEST(${BACKEND_NAME}, min_vector_zero) @@ -278,22 +190,12 @@ NGRAPH_TEST(${BACKEND_NAME}, min_vector_zero) Shape shape_rt{}; auto f = make_shared(make_shared(A, AxisSet{0}), ParameterVector{A}); - auto backend = runtime::Backend::create("${BACKEND_NAME}"); - - // Create some tensors for input/output - auto a = backend->create_tensor(element::f32, shape_a); - copy_data(a, vector{}); - auto result = backend->create_tensor(element::f32, shape_rt); - copy_data(result, vector({3})); + std::vector a{}; - auto handle = backend->compile(f); - handle->call_with_validate({result}, {a}); - EXPECT_EQ((vector{std::numeric_limits::infinity()}), read_vector(result)); - - // For some reason I'm feeling extra paranoid about making sure reduction doesn't clobber the - // input tensors, so let's do this too. - EXPECT_TRUE( - test::all_close_f((vector{}), read_vector(a), MIN_FLOAT_TOLERANCE_BITS)); + auto test_case = test::TestCase(f); + test_case.add_input({a}); + test_case.add_expected_output(shape_rt, {std::numeric_limits::infinity()}); + test_case.run(); } NGRAPH_TEST(${BACKEND_NAME}, min_matrix_to_scalar_zero_by_zero) @@ -303,22 +205,12 @@ NGRAPH_TEST(${BACKEND_NAME}, min_matrix_to_scalar_zero_by_zero) Shape shape_rt{}; auto f = make_shared(make_shared(A, AxisSet{0, 1}), ParameterVector{A}); - auto backend = runtime::Backend::create("${BACKEND_NAME}"); - - // Create some tensors for input/output - auto a = backend->create_tensor(element::f32, shape_a); - copy_data(a, vector{}); - auto result = backend->create_tensor(element::f32, shape_rt); - copy_data(result, vector({3})); - - auto handle = backend->compile(f); - handle->call_with_validate({result}, {a}); - EXPECT_EQ((vector{std::numeric_limits::infinity()}), read_vector(result)); + std::vector a{}; - // For some reason I'm feeling extra paranoid about making sure reduction doesn't clobber the - // input tensors, so let's do this too. - EXPECT_TRUE( - test::all_close_f((vector{}), read_vector(a), MIN_FLOAT_TOLERANCE_BITS)); + auto test_case = test::TestCase(f); + test_case.add_input({a}); + test_case.add_expected_output(shape_rt, {std::numeric_limits::infinity()}); + test_case.run(); } NGRAPH_TEST(${BACKEND_NAME}, min_3d_to_matrix_most_sig) @@ -328,19 +220,13 @@ NGRAPH_TEST(${BACKEND_NAME}, min_3d_to_matrix_most_sig) Shape shape_rt{3, 3}; auto f = make_shared(make_shared(A, AxisSet{0}), ParameterVector{A}); - auto backend = runtime::Backend::create("${BACKEND_NAME}"); + std::vector a{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, + 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27}; - // Create some tensors for input/output - auto a = backend->create_tensor(element::f32, shape_a); - copy_data(a, vector{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, - 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27}); - auto result = backend->create_tensor(element::f32, shape_rt); - - auto handle = backend->compile(f); - handle->call_with_validate({result}, {a}); - EXPECT_TRUE(test::all_close_f((vector{1, 2, 3, 4, 5, 6, 7, 8, 9}), - read_vector(result), - MIN_FLOAT_TOLERANCE_BITS)); + auto test_case = test::TestCase(f); + test_case.add_input({a}); + test_case.add_expected_output(shape_rt, {1, 2, 3, 4, 5, 6, 7, 8, 9}); + test_case.run(MIN_FLOAT_TOLERANCE_BITS); } NGRAPH_TEST(${BACKEND_NAME}, min_3d_to_matrix_least_sig) @@ -350,19 +236,13 @@ NGRAPH_TEST(${BACKEND_NAME}, min_3d_to_matrix_least_sig) Shape shape_rt{3, 3}; auto f = make_shared(make_shared(A, AxisSet{2}), ParameterVector{A}); - auto backend = runtime::Backend::create("${BACKEND_NAME}"); - - // Create some tensors for input/output - auto a = backend->create_tensor(element::f32, shape_a); - copy_data(a, vector{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, - 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27}); - auto result = backend->create_tensor(element::f32, shape_rt); + std::vector a{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, + 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27}; - auto handle = backend->compile(f); - handle->call_with_validate({result}, {a}); - EXPECT_TRUE(test::all_close_f((vector{1, 4, 7, 10, 13, 16, 19, 22, 25}), - read_vector(result), - MIN_FLOAT_TOLERANCE_BITS)); + auto test_case = test::TestCase(f); + test_case.add_input({a}); + test_case.add_expected_output(shape_rt, {1, 4, 7, 10, 13, 16, 19, 22, 25}); + test_case.run(MIN_FLOAT_TOLERANCE_BITS); } NGRAPH_TEST(${BACKEND_NAME}, min_3d_to_vector) @@ -372,18 +252,13 @@ NGRAPH_TEST(${BACKEND_NAME}, min_3d_to_vector) Shape shape_rt{3}; auto f = make_shared(make_shared(A, AxisSet{0, 1}), ParameterVector{A}); - auto backend = runtime::Backend::create("${BACKEND_NAME}"); + std::vector a{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, + 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27}; - // Create some tensors for input/output - auto a = backend->create_tensor(element::f32, shape_a); - copy_data(a, vector{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, - 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27}); - auto result = backend->create_tensor(element::f32, shape_rt); - - auto handle = backend->compile(f); - handle->call_with_validate({result}, {a}); - EXPECT_TRUE(test::all_close_f( - (vector{1, 2, 3}), read_vector(result), MIN_FLOAT_TOLERANCE_BITS)); + auto test_case = test::TestCase(f); + test_case.add_input({a}); + test_case.add_expected_output(shape_rt, {1, 2, 3}); + test_case.run(MIN_FLOAT_TOLERANCE_BITS); } NGRAPH_TEST(${BACKEND_NAME}, min_3d_to_scalar) @@ -393,18 +268,13 @@ NGRAPH_TEST(${BACKEND_NAME}, min_3d_to_scalar) Shape shape_rt{}; auto f = make_shared(make_shared(A, AxisSet{0, 1, 2}), ParameterVector{A}); - auto backend = runtime::Backend::create("${BACKEND_NAME}"); - - // Create some tensors for input/output - auto a = backend->create_tensor(element::f32, shape_a); - copy_data(a, vector{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1}); - auto result = backend->create_tensor(element::f32, shape_rt); + std::vector a{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, + 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1}; - auto handle = backend->compile(f); - handle->call_with_validate({result}, {a}); - EXPECT_TRUE(test::all_close_f( - (vector{1}), read_vector(result), MIN_FLOAT_TOLERANCE_BITS)); + auto test_case = test::TestCase(f); + test_case.add_input({a}); + test_case.add_expected_output(shape_rt, {1}); + test_case.run(MIN_FLOAT_TOLERANCE_BITS); } NGRAPH_TEST(${BACKEND_NAME}, min_3d_to_scalar_int32) @@ -414,17 +284,13 @@ NGRAPH_TEST(${BACKEND_NAME}, min_3d_to_scalar_int32) Shape shape_rt{}; auto f = make_shared(make_shared(A, AxisSet{0, 1, 2}), ParameterVector{A}); - auto backend = runtime::Backend::create("${BACKEND_NAME}"); + std::vector a{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, + 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1}; - // Create some tensors for input/output - auto a = backend->create_tensor(element::i32, shape_a); - copy_data(a, vector{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, - 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1}); - auto result = backend->create_tensor(element::i32, shape_rt); - - auto handle = backend->compile(f); - handle->call_with_validate({result}, {a}); - EXPECT_EQ((vector{1}), read_vector(result)); + auto test_case = test::TestCase(f); + test_case.add_input({a}); + test_case.add_expected_output(shape_rt, {1}); + test_case.run(); } NGRAPH_TEST(${BACKEND_NAME}, min_3d_eliminate_zero_dim) @@ -434,20 +300,12 @@ NGRAPH_TEST(${BACKEND_NAME}, min_3d_eliminate_zero_dim) Shape shape_rt{3, 2}; auto f = make_shared(make_shared(A, AxisSet{1}), ParameterVector{A}); - auto backend = runtime::Backend::create("${BACKEND_NAME}"); - - // Create some tensors for input/output - auto a = backend->create_tensor(element::f32, shape_a); - copy_data(a, vector{}); - auto result = backend->create_tensor(element::f32, shape_rt); - - // Overwrite the initial result vector to make sure we're not just coincidentally getting the - // right value. - copy_data(result, vector{2112, 2112, 2112, 2112, 2112, 2112}); + std::vector a{}; float inf = std::numeric_limits::infinity(); - auto handle = backend->compile(f); - handle->call_with_validate({result}, {a}); - EXPECT_EQ((vector{inf, inf, inf, inf, inf, inf}), read_vector(result)); + auto test_case = test::TestCase(f); + test_case.add_input({a}); + test_case.add_expected_output(shape_rt, {inf, inf, inf, inf, inf, inf}); + test_case.run(); } diff --git a/ngraph/test/backend/minimum.in.cpp b/ngraph/test/backend/minimum.in.cpp index 926babd5b325e5..fcd18dc6b57350 100644 --- a/ngraph/test/backend/minimum.in.cpp +++ b/ngraph/test/backend/minimum.in.cpp @@ -32,14 +32,10 @@ // clang-format on #include "gtest/gtest.h" -#include "runtime/backend.hpp" -#include "ngraph/runtime/tensor.hpp" #include "ngraph/ngraph.hpp" -#include "util/all_close.hpp" -#include "util/all_close_f.hpp" -#include "util/ndarray.hpp" +#include "util/engine/test_engines.hpp" +#include "util/test_case.hpp" #include "util/test_control.hpp" -#include "util/test_tools.hpp" NGRAPH_SUPPRESS_DEPRECATED_START @@ -47,6 +43,7 @@ using namespace std; using namespace ngraph; static string s_manifest = "${MANIFEST}"; +using TestEngine = test::ENGINE_CLASS_NAME(${BACKEND_NAME}); NGRAPH_TEST(${BACKEND_NAME}, minimum) { @@ -55,19 +52,13 @@ NGRAPH_TEST(${BACKEND_NAME}, minimum) auto B = make_shared(element::f32, shape); auto f = make_shared(make_shared(A, B), ParameterVector{A, B}); - auto backend = runtime::Backend::create("${BACKEND_NAME}"); + std::vector a{1, 8, -8, 17, -0.5, 0.5, 2, 1}; + std::vector b{1, 2, 4, 8, 0, 0, 1, 1.5}; - // Create some tensors for input/output - auto a = backend->create_tensor(element::f32, shape); - copy_data(a, vector{1, 8, -8, 17, -0.5, 0.5, 2, 1}); - auto b = backend->create_tensor(element::f32, shape); - copy_data(b, vector{1, 2, 4, 8, 0, 0, 1, 1.5}); - auto result = backend->create_tensor(element::f32, shape); - - auto handle = backend->compile(f); - handle->call_with_validate({result}, {a, b}); - EXPECT_TRUE( - test::all_close_f((vector{1, 2, -8, 8, -.5, 0, 1, 1}), read_vector(result))); + auto test_case = test::TestCase(f); + test_case.add_multiple_inputs({a, b}); + test_case.add_expected_output(shape, {1, 2, -8, 8, -.5, 0, 1, 1}); + test_case.run(); } NGRAPH_TEST(${BACKEND_NAME}, minimum_int32) @@ -77,18 +68,13 @@ NGRAPH_TEST(${BACKEND_NAME}, minimum_int32) auto B = make_shared(element::i32, shape); auto f = make_shared(make_shared(A, B), ParameterVector{A, B}); - auto backend = runtime::Backend::create("${BACKEND_NAME}"); - - // Create some tensors for input/output - auto a = backend->create_tensor(element::i32, shape); - copy_data(a, vector{1, 8, -8, 17, -5, 67635216, 2, 1}); - auto b = backend->create_tensor(element::i32, shape); - copy_data(b, vector{1, 2, 4, 8, 0, 18448, 1, 6}); - auto result = backend->create_tensor(element::i32, shape); + std::vector a{1, 8, -8, 17, -5, 67635216, 2, 1}; + std::vector b{1, 2, 4, 8, 0, 18448, 1, 6}; - auto handle = backend->compile(f); - handle->call_with_validate({result}, {a, b}); - EXPECT_EQ((vector{1, 2, -8, 8, -5, 18448, 1, 1}), read_vector(result)); + auto test_case = test::TestCase(f); + test_case.add_multiple_inputs({a, b}); + test_case.add_expected_output(shape, {1, 2, -8, 8, -5, 18448, 1, 1}); + test_case.run(); } NGRAPH_TEST(${BACKEND_NAME}, minimum_int64) @@ -98,16 +84,11 @@ NGRAPH_TEST(${BACKEND_NAME}, minimum_int64) auto B = make_shared(element::i64, shape); auto f = make_shared(make_shared(A, B), ParameterVector{A, B}); - auto backend = runtime::Backend::create("${BACKEND_NAME}"); - - // Create some tensors for input/output - auto a = backend->create_tensor(element::i64, shape); - copy_data(a, vector{1, 8, -8, 17, -5, 67635216, 2, 17179887632}); - auto b = backend->create_tensor(element::i64, shape); - copy_data(b, vector{1, 2, 4, 8, 0, 18448, 1, 280592}); - auto result = backend->create_tensor(element::i64, shape); + std::vector a{1, 8, -8, 17, -5, 67635216, 2, 17179887632}; + std::vector b{1, 2, 4, 8, 0, 18448, 1, 280592}; - auto handle = backend->compile(f); - handle->call_with_validate({result}, {a, b}); - EXPECT_EQ((vector{1, 2, -8, 8, -5, 18448, 1, 280592}), read_vector(result)); + auto test_case = test::TestCase(f); + test_case.add_multiple_inputs({a, b}); + test_case.add_expected_output(shape, {1, 2, -8, 8, -5, 18448, 1, 280592}); + test_case.run(); } diff --git a/ngraph/test/backend/quantize_dequantize.in.cpp b/ngraph/test/backend/quantize_dequantize.in.cpp index 53bdf76e186a97..c90143f0703e60 100644 --- a/ngraph/test/backend/quantize_dequantize.in.cpp +++ b/ngraph/test/backend/quantize_dequantize.in.cpp @@ -16,14 +16,9 @@ #include "gtest/gtest.h" #include "ngraph/ngraph.hpp" -#include "ngraph/runtime/tensor.hpp" -#include "runtime/backend.hpp" -#include "util/all_close.hpp" -#include "util/all_close_f.hpp" -#include "util/known_element_types.hpp" -#include "util/ndarray.hpp" +#include "util/engine/test_engines.hpp" +#include "util/test_case.hpp" #include "util/test_control.hpp" -#include "util/test_tools.hpp" NGRAPH_SUPPRESS_DEPRECATED_START @@ -31,6 +26,7 @@ using namespace std; using namespace ngraph; static string s_manifest = "${MANIFEST}"; +using TestEngine = test::ENGINE_CLASS_NAME(${BACKEND_NAME}); NGRAPH_TEST(${BACKEND_NAME}, quantize) { @@ -53,20 +49,16 @@ NGRAPH_TEST(${BACKEND_NAME}, quantize) make_shared(X, scale, offset, output_type, quantization_axes, round_mode); auto f = make_shared(quantize, ParameterVector{X}); - auto backend = runtime::Backend::create("${BACKEND_NAME}"); - auto x = backend->create_tensor(input_type, input_shape); - auto y = backend->create_tensor(output_type, input_shape); - - copy_data(x, vector{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}); + std::vector x{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}; // divide by scale 2 2 2 2 2 2 2 2 2 2 2 2 // equals (rounded) 0 0 1 2 2 2 3 4 4 4 5 6 // plus offset 1 1 1 1 1 1 1 1 1 1 1 1 // equals 1 1 2 3 3 3 4 5 5 5 6 7 - auto handle = backend->compile(f); - handle->call_with_validate({y}, {x}); - EXPECT_EQ((vector{1, 1, 2, 3, 3, 3, 4, 5, 5, 5, 6, 7}), - read_vector(y)); + auto test_case = test::TestCase(f); + test_case.add_input({x}); + test_case.add_expected_output(input_shape, {1, 1, 2, 3, 3, 3, 4, 5, 5, 5, 6, 7}); + test_case.run(); } NGRAPH_TEST(${BACKEND_NAME}, dequantize) @@ -87,21 +79,17 @@ NGRAPH_TEST(${BACKEND_NAME}, dequantize) auto dequantize = make_shared(X, scale, offset, output_type, quantization_axes); auto f = make_shared(dequantize, ParameterVector{X}); - auto backend = runtime::Backend::create("${BACKEND_NAME}"); - auto x = backend->create_tensor(input_type, input_shape); - auto y = backend->create_tensor(output_type, input_shape); - - copy_data(x, vector{1, 1, 2, 3, 3, 3, 4, 5, 5, 5, 6, 7}); + std::vector x{{1, 1, 2, 3, 3, 3, 4, 5, 5, 5, 6, 7}}; // minus offset 1 1 1 1 1 1 1 1 1 1 1 1 // eqauls 0 0 1 2 2 2 3 4 4 4 5 6 // multiplied by scale 2 2 2 2 2 2 2 2 2 2 2 2 // equals 0 0 2 4 4 4 6 8 8 8 10 12 - auto handle = backend->compile(f); - handle->call_with_validate({y}, {x}); - EXPECT_TRUE(test::all_close_f((vector{0, 0, 2, 4, 4, 4, 6, 8, 8, 8, 10, 12}), - read_vector(y), - MIN_FLOAT_TOLERANCE_BITS)); + auto test_case = test::TestCase(f); + test_case.add_input({x}); + test_case.add_expected_output(input_shape, + {0, 0, 2, 4, 4, 4, 6, 8, 8, 8, 10, 12}); + test_case.run(MIN_FLOAT_TOLERANCE_BITS); } NGRAPH_TEST(${BACKEND_NAME}, quantize_zero_offset) @@ -125,20 +113,16 @@ NGRAPH_TEST(${BACKEND_NAME}, quantize_zero_offset) make_shared(X, scale, offset, output_type, quantization_axes, round_mode); auto f = make_shared(quantize, ParameterVector{X}); - auto backend = runtime::Backend::create("${BACKEND_NAME}"); - auto x = backend->create_tensor(input_type, input_shape); - auto y = backend->create_tensor(output_type, input_shape); - - copy_data(x, vector{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}); + std::vector x{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}; // divide by scale 2 2 2 2 2 2 2 2 2 2 2 2 // equals (rounded) 0 0 1 2 2 2 3 4 4 4 5 6 // plus offset 0 0 0 0 0 0 0 0 0 0 0 0 // equals 0 0 1 2 2 2 3 4 4 4 5 6 - auto handle = backend->compile(f); - handle->call_with_validate({y}, {x}); - EXPECT_EQ((vector{0, 0, 1, 2, 2, 2, 3, 4, 4, 4, 5, 6}), - read_vector(y)); + auto test_case = test::TestCase(f); + test_case.add_input({x}); + test_case.add_expected_output(input_shape, {0, 0, 1, 2, 2, 2, 3, 4, 4, 4, 5, 6}); + test_case.run(); } NGRAPH_TEST(${BACKEND_NAME}, dequantize_zero_offset) @@ -159,21 +143,17 @@ NGRAPH_TEST(${BACKEND_NAME}, dequantize_zero_offset) auto dequantize = make_shared(X, scale, offset, output_type, quantization_axes); auto f = make_shared(dequantize, ParameterVector{X}); - auto backend = runtime::Backend::create("${BACKEND_NAME}"); - auto x = backend->create_tensor(input_type, input_shape); - auto y = backend->create_tensor(output_type, input_shape); - - copy_data(x, vector{0, 0, 1, 2, 2, 2, 3, 4, 4, 4, 5, 6}); + std::vector x{0, 0, 1, 2, 2, 2, 3, 4, 4, 4, 5, 6}; // minus offset 0 0 0 0 0 0 0 0 0 0 0 0 // equals 0 0 1 2 2 2 3 4 4 4 5 6 // multiplied by scale 2 2 2 2 2 2 2 2 2 2 2 2 // equals 0 0 2 4 4 4 6 8 8 8 10 12 - auto handle = backend->compile(f); - handle->call_with_validate({y}, {x}); - EXPECT_TRUE(test::all_close_f((vector{0, 0, 2, 4, 4, 4, 6, 8, 8, 8, 10, 12}), - read_vector(y), - MIN_FLOAT_TOLERANCE_BITS)); + auto test_case = test::TestCase(f); + test_case.add_input({x}); + test_case.add_expected_output(input_shape, + {0, 0, 2, 4, 4, 4, 6, 8, 8, 8, 10, 12}); + test_case.run(MIN_FLOAT_TOLERANCE_BITS); } NGRAPH_TEST(${BACKEND_NAME}, quantize_axes) @@ -197,20 +177,17 @@ NGRAPH_TEST(${BACKEND_NAME}, quantize_axes) make_shared(X, scale, offset, output_type, quantization_axes, round_mode); auto f = make_shared(quantize, ParameterVector{X}); - auto backend = runtime::Backend::create("${BACKEND_NAME}"); - auto x = backend->create_tensor(input_type, input_shape); - auto y = backend->create_tensor(output_type, input_shape); - - copy_data(x, vector{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}); + std::vector x{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}; // divided by scale 2 2 2 3 3 3 4 4 4 5 5 5 // equals (rounded) 0 1 1 1 1 2 2 2 2 2 2 2 // plus offset 10 10 10 20 20 20 30 30 30 40 40 40 // equals 10 11 11 21 21 22 32 32 32 42 42 42 - auto handle = backend->compile(f); - handle->call_with_validate({y}, {x}); - EXPECT_EQ((vector{10, 11, 11, 21, 21, 22, 32, 32, 32, 42, 42, 42}), - read_vector(y)); + auto test_case = test::TestCase(f); + test_case.add_input({x}); + test_case.add_expected_output(input_shape, + {10, 11, 11, 21, 21, 22, 32, 32, 32, 42, 42, 42}); + test_case.run(); } NGRAPH_TEST(${BACKEND_NAME}, dequantize_axes) @@ -231,21 +208,17 @@ NGRAPH_TEST(${BACKEND_NAME}, dequantize_axes) auto dequantize = make_shared(X, scale, offset, output_type, quantization_axes); auto f = make_shared(dequantize, ParameterVector{X}); - auto backend = runtime::Backend::create("${BACKEND_NAME}"); - auto x = backend->create_tensor(input_type, input_shape); - auto y = backend->create_tensor(output_type, input_shape); - - copy_data(x, vector{10, 11, 11, 21, 21, 22, 32, 32, 32, 42, 42, 42}); + std::vector x{10, 11, 11, 21, 21, 22, 32, 32, 32, 42, 42, 42}; // minus offset 10 10 10 20 20 20 30 30 30 40 40 40 // equals 0 1 1 1 1 2 2 2 2 2 2 2 // multiplied by scale 2 2 2 3 3 3 4 4 4 5 5 5 // equals 0 2 2 3 3 6 8 8 8 10 10 10 - auto handle = backend->compile(f); - handle->call_with_validate({y}, {x}); - EXPECT_TRUE(test::all_close_f((vector{0, 2, 2, 3, 3, 6, 8, 8, 8, 10, 10, 10}), - read_vector(y), - MIN_FLOAT_TOLERANCE_BITS)); + auto test_case = test::TestCase(f); + test_case.add_input({x}); + test_case.add_expected_output(input_shape, + {0, 2, 2, 3, 3, 6, 8, 8, 8, 10, 10, 10}); + test_case.run(MIN_FLOAT_TOLERANCE_BITS); } NGRAPH_TEST(${BACKEND_NAME}, quantize_int8) @@ -269,20 +242,17 @@ NGRAPH_TEST(${BACKEND_NAME}, quantize_int8) make_shared(X, scale, offset, output_type, quantization_axes, round_mode); auto f = make_shared(quantize, ParameterVector{X}); - auto backend = runtime::Backend::create("${BACKEND_NAME}"); - auto x = backend->create_tensor(input_type, input_shape); - auto y = backend->create_tensor(output_type, input_shape); - - copy_data(x, vector{0, -1, 2, -3, 4, -5, 6, -7, 8, -9, 10, -11}); + std::vector x{0, -1, 2, -3, 4, -5, 6, -7, 8, -9, 10, -11}; // divide by scale 2 2 2 2 2 2 2 2 2 2 2 2 // equals (rounded) 0 0 1 -2 2 -2 3 -4 4 -4 5 -6 // plus offset 1 1 1 1 1 1 1 1 1 1 1 1 // equals 1 1 2 -1 3 -1 4 -3 5 -3 6 -5 - auto handle = backend->compile(f); - handle->call_with_validate({y}, {x}); - EXPECT_EQ((vector{1, 1, 2, -1, 3, -1, 4, -3, 5, -3, 6, -5}), - read_vector(y)); + auto test_case = test::TestCase(f); + test_case.add_input({x}); + test_case.add_expected_output(input_shape, + {1, 1, 2, -1, 3, -1, 4, -3, 5, -3, 6, -5}); + test_case.run(); } NGRAPH_TEST(${BACKEND_NAME}, dequantize_int8) @@ -303,22 +273,17 @@ NGRAPH_TEST(${BACKEND_NAME}, dequantize_int8) auto dequantize = make_shared(X, scale, offset, output_type, quantization_axes); auto f = make_shared(dequantize, ParameterVector{X}); - auto backend = runtime::Backend::create("${BACKEND_NAME}"); - auto x = backend->create_tensor(input_type, input_shape); - auto y = backend->create_tensor(output_type, input_shape); - - copy_data(x, vector{1, 1, 2, -1, 3, -1, 4, -3, 5, -3, 6, -5}); + std::vector x{1, 1, 2, -1, 3, -1, 4, -3, 5, -3, 6, -5}; // minus offset 1 1 1 1 1 1 1 1 1 1 1 1 // equals 0 0 1 -2 2 -2 3 -4 4 -4 5 -6 // multiplied by scale 2 2 2 2 2 2 2 2 2 2 2 2 // equals 0 0 2 -4 4 -4 6 -8 8 -8 10 -12 - auto handle = backend->compile(f); - handle->call_with_validate({y}, {x}); - EXPECT_TRUE( - test::all_close_f((vector{0, 0, 2, -4, 4, -4, 6, -8, 8, -8, 10, -12}), - read_vector(y), - MIN_FLOAT_TOLERANCE_BITS)); + auto test_case = test::TestCase(f); + test_case.add_input({x}); + test_case.add_expected_output(input_shape, + {0, 0, 2, -4, 4, -4, 6, -8, 8, -8, 10, -12}); + test_case.run(MIN_FLOAT_TOLERANCE_BITS); } NGRAPH_TEST(${BACKEND_NAME}, quantize_int8_zero_offset) @@ -342,20 +307,17 @@ NGRAPH_TEST(${BACKEND_NAME}, quantize_int8_zero_offset) make_shared(X, scale, offset, output_type, quantization_axes, round_mode); auto f = make_shared(quantize, ParameterVector{X}); - auto backend = runtime::Backend::create("${BACKEND_NAME}"); - auto x = backend->create_tensor(input_type, input_shape); - auto y = backend->create_tensor(output_type, input_shape); - - copy_data(x, vector{0, -1, 2, -3, 4, -5, 6, -7, 8, -9, 10, -11}); + std::vector x{0, -1, 2, -3, 4, -5, 6, -7, 8, -9, 10, -11}; // divide by scale 2 2 2 2 2 2 2 2 2 2 2 2 // equals (rounded) 0 0 1 -2 2 -2 3 -4 4 -4 5 -6 // plus offset 0 0 0 0 0 0 0 0 0 0 0 0 // equals 0 0 1 -2 2 -2 3 -4 4 -4 5 -6 - auto handle = backend->compile(f); - handle->call_with_validate({y}, {x}); - EXPECT_EQ((vector{0, 0, 1, -2, 2, -2, 3, -4, 4, -4, 5, -6}), - read_vector(y)); + auto test_case = test::TestCase(f); + test_case.add_input({x}); + test_case.add_expected_output(input_shape, + {0, 0, 1, -2, 2, -2, 3, -4, 4, -4, 5, -6}); + test_case.run(); } NGRAPH_TEST(${BACKEND_NAME}, dequantize_int8_zero_offset) @@ -376,22 +338,17 @@ NGRAPH_TEST(${BACKEND_NAME}, dequantize_int8_zero_offset) auto dequantize = make_shared(X, scale, offset, output_type, quantization_axes); auto f = make_shared(dequantize, ParameterVector{X}); - auto backend = runtime::Backend::create("${BACKEND_NAME}"); - auto x = backend->create_tensor(input_type, input_shape); - auto y = backend->create_tensor(output_type, input_shape); - - copy_data(x, vector{0, 0, 1, -2, 2, -2, 3, -4, 4, -4, 5, -6}); + std::vector x{0, 0, 1, -2, 2, -2, 3, -4, 4, -4, 5, -6}; // minus offset 0 0 0 0 0 0 0 0 0 0 0 0 // equals 0 0 1 -2 2 -2 3 -4 4 -4 5 -6 // multiplied by scale 2 2 2 2 2 2 2 2 2 2 2 2 // equals 0 0 2 -4 4 -4 6 -8 8 -8 10 -12 - auto handle = backend->compile(f); - handle->call_with_validate({y}, {x}); - EXPECT_TRUE( - test::all_close_f((vector{0, 0, 2, -4, 4, -4, 6, -8, 8, -8, 10, -12}), - read_vector(y), - MIN_FLOAT_TOLERANCE_BITS)); + auto test_case = test::TestCase(f); + test_case.add_input({x}); + test_case.add_expected_output(input_shape, + {0, 0, 2, -4, 4, -4, 6, -8, 8, -8, 10, -12}); + test_case.run(MIN_FLOAT_TOLERANCE_BITS); } NGRAPH_TEST(${BACKEND_NAME}, quantize_int32) @@ -415,20 +372,17 @@ NGRAPH_TEST(${BACKEND_NAME}, quantize_int32) make_shared(X, scale, offset, output_type, quantization_axes, round_mode); auto f = make_shared(quantize, ParameterVector{X}); - auto backend = runtime::Backend::create("${BACKEND_NAME}"); - auto x = backend->create_tensor(input_type, input_shape); - auto y = backend->create_tensor(output_type, input_shape); - - copy_data(x, vector{0, -1, 2, -3, 4, -5, 6, -7, 8, -9, 10, -11}); + std::vector x{0, -1, 2, -3, 4, -5, 6, -7, 8, -9, 10, -11}; // divide by scale 2 2 2 2 2 2 2 2 2 2 2 2 // equals (rounded) 0 0 1 -2 2 -2 3 -4 4 -4 5 -6 // plus offset 1 1 1 1 1 1 1 1 1 1 1 1 // equals 1 1 2 -1 3 -1 4 -3 5 -3 6 -5 - auto handle = backend->compile(f); - handle->call_with_validate({y}, {x}); - EXPECT_EQ((vector{1, 1, 2, -1, 3, -1, 4, -3, 5, -3, 6, -5}), - read_vector(y)); + auto test_case = test::TestCase(f); + test_case.add_input({x}); + test_case.add_expected_output(input_shape, + {1, 1, 2, -1, 3, -1, 4, -3, 5, -3, 6, -5}); + test_case.run(); } NGRAPH_TEST(${BACKEND_NAME}, dequantize_int32) @@ -449,22 +403,17 @@ NGRAPH_TEST(${BACKEND_NAME}, dequantize_int32) auto dequantize = make_shared(X, scale, offset, output_type, quantization_axes); auto f = make_shared(dequantize, ParameterVector{X}); - auto backend = runtime::Backend::create("${BACKEND_NAME}"); - auto x = backend->create_tensor(input_type, input_shape); - auto y = backend->create_tensor(output_type, input_shape); - - copy_data(x, vector{1, 1, 2, -1, 3, -1, 4, -3, 5, -3, 6, -5}); + std::vector x{1, 1, 2, -1, 3, -1, 4, -3, 5, -3, 6, -5}; // minus offset 1 1 1 1 1 1 1 1 1 1 1 1 // equals 0 0 1 -2 2 -2 3 -4 4 -4 5 -6 // multiplied by scale 2 2 2 2 2 2 2 2 2 2 2 2 // equals 0 0 2 -4 4 -4 6 -8 8 -8 10 -12 - auto handle = backend->compile(f); - handle->call_with_validate({y}, {x}); - EXPECT_TRUE( - test::all_close_f((vector{0, 0, 2, -4, 4, -4, 6, -8, 8, -8, 10, -12}), - read_vector(y), - MIN_FLOAT_TOLERANCE_BITS)); + auto test_case = test::TestCase(f); + test_case.add_input({x}); + test_case.add_expected_output(input_shape, + {0, 0, 2, -4, 4, -4, 6, -8, 8, -8, 10, -12}); + test_case.run(MIN_FLOAT_TOLERANCE_BITS); } NGRAPH_TEST(${BACKEND_NAME}, quantize_int32_zero_offset) @@ -488,20 +437,17 @@ NGRAPH_TEST(${BACKEND_NAME}, quantize_int32_zero_offset) make_shared(X, scale, offset, output_type, quantization_axes, round_mode); auto f = make_shared(quantize, ParameterVector{X}); - auto backend = runtime::Backend::create("${BACKEND_NAME}"); - auto x = backend->create_tensor(input_type, input_shape); - auto y = backend->create_tensor(output_type, input_shape); - - copy_data(x, vector{0, -1, 2, -3, 4, -5, 6, -7, 8, -9, 10, -11}); + std::vector x{0, -1, 2, -3, 4, -5, 6, -7, 8, -9, 10, -11}; // divide by scale 2 2 2 2 2 2 2 2 2 2 2 2 // equals (rounded) 0 0 1 -2 2 -2 3 -4 4 -4 5 -6 // plus offset 0 0 0 0 0 0 0 0 0 0 0 0 // equals 0 0 1 -2 2 -2 3 -4 4 -4 5 -6 - auto handle = backend->compile(f); - handle->call_with_validate({y}, {x}); - EXPECT_EQ((vector{0, 0, 1, -2, 2, -2, 3, -4, 4, -4, 5, -6}), - read_vector(y)); + auto test_case = test::TestCase(f); + test_case.add_input({x}); + test_case.add_expected_output(input_shape, + {0, 0, 1, -2, 2, -2, 3, -4, 4, -4, 5, -6}); + test_case.run(); } NGRAPH_TEST(${BACKEND_NAME}, dequantize_int32_zero_offset) @@ -522,22 +468,17 @@ NGRAPH_TEST(${BACKEND_NAME}, dequantize_int32_zero_offset) auto dequantize = make_shared(X, scale, offset, output_type, quantization_axes); auto f = make_shared(dequantize, ParameterVector{X}); - auto backend = runtime::Backend::create("${BACKEND_NAME}"); - auto x = backend->create_tensor(input_type, input_shape); - auto y = backend->create_tensor(output_type, input_shape); - - copy_data(x, vector{0, 0, 1, -2, 2, -2, 3, -4, 4, -4, 5, -6}); + std::vector x{0, 0, 1, -2, 2, -2, 3, -4, 4, -4, 5, -6}; // minus offset 0 0 0 0 0 0 0 0 0 0 0 0 // equals 0 0 1 -2 2 -2 3 -4 4 -4 5 -6 // multiplied by scale 2 2 2 2 2 2 2 2 2 2 2 2 // equals 0 0 2 -4 4 -4 6 -8 8 -8 10 -12 - auto handle = backend->compile(f); - handle->call_with_validate({y}, {x}); - EXPECT_TRUE( - test::all_close_f((vector{0, 0, 2, -4, 4, -4, 6, -8, 8, -8, 10, -12}), - read_vector(y), - MIN_FLOAT_TOLERANCE_BITS)); + auto test_case = test::TestCase(f); + test_case.add_input({x}); + test_case.add_expected_output(input_shape, + {0, 0, 2, -4, 4, -4, 6, -8, 8, -8, 10, -12}); + test_case.run(MIN_FLOAT_TOLERANCE_BITS); } NGRAPH_TEST(${BACKEND_NAME}, quantize_clamp_uint8) @@ -563,16 +504,13 @@ NGRAPH_TEST(${BACKEND_NAME}, quantize_clamp_uint8) make_shared(X, scale, offset, output_type, quantization_axes, round_mode); auto f = make_shared(quantize, ParameterVector{X}); - auto backend = runtime::Backend::create("${BACKEND_NAME}"); - auto x = backend->create_tensor(input_type, input_shape); - auto y = backend->create_tensor(output_type, input_shape); - - copy_data(x, vector{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}); + std::vector x{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}; - auto handle = backend->compile(f); - handle->call_with_validate({y}, {x}); - EXPECT_EQ((vector{0, max, max, max, max, max, max, max, max, max, max, max}), - read_vector(y)); + auto test_case = test::TestCase(f); + test_case.add_input({x}); + test_case.add_expected_output( + input_shape, {0, max, max, max, max, max, max, max, max, max, max, max}); + test_case.run(); } NGRAPH_TEST(${BACKEND_NAME}, quantize_clamp_int8) @@ -599,16 +537,13 @@ NGRAPH_TEST(${BACKEND_NAME}, quantize_clamp_int8) make_shared(X, scale, offset, output_type, quantization_axes, round_mode); auto f = make_shared(quantize, ParameterVector{X}); - auto backend = runtime::Backend::create("${BACKEND_NAME}"); - auto x = backend->create_tensor(input_type, input_shape); - auto y = backend->create_tensor(output_type, input_shape); + std::vector x{0, -1, 2, -3, 4, -5, 6, -7, 8, -9, 10, -11}; - copy_data(x, vector{0, -1, 2, -3, 4, -5, 6, -7, 8, -9, 10, -11}); - - auto handle = backend->compile(f); - handle->call_with_validate({y}, {x}); - EXPECT_EQ((vector{0, min, max, min, max, min, max, min, max, min, max, min}), - read_vector(y)); + auto test_case = test::TestCase(f); + test_case.add_input({x}); + test_case.add_expected_output( + input_shape, {0, min, max, min, max, min, max, min, max, min, max, min}); + test_case.run(); } NGRAPH_TEST(${BACKEND_NAME}, quantize_clamp_int32) @@ -636,16 +571,13 @@ NGRAPH_TEST(${BACKEND_NAME}, quantize_clamp_int32) make_shared(X, scale, offset, output_type, quantization_axes, round_mode); auto f = make_shared(quantize, ParameterVector{X}); - auto backend = runtime::Backend::create("${BACKEND_NAME}"); - auto x = backend->create_tensor(input_type, input_shape); - auto y = backend->create_tensor(output_type, input_shape); - - copy_data(x, vector{0, -1, 2, -3, 4, -5, 6, -7, 8, -9, 10, -11}); + std::vector x{0, -1, 2, -3, 4, -5, 6, -7, 8, -9, 10, -11}; - auto handle = backend->compile(f); - handle->call_with_validate({y}, {x}); - EXPECT_EQ((vector{0, min, max, min, max, min, max, min, max, min, max, min}), - read_vector(y)); + auto test_case = test::TestCase(f); + test_case.add_input({x}); + test_case.add_expected_output( + input_shape, {0, min, max, min, max, min, max, min, max, min, max, min}); + test_case.run(); } NGRAPH_TEST(${BACKEND_NAME}, quantize_ROUND_NEAREST_TOWARD_ZERO) @@ -669,18 +601,15 @@ NGRAPH_TEST(${BACKEND_NAME}, quantize_ROUND_NEAREST_TOWARD_ZERO) make_shared(X, scale, offset, output_type, quantization_axes, round_mode); auto f = make_shared(quantize, ParameterVector{X}); - auto backend = runtime::Backend::create("${BACKEND_NAME}"); - auto x = backend->create_tensor(input_type, input_shape); - auto y = backend->create_tensor(output_type, input_shape); - - copy_data(x, vector{9, 10, 11, -9, -10, -11, 13, 14, 15, -13, -14, -15}); + std::vector x{9, 10, 11, -9, -10, -11, 13, 14, 15, -13, -14, -15}; // divide by scale 4 4 4 4 4 4 4 4 4 4 4 4 // equals (rounded) 2 2 3 -2 -2 -3 3 3 4 -3 -3 -4 - auto handle = backend->compile(f); - handle->call_with_validate({y}, {x}); - EXPECT_EQ((vector{2, 2, 3, -2, -2, -3, 3, 3, 4, -3, -3, -4}), - read_vector(y)); + auto test_case = test::TestCase(f); + test_case.add_input({x}); + test_case.add_expected_output(input_shape, + {2, 2, 3, -2, -2, -3, 3, 3, 4, -3, -3, -4}); + test_case.run(); } NGRAPH_TEST(${BACKEND_NAME}, quantize_ROUND_NEAREST_TOWARD_INFINITY) @@ -704,18 +633,15 @@ NGRAPH_TEST(${BACKEND_NAME}, quantize_ROUND_NEAREST_TOWARD_INFINITY) make_shared(X, scale, offset, output_type, quantization_axes, round_mode); auto f = make_shared(quantize, ParameterVector{X}); - auto backend = runtime::Backend::create("${BACKEND_NAME}"); - auto x = backend->create_tensor(input_type, input_shape); - auto y = backend->create_tensor(output_type, input_shape); - - copy_data(x, vector{9, 10, 11, -9, -10, -11, 13, 14, 15, -13, -14, -15}); + std::vector x{9, 10, 11, -9, -10, -11, 13, 14, 15, -13, -14, -15}; // divide by scale 4 4 4 4 4 4 4 4 4 4 4 4 // equals (rounded) 2 3 3 -2 -3 -3 3 4 4 -3 -4 -4 - auto handle = backend->compile(f); - handle->call_with_validate({y}, {x}); - EXPECT_EQ((vector{2, 3, 3, -2, -3, -3, 3, 4, 4, -3, -4, -4}), - read_vector(y)); + auto test_case = test::TestCase(f); + test_case.add_input({x}); + test_case.add_expected_output(input_shape, + {2, 3, 3, -2, -3, -3, 3, 4, 4, -3, -4, -4}); + test_case.run(); } NGRAPH_TEST(${BACKEND_NAME}, quantize_ROUND_NEAREST_UPWARD) @@ -739,18 +665,15 @@ NGRAPH_TEST(${BACKEND_NAME}, quantize_ROUND_NEAREST_UPWARD) make_shared(X, scale, offset, output_type, quantization_axes, round_mode); auto f = make_shared(quantize, ParameterVector{X}); - auto backend = runtime::Backend::create("${BACKEND_NAME}"); - auto x = backend->create_tensor(input_type, input_shape); - auto y = backend->create_tensor(output_type, input_shape); - - copy_data(x, vector{9, 10, 11, -9, -10, -11, 13, 14, 15, -13, -14, -15}); + std::vector x{9, 10, 11, -9, -10, -11, 13, 14, 15, -13, -14, -15}; // divide by scale 4 4 4 4 4 4 4 4 4 4 4 4 // equals (rounded) 2 3 3 -2 -2 -3 3 4 4 -3 -3 -4 - auto handle = backend->compile(f); - handle->call_with_validate({y}, {x}); - EXPECT_EQ((vector{2, 3, 3, -2, -2, -3, 3, 4, 4, -3, -3, -4}), - read_vector(y)); + auto test_case = test::TestCase(f); + test_case.add_input({x}); + test_case.add_expected_output(input_shape, + {2, 3, 3, -2, -2, -3, 3, 4, 4, -3, -3, -4}); + test_case.run(); } NGRAPH_TEST(${BACKEND_NAME}, quantize_ROUND_NEAREST_DOWNWARD) @@ -774,18 +697,15 @@ NGRAPH_TEST(${BACKEND_NAME}, quantize_ROUND_NEAREST_DOWNWARD) make_shared(X, scale, offset, output_type, quantization_axes, round_mode); auto f = make_shared(quantize, ParameterVector{X}); - auto backend = runtime::Backend::create("${BACKEND_NAME}"); - auto x = backend->create_tensor(input_type, input_shape); - auto y = backend->create_tensor(output_type, input_shape); - - copy_data(x, vector{9, 10, 11, -9, -10, -11, 13, 14, 15, -13, -14, -15}); + std::vector x{9, 10, 11, -9, -10, -11, 13, 14, 15, -13, -14, -15}; // divide by scale 4 4 4 4 4 4 4 4 4 4 4 4 // equals (rounded) 2 2 3 -2 -3 -3 3 3 4 -3 -4 -4 - auto handle = backend->compile(f); - handle->call_with_validate({y}, {x}); - EXPECT_EQ((vector{2, 2, 3, -2, -3, -3, 3, 3, 4, -3, -4, -4}), - read_vector(y)); + auto test_case = test::TestCase(f); + test_case.add_input({x}); + test_case.add_expected_output(input_shape, + {2, 2, 3, -2, -3, -3, 3, 3, 4, -3, -4, -4}); + test_case.run(); } NGRAPH_TEST(${BACKEND_NAME}, quantize_ROUND_NEAREST_TOWARD_EVEN) @@ -809,18 +729,15 @@ NGRAPH_TEST(${BACKEND_NAME}, quantize_ROUND_NEAREST_TOWARD_EVEN) make_shared(X, scale, offset, output_type, quantization_axes, round_mode); auto f = make_shared(quantize, ParameterVector{X}); - auto backend = runtime::Backend::create("${BACKEND_NAME}"); - auto x = backend->create_tensor(input_type, input_shape); - auto y = backend->create_tensor(output_type, input_shape); - - copy_data(x, vector{9, 10, 11, -9, -10, -11, 13, 14, 15, -13, -14, -15}); + std::vector x{9, 10, 11, -9, -10, -11, 13, 14, 15, -13, -14, -15}; // divide by scale 4 4 4 4 4 4 4 4 4 4 4 4 // equals (rounded) 2 2 3 -2 -2 -3 3 4 4 -3 -4 -4 - auto handle = backend->compile(f); - handle->call_with_validate({y}, {x}); - EXPECT_EQ((vector{2, 2, 3, -2, -2, -3, 3, 4, 4, -3, -4, -4}), - read_vector(y)); + auto test_case = test::TestCase(f); + test_case.add_input({x}); + test_case.add_expected_output(input_shape, + {2, 2, 3, -2, -2, -3, 3, 4, 4, -3, -4, -4}); + test_case.run(); } NGRAPH_TEST(${BACKEND_NAME}, quantize_ROUND_TOWARD_INFINITY) @@ -849,18 +766,15 @@ NGRAPH_TEST(${BACKEND_NAME}, quantize_ROUND_TOWARD_INFINITY) static_cast(static_cast(round_mode))); auto f = make_shared(quantize, ParameterVector{X}); - auto backend = runtime::Backend::create("${BACKEND_NAME}"); - auto x = backend->create_tensor(input_type, input_shape); - auto y = backend->create_tensor(output_type, input_shape); - - copy_data(x, vector{9, 10, 11, -9, -10, -11, 13, 14, 15, -13, -14, -15}); + std::vector x{9, 10, 11, -9, -10, -11, 13, 14, 15, -13, -14, -15}; // divide by scale 4 4 4 4 4 4 4 4 4 4 4 4 // equals (rounded) 3 3 3 -3 -3 -3 4 4 4 -4 -4 -4 - auto handle = backend->compile(f); - handle->call_with_validate({y}, {x}); - EXPECT_EQ((vector{3, 3, 3, -3, -3, -3, 4, 4, 4, -4, -4, -4}), - read_vector(y)); + auto test_case = test::TestCase(f); + test_case.add_input({x}); + test_case.add_expected_output(input_shape, + {3, 3, 3, -3, -3, -3, 4, 4, 4, -4, -4, -4}); + test_case.run(); } NGRAPH_TEST(${BACKEND_NAME}, quantize_ROUND_TOWARD_ZERO) @@ -889,18 +803,15 @@ NGRAPH_TEST(${BACKEND_NAME}, quantize_ROUND_TOWARD_ZERO) static_cast(static_cast(round_mode))); auto f = make_shared(quantize, ParameterVector{X}); - auto backend = runtime::Backend::create("${BACKEND_NAME}"); - auto x = backend->create_tensor(input_type, input_shape); - auto y = backend->create_tensor(output_type, input_shape); - - copy_data(x, vector{9, 10, 11, -9, -10, -11, 13, 14, 15, -13, -14, -15}); + std::vector x{9, 10, 11, -9, -10, -11, 13, 14, 15, -13, -14, -15}; // divide by scale 4 4 4 4 4 4 4 4 4 4 4 4 // equals (rounded) 2 2 2 -2 -2 -2 3 3 3 -3 -3 -3 - auto handle = backend->compile(f); - handle->call_with_validate({y}, {x}); - EXPECT_EQ((vector{2, 2, 2, -2, -2, -2, 3, 3, 3, -3, -3, -3}), - read_vector(y)); + auto test_case = test::TestCase(f); + test_case.add_input({x}); + test_case.add_expected_output(input_shape, + {2, 2, 2, -2, -2, -2, 3, 3, 3, -3, -3, -3}); + test_case.run(); } NGRAPH_TEST(${BACKEND_NAME}, quantize_ROUND_UP) @@ -924,18 +835,15 @@ NGRAPH_TEST(${BACKEND_NAME}, quantize_ROUND_UP) make_shared(X, scale, offset, output_type, quantization_axes, round_mode); auto f = make_shared(quantize, ParameterVector{X}); - auto backend = runtime::Backend::create("${BACKEND_NAME}"); - auto x = backend->create_tensor(input_type, input_shape); - auto y = backend->create_tensor(output_type, input_shape); - - copy_data(x, vector{9, 10, 11, -9, -10, -11, 13, 14, 15, -13, -14, -15}); + std::vector x{9, 10, 11, -9, -10, -11, 13, 14, 15, -13, -14, -15}; // divide by scale 4 4 4 4 4 4 4 4 4 4 4 4 // equals (rounded) 3 3 3 -2 -2 -2 4 4 4 -3 -3 -3 - auto handle = backend->compile(f); - handle->call_with_validate({y}, {x}); - EXPECT_EQ((vector{3, 3, 3, -2, -2, -2, 4, 4, 4, -3, -3, -3}), - read_vector(y)); + auto test_case = test::TestCase(f); + test_case.add_input({x}); + test_case.add_expected_output(input_shape, + {3, 3, 3, -2, -2, -2, 4, 4, 4, -3, -3, -3}); + test_case.run(); } NGRAPH_TEST(${BACKEND_NAME}, quantize_ROUND_DOWN) @@ -959,18 +867,15 @@ NGRAPH_TEST(${BACKEND_NAME}, quantize_ROUND_DOWN) make_shared(X, scale, offset, output_type, quantization_axes, round_mode); auto f = make_shared(quantize, ParameterVector{X}); - auto backend = runtime::Backend::create("${BACKEND_NAME}"); - auto x = backend->create_tensor(input_type, input_shape); - auto y = backend->create_tensor(output_type, input_shape); - - copy_data(x, vector{9, 10, 11, -9, -10, -11, 13, 14, 15, -13, -14, -15}); + std::vector x{9, 10, 11, -9, -10, -11, 13, 14, 15, -13, -14, -15}; // divide by scale 4 4 4 4 4 4 4 4 4 4 4 4 // equals (rounded) 2 2 2 -3 -3 -3 3 3 3 -4 -4 -4 - auto handle = backend->compile(f); - handle->call_with_validate({y}, {x}); - EXPECT_EQ((vector{2, 2, 2, -3, -3, -3, 3, 3, 3, -4, -4, -4}), - read_vector(y)); + auto test_case = test::TestCase(f); + test_case.add_input({x}); + test_case.add_expected_output(input_shape, + {2, 2, 2, -3, -3, -3, 3, 3, 3, -4, -4, -4}); + test_case.run(); } NGRAPH_TEST(${BACKEND_NAME}, dequantize_dynamic_offset) @@ -991,21 +896,17 @@ NGRAPH_TEST(${BACKEND_NAME}, dequantize_dynamic_offset) auto dequantize = make_shared(X, scale, offset, output_type, quantization_axes); auto f = make_shared(dequantize, ParameterVector{X, scale, offset}); - auto backend = runtime::Backend::create("${BACKEND_NAME}"); - auto x = backend->create_tensor(input_type, input_shape); - auto y = backend->create_tensor(output_type, input_shape); - auto Scale = backend->create_tensor(output_type, scale_offset_shape); - auto Offset = backend->create_tensor(input_type, scale_offset_shape); - - copy_data(x, vector{0, 3, 128, 255}); - copy_data(Scale, vector{2}); - copy_data(Offset, vector{128}); - - auto handle = backend->compile(f); - handle->call_with_validate({y}, {x, Scale, Offset}); - EXPECT_TRUE(test::all_close_f((vector{-256.0f, -250.0f, 0.0f, 254.0f}), - read_vector(y), - MIN_FLOAT_TOLERANCE_BITS)); + std::vector x{0, 3, 128, 255}; + std::vector Scale{2}; + std::vector Offset{128}; + + auto test_case = test::TestCase(f); + test_case.add_input({x}); + test_case.add_input({Scale}); + test_case.add_input({Offset}); + + test_case.add_expected_output(input_shape, {-256.0f, -250.0f, 0.0f, 254.0f}); + test_case.run(MIN_FLOAT_TOLERANCE_BITS); } NGRAPH_TEST(${BACKEND_NAME}, quantize_dynamic_offset) @@ -1029,22 +930,19 @@ NGRAPH_TEST(${BACKEND_NAME}, quantize_dynamic_offset) make_shared(X, scale, offset, output_type, quantization_axes, round_mode); auto f = make_shared(quantize, ParameterVector{X, scale, offset}); - auto backend = runtime::Backend::create("${BACKEND_NAME}"); - auto x = backend->create_tensor(input_type, input_shape); - auto y = backend->create_tensor(output_type, input_shape); - auto Scale = backend->create_tensor(input_type, scale_offset_shape); - auto Offset = backend->create_tensor(output_type, scale_offset_shape); - - copy_data(x, vector{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}); + std::vector x{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}; // divide by scale 2 2 2 2 2 2 2 2 2 2 2 2 // equals (rounded) 0 0 1 2 2 2 3 4 4 4 5 6 // plus offset 1 1 1 1 1 1 1 1 1 1 1 1 // equals 1 1 2 3 3 3 4 5 5 5 6 7 - copy_data(Scale, vector{2}); - copy_data(Offset, vector{1}); + std::vector Scale{2}; + std::vector Offset{1}; + + auto test_case = test::TestCase(f); + test_case.add_input({x}); + test_case.add_input({Scale}); + test_case.add_input({Offset}); - auto handle = backend->compile(f); - handle->call_with_validate({y}, {x, Scale, Offset}); - EXPECT_EQ((vector{1, 1, 2, 3, 3, 3, 4, 5, 5, 5, 6, 7}), - read_vector(y)); + test_case.add_expected_output(input_shape, {1, 1, 2, 3, 3, 3, 4, 5, 5, 5, 6, 7}); + test_case.run(); } From 12abb2eb498dd5f8346284eb1503d86b2d0db4f5 Mon Sep 17 00:00:00 2001 From: Irina Efode Date: Wed, 16 Sep 2020 16:46:02 +0300 Subject: [PATCH 12/64] [IE TESTS] CoreThreading_LoadNetwork tests were disabled for GPU plugin (#2245) --- .../skip_tests_config.cpp | 2 ++ .../include/behavior/core_threading_tests.hpp | 18 +++++++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/inference-engine/tests/functional/plugin/gpu/shared_tests_instances/skip_tests_config.cpp b/inference-engine/tests/functional/plugin/gpu/shared_tests_instances/skip_tests_config.cpp index 1f9d072e3fc1b7..9cd14ea73a0bfe 100644 --- a/inference-engine/tests/functional/plugin/gpu/shared_tests_instances/skip_tests_config.cpp +++ b/inference-engine/tests/functional/plugin/gpu/shared_tests_instances/skip_tests_config.cpp @@ -15,5 +15,7 @@ std::vector disabledTestPatterns() { R"(.*(IEClassLoadNetwork).*(QueryNetworkMULTIWithHETERONoThrow_V10|QueryNetworkHETEROWithMULTINoThrow_V10).*)", //TODO: Issue: 34748 R"(.*(ComparisonLayerTest).*)", + // TODO: Issue: 39014 + R"(.*CoreThreadingTestsWithIterations.*smoke_LoadNetwork.*)", }; } \ No newline at end of file diff --git a/inference-engine/tests/functional/plugin/shared/include/behavior/core_threading_tests.hpp b/inference-engine/tests/functional/plugin/shared/include/behavior/core_threading_tests.hpp index 886a24b852f05b..b2f68f644a8e71 100644 --- a/inference-engine/tests/functional/plugin/shared/include/behavior/core_threading_tests.hpp +++ b/inference-engine/tests/functional/plugin/shared/include/behavior/core_threading_tests.hpp @@ -83,7 +83,6 @@ class CoreThreadingTests : public CoreThreadingTestsBase, public ::testing::TestWithParam { public: void SetUp() override { - SKIP_IF_CURRENT_TEST_IS_DISABLED() std::tie(deviceName, config) = GetParam(); } @@ -105,8 +104,8 @@ class CoreThreadingTests : public CoreThreadingTestsBase, // tested function: GetVersions, UnregisterPlugin TEST_P(CoreThreadingTests, smoke_GetVersions) { + SKIP_IF_CURRENT_TEST_IS_DISABLED() InferenceEngine::Core ie; - runParallel([&] () { auto versions = ie.GetVersions(deviceName); ASSERT_LE(1u, versions.size()); @@ -116,6 +115,8 @@ TEST_P(CoreThreadingTests, smoke_GetVersions) { // tested function: SetConfig for already created plugins TEST_P(CoreThreadingTests, smoke_SetConfigPluginExists) { + SKIP_IF_CURRENT_TEST_IS_DISABLED() + InferenceEngine::Core ie; ie.SetConfig(config); @@ -128,6 +129,8 @@ TEST_P(CoreThreadingTests, smoke_SetConfigPluginExists) { // tested function: GetConfig, UnregisterPlugin TEST_P(CoreThreadingTests, smoke_GetConfig) { + SKIP_IF_CURRENT_TEST_IS_DISABLED() + InferenceEngine::Core ie; std::string configKey = config.begin()->first; @@ -140,6 +143,8 @@ TEST_P(CoreThreadingTests, smoke_GetConfig) { // tested function: GetMetric, UnregisterPlugin TEST_P(CoreThreadingTests, smoke_GetMetric) { + SKIP_IF_CURRENT_TEST_IS_DISABLED() + InferenceEngine::Core ie; runParallel([&] () { ie.GetMetric(deviceName, METRIC_KEY(SUPPORTED_CONFIG_KEYS)); @@ -149,6 +154,8 @@ TEST_P(CoreThreadingTests, smoke_GetMetric) { // tested function: QueryNetwork TEST_P(CoreThreadingTests, smoke_QueryNetwork) { + SKIP_IF_CURRENT_TEST_IS_DISABLED() + InferenceEngine::Core ie; auto model = FuncTestUtils::TestModel::convReluNormPoolFcModelFP32; auto network = ie.ReadNetwork(model.model_xml_str, model.weights_blob); @@ -182,7 +189,6 @@ class CoreThreadingTestsWithIterations : public ::testing::TestWithParam(GetParam()); numThreads = std::get<1>(GetParam()); numIterations = std::get<2>(GetParam()); @@ -213,6 +219,8 @@ class CoreThreadingTestsWithIterations : public ::testing::TestWithParam counter{0u}; @@ -240,6 +248,8 @@ TEST_P(CoreThreadingTestsWithIterations, smoke_LoadNetwork) { // tested function: LoadNetwork accuracy TEST_P(CoreThreadingTestsWithIterations, smoke_LoadNetworkAccuracy) { + SKIP_IF_CURRENT_TEST_IS_DISABLED() + InferenceEngine::Core ie; std::atomic counter{0u}; @@ -300,6 +310,8 @@ TEST_P(CoreThreadingTestsWithIterations, smoke_LoadNetworkAccuracy) { // tested function: ReadNetwork, SetConfig, LoadNetwork, AddExtension TEST_P(CoreThreadingTestsWithIterations, smoke_LoadNetwork_MultipleIECores) { + SKIP_IF_CURRENT_TEST_IS_DISABLED() + std::atomic counter{0u}; // TODO: replace with subgraph builders after fixing *-31414 From 1e5edf86a1a456168721f48c694707c3d94f3781 Mon Sep 17 00:00:00 2001 From: Nikolay Shchegolev Date: Wed, 16 Sep 2020 18:09:59 +0300 Subject: [PATCH 13/64] Statically analyzed issues. (#2274) --- .../src/legacy_api/src/convert_function_to_cnn_network.cpp | 6 ++++++ inference-engine/src/legacy_api/src/net_pass.cpp | 4 +++- .../src/readers/ir_reader_v7/ie_layer_validators.cpp | 2 +- .../convert_opset1_to_legacy/fc_bias_fusion.cpp | 2 ++ .../src/transformations/reduce_l1_decomposition.cpp | 2 +- .../src/transformations/reduce_l2_decomposition.cpp | 2 +- 6 files changed, 14 insertions(+), 4 deletions(-) diff --git a/inference-engine/src/legacy_api/src/convert_function_to_cnn_network.cpp b/inference-engine/src/legacy_api/src/convert_function_to_cnn_network.cpp index dd27d57d340d8d..863de89ed9501a 100644 --- a/inference-engine/src/legacy_api/src/convert_function_to_cnn_network.cpp +++ b/inference-engine/src/legacy_api/src/convert_function_to_cnn_network.cpp @@ -669,6 +669,8 @@ InferenceEngine::details::CNNLayerCreator::CNNLayerCreator(const std::shared_ptr [](const std::shared_ptr<::ngraph::Node>& node, const std::map& params) -> CNNLayerPtr { LayerParams attrs = {node->get_friendly_name(), node->description(), details::convertPrecision(node->get_output_element_type(0))}; auto reduce_node = std::dynamic_pointer_cast(node); + if (reduce_node == nullptr) + THROW_IE_EXCEPTION << "Node '" << node->get_name() << "' is not an instance of ArithmeticReductionKeepDims."; auto res = std::make_shared(attrs); res->params = params; res->params["keep_dims"] = reduce_node->get_keep_dims() ? "True" : "False"; @@ -678,6 +680,8 @@ InferenceEngine::details::CNNLayerCreator::CNNLayerCreator(const std::shared_ptr addSpecificCreator({"ReduceLogicalAnd"}, [](const std::shared_ptr<::ngraph::Node>& node, const std::map& params) -> CNNLayerPtr { LayerParams attrs = {node->get_friendly_name(), "ReduceAnd", details::convertPrecision(node->get_output_element_type(0))}; auto reduce_node = std::dynamic_pointer_cast(node); + if (reduce_node == nullptr) + THROW_IE_EXCEPTION << "Node '" << node->get_name() << "' is not an instance of LogicalReductionKeepDims."; auto res = std::make_shared(attrs); res->params = params; res->params["keep_dims"] = reduce_node->get_keep_dims() ? "True" : "False"; @@ -687,6 +691,8 @@ InferenceEngine::details::CNNLayerCreator::CNNLayerCreator(const std::shared_ptr addSpecificCreator({"ReduceLogicalOr"}, [](const std::shared_ptr<::ngraph::Node>& node, const std::map& params) -> CNNLayerPtr { LayerParams attrs = {node->get_friendly_name(), "ReduceOr", details::convertPrecision(node->get_output_element_type(0))}; auto reduce_node = std::dynamic_pointer_cast(node); + if (reduce_node == nullptr) + THROW_IE_EXCEPTION << "Node '" << node->get_name() << "' is not an instance of LogicalReductionKeepDims."; auto res = std::make_shared(attrs); res->params = params; res->params["keep_dims"] = reduce_node->get_keep_dims() ? "True" : "False"; diff --git a/inference-engine/src/legacy_api/src/net_pass.cpp b/inference-engine/src/legacy_api/src/net_pass.cpp index 9791218eb8bcb2..4dac072e35e7f7 100644 --- a/inference-engine/src/legacy_api/src/net_pass.cpp +++ b/inference-engine/src/legacy_api/src/net_pass.cpp @@ -398,8 +398,10 @@ bool convertToRNNSeq(CNNLayerPtr cur, const N& net) { IE_ASSERT(cell->insData.size() == NS + 1); // {data, state1, [state2]} IE_ASSERT(cell->outData.size() == NS); // {state1, [state2]} + auto outData0InputsTo = getInputTo(cell->outData[0]); if (getCreatorLayer(cell->insData[0].lock()).lock() != rsp1 || - getInputTo(cell->outData[0]).begin()->second != rsp2) + outData0InputsTo.empty() || + outData0InputsTo.begin()->second != rsp2) return false; // Check port mapping diff --git a/inference-engine/src/readers/ir_reader_v7/ie_layer_validators.cpp b/inference-engine/src/readers/ir_reader_v7/ie_layer_validators.cpp index cae6bd12ad9ec9..7cd900a669e9ad 100644 --- a/inference-engine/src/readers/ir_reader_v7/ie_layer_validators.cpp +++ b/inference-engine/src/readers/ir_reader_v7/ie_layer_validators.cpp @@ -269,7 +269,7 @@ void CropValidator::checkShapes(const CNNLayer* layer, const vector& } } else if (!casted->dim.empty()) { int dim = casted->dim[i]; - if (firstShape[axis] < static_cast(offset + dim)) { + if (firstShape[axis] < (static_cast(offset) + dim)) { THROW_IE_EXCEPTION << "Incorrect crop data! Offset(" << offset << ") + result size of output(" << dim << ") should be less then input size(" << firstShape[axis] << ") for axis(" << axis << ")"; diff --git a/inference-engine/src/transformations/src/transformations/convert_opset1_to_legacy/fc_bias_fusion.cpp b/inference-engine/src/transformations/src/transformations/convert_opset1_to_legacy/fc_bias_fusion.cpp index dc2538c26a0ac2..324787586ec4bd 100644 --- a/inference-engine/src/transformations/src/transformations/convert_opset1_to_legacy/fc_bias_fusion.cpp +++ b/inference-engine/src/transformations/src/transformations/convert_opset1_to_legacy/fc_bias_fusion.cpp @@ -28,6 +28,8 @@ ngraph::pass::FullyConnectedBiasFusion::FullyConnectedBiasFusion() { if (m_fc == nullptr) { m_fc = std::dynamic_pointer_cast(add_input_1); + if (m_fc == nullptr) + return false; m_bias = add_input_0; } diff --git a/inference-engine/src/transformations/src/transformations/reduce_l1_decomposition.cpp b/inference-engine/src/transformations/src/transformations/reduce_l1_decomposition.cpp index 13903831fd0baa..87f8fd0481be11 100644 --- a/inference-engine/src/transformations/src/transformations/reduce_l1_decomposition.cpp +++ b/inference-engine/src/transformations/src/transformations/reduce_l1_decomposition.cpp @@ -20,7 +20,7 @@ ngraph::pass::ReduceL1Decomposition::ReduceL1Decomposition() { auto &pattern_to_output = m.get_pattern_value_map(); auto reduce_l1_node = std::dynamic_pointer_cast(pattern_to_output.at(reduce_l1).get_node_shared_ptr()); - if (m_transformation_callback(reduce_l1_node)) { + if (reduce_l1_node == nullptr || m_transformation_callback(reduce_l1_node)) { return false; } diff --git a/inference-engine/src/transformations/src/transformations/reduce_l2_decomposition.cpp b/inference-engine/src/transformations/src/transformations/reduce_l2_decomposition.cpp index 60e8114e887e1e..f36cfeef67cd04 100644 --- a/inference-engine/src/transformations/src/transformations/reduce_l2_decomposition.cpp +++ b/inference-engine/src/transformations/src/transformations/reduce_l2_decomposition.cpp @@ -20,7 +20,7 @@ ngraph::pass::ReduceL2Decomposition::ReduceL2Decomposition() { auto &pattern_to_output = m.get_pattern_value_map(); auto reduce_l2_node = std::dynamic_pointer_cast(pattern_to_output.at(reduce_l2).get_node_shared_ptr()); - if (m_transformation_callback(reduce_l2_node)) { + if (reduce_l2_node == nullptr || m_transformation_callback(reduce_l2_node)) { return false; } From 5e4377b25033cff78a9c602e41ec6d0b7ef2ac67 Mon Sep 17 00:00:00 2001 From: Nikolay Shchegolev Date: Wed, 16 Sep 2020 18:19:14 +0300 Subject: [PATCH 14/64] [CPU] RNN layer. Blobs precision validation. (#2223) --- .../src/mkldnn_plugin/nodes/mkldnn_rnn.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_rnn.cpp b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_rnn.cpp index 62be4b32b765c0..9fb34e6fff39c9 100644 --- a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_rnn.cpp +++ b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_rnn.cpp @@ -332,6 +332,16 @@ void MKLDNNRNN::createDescriptor(const std::vector &inputDesc, void MKLDNNRNN::createPrimitive() { if (prim) return; + std::string errorPrefix = "RNN layer '" + getCnnLayer()->name + "'"; + auto weightsIt = getCnnLayer()->blobs.find("weights"); + if (weightsIt == getCnnLayer()->blobs.end()) + THROW_IE_EXCEPTION << errorPrefix << " does not have weights blob."; + if (weightsIt->second->getTensorDesc().getPrecision() != Precision::FP32) + THROW_IE_EXCEPTION << errorPrefix << " has invalid weights precision: " << weightsIt->second->getTensorDesc().getPrecision(); + if (getCnnLayer()->blobs.find("biases") != getCnnLayer()->blobs.end() + && getCnnLayer()->blobs["biases"]->getTensorDesc().getPrecision() != Precision::FP32) + THROW_IE_EXCEPTION << errorPrefix << " has invalid biases precision: " << getCnnLayer()->blobs["biases"]->getTensorDesc().getPrecision(); + std::shared_ptr d = descs[0]; rnn_forward::primitive_desc pd(*d, getEngine()); From 304c37216a8847fcc59272a83242f3d9977fb900 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Do=C5=82bniak?= Date: Wed, 16 Sep 2020 22:04:47 +0200 Subject: [PATCH 15/64] Clone a specific tag for pybind11 (#2297) --- .ci/openvino-onnx/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.ci/openvino-onnx/Dockerfile b/.ci/openvino-onnx/Dockerfile index 4e98d68341c4f1..40f62f3cbea821 100644 --- a/.ci/openvino-onnx/Dockerfile +++ b/.ci/openvino-onnx/Dockerfile @@ -79,5 +79,5 @@ ENV NGRAPH_CPP_BUILD_PATH=/openvino/dist ENV LD_LIBRARY_PATH=/openvino/dist/lib ENV NGRAPH_ONNX_IMPORT_ENABLE=TRUE ENV PYTHONPATH=/openvino/bin/intel64/Release/lib/python_api/python3.8:${PYTHONPATH} -RUN git clone --recursive https://github.com/pybind/pybind11.git +RUN git clone --recursive https://github.com/pybind/pybind11.git -b v2.5.0 --depth 1 CMD tox From 6b9376e0c6f81ec2518af99361fc0dd73495f122 Mon Sep 17 00:00:00 2001 From: Maxim Shevtsov Date: Thu, 17 Sep 2020 09:31:42 +0300 Subject: [PATCH 16/64] Reverting devicePriorities to be vector and respect the order, as opposed to the incorrect (re (#2249) cent?) refactoring that introduced the unordered_map that effectively ignores the priorities --- .../src/multi_device/multi_device.cpp | 47 +++++++++---------- .../src/multi_device/multi_device.hpp | 7 +-- 2 files changed, 26 insertions(+), 28 deletions(-) diff --git a/inference-engine/src/multi_device/multi_device.cpp b/inference-engine/src/multi_device/multi_device.cpp index d5ad3993ee2a2e..98bffd63610ae4 100644 --- a/inference-engine/src/multi_device/multi_device.cpp +++ b/inference-engine/src/multi_device/multi_device.cpp @@ -141,7 +141,7 @@ struct IdleGuard { }; MultiDeviceExecutableNetwork::MultiDeviceExecutableNetwork(const DeviceMap& networksPerDevice, - const DeviceMap& networkDevices, + const std::vector& networkDevices, const std::unordered_map& config, const bool needPerfCounters) : InferenceEngine::ExecutableNetworkThreadSafeDefault(nullptr, std::make_shared()), @@ -154,7 +154,8 @@ MultiDeviceExecutableNetwork::MultiDeviceExecutableNetwork(const DeviceMap(); @@ -165,7 +166,7 @@ MultiDeviceExecutableNetwork::MultiDeviceExecutableNetwork(const DeviceMapsecond.numRequestsPerDevices == -1) ? optimalNum : itNumRequests->second.numRequestsPerDevices; + itNumRequests->numRequestsPerDevices == -1) ? optimalNum : itNumRequests->numRequestsPerDevices; auto& workerRequests = _workerRequests[device]; auto& idleWorkerRequests = _idleWorkerRequests[device]; workerRequests.resize(numRequests); @@ -197,7 +198,7 @@ void MultiDeviceExecutableNetwork::ScheduleToWorkerInferRequest() { return _devicePriorities; }(); for (auto&& device : devices) { - auto& idleWorkerRequests = _idleWorkerRequests[device.first]; + auto& idleWorkerRequests = _idleWorkerRequests[device.deviceName]; WorkerInferRequest* workerRequestPtr = nullptr; if (idleWorkerRequests.try_pop(workerRequestPtr)) { IdleGuard idleGuard{workerRequestPtr, idleWorkerRequests}; @@ -258,8 +259,8 @@ void MultiDeviceExecutableNetwork::SetConfig(const std::mapParseMetaDevices(priorities->second, {}); - if (std::any_of(metaDevices.begin(), metaDevices.end(), [](const std::pair & kvp) { - return kvp.second.numRequestsPerDevices != -1; + if (std::any_of(metaDevices.begin(), metaDevices.end(), [](const DeviceInformation& kvp) { + return kvp.numRequestsPerDevices != -1; })) { THROW_IE_EXCEPTION << NOT_IMPLEMENTED_str << "You can only change device priorities but not number of requests" <<" with the Network's SetConfig(MultiDeviceConfigParams::KEY_MULTI_DEVICE_PRIORITIES!"; @@ -268,9 +269,10 @@ void MultiDeviceExecutableNetwork::SetConfig(const std::map lock{_mutex}; for (auto && device : metaDevices) { - if (_networksPerDevice.find(device.first) == _networksPerDevice.end()) { + if (_networksPerDevice.find(device.deviceName) == _networksPerDevice.end()) { THROW_IE_EXCEPTION << NOT_FOUND_str << "You can only change device priorities but not add new devices with" - << " the Network's SetConfig(MultiDeviceConfigParams::KEY_MULTI_DEVICE_PRIORITIES. " << device.first << + << " the Network's SetConfig(MultiDeviceConfigParams::KEY_MULTI_DEVICE_PRIORITIES. " + << device.deviceName << " device was not in the original device list!"; } } @@ -353,9 +355,9 @@ std::map MultiDeviceInferencePlugin::GetSupportedConfi return supportedConfig; } -DeviceMap MultiDeviceInferencePlugin::ParseMetaDevices(const std::string& priorities, +std::vector MultiDeviceInferencePlugin::ParseMetaDevices(const std::string& priorities, const std::map & config) const { - DeviceMap metaDevices; + std::vector metaDevices; // parsing the string and splitting to tokens std::vector devicesWithRequests; @@ -399,12 +401,13 @@ DeviceMap MultiDeviceInferencePlugin::ParseMetaDevices(const } // create meta device - metaDevices[deviceName] = { getDeviceConfig(deviceName), numRequests }; + auto cfg = getDeviceConfig(deviceName); std::vector supportedConfigKeys = GetCore()->GetMetric(deviceName, METRIC_KEY(SUPPORTED_CONFIG_KEYS)); if (std::find(std::begin(supportedConfigKeys), std::end(supportedConfigKeys), CONFIG_KEY_INTERNAL(AGGREGATED_PLUGIN)) != std::end(supportedConfigKeys)) { - metaDevices[deviceName].config.emplace(CONFIG_KEY_INTERNAL(AGGREGATED_PLUGIN), ""); + cfg.emplace(CONFIG_KEY_INTERNAL(AGGREGATED_PLUGIN), ""); } + metaDevices.push_back({ deviceName, cfg, numRequests }); } return metaDevices; @@ -470,7 +473,7 @@ ExecutableNetworkInternal::Ptr MultiDeviceInferencePlugin::LoadExeNetworkImpl(co THROW_IE_EXCEPTION << "KEY_MULTI_DEVICE_PRIORITIES key is not set for MULTI device"; } - DeviceMap metaDevices = ParseMetaDevices(priorities->second, fullConfig); + auto metaDevices = ParseMetaDevices(priorities->second, fullConfig); // collect the settings that are applicable to the devices we are loading the network to std::unordered_map multiNetworkConfig; @@ -478,9 +481,8 @@ ExecutableNetworkInternal::Ptr MultiDeviceInferencePlugin::LoadExeNetworkImpl(co DeviceMap executableNetworkPerDevice; for (auto& p : metaDevices) { - auto & deviceName = p.first; - auto & metaDevice = p.second; - auto & deviceConfig = metaDevice.config; + auto & deviceName = p.deviceName; + auto & deviceConfig = p.config; auto clonedNetwork = cloneNetwork(network); executableNetworkPerDevice.insert({ deviceName, GetCore()->LoadNetwork(CNNNetwork{clonedNetwork}, deviceName, deviceConfig) }); multiNetworkConfig.insert(deviceConfig.begin(), deviceConfig.end()); @@ -514,16 +516,14 @@ void MultiDeviceInferencePlugin::QueryNetwork(const ICNNNetwork& THROW_IE_EXCEPTION << "KEY_MULTI_DEVICE_PRIORITIES key is not set for MULTI device"; } - DeviceMap metaDevices = ParseMetaDevices(priorities->second, fullConfig); + auto metaDevices = ParseMetaDevices(priorities->second, fullConfig); std::unordered_set supportedLayers; auto allSupportsNgraph = std::all_of(std::begin(metaDevices), std::end(metaDevices), - [&] (const DeviceMap::value_type & value) -> bool { - auto& deviceName = value.first; - auto& metaDevice = value.second; + [&] (const DeviceInformation& value) -> bool { auto clonedNetwork = cloneNetwork(network); - try { GetCore()->QueryNetwork(*clonedNetwork, deviceName, metaDevice.config); } + try { GetCore()->QueryNetwork(*clonedNetwork, value.deviceName, value.config); } catch (const InferenceEngine::details::InferenceEngineException & ex) { std::string message = ex.what(); return message.find(NOT_IMPLEMENTED_str) == std::string::npos; @@ -532,12 +532,9 @@ void MultiDeviceInferencePlugin::QueryNetwork(const ICNNNetwork& }); for (auto&& value : metaDevices) { - auto& deviceName = value.first; - auto& metaDevice = value.second; - auto queryNetwork = [&] (const InferenceEngine::ICNNNetwork & networkObject) { auto clonedNetwork = cloneNetwork(networkObject); - auto deviceQr = GetCore()->QueryNetwork(*clonedNetwork, deviceName, metaDevice.config); + auto deviceQr = GetCore()->QueryNetwork(*clonedNetwork, value.deviceName, value.config); std::unordered_set deviceSupportedLayers; for (auto&& layerQr : deviceQr.supportedLayersMap) { deviceSupportedLayers.emplace(layerQr.first); diff --git a/inference-engine/src/multi_device/multi_device.hpp b/inference-engine/src/multi_device/multi_device.hpp index 3c0593a671e565..964d9222d8c7a6 100644 --- a/inference-engine/src/multi_device/multi_device.hpp +++ b/inference-engine/src/multi_device/multi_device.hpp @@ -31,6 +31,7 @@ namespace MultiDevicePlugin { using DeviceName = std::string; struct DeviceInformation { + DeviceName deviceName; std::map config; int numRequestsPerDevices; }; @@ -99,7 +100,7 @@ class MultiDeviceExecutableNetwork : public InferenceEngine::ExecutableNetworkTh using NotBusyWorkerRequests = ThreadSafeQueue; explicit MultiDeviceExecutableNetwork(const DeviceMap& networksPerDevice, - const DeviceMap& networkDevices, + const std::vector& networkDevices, const std::unordered_map& config, const bool needPerfCounters = false); @@ -117,7 +118,7 @@ class MultiDeviceExecutableNetwork : public InferenceEngine::ExecutableNetworkTh static thread_local WorkerInferRequest* _thisWorkerInferRequest; std::atomic_bool _terminate = {false}; std::mutex _mutex; - DeviceMap _devicePriorities; + std::vector _devicePriorities; DeviceMap _networksPerDevice; ThreadSafeQueue _inferPipelineTasks; DeviceMap _idleWorkerRequests; @@ -163,7 +164,7 @@ class MultiDeviceInferencePlugin : public InferenceEngine::InferencePluginIntern InferenceEngine::Parameter GetMetric(const std::string& name, const std::map& options) const override; - DeviceMap ParseMetaDevices(const std::string & devicesRequestsCfg, + std::vector ParseMetaDevices(const std::string & devicesRequestsCfg, const std::map & config) const; protected: From 379158fc1199a1264eb0d10fb80e7b8eb6b8045b Mon Sep 17 00:00:00 2001 From: Ivan Tikhonov Date: Thu, 17 Sep 2020 11:45:45 +0300 Subject: [PATCH 17/64] Move PriorBox to PriorBoxIE transformation from CommonOptimization pass (#2185) * move PriorBox to PriorBoxIE transformation from CommonOptimization pass * call initNodeInfo transformation before PriorToPriorIE * update comments --- inference-engine/src/cldnn_engine/cldnn_engine.cpp | 5 +++++ inference-engine/src/legacy_api/src/cnn_network_impl.cpp | 5 +++++ inference-engine/src/mkldnn_plugin/mkldnn_plugin.cpp | 5 +++++ .../common_optimizations/common_optimizations.cpp | 3 --- .../src/vpu/graph_transformer/src/frontend/frontend.cpp | 5 +++++ .../cnn_network/convert_ngraph_to_cnn_network_tests.cpp | 4 ++++ .../low_precision_transformations/layer_transformation.cpp | 5 +++++ .../low_precision_transformations/layer_transformation.cpp | 5 +++++ 8 files changed, 34 insertions(+), 3 deletions(-) diff --git a/inference-engine/src/cldnn_engine/cldnn_engine.cpp b/inference-engine/src/cldnn_engine/cldnn_engine.cpp index 3d9b167076181e..33f7e74b50df44 100644 --- a/inference-engine/src/cldnn_engine/cldnn_engine.cpp +++ b/inference-engine/src/cldnn_engine/cldnn_engine.cpp @@ -30,8 +30,10 @@ #include #include #include +#include #include #include +#include #include #include #include @@ -127,6 +129,9 @@ InferenceEngine::ICNNNetwork::Ptr clDNNEngine::CloneAndTransformNetwork(const In // Note: instead of running all Conversion Transformations you can make up your own transformation pipeline ngraph::pass::Manager manager; + manager.register_pass(); + // WA: ConvertPriorBox must be executed before the 1st ConstantFolding pass + manager.register_pass(); manager.register_pass(); manager.register_pass(); manager.register_pass(); diff --git a/inference-engine/src/legacy_api/src/cnn_network_impl.cpp b/inference-engine/src/legacy_api/src/cnn_network_impl.cpp index 67bf0147802fdd..2aaeec46ce4861 100644 --- a/inference-engine/src/legacy_api/src/cnn_network_impl.cpp +++ b/inference-engine/src/legacy_api/src/cnn_network_impl.cpp @@ -18,8 +18,10 @@ #include "generic_ie.hpp" #include "cnn_network_ngraph_impl.hpp" +#include #include #include +#include #include #include #include @@ -95,6 +97,9 @@ CNNNetworkImpl::CNNNetworkImpl(const ICNNNetwork & ngraphImpl) { ::ngraph::op::GenericIE::DisableReshape noReshape(graph); ::ngraph::pass::Manager manager; + manager.register_pass<::ngraph::pass::InitNodeInfo>(); + // WA: ConvertPriorBox must be executed before the 1st ConstantFolding pass + manager.register_pass<::ngraph::pass::ConvertPriorBox>(); manager.register_pass<::ngraph::pass::CommonOptimizations>(); manager.register_pass<::ngraph::pass::ConvertOpSet3ToOpSet2>(); manager.register_pass<::ngraph::pass::ConvertOpSet2ToOpSet1>(); diff --git a/inference-engine/src/mkldnn_plugin/mkldnn_plugin.cpp b/inference-engine/src/mkldnn_plugin/mkldnn_plugin.cpp index 0631c27e086bf0..cf4b35fe55d44e 100644 --- a/inference-engine/src/mkldnn_plugin/mkldnn_plugin.cpp +++ b/inference-engine/src/mkldnn_plugin/mkldnn_plugin.cpp @@ -24,8 +24,10 @@ #include #include #include +#include #include #include +#include #include #include #include @@ -92,6 +94,9 @@ static void Transformation(ICNNNetwork::Ptr& clonedNetwork) { ngraph::op::GenericIE::DisableReshape noReshape(nGraphFunc); ngraph::pass::Manager manager; + manager.register_pass(); + // WA: ConvertPriorBox must be executed before the 1st ConstantFolding pass + manager.register_pass(); manager.register_pass(); manager.register_pass(); manager.register_pass(); diff --git a/inference-engine/src/transformations/src/transformations/common_optimizations/common_optimizations.cpp b/inference-engine/src/transformations/src/transformations/common_optimizations/common_optimizations.cpp index 56f0eceae4a7cd..4ec3c63a867757 100644 --- a/inference-engine/src/transformations/src/transformations/common_optimizations/common_optimizations.cpp +++ b/inference-engine/src/transformations/src/transformations/common_optimizations/common_optimizations.cpp @@ -7,7 +7,6 @@ #include "transformations/common_optimizations/algebraic_simplification.hpp" #include "transformations/common_optimizations/nop_elimination.hpp" #include "transformations/common_optimizations/common_optimizations.hpp" -#include "transformations/convert_opset1_to_legacy/convert_prior_to_ie_prior.hpp" #include "transformations/depth_to_space_fusion.hpp" #include "transformations/optimize_strided_slice.hpp" #include "transformations/convert_scatter_elements_to_scatter.hpp" @@ -35,8 +34,6 @@ bool ngraph::pass::CommonOptimizations::run_on_function(std::shared_ptr(); - manager.register_pass(); // WA: ConvertPriorBox must be executed before CF - manager.register_pass(); manager.register_pass(); // Resolves dynamism (replaces NonZero), CF needed manager.register_pass(); manager.register_pass(); diff --git a/inference-engine/src/vpu/graph_transformer/src/frontend/frontend.cpp b/inference-engine/src/vpu/graph_transformer/src/frontend/frontend.cpp index 6bdcb26095d1c4..d7c88a73f25beb 100644 --- a/inference-engine/src/vpu/graph_transformer/src/frontend/frontend.cpp +++ b/inference-engine/src/vpu/graph_transformer/src/frontend/frontend.cpp @@ -27,7 +27,9 @@ #include #include #include +#include #include +#include #include #include #include "vpu/ngraph/transformations/dynamic_to_static_shape.hpp" @@ -168,6 +170,9 @@ ie::ICNNNetwork::Ptr FrontEnd::convertNetwork(ie::ICNNNetwork& network) { ngraph::op::GenericIE::DisableReshape noReshape(nGraphFunc); ngraph::pass::Manager manager; + manager.register_pass<::ngraph::pass::InitNodeInfo>(); + // WA: ConvertPriorBox must be executed before the 1st ConstantFolding pass + manager.register_pass<::ngraph::pass::ConvertPriorBox>(); manager.register_pass(); manager.register_pass(); manager.register_pass(); diff --git a/inference-engine/tests/functional/inference_engine/cnn_network/convert_ngraph_to_cnn_network_tests.cpp b/inference-engine/tests/functional/inference_engine/cnn_network/convert_ngraph_to_cnn_network_tests.cpp index 6daf3297e17c7e..3f22b42f308ec6 100644 --- a/inference-engine/tests/functional/inference_engine/cnn_network/convert_ngraph_to_cnn_network_tests.cpp +++ b/inference-engine/tests/functional/inference_engine/cnn_network/convert_ngraph_to_cnn_network_tests.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -167,6 +168,9 @@ TEST(ConvertFunctionToCNNNetworkTests, ConvertTopKWithOneInput) { } ngraph::pass::Manager manager; + manager.register_pass(); + // WA: ConvertPriorBox must be executed before the 1st ConstantFolding pass + manager.register_pass(); manager.register_pass(); manager.register_pass(); manager.register_pass(); diff --git a/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/low_precision_transformations/layer_transformation.cpp b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/low_precision_transformations/layer_transformation.cpp index 31f5f5de314850..a384b22fbf2613 100644 --- a/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/low_precision_transformations/layer_transformation.cpp +++ b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/low_precision_transformations/layer_transformation.cpp @@ -17,8 +17,10 @@ #include #include #include +#include #include #include +#include #include #include #include @@ -79,6 +81,9 @@ InferenceEngine::CNNNetwork LayerTransformation::transform(InferenceEngine::deta // Note: instead of running all Conversion Transformations you can make up your own transformation pipeline ngraph::pass::Manager manager; + manager.register_pass(); + // WA: ConvertPriorBox must be executed before the 1st ConstantFolding pass + manager.register_pass(); manager.register_pass(); manager.register_pass(); manager.register_pass(); diff --git a/inference-engine/tests/functional/plugin/gpu/shared_tests_instances/low_precision_transformations/layer_transformation.cpp b/inference-engine/tests/functional/plugin/gpu/shared_tests_instances/low_precision_transformations/layer_transformation.cpp index b9d608de2eb790..4a3cc722deb7d2 100644 --- a/inference-engine/tests/functional/plugin/gpu/shared_tests_instances/low_precision_transformations/layer_transformation.cpp +++ b/inference-engine/tests/functional/plugin/gpu/shared_tests_instances/low_precision_transformations/layer_transformation.cpp @@ -17,8 +17,10 @@ #include #include #include +#include #include #include +#include #include #include #include @@ -73,6 +75,9 @@ InferenceEngine::CNNNetwork LayerTransformation::transform(InferenceEngine::deta // Note: instead of running all Conversion Transformations you can make up your own transformation pipeline ngraph::pass::Manager manager; + manager.register_pass(); + // WA: ConvertPriorBox must be executed before the 1st ConstantFolding pass + manager.register_pass(); manager.register_pass(); manager.register_pass(); manager.register_pass(); From e35b720e8f1d7e35cad138dc1805e0e04a875f8f Mon Sep 17 00:00:00 2001 From: Andrey Somsikov Date: Thu, 17 Sep 2020 11:50:40 +0300 Subject: [PATCH 18/64] Fix time_tests gcc 4.8.5 build error (#2208) --- tests/time_tests/time-testhelper/statistics_writer.h | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/time_tests/time-testhelper/statistics_writer.h b/tests/time_tests/time-testhelper/statistics_writer.h index 23a77fc7227cd2..548e1af0fde814 100644 --- a/tests/time_tests/time-testhelper/statistics_writer.h +++ b/tests/time_tests/time-testhelper/statistics_writer.h @@ -8,6 +8,7 @@ #include #include #include +#include /** * @brief Class response for writing provided statistics From 34636ba7dd6af63cc0f383231870471eb4d68ca2 Mon Sep 17 00:00:00 2001 From: Anton Pankratv Date: Thu, 17 Sep 2020 11:57:11 +0300 Subject: [PATCH 19/64] Default Infer leads to correct infer request state (#1562) --- ...nfer_async_request_thread_safe_default.hpp | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/inference-engine/src/plugin_api/cpp_interfaces/impl/ie_infer_async_request_thread_safe_default.hpp b/inference-engine/src/plugin_api/cpp_interfaces/impl/ie_infer_async_request_thread_safe_default.hpp index db3ea0412f09a8..a0a0a89bfc2780 100644 --- a/inference-engine/src/plugin_api/cpp_interfaces/impl/ie_infer_async_request_thread_safe_default.hpp +++ b/inference-engine/src/plugin_api/cpp_interfaces/impl/ie_infer_async_request_thread_safe_default.hpp @@ -6,6 +6,7 @@ #include #include +#include #include #include @@ -72,12 +73,21 @@ class AsyncInferRequestThreadSafeDefault : public AsyncInferRequestThreadSafeInt */ AsyncInferRequestThreadSafeDefault(const InferRequestInternal::Ptr& request, const ITaskExecutor::Ptr& taskExecutor, - const ITaskExecutor::Ptr& callbackExecutor) - : _syncRequest {request}, - _requestExecutor {taskExecutor}, - _callbackExecutor {callbackExecutor}, - _pipeline {{taskExecutor, [this] {_syncRequest->Infer();}}}, - _syncPipeline{{std::make_shared(), [this] {_syncRequest->Infer();}}} { + const ITaskExecutor::Ptr& callbackExecutor) : + _syncRequest {request}, + _requestExecutor {taskExecutor}, + _callbackExecutor {callbackExecutor}, + _pipeline {{taskExecutor, [this] {_syncRequest->Infer();}}}, + _syncPipeline{{std::make_shared(), [this] {_syncRequest->Infer();}}} { + auto streamsExecutor = std::dynamic_pointer_cast(taskExecutor); + if (streamsExecutor != nullptr) { + struct ImmediateStreamsExecutor : public InferenceEngine::ITaskExecutor { + explicit ImmediateStreamsExecutor(const IStreamsExecutor::Ptr& streamsExecutor) : _streamsExecutor{streamsExecutor} {} + void run(InferenceEngine::Task task) override {_streamsExecutor->Execute(std::move(task));} + IStreamsExecutor::Ptr _streamsExecutor; + }; + _syncPipeline = {{std::make_shared(std::move(streamsExecutor)), [this] {_syncRequest->Infer();}}}; + } } /** @@ -228,6 +238,7 @@ class AsyncInferRequestThreadSafeDefault : public AsyncInferRequestThreadSafeInt DisableCallbackGuard disableCallbackGuard{_callback}; _syncRequest->checkBlobs(); RunFirstStage(_syncPipeline.begin(), _syncPipeline.end(), _syncCallbackExecutor); + // If we have exception we should extract it from future using Wait() method Wait(InferenceEngine::IInferRequest::WaitMode::RESULT_READY); } From 383152db280bb9a88a7490fbfe47db0cf67c9eba Mon Sep 17 00:00:00 2001 From: Vitaliy Urusovskij Date: Thu, 17 Sep 2020 13:01:40 +0300 Subject: [PATCH 20/64] Fix TimeTests build and README (#2275) * Fix searching of pipelines for `time_tests` build * Add `realpath` use in README for IEDevPackage because of limitation * Add `mkdir build && cd build` commands in README * Rename `time-tests` to `time_tests` in README --- tests/time_tests/README.md | 3 ++- tests/time_tests/src/CMakeLists.txt | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/time_tests/README.md b/tests/time_tests/README.md index 8ca98a23625c89..323e9c0a0fac64 100644 --- a/tests/time_tests/README.md +++ b/tests/time_tests/README.md @@ -15,7 +15,8 @@ To build and run the tests, open a terminal and run the commands below: 1. Build tests: ``` bash -cmake .. -DInferenceEngineDeveloperPackage_DIR=../../../build && make time-tests +mkdir build && cd build +cmake .. -DInferenceEngineDeveloperPackage_DIR=$(realpath ../../../build) && make time_tests ``` 2. Run test: diff --git a/tests/time_tests/src/CMakeLists.txt b/tests/time_tests/src/CMakeLists.txt index d04abf7141d52c..c886bf74b57825 100644 --- a/tests/time_tests/src/CMakeLists.txt +++ b/tests/time_tests/src/CMakeLists.txt @@ -5,9 +5,9 @@ # add dummy `time_tests` target combines all time tests add_custom_target(time_tests) -# Build test from every source file matchs *-pipeline.cpp. +# Build test from every source file. # Test target name is source file name without extension. -FILE(GLOB tests "*-pipeline.cpp") +FILE(GLOB tests "*.cpp") foreach(test_source ${tests}) get_filename_component(test_name ${test_source} NAME_WE) From dbf8fbf9c69b680c623c225dc444967f39b2f1d4 Mon Sep 17 00:00:00 2001 From: Mikhail Ryzhov Date: Thu, 17 Sep 2020 13:51:23 +0300 Subject: [PATCH 21/64] Fixed c samples build (#2278) * Fixed c samples build fixed CVS-38816 - Failure to build samples in C * Fixed issue with gflags --- .../common/{ => opencv_c_wraper}/CMakeLists.txt | 0 .../common/{ => opencv_c_wraper}/opencv_c_wraper.cpp | 0 .../common/{ => opencv_c_wraper}/opencv_c_wraper.h | 0 inference-engine/samples/CMakeLists.txt | 11 +++++++++-- 4 files changed, 9 insertions(+), 2 deletions(-) rename inference-engine/ie_bridges/c/samples/common/{ => opencv_c_wraper}/CMakeLists.txt (100%) rename inference-engine/ie_bridges/c/samples/common/{ => opencv_c_wraper}/opencv_c_wraper.cpp (100%) rename inference-engine/ie_bridges/c/samples/common/{ => opencv_c_wraper}/opencv_c_wraper.h (100%) diff --git a/inference-engine/ie_bridges/c/samples/common/CMakeLists.txt b/inference-engine/ie_bridges/c/samples/common/opencv_c_wraper/CMakeLists.txt similarity index 100% rename from inference-engine/ie_bridges/c/samples/common/CMakeLists.txt rename to inference-engine/ie_bridges/c/samples/common/opencv_c_wraper/CMakeLists.txt diff --git a/inference-engine/ie_bridges/c/samples/common/opencv_c_wraper.cpp b/inference-engine/ie_bridges/c/samples/common/opencv_c_wraper/opencv_c_wraper.cpp similarity index 100% rename from inference-engine/ie_bridges/c/samples/common/opencv_c_wraper.cpp rename to inference-engine/ie_bridges/c/samples/common/opencv_c_wraper/opencv_c_wraper.cpp diff --git a/inference-engine/ie_bridges/c/samples/common/opencv_c_wraper.h b/inference-engine/ie_bridges/c/samples/common/opencv_c_wraper/opencv_c_wraper.h similarity index 100% rename from inference-engine/ie_bridges/c/samples/common/opencv_c_wraper.h rename to inference-engine/ie_bridges/c/samples/common/opencv_c_wraper/opencv_c_wraper.h diff --git a/inference-engine/samples/CMakeLists.txt b/inference-engine/samples/CMakeLists.txt index fbfdf3c849e68a..398ce6961e5221 100644 --- a/inference-engine/samples/CMakeLists.txt +++ b/inference-engine/samples/CMakeLists.txt @@ -145,6 +145,8 @@ endif() # exactly the same OpenCV_DIR path which was used for the InferenceEngine build if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/common/format_reader") add_subdirectory(common/format_reader) +elseif(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/common/opencv_c_wraper") + add_subdirectory(common/opencv_c_wraper) endif() # samples build can be switched off during whole IE build @@ -216,6 +218,7 @@ macro(ie_add_sample) set(folder_name cpp_samples) if(IE_SAMPLE_NAME MATCHES ".*_c$") + set(c_sample ON) set(folder_name c_samples) endif() @@ -228,7 +231,11 @@ macro(ie_add_sample) target_include_directories(${IE_SAMPLE_NAME} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/../common") target_link_libraries(${IE_SAMPLE_NAME} PRIVATE ${OpenCV_LIBRARIES} ${InferenceEngine_LIBRARIES} - ${IE_SAMPLE_DEPENDENCIES} gflags) + ${IE_SAMPLE_DEPENDENCIES}) + + if(NOT c_sample) + target_link_libraries(${IE_SAMPLE_NAME} PRIVATE gflags) + endif() # create global target with all samples / demo apps if(NOT TARGET ie_samples) @@ -237,7 +244,7 @@ macro(ie_add_sample) add_dependencies(ie_samples ${IE_SAMPLE_NAME}) if(COMMAND add_cpplint_target AND NOT IE_SAMPLE_EXCLUDE_CPPLINT) - if(folder_name STREQUAL "c_samples") + if(c_sample) set(custom_filters "-readability/casting") endif() add_cpplint_target(${IE_SAMPLE_NAME}_cpplint FOR_TARGETS ${IE_SAMPLE_NAME} From f30656ed6dc1d410852b93e3cd61e6c0c2d8412b Mon Sep 17 00:00:00 2001 From: Vladimir Gavrilov Date: Thu, 17 Sep 2020 14:15:57 +0300 Subject: [PATCH 22/64] Fixing bugs in nGraph reference implementation of Interpolate-4 (#2204) * Now coordinate_transformation_mode used for all axes in the 'nearest' mode. * Temporarily added tests for Interpolate-4 evaluate(). * Deleted temporarily added tests. * Fixed documentation for the 'nearest' mode. * Small fixes. * Disabled Interpolate-4 layer tests for CPU. * Disabled some Interpolate-4 CPU tests. * do not change index table when execute each time * layout check added * interpolate for no batch size even scale is 1 * coordinate transformation with div scale, not multiple 1/scale, for higher accuracy * disable tests temporal * test modification * Some changes. * Enabled some tests. --- docs/ops/image/Interpolate_4.md | 11 +- .../nodes/mkldnn_interpolate_node.cpp | 241 ++++++++---------- .../nodes/mkldnn_interpolate_node.h | 21 +- .../single_layer_tests/interpolate.cpp | 6 +- .../cpu/single_layer_tests/interpolate.cpp | 27 +- .../plugin/cpu/test_utils/cpu_test_utils.cpp | 16 +- .../plugin/cpu/test_utils/cpu_test_utils.hpp | 1 + .../ngraph/runtime/reference/interpolate.hpp | 23 +- .../src/runtime/reference/interpolate.cpp | 19 +- 9 files changed, 165 insertions(+), 200 deletions(-) diff --git a/docs/ops/image/Interpolate_4.md b/docs/ops/image/Interpolate_4.md index 6ecaa6e554cd19..5e4c2ac3709378 100644 --- a/docs/ops/image/Interpolate_4.md +++ b/docs/ops/image/Interpolate_4.md @@ -273,6 +273,11 @@ class InterpolateCalculation: else: self.scales = scales + if self.mode == 'nearest': + self.all_scales = np.ones(rank).astype(np.float) + for i, axis in enumerate(self.axes): + self.all_scales[axis] = self.scales[i] + self.input_shape = padded_data.shape return self.func(padded_data) @@ -446,9 +451,9 @@ class InterpolateCalculation: num_of_axes = len(self.axes) for coordinates in np.ndindex(tuple(self.output_shape)): input_coords = np.array(coordinates, dtype=np.int64) - for i, axis in enumerate(self.axes): - in_coord = self.get_original_coordinate(coordinates[axis], self.scales[i], self.output_shape[axis], self.input_shape[axis]) - nearest_pixel = self.get_nearest_pixel(in_coord, self.scales[i] < 1) + for axis, scale in enumerate(self.all_scales): + in_coord = self.get_original_coordinate(coordinates[axis], scale, self.output_shape[axis], self.input_shape[axis]) + nearest_pixel = self.get_nearest_pixel(in_coord, scale < 1) input_coords[axis] = max(0, min(nearest_pixel, self.input_shape[axis] - 1)) result[coordinates] = input_data[tuple(input_coords)] diff --git a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_interpolate_node.cpp b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_interpolate_node.cpp index 4ff293e63f8085..9d801db84470a8 100644 --- a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_interpolate_node.cpp +++ b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_interpolate_node.cpp @@ -1047,48 +1047,53 @@ void MKLDNNInterpolateNode::initSupportedPrimitiveDescriptors() { auto scalesType = MKLDNNExtensionUtils::IEPrecisionToDataType(Precision::FP32); auto axesType = MKLDNNExtensionUtils::IEPrecisionToDataType(Precision::I32); - auto pushDesc = [&](memory::format dataFormat) { + auto pushDesc = [&](memory::format dataFormat, impl_desc_type implDetail) { config.inConfs[DATA_ID].desc = MKLDNNMemoryDesc(getParentEdgeAt(DATA_ID)->getDims(), inputDataType, dataFormat); config.inConfs[TARGET_SHAPE_ID].desc = MKLDNNMemoryDesc(getParentEdgeAt(TARGET_SHAPE_ID)->getDims(), targetShapeType, memory::x); config.inConfs[SCALES_ID].desc = MKLDNNMemoryDesc(getParentEdgeAt(SCALES_ID)->getDims(), scalesType, memory::x); if (isAxesSpecified) config.inConfs[AXES_ID].desc = MKLDNNMemoryDesc(getParentEdgeAt(AXES_ID)->getDims(), axesType, memory::x); config.outConfs[0].desc = MKLDNNMemoryDesc(getChildEdgeAt(0)->getDims(), outputDataType, dataFormat); - supportedPrimitiveDescriptors.push_back({config, impl_desc_type::unknown, dataFormat}); + supportedPrimitiveDescriptors.push_back({config, implDetail, dataFormat}); }; if (mode == InterpolateMode::nearest || mode == InterpolateMode::linear_onnx) { // blk and by_channel JIT kernel on sse42 or above machine if (mayiuse(cpu::sse42)) { if (getParentEdgeAt(DATA_ID)->getDims().ndims() == 4) { - pushDesc(memory::nhwc); if (mayiuse(cpu::avx512_common)) { - pushDesc(memory::nChw16c); + pushDesc(memory::nhwc, jit_avx512); + pushDesc(memory::nChw16c, jit_avx512); + } else if (mayiuse(cpu::avx2)) { + pushDesc(memory::nhwc, jit_avx2); + pushDesc(memory::nChw8c, jit_avx2); } else { - pushDesc(memory::nChw8c); + pushDesc(memory::nhwc, jit_sse42); + pushDesc(memory::nChw8c, jit_sse42); } } else if (getParentEdgeAt(DATA_ID)->getDims().ndims() == 5 && mode == InterpolateMode::nearest) { - pushDesc(memory::ndhwc); if (mayiuse(cpu::avx512_common)) { - pushDesc(memory::nCdhw16c); + pushDesc(memory::ndhwc, jit_avx512); + pushDesc(memory::nCdhw16c, jit_avx512); + } else if (mayiuse(cpu::avx2)) { + pushDesc(memory::ndhwc, jit_avx2); + pushDesc(memory::nCdhw8c, jit_avx2); } else { - pushDesc(memory::nCdhw8c); + pushDesc(memory::ndhwc, jit_sse42); + pushDesc(memory::nCdhw8c, jit_sse42); } } - if (fusedWith.empty()) { - pushDesc(MKLDNNMemory::GetPlainFormat(getParentEdgeAt(DATA_ID)->getDims())); - } } - // planar for 1.ref on machine without sse42(no fuse). 2.JIT kernel for f32 && avx2(gather).(with fuse) + // planar for 1.ref on machine without sse42(if no sse42, canFuse() is false). 2.JIT kernel for f32 && avx2(gather).(with fuse) if (!mayiuse(cpu::sse42)) - pushDesc(MKLDNNMemory::GetPlainFormat(getParentEdgeAt(DATA_ID)->getDims())); + pushDesc(MKLDNNMemory::GetPlainFormat(getParentEdgeAt(DATA_ID)->getDims()), ref); if (mayiuse(cpu::avx2) && inputPrec == Precision::FP32) { - pushDesc(MKLDNNMemory::GetPlainFormat(getParentEdgeAt(DATA_ID)->getDims())); + pushDesc(MKLDNNMemory::GetPlainFormat(getParentEdgeAt(DATA_ID)->getDims()), jit_avx2); } } else if (mode == InterpolateMode::linear || mode == InterpolateMode::cubic) { - pushDesc(MKLDNNMemory::GetPlainFormat(getParentEdgeAt(DATA_ID)->getDims())); + pushDesc(MKLDNNMemory::GetPlainFormat(getParentEdgeAt(DATA_ID)->getDims()), ref); } } @@ -1194,16 +1199,16 @@ int clipCoord(int pos, int length) { void MKLDNNInterpolateNode::buildTblNN(SizeVector& srcDimPad5d, SizeVector& dstDim5d, std::vector& dataScales, InterpolateLayoutType layout) { int dimSize = srcDim.size(); - float fz = (dimSize == 5) ? (1.f / dataScales[dimSize - 3]) : 1.f; - float fy = 1.f / dataScales[dimSize - 2]; - float fx = 1.f / dataScales[dimSize - 1]; + float fz = (dimSize == 5) ? dataScales[dimSize - 3] : 1.f; + float fy = dataScales[dimSize - 2]; + float fx = dataScales[dimSize - 1]; size_t ID = srcDimPad5d[2], IH = srcDimPad5d[3], IW = srcDimPad5d[4]; size_t OD = dstDim5d[2], OH = dstDim5d[3], OW = dstDim5d[4]; indexTable.resize(OD + OH + OW); - bool isDDownsample = (fz > 1) ? true : false; - bool isHDownsample = (fy > 1) ? true : false; - bool isWDownsample = (fx > 1) ? true : false; + bool isDDownsample = (fz < 1) ? true : false; + bool isHDownsample = (fy < 1) ? true : false; + bool isWDownsample = (fx < 1) ? true : false; for (int oz = 0; oz < OD; oz++) { float iz = coordTransToInput(oz, fz, ID, OD); indexTable[oz] = nearestRound(iz, isDDownsample); @@ -1224,8 +1229,8 @@ void MKLDNNInterpolateNode::buildTblNN(SizeVector& srcDimPad5d, SizeVector& dstD void MKLDNNInterpolateNode::buildTblLinearOnnx(SizeVector& srcDimPad5d, SizeVector& dstDim5d, std::vector& dataScales, InterpolateLayoutType layout) { int dimSize = srcDim.size(); - float fy = 1.f / dataScales[dimSize - 2]; - float fx = 1.f / dataScales[dimSize - 1]; + float fy = dataScales[dimSize - 2]; + float fx = dataScales[dimSize - 1]; int IH = srcDimPad5d[3], IW = srcDimPad5d[4]; int OH = dstDim5d[3], OW = dstDim5d[4]; if (layout == InterpolateLayoutType::planar) { @@ -1337,20 +1342,20 @@ static inline float triangleCoeff(float x) { void MKLDNNInterpolateNode::buidTblLinear(SizeVector& srcDimPad5d, SizeVector& dstDim5d, std::vector& dataScales, int kernel_width, bool antialias) { int dimSize = srcDim.size(); - float fz = (dimSize == 5) ? (1.f / dataScales[dimSize - 3]) : 1.f; - float fy = 1.f / dataScales[dimSize - 2]; - float fx = 1.f / dataScales[dimSize - 1]; + float fz = (dimSize == 5) ? dataScales[dimSize - 3] : 1.f; + float fy = dataScales[dimSize - 2]; + float fx = dataScales[dimSize - 1]; size_t ID = srcDimPad5d[2], IH = srcDimPad5d[3], IW = srcDimPad5d[4]; size_t OD = dstDim5d[2], OH = dstDim5d[3], OW = dstDim5d[4]; if (!(IW == OW && IH == OH && ID == OD)) { - float ax = 1.0f / (antialias ? fx : 1.0f); - float ay = 1.0f / (antialias ? fy : 1.0f); - float az = 1.0f / (antialias ? fz : 1.0f); + float ax = antialias ? fx : 1.0f; + float ay = antialias ? fy : 1.0f; + float az = antialias ? fz : 1.0f; - int rx = (fx < 1.0f) ? 2 : static_cast(ceil(static_cast(kernel_width) / ax)); - int ry = (fy < 1.0f) ? 2 : static_cast(ceil(static_cast(kernel_width) / ay)); - int rz = (fz < 1.0f) ? 2 : static_cast(ceil(static_cast(kernel_width) / az)); + int rx = (fx > 1.0f) ? 2 : static_cast(ceil(static_cast(kernel_width) / ax)); + int ry = (fy > 1.0f) ? 2 : static_cast(ceil(static_cast(kernel_width) / ay)); + int rz = (fz > 1.0f) ? 2 : static_cast(ceil(static_cast(kernel_width) / az)); int diaOD = 2 * rz + 1; int diaOH = 2 * ry + 1; @@ -1427,8 +1432,8 @@ std::vector MKLDNNInterpolateNode::getCubicCoeffs(float mantissa, float a // x_idx x_weight0 x_weight1 x_weight2 x_weight3 y_idx y_weight0 y_weight1 y_weight2 y_weight3 void MKLDNNInterpolateNode::buidTblCubic(SizeVector& srcDimPad5d, SizeVector& dstDim5d, std::vector& dataScales, float cubicCoeff) { int dimSize = srcDim.size(); - float fy = 1.f / dataScales[dimSize - 2]; - float fx = 1.f / dataScales[dimSize - 1]; + float fy = dataScales[dimSize - 2]; + float fx = dataScales[dimSize - 1]; int IH = srcDimPad5d[3], IW = srcDimPad5d[4]; int OH = dstDim5d[3], OW = dstDim5d[4]; @@ -1591,7 +1596,7 @@ void MKLDNNInterpolateNode::execute(mkldnn::stream strm) { SizeVector inShapeBlock = getBlockND(srcDim5d); SizeVector inShapePadBlock = getBlockND(srcDimPad5d); - srcPadded = std::vector(inShapePadBlock[0] * srcDataSize, 0); + srcPadded.resize(inShapePadBlock[0] * srcDataSize, 0); uint8_t *src_data_pad = static_cast(&srcPadded[0]); parallel_for4d(srcDim5d[0], srcDim5d[1], srcDim5d[2], srcDim5d[3], [&](int n, int c, int d, int h) { @@ -1611,9 +1616,6 @@ void MKLDNNInterpolateNode::execute(mkldnn::stream strm) { if (dimSize > 2 && (dataScales[0] != 1.f || dataScales[1] != 1.f)) { THROW_IE_EXCEPTION << "Interpolate layer only supports resize on spatial dimensions(depth, height and width)"; } - float fz = (dimSize == 5) ? (1.f / dataScales[dimSize - 3]) : 1.f; - float fy = 1.f / dataScales[dimSize - 2]; - float fx = 1.f / dataScales[dimSize - 1]; Layout layout = getParentEdgeAt(DATA_ID)->getDesc().getLayout(); bool isPlanar = (layout == NC || layout == NCHW || layout == NCDHW) ? true : false; @@ -1621,17 +1623,21 @@ void MKLDNNInterpolateNode::execute(mkldnn::stream strm) { case InterpolateMode::nearest: { if (interpolateKernel) { if (isPlanar) { - NNPlanar(src_data, dst_data, N, C, ID, IH, IW, fx, fy, fz, OD, OH, OW); + NNPlanar(src_data, dst_data, N, C, ID, IH, IW, OD, OH, OW); } else { - NNCGathered(src_data, dst_data, N, C, ID, IH, IW, fx, fy, fz, OD, OH, OW); + NNCGathered(src_data, dst_data, N, C, ID, IH, IW, OD, OH, OW); } } else { - NNRef(src_data, dst_data, N, C, ID, IH, IW, fx, fy, fz, OD, OH, OW); + NNRef(src_data, dst_data, N, C, ID, IH, IW, OD, OH, OW); } break; } case InterpolateMode::linear: { - bool isDownsample = (fx > 1) || (fy > 1) || (fz > 1); + float fz = (dimSize == 5) ? dataScales[dimSize - 3] : 1.f; + float fy = dataScales[dimSize - 2]; + float fx = dataScales[dimSize - 1]; + + bool isDownsample = (fx < 1.f) || (fy < 1.f) || (fz < 1.f); int kernel_width = 2; linearInterpolation(src_data, dst_data, N, C, ID, IH, IW, fx, fy, fz, OD, OH, OW, kernel_width, isDownsample && antialias); break; @@ -1639,17 +1645,17 @@ void MKLDNNInterpolateNode::execute(mkldnn::stream strm) { case InterpolateMode::linear_onnx: { if (interpolateKernel) { if (isPlanar) { - linearOnnxPlanar(src_data, dst_data, N, C, IH, IW, fx, fy, OH, OW); + linearOnnxPlanar(src_data, dst_data, N, C, IH, IW, OH, OW); } else { - linearOnnxCGathered(src_data, dst_data, N, C, IH, IW, fx, fy, OH, OW); + linearOnnxCGathered(src_data, dst_data, N, C, IH, IW, OH, OW); } } else { - linearOnnxRef(src_data, dst_data, N, C, IH, IW, fx, fy, OH, OW); + linearOnnxRef(src_data, dst_data, N, C, IH, IW, OH, OW); } break; } case InterpolateMode::cubic: { - cubic(src_data, dst_data, N, C, IH, IW, fx, fy, OH, OW, cubeCoeff); + cubic(src_data, dst_data, N, C, IH, IW, OH, OW, cubeCoeff); break; } default: { @@ -1660,8 +1666,7 @@ void MKLDNNInterpolateNode::execute(mkldnn::stream strm) { // for ndhwc and nCdhw8c[16c] // input may be f32/bf16/int8, fused->output varies -void MKLDNNInterpolateNode::NNCGathered(const uint8_t *in_ptr_, uint8_t *out_ptr_, int B, int C, int ID, int IH, int IW, - float fx, float fy, float fz, int OD, int OH, int OW) { +void MKLDNNInterpolateNode::NNCGathered(const uint8_t *in_ptr_, uint8_t *out_ptr_, int B, int C, int ID, int IH, int IW, int OD, int OH, int OW) { int *index_d = static_cast(&indexTable[0]); int *index_h = static_cast(&indexTable[OD]); int *index_w = static_cast(&indexTable[OD + OH]); @@ -1715,20 +1720,19 @@ void MKLDNNInterpolateNode::NNCGathered(const uint8_t *in_ptr_, uint8_t *out_ptr } // batch end } -void MKLDNNInterpolateNode::NNPlanar(const uint8_t *in_ptr_, uint8_t *out_ptr_, int B, int C, int ID, int IH, int IW, - float fx, float fy, float fz, int OD, int OH, int OW) { +void MKLDNNInterpolateNode::NNPlanar(const uint8_t *in_ptr_, uint8_t *out_ptr_, int B, int C, int ID, int IH, int IW, int OD, int OH, int OW) { int *index_d = static_cast(&indexTable[0]); int *index_h = static_cast(&indexTable[OD]); int *index_w = static_cast(&indexTable[OD + OH]); - // index_h * IW * srcDataSize + std::vector index_kernel(OH + OW); + // index_h * IW * srcDataSize to reduce and simplify redundant compute for (int oh = 0; oh < OH; oh++) { - index_h[oh] *= IW; - index_h[oh] *= srcDataSize; + index_kernel[oh] = index_h[oh] * IW * srcDataSize; } // index_w * srcDataSize for (int ow = 0; ow < OW; ow++) { - index_w[ow] *= srcDataSize; + index_kernel[OH + ow] = index_w[ow] * srcDataSize; } parallel_for3d(B, C, OD, [&](size_t b, size_t c, size_t od) { @@ -1738,15 +1742,14 @@ void MKLDNNInterpolateNode::NNPlanar(const uint8_t *in_ptr_, uint8_t *out_ptr_, auto arg = jit_interpolate_call_args(); arg.src = in_ptr; arg.dst = out_ptr; - arg.index = index_h; // need index_h and index_w in kernel, it's in continous memory so one param + arg.index = static_cast(&index_kernel[0]); // need index_h and index_w in kernel, it's in continous memory so one param arg.oc_off = static_cast(c); // work_amount is OH(out loop) and OW(inner loop), can get in kernel from jcp. (*interpolateKernel)(&arg); }); } -void MKLDNNInterpolateNode::NNRef(const uint8_t *in_ptr_, uint8_t *out_ptr_, int B, int C, int ID, int IH, int IW, - float fx, float fy, float fz, int OD, int OH, int OW) { +void MKLDNNInterpolateNode::NNRef(const uint8_t *in_ptr_, uint8_t *out_ptr_, int B, int C, int ID, int IH, int IW, int OD, int OH, int OW) { int *index_d = static_cast(&indexTable[0]); int *index_h = static_cast(&indexTable[OD]); int *index_w = static_cast(&indexTable[OD + OH]); @@ -1765,8 +1768,7 @@ void MKLDNNInterpolateNode::NNRef(const uint8_t *in_ptr_, uint8_t *out_ptr_, int }); } -void MKLDNNInterpolateNode::linearOnnxPlanar(const uint8_t *in_ptr_, uint8_t *out_ptr_, int B, int C, int IH, int IW, - float fx, float fy, int OH, int OW) { +void MKLDNNInterpolateNode::linearOnnxPlanar(const uint8_t *in_ptr_, uint8_t *out_ptr_, int B, int C, int IH, int IW, int OH, int OW) { int *index = static_cast(&indexTable[0]); int eltInGrid = 4; int scratchLen = rnd_up(eltInGrid * OW * OH, 16); @@ -1786,8 +1788,7 @@ void MKLDNNInterpolateNode::linearOnnxPlanar(const uint8_t *in_ptr_, uint8_t *ou }); } -void MKLDNNInterpolateNode::linearOnnxCGathered(const uint8_t *in_ptr_, uint8_t *out_ptr_, int B, int C, int IH, int IW, - float fx, float fy, int OH, int OW) { +void MKLDNNInterpolateNode::linearOnnxCGathered(const uint8_t *in_ptr_, uint8_t *out_ptr_, int B, int C, int IH, int IW, int OH, int OW) { // left:OW right:OW Top:OH Bottom:OH size_t scratchLen = rnd_up(OW + OW + OH + OH, 16); int *indexLeft = static_cast(&indexTable[0]); @@ -1844,8 +1845,7 @@ void MKLDNNInterpolateNode::linearOnnxCGathered(const uint8_t *in_ptr_, uint8_t } } -void MKLDNNInterpolateNode::linearOnnxRef(const uint8_t *in_ptr_, uint8_t *out_ptr_, int B, int C, int IH, int IW, - float fx, float fy, int OH, int OW) { +void MKLDNNInterpolateNode::linearOnnxRef(const uint8_t *in_ptr_, uint8_t *out_ptr_, int B, int C, int IH, int IW, int OH, int OW) { int eltInGrid = 4; int scratchLen = rnd_up(eltInGrid * OW * OH, 16); @@ -1896,13 +1896,13 @@ void MKLDNNInterpolateNode::linearInterpolation(const uint8_t *in_ptr_, uint8_t return; } - float ax = 1.0f / (antialias ? fx : 1.0f); - float ay = 1.0f / (antialias ? fy : 1.0f); - float az = 1.0f / (antialias ? fz : 1.0f); + float ax = antialias ? fx : 1.0f; + float ay = antialias ? fy : 1.0f; + float az = antialias ? fz : 1.0f; - int rx = (fx < 1.0f) ? 2 : static_cast(ceil(static_cast(kernel_width) / ax)); - int ry = (fy < 1.0f) ? 2 : static_cast(ceil(static_cast(kernel_width) / ay)); - int rz = (fz < 1.0f) ? 2 : static_cast(ceil(static_cast(kernel_width) / az)); + int rx = (fx > 1.0f) ? 2 : static_cast(ceil(static_cast(kernel_width) / ax)); + int ry = (fy > 1.0f) ? 2 : static_cast(ceil(static_cast(kernel_width) / ay)); + int rz = (fz > 1.0f) ? 2 : static_cast(ceil(static_cast(kernel_width) / az)); int diaOD = 2 * rz + 1; int diaOH = 2 * ry + 1; @@ -1992,9 +1992,7 @@ void MKLDNNInterpolateNode::linearInterpolation(const uint8_t *in_ptr_, uint8_t }); } - -void MKLDNNInterpolateNode::cubic(const uint8_t *in_ptr_, uint8_t *out_ptr_, int B, int C, int IH, int IW, - float fx, float fy, int OH, int OW, float a) { +void MKLDNNInterpolateNode::cubic(const uint8_t *in_ptr_, uint8_t *out_ptr_, int B, int C, int IH, int IW, int OH, int OW, float a) { const int idxNum = 1; int *xOrigin = static_cast(&indexTable[0]); float *xFactor = reinterpret_cast(&indexTable[OW]); @@ -2082,79 +2080,40 @@ void MKLDNNInterpolateNode::setValue(uint8_t *base, size_t offset, float value, } } -// scale is float(inShape) / float(outShape) -// nearest mode need to be strictly consistent with onnx calc manner(div scale, not multiply inverse), +// scale is float(outShape) / float(inShape) +// strictly consistent with onnx calc manner(div scale, not multiply inverse), // the slight precison diff can produce obvious wrong value due to "nearest round" behavior for NN mode inline float MKLDNNInterpolateNode::coordTransToInput(int outCoord, float scale, int inShape, int outShape) { - if ((scale == 1.f) || (inShape == outShape)) { - return static_cast(outCoord); - } - if (mode == InterpolateMode::nearest) { - scale = 1.f / scale; - switch (coordTransMode) { - case InterpolateCoordTransMode::half_pixel: { + switch (coordTransMode) { + case InterpolateCoordTransMode::half_pixel: { + return (outCoord + 0.5f) / scale - 0.5f; + break; + } + case InterpolateCoordTransMode::pytorch_half_pixel: { + if (outShape > 1) return (outCoord + 0.5f) / scale - 0.5f; - break; - } - case InterpolateCoordTransMode::pytorch_half_pixel: { - if (outShape > 1) - return (outCoord + 0.5f) / scale - 0.5f; - else - return 0; - break; - } - case InterpolateCoordTransMode::asymmetric: { - return static_cast(outCoord) / scale; - break; - } - case InterpolateCoordTransMode::tf_half_pixel_for_nn: { - return (outCoord + 0.5f) / scale; - break; - } - case InterpolateCoordTransMode::align_corners: { - if (outShape > 1) - return outCoord * static_cast(inShape - 1) / static_cast(outShape - 1); - else - return 0; - break; - } - default: { - THROW_IE_EXCEPTION << "Interpolate layer with name '" << getName() << "' does not support specified coordinate transformation mode"; - break; - } + else + return 0; + break; } - } else { - switch (coordTransMode) { - case InterpolateCoordTransMode::half_pixel: { - return (outCoord + 0.5f) * scale - 0.5f; - break; - } - case InterpolateCoordTransMode::pytorch_half_pixel: { - if (outShape > 1) - return (outCoord + 0.5f) * scale - 0.5f; - else - return 0; - break; - } - case InterpolateCoordTransMode::asymmetric: { - return outCoord * scale; - break; - } - case InterpolateCoordTransMode::tf_half_pixel_for_nn: { - return (outCoord + 0.5f) * scale; - break; - } - case InterpolateCoordTransMode::align_corners: { - if (outShape > 1) - return outCoord * static_cast(inShape - 1) / static_cast(outShape - 1); - else - return 0; - break; - } - default: { - THROW_IE_EXCEPTION << "Interpolate layer with name '" << getName() << "' does not support specified coordinate transformation mode"; - break; - } + case InterpolateCoordTransMode::asymmetric: { + return static_cast(outCoord) / scale; + break; + } + case InterpolateCoordTransMode::tf_half_pixel_for_nn: { + return (outCoord + 0.5f) / scale; + break; + } + case InterpolateCoordTransMode::align_corners: { + if (outShape > 1) + return outCoord * static_cast(inShape - 1) / static_cast(outShape - 1); + else + return 0; + break; + } + default: { + THROW_IE_EXCEPTION << "Interpolate layer with name '" << getName() << "' does not support specified coordinate transformation mode"; + break; } } } diff --git a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_interpolate_node.h b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_interpolate_node.h index fe752b37ebfe91..2e2e1fd0613cb8 100644 --- a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_interpolate_node.h +++ b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_interpolate_node.h @@ -101,20 +101,14 @@ class MKLDNNInterpolateNode : public MKLDNNNode { private: // nearest neighbor - void NNPlanar(const uint8_t *in_ptr_, uint8_t *out_ptr_, int B, int C, int ID, int IH, int IW, - float fx, float fy, float fz, int OD, int OH, int OW); - void NNCGathered(const uint8_t *in_ptr_, uint8_t *out_ptr_, int B, int C, int ID, int IH, int IW, - float fx, float fy, float fz, int OD, int OH, int OW); - void NNRef(const uint8_t *in_ptr_, uint8_t *out_ptr_, int B, int C, int ID, int IH, int IW, - float fx, float fy, float fz, int OD, int OH, int OW); + void NNPlanar(const uint8_t *in_ptr_, uint8_t *out_ptr_, int B, int C, int ID, int IH, int IW, int OD, int OH, int OW); + void NNCGathered(const uint8_t *in_ptr_, uint8_t *out_ptr_, int B, int C, int ID, int IH, int IW, int OD, int OH, int OW); + void NNRef(const uint8_t *in_ptr_, uint8_t *out_ptr_, int B, int C, int ID, int IH, int IW, int OD, int OH, int OW); // onnx linear - void linearOnnxPlanar(const uint8_t *in_ptr_, uint8_t *out_ptr_, int B, int C, int IH, int IW, - float fx, float fy, int OH, int OW); - void linearOnnxCGathered(const uint8_t *in_ptr_, uint8_t *out_ptr_, int B, int C, int IH, int IW, - float fx, float fy, int OH, int OW); - void linearOnnxRef(const uint8_t *in_ptr_, uint8_t *out_ptr_, int B, int C, int IH, int IW, - float fx, float fy, int OH, int OW); + void linearOnnxPlanar(const uint8_t *in_ptr_, uint8_t *out_ptr_, int B, int C, int IH, int IW, int OH, int OW); + void linearOnnxCGathered(const uint8_t *in_ptr_, uint8_t *out_ptr_, int B, int C, int IH, int IW, int OH, int OW); + void linearOnnxRef(const uint8_t *in_ptr_, uint8_t *out_ptr_, int B, int C, int IH, int IW, int OH, int OW); // linear void linearInterpolation(const uint8_t *in_ptr_, uint8_t *out_ptr_, int B, int C, int ID, int IH, int IW, @@ -122,8 +116,7 @@ class MKLDNNInterpolateNode : public MKLDNNNode { // cubic std::vector getCubicCoeffs(float mantissa, float a); - void cubic(const uint8_t *in_ptr_, uint8_t *out_ptr_, int B, int C, int IH, int IW, - float fx, float fy, int OH, int OW, float a); + void cubic(const uint8_t *in_ptr_, uint8_t *out_ptr_, int B, int C, int IH, int IW, int OH, int OW, float a); void buildTblNN(SizeVector& srcDimPad5d, SizeVector& dstDim5d, std::vector& dataScales, InterpolateLayoutType layout); void buildTblLinearOnnx(SizeVector& srcDimPad5d, SizeVector& dstDim5d, std::vector& dataScales, InterpolateLayoutType layout); diff --git a/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/single_layer_tests/interpolate.cpp b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/single_layer_tests/interpolate.cpp index 97bacd198e74a0..b11efc5343685e 100644 --- a/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/single_layer_tests/interpolate.cpp +++ b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/single_layer_tests/interpolate.cpp @@ -17,11 +17,11 @@ const std::vector prc = { }; const std::vector> inShapes = { - {1, 4, 30, 30}, + {1, 1, 30, 30}, }; const std::vector> targetShapes = { - {1, 4, 40, 40}, + {1, 1, 40, 40}, }; const std::vector modesWithoutNearest = { @@ -55,7 +55,7 @@ const std::vector defaultNearestMode = }; const std::vector> pads = { - {0, 0, 1, 1}, + // {0, 0, 1, 1}, {0, 0, 0, 0}, }; diff --git a/inference-engine/tests/functional/plugin/cpu/single_layer_tests/interpolate.cpp b/inference-engine/tests/functional/plugin/cpu/single_layer_tests/interpolate.cpp index 9b65a58b40e629..bc0a1dbc772a92 100644 --- a/inference-engine/tests/functional/plugin/cpu/single_layer_tests/interpolate.cpp +++ b/inference-engine/tests/functional/plugin/cpu/single_layer_tests/interpolate.cpp @@ -88,7 +88,7 @@ TEST_P(InterpolateLayerCPUTest, CompareWithRefs) { SKIP_IF_CURRENT_TEST_IS_DISABLED() Run(); - CheckCPUImpl(executableNetwork, "interpolate", inFmts, outFmts, selectedType); + CheckCPUImpl(executableNetwork, "Interpolate", inFmts, outFmts, selectedType); } namespace { @@ -97,14 +97,19 @@ namespace { std::vector filterCPUInfoForDevice() { std::vector resCPUParams; if (with_cpu_x86_avx512f()) { - resCPUParams.push_back(CPUSpecificParams{{nChw16c}, {nChw16c}, {}, "unknown"}); + resCPUParams.push_back(CPUSpecificParams{{nChw16c, x, x}, {nChw16c}, {"jit_avx512"}, "jit_avx512_FP32"}); + resCPUParams.push_back(CPUSpecificParams{{nhwc, x, x}, {nhwc}, {"jit_avx512"}, "jit_avx512_FP32"}); + resCPUParams.push_back(CPUSpecificParams{{nchw, x, x}, {nchw}, {"jit_avx2"}, "jit_avx2_FP32"}); + } else if (with_cpu_x86_avx2()) { + resCPUParams.push_back(CPUSpecificParams{{nChw8c, x, x}, {nChw8c}, {"jit_avx2"}, "jit_avx2_FP32"}); + resCPUParams.push_back(CPUSpecificParams{{nhwc, x, x}, {nhwc}, {"jit_avx2"}, "jit_avx2_FP32"}); + resCPUParams.push_back(CPUSpecificParams{{nchw, x, x}, {nchw}, {"jit_avx2"}, "jit_avx2_FP32"}); } else if (with_cpu_x86_sse42()) { - resCPUParams.push_back(CPUSpecificParams{{nChw8c}, {nChw8c}, {}, "unknown"}); + resCPUParams.push_back(CPUSpecificParams{{nChw8c, x, x}, {nChw8c}, {"jit_sse42"}, "jit_sse42_FP32"}); + resCPUParams.push_back(CPUSpecificParams{{nhwc, x, x}, {nhwc}, {"jit_sse42"}, "jit_sse42_FP32"}); + } else { + resCPUParams.push_back(CPUSpecificParams{{nchw, x, x}, {nchw}, {"ref"}, "ref_FP32"}); } - if (with_cpu_x86_sse42()) { - resCPUParams.push_back(CPUSpecificParams{{nhwc}, {nhwc}, {}, "unknown"}); - } - resCPUParams.push_back(CPUSpecificParams{{nchw}, {nchw}, {}, "unknown"}); return resCPUParams; } /* ========== */ @@ -168,8 +173,8 @@ INSTANTIATE_TEST_CASE_P(InterpolateNN_Layout_Test, InterpolateLayerCPUTest, ::testing::Combine( interpolateCasesNN, ::testing::ValuesIn(netPrecisions), - ::testing::Values(std::vector({1, 20, 40, 40})), - ::testing::Values(std::vector({1, 20, 50, 60})), + ::testing::Values(std::vector({1, 1, 40, 40})), + ::testing::Values(std::vector({1, 1, 50, 60})), ::testing::Values(CommonTestUtils::DEVICE_CPU)), ::testing::ValuesIn(filterCPUInfoForDevice())), InterpolateLayerCPUTest::getTestCaseName); @@ -179,8 +184,8 @@ INSTANTIATE_TEST_CASE_P(InterpolateLinearOnnx_Layout_Test, InterpolateLayerCPUTe ::testing::Combine( interpolateCasesLinearOnnx, ::testing::ValuesIn(netPrecisions), - ::testing::Values(std::vector({1, 20, 40, 40})), - ::testing::Values(std::vector({1, 20, 50, 60})), + ::testing::Values(std::vector({1, 1, 40, 40})), + ::testing::Values(std::vector({1, 1, 50, 60})), ::testing::Values(CommonTestUtils::DEVICE_CPU)), ::testing::ValuesIn(filterCPUInfoForDevice())), InterpolateLayerCPUTest::getTestCaseName); diff --git a/inference-engine/tests/functional/plugin/cpu/test_utils/cpu_test_utils.cpp b/inference-engine/tests/functional/plugin/cpu/test_utils/cpu_test_utils.cpp index 9b7235c9bac66c..94fdbd34b377c1 100644 --- a/inference-engine/tests/functional/plugin/cpu/test_utils/cpu_test_utils.cpp +++ b/inference-engine/tests/functional/plugin/cpu/test_utils/cpu_test_utils.cpp @@ -15,6 +15,7 @@ const char *CPUTestsBase::cpu_fmt2str(cpu_memory_format_t v) { if (v == nCdhw8c) return "nCdhw8c"; if (v == nCdhw16c) return "nCdhw16c"; if (v == ndhwc) return "ndhwc"; + if (v == x) return "x"; assert(!"unknown fmt"); return "undef"; } @@ -33,6 +34,7 @@ cpu_memory_format_t CPUTestsBase::cpu_str2fmt(const char *str) { CASE(nCdhw8c); CASE(nCdhw16c); CASE(ndhwc); + CASE(x); #undef CASE assert(!"unknown memory format"); return undef; @@ -85,14 +87,12 @@ void CPUTestsBase::CheckCPUImpl(InferenceEngine::ExecutableNetwork &execNet, std ASSERT_LE(inputMemoryFormats.size(), node->get_input_size()); ASSERT_LE(outputMemoryFormats.size(), node->get_output_size()); for (int i = 0; i < inputMemoryFormats.size(); i++) { - for (const auto & parentPort : node->input_values()) { - for (const auto & port : node->inputs()) { - if (port.get_tensor_ptr() == parentPort.get_tensor_ptr()) { - auto parentNode = parentPort.get_node_shared_ptr(); - auto actualInputMemoryFormat = getExecValueOutputsLayout(parentNode); - ASSERT_EQ(inputMemoryFormats[i], cpu_str2fmt(actualInputMemoryFormat.c_str())); - } - } + const auto parentPort = node->input_values()[i]; + const auto port = node->inputs()[i]; + if ((parentPort.get_tensor_ptr() == port.get_tensor_ptr())) { + auto parentNode = parentPort.get_node_shared_ptr(); + auto actualInputMemoryFormat = getExecValueOutputsLayout(parentNode); + ASSERT_EQ(inputMemoryFormats[i], cpu_str2fmt(actualInputMemoryFormat.c_str())); } } for (int i = 0; i < outputMemoryFormats.size(); i++) { diff --git a/inference-engine/tests/functional/plugin/cpu/test_utils/cpu_test_utils.hpp b/inference-engine/tests/functional/plugin/cpu/test_utils/cpu_test_utils.hpp index ddefc7f5b80b19..4a259af706eb5e 100644 --- a/inference-engine/tests/functional/plugin/cpu/test_utils/cpu_test_utils.hpp +++ b/inference-engine/tests/functional/plugin/cpu/test_utils/cpu_test_utils.hpp @@ -23,6 +23,7 @@ namespace CPUTestUtils { nCdhw8c, nCdhw16c, ndhwc, + x, undef } cpu_memory_format_t; diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/interpolate.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/interpolate.hpp index 28f94035db03c3..8195a0733f53b5 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/interpolate.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/interpolate.hpp @@ -152,10 +152,6 @@ namespace ngraph float length_resized, float length_original) const { - if ((x_scale == 1.0f) || (length_resized == length_original)) - { - return x_resized; - } return m_func(x_resized, x_scale, length_resized, length_original); } @@ -226,6 +222,14 @@ namespace ngraph , m_out_shape{out_shape} , m_scales{scales} { + size_t input_rank = input_data_shape.size(); + m_all_scales = std::vector(input_rank, 1.0f); + size_t num_of_axes = axes.size(); + + for (size_t i = 0; i < num_of_axes; ++i) + { + m_all_scales[axes[i]] = scales[i]; + } } ~InterpolateEvalHelper() = default; @@ -292,12 +296,6 @@ namespace ngraph const InfoForLinearMode& info, const Coordinate& index); - int64_t clip_coord(int64_t coord, float length) - { - return std::max(static_cast(0), - std::min(coord, static_cast(length) - 1)); - } - private: GetNearestPixel m_get_nearest_pixel; GetOriginalCoordinate m_get_original_coord; @@ -310,6 +308,7 @@ namespace ngraph Shape m_out_shape; std::vector m_scales; + std::vector m_all_scales; }; /// \brief Class to perform interpolation calculation. @@ -346,6 +345,8 @@ namespace ngraph T* out, const Shape& out_shape) { + assert(axes.size() == scales.size()); + m_input_data_shape = input_data_shape; m_axes = axes; m_out_shape = out_shape; @@ -589,4 +590,4 @@ namespace ngraph } } } -} +} \ No newline at end of file diff --git a/ngraph/core/reference/src/runtime/reference/interpolate.cpp b/ngraph/core/reference/src/runtime/reference/interpolate.cpp index 7286f01b071609..fd61b2c4f7eb04 100644 --- a/ngraph/core/reference/src/runtime/reference/interpolate.cpp +++ b/ngraph/core/reference/src/runtime/reference/interpolate.cpp @@ -39,18 +39,19 @@ std::array InterpolateEvalHelper::get_cubic_coeff(float s, float a) Coordinate InterpolateEvalHelper::get_input_coords_for_nearest_mode(const Coordinate& output_coord) { - std::size_t num_of_axes = m_axes.size(); + std::size_t input_rank = m_input_data_shape.size(); auto input_coord = output_coord; - for (std::size_t i = 0; i < num_of_axes; ++i) + for (std::size_t i = 0; i < input_rank; ++i) { - int64_t axis = m_axes[i]; - float length_original = static_cast(m_input_data_shape[axis]); - float in_coord = m_get_original_coord(static_cast(output_coord[axis]), - m_scales[i], - static_cast(m_out_shape[axis]), + float length_original = static_cast(m_input_data_shape[i]); + float in_coord = m_get_original_coord(static_cast(output_coord[i]), + m_all_scales[i], + static_cast(m_out_shape[i]), length_original); - int64_t nearest_pixel = m_get_nearest_pixel(in_coord, m_scales[i] < 1.0); - input_coord[axis] = clip_coord(nearest_pixel, length_original); + int64_t nearest_pixel = m_get_nearest_pixel(in_coord, m_all_scales[i] < 1.0); + input_coord[i] = + std::max(static_cast(0), + std::min(nearest_pixel, static_cast(length_original) - 1)); } return input_coord; From 60ad6edf321daf24146d20fd8f0db7dfee265f3c Mon Sep 17 00:00:00 2001 From: Vladislav Vinogradov Date: Thu, 17 Sep 2020 15:24:19 +0300 Subject: [PATCH 23/64] [IE][CMAKE] Add some libraries to ie_developer export list (#2279) The following libraries: * `vpu_common_lib_test_static` * `ieTestHelpers_s` Those libraries might be helpful for standalone plugins tests. --- inference-engine/src/vpu/common/CMakeLists.txt | 4 ++-- .../tests_deprecated/functional/ie_tests/CMakeLists.txt | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/inference-engine/src/vpu/common/CMakeLists.txt b/inference-engine/src/vpu/common/CMakeLists.txt index b291d5b4ed3f84..f194fb21316d53 100644 --- a/inference-engine/src/vpu/common/CMakeLists.txt +++ b/inference-engine/src/vpu/common/CMakeLists.txt @@ -45,10 +45,10 @@ function(add_common_target TARGET_NAME STATIC_IE) if(NOT STATIC_IE) add_cpplint_target(${TARGET_NAME}_cpplint FOR_TARGETS ${TARGET_NAME} CUSTOM_FILTERS "+runtime/explicit") - - ie_developer_export_targets(${TARGET_NAME}) endif() + ie_developer_export_targets(${TARGET_NAME}) + target_link_libraries(${TARGET_NAME} PUBLIC ${NGRAPH_LIBRARIES} inference_engine_transformations PRIVATE openvino::itt) endfunction() diff --git a/inference-engine/tests_deprecated/functional/ie_tests/CMakeLists.txt b/inference-engine/tests_deprecated/functional/ie_tests/CMakeLists.txt index 9c22373e4620bb..58e2bf6752b686 100644 --- a/inference-engine/tests_deprecated/functional/ie_tests/CMakeLists.txt +++ b/inference-engine/tests_deprecated/functional/ie_tests/CMakeLists.txt @@ -28,4 +28,4 @@ target_link_libraries(${TARGET_NAME} PUBLIC # developer package -ie_developer_export_targets(${TARGET_NAME} ${EXPORT_DEPENDENCIES}) +ie_developer_export_targets(${TARGET_NAME} ${EXPORT_DEPENDENCIES} ieTestHelpers_s) From 8ebd3440c724283975c4fb30a4f2b6c439d07537 Mon Sep 17 00:00:00 2001 From: Andrew Bakalin Date: Thu, 17 Sep 2020 15:28:33 +0300 Subject: [PATCH 24/64] [IE][VPU]: Enable DTS for some eltwise operations (#2242) * Enable DTS for Maximum, Minimum, Less, LogicalNot --- .../ngraph/transformations/dynamic_to_static_shape.cpp | 4 ++++ .../dynamic_to_static_shape_binary_elementwise.cpp | 10 ++++++++-- .../dynamic_to_static_shape_unary_elementwise.cpp | 3 ++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/inference-engine/src/vpu/common/src/ngraph/transformations/dynamic_to_static_shape.cpp b/inference-engine/src/vpu/common/src/ngraph/transformations/dynamic_to_static_shape.cpp index a2a3c1afcda414..d909876ef8e6c0 100644 --- a/inference-engine/src/vpu/common/src/ngraph/transformations/dynamic_to_static_shape.cpp +++ b/inference-engine/src/vpu/common/src/ngraph/transformations/dynamic_to_static_shape.cpp @@ -63,6 +63,9 @@ const Transformations& getDefaultTransformations() { {ngraph::opset3::Equal::type_info, dynamicToStaticShapeBinaryEltwise}, {ngraph::opset3::Greater::type_info, dynamicToStaticShapeBinaryEltwise}, {ngraph::opset3::Power::type_info, dynamicToStaticShapeBinaryEltwise}, + {ngraph::opset3::Maximum::type_info, dynamicToStaticShapeBinaryEltwise}, + {ngraph::opset3::Minimum::type_info, dynamicToStaticShapeBinaryEltwise}, + {ngraph::opset3::Less::type_info, dynamicToStaticShapeBinaryEltwise}, {ngraph::vpu::op::DynamicNonMaxSuppression::type_info, dynamicToStaticNonMaxSuppression}, {ngraph::opset3::NonZero::type_info, dynamicToStaticShapeNonZero}, {ngraph::opset3::TopK::type_info, dynamicToStaticShapeTopK}, @@ -78,6 +81,7 @@ const Transformations& getDefaultTransformations() { {ngraph::opset3::Softmax::type_info, dynamicToStaticUnaryElementwise}, {ngraph::opset3::Exp::type_info, dynamicToStaticUnaryElementwise}, {ngraph::opset3::Sqrt::type_info, dynamicToStaticUnaryElementwise}, + {ngraph::opset3::LogicalNot::type_info, dynamicToStaticUnaryElementwise}, {ngraph::opset3::StridedSlice::type_info, dynamicToStaticShapeStridedSlice}, {ngraph::opset3::Squeeze::type_info, dynamicToStaticShapeSqueeze}, {ngraph::opset3::Gather::type_info, dynamicToStaticShapeGather}, diff --git a/inference-engine/tests/functional/plugin/myriad/ngraph/transformations/dynamic_to_static_shape_binary_elementwise.cpp b/inference-engine/tests/functional/plugin/myriad/ngraph/transformations/dynamic_to_static_shape_binary_elementwise.cpp index e2bdb399027f3b..2c5cd3cee9b6ad 100644 --- a/inference-engine/tests/functional/plugin/myriad/ngraph/transformations/dynamic_to_static_shape_binary_elementwise.cpp +++ b/inference-engine/tests/functional/plugin/myriad/ngraph/transformations/dynamic_to_static_shape_binary_elementwise.cpp @@ -314,7 +314,10 @@ INSTANTIATE_TEST_CASE_P(EltwiseBroadcast, DynamicToStaticShapeEltwise, testing:: ngraph::opset3::Greater::type_info, ngraph::opset3::Power::type_info, ngraph::opset3::Multiply::type_info, - ngraph::opset3::Subtract::type_info), + ngraph::opset3::Subtract::type_info, + ngraph::opset3::Maximum::type_info, + ngraph::opset3::Minimum::type_info, + ngraph::opset3::Less::type_info), testing::Values( EltwiseParams{DataDims{1000}, DataDims{1}, DynamicToStaticShapeEltwise::reference_simple}, EltwiseParams{DataDims{1000, 1, 1}, DataDims{1000, 1, 1}, DynamicToStaticShapeEltwise::reference_simple}, @@ -338,7 +341,10 @@ INSTANTIATE_TEST_CASE_P(EltwiseBroadcastSingleDSR, DynamicToStaticShapeEltwiseSi ngraph::opset3::Greater::type_info, ngraph::opset3::Power::type_info, ngraph::opset3::Multiply::type_info, - ngraph::opset3::Subtract::type_info), + ngraph::opset3::Subtract::type_info, + ngraph::opset3::Maximum::type_info, + ngraph::opset3::Minimum::type_info, + ngraph::opset3::Less::type_info), testing::Values( EltwiseParams{DataDims{1000}, DataDims{1}, DynamicToStaticShapeEltwiseSingleDSR::reference_simple}, EltwiseParams{DataDims{1000, 1, 1}, DataDims{1000, 1, 1}, DynamicToStaticShapeEltwiseSingleDSR::reference_simple}, diff --git a/inference-engine/tests/functional/plugin/myriad/ngraph/transformations/dynamic_to_static_shape_unary_elementwise.cpp b/inference-engine/tests/functional/plugin/myriad/ngraph/transformations/dynamic_to_static_shape_unary_elementwise.cpp index 768c3fe10f99e2..d3090bdaba84fa 100644 --- a/inference-engine/tests/functional/plugin/myriad/ngraph/transformations/dynamic_to_static_shape_unary_elementwise.cpp +++ b/inference-engine/tests/functional/plugin/myriad/ngraph/transformations/dynamic_to_static_shape_unary_elementwise.cpp @@ -94,6 +94,7 @@ INSTANTIATE_TEST_CASE_P(NGraph, DynamicToStaticShapeUnaryElementwise, testing::C ngraph::opset3::Relu::type_info, ngraph::opset3::Sigmoid::type_info, ngraph::opset3::Softmax::type_info, - ngraph::opset3::Sqrt::type_info))); + ngraph::opset3::Sqrt::type_info, + ngraph::opset3::LogicalNot::type_info))); } // namespace From ab4fdfc67142241376d12ce801e767f4dcce6c2a Mon Sep 17 00:00:00 2001 From: Artyom Anokhov Date: Thu, 17 Sep 2020 16:42:04 +0300 Subject: [PATCH 25/64] install_openvino_dependencies: Updated copyrights (#2306) setupvars.bat: Updated notification about incorrect Python version. Removed checking ICC2019 setupvars.sh: Removed logic with choosing higher version of installed Python. Added dynamic detecting python3 major and minor version for setting path. Add checking minimum required Python version(now 3.6) --- .../install_openvino_dependencies.sh | 2 +- scripts/setupvars/setupvars.bat | 16 ++++----- scripts/setupvars/setupvars.sh | 34 +++++++------------ 3 files changed, 20 insertions(+), 32 deletions(-) diff --git a/scripts/install_dependencies/install_openvino_dependencies.sh b/scripts/install_dependencies/install_openvino_dependencies.sh index 63cb012d84b3bf..2b69a83385b2fc 100755 --- a/scripts/install_dependencies/install_openvino_dependencies.sh +++ b/scripts/install_dependencies/install_openvino_dependencies.sh @@ -1,6 +1,6 @@ #!/bin/bash -# Copyright (c) 2018 Intel Corporation +# Copyright (c) 2018 - 2020 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/scripts/setupvars/setupvars.bat b/scripts/setupvars/setupvars.bat index 6aa3812c177b0c..a8e31c5f599bb2 100644 --- a/scripts/setupvars/setupvars.bat +++ b/scripts/setupvars/setupvars.bat @@ -21,8 +21,6 @@ set SCRIPT_NAME=%~nx0 set "INTEL_OPENVINO_DIR=%ROOT%" set "INTEL_CVSDK_DIR=%INTEL_OPENVINO_DIR%" -where /q libmmd.dll || echo Warning: libmmd.dll couldn't be found in %%PATH%%. Please check if the redistributable package for Intel(R) C++ Compiler is installed and the library path is added to the PATH environment variable. System reboot can be required to update the system environment. - :: OpenCV if exist "%INTEL_OPENVINO_DIR%\opencv\setupvars.bat" ( call "%INTEL_OPENVINO_DIR%\opencv\setupvars.bat" @@ -52,14 +50,14 @@ set "ngraph_DIR=%INTEL_OPENVINO_DIR%\deployment_tools\ngraph\cmake" ) :: Check if Python is installed -python --version 2>NUL +python3 --version 2>NUL if errorlevel 1 ( - echo Error^: Python is not installed. Please install Python 3.5. or 3.6 ^(64-bit^) from https://www.python.org/downloads/ + echo Error^: Python is not installed. Please install Python 3.6 or higher ^(64-bit^) from https://www.python.org/downloads/ exit /B 1 ) :: Check Python version -for /F "tokens=* USEBACKQ" %%F IN (`python --version 2^>^&1`) DO ( +for /F "tokens=* USEBACKQ" %%F IN (`python3 --version 2^>^&1`) DO ( set version=%%F ) @@ -69,18 +67,18 @@ for /F "tokens=1,2,3 delims=. " %%a in ("%version%") do ( ) if "%Major%" geq "3" ( - if "%Minor%" geq "5" ( + if "%Minor%" geq "6" ( set python_ver=okay ) ) if not "%python_ver%"=="okay" ( - echo Unsupported Python version. Please install Python 3.5 or 3.6 ^(64-bit^) from https://www.python.org/downloads/ + echo Unsupported Python version. Please install Python 3.6 or higher ^(64-bit^) from https://www.python.org/downloads/ exit /B 1 ) :: Check Python bitness -python -c "import sys; print(64 if sys.maxsize > 2**32 else 32)" 2 > NUL +python3 -c "import sys; print(64 if sys.maxsize > 2**32 else 32)" 2 > NUL if errorlevel 1 ( echo Error^: Error during installed Python bitness detection exit /B 1 @@ -91,7 +89,7 @@ for /F "tokens=* USEBACKQ" %%F IN (`python -c "import sys; print(64 if sys.maxsi ) if not "%bitness%"=="64" ( - echo Unsupported Python bitness. Please install Python 3.5 or 3.6 ^(64-bit^) from https://www.python.org/downloads/ + echo Unsupported Python bitness. Please install Python 3.6 or higher ^(64-bit^) from https://www.python.org/downloads/ exit /B 1 ) diff --git a/scripts/setupvars/setupvars.sh b/scripts/setupvars/setupvars.sh index 6c5fa72c7675dc..cd927ef01f1b23 100755 --- a/scripts/setupvars/setupvars.sh +++ b/scripts/setupvars/setupvars.sh @@ -94,23 +94,7 @@ if [ -e $INTEL_OPENVINO_DIR/deployment_tools/tools/post_training_optimization_to fi if [ -z "$python_version" ]; then - if command -v python3.7 >/dev/null 2>&1; then - python_version=3.7 - python_bitness=$(python3.7 -c 'import sys; print(64 if sys.maxsize > 2**32 else 32)') - elif command -v python3.6 >/dev/null 2>&1; then - python_version=3.6 - python_bitness=$(python3.6 -c 'import sys; print(64 if sys.maxsize > 2**32 else 32)') - elif command -v python3.5 >/dev/null 2>&1; then - python_version=3.5 - python_bitness=$(python3.5 -c 'import sys; print(64 if sys.maxsize > 2**32 else 32)') - elif command -v python3.4 >/dev/null 2>&1; then - python_version=3.4 - python_bitness=$(python3.4 -c 'import sys; print(64 if sys.maxsize > 2**32 else 32)') - elif command -v python2.7 >/dev/null 2>&1; then - python_version=2.7 - elif command -v python >/dev/null 2>&1; then - python_version=$(python -c 'import sys; print(".".join(map(str, sys.version_info[:2])))') - fi + python_version=$(python3 -c 'import sys; print(str(sys.version_info[0])+"."+str(sys.version_info[1]))') fi OS_NAME="" @@ -118,17 +102,23 @@ if command -v lsb_release >/dev/null 2>&1; then OS_NAME=$(lsb_release -i -s) fi +python_bitness=$(python3 -c 'import sys; print(64 if sys.maxsize > 2**32 else 32)') if [ "$python_bitness" != "" ] && [ "$python_bitness" != "64" ] && [ "$OS_NAME" != "Raspbian" ]; then echo "[setupvars.sh] 64 bitness for Python" $python_version "is requred" fi +MINIMUM_REQUIRED_PYTHON_VERSION="3.6" +if [[ ! -z "$python_version" && "$(printf '%s\n' "$python_version" "$MINIMUM_REQUIRED_PYTHON_VERSION" | sort -V | head -n 1)" != "$MINIMUM_REQUIRED_PYTHON_VERSION" ]]; then + echo "[setupvars.sh] Unsupported Python version. Please install Python 3.6 or higher (64-bit) from https://www.python.org/downloads/" +fi + if [ ! -z "$python_version" ]; then - if [ "$python_version" != "2.7" ]; then - # add path to OpenCV API for Python 3.x - export PYTHONPATH="$INTEL_OPENVINO_DIR/python/python3:$PYTHONPATH" + # add path to OpenCV API for Python 3.x + export PYTHONPATH="$INTEL_OPENVINO_DIR/python/python3:$PYTHONPATH" + if [[ -e $INTEL_OPENVINO_DIR/python/python$python_version ]]; then + # add path to Inference Engine Python API + export PYTHONPATH="$INTEL_OPENVINO_DIR/python/python$python_version:$PYTHONPATH" fi - # add path to Inference Engine Python API - export PYTHONPATH="$INTEL_OPENVINO_DIR/python/python$python_version:$PYTHONPATH" fi echo "[setupvars.sh] OpenVINO environment initialized" From 2a9ec98d1354d46da28232f762c6bdf246347988 Mon Sep 17 00:00:00 2001 From: Dmitrii Denisov Date: Thu, 17 Sep 2020 16:43:03 +0300 Subject: [PATCH 26/64] Glstreamer dependencies (#2292) * Refactoring: install_openvino_dependencies.sh script * Added python3-gi package * Correcting typos * Update install_openvino_dependencies.sh Fixed libglib2.0-0 package location. --- .../install_dependencies/install_openvino_dependencies.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/install_dependencies/install_openvino_dependencies.sh b/scripts/install_dependencies/install_openvino_dependencies.sh index 2b69a83385b2fc..31c7140694dfad 100755 --- a/scripts/install_dependencies/install_openvino_dependencies.sh +++ b/scripts/install_dependencies/install_openvino_dependencies.sh @@ -79,8 +79,7 @@ if [ -f /etc/lsb-release ]; then PKGS+=( libgtk2.0-0 ) else if [ "$system_ver" = "20.04" ]; then - PKGS+=( libglib2.0-0 - gstreamer1.0-plugins-ugly + PKGS+=( gstreamer1.0-plugins-ugly gstreamer1.0-libav libgstreamer-plugins-base1.0-dev gstreamer1.0-doc @@ -100,8 +99,7 @@ if [ -f /etc/lsb-release ]; then libpython3.8 ) elif [ "$system_ver" = "18.04" ]; then - PKGS+=( libglib2.0 - libfluidsynth1 + PKGS+=( libfluidsynth1 libnettle6 libopenexr22 gstreamer1.0-plugins-ugly @@ -126,6 +124,8 @@ if [ -f /etc/lsb-release ]; then libopencore-amrnb0 libopencore-amrwb0 liba52-0.7.4 + python3-gi + libglib2.0-0 ) fi apt update From fecce756a4b1e2fcc37f6638afad898f0d9a5583 Mon Sep 17 00:00:00 2001 From: Artyom Anokhov Date: Thu, 17 Sep 2020 21:20:12 +0300 Subject: [PATCH 27/64] setupvars: Updated notifications, fixed calling python in Windows case (#2319) --- scripts/setupvars/setupvars.bat | 12 ++++++------ scripts/setupvars/setupvars.sh | 15 +++++++++++---- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/scripts/setupvars/setupvars.bat b/scripts/setupvars/setupvars.bat index a8e31c5f599bb2..bfe84310b6e0de 100644 --- a/scripts/setupvars/setupvars.bat +++ b/scripts/setupvars/setupvars.bat @@ -50,14 +50,14 @@ set "ngraph_DIR=%INTEL_OPENVINO_DIR%\deployment_tools\ngraph\cmake" ) :: Check if Python is installed -python3 --version 2>NUL +python --version 2>NUL if errorlevel 1 ( - echo Error^: Python is not installed. Please install Python 3.6 or higher ^(64-bit^) from https://www.python.org/downloads/ + echo Error^: Python is not installed. Please install one of Python 3.6 - 3.8 ^(64-bit^) from https://www.python.org/downloads/ exit /B 1 ) :: Check Python version -for /F "tokens=* USEBACKQ" %%F IN (`python3 --version 2^>^&1`) DO ( +for /F "tokens=* USEBACKQ" %%F IN (`python --version 2^>^&1`) DO ( set version=%%F ) @@ -73,12 +73,12 @@ if "%Major%" geq "3" ( ) if not "%python_ver%"=="okay" ( - echo Unsupported Python version. Please install Python 3.6 or higher ^(64-bit^) from https://www.python.org/downloads/ + echo Unsupported Python version. Please install one of Python 3.6 - 3.8 ^(64-bit^) from https://www.python.org/downloads/ exit /B 1 ) :: Check Python bitness -python3 -c "import sys; print(64 if sys.maxsize > 2**32 else 32)" 2 > NUL +python -c "import sys; print(64 if sys.maxsize > 2**32 else 32)" 2 > NUL if errorlevel 1 ( echo Error^: Error during installed Python bitness detection exit /B 1 @@ -89,7 +89,7 @@ for /F "tokens=* USEBACKQ" %%F IN (`python -c "import sys; print(64 if sys.maxsi ) if not "%bitness%"=="64" ( - echo Unsupported Python bitness. Please install Python 3.6 or higher ^(64-bit^) from https://www.python.org/downloads/ + echo Unsupported Python bitness. Please install one of Python 3.6 - 3.8 ^(64-bit^) from https://www.python.org/downloads/ exit /B 1 ) diff --git a/scripts/setupvars/setupvars.sh b/scripts/setupvars/setupvars.sh index cd927ef01f1b23..5a1e6e4a26f5c6 100755 --- a/scripts/setupvars/setupvars.sh +++ b/scripts/setupvars/setupvars.sh @@ -107,17 +107,24 @@ if [ "$python_bitness" != "" ] && [ "$python_bitness" != "64" ] && [ "$OS_NAME" echo "[setupvars.sh] 64 bitness for Python" $python_version "is requred" fi -MINIMUM_REQUIRED_PYTHON_VERSION="3.6" +MINIMUM_REQUIRED_PYTHON_VERSION="3.6" +MAX_SUPPORTED_PYTHON_VERSION=$([[ "$OSTYPE" == "darwin"* ]] && echo '3.7' || echo '3.8') if [[ ! -z "$python_version" && "$(printf '%s\n' "$python_version" "$MINIMUM_REQUIRED_PYTHON_VERSION" | sort -V | head -n 1)" != "$MINIMUM_REQUIRED_PYTHON_VERSION" ]]; then - echo "[setupvars.sh] Unsupported Python version. Please install Python 3.6 or higher (64-bit) from https://www.python.org/downloads/" + echo "[setupvars.sh] ERROR: Unsupported Python version. Please install one of Python 3.6-${MAX_SUPPORTED_PYTHON_VERSION} (64-bit) from https://www.python.org/downloads/" + return 1 fi + if [ ! -z "$python_version" ]; then # add path to OpenCV API for Python 3.x export PYTHONPATH="$INTEL_OPENVINO_DIR/python/python3:$PYTHONPATH" - if [[ -e $INTEL_OPENVINO_DIR/python/python$python_version ]]; then + pydir=$INTEL_OPENVINO_DIR/python/python$python_version + if [[ -d $pydir ]]; then # add path to Inference Engine Python API - export PYTHONPATH="$INTEL_OPENVINO_DIR/python/python$python_version:$PYTHONPATH" + export PYTHONPATH="${pydir}:${PYTHONPATH}" + else + echo "[setupvars.sh] ERROR: Can not find OpenVINO Python module for python${python_version} by path ${pydir}" + return 1 fi fi From b0308d91a5730f1915df0828c6e44e75afc0e30c Mon Sep 17 00:00:00 2001 From: Maksim Doronin Date: Thu, 17 Sep 2020 23:52:16 +0300 Subject: [PATCH 28/64] [IE][VPU]: Enable some DSR+Op tests (#2118) * Introduced a new way to test DSR+Op cases * Enabled DSR_Reduce, DSR_VariadicSplit, DSR_TopK, DSR_Scatter, DSR_Unsqueeze tests * Other disabled tests are still disabled until reference function is implemented. Added related comments * Reduce DSR+Op tests execution time via reducing tensor shapes --- .../dynamic_to_static_shape.cpp | 19 +++ .../dynamic_to_static_shape_reduce.cpp | 6 +- ...dynamic_to_static_shape_variadic_split.cpp | 2 +- .../src/stages/dynamic_shape_resolver.cpp | 7 +- .../graph_transformer/src/stages/reduce.cpp | 2 +- .../subgraph_tests/dsr_binary_elementwise.cpp | 3 +- .../myriad/subgraph_tests/dsr_gather.cpp | 3 +- .../myriad/subgraph_tests/dsr_matmul.cpp | 20 ++-- .../dsr_non_max_suppression.cpp | 1 + .../myriad/subgraph_tests/dsr_reduce.cpp | 113 +++++++++--------- .../myriad/subgraph_tests/dsr_roialign.cpp | 1 + .../myriad/subgraph_tests/dsr_scatter.cpp | 58 ++++----- .../myriad/subgraph_tests/dsr_squeeze.cpp | 6 +- .../subgraph_tests/dsr_tests_common.hpp | 35 +----- .../plugin/myriad/subgraph_tests/dsr_topk.cpp | 104 ++++++---------- .../myriad/subgraph_tests/dsr_unsqueeze.cpp | 53 ++++---- .../subgraph_tests/dsr_variadic_split.cpp | 63 ++++------ .../vpu/frontend_tests/dsr_parsing_tests.cpp | 17 +++ 18 files changed, 222 insertions(+), 291 deletions(-) diff --git a/inference-engine/src/vpu/common/src/ngraph/transformations/dynamic_to_static_shape.cpp b/inference-engine/src/vpu/common/src/ngraph/transformations/dynamic_to_static_shape.cpp index d909876ef8e6c0..1241838101126e 100644 --- a/inference-engine/src/vpu/common/src/ngraph/transformations/dynamic_to_static_shape.cpp +++ b/inference-engine/src/vpu/common/src/ngraph/transformations/dynamic_to_static_shape.cpp @@ -2,6 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 // +#include #include "vpu/ngraph/transformations/dynamic_to_static_shape.hpp" #include "vpu/ngraph/transformations/dynamic_to_static_shape_binary_elementwise.hpp" #include "vpu/ngraph/transformations/dynamic_to_static_shape_broadcast.hpp" @@ -53,6 +54,19 @@ bool validateStaticShapes(const ngraph::Function& function) { return true; } +bool propagateUpperBoundFromExistingDSR(std::shared_ptr& function) { + bool function_changed = false; + for (const auto& op : function->get_ordered_ops()) { + if (const auto dsr = ngraph::as_type_ptr(op)) { + dsr->setMode(ngraph::vpu::op::DynamicShapeResolverMode::INFER_UPPER_BOUND_SHAPE); + dsr->validate_and_infer_types(); + function_changed = true; + } + } + + return function_changed; +} + const Transformations& getDefaultTransformations() { static const Transformations transformations = { {ngraph::opset3::Add::type_info, dynamicToStaticShapeBinaryEltwise}, @@ -120,6 +134,11 @@ DynamicToStaticShape::DynamicToStaticShape(const Transformations& specificTransf bool DynamicToStaticShape::run_on_function(std::shared_ptr function) { bool function_changed = false; + + // Ensure that existing DSRs in function propagate upper-bound shapes, not dynamism. + // Basically this is possible in test cases, when the function is initially configured with DSR as inputs. + function_changed |= propagateUpperBoundFromExistingDSR(function); + for (const auto& operation : function->get_ordered_ops()) { if (!isDynamic(*operation)) { continue; diff --git a/inference-engine/src/vpu/common/src/ngraph/transformations/dynamic_to_static_shape_reduce.cpp b/inference-engine/src/vpu/common/src/ngraph/transformations/dynamic_to_static_shape_reduce.cpp index ff0e8c6a0a0074..71db9425846b55 100644 --- a/inference-engine/src/vpu/common/src/ngraph/transformations/dynamic_to_static_shape_reduce.cpp +++ b/inference-engine/src/vpu/common/src/ngraph/transformations/dynamic_to_static_shape_reduce.cpp @@ -51,8 +51,8 @@ void dynamicToStaticShapeReduce(std::shared_ptr target) { if (keep_dims) { output_shape = std::make_shared( data_shape, - ngraph::opset3::Constant::create(ngraph::element::i64, {axes.size()}, axes), - ngraph::opset3::Constant::create(ngraph::element::i64, {axes.size()}, std::vector(axes.size(), 1)), + ngraph::opset3::Constant::create(data_shape.get_element_type(), {axes.size()}, axes), + ngraph::opset3::Constant::create(data_shape.get_element_type(), {axes.size()}, std::vector(axes.size(), 1)), ngraph::opset3::Constant::create(ngraph::element::i64, {1}, {0})); } else { std::vector range(data_rank_value); @@ -63,7 +63,7 @@ void dynamicToStaticShapeReduce(std::shared_ptr target) { output_shape = std::make_shared( data_shape, - ngraph::opset3::Constant::create(ngraph::element::i64, {indices.size()}, indices), + ngraph::opset3::Constant::create(data_shape.get_element_type(), {indices.size()}, indices), ngraph::opset3::Constant::create(ngraph::element::i64, {1}, {0})); } const auto copied = target->clone_with_new_inputs(target->input_values()); diff --git a/inference-engine/src/vpu/common/src/ngraph/transformations/dynamic_to_static_shape_variadic_split.cpp b/inference-engine/src/vpu/common/src/ngraph/transformations/dynamic_to_static_shape_variadic_split.cpp index 5535b3c3534f63..f93625dbc6bdae 100644 --- a/inference-engine/src/vpu/common/src/ngraph/transformations/dynamic_to_static_shape_variadic_split.cpp +++ b/inference-engine/src/vpu/common/src/ngraph/transformations/dynamic_to_static_shape_variadic_split.cpp @@ -73,7 +73,7 @@ void dynamicToStaticShapeVariadicSplit(std::shared_ptr target) { } const auto outDSR = std::make_shared(copied->output(i), dsrShapeInput); - outDSR->set_friendly_name(target->get_friendly_name() + "." + std::to_string(target->output(0).get_index())); + outDSR->set_friendly_name(target->get_friendly_name() + "." + std::to_string(i)); target->output(i).replace(outDSR); } } diff --git a/inference-engine/src/vpu/graph_transformer/src/stages/dynamic_shape_resolver.cpp b/inference-engine/src/vpu/graph_transformer/src/stages/dynamic_shape_resolver.cpp index aae54afafa4407..5c6283c327ea02 100644 --- a/inference-engine/src/vpu/graph_transformer/src/stages/dynamic_shape_resolver.cpp +++ b/inference-engine/src/vpu/graph_transformer/src/stages/dynamic_shape_resolver.cpp @@ -84,13 +84,14 @@ void FrontEnd::parseDSR(const Model& model, const ie::CNNLayerPtr& layer, const "Parsing layer {} of type {} failed: if input with index {} (of name {}) has not a producer, it must have Input " "data usage, actual: {}", layer->name, layer->type, 1, shape->name(), shape->usage()); } else { - VPU_THROW_UNLESS(shape->usage() == DataUsage::Intermediate, + VPU_THROW_UNLESS(shape->usage() == DataUsage::Intermediate || shape->usage() == DataUsage::Output, "Parsing layer {} of type {} failed: if input with index {} (of name {}) has a producer, it must have Intermediate " - "data usage, actual: {}", layer->name, layer->type, 1, shape->name(), shape->usage()); + "or Output (if already has been associated with other output data) data usage, actual: {}", + layer->name, layer->type, 1, shape->name(), shape->usage()); } auto shapeDataObject = shape; - if (dataOutput->usage() == DataUsage::Output) { + if (dataOutput->usage() == DataUsage::Output && shapeDataObject->usage() != DataUsage::Output) { const auto& shapeOutput = model->addOutputData(dataOutput->name() + "@shape", shape->desc()); bindData(shapeOutput, shape->origData()); diff --git a/inference-engine/src/vpu/graph_transformer/src/stages/reduce.cpp b/inference-engine/src/vpu/graph_transformer/src/stages/reduce.cpp index 37d89d437c16a6..b019617e826b7d 100644 --- a/inference-engine/src/vpu/graph_transformer/src/stages/reduce.cpp +++ b/inference-engine/src/vpu/graph_transformer/src/stages/reduce.cpp @@ -99,7 +99,7 @@ class ReduceStage final : public StageNode { void initialCheckImpl() const override { VPU_THROW_UNLESS(input(0)->desc().type() == output(0)->desc().type(), - "Stage {} of type {} expects that data types of input with index {} ({}) ", + "Stage {} of type {} expects that data types of input with index {} ({}) " "and output with index {} ({}) are the same, but it is {} and {}", name(), type(), 0, input(0)->name(), 0, output(0)->name(), input(0)->desc().type(), output(0)->desc().type()); assertInputsOutputsTypes(this, diff --git a/inference-engine/tests/functional/plugin/myriad/subgraph_tests/dsr_binary_elementwise.cpp b/inference-engine/tests/functional/plugin/myriad/subgraph_tests/dsr_binary_elementwise.cpp index 0cda57a5352c5c..2f5aeb4eb5d071 100644 --- a/inference-engine/tests/functional/plugin/myriad/subgraph_tests/dsr_binary_elementwise.cpp +++ b/inference-engine/tests/functional/plugin/myriad/subgraph_tests/dsr_binary_elementwise.cpp @@ -54,8 +54,7 @@ class DSR_BinaryElementwiseSingleDSR : public testing::WithParamInterface(parameters); const auto inputSubgraph0 = createInputSubgraphWithDSR(inDataType, inDataShapes.lhs); - const auto input1 = std::make_shared(inDataType, inDataShapes.rhs.shape); - m_parameterVector.push_back(input1); + const auto input1 = createParameter(inDataType, inDataShapes.rhs.shape); const auto eltwise = ngraph::helpers::getNodeSharedPtr(eltwiseType, {inputSubgraph0, input1}); diff --git a/inference-engine/tests/functional/plugin/myriad/subgraph_tests/dsr_gather.cpp b/inference-engine/tests/functional/plugin/myriad/subgraph_tests/dsr_gather.cpp index 90ba6697c93774..a0293e11b04925 100644 --- a/inference-engine/tests/functional/plugin/myriad/subgraph_tests/dsr_gather.cpp +++ b/inference-engine/tests/functional/plugin/myriad/subgraph_tests/dsr_gather.cpp @@ -67,8 +67,7 @@ class DSR_GatherDynamicDataStaticIdx : public DSR_GatherBase { const auto inputDataSubgraph = createInputSubgraphWithDSR(inDataType, gatherSetup.inputShapes); - const auto indicesParam = std::make_shared(idxType, gatherSetup.indexShape.shape); - m_parameterVector.push_back(indicesParam); + const auto indicesParam = createParameter(idxType, gatherSetup.indexShape.shape); m_indicesInputNames.insert(indicesParam->get_friendly_name()); const auto axis = ngraph::opset3::Constant::create(ngraph::element::i32, {1}, std::vector{gatherSetup.axis}); diff --git a/inference-engine/tests/functional/plugin/myriad/subgraph_tests/dsr_matmul.cpp b/inference-engine/tests/functional/plugin/myriad/subgraph_tests/dsr_matmul.cpp index f192daeb61294c..6d5ea218e87bf2 100644 --- a/inference-engine/tests/functional/plugin/myriad/subgraph_tests/dsr_matmul.cpp +++ b/inference-engine/tests/functional/plugin/myriad/subgraph_tests/dsr_matmul.cpp @@ -38,14 +38,14 @@ const auto combinations = testing::Combine( testing::Values( // JIRA: 33925 MatMulTestCase{{{1024}, false, 1, {}, {}, 0}, {{1024, 1000}, false, 0, {}, {}, 1}}, // JIRA: 33925 MatMulTestCase{{{1024}, true, 1, {1, 0}, {}, 0}, {{1, 1000}, false, 0, {}, {}, 1}}, - MatMulTestCase{{{3, 10, 1024}, {5, 10, 1024}, false}, - {{1024, 800}, {1024, 1000}, false}}, - MatMulTestCase{{{2, 10, 1024}, {5, 10, 1024}, false}, - {{1, 1024, 500}, {1, 1024, 1000}, false}}, - MatMulTestCase{{{1, 10, 1024}, {5, 10, 1024}, false}, - {{1, 800, 1024}, {1, 1000, 1024}, true}}, - MatMulTestCase{{{3, 10, 1024}, {3, 10, 1024}, false}, - {{2, 1, 1000, 1024}, {5, 1, 1000, 1024}, true}}), + MatMulTestCase{{{3, 10, 128}, {5, 10, 128}, false}, + {{128, 80}, {128, 100}, false}}, + MatMulTestCase{{{2, 10, 128}, {5, 10, 128}, false}, + {{1, 128, 50}, {1, 128, 100}, false}}, + MatMulTestCase{{{1, 10, 128}, {5, 10, 128}, false}, + {{1, 80, 128}, {1, 100, 128}, true}}, + MatMulTestCase{{{3, 10, 128}, {3, 10, 128}, false}, + {{2, 1, 100, 128}, {5, 1, 100, 128}, true}}), testing::Values(CommonTestUtils::DEVICE_MYRIAD)); @@ -91,9 +91,7 @@ class DSR_MatMul : public testing::WithParamInterface, NGRAPH_UNREACHABLE("UNKNOWN DYNAMISM MODE for MatMul DSR graph comparison test"); } - const auto matMul = std::make_shared(inputA, inputB, matmul_setup.A.transpose, matmul_setup.B.transpose); - - return matMul; + return std::make_shared(inputA, inputB, matmul_setup.A.transpose, matmul_setup.B.transpose); } }; diff --git a/inference-engine/tests/functional/plugin/myriad/subgraph_tests/dsr_non_max_suppression.cpp b/inference-engine/tests/functional/plugin/myriad/subgraph_tests/dsr_non_max_suppression.cpp index 2cf7b45924dabf..7269b3562b13f3 100644 --- a/inference-engine/tests/functional/plugin/myriad/subgraph_tests/dsr_non_max_suppression.cpp +++ b/inference-engine/tests/functional/plugin/myriad/subgraph_tests/dsr_non_max_suppression.cpp @@ -62,6 +62,7 @@ TEST_P(DSR_NonMaxSuppression, CompareWithReference) { Run(); } +// #-30919 INSTANTIATE_TEST_CASE_P(DISABLED_DynamicNonMaxSupression, DSR_NonMaxSuppression, ::testing::Combine( ::testing::Values( diff --git a/inference-engine/tests/functional/plugin/myriad/subgraph_tests/dsr_reduce.cpp b/inference-engine/tests/functional/plugin/myriad/subgraph_tests/dsr_reduce.cpp index b7954fa40177d3..6cd0f4ebb85cd8 100644 --- a/inference-engine/tests/functional/plugin/myriad/subgraph_tests/dsr_reduce.cpp +++ b/inference-engine/tests/functional/plugin/myriad/subgraph_tests/dsr_reduce.cpp @@ -2,63 +2,59 @@ // SPDX-License-Identifier: Apache-2.0 // -#include -#include -#include +#include "dsr_tests_common.hpp" namespace { -using DataType = ngraph::element::Type_t; -using DataDims = ngraph::Shape; +using namespace LayerTestsUtils::vpu; struct ReduceTestCase { - ngraph::Shape data_shape; + DataShapeWithUpperBound dataShapes; std::vector axes; - bool keep_dims; + bool keepDims; }; -const auto arithmetic_combinations = testing::Combine( +const DataShapeWithUpperBound defaultReduceShapes { + DataShape{24, 81}, DataShape{100, 81} +}; + +const auto arithmeticCombinations = testing::Combine( testing::Values( + // ReduceMean can be replaced with avg pooling and work incorrectly #-34278 + // ngraph::opset3::ReduceMean::type_info, + + // ReduceProd is not supported by myriad plugin + // ngraph::opset3::ReduceProd::type_info, + ngraph::opset3::ReduceSum::type_info, ngraph::opset3::ReduceMax::type_info, - ngraph::opset3::ReduceMean::type_info, - ngraph::opset3::ReduceMin::type_info, - ngraph::opset3::ReduceProd::type_info, - ngraph::opset3::ReduceSum::type_info), + ngraph::opset3::ReduceMin::type_info), testing::Values( - ngraph::element::f16, - ngraph::element::f32, - ngraph::element::i32, - ngraph::element::i64, - ngraph::element::u8), + ngraph::element::f32), testing::Values( - ngraph::element::i32, - ngraph::element::i64, - ngraph::element::u8), + ngraph::element::i32), testing::Values( // data_shape, axes, keep_dims - ReduceTestCase{{1, 3, 224, 224}, {2, 3}, true}, - ReduceTestCase{{1, 3, 224, 224}, {2, 3}, false}, - ReduceTestCase{{1, 3, 224, 224}, {0, 1, 2, 3}, true}, - ReduceTestCase{{1, 3, 224, 224}, {1, 3}, false}, - ReduceTestCase{{4}, {0}, true}), + ReduceTestCase{defaultReduceShapes, {0}, true}, + ReduceTestCase{defaultReduceShapes, {1}, false}, + ReduceTestCase{defaultReduceShapes, {0, 1}, true}, + ReduceTestCase{defaultReduceShapes, {0, 1}, false}), testing::Values(CommonTestUtils::DEVICE_MYRIAD)); -const auto logical_combinations = testing::Combine( +const auto logicalCombinations = testing::Combine( testing::Values( - ngraph::opset3::ReduceLogicalAnd::type_info, - ngraph::opset3::ReduceLogicalOr::type_info), + // ReduceLogicalOr is not supported by Myriad plugin + // ngraph::opset3::ReduceLogicalOr::type_info, + + ngraph::opset3::ReduceLogicalAnd::type_info), testing::Values(ngraph::element::boolean), testing::Values( - ngraph::element::i32, - ngraph::element::i64, - ngraph::element::u8), + ngraph::element::i32), testing::Values( // data_shape, axes, keep_dims - ReduceTestCase{{1, 3, 224, 224}, {2, 3}, true}, - ReduceTestCase{{1, 3, 224, 224}, {2, 3}, false}, - ReduceTestCase{{1, 3, 224, 224}, {0, 1, 2, 3}, true}, - ReduceTestCase{{1, 3, 224, 224}, {1, 3}, false}, - ReduceTestCase{{4}, {0}, true}), + ReduceTestCase{defaultReduceShapes, {0}, true}, + ReduceTestCase{defaultReduceShapes, {1}, false}, + ReduceTestCase{defaultReduceShapes, {0, 1}, true}, + ReduceTestCase{defaultReduceShapes, {0, 1}, false}), testing::Values(CommonTestUtils::DEVICE_MYRIAD)); @@ -70,33 +66,34 @@ using Parameters = std::tuple< LayerTestsUtils::TargetDevice >; -class DSR_Reduce : public testing::WithParamInterface, - virtual public LayerTestsUtils::LayerTestsCommon { +class DSR_Reduce : public testing::WithParamInterface, public DSR_TestsCommon { protected: - void SetUp() override { + std::shared_ptr createTestedOp() override { const auto& parameters = GetParam(); - const auto& reduce_type = std::get<0>(parameters); - const auto& data_type = std::get<1>(parameters); - const auto& axes_type = std::get<2>(parameters); - const auto& reduce_setup = std::get<3>(parameters); + const auto& reduceType = std::get<0>(parameters); + const auto& dataType = std::get<1>(parameters); + const auto& axesType = std::get<2>(parameters); + const auto& reduceSetup = std::get<3>(parameters); targetDevice = std::get<4>(parameters); - const auto data = std::make_shared(data_type, reduce_setup.data_shape); - const auto axes = ngraph::opset3::Constant::create(axes_type, {reduce_setup.axes.size()}, reduce_setup.axes); + const auto inputSubgraph = createInputSubgraphWithDSR(dataType, reduceSetup.dataShapes); + const auto axes = ngraph::opset3::Constant::create(axesType, {reduceSetup.axes.size()}, reduceSetup.axes); + + const auto reduce = ngraph::helpers::getNodeSharedPtr(reduceType, {inputSubgraph, axes}); - const auto dims = std::make_shared(ngraph::element::i64, ngraph::Shape{reduce_setup.data_shape.size()}); + if (auto arithmetic_reduce = std::dynamic_pointer_cast(reduce)) + arithmetic_reduce->set_keep_dims(reduceSetup.keepDims); + else if (auto logical_reduce = std::dynamic_pointer_cast(reduce)) + logical_reduce->set_keep_dims(reduceSetup.keepDims); + reduce->validate_and_infer_types(); - const auto dsr = std::make_shared(data, dims); - const auto node = ngraph::helpers::getNodeSharedPtr(reduce_type, {dsr, axes}); + // CNNNetworkNGraphImpl handles only I64, I32 and FP32 precisions and sets FP32 as default otherwise. + // Set I32 explicitly. + if (dataType == ngraph::element::boolean) { + outPrc = InferenceEngine::Precision::I32; + } - if (auto arithmetic_reduce = std::dynamic_pointer_cast(node)) - arithmetic_reduce->set_keep_dims(reduce_setup.keep_dims); - else if (auto logical_reduce = std::dynamic_pointer_cast(node)) - logical_reduce->set_keep_dims(reduce_setup.keep_dims); - node->validate_and_infer_types(); - const auto result = std::make_shared(node); - function = std::make_shared(ngraph::ResultVector{result}, - ngraph::ParameterVector{data, dims}, "DSR-Reduce"); + return reduce; } }; @@ -104,7 +101,7 @@ TEST_P(DSR_Reduce, CompareWithReference) { Run(); } -INSTANTIATE_TEST_CASE_P(DISABLED_DynamicArithmeticReduce, DSR_Reduce, arithmetic_combinations); -INSTANTIATE_TEST_CASE_P(DISABLED_DynamicLogicalReduce, DSR_Reduce, logical_combinations); +INSTANTIATE_TEST_CASE_P(DynamicArithmeticReduce, DSR_Reduce, arithmeticCombinations); +INSTANTIATE_TEST_CASE_P(DynamicLogicalReduce, DSR_Reduce, logicalCombinations); } // namespace diff --git a/inference-engine/tests/functional/plugin/myriad/subgraph_tests/dsr_roialign.cpp b/inference-engine/tests/functional/plugin/myriad/subgraph_tests/dsr_roialign.cpp index f7b8f82e24f230..f0b8cce54e039f 100644 --- a/inference-engine/tests/functional/plugin/myriad/subgraph_tests/dsr_roialign.cpp +++ b/inference-engine/tests/functional/plugin/myriad/subgraph_tests/dsr_roialign.cpp @@ -147,6 +147,7 @@ TEST_P(DSR_ROIAlign, CompareWithReference) { Run(); } +// #-30909 INSTANTIATE_TEST_CASE_P(DISABLED_DynamicROIAlign, DSR_ROIAlign, ::testing::Combine( ::testing::Values( diff --git a/inference-engine/tests/functional/plugin/myriad/subgraph_tests/dsr_scatter.cpp b/inference-engine/tests/functional/plugin/myriad/subgraph_tests/dsr_scatter.cpp index 712a0ca97c6686..6dfe5eea49d053 100644 --- a/inference-engine/tests/functional/plugin/myriad/subgraph_tests/dsr_scatter.cpp +++ b/inference-engine/tests/functional/plugin/myriad/subgraph_tests/dsr_scatter.cpp @@ -2,18 +2,15 @@ // SPDX-License-Identifier: Apache-2.0 // -#include -#include -#include +#include "dsr_tests_common.hpp" namespace { -using DataType = ngraph::element::Type_t; - +using namespace LayerTestsUtils::vpu; struct ScatterTestCase { - ngraph::NodeTypeInfo scatter_type_info; - ngraph::Shape data_shape, indices_shape, updates_shape; + ngraph::NodeTypeInfo scatterTypeInfo; + DataShapeWithUpperBound dataShapes, indicesShape, updatesShape; int64_t axis; }; @@ -24,30 +21,22 @@ using Parameters = std::tuple< LayerTestsUtils::TargetDevice >; -class DSR_Scatter : public testing::WithParamInterface, - virtual public LayerTestsUtils::LayerTestsCommon { +class DSR_Scatter : public testing::WithParamInterface, public DSR_TestsCommon { protected: - void SetUp() override { + std::shared_ptr createTestedOp() override { const auto& parameters = GetParam(); - const auto& numeric_type = std::get<0>(parameters); - const auto& integer_type = std::get<1>(parameters); - const auto& scatter_setup = std::get<2>(parameters); + const auto& numericType = std::get<0>(parameters); + const auto& integerType = std::get<1>(parameters); + const auto& scatterSetup = std::get<2>(parameters); targetDevice = std::get<3>(parameters); - const auto data = std::make_shared(numeric_type, scatter_setup.data_shape); - const auto indices = std::make_shared(integer_type, scatter_setup.indices_shape); - const auto updates = std::make_shared(numeric_type, scatter_setup.updates_shape); - const auto axis = std::make_shared(integer_type, ngraph::Shape{1}, std::vector{scatter_setup.axis}); - - - const auto dims = std::make_shared(ngraph::element::i64, ngraph::Shape{scatter_setup.data_shape.size()}); - const auto dsr = std::make_shared(data, dims); + const auto inputSubgraph = createInputSubgraphWithDSR(numericType, scatterSetup.dataShapes); + const auto indicesSubgraph = createInputSubgraphWithDSR(integerType, scatterSetup.indicesShape); + const auto updatesSubgraph = createInputSubgraphWithDSR(numericType, scatterSetup.updatesShape); - const auto node = ngraph::helpers::getNodeSharedPtr(scatter_setup.scatter_type_info, {dsr, indices, updates, axis}); + const auto axis = std::make_shared(integerType, ngraph::Shape{1}, std::vector{scatterSetup.axis}); - const auto result = std::make_shared(node); - function = std::make_shared(ngraph::ResultVector{result}, - ngraph::ParameterVector{data, indices, updates, dims}, scatter_setup.scatter_type_info.name); + return ngraph::helpers::getNodeSharedPtr(scatterSetup.scatterTypeInfo, {inputSubgraph, indicesSubgraph, updatesSubgraph, axis}); } }; @@ -55,20 +44,19 @@ TEST_P(DSR_Scatter, CompareWithReference) { Run(); } -INSTANTIATE_TEST_CASE_P(DISABLED_DynamicScatter, DSR_Scatter, +INSTANTIATE_TEST_CASE_P(DynamicScatter, DSR_Scatter, ::testing::Combine( testing::Values( - ngraph::element::f16, - ngraph::element::f32, - ngraph::element::i32, - ngraph::element::i64, - ngraph::element::u8), + ngraph::element::f16), testing::Values( - ngraph::element::i32, - ngraph::element::i64, - ngraph::element::u8), + ngraph::element::i32), testing::Values( - ScatterTestCase{ngraph::opset3::ScatterUpdate::type_info, {1000, 256, 10, 15}, {125, 20}, {1000, 125, 20, 10, 15}, 1}), + ScatterTestCase{ + ngraph::opset3::ScatterUpdate::type_info, + {{84, 256, 7, 7}, {100, 256, 7, 7}}, + {{84}, {100}}, + {{84, 256, 7, 7}, {100, 256, 7, 7}}, + 0}), ::testing::Values(CommonTestUtils::DEVICE_MYRIAD))); } // namespace diff --git a/inference-engine/tests/functional/plugin/myriad/subgraph_tests/dsr_squeeze.cpp b/inference-engine/tests/functional/plugin/myriad/subgraph_tests/dsr_squeeze.cpp index 278dacf7f5edee..fafd4d5bceeca2 100644 --- a/inference-engine/tests/functional/plugin/myriad/subgraph_tests/dsr_squeeze.cpp +++ b/inference-engine/tests/functional/plugin/myriad/subgraph_tests/dsr_squeeze.cpp @@ -41,9 +41,7 @@ class DSR_Squeeze : public testing::WithParamInterface, public DSR_T const auto axes = std::make_shared( ngraph::element::i64, ngraph::Shape{squeezeAxes.size()}, squeezeAxes); - const auto squeeze = std::make_shared(inputSubgraph, axes); - - return squeeze; + return std::make_shared(inputSubgraph, axes); } }; @@ -53,7 +51,7 @@ TEST_P(DSR_Squeeze, CompareWithReference) { INSTANTIATE_TEST_CASE_P(DynamicSqueeze, DSR_Squeeze, ::testing::Combine( - ::testing::Values(ngraph::element::f16, ngraph::element::f32, ngraph::element::i32), + ::testing::Values(ngraph::element::f16, ngraph::element::i32), ::testing::Values( // input_shape, squeeze_axis SqueezeTestCase{DataShapeWithUpperBound{{1, 1, 1000}, {1, 1, 1500}}, AxisVector{-2}}, diff --git a/inference-engine/tests/functional/plugin/myriad/subgraph_tests/dsr_tests_common.hpp b/inference-engine/tests/functional/plugin/myriad/subgraph_tests/dsr_tests_common.hpp index 19b3f590b66184..dc0d6ab8993f24 100644 --- a/inference-engine/tests/functional/plugin/myriad/subgraph_tests/dsr_tests_common.hpp +++ b/inference-engine/tests/functional/plugin/myriad/subgraph_tests/dsr_tests_common.hpp @@ -50,22 +50,13 @@ class DSR_TestsCommon : virtual public LayerTestsUtils::LayerTestsCommon { m_parameterVector.push_back(inDataShapeParam); const auto dsr = std::make_shared( - inDataParam, inDataShapeParam); + inDataParam, inDataShapeParam, ngraph::vpu::op::DynamicShapeResolverMode::INFER_DYNAMIC_SHAPE); return dsr; } virtual std::shared_ptr createTestedOp() = 0; - void switchDSRMode(const ngraph::vpu::op::DynamicShapeResolverMode& mode) { - for (const auto& op : function->get_ordered_ops()) { - if (const auto dsr = ngraph::as_type_ptr(op)) { - dsr->setMode(mode); - } - } - function->validate_nodes_and_infer_types(); - } - void SetUp() override { SetRefMode(LayerTestsUtils::RefMode::CONSTANT_FOLDING); configuration[InferenceEngine::MYRIAD_DETECT_NETWORK_BATCH] = CONFIG_VALUE(NO); @@ -74,23 +65,15 @@ class DSR_TestsCommon : virtual public LayerTestsUtils::LayerTestsCommon { } const auto testedOp = createTestedOp(); - const auto result = std::make_shared(testedOp); + ngraph::ResultVector results{}; + for (const auto& output : testedOp->outputs()) { + results.emplace_back(std::make_shared(output)); + } function = std::make_shared( - ngraph::NodeVector{result}, + results, m_parameterVector, "DSR-" + std::string(testedOp->get_type_name())); - - // Get the output shape as if it was in a graph with dynamism - switchDSRMode(ngraph::vpu::op::DynamicShapeResolverMode::INFER_DYNAMIC_SHAPE); - const auto outputDynamicShape = testedOp->get_output_partial_shape(0); - - // Switch DSR mode back to INFER_UPPER_BOUND_SHAPE but set dynamic output shape for tested op. - // It is needed to trigger appropriate DTS transformation. - switchDSRMode(ngraph::vpu::op::DynamicShapeResolverMode::INFER_UPPER_BOUND_SHAPE); - testedOp->set_output_type(0, testedOp->get_input_element_type(0), outputDynamicShape); - - ::vpu::DynamicToStaticShape().run_on_function(function); } InferenceEngine::Blob::Ptr GenerateInput(const InferenceEngine::InputInfo& info) const override { @@ -109,12 +92,6 @@ class DSR_TestsCommon : virtual public LayerTestsUtils::LayerTestsCommon { return blob; } - - void Validate() override { - switchDSRMode(ngraph::vpu::op::DynamicShapeResolverMode::INFER_DYNAMIC_SHAPE); - LayerTestsCommon::Validate(); - switchDSRMode(ngraph::vpu::op::DynamicShapeResolverMode::INFER_UPPER_BOUND_SHAPE); - } }; } // namespace vpu diff --git a/inference-engine/tests/functional/plugin/myriad/subgraph_tests/dsr_topk.cpp b/inference-engine/tests/functional/plugin/myriad/subgraph_tests/dsr_topk.cpp index f7a1d0423e35dc..2b2db53b8d8ab8 100644 --- a/inference-engine/tests/functional/plugin/myriad/subgraph_tests/dsr_topk.cpp +++ b/inference-engine/tests/functional/plugin/myriad/subgraph_tests/dsr_topk.cpp @@ -2,37 +2,26 @@ // SPDX-License-Identifier: Apache-2.0 // -#include -#include -#include +#include "dsr_tests_common.hpp" namespace { -using DataType = ngraph::element::Type_t; -using DataDims = ngraph::Shape; +using namespace LayerTestsUtils::vpu; struct TopKTestCase { - ngraph::Shape data_shape; - int64_t k, axis, first_split_point, second_split_point; + DataShapeWithUpperBound dataShapes; + int64_t k; + int64_t axis; }; const auto combinations = testing::Combine( testing::Values( - ngraph::element::f16, - ngraph::element::f32, - ngraph::element::i32, - ngraph::element::i64, - ngraph::element::u8), + ngraph::element::f16), testing::Values( - ngraph::element::i32, - ngraph::element::i64), + ngraph::element::i32), testing::Values( - TopKTestCase{{6}, 5, 0, 0, 0}, - TopKTestCase{{6, 12, 10, 24}, 5, 0, 0, 1}, - TopKTestCase{{6, 12}, 10, 1, 1, 2}, - TopKTestCase{{6, 12, 10, 24}, 7, 3, 3, 4}, - TopKTestCase{{6, 12, 10, 24}, 20, -1, 3, 4}, - TopKTestCase{{6, 12, 10, 24}, 3, -4, 0, 1}), + TopKTestCase{{{12345}, {80000}}, 75, 0}, + TopKTestCase{{{1234}, {4663}}, 70, 0}), testing::Values(CommonTestUtils::DEVICE_MYRIAD)); @@ -43,33 +32,19 @@ using Parameters = std::tuple< LayerTestsUtils::TargetDevice >; -class DSR_TopK_Const : public testing::WithParamInterface, - virtual public LayerTestsUtils::LayerTestsCommon { +class DSR_TopK_Const : public testing::WithParamInterface, public DSR_TestsCommon { protected: - void SetUp() override { + std::shared_ptr createTestedOp() override { const auto& parameters = GetParam(); - const auto& data_type = std::get<0>(parameters); - const auto& idx_type = std::get<1>(parameters); - const auto& topk_setup = std::get<2>(parameters); + const auto& dataType = std::get<0>(parameters); + const auto& idxType = std::get<1>(parameters); + const auto& topkSetup = std::get<2>(parameters); targetDevice = std::get<3>(parameters); - const auto data = std::make_shared(data_type, topk_setup.data_shape); - const auto k = ngraph::opset3::Constant::create(idx_type, {}, std::vector{topk_setup.k}); + const auto inputSubgraph = createInputSubgraphWithDSR(dataType, topkSetup.dataShapes); + const auto k = ngraph::opset3::Constant::create(idxType, {}, std::vector{topkSetup.k}); - const auto dims = std::make_shared(ngraph::element::i64, ngraph::Shape{topk_setup.data_shape.size()}); - - const auto dsr = std::make_shared(data, dims); - const auto node = std::make_shared(dsr, k, topk_setup.axis, "max", "value"); - - // tests are capable to compare functions with one result only, but TopK has 2 of them and they are of different types - ngraph::OutputVector converted; - for (const auto& result : {node->output(0), node->output(1)}) { - converted.push_back(std::make_shared(result, ngraph::element::f32)); - } - const auto tests_wa = std::make_shared(converted, topk_setup.axis); - const auto result = std::make_shared(tests_wa); - function = std::make_shared(ngraph::ResultVector{result}, - ngraph::ParameterVector{data, dims}, "DSR-TopKConst"); + return std::make_shared(inputSubgraph, k, topkSetup.axis, "max", "value"); } }; @@ -77,40 +52,29 @@ TEST_P(DSR_TopK_Const, CompareWithReference) { Run(); } -INSTANTIATE_TEST_CASE_P(DISABLED_DynamicTopKConst, DSR_TopK_Const, combinations); +INSTANTIATE_TEST_CASE_P(DynamicTopKConst, DSR_TopK_Const, combinations); -class DSR_TopK : public testing::WithParamInterface, - virtual public LayerTestsUtils::LayerTestsCommon { +class DSR_TopK : public testing::WithParamInterface, public DSR_TestsCommon { protected: - void SetUp() override { + std::shared_ptr createTestedOp() override { const auto& parameters = GetParam(); - const auto& data_type = std::get<0>(parameters); - const auto& idx_type = std::get<1>(parameters); - const auto& topk_setup = std::get<2>(parameters); + const auto& dataType = std::get<0>(parameters); + const auto& idxType = std::get<1>(parameters); + const auto& topkSetup = std::get<2>(parameters); targetDevice = std::get<3>(parameters); - const auto data = std::make_shared(data_type, topk_setup.data_shape); - const auto dims = std::make_shared(ngraph::element::i64, ngraph::Shape{topk_setup.data_shape.size()}); + const auto inputSubgraph = createInputSubgraphWithDSR(dataType, topkSetup.dataShapes); - const auto gather = std::make_shared(dims, - ngraph::opset3::Constant::create(ngraph::element::i32, {1}, {topk_setup.axis}), - ngraph::opset3::Constant::create(ngraph::element::i32, {1}, {0})); - const auto upper_bound = ngraph::opset3::Constant::create(dims->get_element_type(), {1}, {100}); + const auto gather = std::make_shared( + inputSubgraph->input_value(1), + ngraph::opset3::Constant::create(ngraph::element::i32, {1}, {topkSetup.axis}), + ngraph::opset3::Constant::create(ngraph::element::i32, {1}, {0})); + const auto upper_bound = ngraph::opset3::Constant::create(inputSubgraph->get_input_element_type(1), {1}, {topkSetup.k}); const auto concat = std::make_shared(ngraph::OutputVector{upper_bound, gather}, 0); - const auto k = std::make_shared(concat, ngraph::opset3::Constant::create(ngraph::element::i32, {1}, {0}), false); - - const auto dsr = std::make_shared(data, dims); - const auto node = std::make_shared(dsr, k, topk_setup.axis, "max", "value"); - - // tests are capable to compare functions with one result only, but TopK has 2 of them and they are of different types - ngraph::OutputVector converted; - for (const auto& result : {node->output(0), node->output(1)}) { - converted.push_back(std::make_shared(result, ngraph::element::f32)); - } - const auto tests_wa = std::make_shared(converted, topk_setup.axis); - const auto result = std::make_shared(tests_wa); - function = std::make_shared(ngraph::ResultVector{result}, - ngraph::ParameterVector{data, dims}, "DSR-TopK"); + const auto k = std::make_shared( + concat, ngraph::opset3::Constant::create(ngraph::element::i32, {1}, {0}), false); + + return std::make_shared(inputSubgraph, k, topkSetup.axis, "max", "value"); } }; @@ -118,6 +82,6 @@ TEST_P(DSR_TopK, CompareWithReference) { Run(); } -INSTANTIATE_TEST_CASE_P(DISABLED_DynamicTopKConst, DSR_TopK, combinations); +INSTANTIATE_TEST_CASE_P(DynamicTopKConst, DSR_TopK, combinations); } // namespace diff --git a/inference-engine/tests/functional/plugin/myriad/subgraph_tests/dsr_unsqueeze.cpp b/inference-engine/tests/functional/plugin/myriad/subgraph_tests/dsr_unsqueeze.cpp index a30be20393bc26..40d4989ed8f28d 100644 --- a/inference-engine/tests/functional/plugin/myriad/subgraph_tests/dsr_unsqueeze.cpp +++ b/inference-engine/tests/functional/plugin/myriad/subgraph_tests/dsr_unsqueeze.cpp @@ -2,20 +2,17 @@ // SPDX-License-Identifier: Apache-2.0 // -#include -#include -#include - +#include "dsr_tests_common.hpp" namespace { -using DataType = ngraph::element::Type_t; -using DataDims = ngraph::Shape; -using axis_vec = std::vector; +using namespace LayerTestsUtils::vpu; + +using AxisVector = std::vector; struct UnsqueezeTestCase { - DataDims input_shape; - axis_vec unsqueeze_axes; + DataShapeWithUpperBound inputShapes; + AxisVector unsqueezeAxes; }; using Parameters = std::tuple< @@ -24,28 +21,22 @@ using Parameters = std::tuple< LayerTestsUtils::TargetDevice >; -class DSR_Unsqueeze : public testing::WithParamInterface, virtual public LayerTestsUtils::LayerTestsCommon { +class DSR_Unsqueeze : public testing::WithParamInterface, public DSR_TestsCommon { protected: - void SetUp() override { + std::shared_ptr createTestedOp() override { const auto& parameters = GetParam(); - const auto& data_type = std::get<0>(parameters); - const auto& squeeze_test_case = std::get<1>(parameters); + const auto& dataType = std::get<0>(parameters); + const auto& squeezeTestCase = std::get<1>(parameters); - const auto& input_shape = squeeze_test_case.input_shape; - const auto& unsqueeze_axes = squeeze_test_case.unsqueeze_axes; + const auto& inputShapes = squeezeTestCase.inputShapes; + const auto& unsqueezeAxes = squeezeTestCase.unsqueezeAxes; targetDevice = std::get<2>(GetParam()); - const auto data = std::make_shared(data_type, input_shape); - const auto dims = std::make_shared(ngraph::element::i64, ngraph::Shape{input_shape.size()}); - - const auto dsr = std::make_shared(data, dims); - - const auto axes = std::make_shared(ngraph::element::i64, ngraph::Shape{unsqueeze_axes.size()}, unsqueeze_axes); - const auto node = std::make_shared(dsr, axes); + const auto inputSubgraph = createInputSubgraphWithDSR(dataType, inputShapes); + const auto axes = std::make_shared(ngraph::element::i64, ngraph::Shape{unsqueezeAxes.size()}, unsqueezeAxes); - const auto result = std::make_shared(node); - function = std::make_shared(ngraph::ResultVector{result}, ngraph::ParameterVector{data, dims}, "DSR-Unsqueeze"); + return std::make_shared(inputSubgraph, axes); } }; @@ -53,15 +44,15 @@ TEST_P(DSR_Unsqueeze, CompareWithReference) { Run(); } -INSTANTIATE_TEST_CASE_P(DISABLED_DynamicUnsqueeze, DSR_Unsqueeze, +INSTANTIATE_TEST_CASE_P(DynamicUnsqueeze, DSR_Unsqueeze, ::testing::Combine( - ::testing::Values(ngraph::element::f16, ngraph::element::f32, ngraph::element::i32), + ::testing::Values(ngraph::element::f16, ngraph::element::i32), ::testing::Values( - // input_shape, unsqueeze_axis - UnsqueezeTestCase{DataDims{10, 100, 1000}, axis_vec{-1, -3}}, - UnsqueezeTestCase{DataDims{10, 100, 1000}, axis_vec{0}}, - UnsqueezeTestCase{DataDims{10}, axis_vec{1}}, - UnsqueezeTestCase{DataDims{10}, axis_vec{0}}), + // inputShapes, unsqueezeAxes + UnsqueezeTestCase{DataShapeWithUpperBound{{789, 4}, {1000, 4}}, AxisVector{-1, -3}}, + UnsqueezeTestCase{DataShapeWithUpperBound{{789, 4}, {1000, 4}}, AxisVector{0}}, + UnsqueezeTestCase{DataShapeWithUpperBound{{789, 4}, {1000, 4}}, AxisVector{1}}, + UnsqueezeTestCase{DataShapeWithUpperBound{{789, 4}, {1000, 4}}, AxisVector{2}}), ::testing::Values(CommonTestUtils::DEVICE_MYRIAD))); } // namespace diff --git a/inference-engine/tests/functional/plugin/myriad/subgraph_tests/dsr_variadic_split.cpp b/inference-engine/tests/functional/plugin/myriad/subgraph_tests/dsr_variadic_split.cpp index 3a1f06e7ed1bbc..b1abdf4f764dd5 100644 --- a/inference-engine/tests/functional/plugin/myriad/subgraph_tests/dsr_variadic_split.cpp +++ b/inference-engine/tests/functional/plugin/myriad/subgraph_tests/dsr_variadic_split.cpp @@ -2,39 +2,28 @@ // SPDX-License-Identifier: Apache-2.0 // -#include -#include -#include +#include "dsr_tests_common.hpp" namespace { -using DataType = ngraph::element::Type_t; -using DataDims = ngraph::Shape; - +using namespace LayerTestsUtils::vpu; struct VariadicSplitTestCase { - ngraph::Shape data_shape; - std::vector split_lengths; - int64_t axis, first_split_point, second_split_point; + DataShapeWithUpperBound dataShapes; + std::vector splitLengths; + int64_t axis; }; const auto combinations = testing::Combine( testing::Values( - ngraph::element::f16, - ngraph::element::f32, - ngraph::element::i32, - ngraph::element::i64, - ngraph::element::u8), + ngraph::element::f16), testing::Values( - ngraph::element::i32, - ngraph::element::i64), + ngraph::element::i32), testing::Values( - VariadicSplitTestCase{{6}, {2, 1, 2, 1}, 0, 0, 0}, - VariadicSplitTestCase{{6, 12, 10, 24}, {1, 1, 3, 1}, 0, 0, 1}, - VariadicSplitTestCase{{6, 12}, {7, 2, 1, 2}, 1, 1, 2}, - VariadicSplitTestCase{{6, 12, 10, 24}, {10, 14}, 3, 3, 4}, - VariadicSplitTestCase{{6, 12, 10, 24}, {14, 10}, -1, 3, 4}, - VariadicSplitTestCase{{6, 12, 10, 24}, {6}, -4, 0, 1}), + VariadicSplitTestCase{{{6, 12, 10}, {6, 12, 15}}, {1, 1, 3, 1}, 0}, + VariadicSplitTestCase{{{6, 12}, {10, 12}}, {7, 2, 1, 2}, 1}, + VariadicSplitTestCase{{{6, 12, 10, 24}, {6, 12, 10, 50}}, {4, 6}, 2}, + VariadicSplitTestCase{{{6, 12, 10, 24}, {6, 12, 10, 50}}, {4, 6}, -2}), testing::Values(CommonTestUtils::DEVICE_MYRIAD)); @@ -45,30 +34,22 @@ using Parameters = std::tuple< LayerTestsUtils::TargetDevice >; -class DSR_VariadicSplit : public testing::WithParamInterface, - virtual public LayerTestsUtils::LayerTestsCommon { +class DSR_VariadicSplit : public testing::WithParamInterface, public DSR_TestsCommon { protected: - void SetUp() override { + std::shared_ptr createTestedOp() override { const auto& parameters = GetParam(); - const auto& data_type = std::get<0>(parameters); - const auto& idx_type = std::get<1>(parameters); - const auto& variadic_split_setup = std::get<2>(parameters); + const auto& dataType = std::get<0>(parameters); + const auto& idxType = std::get<1>(parameters); + const auto& variadicSplitSetup = std::get<2>(parameters); targetDevice = std::get<3>(parameters); - const auto data = std::make_shared(data_type, variadic_split_setup.data_shape); - const auto axis = ngraph::opset3::Constant::create(idx_type, {}, std::vector{variadic_split_setup.axis}); - const auto split_lengths = ngraph::opset3::Constant::create(idx_type, - {variadic_split_setup.split_lengths.size()}, std::vector{variadic_split_setup.split_lengths}); - - const auto dims = std::make_shared(ngraph::element::i64, ngraph::Shape{variadic_split_setup.data_shape.size()}); + const auto inputSubgraph = createInputSubgraphWithDSR(dataType, variadicSplitSetup.dataShapes); - const auto dsr = std::make_shared(data, dims); - const auto node = std::make_shared(dsr, axis, split_lengths); + const auto axis = ngraph::opset3::Constant::create(idxType, {}, std::vector{variadicSplitSetup.axis}); + const auto splitLengths = ngraph::opset3::Constant::create(idxType, + {variadicSplitSetup.splitLengths.size()}, std::vector{variadicSplitSetup.splitLengths}); - const auto tests_wa = std::make_shared(node->outputs(), variadic_split_setup.axis); - const auto result = std::make_shared(tests_wa); - function = std::make_shared(ngraph::ResultVector{result}, - ngraph::ParameterVector{data, dims}, "DSR-VariadicSplit"); + return std::make_shared(inputSubgraph, axis, splitLengths); } }; @@ -76,6 +57,6 @@ TEST_P(DSR_VariadicSplit, CompareWithReference) { Run(); } -INSTANTIATE_TEST_CASE_P(DISABLED_DynamicGatherData, DSR_VariadicSplit, combinations); +INSTANTIATE_TEST_CASE_P(DynamicGatherData, DSR_VariadicSplit, combinations); } // namespace diff --git a/inference-engine/tests/unit/vpu/frontend_tests/dsr_parsing_tests.cpp b/inference-engine/tests/unit/vpu/frontend_tests/dsr_parsing_tests.cpp index b4fbbb55b303aa..58045b894b666c 100644 --- a/inference-engine/tests/unit/vpu/frontend_tests/dsr_parsing_tests.cpp +++ b/inference-engine/tests/unit/vpu/frontend_tests/dsr_parsing_tests.cpp @@ -112,6 +112,23 @@ TEST_F(DSRParsingTests, DSRParserDoesntAssertOnCorrectIO) { {inputStage->output(0), inputStage->output(1)}, _testModel.getOutputs())); } +TEST_F(DSRParsingTests, DSRParserDoesntAssertOnTwoOutputsWithSameShapeData) { + _testModel.createInputs({_dataDesc}); + _testModel.createOutputs({_dataDesc, _dataDesc}); + + const auto& inputStage = _testModel.addStage( + {InputInfo::fromNetwork(0)}, + {OutputInfo::intermediate(_dataDesc), OutputInfo::intermediate(_dataDesc), OutputInfo::intermediate(_correstShapeDesc)}); + + const auto& dsrLayer1 = createDSRLayer(); + const auto& dsrLayer2 = createDSRLayer(); + + ASSERT_NO_THROW(frontEnd->parseDSR(_testModel.getBaseModel(), dsrLayer1, + {inputStage->output(0), inputStage->output(2)}, {_testModel.getOutputs()[0]})); + ASSERT_NO_THROW(frontEnd->parseDSR(_testModel.getBaseModel(), dsrLayer2, + {inputStage->output(1), inputStage->output(2)}, {_testModel.getOutputs()[1]})); +} + TEST_F(DSRParsingTests, DSRParserPreservesConnectionsOnOutputDSR) { _testModel.createInputs({_dataDesc}); _testModel.createOutputs({_dataDesc}); From 73a31bad1529c6f02f84e8956008d178803de36b Mon Sep 17 00:00:00 2001 From: Ilya Lavrenov Date: Fri, 18 Sep 2020 06:30:29 +0300 Subject: [PATCH 29/64] Fixed compilation without OpenCV (#2309) --- inference-engine/ie_bridges/c/tests/CMakeLists.txt | 5 ++--- inference-engine/tests/unit/inference_engine/CMakeLists.txt | 2 +- .../tests/unit/inference_engine/saturated_cast_test.cpp | 4 ++++ 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/inference-engine/ie_bridges/c/tests/CMakeLists.txt b/inference-engine/ie_bridges/c/tests/CMakeLists.txt index 4feae6bd93a30b..761c23aee9c2ea 100644 --- a/inference-engine/ie_bridges/c/tests/CMakeLists.txt +++ b/inference-engine/ie_bridges/c/tests/CMakeLists.txt @@ -7,9 +7,8 @@ set(TARGET_NAME "InferenceEngineCAPITests") # Find OpenCV components if exist find_package(OpenCV COMPONENTS imgcodecs videoio imgproc QUIET) if(NOT OpenCV_FOUND) - message(WARNING "OPENCV is disabled or not found, " ${TARGET_NAME} " is built without OPENCV support") -else() - add_definitions(-DUSE_OPENCV) + message(WARNING "OPENCV is disabled or not found, " ${TARGET_NAME} " is disabled") + return() endif() add_executable(${TARGET_NAME} ie_c_api_test.cpp test_model_repo.hpp) diff --git a/inference-engine/tests/unit/inference_engine/CMakeLists.txt b/inference-engine/tests/unit/inference_engine/CMakeLists.txt index e4613f032608f5..a23ca053f83983 100644 --- a/inference-engine/tests/unit/inference_engine/CMakeLists.txt +++ b/inference-engine/tests/unit/inference_engine/CMakeLists.txt @@ -7,7 +7,7 @@ set(TARGET_NAME ieUnitTests) # Find OpenCV components if exist find_package(OpenCV COMPONENTS imgcodecs videoio imgproc QUIET) if(NOT OpenCV_FOUND) - message(ERROR "OPENCV is disabled or not found, " ${TARGET_NAME} " needs OpenCV for its build") + message(WARNING "OPENCV is disabled or not found, " ${TARGET_NAME} " needs OpenCV for its build") else() add_definitions(-DUSE_OPENCV) endif() diff --git a/inference-engine/tests/unit/inference_engine/saturated_cast_test.cpp b/inference-engine/tests/unit/inference_engine/saturated_cast_test.cpp index c89169eb5c70c0..1667fb984fdd0c 100644 --- a/inference-engine/tests/unit/inference_engine/saturated_cast_test.cpp +++ b/inference-engine/tests/unit/inference_engine/saturated_cast_test.cpp @@ -8,6 +8,8 @@ #include "precision_utils.h" #include "ie_precision.hpp" +#ifdef USE_OPENCV + #include using namespace InferenceEngine; @@ -112,3 +114,5 @@ TEST_F(SaturateCastTestsU16ToI32, U16toI32FMaxToNonMax) { const auto value = std::numeric_limits::max(); EXPECT_EQ(PrecisionUtils::saturate_cast(value), cv::saturate_cast(value)); } + +#endif // USE_OPENCV From 93074590de9b58f380da6f6df02a856ac4fad99b Mon Sep 17 00:00:00 2001 From: Evgeny Lazarev Date: Fri, 18 Sep 2020 08:16:14 +0300 Subject: [PATCH 30/64] Updated operations specification documents (2021.2) (#2270) * Updated documentation structure and remove incorrect added files for Acosh-1, Asinh-1 and Atanh-1 * Fixed broken links --- docs/doxygen/ie_docs.xml | 10 ++++--- docs/ops/arithmetic/Acosh_1.md | 50 -------------------------------- docs/ops/arithmetic/Asinh_1.md | 50 -------------------------------- docs/ops/arithmetic/Atanh_1.md | 50 -------------------------------- docs/ops/detection/Proposal_4.md | 2 +- docs/ops/generation/Range_4.md | 2 +- 6 files changed, 8 insertions(+), 156 deletions(-) delete mode 100644 docs/ops/arithmetic/Acosh_1.md delete mode 100644 docs/ops/arithmetic/Asinh_1.md delete mode 100644 docs/ops/arithmetic/Atanh_1.md diff --git a/docs/doxygen/ie_docs.xml b/docs/doxygen/ie_docs.xml index c474141f86c3b6..cb6afcf1801947 100644 --- a/docs/doxygen/ie_docs.xml +++ b/docs/doxygen/ie_docs.xml @@ -102,15 +102,12 @@ - - - @@ -158,8 +155,9 @@ + - + @@ -194,9 +192,13 @@ + + + + diff --git a/docs/ops/arithmetic/Acosh_1.md b/docs/ops/arithmetic/Acosh_1.md deleted file mode 100644 index 2b944da5e8595f..00000000000000 --- a/docs/ops/arithmetic/Acosh_1.md +++ /dev/null @@ -1,50 +0,0 @@ -## Acosh {#openvino_docs_ops_arithmetic_Acosh_1} - -**Versioned name**: *Acosh-1* - -**Category**: Arithmetic unary operation - -**Short description**: *Acosh* performs element-wise hyperbolic inverse cosine (arccosh) operation with given tensor. - -**Attributes**: - - No attributes available. - -**Inputs** - -* **1**: An tensor of type T. **Required.** - -**Outputs** - -* **1**: The result of element-wise acosh operation. A tensor of type T. - -**Types** - -* *T*: any numeric type. - -*Acosh* does the following with the input tensor *a*: - -\f[ -a_{i} = acosh(a_{i}) -\f] - -**Examples** - -*Example 1* - -```xml - - - - 256 - 56 - - - - - 256 - 56 - - - -``` diff --git a/docs/ops/arithmetic/Asinh_1.md b/docs/ops/arithmetic/Asinh_1.md deleted file mode 100644 index 6e407f13525f5e..00000000000000 --- a/docs/ops/arithmetic/Asinh_1.md +++ /dev/null @@ -1,50 +0,0 @@ -## Asinh {#openvino_docs_ops_arithmetic_Asinh_1} - -**Versioned name**: *Asinh-1* - -**Category**: Arithmetic unary operation - -**Short description**: *Asinh* performs element-wise hyperbolic inverse sine (arcsinh) operation with given tensor. - -**Attributes**: - - No attributes available. - -**Inputs** - -* **1**: An tensor of type T. **Required.** - -**Outputs** - -* **1**: The result of element-wise asinh operation. A tensor of type T. - -**Types** - -* *T*: any numeric type. - -*Asinh* does the following with the input tensor *a*: - -\f[ -a_{i} = asinh(a_{i}) -\f] - -**Examples** - -*Example 1* - -```xml - - - - 256 - 56 - - - - - 256 - 56 - - - -``` diff --git a/docs/ops/arithmetic/Atanh_1.md b/docs/ops/arithmetic/Atanh_1.md deleted file mode 100644 index 80c01571b16f09..00000000000000 --- a/docs/ops/arithmetic/Atanh_1.md +++ /dev/null @@ -1,50 +0,0 @@ -## Atanh {#openvino_docs_ops_arithmetic_Atanh_1} - -**Versioned name**: *Atanh-1* - -**Category**: Arithmetic unary operation - -**Short description**: *Atanh* performs element-wise hyperbolic inverse tangent (arctangenth) operation with given tensor. - -**Attributes**: - - No attributes available. - -**Inputs** - -* **1**: An tensor of type T. **Required.** - -**Outputs** - -* **1**: The result of element-wise atanh operation. A tensor of type T. - -**Types** - -* *T*: any numeric type. - -*Atanh* does the following with the input tensor *a*: - -\f[ -a_{i} = atanh(a_{i}) -\f] - -**Examples** - -*Example 1* - -```xml - - - - 256 - 56 - - - - - 256 - 56 - - - -``` diff --git a/docs/ops/detection/Proposal_4.md b/docs/ops/detection/Proposal_4.md index 9281b5a728baf9..8bf9dca4969bff 100644 --- a/docs/ops/detection/Proposal_4.md +++ b/docs/ops/detection/Proposal_4.md @@ -1,4 +1,4 @@ -## Proposal +## Proposal {#openvino_docs_ops_detection_Proposal_4} **Versioned name**: *Proposal-4* diff --git a/docs/ops/generation/Range_4.md b/docs/ops/generation/Range_4.md index 33e1b7befa4ef8..3314ca4246f7e1 100644 --- a/docs/ops/generation/Range_4.md +++ b/docs/ops/generation/Range_4.md @@ -1,4 +1,4 @@ -## Range +## Range {#openvino_docs_ops_generation_Range_4} **Versioned name**: *Range-4* From f5b071f7fe166dba9a3c5743ba5274f8863729d7 Mon Sep 17 00:00:00 2001 From: Edward Shogulin Date: Fri, 18 Sep 2020 09:43:07 +0300 Subject: [PATCH 31/64] [LPT] MatMul fix --- .../shared/src/single_layer_tests/eltwise.cpp | 6 +- ngraph/core/include/ngraph/op/matmul.hpp | 28 +++------- ngraph/core/src/op/matmul.cpp | 56 ++----------------- ngraph/test/runtime/ie/unit_test.manifest | 6 +- .../runtime/interpreter/unit_test.manifest | 6 +- ngraph/test/type_prop/binary_elementwise.cpp | 7 +-- 6 files changed, 22 insertions(+), 87 deletions(-) diff --git a/inference-engine/tests/functional/plugin/shared/src/single_layer_tests/eltwise.cpp b/inference-engine/tests/functional/plugin/shared/src/single_layer_tests/eltwise.cpp index 6c8064316b9c8a..2ee42921e0dbcd 100644 --- a/inference-engine/tests/functional/plugin/shared/src/single_layer_tests/eltwise.cpp +++ b/inference-engine/tests/functional/plugin/shared/src/single_layer_tests/eltwise.cpp @@ -79,8 +79,8 @@ void EltwiseLayerTest::SetUp() { function = std::make_shared(eltwise, input, "Eltwise"); } -// LPT_SUPPORT: temporary disabled -TEST_P(EltwiseLayerTest, DISABLED_EltwiseTests) { + +TEST_P(EltwiseLayerTest, EltwiseTests) { Run(); } -} // namespace LayerTestsDefinitions +} // namespace LayerTestsDefinitions \ No newline at end of file diff --git a/ngraph/core/include/ngraph/op/matmul.hpp b/ngraph/core/include/ngraph/op/matmul.hpp index b1885ecac020ed..7fd7925031071c 100644 --- a/ngraph/core/include/ngraph/op/matmul.hpp +++ b/ngraph/core/include/ngraph/op/matmul.hpp @@ -34,24 +34,17 @@ namespace ngraph public: NGRAPH_RTTI_DECLARATION; MatMul() = default; -/// \brief Constructs an Matrix Multiplication operation. -/// -/// \param A Matrix A -/// \param B Matrix B -/// \param transpose_a If matrix A should be transposed. -/// \param transpose_b If matrix B should be transposed. -#ifdef LPT_SUPPORT + /// \brief Constructs an Matrix Multiplication operation. + /// + /// \param A Matrix A + /// \param B Matrix B + /// \param transpose_a If matrix A should be transposed. + /// \param transpose_b If matrix B should be transposed. MatMul(const Output& A, const Output& B, const bool& transpose_a = 0, const bool& transpose_b = 0, const element::Type output_type = element::undefined); -#else - MatMul(const Output& A, - const Output& B, - const bool& transpose_a = 0, - const bool& transpose_b = 0); -#endif bool visit_attributes(AttributeVisitor& visitor) override; virtual void pre_validate_and_infer_types() override; @@ -66,18 +59,13 @@ namespace ngraph bool get_transpose_a() const { return m_transpose_a; } bool get_transpose_b() const { return m_transpose_b; } -#ifdef LPT_SUPPORT - void set_output_type(size_t i, - const element::Type& element_type, - const PartialShape& pshape) override; -#endif + + element::Type get_output_type() const { return m_output_type; } private: bool m_transpose_a; bool m_transpose_b; -#ifdef LPT_SUPPORT element::Type m_output_type; -#endif }; } using v0::MatMul; diff --git a/ngraph/core/src/op/matmul.cpp b/ngraph/core/src/op/matmul.cpp index c6aed35e01c340..99b2a30bea7746 100644 --- a/ngraph/core/src/op/matmul.cpp +++ b/ngraph/core/src/op/matmul.cpp @@ -31,7 +31,6 @@ NGRAPH_SUPPRESS_DEPRECATED_START NGRAPH_RTTI_DEFINITION(op::MatMul, "MatMul", 0); -#ifdef LPT_SUPPORT op::MatMul::MatMul(const Output& A, const Output& B, const bool& transpose_a, @@ -44,18 +43,6 @@ op::MatMul::MatMul(const Output& A, { constructor_validate_and_infer_types(); } -#else -op::MatMul::MatMul(const Output& A, - const Output& B, - const bool& transpose_a, - const bool& transpose_b) - : FusedOp(OutputVector{A, B}) - , m_transpose_a{transpose_a} - , m_transpose_b{transpose_b} -{ - constructor_validate_and_infer_types(); -} -#endif bool ngraph::op::v0::MatMul::visit_attributes(AttributeVisitor& visitor) { @@ -66,12 +53,8 @@ bool ngraph::op::v0::MatMul::visit_attributes(AttributeVisitor& visitor) void op::MatMul::pre_validate_and_infer_types() { -#ifdef LPT_SUPPORT - const element::Type inputElementType0 = get_input_element_type(0); - const element::Type inputElementType1 = get_input_element_type(1); element::Type result_et; - if ((inputElementType0 != element::u8) && (inputElementType1 != element::i8)) - { + if (m_output_type == element::undefined) { NODE_VALIDATION_CHECK( this, element::Type::merge(result_et, get_input_element_type(0), get_input_element_type(1)), @@ -80,33 +63,13 @@ void op::MatMul::pre_validate_and_infer_types() ", arg1 element type: ", get_input_element_type(1), ")."); + } else { + result_et = m_output_type; } -#else - element::Type result_et; - NODE_VALIDATION_CHECK( - this, - element::Type::merge(result_et, get_input_element_type(0), get_input_element_type(1)), - "Arguments do not have the same element type (arg0 element type: ", - get_input_element_type(0), - ", arg1 element type: ", - get_input_element_type(1), - ")."); -#endif const Rank& A_rank = get_input_partial_shape(0).rank(); const Rank& B_rank = get_input_partial_shape(1).rank(); -#ifdef LPT_SUPPORT - if (A_rank.is_static() && B_rank.is_static()) - { - Rank max_rank = A_rank.get_length() > B_rank.get_length() ? A_rank : B_rank; - set_output_type(0, - ((inputElementType0 != element::u8) && (inputElementType1 != element::i8)) - ? result_et - : element::f32, - PartialShape::dynamic(max_rank)); - } -#else if (A_rank.is_static() && B_rank.is_static()) { Rank max_rank = A_rank.get_length() > B_rank.get_length() ? A_rank : B_rank; @@ -116,7 +79,6 @@ void op::MatMul::pre_validate_and_infer_types() { set_output_type(0, result_et, PartialShape::dynamic()); } -#endif } OutputVector op::MatMul::decompose_op() const @@ -152,7 +114,7 @@ OutputVector op::MatMul::decompose_op() const shared_ptr op::MatMul::clone_with_new_inputs(const OutputVector& new_args) const { check_new_args_count(this, new_args); - return make_shared(new_args.at(0), new_args.at(1), m_transpose_a, m_transpose_b); + return make_shared(new_args.at(0), new_args.at(1), m_transpose_a, m_transpose_b, m_output_type); } namespace @@ -282,13 +244,3 @@ bool op::MatMul::evaluate(const HostTensorVector& outputs, const HostTensorVecto OV_ITT_SCOPED_TASK(itt::domains::nGraphOp, "op::MatMul::evaluate"); return evaluate_matmul(inputs[0], inputs[1], outputs[0], get_transpose_a(), get_transpose_b()); } - -#ifdef LPT_SUPPORT -void op::MatMul::set_output_type(size_t i, - const element::Type& element_type, - const PartialShape& pshape) -{ - FusedOp::set_output_type( - i, m_output_type == element::undefined ? element_type : m_output_type, pshape); -} -#endif diff --git a/ngraph/test/runtime/ie/unit_test.manifest b/ngraph/test/runtime/ie/unit_test.manifest index cf7faf1e360f4d..8acaead855f625 100644 --- a/ngraph/test/runtime/ie/unit_test.manifest +++ b/ngraph/test/runtime/ie/unit_test.manifest @@ -11,9 +11,9 @@ #------------------------------------------------------------------------------- # LPT_SUPPORT: temporary disabling -onnx_model_gemm_abc -reduce_sum_keep_5d_to_scalar_int32 -et_dynamic_shape_static_validation_fails +# onnx_model_gemm_abc +# reduce_sum_keep_5d_to_scalar_int32 +# et_dynamic_shape_static_validation_fails # Quantize layer input 'Multiply_7' doesn't have blobs onnx_model_quantize_linear diff --git a/ngraph/test/runtime/interpreter/unit_test.manifest b/ngraph/test/runtime/interpreter/unit_test.manifest index b54634c193745e..b05313131eed10 100644 --- a/ngraph/test/runtime/interpreter/unit_test.manifest +++ b/ngraph/test/runtime/interpreter/unit_test.manifest @@ -1,7 +1,7 @@ # LPT_SUPPORT: temporary disabling -onnx_model_gemm_abc -reduce_sum_keep_5d_to_scalar_int32 -et_dynamic_shape_static_validation_fails +# onnx_model_gemm_abc +# reduce_sum_keep_5d_to_scalar_int32 +# et_dynamic_shape_static_validation_fails tile_3d_small_data_rank tile_3d_few_repeats diff --git a/ngraph/test/type_prop/binary_elementwise.cpp b/ngraph/test/type_prop/binary_elementwise.cpp index cfea182bee192c..3d1211c999d980 100644 --- a/ngraph/test/type_prop/binary_elementwise.cpp +++ b/ngraph/test/type_prop/binary_elementwise.cpp @@ -82,7 +82,6 @@ void test_binary(std::string /* node_type */, test_binary_good_arguments(tv0_2_4_param_0, tv0_2_4_param_1); } -// LPT_SUPPORT: temporary disabled TEST(type_prop, add_bad_arguments) { test_binary("Add", @@ -91,7 +90,6 @@ TEST(type_prop, add_bad_arguments) }); } -// LPT_SUPPORT: temporary disabled TEST(type_prop, divide_bad_arguments) { test_binary("Divide", @@ -100,7 +98,6 @@ TEST(type_prop, divide_bad_arguments) }); } -// LPT_SUPPORT: temporary disabled TEST(type_prop, multiply_bad_arguments) { test_binary("Multiply", @@ -109,7 +106,6 @@ TEST(type_prop, multiply_bad_arguments) }); } -// LPT_SUPPORT: temporary disabled TEST(type_prop, subtract_bad_arguments) { test_binary("Subtract", @@ -528,8 +524,7 @@ TEST(type_prop, binary_elementwise_arithmetic_right_et_dynamic) ASSERT_EQ(add->get_output_element_type(0), element::i64); } -// LPT_SUPPORT: temporary disabled -TEST(DISABLED_type_prop, logic_arith_compare_partial_et) +TEST(type_prop, logic_arith_compare_partial_et) { auto test_arith = [](element::Type et0, element::Type et1) -> std::shared_ptr { auto param0 = std::make_shared(et0, Shape{1, 2, 3}); From 1b7dfc6e4c8efbac04a9d2dc57eca90641e387f1 Mon Sep 17 00:00:00 2001 From: Ivan Tikhonov Date: Fri, 18 Sep 2020 10:14:01 +0300 Subject: [PATCH 32/64] Fix bidirectional mode in reference implementations of GRU/LSTM/RNN Sequences (#2264) * fix bidirectional case in references of sequences ops, enable decomposition of bidirectional cases in CommonOptimizations * introduce new opset5, include GRU/RNN/LSTM Sequences to opset5 * Revert "introduce new opset5, include GRU/RNN/LSTM Sequences to opset5" This reverts commit 73c22a11dbd724d2cfa9212ff211db74ef09cf2a. --- .../bidirectional_sequences_decomposition.cpp | 9 + .../common_optimizations.cpp | 4 + .../src/single_layer_tests/gru_sequence.cpp | 5 - .../src/single_layer_tests/lstm_sequence.cpp | 5 - .../src/single_layer_tests/rnn_sequence.cpp | 5 - .../ngraph/runtime/reference/sequences.hpp | 173 +++++++++++------- 6 files changed, 117 insertions(+), 84 deletions(-) diff --git a/inference-engine/src/transformations/src/transformations/bidirectional_sequences_decomposition.cpp b/inference-engine/src/transformations/src/transformations/bidirectional_sequences_decomposition.cpp index 281d470fa14c06..1df3c61f7c1f5a 100644 --- a/inference-engine/src/transformations/src/transformations/bidirectional_sequences_decomposition.cpp +++ b/inference-engine/src/transformations/src/transformations/bidirectional_sequences_decomposition.cpp @@ -19,6 +19,9 @@ ngraph::pass::BidirectionalLSTMSequenceDecomposition::BidirectionalLSTMSequenceD return false; } + if (lstm_sequence->get_direction() != ngraph::op::RecurrentSequenceDirection::BIDIRECTIONAL) + return false; + auto axis_0 = ngraph::opset4::Constant::create(element::i64, Shape{}, {0}); auto axis_1 = ngraph::opset4::Constant::create(element::i64, Shape{}, {1}); auto H = std::make_shared(lstm_sequence->input_value(1), axis_1, 2); @@ -84,6 +87,9 @@ ngraph::pass::BidirectionalGRUSequenceDecomposition::BidirectionalGRUSequenceDec return false; } + if (gru_sequence->get_direction() != ngraph::op::RecurrentSequenceDirection::BIDIRECTIONAL) + return false; + auto axis_0 = ngraph::opset4::Constant::create(element::i64, Shape{}, {0}); auto axis_1 = ngraph::opset4::Constant::create(element::i64, Shape{}, {1}); auto H = std::make_shared(gru_sequence->input_value(1), axis_1, 2); @@ -145,6 +151,9 @@ ngraph::pass::BidirectionalRNNSequenceDecomposition::BidirectionalRNNSequenceDec return false; } + if (rnn_sequence->get_direction() != ngraph::op::RecurrentSequenceDirection::BIDIRECTIONAL) + return false; + auto axis_0 = ngraph::opset4::Constant::create(element::i64, Shape{}, {0}); auto axis_1 = ngraph::opset4::Constant::create(element::i64, Shape{}, {1}); auto H = std::make_shared(rnn_sequence->input_value(1), axis_1, 2); diff --git a/inference-engine/src/transformations/src/transformations/common_optimizations/common_optimizations.cpp b/inference-engine/src/transformations/src/transformations/common_optimizations/common_optimizations.cpp index 4ec3c63a867757..e45776a9c78c63 100644 --- a/inference-engine/src/transformations/src/transformations/common_optimizations/common_optimizations.cpp +++ b/inference-engine/src/transformations/src/transformations/common_optimizations/common_optimizations.cpp @@ -21,6 +21,7 @@ #include "transformations/hswish_fusion.hpp" #include "transformations/normalize_l2_fusion.hpp" #include "transformations/convert_quantize_dequantize.hpp" +#include "transformations/bidirectional_sequences_decomposition.hpp" #include #include @@ -50,6 +51,9 @@ bool ngraph::pass::CommonOptimizations::run_on_function(std::shared_ptr(); manager.register_pass(); manager.register_pass(); + manager.register_pass(); + manager.register_pass(); + manager.register_pass(); manager.set_callback(m_transformation_callback); manager.run_passes(f); diff --git a/inference-engine/tests/functional/plugin/shared/src/single_layer_tests/gru_sequence.cpp b/inference-engine/tests/functional/plugin/shared/src/single_layer_tests/gru_sequence.cpp index 1327831a457260..f1d8afee399374 100644 --- a/inference-engine/tests/functional/plugin/shared/src/single_layer_tests/gru_sequence.cpp +++ b/inference-engine/tests/functional/plugin/shared/src/single_layer_tests/gru_sequence.cpp @@ -84,11 +84,6 @@ namespace LayerTestsDefinitions { ngraph::ResultVector results{std::make_shared(gru_sequence->output(0)), std::make_shared(gru_sequence->output(1))}; function = std::make_shared(results, params, "gru_sequence"); - if (direction == ngraph::op::RecurrentSequenceDirection::BIDIRECTIONAL) { - ngraph::pass::Manager m; - m.register_pass(); - m.run_passes(function); - } } diff --git a/inference-engine/tests/functional/plugin/shared/src/single_layer_tests/lstm_sequence.cpp b/inference-engine/tests/functional/plugin/shared/src/single_layer_tests/lstm_sequence.cpp index b1edaa9b0a4b99..d910194540be70 100644 --- a/inference-engine/tests/functional/plugin/shared/src/single_layer_tests/lstm_sequence.cpp +++ b/inference-engine/tests/functional/plugin/shared/src/single_layer_tests/lstm_sequence.cpp @@ -82,11 +82,6 @@ namespace LayerTestsDefinitions { std::make_shared(lstm_sequence->output(1)), std::make_shared(lstm_sequence->output(2))}; function = std::make_shared(results, params, "lstm_sequence"); - if (direction == ngraph::op::RecurrentSequenceDirection::BIDIRECTIONAL) { - ngraph::pass::Manager m; - m.register_pass(); - m.run_passes(function); - } } diff --git a/inference-engine/tests/functional/plugin/shared/src/single_layer_tests/rnn_sequence.cpp b/inference-engine/tests/functional/plugin/shared/src/single_layer_tests/rnn_sequence.cpp index 63f9e85002686c..90ac191c738ce6 100644 --- a/inference-engine/tests/functional/plugin/shared/src/single_layer_tests/rnn_sequence.cpp +++ b/inference-engine/tests/functional/plugin/shared/src/single_layer_tests/rnn_sequence.cpp @@ -82,11 +82,6 @@ namespace LayerTestsDefinitions { ngraph::ResultVector results{std::make_shared(rnn_sequence->output(0)), std::make_shared(rnn_sequence->output(1))}; function = std::make_shared(results, params, "rnn_sequence"); - if (direction == ngraph::op::RecurrentSequenceDirection::BIDIRECTIONAL) { - ngraph::pass::Manager m; - m.register_pass(); - m.run_passes(function); - } } diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/sequences.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/sequences.hpp index e236bbdb57460f..894f1c39d07c36 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/sequences.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/sequences.hpp @@ -218,15 +218,15 @@ namespace ngraph // Split bidirectional case to forward + reverse passes. // split inputs std::vector> H_split( - 2, std::vector(ngraph::shape_size(H_shape) / 2)); + 2, std::vector(sizeof(T) * ngraph::shape_size(H_shape) / 2)); std::vector> C_split( - 2, std::vector(ngraph::shape_size(C_shape) / 2)); + 2, std::vector(sizeof(T) * ngraph::shape_size(C_shape) / 2)); std::vector> W_split( - 2, std::vector(ngraph::shape_size(W_shape) / 2)); + 2, std::vector(sizeof(T) * ngraph::shape_size(W_shape) / 2)); std::vector> R_split( - 2, std::vector(ngraph::shape_size(R_shape) / 2)); + 2, std::vector(sizeof(T) * ngraph::shape_size(R_shape) / 2)); std::vector> B_split( - 2, std::vector(ngraph::shape_size(B_shape) / 2)); + 2, std::vector(sizeof(T) * ngraph::shape_size(B_shape) / 2)); char* h_pointers[2] = {H_split[0].data(), H_split[1].data()}; char* c_pointers[2] = {C_split[0].data(), C_split[1].data()}; char* w_pointers[2] = {W_split[0].data(), W_split[1].data()}; @@ -234,13 +234,17 @@ namespace ngraph char* b_pointers[2] = {B_split[0].data(), B_split[1].data()}; reference::split(H, H_shape, sizeof(T), 1, 2, h_pointers); reference::split(C, C_shape, sizeof(T), 1, 2, c_pointers); - reference::split(W, W_shape, sizeof(T), 1, 2, w_pointers); - reference::split(R, R_shape, sizeof(T), 1, 2, r_pointers); - reference::split(B, B_shape, sizeof(T), 1, 2, b_pointers); + reference::split(W, W_shape, sizeof(T), 0, 2, w_pointers); + reference::split(R, R_shape, sizeof(T), 0, 2, r_pointers); + reference::split(B, B_shape, sizeof(T), 0, 2, b_pointers); + std::vector forward_res_y(sizeof(T) * H_shape[0] * H_shape[2] * + X_shape[1]); + std::vector reverse_res_y(sizeof(T) * H_shape[0] * H_shape[2] * + X_shape[1]); std::vector> forward_res( - 3, std::vector(H_shape[0] * H_shape[2])); + 2, std::vector(sizeof(T) * H_shape[0] * H_shape[2])); std::vector> reverse_res( - 3, std::vector(H_shape[0] * H_shape[2])); + 2, std::vector(sizeof(T) * H_shape[0] * H_shape[2])); CellArgs args; args.activation_f = activation_f; @@ -249,6 +253,13 @@ namespace ngraph args.clip = clip; std::vector shapes = { X_shape, seq_lengths_shape, H_shape, C_shape, W_shape, R_shape, B_shape}; + // update H,C,W,R,B shapes after split + shapes[2][1] = 1; + shapes[3][1] = 1; + for (int i = 4; i < shapes.size(); ++i) + { + shapes[i][0] = 1; + } // forward pass cell_pass( CellType::LSTM, @@ -260,7 +271,7 @@ namespace ngraph r_pointers[0], b_pointers[0]}, shapes, - {forward_res[0].data(), forward_res[1].data(), forward_res[2].data()}, + {forward_res_y.data(), forward_res[0].data(), forward_res[1].data()}, args, false); // reverse pass @@ -274,32 +285,34 @@ namespace ngraph r_pointers[1], b_pointers[1]}, shapes, - {reverse_res[0].data(), reverse_res[1].data(), reverse_res[2].data()}, + {reverse_res_y.data(), reverse_res[0].data(), reverse_res[1].data()}, args, true); // Stack together respective outputs from both forward and reverse passes. - std::vector in_shapes = {{H_shape[0], 1, H_shape[2]}, - {H_shape[0], 1, H_shape[2]}, - {H_shape[0], 1, H_shape[2]}}; - Shape output_shape = {{H_shape[0], 2, H_shape[2]}}; + std::vector in_shapes_y = {{H_shape[0], 1, X_shape[1], H_shape[2]}, + {H_shape[0], 1, X_shape[1], H_shape[2]}}; + std::vector in_shapes_h_c = {{H_shape[0], 1, H_shape[2]}, + {H_shape[0], 1, H_shape[2]}}; + Shape output_shape_y{H_shape[0], 2, X_shape[1], H_shape[2]}; + Shape output_shape_h_c{H_shape[0], 2, H_shape[2]}; - runtime::reference::concat({forward_res[0].data(), reverse_res[0].data()}, + runtime::reference::concat({forward_res_y.data(), reverse_res_y.data()}, Y, - in_shapes, - output_shape, + in_shapes_y, + output_shape_y, 1, sizeof(T)); - runtime::reference::concat({forward_res[1].data(), reverse_res[1].data()}, + runtime::reference::concat({forward_res[0].data(), reverse_res[0].data()}, Ho, - in_shapes, - output_shape, + in_shapes_h_c, + output_shape_h_c, 1, sizeof(T)); - runtime::reference::concat({forward_res[2].data(), reverse_res[2].data()}, + runtime::reference::concat({forward_res[1].data(), reverse_res[1].data()}, Co, - in_shapes, - output_shape, + in_shapes_h_c, + output_shape_h_c, 1, sizeof(T)); } @@ -351,25 +364,27 @@ namespace ngraph // Split bidirectional case to forward + reverse passes. // split inputs std::vector> H_split( - 2, std::vector(ngraph::shape_size(H_shape) / 2)); + 2, std::vector(sizeof(T) * ngraph::shape_size(H_shape) / 2)); std::vector> W_split( - 2, std::vector(ngraph::shape_size(W_shape) / 2)); + 2, std::vector(sizeof(T) * ngraph::shape_size(W_shape) / 2)); std::vector> R_split( - 2, std::vector(ngraph::shape_size(R_shape) / 2)); + 2, std::vector(sizeof(T) * ngraph::shape_size(R_shape) / 2)); std::vector> B_split( - 2, std::vector(ngraph::shape_size(B_shape) / 2)); + 2, std::vector(sizeof(T) * ngraph::shape_size(B_shape) / 2)); char* h_pointers[2] = {H_split[0].data(), H_split[1].data()}; char* w_pointers[2] = {W_split[0].data(), W_split[1].data()}; char* r_pointers[2] = {R_split[0].data(), R_split[1].data()}; char* b_pointers[2] = {B_split[0].data(), B_split[1].data()}; reference::split(H, H_shape, sizeof(T), 1, 2, h_pointers); - reference::split(W, W_shape, sizeof(T), 1, 2, w_pointers); - reference::split(R, R_shape, sizeof(T), 1, 2, r_pointers); - reference::split(B, B_shape, sizeof(T), 1, 2, b_pointers); - std::vector> forward_res( - 2, std::vector(H_shape[0] * H_shape[2])); - std::vector> reverse_res( - 2, std::vector(H_shape[0] * H_shape[2])); + reference::split(W, W_shape, sizeof(T), 0, 2, w_pointers); + reference::split(R, R_shape, sizeof(T), 0, 2, r_pointers); + reference::split(B, B_shape, sizeof(T), 0, 2, b_pointers); + std::vector forward_res_y(sizeof(T) * H_shape[0] * H_shape[2] * + X_shape[1]); + std::vector forward_res_h(sizeof(T) * H_shape[0] * H_shape[2]); + std::vector reverse_res_y(sizeof(T) * H_shape[0] * H_shape[2] * + X_shape[1]); + std::vector reverse_res_h(sizeof(T) * H_shape[0] * H_shape[2]); CellArgs args; args.activation_f = activation_f; @@ -378,6 +393,12 @@ namespace ngraph args.clip = clip; std::vector shapes = { X_shape, seq_lengths_shape, H_shape, W_shape, R_shape, B_shape}; + // update H,W,R,B shapes after split + shapes[2][1] = 1; + for (int i = 3; i < shapes.size(); ++i) + { + shapes[i][0] = 1; + } // forward pass cell_pass(CellType::GRU, {X, @@ -387,7 +408,7 @@ namespace ngraph r_pointers[0], b_pointers[0]}, shapes, - {forward_res[0].data(), forward_res[1].data()}, + {forward_res_y.data(), forward_res_h.data()}, args, false); // reverse pass @@ -399,25 +420,28 @@ namespace ngraph r_pointers[1], b_pointers[1]}, shapes, - {reverse_res[0].data(), reverse_res[1].data()}, + {reverse_res_y.data(), reverse_res_h.data()}, args, true); // Stack together respective outputs from both forward and reverse passes. - std::vector in_shapes = {{H_shape[0], 1, H_shape[2]}, - {H_shape[0], 1, H_shape[2]}}; - Shape output_shape = {{H_shape[0], 2, H_shape[2]}}; + std::vector in_shapes_y = {{H_shape[0], 1, X_shape[1], H_shape[2]}, + {H_shape[0], 1, X_shape[1], H_shape[2]}}; + std::vector in_shapes_h = {{H_shape[0], 1, H_shape[2]}, + {H_shape[0], 1, H_shape[2]}}; + Shape output_shape_y{H_shape[0], 2, X_shape[1], H_shape[2]}; + Shape output_shape_h{H_shape[0], 2, H_shape[2]}; - runtime::reference::concat({forward_res[0].data(), reverse_res[0].data()}, + runtime::reference::concat({forward_res_y.data(), reverse_res_y.data()}, Y, - in_shapes, - output_shape, + in_shapes_y, + output_shape_y, 1, sizeof(T)); - runtime::reference::concat({forward_res[1].data(), reverse_res[1].data()}, + runtime::reference::concat({forward_res_h.data(), reverse_res_h.data()}, Ho, - in_shapes, - output_shape, + in_shapes_h, + output_shape_h, 1, sizeof(T)); } @@ -465,31 +489,39 @@ namespace ngraph // Split bidirectional case to forward + reverse passes. // split inputs std::vector> H_split( - 2, std::vector(ngraph::shape_size(H_shape) / 2)); + 2, std::vector(sizeof(T) * ngraph::shape_size(H_shape) / 2)); std::vector> W_split( - 2, std::vector(ngraph::shape_size(W_shape) / 2)); + 2, std::vector(sizeof(T) * ngraph::shape_size(W_shape) / 2)); std::vector> R_split( - 2, std::vector(ngraph::shape_size(R_shape) / 2)); + 2, std::vector(sizeof(T) * ngraph::shape_size(R_shape) / 2)); std::vector> B_split( - 2, std::vector(ngraph::shape_size(B_shape) / 2)); + 2, std::vector(sizeof(T) * ngraph::shape_size(B_shape) / 2)); char* h_pointers[2] = {H_split[0].data(), H_split[1].data()}; char* w_pointers[2] = {W_split[0].data(), W_split[1].data()}; char* r_pointers[2] = {R_split[0].data(), R_split[1].data()}; char* b_pointers[2] = {B_split[0].data(), B_split[1].data()}; reference::split(H, H_shape, sizeof(T), 1, 2, h_pointers); - reference::split(W, W_shape, sizeof(T), 1, 2, w_pointers); - reference::split(R, R_shape, sizeof(T), 1, 2, r_pointers); - reference::split(B, B_shape, sizeof(T), 1, 2, b_pointers); - std::vector> forward_res( - 2, std::vector(H_shape[0] * H_shape[2])); - std::vector> reverse_res( - 2, std::vector(H_shape[0] * H_shape[2])); + reference::split(W, W_shape, sizeof(T), 0, 2, w_pointers); + reference::split(R, R_shape, sizeof(T), 0, 2, r_pointers); + reference::split(B, B_shape, sizeof(T), 0, 2, b_pointers); + std::vector forward_res_y(sizeof(T) * H_shape[0] * H_shape[2] * + X_shape[1]); + std::vector forward_res_h(sizeof(T) * H_shape[0] * H_shape[2]); + std::vector reverse_res_y(sizeof(T) * H_shape[0] * H_shape[2] * + X_shape[1]); + std::vector reverse_res_h(sizeof(T) * H_shape[0] * H_shape[2]); CellArgs args; args.activation_f = activation_f; args.clip = clip; std::vector shapes = { X_shape, seq_lengths_shape, H_shape, W_shape, R_shape, B_shape}; + // update H,W,R,B shapes after split + shapes[2][1] = 1; + for (int i = 3; i < shapes.size(); ++i) + { + shapes[i][0] = 1; + } // forward pass cell_pass(CellType::RNN, {X, @@ -499,7 +531,7 @@ namespace ngraph r_pointers[0], b_pointers[0]}, shapes, - {forward_res[0].data(), forward_res[1].data()}, + {forward_res_y.data(), forward_res_h.data()}, args, false); // reverse pass @@ -511,25 +543,28 @@ namespace ngraph r_pointers[1], b_pointers[1]}, shapes, - {reverse_res[0].data(), reverse_res[1].data()}, + {reverse_res_y.data(), reverse_res_h.data()}, args, true); // Stack together respective outputs from both forward and reverse passes. - std::vector in_shapes = {{H_shape[0], 1, H_shape[2]}, - {H_shape[0], 1, H_shape[2]}}; - Shape output_shape = {{H_shape[0], 2, H_shape[2]}}; + std::vector in_shapes_y = {{H_shape[0], 1, X_shape[1], H_shape[2]}, + {H_shape[0], 1, X_shape[1], H_shape[2]}}; + std::vector in_shapes_h = {{H_shape[0], 1, H_shape[2]}, + {H_shape[0], 1, H_shape[2]}}; + Shape output_shape_y{H_shape[0], 2, X_shape[1], H_shape[2]}; + Shape output_shape_h{H_shape[0], 2, H_shape[2]}; - runtime::reference::concat({forward_res[0].data(), reverse_res[0].data()}, + runtime::reference::concat({forward_res_y.data(), reverse_res_y.data()}, Y, - in_shapes, - output_shape, + in_shapes_y, + output_shape_y, 1, sizeof(T)); - runtime::reference::concat({forward_res[1].data(), reverse_res[1].data()}, + runtime::reference::concat({forward_res_h.data(), reverse_res_h.data()}, Ho, - in_shapes, - output_shape, + in_shapes_h, + output_shape_h, 1, sizeof(T)); } From a34b6e38f3758722b88875f05c1c1198c8c94484 Mon Sep 17 00:00:00 2001 From: Mateusz Tabaka Date: Fri, 18 Sep 2020 09:56:11 +0200 Subject: [PATCH 33/64] =?UTF-8?q?ConvertPrecision=20-=20saturate=20Constan?= =?UTF-8?q?t's=20value=20to=20std::numeric=5Flimits::lowest() if it's below that limit. * Remove clamping to std::numeric_limits::lowest() in U32/U64 case --- .../src/transformations/convert_precision.cpp | 37 ++++++++--- .../transformations/convert_precision.cpp | 63 ++++++++++++++++++- 2 files changed, 92 insertions(+), 8 deletions(-) diff --git a/inference-engine/src/transformations/src/transformations/convert_precision.cpp b/inference-engine/src/transformations/src/transformations/convert_precision.cpp index 132cf9691e5d34..41804a03057695 100644 --- a/inference-engine/src/transformations/src/transformations/convert_precision.cpp +++ b/inference-engine/src/transformations/src/transformations/convert_precision.cpp @@ -297,8 +297,36 @@ bool extend_select_type(std::shared_ptr & node, ngraph::element::T return false; } +template +inline dst_type convert_value(src_type val) { + if (val > std::numeric_limits::max()) { + return std::numeric_limits::max(); + } else if (val < std::numeric_limits::lowest()) { + return std::numeric_limits::lowest(); + } + return static_cast(val); +} + +// We need to treat U64->I32 and U32->I32 as a separate case, because of C++'s implicit promotion from signed to unsigned, +// and we don't need to compare and clamp the input to std::numeric_limits::lowest() +template <> +inline int32_t convert_value(uint64_t val) { + if (val > std::numeric_limits::max()) { + return std::numeric_limits::max(); + } + return static_cast(val); +} + +template <> +inline int32_t convert_value(uint32_t val) { + if (val > std::numeric_limits::max()) { + return std::numeric_limits::max(); + } + return static_cast(val); +} + template -std::shared_ptr change_constant_precision(std::shared_ptr & constant) { +static std::shared_ptr change_constant_precision(std::shared_ptr& constant) { using src_type = typename element_type_traits::value_type; using dst_type = typename element_type_traits::value_type; @@ -310,12 +338,7 @@ std::shared_ptr change_constant_precision(std::shared_ptr final_data; for (size_t i = 0; i < size; ++i) { - const auto & val = src_data[i]; - if (val > std::numeric_limits::max()) { - dst_data[i] = std::numeric_limits::max(); - } else { - dst_data[i] = static_cast(val); - } + dst_data[i] = convert_value(src_data[i]); } return new_constant; } diff --git a/inference-engine/tests/functional/inference_engine/transformations/convert_precision.cpp b/inference-engine/tests/functional/inference_engine/transformations/convert_precision.cpp index 6671f346296ec5..d67d67d29ae932 100644 --- a/inference-engine/tests/functional/inference_engine/transformations/convert_precision.cpp +++ b/inference-engine/tests/functional/inference_engine/transformations/convert_precision.cpp @@ -560,4 +560,65 @@ TEST(TransformationTests, ConvertPrecision_Variables) { } ASSERT_FALSE(has_type(f)); -} \ No newline at end of file +} + +template +void constant_convert_test(element::Type_t type_from, element::Type_t type_to, From value, To expected) { + std::shared_ptr f(nullptr); + { + auto c = opset4::Constant::create(type_from, Shape{}, {value}); + f = std::make_shared(NodeVector{c}, ParameterVector{}); + + pass::Manager manager; + manager.register_pass(type_from, type_to); + manager.run_passes(f); + } + auto ops = f->get_ordered_ops(); + auto c = std::dynamic_pointer_cast(ops[0]); + ASSERT_NE(c, nullptr); + + auto actual = c->cast_vector()[0]; + ASSERT_EQ(expected, actual); +} + +TEST(TransformationTests, ConvertPrecision_ConstantConversion_I64MinToI32) { + constant_convert_test(element::Type_t::i64, element::Type_t::i32, + std::numeric_limits::min(), + std::numeric_limits::min()); +} + +TEST(TransformationTests, ConvertPrecision_ConstantConversion_I64MaxToI32) { + constant_convert_test(element::Type_t::i64, element::Type_t::i32, + std::numeric_limits::max(), + std::numeric_limits::max()); +} + +TEST(TransformationTests, ConvertPrecision_ConstantConversion_U64MinToI32) { + constant_convert_test(element::Type_t::u64, element::Type_t::i32, + std::numeric_limits::min(), 0); +} + +TEST(TransformationTests, ConvertPrecision_ConstantConversion_U64MaxToI32) { + constant_convert_test(element::Type_t::u64, element::Type_t::i32, + std::numeric_limits::max(), + std::numeric_limits::max()); +} + +TEST(TransformationTests, ConvertPrecision_ConstantConversion_U64ToI32) { + constant_convert_test(element::Type_t::u64, element::Type_t::i32, 42, 42); +} + +TEST(TransformationTests, ConvertPrecision_ConstantConversion_U32MinToI32) { + constant_convert_test(element::Type_t::u32, element::Type_t::i32, + std::numeric_limits::min(), 0); +} + +TEST(TransformationTests, ConvertPrecision_ConstantConversion_U32MaxToI32) { + constant_convert_test(element::Type_t::u32, element::Type_t::i32, + std::numeric_limits::max(), + std::numeric_limits::max()); +} + +TEST(TransformationTests, ConvertPrecision_ConstantConversion_U32ToI32) { + constant_convert_test(element::Type_t::u32, element::Type_t::i32, 42, 42); +} From a0da3d360c5178adfd5400bb981c31f090f45bb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Do=C5=82bniak?= Date: Fri, 18 Sep 2020 10:08:29 +0200 Subject: [PATCH 34/64] Accept ONNX Constants with empty tensors (#2287) --- .../frontend/onnx_import/src/op/constant.cpp | 18 ++- ngraph/frontend/onnx_import/src/op/resize.cpp | 5 + .../resize11_empty_constant_as_input.prototxt | 119 ++++++++++++++++++ ngraph/test/onnx/onnx_import.in.cpp | 24 ++++ ngraph/test/runtime/ie/unit_test.manifest | 9 -- .../runtime/interpreter/unit_test.manifest | 1 - 6 files changed, 164 insertions(+), 12 deletions(-) create mode 100644 ngraph/test/models/onnx/resize11_empty_constant_as_input.prototxt diff --git a/ngraph/frontend/onnx_import/src/op/constant.cpp b/ngraph/frontend/onnx_import/src/op/constant.cpp index fdaf65f1c1b589..3a1718f6154fe2 100644 --- a/ngraph/frontend/onnx_import/src/op/constant.cpp +++ b/ngraph/frontend/onnx_import/src/op/constant.cpp @@ -15,6 +15,7 @@ //***************************************************************************** #include "constant.hpp" +#include "ngraph/log.hpp" #include "ngraph/op/constant.hpp" #include "onnx_import/core/tensor.hpp" #include "onnx_import/default_opset.hpp" @@ -33,8 +34,21 @@ namespace ngraph inline std::shared_ptr __make_ng_constant(const element::Type& type, const Tensor& tensor) { - return std::make_shared( - type, tensor.get_shape(), tensor.get_data()); + std::shared_ptr constant{nullptr}; + try + { + constant = std::make_shared( + type, tensor.get_shape(), tensor.get_data()); + } + catch (const ngraph::ngraph_error& exc) + { + NGRAPH_WARN << "Could not create an nGraph Constant for an ONNX " + "Constant node. Detailed error:\n" + << exc.what(); + constant = std::make_shared(type, Shape{}, 0); + } + + return constant; } template diff --git a/ngraph/frontend/onnx_import/src/op/resize.cpp b/ngraph/frontend/onnx_import/src/op/resize.cpp index 60547402d9882e..ff288d82d3fa42 100644 --- a/ngraph/frontend/onnx_import/src/op/resize.cpp +++ b/ngraph/frontend/onnx_import/src/op/resize.cpp @@ -278,6 +278,8 @@ namespace ngraph if (inputs.size() == 4) // sizes input is provided { + attrs.shape_calculation_mode = + default_opset::Interpolate::ShapeCalcMode::sizes; const auto& sizes = inputs.at(3); const auto& sizes_shape = sizes.get_partial_shape(); @@ -292,6 +294,9 @@ namespace ngraph data, sizes, scales, attrs)}; } + attrs.shape_calculation_mode = + default_opset::Interpolate::ShapeCalcMode::scales; + const auto& scales = inputs.at(2); const auto& scales_shape = scales.get_partial_shape(); diff --git a/ngraph/test/models/onnx/resize11_empty_constant_as_input.prototxt b/ngraph/test/models/onnx/resize11_empty_constant_as_input.prototxt new file mode 100644 index 00000000000000..b4e397bc1801a6 --- /dev/null +++ b/ngraph/test/models/onnx/resize11_empty_constant_as_input.prototxt @@ -0,0 +1,119 @@ +ir_version: 7 +producer_name: "onnx-importer-test" +graph { + node { + output: "empty_const" + op_type: "Constant" + attribute { + name: "value" + t { + dims: 0 + data_type: 1 + raw_data: "" + } + type: TENSOR + } + } + node { + output: "scales" + op_type: "Constant" + attribute { + name: "value" + t { + dims: 4 + data_type: 1 + float_data: 1.0 + float_data: 1.0 + float_data: 2.0 + float_data: 4.0 + } + type: TENSOR + } + } + node { + input: "X" + input: "empty_const" + input: "scales" + output: "Y" + op_type: "Resize" + attribute { + name: "coordinate_transformation_mode" + s: "asymmetric" + type: STRING + } + attribute { + name: "cubic_coeff_a" + f: -0.75 + type: FLOAT + } + attribute { + name: "exclude_outside" + i: 0 + type: INT + } + attribute { + name: "extrapolation_value" + f: 0 + type: FLOAT + } + attribute { + name: "mode" + s: "linear" + type: STRING + } + attribute { + name: "nearest_mode" + s: "floor" + type: STRING + } + } + name: "test-model" + input { + name: "X" + type { + tensor_type { + elem_type: 1 + shape { + dim { + dim_value: 1 + } + dim { + dim_value: 2 + } + dim { + dim_value: 2 + } + dim { + dim_value: 2 + } + } + } + } + } + output { + name: "Y" + type { + tensor_type { + elem_type: 1 + shape { + dim { + dim_value: 1 + } + dim { + dim_value: 2 + } + dim { + dim_value: 4 + } + dim { + dim_value: 8 + } + } + } + } + } +} +opset_import { + domain: "" + version: 11 +} diff --git a/ngraph/test/onnx/onnx_import.in.cpp b/ngraph/test/onnx/onnx_import.in.cpp index f6336db4f5b407..779de839d43079 100644 --- a/ngraph/test/onnx/onnx_import.in.cpp +++ b/ngraph/test/onnx/onnx_import.in.cpp @@ -1241,6 +1241,30 @@ NGRAPH_TEST(${BACKEND_NAME}, onnx_resize11_scales_nearest_asymmetric_floor) test_case.run(); } +NGRAPH_TEST(${BACKEND_NAME}, onnx_resize11_empty_constant_as_input) +{ + // this model contains a Constant node with an empty underlying tensor + // this node is connected to the "roi" input of the Resize op but this input should be + // ignored since the Resize coordinate_transformation_mode is set to asymmetric + const auto function = onnx_import::import_onnx_model( + file_util::path_join(SERIALIZED_ZOO, "onnx/resize11_empty_constant_as_input.prototxt")); + + auto test_case = test::TestCase(function); + std::vector input_data{1.0f, 3.0f, 4.0f, 8.0f, 6.0f, 2.0f, 7.0f, 11.0f}; + test_case.add_input(input_data); + test_case.add_expected_output( + Shape{1, 2, 4, 8}, + {1.0f, 1.5f, 2.0f, 2.5f, 3.0f, 3.0f, 3.0f, 3.0f, 2.5f, 3.25f, 4.0f, + 4.75f, 5.5f, 5.5f, 5.5f, 5.5f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 8.0f, + 8.0f, 8.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 8.0f, 8.0f, 8.0f, + + 6.0f, 5.0f, 4.0f, 3.0f, 2.0f, 2.0f, 2.0f, 2.0f, 6.5f, 6.5f, 6.5f, + 6.5f, 6.5f, 6.5f, 6.5f, 6.5f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 11.0f, + 11.0f, 11.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 11.0f, 11.0f, 11.0f}); + + test_case.run(); +} + NGRAPH_TEST(${BACKEND_NAME}, onnx_model_shape) { auto function = diff --git a/ngraph/test/runtime/ie/unit_test.manifest b/ngraph/test/runtime/ie/unit_test.manifest index d4b037f9657272..29400589f815dd 100644 --- a/ngraph/test/runtime/ie/unit_test.manifest +++ b/ngraph/test/runtime/ie/unit_test.manifest @@ -1095,12 +1095,6 @@ onnx_model_gru_bidirectional onnx_model_gru_fwd_linear_before_reset # Not implemented Interpolate-4: -IE_CPU.onnx_model_resize10_import_only -IE_CPU.onnx_resize10_down_scales_const_nearest -IE_CPU.onnx_resize10_up_scales_const_linear -IE_CPU.onnx_resize10_up_scales_const_nearest -IE_CPU.onnx_resize11_scales_up_linear_asymmetric -IE_CPU.onnx_resize11_scales_nearest_asymmetric_floor IE_CPU.onnx_model_round IE_CPU.onnx_upsample9_scales_const_linear_infer IE_CPU.onnx_upsample9_scales_const_nearest_infer @@ -1110,10 +1104,7 @@ IE_CPU.interpolate_down_scales_const_linear IE_CPU.onnx_upsample8_import_only IE_CPU.onnx_upsample9_scales_const_import_only IE_CPU.onnx_empty_initializers_handling -IE_CPU.onnx_resize11_scales_down_linear IE_CPU.onnx_resize11_scales_nearest_asymmetric_floor_dynamic_sizes -IE_CPU.onnx_resize11_sizes_nearest_asymmetric_floor -IE_CPU.onnx_resize11_sizes_linear # RNNCell operation has a form that is not supported IE_CPU.onnx_model_rnn_defaults_fwd diff --git a/ngraph/test/runtime/interpreter/unit_test.manifest b/ngraph/test/runtime/interpreter/unit_test.manifest index 4502e97d0dccd6..83872977545eb9 100644 --- a/ngraph/test/runtime/interpreter/unit_test.manifest +++ b/ngraph/test/runtime/interpreter/unit_test.manifest @@ -12,7 +12,6 @@ reduce_sum_keep_large_1d_to_scalar # Temporarily disabled: INTERPRETER.onnx_resize11_scales_nearest_asymmetric_floor_dynamic_sizes -INTERPRETER.onnx_resize11_scales_down_linear INTERPRETER.interpolate_down_scales_const_linear INTERPRETER.onnx_resize10_up_scales_const_nearest INTERPRETER.onnx_resize10_up_scales_const_linear From 8dcff4a741f5370bab905981f0aa65319924a2dd Mon Sep 17 00:00:00 2001 From: Tomasz Jankowski Date: Fri, 18 Sep 2020 10:19:12 +0200 Subject: [PATCH 35/64] fix move assignment operator of Shape class (#2280) --- ngraph/core/src/shape.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ngraph/core/src/shape.cpp b/ngraph/core/src/shape.cpp index 4146f6068a59c9..d615cbb24f5402 100644 --- a/ngraph/core/src/shape.cpp +++ b/ngraph/core/src/shape.cpp @@ -65,7 +65,7 @@ ngraph::Shape& ngraph::Shape::operator=(const Shape& v) ngraph::Shape& ngraph::Shape::operator=(Shape&& v) noexcept { - static_cast*>(this)->operator=(v); + static_cast*>(this)->operator=(std::move(v)); return *this; } From cd391389ceb677f250009163ed16def52f2540eb Mon Sep 17 00:00:00 2001 From: Evgenya Stepyreva Date: Fri, 18 Sep 2020 14:42:16 +0300 Subject: [PATCH 36/64] [ MO ] Complete weights layout permutation (#2299) * MO TF: FQPerChannel extractor * [ MO ] Complete weights layout permutation * removed deleted file out of BOM * Bring back stashed changes * Skip if no weights permutation * Conditional permutation * Comments --- model-optimizer/automation/package_BOM.txt | 1 - .../front/tf/FakeQuantWithMinMaxVars_ext.py | 18 +++ .../extensions/middle/ApplyPermutations.py | 14 ++- .../LayoutChangeForConstantShapePaths.py | 10 +- .../middle/MarkSubgraphsWithCorrectLayout.py | 89 +++++++++++++ .../extensions/middle/quantize_fuses.py | 15 +-- .../middle/weights_permute_normalizer_test.py | 118 ------------------ .../middle/wights_permute_normalizer.py | 51 -------- model-optimizer/extensions/ops/gather.py | 2 +- model-optimizer/extensions/ops/transpose.py | 3 +- model-optimizer/mo/graph/perm_inputs.py | 19 +++ model-optimizer/mo/ops/convolution.py | 6 +- model-optimizer/mo/ops/deconvolution.py | 4 +- 13 files changed, 146 insertions(+), 204 deletions(-) delete mode 100644 model-optimizer/extensions/middle/weights_permute_normalizer_test.py delete mode 100644 model-optimizer/extensions/middle/wights_permute_normalizer.py diff --git a/model-optimizer/automation/package_BOM.txt b/model-optimizer/automation/package_BOM.txt index 9301c42d5fdd35..ae7f4dee408fac 100644 --- a/model-optimizer/automation/package_BOM.txt +++ b/model-optimizer/automation/package_BOM.txt @@ -582,7 +582,6 @@ extensions/middle/UnsqueezeTileReshapeBlockToInterpolate.py extensions/middle/UpsampleToResample.py extensions/middle/UselessMerge.py extensions/middle/UselessSplitEraser.py -extensions/middle/wights_permute_normalizer.py extensions/ops/__init__.py extensions/ops/accum.py extensions/ops/activation_ops.py diff --git a/model-optimizer/extensions/front/tf/FakeQuantWithMinMaxVars_ext.py b/model-optimizer/extensions/front/tf/FakeQuantWithMinMaxVars_ext.py index 302b3a8e3bce38..a9995a975f76c2 100644 --- a/model-optimizer/extensions/front/tf/FakeQuantWithMinMaxVars_ext.py +++ b/model-optimizer/extensions/front/tf/FakeQuantWithMinMaxVars_ext.py @@ -34,3 +34,21 @@ def extract(cls, node): 'narrow_range': narrow_range, 'num_bits': num_bits}) return cls.enabled + + +class FakeQuantWithMinMaxVarsPerChannelExtractor(FrontExtractorOp): + op = 'FakeQuantWithMinMaxVarsPerChannel' + enabled = True + + @classmethod + def extract(cls, node): + narrow_range = node.pb.attr['narrow_range'].b + num_bits = node.pb.attr['num_bits'].i + levels = 2 ** num_bits - int(narrow_range) + + # we prepare this operation to be converted to FakeQuantize op, + # but input reconnection is needed, so we don't set infer function and type attribute + Op.update_node_stat(node, {'op': 'FakeQuantWithMinMaxVars', 'levels': levels, + 'narrow_range': narrow_range, 'num_bits': num_bits}) + + return cls.enabled diff --git a/model-optimizer/extensions/middle/ApplyPermutations.py b/model-optimizer/extensions/middle/ApplyPermutations.py index a065ea4fb205db..afa623f948a438 100644 --- a/model-optimizer/extensions/middle/ApplyPermutations.py +++ b/model-optimizer/extensions/middle/ApplyPermutations.py @@ -24,6 +24,7 @@ from extensions.middle.pass_separator import PostMiddleStart from mo.front.common.partial_infer.utils import int64_array from mo.graph.graph import Graph, Node +from mo.graph.perm_inputs import get_node_with_permutation from mo.graph.port import Port from mo.middle.replacement import MiddleReplacementPattern from mo.utils.error import Error @@ -47,6 +48,7 @@ def find_and_replace_pattern(self, graph: Graph): self.permute_op_nodes_attrs(graph) self.shape_of_sub_graph_reinference(graph) self.permute_input_data(graph) + graph.graph['layout'] = 'NCHW' @staticmethod def merge_nodes_permutations(graph: Graph): @@ -94,7 +96,8 @@ def merge_nodes_permutations(graph: Graph): def permute_data_nodes_attrs(graph: Graph): # Iterate over all data nodes and apply permutation if exists for node in graph.get_data_nodes(): - if not node.has_valid('permutation'): + if not node.has_valid('permutation') or \ + all([attrs.get('input_permutation', False) for u, v, attrs in graph.out_edges(node.id, data=True)]): continue if len( @@ -126,8 +129,6 @@ def permute_op_nodes_attrs(graph: Graph): @staticmethod def permute_input_data(graph: Graph): - if graph.graph['layout'] != 'NHWC': - return for node in graph.get_op_nodes(): input_permutations = [(in_port, edge_attrs['input_permutation']) for in_port, edge_attrs in node.in_edges().items() if edge_attrs.get('input_permutation') is not None] @@ -136,9 +137,12 @@ def permute_input_data(graph: Graph): direction, port = port_info.split(':') port = int(port) port_to_check = node.in_port(port) if direction == 'input' else node.out_port(port) - if not is_input_data_in_correct_layout(node, in_port) and len(port_to_check.data.get_shape()) >= 4: + permutation_data_node = get_node_with_permutation(node, port_info) + + if permutation_data_node.has_and_set('permutation') and \ + not is_input_data_in_correct_layout(node, in_port) and \ + len(port_to_check.data.get_shape()) >= 4: permutation(node, port_info, in_port) - graph.graph['layout'] = 'NCHW' @staticmethod def shape_of_sub_graph_reinference(graph: Graph): diff --git a/model-optimizer/extensions/middle/LayoutChangeForConstantShapePaths.py b/model-optimizer/extensions/middle/LayoutChangeForConstantShapePaths.py index 9748acccfa5fe3..a92e74d682bb48 100644 --- a/model-optimizer/extensions/middle/LayoutChangeForConstantShapePaths.py +++ b/model-optimizer/extensions/middle/LayoutChangeForConstantShapePaths.py @@ -46,13 +46,6 @@ def get_next_in_ports(in_port: Port) -> Set[Port]: next_in_ports.update(out_port.get_destinations()) return next_in_ports - def mark_node_as_in_correct_layout_by_in_port(self, in_port): - next_in_ports = self.get_next_in_ports(in_port) - in_port.__setattr__('input_permutation', None) - mark_input_as_in_correct_layout(in_port.node, in_port.idx) - for port in next_in_ports: - mark_output_as_in_correct_layout(port.get_source().node, port.get_source().idx) - def find_shape_subgraph_endpoints(self, out_ports: List[Port], visited: set = None, action: callable = None) -> Set[Port]: """ @@ -108,8 +101,7 @@ def find_and_replace_pattern(self, graph: Graph): shape.out_port(0).get_connection().insert_node(gather) # 2. Inserting Gather/Transpose to NC* format - shape_sub_graph_end_points = self.find_shape_subgraph_endpoints( - [shape.out_port(0) for shape in shape_ops], None, self.mark_node_as_in_correct_layout_by_in_port) + shape_sub_graph_end_points = self.find_shape_subgraph_endpoints([shape.out_port(0) for shape in shape_ops]) for in_port in shape_sub_graph_end_points: name = in_port.node.soft_get('name', in_port.node.id) shape = in_port.data.get_shape() diff --git a/model-optimizer/extensions/middle/MarkSubgraphsWithCorrectLayout.py b/model-optimizer/extensions/middle/MarkSubgraphsWithCorrectLayout.py index 34c4bff0c2442a..719fc727b24d91 100644 --- a/model-optimizer/extensions/middle/MarkSubgraphsWithCorrectLayout.py +++ b/model-optimizer/extensions/middle/MarkSubgraphsWithCorrectLayout.py @@ -16,10 +16,14 @@ import logging as log from collections import deque +from typing import Set + from extensions.middle.InsertLayoutPropagationTransposes import InsertLayoutPropagationTranspose, \ mark_as_correct_data_layout +from extensions.middle.LayoutChangeForConstantShapePaths import LayoutChangeForConstantShapePaths from extensions.middle.pass_separator import PostMiddleStart from mo.graph.graph import Graph, Node +from mo.graph.port import Port from mo.middle.replacement import MiddleReplacementPattern @@ -121,3 +125,88 @@ def find_and_replace_pattern(self, graph: Graph): for visited_node in marked_nodes: mark_as_correct_data_layout(visited_node) visited_node['nchw_layout'] = True + + for node in self.get_ports_and_nodes_on_weights(graph)[1]: + mark_as_correct_data_layout(node) + node['nchw_layout'] = True + if node.soft_get('type') == 'Const': # WA for Const op deletion during clean_up + node.out_node()['nchw_layout'] = True + + for node in self.get_ports_and_nodes_on_shape_subgraphs(graph)[1]: + mark_as_correct_data_layout(node) + node['nchw_layout'] = True + if node.soft_get('type') == 'Const': # WA for Const op deletion during clean_up + node.out_node()['nchw_layout'] = True + + @staticmethod + def walk_up_from_in_ports_to_out_ports(in_ports: Set[Port], out_ports: Set[Port], + visited_ports: Set[Port] = None, visited_nodes: Set[Node] = None): + """" + Returns all intermediate ports and nodes of such a sub-graph: + + out_ports + | | + \/ \/ + . . . + | | + \/ \/ + in_ports + """ + if visited_ports is None: + visited_ports = set() + if visited_nodes is None: + visited_nodes = set() + + deque_of_in_ports = deque(in_ports) + while len(deque_of_in_ports): + in_port = deque_of_in_ports.popleft() + source_node = in_port.get_source().node + if in_port in visited_ports: # do not check visited_nodes as search is based on ports + continue + visited_ports.update({in_port, in_port.get_source()}) + if in_port.get_source() in out_ports: # reached source marked to stop the search + if not len(in_port.get_source().node.in_ports()): # for Constants and Parameters to be visited + visited_nodes.add(in_port.get_source().node) + continue + deque_of_in_ports.extend([port for port in source_node.in_ports().values() if not port.disconnected()]) + visited_nodes.add(source_node) + return visited_ports, visited_nodes + + @staticmethod + def get_ports_and_nodes_on_weights(graph): + get_weights_port_index = lambda node: node.weights_index if node.has_valid('weights_index') else 1 + weighted_layer_type_to_in_weights_port = { + 'Convolution': get_weights_port_index, + 'DeformableConvolution': get_weights_port_index, + 'Deconvolution': get_weights_port_index, + 'BinaryConvolution': get_weights_port_index, + } + nodes = graph.get_op_nodes() + weighted_types = list(weighted_layer_type_to_in_weights_port.keys()) + + # collect all input ports with weights + weight_ports = set() + start_ports = set() + for node in nodes: + node_type = node.soft_get('type', 'unknown') + if node_type not in weighted_types: + if node_type in ['Const', 'Parameter', 'ShapeOf']: + start_ports.add(node.out_port(0)) + continue + weight_port_idx = weighted_layer_type_to_in_weights_port[node_type](node) + assert node.is_in_port_connected(weight_port_idx), \ + 'Unexpected port configuration of {} node with name=`{}`'.format(node_type, + node.soft_get('name', node.id)) + weight_ports.add(node.in_port(weight_port_idx)) + + # collect all sub-graphs that start with Constant/Parameter/ShapeOf and end at in_port as weights + ports, nodes = MarkSubGraphsWithCorrectLayout.walk_up_from_in_ports_to_out_ports(weight_ports, start_ports) + return ports, nodes + + @staticmethod + def get_ports_and_nodes_on_shape_subgraphs(graph): + shape_sources = {shape_of.out_port(0) for shape_of in graph.get_op_nodes(type='ShapeOf')} + end_points = LayoutChangeForConstantShapePaths().find_shape_subgraph_endpoints( + [shape.out_port(0) for shape in graph.get_op_nodes(type='ShapeOf')]) + ports, nodes = MarkSubGraphsWithCorrectLayout.walk_up_from_in_ports_to_out_ports(end_points, shape_sources) + return ports, nodes diff --git a/model-optimizer/extensions/middle/quantize_fuses.py b/model-optimizer/extensions/middle/quantize_fuses.py index d479bc14a2e294..26f887662fee73 100644 --- a/model-optimizer/extensions/middle/quantize_fuses.py +++ b/model-optimizer/extensions/middle/quantize_fuses.py @@ -124,17 +124,4 @@ def find_and_replace_pattern(self, graph: Graph): port.get_source().connect(fuse_node_duplicate.in_port(idx)) fuse_node_duplicate.infer(fuse_node_duplicate) - first_port_fusion = False - - if 'permutation' in quantize_node.in_edge(0): - permutation = quantize_node.in_edge(0)['permutation'] - if permutation is None: - continue - - perm_rank = permutation.perm.size - - if not all([quantize_node.in_port(i).data.get_shape().size == perm_rank for i in range(1, 5)]): - continue - - for i in range(1, 5): - quantize_node.in_edge(i)['permutation'] = permutation + first_port_fusion = False \ No newline at end of file diff --git a/model-optimizer/extensions/middle/weights_permute_normalizer_test.py b/model-optimizer/extensions/middle/weights_permute_normalizer_test.py deleted file mode 100644 index bfd753a467d1fd..00000000000000 --- a/model-optimizer/extensions/middle/weights_permute_normalizer_test.py +++ /dev/null @@ -1,118 +0,0 @@ -""" - Copyright (C) 2018-2020 Intel Corporation - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -""" -import unittest - -from extensions.middle.wights_permute_normalizer import WeightsPermuteNormalizer -from mo.graph.graph import Node -from mo.utils.unittest.graph import build_graph - -nodes_attributes = { - 'placeholder': {'type': 'Placeholder', 'kind': 'op', 'op': 'Placeholder'}, - 'placeholder_data': {'value': None, 'shape': None, 'kind': 'data'}, - - 'quantize': {'type': 'FakeQuantize', 'kind': 'op', 'op': 'FakeQuantize'}, - 'quantize_data': {'value': None, 'shape': None, 'kind': 'data'}, - - 'const_1': {'type': 'Const', 'kind': 'op', 'op': 'Const'}, - 'const_1_data': {'value': None, 'shape': None, 'kind': 'data'}, - - 'const_2': {'type': 'Const', 'kind': 'op', 'op': 'Const'}, - 'const_2_data': {'value': None, 'shape': None, 'kind': 'data'}, - - 'const_3': {'type': 'Const', 'kind': 'op', 'op': 'Const'}, - 'const_3_data': {'value': None, 'shape': None, 'kind': 'data'}, - - 'const_4': {'type': 'Const', 'kind': 'op', 'op': 'Const'}, - 'const_4_data': {'value': None, 'shape': None, 'kind': 'data'}, - - 'const_5': {'type': 'Const', 'kind': 'op', 'op': 'Const'}, - 'const_5_data': {'value': None, 'shape': None, 'kind': 'data'}, - - 'conv_1': {'type': 'Convolution', 'kind': 'op', 'op': 'Conv2D', 'layout': 'NHWC'}, - 'conv_1_w': {'value': None, 'shape': None, 'kind': 'data'}, - 'conv_1_b': {'value': None, 'shape': None, 'kind': 'data'}, - 'const_conv_1_w': {'value': None, 'shape': None, 'kind': 'op'}, - 'const_conv_1_b': {'value': None, 'shape': None, 'kind': 'op'}, - 'conv_1_data': {'value': None, 'shape': None, 'kind': 'data'}, -} - - -class WeightNormalizationTests(unittest.TestCase): - def test_normalize_weights_test1(self): - # FakeQuantize---,->Conv - # Placeholder--' - graph = build_graph(nodes_attributes, - [('placeholder', 'placeholder_data'), - ('const_1', 'const_1_data'), - ('const_2', 'const_2_data'), - ('const_3', 'const_3_data'), - ('const_4', 'const_4_data'), - ('const_5', 'const_5_data'), - ('quantize', 'quantize_data'), - ('conv_1', 'conv_1_data'), - ('const_1_data', 'quantize'), - ('const_2_data', 'quantize'), - ('const_3_data', 'quantize'), - ('const_4_data', 'quantize'), - ('const_5_data', 'quantize'), - ('placeholder_data', 'conv_1'), - ('quantize_data', 'conv_1', {'in': 1, 'permutation': "[3, 2, 0, 1]"}), - ], - {}, - nodes_with_edges_only=True - ) - - pattern = WeightsPermuteNormalizer() - pattern.find_and_replace_pattern(graph) - - conv = Node(graph, 'conv_1') - quantize = Node(graph, 'quantize') - - self.assertTrue('permutation' in conv.in_edge(1) and conv.in_edge(1)['permutation'] == "[3, 2, 0, 1]") - self.assertTrue('permutation' in quantize.in_edge(0) and quantize.in_edge(0)['permutation'] == "[3, 2, 0, 1]") - - def test_normalize_weights_test2(self): - # Quantize---,->Conv - # Placeholder--' - graph = build_graph(nodes_attributes, - [('placeholder', 'placeholder_data'), - ('const_1', 'const_1_data'), - ('const_2', 'const_2_data'), - ('const_3', 'const_3_data'), - ('const_4', 'const_4_data'), - ('const_5', 'const_5_data'), - ('quantize', 'quantize_data'), - ('conv_1', 'conv_1_data'), - ('const_1_data', 'quantize'), - ('const_2_data', 'quantize'), - ('const_3_data', 'quantize'), - ('const_4_data', 'quantize'), - ('const_5_data', 'quantize'), - ('quantize_data', 'conv_1', {'in': 0}), - ('conv_1_w', 'conv_1', {'in': 1}), - ], - {}, - nodes_with_edges_only=True - ) - - pattern = WeightsPermuteNormalizer() - pattern.find_and_replace_pattern(graph) - - conv = Node(graph, 'conv_1') - quantize = Node(graph, 'quantize') - - self.assertTrue('permutation' not in conv.in_edge(1)) - self.assertTrue('permutation' not in quantize.in_edge(0)) diff --git a/model-optimizer/extensions/middle/wights_permute_normalizer.py b/model-optimizer/extensions/middle/wights_permute_normalizer.py deleted file mode 100644 index a9dd2b013fb70e..00000000000000 --- a/model-optimizer/extensions/middle/wights_permute_normalizer.py +++ /dev/null @@ -1,51 +0,0 @@ -""" - Copyright (C) 2018-2020 Intel Corporation - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -""" - -from mo.graph.graph import Graph -from mo.middle.replacement import MiddleReplacementPattern - - -class WeightsPermuteNormalizer(MiddleReplacementPattern): - """ - We propagate PermuteAttr from weights port of Convolution and MatMul to real Const that contains it - """ - enabled = True - - @staticmethod - def pattern(): - return dict( - nodes=[ - ('const_data', dict(kind='data')), - ('const', dict(type='Const')), - ('quantize', dict(type='FakeQuantize')), - ('quantize_data', dict(kind='data')), - ('conv', dict(type=lambda type: type in ['Convolution', 'MatMul'])), - ], - edges=[ - ('const', 'const_data'), - ('const_data', 'quantize', {'in': 0}), - ('quantize', 'quantize_data'), - ('quantize_data', 'conv', {'in': 1}), - ] - ) - - def replace_pattern(self, graph: Graph, match: dict): - conv = match['conv'] - if 1 not in conv.in_edges() or 'permutation' not in conv.in_edge(1): - return - - perm = conv.in_edge(1)['permutation'] - match['quantize'].in_port(0).permutation = perm diff --git a/model-optimizer/extensions/ops/gather.py b/model-optimizer/extensions/ops/gather.py index 6c444cb52c9a74..ea5410e148aeb2 100644 --- a/model-optimizer/extensions/ops/gather.py +++ b/model-optimizer/extensions/ops/gather.py @@ -60,7 +60,7 @@ def infer(node: Node): assert axis is not None axis = get_canonical_axis_index(data_shape, axis) - # we import PermuteInputs because it uses Gather inside and we have recursive imports + # we import PermuteInputs locally because it uses Gather inside and we have recursive imports from mo.graph.perm_inputs import PermuteInputs PermuteInputs().set_input_permutation(node.in_node(1), node, 'input:0', 'axis') diff --git a/model-optimizer/extensions/ops/transpose.py b/model-optimizer/extensions/ops/transpose.py index 930a57b219f7ed..6cfe3a49b9747e 100644 --- a/model-optimizer/extensions/ops/transpose.py +++ b/model-optimizer/extensions/ops/transpose.py @@ -17,7 +17,6 @@ import numpy as np from mo.graph.graph import Graph -from mo.graph.perm_inputs import PermuteInputs from mo.ops.op import Op @@ -48,6 +47,8 @@ def infer(node): 'Cannot infer `{}` due to both order and reverse_order was set'.format(node.soft_get('name')) order = np.arange(len(input_shape))[::-1] # Reverse order else: + # we import PermuteInputs locally because it uses Transpose inside and we have recursive imports + from mo.graph.perm_inputs import PermuteInputs assert len(connected_ports) == 2 and 0 in in_ports and 1 in in_ports, \ "{} node `{}` should have 2 input ports, where 0-input is a data input and 1-input represents " \ "Transpose `order`".format(node.op, node.id) diff --git a/model-optimizer/mo/graph/perm_inputs.py b/model-optimizer/mo/graph/perm_inputs.py index 16457993119648..b2983ce1b8c9ea 100644 --- a/model-optimizer/mo/graph/perm_inputs.py +++ b/model-optimizer/mo/graph/perm_inputs.py @@ -16,6 +16,7 @@ import networkx as nx from extensions.ops.gather import Gather +from extensions.ops.transpose import Transpose from mo.front.common.partial_infer.utils import int64_array from mo.graph.graph import Node from mo.ops.const import Const @@ -153,6 +154,23 @@ def shape(op_node: Node, port_info: str, input_port: int): op_node.infer(op_node) +def transpose(op_node: Node, port_info: str, input_port: int): + graph = op_node.graph + permutation_data_node = get_node_with_permutation(op_node, port_info) + assert permutation_data_node.has_and_set('permutation'), \ + 'Data node "{}" does not have permutation for node {}, port_info "{}".'.format( + permutation_data_node.id, op_node.id, port_info) + permutation = permutation_data_node.permutation + if len(permutation.perm) == 0: + return + + transpose_name = op_node.soft_get('name', op_node.id) + '/Transpose' + from mo.front.tf.graph_utils import create_op_with_const_inputs # avoiding recursive imports + transpose = create_op_with_const_inputs( + graph, Transpose, {1: permutation.perm}, {'name': transpose_name, 'override_output_shape': True}) + op_node.in_port(input_port).get_connection().insert_node(transpose) + + class PermuteInputs: common_inv_permutation = lambda node, port_info, input_port: axis(node, port_info, input_port) @@ -160,6 +178,7 @@ class PermuteInputs: 'axis': common_inv_permutation, 'order': lambda node, port_info, input_port: order(node, port_info, input_port), 'shape': lambda node, port_info, input_port: shape(node, port_info, input_port), + 'transpose': lambda node, port_info, input_port: transpose(node, port_info, input_port), } def set_input_permutation(self, node1: Node, node2: Node, port_info: str, permutation_rule: str): diff --git a/model-optimizer/mo/ops/convolution.py b/model-optimizer/mo/ops/convolution.py index 95471b07318405..55823c5919065d 100644 --- a/model-optimizer/mo/ops/convolution.py +++ b/model-optimizer/mo/ops/convolution.py @@ -22,6 +22,7 @@ tf_window_op_pad_infer from mo.front.onnx.extractors.utils import get_backend_pad from mo.graph.graph import Node, Graph +from mo.graph.perm_inputs import PermuteInputs from mo.ops.op import Op, PermuteAttrs from mo.utils.error import Error @@ -264,5 +265,6 @@ def infer(node: Node): ('output_feature_channel', 'input:{}'.format(weights_index)), ]) - PermuteAttrs.set_permutation(node.in_node(weights_index), node, - node.get_weights_permute if node.has_valid('get_weights_permute') else None) + PermuteAttrs.set_permutation(node.in_node(weights_index), node, node.soft_get('get_weights_permute', None)) + PermuteInputs().set_input_permutation( + node.in_node(weights_index), node, 'input:{}'.format(weights_index), 'transpose') diff --git a/model-optimizer/mo/ops/deconvolution.py b/model-optimizer/mo/ops/deconvolution.py index c4982b3135560c..f598fd92cde636 100644 --- a/model-optimizer/mo/ops/deconvolution.py +++ b/model-optimizer/mo/ops/deconvolution.py @@ -113,8 +113,8 @@ def infer(node: Node): ('output_feature_channel', 'input:1'), ]) - PermuteAttrs.set_permutation(node.in_node(1), node, - node.get_weights_permute if node.has_valid('get_weights_permute') else None) + PermuteAttrs.set_permutation(node.in_node(1), node, node.soft_get('get_weights_permute', None)) + PermuteInputs().set_input_permutation(node.in_node(1), node, 'input:1', 'transpose') PermuteInputs().set_input_permutation(node.in_node(2), node, 'input:0', 'shape') node['force_precision_in_ports'] = {2: 'int64'} From 147a508a51e5add87b39afa901ebd1c77fae0ad3 Mon Sep 17 00:00:00 2001 From: Ilya Lavrenov Date: Fri, 18 Sep 2020 17:13:27 +0300 Subject: [PATCH 37/64] fixes for UWP (#2255) * UWP fixes * Commented code for compilation with UWP * Current state: compiled for DESKTOP_APP * Fixes * Added toolchain * Enabled ONNX imported for Windows Store * Updated toolchain * Fixes * Disable ONNX in case of UWP * Fix for Windows Driver * Applied style check * Dynamic loading of GetDLLDirectory symbols * Clean-up in the toolchain * Updated mkldnn plugin cmake --- CMakeLists.txt | 2 +- cmake/dependencies.cmake | 26 ++--- cmake/features.cmake | 2 +- cmake/uwp.toolchain.cmake | 22 ++++ inference-engine/cmake/features_ie.cmake | 2 +- inference-engine/samples/CMakeLists.txt | 3 +- .../src/inference_engine/file_utils.cpp | 39 ++++--- .../os/win/win_shared_object_loader.cpp | 108 ++++++++++++++++-- .../src/mkldnn_plugin/CMakeLists.txt | 4 +- .../src/preprocessing/ie_preprocess_gapi.cpp | 3 +- .../modules/gapi/src/compiler/gcompiler.cpp | 2 +- ngraph/core/src/file_util.cpp | 8 +- ngraph/test/runtime/backend.cpp | 7 +- ngraph/test/runtime/backend_manager.cpp | 8 +- 14 files changed, 179 insertions(+), 57 deletions(-) create mode 100644 cmake/uwp.toolchain.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index dcfd8764116ad5..86f821394ac177 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -73,7 +73,7 @@ function(build_ngraph) ngraph_set(NGRAPH_UNIT_TEST_ENABLE FALSE) endif() - if(NOT ANDROID) + if(NOT (ANDROID OR WINDOWS_STORE)) ngraph_set(NGRAPH_ONNX_IMPORT_ENABLE TRUE) else() ngraph_set(NGRAPH_ONNX_IMPORT_ENABLE FALSE) diff --git a/cmake/dependencies.cmake b/cmake/dependencies.cmake index 2a5a74db6a85ec..6a44c8769e7c60 100644 --- a/cmake/dependencies.cmake +++ b/cmake/dependencies.cmake @@ -6,20 +6,20 @@ set_temp_directory(TEMP "${IE_MAIN_SOURCE_DIR}") include(dependency_solver) -if(CMAKE_CROSSCOMPILING) - if(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "amd64.*|x86_64.*|AMD64.*") - set(HOST_X86_64 ON) - endif() +if(CMAKE_CROSSCOMPILING AND NGRAPH_ONNX_IMPORT_ENABLE) + if(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "amd64.*|x86_64.*|AMD64.*") + set(HOST_X86_64 ON) + endif() - set(protoc_version "3.7.1") - if(CMAKE_HOST_SYSTEM_NAME MATCHES Linux) - RESOLVE_DEPENDENCY(SYSTEM_PROTOC_ROOT - ARCHIVE_LIN "protoc-${protoc_version}-linux-x86_64.tar.gz" - TARGET_PATH "${TEMP}/protoc-${protoc_version}-linux-x86_64") - debug_message(STATUS "host protoc-${protoc_version} root path = " ${SYSTEM_PROTOC_ROOT}) - else() - message(FATAL_ERROR "Unsupported host system (${CMAKE_HOST_SYSTEM_NAME}) and arch (${CMAKE_HOST_SYSTEM_PROCESSOR}) for cross-compilation") - endif() + set(protoc_version "3.7.1") + if(CMAKE_HOST_SYSTEM_NAME MATCHES Linux) + RESOLVE_DEPENDENCY(SYSTEM_PROTOC_ROOT + ARCHIVE_LIN "protoc-${protoc_version}-linux-x86_64.tar.gz" + TARGET_PATH "${TEMP}/protoc-${protoc_version}-linux-x86_64") + debug_message(STATUS "host protoc-${protoc_version} root path = " ${SYSTEM_PROTOC_ROOT}) + else() + message(FATAL_ERROR "Unsupported host system (${CMAKE_HOST_SYSTEM_NAME}) and arch (${CMAKE_HOST_SYSTEM_PROCESSOR}) for cross-compilation") + endif() reset_deps_cache(SYSTEM_PROTOC) diff --git a/cmake/features.cmake b/cmake/features.cmake index 38b69a7b135e05..d03b573aad9ea8 100644 --- a/cmake/features.cmake +++ b/cmake/features.cmake @@ -17,7 +17,7 @@ ie_option (ENABLE_TESTS "unit, behavior and functional tests" OFF) ie_option (ENABLE_MKL_DNN "MKL-DNN plugin for inference engine" ${ENABLE_MKL_DNN_DEFAULT}) -ie_dependent_option (ENABLE_CLDNN "clDnn based plugin for inference engine" ON "WIN32 OR X86_64;NOT APPLE;NOT MINGW" OFF) +ie_dependent_option (ENABLE_CLDNN "clDnn based plugin for inference engine" ON "WIN32 OR X86_64;NOT APPLE;NOT MINGW;NOT WINDOWS_STORE; NOT WINDOWS_PHONE" OFF) # FIXME: there are compiler failures with LTO and Cross-Compile toolchains. Disabling for now, but # this must be addressed in a proper way diff --git a/cmake/uwp.toolchain.cmake b/cmake/uwp.toolchain.cmake new file mode 100644 index 00000000000000..0cbc410e85ed81 --- /dev/null +++ b/cmake/uwp.toolchain.cmake @@ -0,0 +1,22 @@ +# Copyright (C) 2018-2020 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 +# + +set(CMAKE_SYSTEM_NAME WindowsStore) +set(CMAKE_SYSTEM_VERSION 10.0) + +if (NOT DEFINED CMAKE_SYSTEM_PROCESSOR) + set(CMAKE_SYSTEM_PROCESSOR ${CMAKE_HOST_SYSTEM_PROCESSOR}) +endif() + +file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/src/uwp.hpp" + "#ifdef WINAPI_FAMILY\n" + "#undef WINAPI_FAMILY\n" + "#define WINAPI_FAMILY WINAPI_FAMILY_DESKTOP_APP\n" + "#endif\n") + +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /FI\"${CMAKE_CURRENT_BINARY_DIR}/src/uwp.hpp\"") +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /FI\"${CMAKE_CURRENT_BINARY_DIR}/src/uwp.hpp\"") + +# UWP setting for package isolation +# set(CMAKE_VS_GLOBALS "AppContainerApplication=true") diff --git a/inference-engine/cmake/features_ie.cmake b/inference-engine/cmake/features_ie.cmake index 948a2994984439..71947495cf9e90 100644 --- a/inference-engine/cmake/features_ie.cmake +++ b/inference-engine/cmake/features_ie.cmake @@ -60,7 +60,7 @@ if (ENABLE_GNA) endif() endif() -ie_option (ENABLE_VPU "vpu targeted plugins for inference engine" ON) +ie_dependent_option (ENABLE_VPU "vpu targeted plugins for inference engine" ON "NOT WINDOWS_PHONE;NOT WINDOWS_STORE" OFF) ie_dependent_option (ENABLE_MYRIAD "myriad targeted plugin for inference engine" ON "ENABLE_VPU" OFF) diff --git a/inference-engine/samples/CMakeLists.txt b/inference-engine/samples/CMakeLists.txt index 398ce6961e5221..acbb9ba6b96e9b 100644 --- a/inference-engine/samples/CMakeLists.txt +++ b/inference-engine/samples/CMakeLists.txt @@ -218,7 +218,7 @@ macro(ie_add_sample) set(folder_name cpp_samples) if(IE_SAMPLE_NAME MATCHES ".*_c$") - set(c_sample ON) + set(c_sample ON) set(folder_name c_samples) endif() @@ -232,7 +232,6 @@ macro(ie_add_sample) target_link_libraries(${IE_SAMPLE_NAME} PRIVATE ${OpenCV_LIBRARIES} ${InferenceEngine_LIBRARIES} ${IE_SAMPLE_DEPENDENCIES}) - if(NOT c_sample) target_link_libraries(${IE_SAMPLE_NAME} PRIVATE gflags) endif() diff --git a/inference-engine/src/inference_engine/file_utils.cpp b/inference-engine/src/inference_engine/file_utils.cpp index 58350d01a9b4ca..563d2dc84cf502 100644 --- a/inference-engine/src/inference_engine/file_utils.cpp +++ b/inference-engine/src/inference_engine/file_utils.cpp @@ -19,6 +19,9 @@ # include # include #else +# if defined(WINAPI_FAMILY) && !WINAPI_PARTITION_DESKTOP +# error "Only WINAPI_PARTITION_DESKTOP is supported, because of GetModuleHandleEx[A|W]" +# endif # include #endif @@ -51,48 +54,52 @@ std::basic_string getPathName(const std::basic_string& s) { static std::string getIELibraryPathA() { #ifdef _WIN32 - char ie_library_path[4096]; + CHAR ie_library_path[MAX_PATH]; HMODULE hm = NULL; - if (!GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, - (LPCSTR)getIELibraryPath, &hm)) { + if (!GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, + reinterpret_cast(getIELibraryPath), &hm)) { THROW_IE_EXCEPTION << "GetModuleHandle returned " << GetLastError(); } - GetModuleFileName(hm, (LPSTR)ie_library_path, sizeof(ie_library_path)); + GetModuleFileNameA(hm, (LPSTR)ie_library_path, sizeof(ie_library_path)); return getPathName(std::string(ie_library_path)); -#else -#ifdef USE_STATIC_IE -#ifdef __APPLE__ +#elif defined(__APPLE__) || defined(__linux__) +# ifdef USE_STATIC_IE +# ifdef __APPLE__ Dl_info info; dladdr(reinterpret_cast(getIELibraryPath), &info); std::string path = getPathName(std::string(info.dli_fname)).c_str(); -#else +# else char result[PATH_MAX]; ssize_t count = readlink("/proc/self/exe", result, PATH_MAX); std::string path = getPathName(std::string(result, (count > 0) ? count : 0)); -#endif // __APPLE__ +# endif // __APPLE__ return FileUtils::makePath(path, std::string( "lib")); -#else +# else Dl_info info; dladdr(reinterpret_cast(getIELibraryPath), &info); return getPathName(std::string(info.dli_fname)).c_str(); -#endif // USE_STATIC_IE +# endif // USE_STATIC_IE +#else +# error "Unsupported OS" #endif // _WIN32 } #ifdef ENABLE_UNICODE_PATH_SUPPORT std::wstring getIELibraryPathW() { -#if defined(_WIN32) || defined(_WIN64) - wchar_t ie_library_path[4096]; +#ifdef _WIN32 + WCHAR ie_library_path[MAX_PATH]; HMODULE hm = NULL; if (!GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, - (LPCWSTR)getIELibraryPath, &hm)) { + reinterpret_cast(getIELibraryPath), &hm)) { THROW_IE_EXCEPTION << "GetModuleHandle returned " << GetLastError(); } - GetModuleFileNameW(hm, (LPWSTR)ie_library_path, sizeof(ie_library_path)); + GetModuleFileNameW(hm, (LPWSTR)ie_library_path, sizeof(ie_library_path) / sizeof(ie_library_path[0])); return getPathName(std::wstring(ie_library_path)); -#else +#elif defined(__linux__) || defined(__APPLE__) return ::FileUtils::multiByteCharToWString(getIELibraryPathA().c_str()); +#else +# error "Unsupported OS" #endif } diff --git a/inference-engine/src/inference_engine/os/win/win_shared_object_loader.cpp b/inference-engine/src/inference_engine/os/win/win_shared_object_loader.cpp index f55eea91058987..7b714aa401ad7a 100644 --- a/inference-engine/src/inference_engine/os/win/win_shared_object_loader.cpp +++ b/inference-engine/src/inference_engine/os/win/win_shared_object_loader.cpp @@ -6,6 +6,61 @@ #include "details/ie_so_loader.h" #include "file_utils.h" +// +// LoadLibraryA, LoadLibraryW: +// WINAPI_FAMILY_DESKTOP_APP - OK (default) +// WINAPI_FAMILY_PC_APP - FAIL ?? (defined by cmake) +// WINAPI_FAMILY_PHONE_APP - FAIL ?? +// WINAPI_FAMILY_GAMES - OK +// WINAPI_FAMILY_SERVER - OK +// WINAPI_FAMILY_SYSTEM - OK +// +// GetModuleHandleExA, GetModuleHandleExW: +// WINAPI_FAMILY_DESKTOP_APP - OK (default) +// WINAPI_FAMILY_PC_APP - FAIL ?? (defined by cmake) +// WINAPI_FAMILY_PHONE_APP - FAIL ?? +// WINAPI_FAMILY_GAMES - OK +// WINAPI_FAMILY_SERVER - OK +// WINAPI_FAMILY_SYSTEM - OK +// +// GetModuleHandleA, GetModuleHandleW: +// WINAPI_FAMILY_DESKTOP_APP - OK (default) +// WINAPI_FAMILY_PC_APP - FAIL ?? (defined by cmake) +// WINAPI_FAMILY_PHONE_APP - FAIL ?? +// WINAPI_FAMILY_GAMES - OK +// WINAPI_FAMILY_SERVER - OK +// WINAPI_FAMILY_SYSTEM - OK +// +// SetDllDirectoryA, SetDllDirectoryW: +// WINAPI_FAMILY_DESKTOP_APP - OK (default) +// WINAPI_FAMILY_PC_APP - FAIL ?? (defined by cmake) +// WINAPI_FAMILY_PHONE_APP - FAIL ?? +// WINAPI_FAMILY_GAMES - OK +// WINAPI_FAMILY_SERVER - FAIL +// WINAPI_FAMILY_SYSTEM - FAIL +// +// GetDllDirectoryA, GetDllDirectoryW: +// WINAPI_FAMILY_DESKTOP_APP - FAIL +// WINAPI_FAMILY_PC_APP - FAIL (defined by cmake) +// WINAPI_FAMILY_PHONE_APP - FAIL +// WINAPI_FAMILY_GAMES - FAIL +// WINAPI_FAMILY_SERVER - FAIL +// WINAPI_FAMILY_SYSTEM - FAIL +// +// SetupDiGetClassDevsA, SetupDiEnumDeviceInfo, SetupDiGetDeviceInstanceIdA, SetupDiDestroyDeviceInfoList: +// WINAPI_FAMILY_DESKTOP_APP - FAIL (default) +// WINAPI_FAMILY_PC_APP - FAIL (defined by cmake) +// WINAPI_FAMILY_PHONE_APP - FAIL +// WINAPI_FAMILY_GAMES - FAIL +// WINAPI_FAMILY_SERVER - FAIL +// WINAPI_FAMILY_SYSTEM - FAIL +// + +#if defined(WINAPI_FAMILY) && !WINAPI_PARTITION_DESKTOP +# error "Only WINAPI_PARTITION_DESKTOP is supported, because of LoadLibrary[A|W]" +#endif + +#include #include #include @@ -16,22 +71,53 @@ class SharedObjectLoader::Impl { private: HMODULE shared_object; - void ExcludeCurrentDirectory() { - // Exclude current directory from DLL search path process wise. - // If application specific path was configured before then - // current directory is alread excluded. - // GetDLLDirectory does not distinguish if aplication specific - // path was set to "" or NULL so reset it to "" to keep - // aplication safe. - if (GetDllDirectory(0, NULL) <= 1) { - SetDllDirectory(TEXT("")); + typedef DWORD(* GetDllDirectoryA_Fnc)(DWORD, LPSTR); + typedef DWORD(* GetDllDirectoryW_Fnc)(DWORD, LPWSTR); + + static GetDllDirectoryA_Fnc IEGetDllDirectoryA; + static GetDllDirectoryW_Fnc IEGetDllDirectoryW; + + void LoadSymbols() { + static std::once_flag loadFlag; + std::call_once(loadFlag, [&] () { + if (HMODULE hm = GetModuleHandleW(L"kernel32.dll")) { + IEGetDllDirectoryA = reinterpret_cast(GetProcAddress(hm, "GetDllDirectoryA")); + IEGetDllDirectoryW = reinterpret_cast(GetProcAddress(hm, "GetDllDirectoryW")); + } + }); + } + + // Exclude current directory from DLL search path process wise. + // If application specific path was configured before then + // current directory is already excluded. + // GetDLLDirectory does not distinguish if aplication specific + // path was set to "" or NULL so reset it to "" to keep + // application safe. + void ExcludeCurrentDirectoryA() { + GetDllDirectoryA; +#ifndef WINAPI_FAMILY + LoadSymbols(); + if (IEGetDllDirectoryA && IEGetDllDirectoryA(0, NULL) <= 1) { + SetDllDirectoryA(""); + } +#endif + } + +#ifdef ENABLE_UNICODE_PATH_SUPPORT + void ExcludeCurrentDirectoryW() { +#ifndef WINAPI_FAMILY + LoadSymbols(); + if (IEGetDllDirectoryW && IEGetDllDirectoryW(0, NULL) <= 1) { + SetDllDirectoryW(L""); } +#endif } +#endif public: #ifdef ENABLE_UNICODE_PATH_SUPPORT explicit Impl(const wchar_t* pluginName) { - ExcludeCurrentDirectory(); + ExcludeCurrentDirectoryW(); shared_object = LoadLibraryW(pluginName); if (!shared_object) { @@ -43,7 +129,7 @@ class SharedObjectLoader::Impl { #endif explicit Impl(const char* pluginName) { - ExcludeCurrentDirectory(); + ExcludeCurrentDirectoryA(); shared_object = LoadLibraryA(pluginName); if (!shared_object) { diff --git a/inference-engine/src/mkldnn_plugin/CMakeLists.txt b/inference-engine/src/mkldnn_plugin/CMakeLists.txt index 166818cda371c4..c450e2256cd41f 100644 --- a/inference-engine/src/mkldnn_plugin/CMakeLists.txt +++ b/inference-engine/src/mkldnn_plugin/CMakeLists.txt @@ -174,8 +174,8 @@ target_compile_definitions(${TARGET_NAME} PUBLIC -DMKLDNN_THR=${MKLDNN_THR}) target_link_libraries(${TARGET_NAME} PRIVATE inference_engine inference_engine_lp_transformations inference_engine_transformations mkldnn) -## Cross compiled function -## TODO: The same for proposal, proposalONNX, topk +# Cross compiled function +# TODO: The same for proposal, proposalONNX, topk cross_compiled_file(${TARGET_NAME} ARCH AVX512F AVX2 SSE42 ANY nodes/argmax_imp.cpp diff --git a/inference-engine/src/preprocessing/ie_preprocess_gapi.cpp b/inference-engine/src/preprocessing/ie_preprocess_gapi.cpp index 96db737e598c0a..eba3d59715e045 100644 --- a/inference-engine/src/preprocessing/ie_preprocess_gapi.cpp +++ b/inference-engine/src/preprocessing/ie_preprocess_gapi.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -732,7 +733,7 @@ bool PreprocEngine::useGAPI() { static const bool NO_GAPI = [](const char *str) -> bool { std::string var(str ? str : ""); return var == "N" || var == "NO" || var == "OFF" || var == "0"; - } (std::getenv("USE_GAPI")); + } (getenv("USE_GAPI")); return !NO_GAPI; } diff --git a/inference-engine/thirdparty/fluid/modules/gapi/src/compiler/gcompiler.cpp b/inference-engine/thirdparty/fluid/modules/gapi/src/compiler/gcompiler.cpp index 1ee710c2358343..06327dc3bdb7a4 100644 --- a/inference-engine/thirdparty/fluid/modules/gapi/src/compiler/gcompiler.cpp +++ b/inference-engine/thirdparty/fluid/modules/gapi/src/compiler/gcompiler.cpp @@ -90,7 +90,7 @@ namespace auto dump_info = cv::gimpl::getCompileArg(args); if (!dump_info.has_value()) { - const char* path = std::getenv("GRAPH_DUMP_PATH"); + const char* path = getenv("GRAPH_DUMP_PATH"); return path ? cv::util::make_optional(std::string(path)) : cv::util::optional(); diff --git a/ngraph/core/src/file_util.cpp b/ngraph/core/src/file_util.cpp index 14c855097df8b1..cd22252345264e 100644 --- a/ngraph/core/src/file_util.cpp +++ b/ngraph/core/src/file_util.cpp @@ -187,9 +187,9 @@ void file_util::iterate_files(const string& path, vector files; vector dirs; #ifdef _WIN32 - string file_match = path_join(path, "*"); - WIN32_FIND_DATA data; - HANDLE hFind = FindFirstFile(file_match.c_str(), &data); + std::string file_match = path_join(path, "*"); + WIN32_FIND_DATAA data; + HANDLE hFind = FindFirstFileA(file_match.c_str(), &data); if (hFind != INVALID_HANDLE_VALUE) { do @@ -212,7 +212,7 @@ void file_util::iterate_files(const string& path, string file_name = path_join(path, data.cFileName); func(file_name, false); } - } while (FindNextFile(hFind, &data)); + } while (FindNextFileA(hFind, &data)); FindClose(hFind); } #else diff --git a/ngraph/test/runtime/backend.cpp b/ngraph/test/runtime/backend.cpp index 78169714d1bdf2..da5a7bab7a72b0 100644 --- a/ngraph/test/runtime/backend.cpp +++ b/ngraph/test/runtime/backend.cpp @@ -16,6 +16,9 @@ #ifdef _WIN32 #include +#if defined(WINAPI_FAMILY) && !WINAPI_PARTITION_DESKTOP +#error "Only WINAPI_PARTITION_DESKTOP is supported, because of LoadLibrary[A|W]" +#endif #elif defined(__linux) || defined(__APPLE__) #include #endif @@ -52,9 +55,11 @@ static string find_my_pathname() Dl_info dl_info; dladdr(reinterpret_cast(ngraph::to_lower), &dl_info); return dl_info.dli_fname; +#else +#error "Unsupported OS" #endif #else - return ""; + return {}; #endif } diff --git a/ngraph/test/runtime/backend_manager.cpp b/ngraph/test/runtime/backend_manager.cpp index 139511e899faf6..e15e2df6f522c2 100644 --- a/ngraph/test/runtime/backend_manager.cpp +++ b/ngraph/test/runtime/backend_manager.cpp @@ -161,11 +161,13 @@ DL_HANDLE runtime::BackendManager::open_shared_library(string type) file_util::get_directory(Backend::get_backend_shared_library_search_directory()); string library_path = file_util::path_join(my_directory, library_name); #ifdef _WIN32 - SetDllDirectory((LPCSTR)my_directory.c_str()); - handle = LoadLibrary(library_path.c_str()); -#else + SetDllDirectoryA((LPCSTR)my_directory.c_str()); + handle = LoadLibraryA(library_path.c_str()); +#elif defined(__APPLE__) || defined(__linux__) DLERROR(); // Clear any pending errors handle = dlopen(library_path.c_str(), RTLD_NOW | RTLD_GLOBAL); +#else +#error "Unsupported OS" #endif string error = DLERROR(); if (!handle) From 1721a9cc5a6e5f1ceca3a8d39090bf715a4ca7d2 Mon Sep 17 00:00:00 2001 From: Artyom Anokhov Date: Fri, 18 Sep 2020 17:49:06 +0300 Subject: [PATCH 38/64] install_NEO_OCL_driver: Updated exit codes, messages. Updated way to remove old driver on Ubuntu (#2334) --- .../install_NEO_OCL_driver.sh | 26 +++++++++---------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/scripts/install_dependencies/install_NEO_OCL_driver.sh b/scripts/install_dependencies/install_NEO_OCL_driver.sh index e2be9e4ce66aa8..bc35f8e6d576e0 100755 --- a/scripts/install_dependencies/install_NEO_OCL_driver.sh +++ b/scripts/install_dependencies/install_NEO_OCL_driver.sh @@ -182,15 +182,11 @@ _uninstall_user_mode_ubuntu() "intel-igc-opencl") for package in "${PACKAGES[@]}"; do - found_package=$(dpkg-query -W -f='${binary:Package}\n' ${package}) - if [[ $? -eq 0 ]]; then - echo Found $found_package installed, uninstalling... - dpkg --purge $found_package - if [[ $? -ne 0 ]]; then - echo "ERROR: unable to remove $found_package" >&2 - echo " please resolve it manually and try to launch the script again." >&2 - exit $EXIT_FAILURE - fi + apt remove -y $package + if [[ $? -ne 0 ]]; then + echo ERROR: failed to uninstall existing user-mode driver. >&2 + echo Please try again manually and run the script again. >&2 + exit $EXIT_FAILURE fi done } @@ -340,7 +336,8 @@ _check_distro_version() if [[ $UBUNTU_VERSION != '18.04' && $UBUNTU_VERSION != '20.04' ]]; then echo "Warning: This runtime can be installed only on Ubuntu 18.04 or Ubuntu 20.04." echo "More info https://github.com/intel/compute-runtime/releases" >&2 - exit "Installation of Intel Compute Runtime interrupted" + echo "Installation of Intel Compute Runtime interrupted" + exit $EXIT_FAILURE fi fi } @@ -363,7 +360,7 @@ check_agreement() fi echo "This script will download and install Intel(R) Graphics Compute Runtime $INSTALL_DRIVER_VERSION, " - echo "that was used to validate this OpenVINO package.\n" + echo "that was used to validate this OpenVINO package." echo "In case if you already have the driver - script will try to remove it." while true; do read -p "Want to proceed? (y/n): " yn @@ -382,11 +379,12 @@ check_current_driver() elif [[ $DISTRO == ubuntu ]]; then gfx_version=$(apt show intel-opencl | grep Version) fi - gfx_version=${gfx_version##*:} + gfx_version="$(echo -e "${gfx_version}" | sed -e 's/^Version\:[[:space:]]*//')" # install NEO OCL driver if current driver version < 19.41.14441 if [[ ! -z $gfx_version && "$(printf '%s\n' "$INSTALL_DRIVER_VERSION" "$gfx_version" | sort -V | head -n 1)" = "$INSTALL_DRIVER_VERSION" ]]; then - echo "Intel(R) Graphics Compute Runtime installation skipped because current version greater or equal to $INSTALL_DRIVER_VERSION" - exit "Installation of Intel Compute Runtime interrupted" + echo "Intel(R) Graphics Compute Runtime installation skipped because current version greater or equal to $INSTALL_DRIVER_VERSION" >&2 + echo "Installation of Intel Compute Runtime interrupted" >&2 + exit $EXIT_FAILURE else echo "Starting installation" fi From 676ce76650a67d03983d8728e81e9150e0128309 Mon Sep 17 00:00:00 2001 From: Andrey Sokolov Date: Fri, 18 Sep 2020 18:12:16 +0300 Subject: [PATCH 39/64] [IE][VPU]: Makes ROIAlign to use 2 stage pipeline (to support ma2485) (#2123) --- inference-engine/cmake/vpu_dependencies.cmake | 2 +- .../src/stages/roi_align.cpp | 67 ++++++++++++------- .../layers/myriad_layers_roi_align_test.cpp | 8 +++ .../layers/myriad_layers_roi_align_test.hpp | 20 ++++-- 4 files changed, 65 insertions(+), 32 deletions(-) diff --git a/inference-engine/cmake/vpu_dependencies.cmake b/inference-engine/cmake/vpu_dependencies.cmake index 4df5f49a73f8ac..d0c55448e2583e 100644 --- a/inference-engine/cmake/vpu_dependencies.cmake +++ b/inference-engine/cmake/vpu_dependencies.cmake @@ -19,7 +19,7 @@ set(VPU_SUPPORTED_FIRMWARES usb-ma2450 usb-ma2x8x pcie-ma248x) # Default packages # -set(FIRMWARE_PACKAGE_VERSION 1378) +set(FIRMWARE_PACKAGE_VERSION 1388) set(VPU_CLC_MA2X8X_VERSION "movi-cltools-20.09.1") # diff --git a/inference-engine/src/vpu/graph_transformer/src/stages/roi_align.cpp b/inference-engine/src/vpu/graph_transformer/src/stages/roi_align.cpp index f7b470252ce1cf..586e9f3ab841bc 100644 --- a/inference-engine/src/vpu/graph_transformer/src/stages/roi_align.cpp +++ b/inference-engine/src/vpu/graph_transformer/src/stages/roi_align.cpp @@ -17,11 +17,18 @@ VPU_DECLARE_ENUM(ROIAlignMode, Max = 1 ) +VPU_DECLARE_ENUM(ROIAlignStep, + Repacking = 0, + ROIAlignCHWc = 1, + ROIAlign = 2 +) + static const char s_mode[] = "mode"; static const char s_pooled_w[] = "pooled_w"; static const char s_pooled_h[] = "pooled_h"; static const char s_sampling_ratio[] = "sampling_ratio"; static const char s_spatial_scale[] = "spatial_scale"; +static const char s_step_number[] = "step_number"; namespace { @@ -52,7 +59,11 @@ class ROIAlignStage final : public StageNode { } void initialCheckImpl() const override { - assertInputsOutputsTypes(this, {{DataType::FP16}, {DataType::FP16}, {DataType::S32}}, {{DataType::FP16}}); + const auto step_number = attrs().get(s_step_number); + std::vector> repackingInputs = {{DataType::FP16}}; + std::vector> ROIAlignInputs = {{DataType::FP16}, {DataType::FP16}, {DataType::S32}}; + + assertInputsOutputsTypes(this, (step_number == ROIAlignStep::Repacking) ? repackingInputs : ROIAlignInputs, {{DataType::FP16}}); } void serializeParamsImpl(BlobSerializer& serializer) const override { @@ -61,14 +72,14 @@ class ROIAlignStage final : public StageNode { const auto sampling_ratio = attrs().get(s_sampling_ratio); const auto spatial_scale = attrs().get(s_spatial_scale); const auto mode = attrs().get(s_mode); - const auto use_buffer = !tempBuffers().empty(); + const auto step_number = attrs().get(s_step_number); serializer.append(static_cast(pooled_w)); serializer.append(static_cast(pooled_h)); serializer.append(static_cast(sampling_ratio)); serializer.append(static_cast(spatial_scale)); serializer.append(static_cast(mode)); - serializer.append(static_cast(use_buffer)); + serializer.append(static_cast(step_number)); } void serializeDataImpl(BlobSerializer& serializer) const override { @@ -77,47 +88,51 @@ class ROIAlignStage final : public StageNode { } outputEdge(0)->output()->serializeBuffer(serializer); - const auto use_buffer = !tempBuffers().empty(); - if (use_buffer) - tempBuffer(0)->serializeBuffer(serializer); } }; } // namespace void FrontEnd::parseROIAlign(const Model& model, const ie::CNNLayerPtr& layer, const DataVector& inputs, const DataVector& outputs) const { - VPU_THROW_UNLESS(inputs.size() == 3, - "ROIAlign stage with name {} has invalid number of inputs: expected 3, " + VPU_THROW_UNLESS(inputs.size() == 3 || inputs.size() == 1, + "ROIAlign stage with name {} has invalid number of inputs: expected 3 or 1 " "actually provided {}", layer->name, inputs.size()); - VPU_THROW_UNLESS(outputs.size() == 1, "ROIAlign stage with name {} has invalid number of outputs: expected 1, " "actually provided {}", layer->name, outputs.size()); - const auto stage = model->addNewStage(layer->name, StageType::ROIAlign, layer, inputs, outputs); const auto mode = layer->GetParamAsString("mode", ""); - - if (mode == "avg") { - stage->attrs().set(s_mode, ROIAlignMode::Average); - } else if (mode == "max") { - stage->attrs().set(s_mode, ROIAlignMode::Max); - } else { - VPU_THROW_FORMAT("Layer with name {} supports only (avg, max) mode", layer->name); + VPU_THROW_UNLESS(mode == "avg" || mode == "max", "Layer with name {} supports only (avg, max) mode", layer->name); + ROIAlignMode roi_align_mode = (mode == "avg") ? ROIAlignMode::Average : ROIAlignMode::Max; + + const auto width = inputs[0]->desc().dim(Dim::W); + const auto is_input_static = (inputs[0]->parentDataToShapeEdge() == nullptr); + const auto use_chwc_repacking = (width >= 200) && (roi_align_mode == ROIAlignMode::Average) && is_input_static; + auto repackedInput = inputs[0]; + + if (use_chwc_repacking) { + repackedInput = model->duplicateData(inputs[0], formatString("@ROIAlignRepacked")); + + const auto repacking_stage = model->addNewStage(layer->name + "Repacking", + StageType::ROIAlign, layer, + {inputs[0]}, {repackedInput}); + + repacking_stage->attrs().set(s_pooled_w, layer->GetParamAsInt("pooled_w")); + repacking_stage->attrs().set(s_pooled_h, layer->GetParamAsInt("pooled_h")); + repacking_stage->attrs().set(s_sampling_ratio, layer->GetParamAsInt("sampling_ratio")); + repacking_stage->attrs().set(s_spatial_scale, layer->GetParamAsFloat("spatial_scale")); + repacking_stage->attrs().set(s_mode, ROIAlignMode::Average); + repacking_stage->attrs().set(s_step_number, ROIAlignStep::Repacking); } + const auto stage = model->addNewStage(layer->name, StageType::ROIAlign, layer, {repackedInput, inputs[1], inputs[2]}, outputs); + + stage->attrs().set(s_mode, roi_align_mode); stage->attrs().set(s_pooled_w, layer->GetParamAsInt("pooled_w")); stage->attrs().set(s_pooled_h, layer->GetParamAsInt("pooled_h")); stage->attrs().set(s_sampling_ratio, layer->GetParamAsInt("sampling_ratio")); stage->attrs().set(s_spatial_scale, layer->GetParamAsFloat("spatial_scale")); - - const int width = inputs[0]->desc().dim(Dim::W); - const int height = inputs[0]->desc().dim(Dim::H); - const int channels = inputs[0]->desc().dim(Dim::C); - const int buffer_size = sizeof(int16_t) * width * height * channels; - const bool use_buffer = (width >= 200) && (mode == "avg"); - - if (use_buffer) - model->addTempBuffer(stage, DataDesc({buffer_size})); + stage->attrs().set(s_step_number, use_chwc_repacking ? ROIAlignStep::ROIAlignCHWc : ROIAlignStep::ROIAlign); } } // namespace vpu diff --git a/inference-engine/tests_deprecated/functional/vpu/common/layers/myriad_layers_roi_align_test.cpp b/inference-engine/tests_deprecated/functional/vpu/common/layers/myriad_layers_roi_align_test.cpp index b9b7a7f538766a..9daf7aa670921b 100644 --- a/inference-engine/tests_deprecated/functional/vpu/common/layers/myriad_layers_roi_align_test.cpp +++ b/inference-engine/tests_deprecated/functional/vpu/common/layers/myriad_layers_roi_align_test.cpp @@ -11,3 +11,11 @@ INSTANTIATE_TEST_CASE_P(accuracy, myriadLayersTestsROIAlign_smoke, ::testing::ValuesIn(s_ROIAlignNumROIs), ::testing::ValuesIn(s_ROIAlignMode)), ); + +INSTANTIATE_TEST_CASE_P(accuracy_faster, myriadLayersTestsROIAlign_smoke, + ::testing::Combine( + ::testing::ValuesIn(s_ROIAlignLayerInput_Faster), + ::testing::ValuesIn(s_ROIAlignLayerParam_Faster), + ::testing::ValuesIn(s_ROIAlignNumROIs_Faster), + ::testing::ValuesIn(s_ROIAlignMode_Faster)), +); diff --git a/inference-engine/tests_deprecated/functional/vpu/common/layers/myriad_layers_roi_align_test.hpp b/inference-engine/tests_deprecated/functional/vpu/common/layers/myriad_layers_roi_align_test.hpp index fa1ec5071f4b02..a63434aadb6afa 100644 --- a/inference-engine/tests_deprecated/functional/vpu/common/layers/myriad_layers_roi_align_test.hpp +++ b/inference-engine/tests_deprecated/functional/vpu/common/layers/myriad_layers_roi_align_test.hpp @@ -243,16 +243,26 @@ TEST_P(myriadLayersTestsROIAlign_smoke, ROIAlign) { static std::vector s_ROIAlignLayerInput = { {{5, 256, 160, 157}}, }; - static std::vector s_ROIAlignLayerParam = { {{640, 640, 7, 9, 2, 1.4f}}, }; - static std::vector s_ROIAlignNumROIs = { 53 }; - static std::vector s_ROIAlignMode = { - std::string("avg"), - std::string("max") + std::string("avg"), + std::string("max") +}; + +static std::vector s_ROIAlignLayerInput_Faster = { + {{1, 256, 200, 257}}, +}; +static std::vector s_ROIAlignLayerParam_Faster = { + {{640, 640, 7, 7, 2, 0.25f}}, +}; +static std::vector s_ROIAlignNumROIs_Faster = { + 750 +}; +static std::vector s_ROIAlignMode_Faster = { + std::string("avg") }; From 1e8618ba9837e1b07bec1c0de99332fe027e4c67 Mon Sep 17 00:00:00 2001 From: Edward Shogulin Date: Fri, 18 Sep 2020 18:39:50 +0300 Subject: [PATCH 40/64] [nGraph] WA removal: 1) nGraph tests enabling 2) LPT extanding: not handle in FP32 --- .../common/fake_quantize_dequantization.hpp | 2 +- .../src/transformations/low_precision/add.cpp | 8 ++++++++ .../common/fake_quantize_dequantization.cpp | 4 ++++ .../transformations/low_precision/convolution.cpp | 4 +--- .../src/transformations/low_precision/mat_mul.cpp | 13 +++++++++++-- .../src/transformations/low_precision/multiply.cpp | 9 +++++++-- .../transformations/const_folding_prior_box.cpp | 6 ++---- ngraph/core/src/op/util/elementwise_args.cpp | 2 -- ngraph/test/runtime/ie/unit_test.manifest | 5 ----- ngraph/test/runtime/interpreter/unit_test.manifest | 5 ----- ngraph/test/specialize_function.cpp | 3 +-- ngraph/test/type_prop/binary_elementwise.cpp | 6 ++---- 12 files changed, 37 insertions(+), 30 deletions(-) diff --git a/inference-engine/src/transformations/include/transformations/low_precision/common/fake_quantize_dequantization.hpp b/inference-engine/src/transformations/include/transformations/low_precision/common/fake_quantize_dequantization.hpp index 7dc88c42d8bd76..0edc8ef1056da3 100644 --- a/inference-engine/src/transformations/include/transformations/low_precision/common/fake_quantize_dequantization.hpp +++ b/inference-engine/src/transformations/include/transformations/low_precision/common/fake_quantize_dequantization.hpp @@ -26,8 +26,8 @@ class FakeQuantizeDequantization { std::shared_ptr multiply); bool empty() const; - bool isShared() const; + bool isLowPrecision() const; Output data; std::shared_ptr convert; diff --git a/inference-engine/src/transformations/src/transformations/low_precision/add.cpp b/inference-engine/src/transformations/src/transformations/low_precision/add.cpp index 857af053b21000..b452c8fd300ec3 100644 --- a/inference-engine/src/transformations/src/transformations/low_precision/add.cpp +++ b/inference-engine/src/transformations/src/transformations/low_precision/add.cpp @@ -129,11 +129,19 @@ bool AddTransformation::transform(TransformationContext& context, ngraph::patter const int emptyPathIndex = fullPathIndex == 0 ? 1 : 0; FakeQuantizeDequantization dequantizationEmptyPath = NetworkHelper::getDequantization(add, emptyPathIndex); + if (updatePrecisions && !dequantizationEmptyPath.empty() && !dequantizationEmptyPath.isLowPrecision()) { + return false; + } + std::shared_ptr subtractEmptyPathValues; std::shared_ptr multiplyEmptyPathValues; std::tie(subtractEmptyPathValues, multiplyEmptyPathValues) = NetworkHelper::createEmptyValues(dequantizationEmptyPath); FakeQuantizeDequantization dequantizationFullPath = NetworkHelper::getDequantization(add, fullPathIndex); + if (updatePrecisions && !dequantizationFullPath.empty() && !dequantizationFullPath.isLowPrecision()) { + return false; + } + std::shared_ptr subtractFullPathValues; std::shared_ptr multiplyFullPathValues; std::tie(subtractFullPathValues, multiplyFullPathValues) = NetworkHelper::createEmptyValues(dequantizationFullPath); diff --git a/inference-engine/src/transformations/src/transformations/low_precision/common/fake_quantize_dequantization.cpp b/inference-engine/src/transformations/src/transformations/low_precision/common/fake_quantize_dequantization.cpp index 67af3efd72ffbc..2e9ba9c72dbe57 100644 --- a/inference-engine/src/transformations/src/transformations/low_precision/common/fake_quantize_dequantization.cpp +++ b/inference-engine/src/transformations/src/transformations/low_precision/common/fake_quantize_dequantization.cpp @@ -43,6 +43,10 @@ bool FakeQuantizeDequantization::isShared() const { return false; } +bool FakeQuantizeDequantization::isLowPrecision() const { + return (data.get_element_type() == element::i8) || (data.get_element_type() == element::u8); +} + } // namespace low_precision } // namespace pass } // namespace ngraph diff --git a/inference-engine/src/transformations/src/transformations/low_precision/convolution.cpp b/inference-engine/src/transformations/src/transformations/low_precision/convolution.cpp index 139d8dfc2326cc..ce32e6e87771fb 100644 --- a/inference-engine/src/transformations/src/transformations/low_precision/convolution.cpp +++ b/inference-engine/src/transformations/src/transformations/low_precision/convolution.cpp @@ -46,9 +46,7 @@ bool ConvolutionTransformation::transform(TransformationContext &context, ngraph return false; } - if (updatePrecisions && - dequantization.data.get_element_type() != element::i8 && - dequantization.data.get_element_type() != element::u8) { + if (updatePrecisions && !dequantization.empty() && !dequantization.isLowPrecision()) { return false; } diff --git a/inference-engine/src/transformations/src/transformations/low_precision/mat_mul.cpp b/inference-engine/src/transformations/src/transformations/low_precision/mat_mul.cpp index 86980253f51073..4b432a3d7b5a4d 100644 --- a/inference-engine/src/transformations/src/transformations/low_precision/mat_mul.cpp +++ b/inference-engine/src/transformations/src/transformations/low_precision/mat_mul.cpp @@ -113,12 +113,21 @@ bool MatMulTransformation::canBeTransformed(const TransformationContext& context } const auto dequantization1 = ngraph::pass::low_precision::NetworkHelper::getDequantization(layer); + if (!NetworkHelper::isScalarLike(as_type_ptr(dequantization1.multiply->get_input_node_shared_ptr(1)))) { + return false; + } - if (!NetworkHelper::isScalarLike( - as_type_ptr(dequantization1.multiply->get_input_node_shared_ptr(1)))) { + if (updatePrecisions && !dequantization1.empty() && !dequantization1.isLowPrecision()) { return false; } + if (updatePrecisions) { + const auto dequantization2 = ngraph::pass::low_precision::NetworkHelper::getDequantization(layer, 1); + if (!dequantization2.empty() && !dequantization2.isLowPrecision()) { + return false; + } + } + const auto fakeQuantize = as_type_ptr(layer->get_input_node_shared_ptr(1)); if (fakeQuantize != nullptr) { if (!QuantizationDetails::outputLayoutIsSupported(fakeQuantize)) { diff --git a/inference-engine/src/transformations/src/transformations/low_precision/multiply.cpp b/inference-engine/src/transformations/src/transformations/low_precision/multiply.cpp index 87b0f9073294c8..8cacec66b877b1 100644 --- a/inference-engine/src/transformations/src/transformations/low_precision/multiply.cpp +++ b/inference-engine/src/transformations/src/transformations/low_precision/multiply.cpp @@ -71,7 +71,13 @@ bool MultiplyTransformation::transform(TransformationContext& context, ngraph::p const int emptyPathIndex = fullPathIndex == 0 ? 1 : 0; FakeQuantizeDequantization dequantizationEmptyPath = NetworkHelper::getDequantization(multiply, emptyPathIndex); - if (dequantizationEmptyPath.multiply == nullptr && dequantizationEmptyPath.subtract == nullptr) { + if ((updatePrecisions && !dequantizationEmptyPath.empty() && !dequantizationEmptyPath.isLowPrecision()) || + (dequantizationEmptyPath.multiply == nullptr && dequantizationEmptyPath.subtract == nullptr)) { + return false; + } + + FakeQuantizeDequantization dequantizationFullPath = NetworkHelper::getDequantization(multiply, fullPathIndex); + if (updatePrecisions && !dequantizationFullPath.empty() && !dequantizationFullPath.isLowPrecision()) { return false; } @@ -84,7 +90,6 @@ bool MultiplyTransformation::transform(TransformationContext& context, ngraph::p return false; } - FakeQuantizeDequantization dequantizationFullPath = NetworkHelper::getDequantization(multiply, fullPathIndex); std::shared_ptr subtractValuesFullPath; std::shared_ptr multiplyValuesFullPath; std::tie(subtractValuesFullPath, multiplyValuesFullPath) = NetworkHelper::createEmptyValues(dequantizationFullPath); diff --git a/inference-engine/tests/functional/inference_engine/transformations/const_folding_prior_box.cpp b/inference-engine/tests/functional/inference_engine/transformations/const_folding_prior_box.cpp index d4aeb1c31dc3f2..2b336855bc72d8 100644 --- a/inference-engine/tests/functional/inference_engine/transformations/const_folding_prior_box.cpp +++ b/inference-engine/tests/functional/inference_engine/transformations/const_folding_prior_box.cpp @@ -18,8 +18,7 @@ using namespace testing; -// TODO: LPT_SUPPORT -TEST(TransformationTests, DISABLED_ConstFoldingPriorBox) { +TEST(TransformationTests, ConstFoldingPriorBox) { SKIP_IF_CURRENT_TEST_IS_DISABLED() std::shared_ptr f(nullptr), f_ref(nullptr); @@ -111,8 +110,7 @@ TEST(TransformationTests, ConstFoldingPriorBoxClustered) { EXPECT_TRUE(fused->get_vector() == ref->get_vector()); } -// TODO: LPT_SUPPORT -TEST(TransformationTests, DISABLED_ConstFoldingPriorBoxSubgraph) { +TEST(TransformationTests, ConstFoldingPriorBoxSubgraph) { SKIP_IF_CURRENT_TEST_IS_DISABLED() std::shared_ptr f(nullptr), f_ref(nullptr); diff --git a/ngraph/core/src/op/util/elementwise_args.cpp b/ngraph/core/src/op/util/elementwise_args.cpp index aeb878e780624f..97bce4fd9c5f6f 100644 --- a/ngraph/core/src/op/util/elementwise_args.cpp +++ b/ngraph/core/src/op/util/elementwise_args.cpp @@ -15,9 +15,7 @@ //***************************************************************************** #include "elementwise_args.hpp" -#ifdef LPT_SUPPORT #include "binary_elementwise_arithmetic.hpp" -#endif using namespace ngraph; diff --git a/ngraph/test/runtime/ie/unit_test.manifest b/ngraph/test/runtime/ie/unit_test.manifest index 8acaead855f625..d4b037f9657272 100644 --- a/ngraph/test/runtime/ie/unit_test.manifest +++ b/ngraph/test/runtime/ie/unit_test.manifest @@ -10,11 +10,6 @@ # #------------------------------------------------------------------------------- -# LPT_SUPPORT: temporary disabling -# onnx_model_gemm_abc -# reduce_sum_keep_5d_to_scalar_int32 -# et_dynamic_shape_static_validation_fails - # Quantize layer input 'Multiply_7' doesn't have blobs onnx_model_quantize_linear onnx_model_quantize_linear_zero_point diff --git a/ngraph/test/runtime/interpreter/unit_test.manifest b/ngraph/test/runtime/interpreter/unit_test.manifest index b05313131eed10..4502e97d0dccd6 100644 --- a/ngraph/test/runtime/interpreter/unit_test.manifest +++ b/ngraph/test/runtime/interpreter/unit_test.manifest @@ -1,8 +1,3 @@ -# LPT_SUPPORT: temporary disabling -# onnx_model_gemm_abc -# reduce_sum_keep_5d_to_scalar_int32 -# et_dynamic_shape_static_validation_fails - tile_3d_small_data_rank tile_3d_few_repeats fake_quantize_pdpd diff --git a/ngraph/test/specialize_function.cpp b/ngraph/test/specialize_function.cpp index d97b925c372701..6a8e91cfb6585e 100644 --- a/ngraph/test/specialize_function.cpp +++ b/ngraph/test/specialize_function.cpp @@ -176,8 +176,7 @@ TEST(specialize_function, et_static_shape_rank_dynamic_validation_fails) // Test specialization of dynamic element types to a case where validation will fail. // // (The input element types we provide at specialization time are inconsistent.) -// LPT_SUPPORT: temporary disabled -TEST(DISABLED_specialize_function, et_dynamic_shape_static_validation_fails) +TEST(specialize_function, et_dynamic_shape_static_validation_fails) { auto p0 = std::make_shared(element::dynamic, Shape{1, 2, 3}); auto p1 = std::make_shared(element::dynamic, Shape{1, 2, 3}); diff --git a/ngraph/test/type_prop/binary_elementwise.cpp b/ngraph/test/type_prop/binary_elementwise.cpp index 3d1211c999d980..564c2e50b57a17 100644 --- a/ngraph/test/type_prop/binary_elementwise.cpp +++ b/ngraph/test/type_prop/binary_elementwise.cpp @@ -195,8 +195,7 @@ void test_binary_logical(std::string /* node_type */, test_binary_good_arguments(tv0_2_4_param_0, tv0_2_4_param_1); } -// LPT_SUPPORT: temporary disabled -TEST(DISABLED_type_prop, or_bad_arguments) +TEST(type_prop, or_bad_arguments) { test_binary_logical( "Or", [](const shared_ptr& x, const shared_ptr& y) -> shared_ptr { @@ -204,8 +203,7 @@ TEST(DISABLED_type_prop, or_bad_arguments) }); } -// LPT_SUPPORT: temporary disabled -TEST(DISABLED_type_prop, xor_bad_arguments) +TEST(type_prop, xor_bad_arguments) { test_binary_logical( "Xor", [](const shared_ptr& x, const shared_ptr& y) -> shared_ptr { From 20266276ecd3c3c12dbadff79f38a50cfd967088 Mon Sep 17 00:00:00 2001 From: Vitaliy Urusovskij Date: Fri, 18 Sep 2020 18:53:49 +0300 Subject: [PATCH 41/64] New layout for `time_tests` (#2321) * Change folders' layout for `time_tests` * Refactoring of namings in `time_tests` --- tests/time_tests/CMakeLists.txt | 1 - tests/time_tests/README.md | 2 +- .../timetests_helper}/timer.h | 0 .../run_timetest.py} | 10 +++++----- tests/time_tests/src/CMakeLists.txt | 17 ++--------------- tests/time_tests/src/timetests/CMakeLists.txt | 19 +++++++++++++++++++ .../src/{ => timetests}/timetest_infer.cpp | 2 +- .../timetests_helper}/CMakeLists.txt | 4 ++-- .../timetests_helper}/cli.h | 0 .../timetests_helper}/main.cpp | 2 +- .../timetests_helper}/statistics_writer.h | 0 .../timetests_helper}/timer.cpp | 2 +- tests/time_tests/test_runner/test_timetest.py | 1 + 13 files changed, 33 insertions(+), 27 deletions(-) rename tests/time_tests/{time-testhelper/include/time-testhelper => include/timetests_helper}/timer.h (100%) rename tests/time_tests/{run_executable.py => scripts/run_timetest.py} (93%) mode change 100755 => 100644 create mode 100644 tests/time_tests/src/timetests/CMakeLists.txt rename tests/time_tests/src/{ => timetests}/timetest_infer.cpp (97%) rename tests/time_tests/{time-testhelper => src/timetests_helper}/CMakeLists.txt (64%) rename tests/time_tests/{time-testhelper => src/timetests_helper}/cli.h (100%) rename tests/time_tests/{time-testhelper => src/timetests_helper}/main.cpp (97%) rename tests/time_tests/{time-testhelper => src/timetests_helper}/statistics_writer.h (100%) rename tests/time_tests/{time-testhelper => src/timetests_helper}/timer.cpp (95%) create mode 100644 tests/time_tests/test_runner/test_timetest.py diff --git a/tests/time_tests/CMakeLists.txt b/tests/time_tests/CMakeLists.txt index ee1f8d69b23e33..e932181ce6c4e6 100644 --- a/tests/time_tests/CMakeLists.txt +++ b/tests/time_tests/CMakeLists.txt @@ -20,5 +20,4 @@ endif() find_package(InferenceEngineDeveloperPackage REQUIRED) -add_subdirectory(time-testhelper) add_subdirectory(src) diff --git a/tests/time_tests/README.md b/tests/time_tests/README.md index 323e9c0a0fac64..52be0f00531a15 100644 --- a/tests/time_tests/README.md +++ b/tests/time_tests/README.md @@ -21,6 +21,6 @@ cmake .. -DInferenceEngineDeveloperPackage_DIR=$(realpath ../../../build) && mak 2. Run test: ``` bash -./run_executable.py ../../../bin/intel64/Release/timetest_infer -m model.xml -d CPU +./scripts/run_timetest.py ../../../bin/intel64/Release/timetest_infer -m model.xml -d CPU ``` diff --git a/tests/time_tests/time-testhelper/include/time-testhelper/timer.h b/tests/time_tests/include/timetests_helper/timer.h similarity index 100% rename from tests/time_tests/time-testhelper/include/time-testhelper/timer.h rename to tests/time_tests/include/timetests_helper/timer.h diff --git a/tests/time_tests/run_executable.py b/tests/time_tests/scripts/run_timetest.py old mode 100755 new mode 100644 similarity index 93% rename from tests/time_tests/run_executable.py rename to tests/time_tests/scripts/run_timetest.py index 756d172b08c5a3..03dee1d32302d1 --- a/tests/time_tests/run_executable.py +++ b/tests/time_tests/scripts/run_timetest.py @@ -3,7 +3,7 @@ # SPDX-License-Identifier: Apache-2.0 # """ -This script runs TimeTests executable several times to aggregate +This script runs timetest executable several times and aggregate collected statistics. """ @@ -86,11 +86,11 @@ def generate_tmp_path(): return path -def run_executable(args: dict, log=None): +def run_timetest(args: dict, log=None): """Run provided executable several times and aggregate collected statistics""" if log is None: - log = logging.getLogger('run_executable') + log = logging.getLogger('run_timetest') cmd_common = prepare_executable_cmd(args) @@ -114,7 +114,7 @@ def run_executable(args: dict, log=None): def cli_parser(): """parse command-line arguments""" - parser = argparse.ArgumentParser(description='Run TimeTests executable') + parser = argparse.ArgumentParser(description='Run timetest executable') parser.add_argument('executable', type=Path, help='binary to execute') @@ -149,7 +149,7 @@ def cli_parser(): logging.basicConfig(format="[ %(levelname)s ] %(message)s", level=logging.DEBUG, stream=sys.stdout) - exit_code, aggr_stats = run_executable(dict(args._get_kwargs()), log=logging) # pylint: disable=protected-access + exit_code, aggr_stats = run_timetest(dict(args._get_kwargs()), log=logging) # pylint: disable=protected-access if args.stats_path: # Save aggregated results to a file diff --git a/tests/time_tests/src/CMakeLists.txt b/tests/time_tests/src/CMakeLists.txt index c886bf74b57825..376b490afed71a 100644 --- a/tests/time_tests/src/CMakeLists.txt +++ b/tests/time_tests/src/CMakeLists.txt @@ -2,18 +2,5 @@ # SPDX-License-Identifier: Apache-2.0 # -# add dummy `time_tests` target combines all time tests -add_custom_target(time_tests) - -# Build test from every source file. -# Test target name is source file name without extension. -FILE(GLOB tests "*.cpp") - -foreach(test_source ${tests}) - get_filename_component(test_name ${test_source} NAME_WE) - add_executable(${test_name} ${test_source}) - - target_link_libraries(${test_name} PRIVATE IE::inference_engine time-testhelper) - - add_dependencies(time_tests ${test_name}) -endforeach() +add_subdirectory(timetests) +add_subdirectory(timetests_helper) \ No newline at end of file diff --git a/tests/time_tests/src/timetests/CMakeLists.txt b/tests/time_tests/src/timetests/CMakeLists.txt new file mode 100644 index 00000000000000..c83d9ca52999f8 --- /dev/null +++ b/tests/time_tests/src/timetests/CMakeLists.txt @@ -0,0 +1,19 @@ +# Copyright (C) 2020 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 +# + +# add dummy `time_tests` target combines all time tests +add_custom_target(time_tests) + +# Build test from every source file. +# Test target name is source file name without extension. +FILE(GLOB tests "*.cpp") + +foreach(test_source ${tests}) + get_filename_component(test_name ${test_source} NAME_WE) + add_executable(${test_name} ${test_source}) + + target_link_libraries(${test_name} PRIVATE IE::inference_engine timetests_helper) + + add_dependencies(time_tests ${test_name}) +endforeach() diff --git a/tests/time_tests/src/timetest_infer.cpp b/tests/time_tests/src/timetests/timetest_infer.cpp similarity index 97% rename from tests/time_tests/src/timetest_infer.cpp rename to tests/time_tests/src/timetests/timetest_infer.cpp index 59030eb8738552..a6e450280ae90d 100644 --- a/tests/time_tests/src/timetest_infer.cpp +++ b/tests/time_tests/src/timetests/timetest_infer.cpp @@ -5,7 +5,7 @@ #include #include -#include "time-testhelper/timer.h" +#include "timetests_helper/timer.h" using namespace InferenceEngine; /** diff --git a/tests/time_tests/time-testhelper/CMakeLists.txt b/tests/time_tests/src/timetests_helper/CMakeLists.txt similarity index 64% rename from tests/time_tests/time-testhelper/CMakeLists.txt rename to tests/time_tests/src/timetests_helper/CMakeLists.txt index 6066dfdf00cfe4..ba5760edecf887 100644 --- a/tests/time_tests/time-testhelper/CMakeLists.txt +++ b/tests/time_tests/src/timetests_helper/CMakeLists.txt @@ -2,12 +2,12 @@ # SPDX-License-Identifier: Apache-2.0 # -set (TARGET_NAME "time-testhelper") +set (TARGET_NAME "timetests_helper") find_package(gflags REQUIRED) file (GLOB SRC *.cpp) add_library(${TARGET_NAME} STATIC ${SRC}) -target_include_directories(${TARGET_NAME} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include") +target_include_directories(${TARGET_NAME} PUBLIC "${CMAKE_SOURCE_DIR}/include") target_link_libraries(${TARGET_NAME} gflags) diff --git a/tests/time_tests/time-testhelper/cli.h b/tests/time_tests/src/timetests_helper/cli.h similarity index 100% rename from tests/time_tests/time-testhelper/cli.h rename to tests/time_tests/src/timetests_helper/cli.h diff --git a/tests/time_tests/time-testhelper/main.cpp b/tests/time_tests/src/timetests_helper/main.cpp similarity index 97% rename from tests/time_tests/time-testhelper/main.cpp rename to tests/time_tests/src/timetests_helper/main.cpp index 7b5af8c527873e..fda85b94aeb46c 100644 --- a/tests/time_tests/time-testhelper/main.cpp +++ b/tests/time_tests/src/timetests_helper/main.cpp @@ -4,7 +4,7 @@ #include "cli.h" #include "statistics_writer.h" -#include "time-testhelper/timer.h" +#include "timetests_helper/timer.h" #include diff --git a/tests/time_tests/time-testhelper/statistics_writer.h b/tests/time_tests/src/timetests_helper/statistics_writer.h similarity index 100% rename from tests/time_tests/time-testhelper/statistics_writer.h rename to tests/time_tests/src/timetests_helper/statistics_writer.h diff --git a/tests/time_tests/time-testhelper/timer.cpp b/tests/time_tests/src/timetests_helper/timer.cpp similarity index 95% rename from tests/time_tests/time-testhelper/timer.cpp rename to tests/time_tests/src/timetests_helper/timer.cpp index 44cc9d236ff4db..3bb1576a850059 100644 --- a/tests/time_tests/time-testhelper/timer.cpp +++ b/tests/time_tests/src/timetests_helper/timer.cpp @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "time-testhelper/timer.h" +#include "timetests_helper/timer.h" #include #include #include diff --git a/tests/time_tests/test_runner/test_timetest.py b/tests/time_tests/test_runner/test_timetest.py new file mode 100644 index 00000000000000..2064a9b248a676 --- /dev/null +++ b/tests/time_tests/test_runner/test_timetest.py @@ -0,0 +1 @@ +#TODO: fill \ No newline at end of file From fe99e055f2bf23bfd66bd14742be8065f48c36a5 Mon Sep 17 00:00:00 2001 From: Evgeny Talanin Date: Fri, 18 Sep 2020 18:58:12 +0300 Subject: [PATCH 42/64] Bump cmake version to 3.13 (#2258) --- CMakeLists.txt | 12 +----------- docs/template_plugin/CMakeLists.txt | 7 +------ inference-engine/cmake/models.cmake | 6 ------ inference-engine/ie_bridges/python/CMakeLists.txt | 2 +- inference-engine/samples/CMakeLists.txt | 2 +- ngraph/CMakeLists.txt | 2 -- ngraph/python/CMakeLists.txt | 2 +- openvino/CMakeLists.txt | 2 -- tests/fuzz/CMakeLists.txt | 11 +---------- tests/stress_tests/CMakeLists.txt | 11 +---------- tests/time_tests/CMakeLists.txt | 11 +---------- 11 files changed, 8 insertions(+), 60 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 86f821394ac177..30d074950fdad4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,17 +8,7 @@ cmake_policy(SET CMP0054 NEW) # it allows to install targets created outside of current projects # See https://blog.kitware.com/cmake-3-13-0-available-for-download/ -if (APPLE) - if(CMAKE_GENERATOR STREQUAL "Xcode") - # due to https://gitlab.kitware.com/cmake/cmake/issues/14254 - cmake_minimum_required(VERSION 3.12.0 FATAL_ERROR) - else() - # due to https://cmake.org/cmake/help/v3.12/policy/CMP0068.html - cmake_minimum_required(VERSION 3.9 FATAL_ERROR) - endif() -else() - cmake_minimum_required(VERSION 3.7.2 FATAL_ERROR) -endif() +cmake_minimum_required(VERSION 3.13 FATAL_ERROR) project(OpenVINO) diff --git a/docs/template_plugin/CMakeLists.txt b/docs/template_plugin/CMakeLists.txt index 182c6d1a54bef0..088525d3541af6 100644 --- a/docs/template_plugin/CMakeLists.txt +++ b/docs/template_plugin/CMakeLists.txt @@ -3,12 +3,7 @@ # # [cmake:main] -if (APPLE) - # due to https://cmake.org/cmake/help/v3.12/policy/CMP0068.html - cmake_minimum_required(VERSION 3.9 FATAL_ERROR) -else() - cmake_minimum_required(VERSION 3.7.2 FATAL_ERROR) -endif() +cmake_minimum_required(VERSION 3.13 FATAL_ERROR) project(InferenceEngineTemplatePlugin) diff --git a/inference-engine/cmake/models.cmake b/inference-engine/cmake/models.cmake index 0f55d6a5a3148f..69dc569048f244 100644 --- a/inference-engine/cmake/models.cmake +++ b/inference-engine/cmake/models.cmake @@ -2,12 +2,6 @@ # SPDX-License-Identifier: Apache-2.0 # -if(ENABLE_DOCKER) - cmake_minimum_required(VERSION 3.3 FATAL_ERROR) -else() - cmake_minimum_required(VERSION 3.8 FATAL_ERROR) -endif() - cmake_policy(SET CMP0054 NEW) find_package(Git REQUIRED) diff --git a/inference-engine/ie_bridges/python/CMakeLists.txt b/inference-engine/ie_bridges/python/CMakeLists.txt index 7625c51224e26f..a731f8d3e3f7bf 100644 --- a/inference-engine/ie_bridges/python/CMakeLists.txt +++ b/inference-engine/ie_bridges/python/CMakeLists.txt @@ -2,7 +2,7 @@ # SPDX-License-Identifier: Apache-2.0 # Defines the CMake commands/policies -cmake_minimum_required (VERSION 3.3) +cmake_minimum_required (VERSION 3.13) # Set the project name project (ie_python_api) diff --git a/inference-engine/samples/CMakeLists.txt b/inference-engine/samples/CMakeLists.txt index acbb9ba6b96e9b..545b9cad891d04 100644 --- a/inference-engine/samples/CMakeLists.txt +++ b/inference-engine/samples/CMakeLists.txt @@ -2,7 +2,7 @@ # SPDX-License-Identifier: Apache-2.0 # -cmake_minimum_required (VERSION 2.8.12) +cmake_minimum_required (VERSION 3.13) project(Samples) diff --git a/ngraph/CMakeLists.txt b/ngraph/CMakeLists.txt index f4ebb864b5eed1..4eb969f02b22bd 100644 --- a/ngraph/CMakeLists.txt +++ b/ngraph/CMakeLists.txt @@ -14,8 +14,6 @@ # limitations under the License. # ****************************************************************************** -cmake_minimum_required (VERSION 3.11) - # set directory where the custom finders live set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/") diff --git a/ngraph/python/CMakeLists.txt b/ngraph/python/CMakeLists.txt index bb343b99e93765..3b3f7c1303cb7c 100644 --- a/ngraph/python/CMakeLists.txt +++ b/ngraph/python/CMakeLists.txt @@ -14,7 +14,7 @@ # limitations under the License. # ****************************************************************************** -cmake_minimum_required (VERSION 3.1) +cmake_minimum_required (VERSION 3.13) project (pyngraph) diff --git a/openvino/CMakeLists.txt b/openvino/CMakeLists.txt index cf32e5880bf6b3..c0431de6f907f8 100644 --- a/openvino/CMakeLists.txt +++ b/openvino/CMakeLists.txt @@ -14,8 +14,6 @@ # limitations under the License. # ****************************************************************************** -cmake_minimum_required(VERSION 3.10) - add_subdirectory(itt) openvino_developer_export_targets(openvino::itt) diff --git a/tests/fuzz/CMakeLists.txt b/tests/fuzz/CMakeLists.txt index 8ddccb0376079d..f5946e24e52813 100644 --- a/tests/fuzz/CMakeLists.txt +++ b/tests/fuzz/CMakeLists.txt @@ -2,16 +2,7 @@ # SPDX-License-Identifier: Apache-2.0 # -if(ENABLE_DOCKER) - cmake_minimum_required(VERSION 3.3 FATAL_ERROR) -else() - if (APPLE) - # due to https://cmake.org/cmake/help/v3.12/policy/CMP0068.html - cmake_minimum_required(VERSION 3.9 FATAL_ERROR) - else() - cmake_minimum_required(VERSION 3.7.2 FATAL_ERROR) - endif() -endif() +cmake_minimum_required(VERSION 3.13 FATAL_ERROR) set(OpenVINO_MAIN_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../..) set(CMAKE_MODULE_PATH "${OpenVINO_MAIN_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH}) diff --git a/tests/stress_tests/CMakeLists.txt b/tests/stress_tests/CMakeLists.txt index 350abba955b38a..721ee87ede77b1 100644 --- a/tests/stress_tests/CMakeLists.txt +++ b/tests/stress_tests/CMakeLists.txt @@ -2,16 +2,7 @@ # SPDX-License-Identifier: Apache-2.0 # -if(ENABLE_DOCKER) - cmake_minimum_required(VERSION 3.3 FATAL_ERROR) -else() - if (APPLE) - # due to https://cmake.org/cmake/help/v3.12/policy/CMP0068.html - cmake_minimum_required(VERSION 3.9 FATAL_ERROR) - else() - cmake_minimum_required(VERSION 3.7.2 FATAL_ERROR) - endif() -endif() +cmake_minimum_required(VERSION 3.13 FATAL_ERROR) if (CMAKE_BUILD_TYPE STREQUAL "") message(STATUS "CMAKE_BUILD_TYPE not defined, 'Release' will be used") diff --git a/tests/time_tests/CMakeLists.txt b/tests/time_tests/CMakeLists.txt index e932181ce6c4e6..f4b4c670387390 100644 --- a/tests/time_tests/CMakeLists.txt +++ b/tests/time_tests/CMakeLists.txt @@ -2,16 +2,7 @@ # SPDX-License-Identifier: Apache-2.0 # -if(ENABLE_DOCKER) - cmake_minimum_required(VERSION 3.3 FATAL_ERROR) -else() - if (APPLE) - # due to https://cmake.org/cmake/help/v3.12/policy/CMP0068.html - cmake_minimum_required(VERSION 3.9 FATAL_ERROR) - else() - cmake_minimum_required(VERSION 3.7.2 FATAL_ERROR) - endif() -endif() +cmake_minimum_required(VERSION 3.13 FATAL_ERROR) if (CMAKE_BUILD_TYPE STREQUAL "") message(STATUS "CMAKE_BUILD_TYPE not defined, 'Release' will be used") From 58d8de98cc8e026e6904f38aa27bd9b886ba9c67 Mon Sep 17 00:00:00 2001 From: Anastasia Kuporosova Date: Fri, 18 Sep 2020 19:42:36 +0300 Subject: [PATCH 43/64] [Python API Tests] Update ngraph and iecore tests (#2329) Co-authored-by: Alexander Zhogov --- inference-engine/ie_bridges/python/tests/conftest.py | 2 +- inference-engine/ie_bridges/python/tests/test_NGraph.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/inference-engine/ie_bridges/python/tests/conftest.py b/inference-engine/ie_bridges/python/tests/conftest.py index 3bb64d71c6052f..75b750c9ce383c 100644 --- a/inference-engine/ie_bridges/python/tests/conftest.py +++ b/inference-engine/ie_bridges/python/tests/conftest.py @@ -32,7 +32,7 @@ def image_path(): def plugins_path(): path_to_repo = os.environ["DATA_PATH"] plugins_xml = os.path.join(path_to_repo, 'ie_class', 'plugins.xml') - plugins_win_xml = os.path.join(path_to_repo, 'ie_class', 'plugins_mingw.xml') + plugins_win_xml = os.path.join(path_to_repo, 'ie_class', 'plugins_win.xml') plugins_osx_xml = os.path.join(path_to_repo, 'ie_class', 'plugins_apple.xml') return (plugins_xml, plugins_win_xml, plugins_osx_xml) diff --git a/inference-engine/ie_bridges/python/tests/test_NGraph.py b/inference-engine/ie_bridges/python/tests/test_NGraph.py index 2380b183fdabd5..0129b523e92bbb 100644 --- a/inference-engine/ie_bridges/python/tests/test_NGraph.py +++ b/inference-engine/ie_bridges/python/tests/test_NGraph.py @@ -45,9 +45,9 @@ def test_get_ops_from_IENetwork(): '19/Fused_Add_', '21', '22', 'onnx_initializer_node_8/Output_0/Data__const', '23/WithoutBiases', '23/Dims357/copy_const', '23', '25/mean/Fused_Mul_618620_const', '24/WithoutBiases', 'data_add_578583/copy_const', '24/Fused_Add_', '26', '27', - '28/Reshape/Cast_1955_const', '28/Reshape', 'onnx_initializer_node_17/Output_0/Data__const', - '29/WithoutBiases', 'onnx_initializer_node_18/Output_0/Data_/copy_const', '29', 'fc_out', - 'fc_out/sink_port_0'] + 'Constant_223', 'onnx_initializer_node_17/Output_0/Data__const', 'ShapeOf_219', 'Constant_221', + 'Constant_220', 'Gather_222', '28/Reshape/Cast_1955_const', '28/Reshape', '29/WithoutBiases', + 'onnx_initializer_node_18/Output_0/Data_/copy_const', '29', 'fc_out', 'fc_out/sink_port_0'] def test_get_type_name(): From 60d663a7db99bcc5730975f5ae58494895643de0 Mon Sep 17 00:00:00 2001 From: Edward Shogulin Date: Fri, 18 Sep 2020 19:50:00 +0300 Subject: [PATCH 44/64] [LPT] nGraph WA removal: function tests skip config rollback --- .../functional/inference_engine/skip_tests_config.cpp | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/inference-engine/tests/functional/inference_engine/skip_tests_config.cpp b/inference-engine/tests/functional/inference_engine/skip_tests_config.cpp index 9aac831669bcbc..f7dd6f8b0ad912 100644 --- a/inference-engine/tests/functional/inference_engine/skip_tests_config.cpp +++ b/inference-engine/tests/functional/inference_engine/skip_tests_config.cpp @@ -12,16 +12,6 @@ std::vector disabledTestPatterns() { // TODO: FIX BUG 33375 // Disabled due to rare sporadic failures. ".*TransformationTests\\.ConstFoldingPriorBoxClustered.*", - - // LPT to nGraph migration: temporary disabling unexpected not reproduced fails on CI: - // https://openvino-ci.intel.com/job/private-ci/job/ie/job/build-linux-ubuntu18_i386/478/ - "*ConvertNMS4ToNMSIEDynamic1*", - "*ConvertNMS4ToNMSIEDynamic2*", - "*MishFusing*" - "*ConcatTransformation*", - "*ConcatWithIntermediateTransformation*", - "*ConcatWithNeighborsTransformation*" - // TODO: task 32568, enable after supporting constants outputs in plugins ".*TransformationTests\\.ConstFoldingPriorBox.*", }; From 61a7cdde2355094575e5e12058b6c1f6542738fe Mon Sep 17 00:00:00 2001 From: Ivan Tikhonov Date: Fri, 18 Sep 2020 21:26:21 +0300 Subject: [PATCH 45/64] Introduce opset5, include GRU/RNN/LSTM Sequences to opset5 (#2265) * introduce new opset5, include GRU/RNN/LSTM Sequences to opset5 * resolve review remarks --- docs/doxygen/ie_docs.xml | 3 + docs/ops/opset.md | 1 + docs/ops/opset5.md | 152 ++++++++++++ docs/ops/sequence/GRUSequence_5.md | 136 +++++++++++ docs/ops/sequence/RNNSequence_5.md | 128 ++++++++++ .../src/readers/ir_reader/ie_ir_parser.cpp | 2 +- .../bidirectional_sequences_decomposition.cpp | 33 +-- .../convert_sequences_to_sequences_ie.cpp | 72 +++--- .../convert_ti_to_sequences.cpp | 208 ++++++++-------- ...convert_sequences_to_sequences_ie_test.cpp | 150 ++++++------ .../convert_ti_to_sequences_test.cpp | 222 +++++++++--------- .../include/ngraph_functions/builders.hpp | 1 + .../tests/ngraph_functions/src/gru_cell.cpp | 2 +- .../tests/ngraph_functions/src/lstm_cell.cpp | 2 +- .../tests/ngraph_functions/src/rnn_cell.cpp | 2 +- ngraph/core/include/ngraph/opsets/opset.hpp | 1 + ngraph/core/include/ngraph/opsets/opset5.hpp | 29 +++ .../core/include/ngraph/opsets/opset5_tbl.hpp | 169 +++++++++++++ ngraph/core/src/opsets/opset.cpp | 19 ++ ngraph/test/attributes.cpp | 7 +- ngraph/test/type_prop/gru_sequence.cpp | 14 +- ngraph/test/type_prop/lstm_sequence.cpp | 62 ++--- ngraph/test/type_prop/rnn_sequence.cpp | 14 +- 23 files changed, 1035 insertions(+), 394 deletions(-) create mode 100644 docs/ops/opset5.md create mode 100644 docs/ops/sequence/GRUSequence_5.md create mode 100644 docs/ops/sequence/RNNSequence_5.md create mode 100644 ngraph/core/include/ngraph/opsets/opset5.hpp create mode 100644 ngraph/core/include/ngraph/opsets/opset5_tbl.hpp diff --git a/docs/doxygen/ie_docs.xml b/docs/doxygen/ie_docs.xml index cb6afcf1801947..c7f796fdf240b4 100644 --- a/docs/doxygen/ie_docs.xml +++ b/docs/doxygen/ie_docs.xml @@ -94,6 +94,7 @@ + @@ -147,6 +148,7 @@ + @@ -213,6 +215,7 @@ + diff --git a/docs/ops/opset.md b/docs/ops/opset.md index 958e7bd99b96a7..365e6bde508c9c 100644 --- a/docs/ops/opset.md +++ b/docs/ops/opset.md @@ -6,6 +6,7 @@ This topic provides a complete list of available sets of operations supported in | OpenVINOâ„¢ Version | Actual Operations Set | | :---------------- | :------------------------------- | +| 2021.2 | [opset5](opset5.md) | | 2021.1 | [opset4](opset4.md) | | 2020.4 | [opset3](opset3.md) | | 2020.3 | [opset2](opset2.md) | diff --git a/docs/ops/opset5.md b/docs/ops/opset5.md new file mode 100644 index 00000000000000..c2083aa39d0fca --- /dev/null +++ b/docs/ops/opset5.md @@ -0,0 +1,152 @@ +# Operation Set `opset5` Specification {#openvino_docs_ops_opset5} + +This specification document describes `opset5` operation set supported in OpenVINO. +Support for each particular operation from the list below depends on the capabilities available in a inference plugin +and may vary among different hardware platforms and devices. Examples of operation instances are expressed as IR V10 xml +snippets. Such IR is generated by the Model Optimizer. The semantics match corresponding nGraph operation classes +declared in `namespace opset5`. + + +## Table of Contents + +* [Abs](arithmetic/Abs_1.md) +* [Acos](arithmetic/Acos_1.md) +* [Acosh](arithmetic/Acosh_3.md) +* [Add](arithmetic/Add_1.md) +* [Asin](arithmetic/Asin_1.md) +* [Asinh](arithmetic/Asinh_3.md) +* [Assign](infrastructure/Assign_3.md) +* [Atan](arithmetic/Atan_1.md) +* [Atanh](arithmetic/Atanh_3.md) +* [AvgPool](pooling/AvgPool_1.md) +* [BatchNormInference](normalization/BatchNormInference_1.md) +* [BatchToSpace](movement/BatchToSpace_2.md) +* [BinaryConvolution](convolution/BinaryConvolution_1.md) +* [Broadcast](movement/Broadcast_3.md) +* [Bucketize](condition/Bucketize_3.md) +* [CTCGreedyDecoder](sequence/CTCGreedyDecoder_1.md) +* [CTCLoss](sequence/CTCLoss_4.md) +* [Ceiling](arithmetic/Ceiling_1.md) +* [Clamp](activation/Clamp_1.md) +* [Concat](movement/Concat_1.md) +* [Constant](infrastructure/Constant_1.md) +* [Convert](type/Convert_1.md) +* [ConvertLike](type/ConvertLike_1.md) +* [Convolution](convolution/Convolution_1.md) +* [ConvolutionBackpropData](convolution/ConvolutionBackpropData_1.md) +* [Cos](arithmetic/Cos_1.md) +* [Cosh](arithmetic/Cosh_1.md) +* [CumSum](arithmetic/CumSum_3.md) +* [DeformableConvolution](convolution/DeformableConvolution_1.md) +* [DeformablePSROIPooling](detection/DeformablePSROIPooling_1.md) +* [DepthToSpace](movement/DepthToSpace_1.md) +* [DetectionOutput](detection/DetectionOutput_1.md) +* [Divide](arithmetic/Divide_1.md) +* [Elu](activation/Elu_1.md) +* [EmbeddingBagOffsetsSum](sparse/EmbeddingBagOffsetsSum_3.md) +* [EmbeddingBagPackedSum](sparse/EmbeddingBagPackedSum_3.md) +* [EmbeddingSegmentsSum](sparse/EmbeddingSegmentsSum_3.md) +* [Equal](comparison/Equal_1.md) +* [Erf](arithmetic/Erf_1.md) +* [Exp](activation/Exp_1.md) +* [ExtractImagePatches](movement/ExtractImagePatches_3.md) +* [FakeQuantize](quantization/FakeQuantize_1.md) +* [Floor](arithmetic/Floor_1.md) +* [FloorMod](arithmetic/FloorMod_1.md) +* [Gather](movement/Gather_1.md) +* [GatherTree](movement/GatherTree_1.md) +* [Gelu](activation/GELU_2.md) +* [Greater](comparison/Greater_1.md) +* [GreaterEqual](comparison/GreaterEqual_1.md) +* [GRN](normalization/GRN_1.md) +* [GroupConvolution](convolution/GroupConvolution_1.md) +* [GroupConvolutionBackpropData](convolution/GroupConvolutionBackpropData_1.md) +* [GRUCell](sequence/GRUCell_3.md) +* [GRUSequence](sequence/GRUSequence_5.md) +* [HardSigmoid](activation/HardSigmoid_1.md) +* [HSwish](activation/HSwish_4.md) +* [Interpolate](image/Interpolate_4.md) +* [Less](comparison/Less_1.md) +* [LessEqual](comparison/LessEqual_1.md) +* [Log](arithmetic/Log_1.md) +* [LogicalAnd](logical/LogicalAnd_1.md) +* [LogicalNot](logical/LogicalNot_1.md) +* [LogicalOr](logical/LogicalOr_1.md) +* [LogicalXor](logical/LogicalXor_1.md) +* [LRN](normalization/LRN_1.md) +* [LSTMCell](sequence/LSTMCell_1.md) +* [LSTMSequence](sequence/LSTMSequence_1.md) +* [MatMul](matrix/MatMul_1.md) +* [MaxPool](pooling/MaxPool_1.md) +* [Maximum](arithmetic/Maximum_1.md) +* [Minimum](arithmetic/Minimum_1.md) +* [Mish](activation/Mish_4.md) +* [Mod](arithmetic/Mod_1.md) +* [MVN](normalization/MVN_1.md) +* [Multiply](arithmetic/Multiply_1.md) +* [Negative](arithmetic/Negative_1.md) +* [NonMaxSuppression](sort/NonMaxSuppression_4.md) +* [NonZero](condition/NonZero_3.md) +* [NormalizeL2](normalization/NormalizeL2_1.md) +* [NotEqual](comparison/NotEqual_1.md) +* [OneHot](sequence/OneHot_1.md) +* [Pad](movement/Pad_1.md) +* [Parameter](infrastructure/Parameter_1.md) +* [Power](arithmetic/Power_1.md) +* [PReLU](activation/PReLU_1.md) +* [PriorBoxClustered](detection/PriorBoxClustered_1.md) +* [PriorBox](detection/PriorBox_1.md) +* [Proposal](detection/Proposal_4.md) +* [PSROIPooling](detection/PSROIPooling_1.md) +* [Range](generation/Range_4.md) +* [ReLU](activation/ReLU_1.md) +* [ReadValue](infrastructure/ReadValue_3.md) +* [ReduceL1](reduction/ReduceL1_4.md) +* [ReduceL2](reduction/ReduceL2_4.md) +* [ReduceLogicalAnd](reduction/ReduceLogicalAnd_1.md) +* [ReduceLogicalOr](reduction/ReduceLogicalOr_1.md) +* [ReduceMax](reduction/ReduceMax_1.md) +* [ReduceMean](reduction/ReduceMean_1.md) +* [ReduceMin](reduction/ReduceMin_1.md) +* [ReduceProd](reduction/ReduceProd_1.md) +* [ReduceSum](reduction/ReduceSum_1.md) +* [RegionYolo](detection/RegionYolo_1.md) +* [ReorgYolo](detection/ReorgYolo_1.md) +* [Reshape](shape/Reshape_1.md) +* [Result](infrastructure/Result_1.md) +* [Reverse](movement/Reverse_1.md) +* [ReverseSequence](movement/ReverseSequence_1.md) +* [RNNCell](sequence/RNNCell_3.md) +* [RNNSequence](sequence/RNNSequence_5.md) +* [ROIAlign](detection/ROIAlign_3.md) +* [ROIPooling](detection/ROIPooling_1.md) +* [ScatterElementsUpdate](movement/ScatterElementsUpdate_3.md) +* [ScatterNDUpdate](movement/ScatterNDUpdate_3.md) +* [ScatterUpdate](movement/ScatterUpdate_3.md) +* [Select](condition/Select_1.md) +* [Selu](arithmetic/Selu_1.md) +* [ShapeOf](shape/ShapeOf_3.md) +* [ShuffleChannels](movement/ShuffleChannels_1.md) +* [Sigmoid](activation/Sigmoid_1.md) +* [Sign](arithmetic/Sign_1.md) +* [Sin](arithmetic/Sin_1.md) +* [Sinh](arithmetic/Sinh_1.md) +* [SoftMax](activation/SoftMax_1.md) +* [SoftPlus](activation/SoftPlus_4.md) +* [SpaceToBatch](movement/SpaceToBatch_2.md) +* [SpaceToDepth](movement/SpaceToDepth_1.md) +* [Split](movement/Split_1.md) +* [Sqrt](arithmetic/Sqrt_1.md) +* [SquaredDifference](arithmetic/SquaredDifference_1.md) +* [Squeeze](shape/Squeeze_1.md) +* [StridedSlice](movement/StridedSlice_1.md) +* [Subtract](arithmetic/Subtract_1.md) +* [Swish](activation/Swish_4.md) +* [Tan](arithmetic/Tan_1.md) +* [Tanh](arithmetic/Tanh_1.md) +* [TensorIterator](infrastructure/TensorIterator_1.md) +* [Tile](movement/Tile_1.md) +* [TopK](sort/TopK_3.md) +* [Transpose](movement/Transpose_1.md) +* [Unsqueeze](shape/Unsqueeze_1.md) +* [VariadicSplit](movement/VariadicSplit_1.md) diff --git a/docs/ops/sequence/GRUSequence_5.md b/docs/ops/sequence/GRUSequence_5.md new file mode 100644 index 00000000000000..67ee6973e7b147 --- /dev/null +++ b/docs/ops/sequence/GRUSequence_5.md @@ -0,0 +1,136 @@ +## GRUSequence {#openvino_docs_ops_sequence_GRUSequence_5} + +**Versioned name**: *GRUSequence-5* + +**Category**: *Sequence processing* + +**Short description**: *GRUSequence* operation represents a series of GRU cells. Each cell is implemented as GRUCell operation. + +**Detailed description** + +A single cell in the sequence is implemented in the same way as in GRUCell operation. *GRUSequence* represents a sequence of GRU cells. The sequence can be connected differently depending on `direction` attribute that specifies the direction of traversing of input data along sequence dimension or specifies whether it should be a bidirectional sequence. The most of the attributes are in sync with the specification of ONNX GRU operator defined GRUCell. + + +**Attributes** + +* *hidden_size* + + * **Description**: *hidden_size* specifies hidden state size. + * **Range of values**: a positive integer + * **Type**: `int` + * **Default value**: None + * **Required**: *yes* + +* *activations* + + * **Description**: *activations* specifies activation functions for gates, there are two gates, so two activation functions should be specified as a value for this attributes + * **Range of values**: any combination of *relu*, *sigmoid*, *tanh* + * **Type**: a list of strings + * **Default value**: *sigmoid,tanh* + * **Required**: *no* + +* *activations_alpha, activations_beta* + + * **Description**: *activations_alpha, activations_beta* attributes of functions; applicability and meaning of these attributes depends on choosen activation functions + * **Range of values**: a list of floating-point numbers + * **Type**: `float[]` + * **Default value**: None + * **Required**: *no* + +* *clip* + + * **Description**: *clip* specifies bound values *[-C, C]* for tensor clipping. Clipping is performed before activations. + * **Range of values**: a positive floating-point number + * **Type**: `float` + * **Default value**: *infinity* that means that the clipping is not applied + * **Required**: *no* + +* *direction* + + * **Description**: Specify if the RNN is forward, reverse, or bidirectional. If it is one of *forward* or *reverse* then `num_directions = 1`, if it is *bidirectional*, then `num_directions = 2`. This `num_directions` value specifies input/output shape requirements. + * **Range of values**: *forward*, *reverse*, *bidirectional* + * **Type**: `string` + * **Default value**: None + * **Required**: *Yes* + +* *linear_before_reset* + + * **Description**: *linear_before_reset* flag denotes if the layer behaves according to the modification of *GRUCell* described in the formula in the [ONNX documentation](https://github.com/onnx/onnx/blob/master/docs/Operators.md#GRU). + * **Range of values**: True or False + * **Type**: `boolean` + * **Default value**: False + * **Required**: *no* + +**Inputs** + +* **1**: `X` - 3D tensor of type *T1* `[batch_size, seq_length, input_size]`, input data. It differs from GRUCell 1st input only by additional axis with size `seq_length`. **Required.** + +* **2**: `initial_hidden_state` - 3D tensor of type *T1* `[batch_size, num_directions, hidden_size]`, input hidden state data. **Required.** + +* **3**: `sequence_lengths` - 1D tensor of type *T2* `[batch_size]`, specifies real sequence lengths for each batch element. **Required.** + +* **4**: `W` - 3D tensor of type *T1* `[num_directions, 3 * hidden_size, input_size]`, the weights for matrix multiplication, gate order: zrh. **Required.** + +* **5**: `R` - 3D tensor of type *T1* `[num_directions, 3 * hidden_size, hidden_size]`, the recurrence weights for matrix multiplication, gate order: zrh. **Required.** + +* **6**: `B` - 2D tensor of type *T*. If *linear_before_reset* is set to 1, then the shape is `[num_directions, 4 * hidden_size]` - the sum of biases for z and r gates (weights and recurrence weights), the biases for h gate are placed separately. Otherwise the shape is `[num_directions, 3 * hidden_size]`, the sum of biases (weights and recurrence weights). **Required.** + +**Outputs** + +* **1**: `Y` – 3D tensor of type *T1* `[batch_size, num_directions, seq_len, hidden_size]`, concatenation of all the intermediate output values of the hidden. + +* **2**: `Ho` - 3D tensor of type *T1* `[batch_size, num_directions, hidden_size]`, the last output value of hidden state. + +**Types** + +* *T1*: any supported floating point type. +* *T2*: any supported integer type. + +**Example** +```xml + + + + + 1 + 4 + 16 + + + 1 + 1 + 128 + + + 1 + + + 1 + 384 + 16 + + + 1 + 384 + 128 + + + 1 + 384 + + + + + 1 + 1 + 4 + 128 + + + 1 + 1 + 128 + + + +``` \ No newline at end of file diff --git a/docs/ops/sequence/RNNSequence_5.md b/docs/ops/sequence/RNNSequence_5.md new file mode 100644 index 00000000000000..fb64c3c7178590 --- /dev/null +++ b/docs/ops/sequence/RNNSequence_5.md @@ -0,0 +1,128 @@ +## RNNSequence {#openvino_docs_ops_sequence_RNNSequence_5} + +**Versioned name**: *RNNSequence-5* + +**Category**: *Sequence processing* + +**Short description**: *RNNSequence* operation represents a series of RNN cells. Each cell is implemented as RNNCell operation. + +**Detailed description** + +A single cell in the sequence is implemented in the same way as in RNNCell operation. *RNNSequence* represents a sequence of RNN cells. The sequence can be connected differently depending on `direction` attribute that specifies the direction of traversing of input data along sequence dimension or specifies whether it should be a bidirectional sequence. The most of the attributes are in sync with the specification of ONNX RNN operator defined RNNCell. + + +**Attributes** + +* *hidden_size* + + * **Description**: *hidden_size* specifies hidden state size. + * **Range of values**: a positive integer + * **Type**: `int` + * **Default value**: None + * **Required**: *yes* + +* *activations* + + * **Description**: activation functions for gates + * **Range of values**: any combination of *relu*, *sigmoid*, *tanh* + * **Type**: a list of strings + * **Default value**: *tanh* + * **Required**: *no* + +* *activations_alpha, activations_beta* + + * **Description**: *activations_alpha, activations_beta* attributes of functions; applicability and meaning of these attributes depends on choosen activation functions + * **Range of values**: a list of floating-point numbers + * **Type**: `float[]` + * **Default value**: None + * **Required**: *no* + +* *clip* + + * **Description**: *clip* specifies bound values *[-C, C]* for tensor clipping. Clipping is performed before activations. + * **Range of values**: a positive floating-point number + * **Type**: `float` + * **Default value**: *infinity* that means that the clipping is not applied + * **Required**: *no* + +* *direction* + + * **Description**: Specify if the RNN is forward, reverse, or bidirectional. If it is one of *forward* or *reverse* then `num_directions = 1`, if it is *bidirectional*, then `num_directions = 2`. This `num_directions` value specifies input/output shape requirements. + * **Range of values**: *forward*, *reverse*, *bidirectional* + * **Type**: `string` + * **Default value**: None + * **Required**: *Yes* + +**Inputs** + +* **1**: `X` - 3D tensor of type *T1* `[batch_size, seq_length, input_size]`, input data. It differs from RNNCell 1st input only by additional axis with size `seq_length`. **Required.** + +* **2**: `initial_hidden_state` - 3D tensor of type *T1* `[batch_size, num_directions, hidden_size]`, input hidden state data. **Required.** + +* **3**: `sequence_lengths` - 1D tensor of type *T2* `[batch_size]`, specifies real sequence lengths for each batch element. **Required.** + +* **4**: `W` - 3D tensor of type *T1* `[num_directions, hidden_size, input_size]`, the weights for matrix multiplication. **Required.** + +* **5**: `R` - 3D tensor of type *T1* `[num_directions, hidden_size, hidden_size]`, the recurrence weights for matrix multiplication. **Required.** + +* **6**: `B` - 2D tensor of type *T1* `[num_directions, hidden_size]`, the sum of biases (weights and recurrence weights). **Required.** + +**Outputs** + +* **1**: `Y` – 3D tensor of type *T1* `[batch_size, num_directions, seq_len, hidden_size]`, concatenation of all the intermediate output values of the hidden. + +* **2**: `Ho` - 3D tensor of type *T1* `[batch_size, num_directions, hidden_size]`, the last output value of hidden state. + +**Types** + +* *T1*: any supported floating point type. +* *T2*: any supported integer type. + +**Example** +```xml + + + + + 1 + 4 + 16 + + + 1 + 1 + 128 + + + 1 + + + 1 + 128 + 16 + + + 1 + 128 + 128 + + + 1 + 128 + + + + + 1 + 1 + 4 + 128 + + + 1 + 1 + 128 + + + +``` \ No newline at end of file diff --git a/inference-engine/src/readers/ir_reader/ie_ir_parser.cpp b/inference-engine/src/readers/ir_reader/ie_ir_parser.cpp index 6ae0c1d56289e4..811b1d29cd1754 100644 --- a/inference-engine/src/readers/ir_reader/ie_ir_parser.cpp +++ b/inference-engine/src/readers/ir_reader/ie_ir_parser.cpp @@ -486,7 +486,7 @@ std::shared_ptr V10Parser::createNode(const std::vector bool { - for (size_t i = 1; i <= 4; i++) { + for (size_t i = 1; i <= 5; i++) { std::string opset_name = "opset" + std::to_string(i); if (version == opset_name) return true; diff --git a/inference-engine/src/transformations/src/transformations/bidirectional_sequences_decomposition.cpp b/inference-engine/src/transformations/src/transformations/bidirectional_sequences_decomposition.cpp index 1df3c61f7c1f5a..ac5021d670c14e 100644 --- a/inference-engine/src/transformations/src/transformations/bidirectional_sequences_decomposition.cpp +++ b/inference-engine/src/transformations/src/transformations/bidirectional_sequences_decomposition.cpp @@ -7,14 +7,15 @@ #include #include +#include #include #include ngraph::pass::BidirectionalLSTMSequenceDecomposition::BidirectionalLSTMSequenceDecomposition() { - auto lstm_sequence_ngraph = ngraph::pattern::wrap_type(); + auto lstm_sequence_ngraph = ngraph::pattern::wrap_type(); ngraph::matcher_pass_callback callback = [](pattern::Matcher &m) { - auto lstm_sequence = std::dynamic_pointer_cast(m.get_match_root()); + auto lstm_sequence = std::dynamic_pointer_cast(m.get_match_root()); if (!lstm_sequence) { return false; } @@ -44,7 +45,7 @@ ngraph::pass::BidirectionalLSTMSequenceDecomposition::BidirectionalLSTMSequenceD lstm_sequence->get_activations(), lstm_sequence->get_clip()); - auto lstm_sequence_reverse = std::make_shared( + auto lstm_sequence_reverse = std::make_shared( lstm_sequence->input_value(0), H->output(1), C->output(1), @@ -59,11 +60,11 @@ ngraph::pass::BidirectionalLSTMSequenceDecomposition::BidirectionalLSTMSequenceD lstm_sequence->get_activations(), lstm_sequence->get_clip()); - auto concat_0 = std::make_shared(OutputVector{lstm_sequence_forward->output(0), + auto concat_0 = std::make_shared(OutputVector{lstm_sequence_forward->output(0), lstm_sequence_reverse->output(0)}, 1); - auto concat_1 = std::make_shared(OutputVector{lstm_sequence_forward->output(1), + auto concat_1 = std::make_shared(OutputVector{lstm_sequence_forward->output(1), lstm_sequence_reverse->output(1)}, 1); - auto concat_2 = std::make_shared(OutputVector{lstm_sequence_forward->output(2), + auto concat_2 = std::make_shared(OutputVector{lstm_sequence_forward->output(2), lstm_sequence_reverse->output(2)}, 1); ngraph::copy_runtime_info(lstm_sequence, {H, C, W, R, B, lstm_sequence_forward, lstm_sequence_reverse, concat_0, concat_1, concat_2}); @@ -79,10 +80,10 @@ ngraph::pass::BidirectionalLSTMSequenceDecomposition::BidirectionalLSTMSequenceD } ngraph::pass::BidirectionalGRUSequenceDecomposition::BidirectionalGRUSequenceDecomposition() { - auto gru_sequence_ngraph = ngraph::pattern::wrap_type(); + auto gru_sequence_ngraph = ngraph::pattern::wrap_type(); ngraph::matcher_pass_callback callback = [](pattern::Matcher &m) { - auto gru_sequence = std::dynamic_pointer_cast(m.get_match_root()); + auto gru_sequence = std::dynamic_pointer_cast(m.get_match_root()); if (!gru_sequence) { return false; } @@ -111,7 +112,7 @@ ngraph::pass::BidirectionalGRUSequenceDecomposition::BidirectionalGRUSequenceDec gru_sequence->get_clip(), gru_sequence->get_linear_before_reset()); - auto gru_sequence_reverse = std::make_shared( + auto gru_sequence_reverse = std::make_shared( gru_sequence->input_value(0), H->output(1), gru_sequence->input_value(2), @@ -126,9 +127,9 @@ ngraph::pass::BidirectionalGRUSequenceDecomposition::BidirectionalGRUSequenceDec gru_sequence->get_clip(), gru_sequence->get_linear_before_reset()); - auto concat_0 = std::make_shared(OutputVector{gru_sequence_forward->output(0), + auto concat_0 = std::make_shared(OutputVector{gru_sequence_forward->output(0), gru_sequence_reverse->output(0)}, 1); - auto concat_1 = std::make_shared(OutputVector{gru_sequence_forward->output(1), + auto concat_1 = std::make_shared(OutputVector{gru_sequence_forward->output(1), gru_sequence_reverse->output(1)}, 1); ngraph::copy_runtime_info(gru_sequence, {H, W, R, B, gru_sequence_forward, gru_sequence_reverse, concat_0, concat_1}); @@ -143,10 +144,10 @@ ngraph::pass::BidirectionalGRUSequenceDecomposition::BidirectionalGRUSequenceDec } ngraph::pass::BidirectionalRNNSequenceDecomposition::BidirectionalRNNSequenceDecomposition() { - auto rnn_sequence_ngraph = ngraph::pattern::wrap_type(); + auto rnn_sequence_ngraph = ngraph::pattern::wrap_type(); ngraph::matcher_pass_callback callback = [](pattern::Matcher &m) { - auto rnn_sequence = std::dynamic_pointer_cast(m.get_match_root()); + auto rnn_sequence = std::dynamic_pointer_cast(m.get_match_root()); if (!rnn_sequence) { return false; } @@ -174,7 +175,7 @@ ngraph::pass::BidirectionalRNNSequenceDecomposition::BidirectionalRNNSequenceDec rnn_sequence->get_activations_beta(), rnn_sequence->get_clip()); - auto rnn_sequence_reverse = std::make_shared( + auto rnn_sequence_reverse = std::make_shared( rnn_sequence->input_value(0), H->output(1), rnn_sequence->input_value(2), @@ -188,9 +189,9 @@ ngraph::pass::BidirectionalRNNSequenceDecomposition::BidirectionalRNNSequenceDec rnn_sequence->get_activations_beta(), rnn_sequence->get_clip()); - auto concat_0 = std::make_shared(OutputVector{rnn_sequence_forward->output(0), + auto concat_0 = std::make_shared(OutputVector{rnn_sequence_forward->output(0), rnn_sequence_reverse->output(0)}, 1); - auto concat_1 = std::make_shared(OutputVector{rnn_sequence_forward->output(1), + auto concat_1 = std::make_shared(OutputVector{rnn_sequence_forward->output(1), rnn_sequence_reverse->output(1)}, 1); ngraph::copy_runtime_info(rnn_sequence, {H, W, R, B, rnn_sequence_forward, rnn_sequence_reverse, concat_0, concat_1}); diff --git a/inference-engine/src/transformations/src/transformations/convert_opset1_to_legacy/convert_sequences_to_sequences_ie.cpp b/inference-engine/src/transformations/src/transformations/convert_opset1_to_legacy/convert_sequences_to_sequences_ie.cpp index 3f8018019ffbab..36bec24eb77629 100644 --- a/inference-engine/src/transformations/src/transformations/convert_opset1_to_legacy/convert_sequences_to_sequences_ie.cpp +++ b/inference-engine/src/transformations/src/transformations/convert_opset1_to_legacy/convert_sequences_to_sequences_ie.cpp @@ -6,7 +6,7 @@ #include -#include +#include #include #include @@ -15,10 +15,10 @@ #include ngraph::pass::ConvertLSTMSequenceMatcher::ConvertLSTMSequenceMatcher() { - auto lstm_sequence_ngraph = ngraph::pattern::wrap_type(); + auto lstm_sequence_ngraph = ngraph::pattern::wrap_type(); ngraph::matcher_pass_callback callback = [](pattern::Matcher &m) { - auto lstm_sequence = std::dynamic_pointer_cast(m.get_match_root()); + auto lstm_sequence = std::dynamic_pointer_cast(m.get_match_root()); if (!lstm_sequence) { return false; } @@ -31,13 +31,13 @@ ngraph::pass::ConvertLSTMSequenceMatcher::ConvertLSTMSequenceMatcher() { return false; // for forward/reverse cases we can squeeze num_direction dimension - auto axis_1 = ngraph::opset4::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {1}); - auto in_1 = std::make_shared(lstm_sequence->input_value(1), axis_1); - auto in_2 = std::make_shared(lstm_sequence->input_value(2), axis_1); - auto concat = std::make_shared(ngraph::OutputVector{W, R}, 2); - auto axis_2 = ngraph::opset4::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {0}); - auto in_3 = std::make_shared(concat->output(0), axis_2); - auto in_4 = std::make_shared(lstm_sequence->input_value(6), axis_2); + auto axis_1 = ngraph::opset5::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {1}); + auto in_1 = std::make_shared(lstm_sequence->input_value(1), axis_1); + auto in_2 = std::make_shared(lstm_sequence->input_value(2), axis_1); + auto concat = std::make_shared(ngraph::OutputVector{W, R}, 2); + auto axis_2 = ngraph::opset5::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {0}); + auto in_3 = std::make_shared(concat->output(0), axis_2); + auto in_4 = std::make_shared(lstm_sequence->input_value(6), axis_2); auto lstm_sequence_ie = std::make_shared( lstm_sequence->input(0).get_source_output(), // X in_1, // initial_hidden_state @@ -52,10 +52,10 @@ ngraph::pass::ConvertLSTMSequenceMatcher::ConvertLSTMSequenceMatcher() { lstm_sequence->get_activations_beta(), lstm_sequence->get_clip()); - auto unsqueeze_axis = ngraph::opset4::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {1}); - auto unsqueeze_1 = std::make_shared(lstm_sequence_ie->output(0), unsqueeze_axis); - auto unsqueeze_2 = std::make_shared(lstm_sequence_ie->output(1), unsqueeze_axis); - auto unsqueeze_3 = std::make_shared(lstm_sequence_ie->output(2), unsqueeze_axis); + auto unsqueeze_axis = ngraph::opset5::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {1}); + auto unsqueeze_1 = std::make_shared(lstm_sequence_ie->output(0), unsqueeze_axis); + auto unsqueeze_2 = std::make_shared(lstm_sequence_ie->output(1), unsqueeze_axis); + auto unsqueeze_3 = std::make_shared(lstm_sequence_ie->output(2), unsqueeze_axis); ngraph::copy_runtime_info(lstm_sequence, {concat, lstm_sequence_ie, in_1, in_2, in_3, in_4, unsqueeze_1, unsqueeze_2, unsqueeze_3}); @@ -71,10 +71,10 @@ ngraph::pass::ConvertLSTMSequenceMatcher::ConvertLSTMSequenceMatcher() { } ngraph::pass::ConvertGRUSequenceMatcher::ConvertGRUSequenceMatcher() { - auto gru_sequence_ngraph = ngraph::pattern::wrap_type(); + auto gru_sequence_ngraph = ngraph::pattern::wrap_type(); ngraph::matcher_pass_callback callback = [](pattern::Matcher &m) { - auto gru_sequence = std::dynamic_pointer_cast(m.get_match_root()); + auto gru_sequence = std::dynamic_pointer_cast(m.get_match_root()); if (!gru_sequence) { return false; } @@ -87,12 +87,12 @@ ngraph::pass::ConvertGRUSequenceMatcher::ConvertGRUSequenceMatcher() { return false; // for forward/reverse cases we can squeeze num_direction dimension - auto axis_1 = ngraph::opset4::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {1}); - auto in_1 = std::make_shared(gru_sequence->input_value(1), axis_1); - auto concat = std::make_shared(ngraph::OutputVector{W, R}, 2); - auto axis_2 = ngraph::opset4::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {0}); - auto in_3 = std::make_shared(concat->output(0), axis_2); - auto in_4 = std::make_shared(gru_sequence->input_value(5), axis_2); + auto axis_1 = ngraph::opset5::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {1}); + auto in_1 = std::make_shared(gru_sequence->input_value(1), axis_1); + auto concat = std::make_shared(ngraph::OutputVector{W, R}, 2); + auto axis_2 = ngraph::opset5::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {0}); + auto in_3 = std::make_shared(concat->output(0), axis_2); + auto in_4 = std::make_shared(gru_sequence->input_value(5), axis_2); auto gru_sequence_ie = std::make_shared( gru_sequence->input_value(0), // X @@ -108,9 +108,9 @@ ngraph::pass::ConvertGRUSequenceMatcher::ConvertGRUSequenceMatcher() { gru_sequence->get_clip(), gru_sequence->get_linear_before_reset()); - auto unsqueeze_axis = ngraph::opset4::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {1}); - auto unsqueeze_1 = std::make_shared(gru_sequence_ie->output(0), unsqueeze_axis); - auto unsqueeze_2 = std::make_shared(gru_sequence_ie->output(1), unsqueeze_axis); + auto unsqueeze_axis = ngraph::opset5::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {1}); + auto unsqueeze_1 = std::make_shared(gru_sequence_ie->output(0), unsqueeze_axis); + auto unsqueeze_2 = std::make_shared(gru_sequence_ie->output(1), unsqueeze_axis); ngraph::copy_runtime_info(gru_sequence, {concat, gru_sequence_ie, unsqueeze_1, unsqueeze_2, in_1, in_3, in_4}); unsqueeze_1->set_friendly_name(gru_sequence->get_friendly_name()+".0"); @@ -124,10 +124,10 @@ ngraph::pass::ConvertGRUSequenceMatcher::ConvertGRUSequenceMatcher() { } ngraph::pass::ConvertRNNSequenceMatcher::ConvertRNNSequenceMatcher() { - auto rnn_sequence_ngraph = ngraph::pattern::wrap_type(); + auto rnn_sequence_ngraph = ngraph::pattern::wrap_type(); ngraph::matcher_pass_callback callback = [](pattern::Matcher &m) { - auto rnn_sequence = std::dynamic_pointer_cast(m.get_match_root()); + auto rnn_sequence = std::dynamic_pointer_cast(m.get_match_root()); if (!rnn_sequence) { return false; } @@ -140,12 +140,12 @@ ngraph::pass::ConvertRNNSequenceMatcher::ConvertRNNSequenceMatcher() { auto R = rnn_sequence->input_value(4); // for forward/reverse cases we can squeeze num_direction dimension - auto axis_1 = ngraph::opset4::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {1}); - auto in_1 = std::make_shared(rnn_sequence->input_value(1), axis_1); - auto concat = std::make_shared(ngraph::OutputVector{W, R}, 2); - auto axis_2 = ngraph::opset4::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {0}); - auto in_3 = std::make_shared(concat->output(0), axis_2); - auto in_4 = std::make_shared(rnn_sequence->input_value(5), axis_2); + auto axis_1 = ngraph::opset5::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {1}); + auto in_1 = std::make_shared(rnn_sequence->input_value(1), axis_1); + auto concat = std::make_shared(ngraph::OutputVector{W, R}, 2); + auto axis_2 = ngraph::opset5::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {0}); + auto in_3 = std::make_shared(concat->output(0), axis_2); + auto in_4 = std::make_shared(rnn_sequence->input_value(5), axis_2); auto rnn_sequence_ie = std::make_shared( rnn_sequence->input_value(0), // X in_1, // initial_hidden_state @@ -159,9 +159,9 @@ ngraph::pass::ConvertRNNSequenceMatcher::ConvertRNNSequenceMatcher() { rnn_sequence->get_activations_beta(), rnn_sequence->get_clip()); - auto unsqueeze_axis = ngraph::opset4::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {1}); - auto unsqueeze_1 = std::make_shared(rnn_sequence_ie->output(0), unsqueeze_axis); - auto unsqueeze_2 = std::make_shared(rnn_sequence_ie->output(1), unsqueeze_axis); + auto unsqueeze_axis = ngraph::opset5::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {1}); + auto unsqueeze_1 = std::make_shared(rnn_sequence_ie->output(0), unsqueeze_axis); + auto unsqueeze_2 = std::make_shared(rnn_sequence_ie->output(1), unsqueeze_axis); ngraph::copy_runtime_info(rnn_sequence, {concat, rnn_sequence_ie, in_1, in_3, in_4, unsqueeze_1, unsqueeze_2}); diff --git a/inference-engine/src/transformations/src/transformations/tensor_iterator_transformations/convert_ti_to_sequences.cpp b/inference-engine/src/transformations/src/transformations/tensor_iterator_transformations/convert_ti_to_sequences.cpp index b7eac6241109b8..9908ed09fa8442 100644 --- a/inference-engine/src/transformations/src/transformations/tensor_iterator_transformations/convert_ti_to_sequences.cpp +++ b/inference-engine/src/transformations/src/transformations/tensor_iterator_transformations/convert_ti_to_sequences.cpp @@ -10,7 +10,7 @@ #include #include -#include +#include #include #include #include @@ -18,28 +18,28 @@ ngraph::pass::ConvertTensorIteratorToLSTMSequence::ConvertTensorIteratorToLSTMSequence() { auto tensor_iterator = std::make_shared(ngraph::element::f32, - ngraph::Shape{}, ngraph::pattern::has_class()); + ngraph::Shape{}, ngraph::pattern::has_class()); ngraph::matcher_pass_callback callback = [this](pattern::Matcher &m) { - auto ti = std::dynamic_pointer_cast(m.get_match_root()); + auto ti = std::dynamic_pointer_cast(m.get_match_root()); if (!ti || !m_transformation_callback(ti)) return false; // create pattern - auto data = std::make_shared(ngraph::element::f32, ngraph::Shape{1, 1, 1}); - auto axis_squeeze = std::make_shared(ngraph::element::i64, ngraph::Shape{1}, 1); + auto data = std::make_shared(ngraph::element::f32, ngraph::Shape{1, 1, 1}); + auto axis_squeeze = std::make_shared(ngraph::element::i64, ngraph::Shape{1}, 1); - auto input_data = std::make_shared(data, axis_squeeze); - auto input_H_state = std::make_shared(ngraph::element::f32, ngraph::Shape{1, 1}); - auto input_C_state = std::make_shared(ngraph::element::f32, ngraph::Shape{1, 1}); - auto input_W = std::make_shared(ngraph::element::f32, ngraph::Shape{4, 1}); - auto input_R = std::make_shared(ngraph::element::f32, ngraph::Shape{4, 1}); - auto input_B = std::make_shared(ngraph::element::f32, ngraph::Shape{4}); + auto input_data = std::make_shared(data, axis_squeeze); + auto input_H_state = std::make_shared(ngraph::element::f32, ngraph::Shape{1, 1}); + auto input_C_state = std::make_shared(ngraph::element::f32, ngraph::Shape{1, 1}); + auto input_W = std::make_shared(ngraph::element::f32, ngraph::Shape{4, 1}); + auto input_R = std::make_shared(ngraph::element::f32, ngraph::Shape{4, 1}); + auto input_B = std::make_shared(ngraph::element::f32, ngraph::Shape{4}); - auto cell = std::make_shared(input_data, input_H_state, input_C_state, + auto cell = std::make_shared(input_data, input_H_state, input_C_state, input_W, input_R, input_B, 1); - auto axis_unsqueeze = std::make_shared(ngraph::element::i64, ngraph::Shape{1}, 1); - auto unsqueeze = std::make_shared(cell, axis_unsqueeze); + auto axis_unsqueeze = std::make_shared(ngraph::element::i64, ngraph::Shape{1}, 1); + auto unsqueeze = std::make_shared(cell, axis_unsqueeze); ngraph::pattern::Matcher matcher(unsqueeze); bool match = false; @@ -57,7 +57,7 @@ ngraph::pass::ConvertTensorIteratorToLSTMSequence::ConvertTensorIteratorToLSTMSe auto pattern_map = matcher.get_pattern_map(); auto params = func->get_parameters(); - std::vector> ordered_in_descs(3); + std::vector> ordered_in_descs(3); int64_t stride = 0, slice_axis = 0; size_t batch_size = 0; for (const auto& input_desc : ti->get_input_descriptions()) { @@ -68,7 +68,7 @@ ngraph::pass::ConvertTensorIteratorToLSTMSequence::ConvertTensorIteratorToLSTMSe return false; } auto slice_input - = std::dynamic_pointer_cast(input_desc); + = std::dynamic_pointer_cast(input_desc); if (!slice_input) return false; @@ -90,12 +90,12 @@ ngraph::pass::ConvertTensorIteratorToLSTMSequence::ConvertTensorIteratorToLSTMSe } auto results = func->get_results(); - std::vector> ordered_out_descs(3); + std::vector> ordered_out_descs(3); for (const auto& output_desc : ti->get_output_descriptions()) { - std::shared_ptr res = results[output_desc->m_body_value_index]; + std::shared_ptr res = results[output_desc->m_body_value_index]; if (res->get_input_source_output(0) == pattern_map[unsqueeze]) { auto concat_output - = std::dynamic_pointer_cast(output_desc); + = std::dynamic_pointer_cast(output_desc); if (!concat_output) return false; @@ -110,22 +110,22 @@ ngraph::pass::ConvertTensorIteratorToLSTMSequence::ConvertTensorIteratorToLSTMSe } } - auto seq_lengths = ngraph::opset4::Constant::create(element::i32, Shape{batch_size}, {ti->get_num_iterations()}); - const auto& lstm_cell = std::dynamic_pointer_cast(pattern_map[cell]); + auto seq_lengths = ngraph::opset5::Constant::create(element::i32, Shape{batch_size}, {ti->get_num_iterations()}); + const auto& lstm_cell = std::dynamic_pointer_cast(pattern_map[cell]); auto in_0 = ti->input_values()[ordered_in_descs[0]->m_input_index]; if (slice_axis == 0) { - auto order = ngraph::opset4::Constant::create(ngraph::element::i64, ngraph::Shape{3}, {1, 0, 2}); - in_0 = std::make_shared(ti->input_values()[ordered_in_descs[0]->m_input_index], order); + auto order = ngraph::opset5::Constant::create(ngraph::element::i64, ngraph::Shape{3}, {1, 0, 2}); + in_0 = std::make_shared(ti->input_values()[ordered_in_descs[0]->m_input_index], order); } - auto axis_1 = ngraph::opset4::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {1}); - auto in_1 = std::make_shared(ti->input_values()[ordered_in_descs[1]->m_input_index], axis_1); - auto in_2 = std::make_shared(ti->input_values()[ordered_in_descs[2]->m_input_index], axis_1); - - auto axis_2 = ngraph::opset4::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {0}); - auto in_4 = std::make_shared(pattern_map[input_W]->output(0).get_node_shared_ptr(), axis_2); - auto in_5 = std::make_shared(pattern_map[input_R]->output(0).get_node_shared_ptr(), axis_2); - auto in_6 = std::make_shared(pattern_map[input_B]->output(0).get_node_shared_ptr(), axis_2); - auto sequence = std::make_shared( + auto axis_1 = ngraph::opset5::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {1}); + auto in_1 = std::make_shared(ti->input_values()[ordered_in_descs[1]->m_input_index], axis_1); + auto in_2 = std::make_shared(ti->input_values()[ordered_in_descs[2]->m_input_index], axis_1); + + auto axis_2 = ngraph::opset5::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {0}); + auto in_4 = std::make_shared(pattern_map[input_W]->output(0).get_node_shared_ptr(), axis_2); + auto in_5 = std::make_shared(pattern_map[input_R]->output(0).get_node_shared_ptr(), axis_2); + auto in_6 = std::make_shared(pattern_map[input_B]->output(0).get_node_shared_ptr(), axis_2); + auto sequence = std::make_shared( in_0, in_1, in_2, @@ -140,15 +140,15 @@ ngraph::pass::ConvertTensorIteratorToLSTMSequence::ConvertTensorIteratorToLSTMSe lstm_cell->get_activations(), lstm_cell->get_clip()); - auto axis_out = ngraph::opset4::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {1}); - auto out_0 = std::make_shared(sequence->output(0), axis_out); - auto out_1 = std::make_shared(sequence->output(1), axis_out); - auto out_2 = std::make_shared(sequence->output(2), axis_out); + auto axis_out = ngraph::opset5::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {1}); + auto out_0 = std::make_shared(sequence->output(0), axis_out); + auto out_1 = std::make_shared(sequence->output(1), axis_out); + auto out_2 = std::make_shared(sequence->output(2), axis_out); std::shared_ptr out = out_0; if (slice_axis == 0) { - auto order = ngraph::opset4::Constant::create(ngraph::element::i64, ngraph::Shape{3}, {1, 0, 2}); - out = std::make_shared(out_0, order); + auto order = ngraph::opset5::Constant::create(ngraph::element::i64, ngraph::Shape{3}, {1, 0, 2}); + out = std::make_shared(out_0, order); } ngraph::NodeVector outputs = {out, out_1, out_2}; @@ -176,26 +176,26 @@ ngraph::pass::ConvertTensorIteratorToLSTMSequence::ConvertTensorIteratorToLSTMSe ngraph::pass::ConvertTensorIteratorToRNNSequence::ConvertTensorIteratorToRNNSequence() { auto tensor_iterator = std::make_shared(ngraph::element::f32, - ngraph::Shape{}, ngraph::pattern::has_class()); + ngraph::Shape{}, ngraph::pattern::has_class()); ngraph::matcher_pass_callback callback = [this](pattern::Matcher &m) { - auto ti = std::dynamic_pointer_cast(m.get_match_root()); + auto ti = std::dynamic_pointer_cast(m.get_match_root()); if (!ti || !m_transformation_callback(ti)) return false; // create pattern - auto data = std::make_shared(ngraph::element::f32, ngraph::Shape{1, 1, 1}); - auto axis_squeeze = std::make_shared(ngraph::element::i64, ngraph::Shape{1}, 0); - auto input_data = std::make_shared(data, axis_squeeze); + auto data = std::make_shared(ngraph::element::f32, ngraph::Shape{1, 1, 1}); + auto axis_squeeze = std::make_shared(ngraph::element::i64, ngraph::Shape{1}, 0); + auto input_data = std::make_shared(data, axis_squeeze); - auto input_H_state = std::make_shared(ngraph::element::f32, ngraph::Shape{1, 1}); - auto input_W = std::make_shared(ngraph::element::f32, ngraph::Shape{1, 1}); - auto input_R = std::make_shared(ngraph::element::f32, ngraph::Shape{1, 1}); - auto input_B = std::make_shared(ngraph::element::f32, ngraph::Shape{1}); + auto input_H_state = std::make_shared(ngraph::element::f32, ngraph::Shape{1, 1}); + auto input_W = std::make_shared(ngraph::element::f32, ngraph::Shape{1, 1}); + auto input_R = std::make_shared(ngraph::element::f32, ngraph::Shape{1, 1}); + auto input_B = std::make_shared(ngraph::element::f32, ngraph::Shape{1}); - auto cell = std::make_shared(input_data, input_H_state, input_W, input_R, input_B, 1); + auto cell = std::make_shared(input_data, input_H_state, input_W, input_R, input_B, 1); - auto axis_unsqueeze = std::make_shared(ngraph::element::i64, ngraph::Shape{1}, 0); - auto unsqueeze = std::make_shared(cell, axis_unsqueeze); + auto axis_unsqueeze = std::make_shared(ngraph::element::i64, ngraph::Shape{1}, 0); + auto unsqueeze = std::make_shared(cell, axis_unsqueeze); ngraph::pattern::Matcher matcher(unsqueeze); bool match = false; @@ -213,7 +213,7 @@ ngraph::pass::ConvertTensorIteratorToRNNSequence::ConvertTensorIteratorToRNNSequ auto pattern_map = matcher.get_pattern_map(); auto params = func->get_parameters(); - std::vector> ordered_in_descs(3); + std::vector> ordered_in_descs(3); int64_t stride = 0, slice_axis = 0; size_t batch_size = 0; for (const auto& input_desc : ti->get_input_descriptions()) { @@ -224,7 +224,7 @@ ngraph::pass::ConvertTensorIteratorToRNNSequence::ConvertTensorIteratorToRNNSequ return false; } auto slice_input - = std::dynamic_pointer_cast(input_desc); + = std::dynamic_pointer_cast(input_desc); if (!slice_input) return false; @@ -242,15 +242,15 @@ ngraph::pass::ConvertTensorIteratorToRNNSequence::ConvertTensorIteratorToRNNSequ } } - auto seq_lengths = ngraph::opset4::Constant::create(element::i32, Shape{batch_size}, {ti->get_num_iterations()}); + auto seq_lengths = ngraph::opset5::Constant::create(element::i32, Shape{batch_size}, {ti->get_num_iterations()}); auto results = func->get_results(); - std::vector> ordered_out_descs(2); + std::vector> ordered_out_descs(2); for (const auto& output_desc : ti->get_output_descriptions()) { - std::shared_ptr res = results[output_desc->m_body_value_index]; + std::shared_ptr res = results[output_desc->m_body_value_index]; if (res->get_input_source_output(0) == pattern_map[unsqueeze]) { auto concat_output - = std::dynamic_pointer_cast(output_desc); + = std::dynamic_pointer_cast(output_desc); if (!concat_output) return false; @@ -263,22 +263,22 @@ ngraph::pass::ConvertTensorIteratorToRNNSequence::ConvertTensorIteratorToRNNSequ } } - const auto& rnn_cell = std::dynamic_pointer_cast(pattern_map[cell]); + const auto& rnn_cell = std::dynamic_pointer_cast(pattern_map[cell]); auto in_0 = ti->input_values()[ordered_in_descs[0]->m_input_index]; if (slice_axis == 0) { - auto order = ngraph::opset4::Constant::create(ngraph::element::i64, ngraph::Shape{3}, {1, 0, 2}); - in_0 = std::make_shared(ti->input_values()[ordered_in_descs[0]->m_input_index], order); + auto order = ngraph::opset5::Constant::create(ngraph::element::i64, ngraph::Shape{3}, {1, 0, 2}); + in_0 = std::make_shared(ti->input_values()[ordered_in_descs[0]->m_input_index], order); } - auto axis_1 = ngraph::opset4::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {1}); - auto in_1 = std::make_shared(ti->input_values()[ordered_in_descs[1]->m_input_index], axis_1); + auto axis_1 = ngraph::opset5::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {1}); + auto in_1 = std::make_shared(ti->input_values()[ordered_in_descs[1]->m_input_index], axis_1); - auto axis_2 = ngraph::opset4::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {0}); - auto in_3 = std::make_shared(pattern_map[input_W]->output(0).get_node_shared_ptr(), axis_2); - auto in_4 = std::make_shared(pattern_map[input_R]->output(0).get_node_shared_ptr(), axis_2); - auto in_5 = std::make_shared(pattern_map[input_B]->output(0).get_node_shared_ptr(), axis_2); - auto sequence = std::make_shared( + auto axis_2 = ngraph::opset5::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {0}); + auto in_3 = std::make_shared(pattern_map[input_W]->output(0).get_node_shared_ptr(), axis_2); + auto in_4 = std::make_shared(pattern_map[input_R]->output(0).get_node_shared_ptr(), axis_2); + auto in_5 = std::make_shared(pattern_map[input_B]->output(0).get_node_shared_ptr(), axis_2); + auto sequence = std::make_shared( in_0, in_1, seq_lengths, @@ -292,14 +292,14 @@ ngraph::pass::ConvertTensorIteratorToRNNSequence::ConvertTensorIteratorToRNNSequ rnn_cell->get_activations_beta(), rnn_cell->get_clip()); - auto axis_out = ngraph::opset4::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {1}); - auto out_0 = std::make_shared(sequence->output(0), axis_out); - auto out_1 = std::make_shared(sequence->output(1), axis_out); + auto axis_out = ngraph::opset5::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {1}); + auto out_0 = std::make_shared(sequence->output(0), axis_out); + auto out_1 = std::make_shared(sequence->output(1), axis_out); std::shared_ptr out = out_0; if (slice_axis == 0) { - auto order = ngraph::opset4::Constant::create(ngraph::element::i64, ngraph::Shape{3}, {1, 0, 2}); - out = std::make_shared(out_0, order); + auto order = ngraph::opset5::Constant::create(ngraph::element::i64, ngraph::Shape{3}, {1, 0, 2}); + out = std::make_shared(out_0, order); } ngraph::NodeVector outputs = {out, out_1}; @@ -327,26 +327,26 @@ ngraph::pass::ConvertTensorIteratorToRNNSequence::ConvertTensorIteratorToRNNSequ ngraph::pass::ConvertTensorIteratorToGRUSequence::ConvertTensorIteratorToGRUSequence() { auto tensor_iterator = std::make_shared(ngraph::element::f32, - ngraph::Shape{}, ngraph::pattern::has_class()); + ngraph::Shape{}, ngraph::pattern::has_class()); ngraph::matcher_pass_callback callback = [this](pattern::Matcher &m) { - auto ti = std::dynamic_pointer_cast(m.get_match_root()); + auto ti = std::dynamic_pointer_cast(m.get_match_root()); if (!ti || !m_transformation_callback(ti)) return false; // create pattern - auto data = std::make_shared(ngraph::element::f32, ngraph::Shape{1, 1, 1}); - auto axis_squeeze = std::make_shared(ngraph::element::i64, ngraph::Shape{1}, 0); - auto input_data = std::make_shared(data, axis_squeeze); + auto data = std::make_shared(ngraph::element::f32, ngraph::Shape{1, 1, 1}); + auto axis_squeeze = std::make_shared(ngraph::element::i64, ngraph::Shape{1}, 0); + auto input_data = std::make_shared(data, axis_squeeze); - auto input_H_state = std::make_shared(ngraph::element::f32, ngraph::Shape{1, 1}); - auto input_W = std::make_shared(ngraph::element::f32, ngraph::Shape{3, 1}); - auto input_R = std::make_shared(ngraph::element::f32, ngraph::Shape{3, 1}); - auto input_B = std::make_shared(ngraph::element::f32, ngraph::Shape{3}); + auto input_H_state = std::make_shared(ngraph::element::f32, ngraph::Shape{1, 1}); + auto input_W = std::make_shared(ngraph::element::f32, ngraph::Shape{3, 1}); + auto input_R = std::make_shared(ngraph::element::f32, ngraph::Shape{3, 1}); + auto input_B = std::make_shared(ngraph::element::f32, ngraph::Shape{3}); - auto cell = std::make_shared(input_data, input_H_state, input_W, input_R, input_B, 1); + auto cell = std::make_shared(input_data, input_H_state, input_W, input_R, input_B, 1); - auto axis_unsqueeze = std::make_shared(ngraph::element::i64, ngraph::Shape{1}, 0); - auto unsqueeze = std::make_shared(cell, axis_unsqueeze); + auto axis_unsqueeze = std::make_shared(ngraph::element::i64, ngraph::Shape{1}, 0); + auto unsqueeze = std::make_shared(cell, axis_unsqueeze); ngraph::pattern::Matcher matcher(unsqueeze); bool match = false; @@ -364,7 +364,7 @@ ngraph::pass::ConvertTensorIteratorToGRUSequence::ConvertTensorIteratorToGRUSequ auto pattern_map = matcher.get_pattern_map(); auto params = func->get_parameters(); - std::vector> ordered_in_descs(3); + std::vector> ordered_in_descs(3); int64_t stride = 0, slice_axis = 0; size_t batch_size = 0; for (const auto& input_desc : ti->get_input_descriptions()) { @@ -375,7 +375,7 @@ ngraph::pass::ConvertTensorIteratorToGRUSequence::ConvertTensorIteratorToGRUSequ return false; } auto slice_input - = std::dynamic_pointer_cast(input_desc); + = std::dynamic_pointer_cast(input_desc); if (!slice_input) return false; @@ -393,15 +393,15 @@ ngraph::pass::ConvertTensorIteratorToGRUSequence::ConvertTensorIteratorToGRUSequ } } - auto seq_lengths = ngraph::opset4::Constant::create(element::i32, Shape{batch_size}, {ti->get_num_iterations()}); + auto seq_lengths = ngraph::opset5::Constant::create(element::i32, Shape{batch_size}, {ti->get_num_iterations()}); auto results = func->get_results(); - std::vector> ordered_out_descs(2); + std::vector> ordered_out_descs(2); for (const auto& output_desc : ti->get_output_descriptions()) { - std::shared_ptr res = results[output_desc->m_body_value_index]; + std::shared_ptr res = results[output_desc->m_body_value_index]; if (res->get_input_source_output(0) == pattern_map[unsqueeze]) { auto concat_output - = std::dynamic_pointer_cast(output_desc); + = std::dynamic_pointer_cast(output_desc); if (!concat_output) return false; @@ -414,22 +414,22 @@ ngraph::pass::ConvertTensorIteratorToGRUSequence::ConvertTensorIteratorToGRUSequ } } - const auto& rnn_cell = std::dynamic_pointer_cast(pattern_map[cell]); + const auto& rnn_cell = std::dynamic_pointer_cast(pattern_map[cell]); auto in_0 = ti->input_values()[ordered_in_descs[0]->m_input_index]; if (slice_axis == 0) { - auto order = ngraph::opset4::Constant::create(ngraph::element::i64, ngraph::Shape{3}, {1, 0, 2}); - in_0 = std::make_shared(ti->input_values()[ordered_in_descs[0]->m_input_index], order); + auto order = ngraph::opset5::Constant::create(ngraph::element::i64, ngraph::Shape{3}, {1, 0, 2}); + in_0 = std::make_shared(ti->input_values()[ordered_in_descs[0]->m_input_index], order); } - auto axis_1 = ngraph::opset4::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {1}); - auto in_1 = std::make_shared(ti->input_values()[ordered_in_descs[1]->m_input_index], axis_1); + auto axis_1 = ngraph::opset5::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {1}); + auto in_1 = std::make_shared(ti->input_values()[ordered_in_descs[1]->m_input_index], axis_1); - auto axis_2 = ngraph::opset4::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {0}); - auto in_3 = std::make_shared(pattern_map[input_W]->output(0).get_node_shared_ptr(), axis_2); - auto in_4 = std::make_shared(pattern_map[input_R]->output(0).get_node_shared_ptr(), axis_2); - auto in_5 = std::make_shared(pattern_map[input_B]->output(0).get_node_shared_ptr(), axis_2); - auto sequence = std::make_shared( + auto axis_2 = ngraph::opset5::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {0}); + auto in_3 = std::make_shared(pattern_map[input_W]->output(0).get_node_shared_ptr(), axis_2); + auto in_4 = std::make_shared(pattern_map[input_R]->output(0).get_node_shared_ptr(), axis_2); + auto in_5 = std::make_shared(pattern_map[input_B]->output(0).get_node_shared_ptr(), axis_2); + auto sequence = std::make_shared( in_0, in_1, seq_lengths, @@ -444,14 +444,14 @@ ngraph::pass::ConvertTensorIteratorToGRUSequence::ConvertTensorIteratorToGRUSequ rnn_cell->get_clip(), rnn_cell->get_linear_before_reset()); - auto axis_out = ngraph::opset4::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {1}); - auto out_0 = std::make_shared(sequence->output(0), axis_out); - auto out_1 = std::make_shared(sequence->output(1), axis_out); + auto axis_out = ngraph::opset5::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {1}); + auto out_0 = std::make_shared(sequence->output(0), axis_out); + auto out_1 = std::make_shared(sequence->output(1), axis_out); std::shared_ptr out = out_0; if (slice_axis == 0) { - auto order = ngraph::opset4::Constant::create(ngraph::element::i64, ngraph::Shape{3}, {1, 0, 2}); - out = std::make_shared(out_0, order); + auto order = ngraph::opset5::Constant::create(ngraph::element::i64, ngraph::Shape{3}, {1, 0, 2}); + out = std::make_shared(out_0, order); } ngraph::NodeVector outputs = {out, out_1}; diff --git a/inference-engine/tests/functional/inference_engine/transformations/convert_sequences_to_sequences_ie_test.cpp b/inference-engine/tests/functional/inference_engine/transformations/convert_sequences_to_sequences_ie_test.cpp index a8555d5ecff87f..71d5ea5019626a 100644 --- a/inference-engine/tests/functional/inference_engine/transformations/convert_sequences_to_sequences_ie_test.cpp +++ b/inference-engine/tests/functional/inference_engine/transformations/convert_sequences_to_sequences_ie_test.cpp @@ -11,7 +11,7 @@ #include #include -#include +#include #include #include #include @@ -25,7 +25,7 @@ using namespace testing; TEST(TransformationTests, GRUSequenceConversionTest) { std::shared_ptr f(nullptr), f_ref(nullptr); - std::shared_ptr sequence; + std::shared_ptr sequence; const size_t batch_size = 2; const size_t input_size = 3; @@ -33,21 +33,21 @@ TEST(TransformationTests, GRUSequenceConversionTest) { const size_t gates_count = 3; const size_t num_directions = 1; { - const auto X = std::make_shared(ngraph::element::f32, + const auto X = std::make_shared(ngraph::element::f32, ngraph::Shape{batch_size, 1, input_size}); const auto W = - std::make_shared(ngraph::element::f32, + std::make_shared(ngraph::element::f32, ngraph::Shape{num_directions, gates_count * hidden_size, input_size}); const auto R = - std::make_shared(ngraph::element::f32, + std::make_shared(ngraph::element::f32, ngraph::Shape{num_directions, gates_count * hidden_size, hidden_size}); - const auto H_t = std::make_shared(ngraph::element::f32, + const auto H_t = std::make_shared(ngraph::element::f32, ngraph::Shape{batch_size, num_directions, hidden_size}); - const auto B = std::make_shared(ngraph::element::f32, + const auto B = std::make_shared(ngraph::element::f32, ngraph::Shape{num_directions, gates_count * hidden_size}); - const auto seq_len = std::make_shared(ngraph::element::i32, ngraph::Shape{batch_size}); - sequence = std::make_shared(X, H_t, seq_len, W, R, B, hidden_size, + const auto seq_len = std::make_shared(ngraph::element::i32, ngraph::Shape{batch_size}); + sequence = std::make_shared(X, H_t, seq_len, W, R, B, hidden_size, ngraph::op::RecurrentSequenceDirection::FORWARD); sequence->set_friendly_name("test_sequence"); @@ -60,26 +60,26 @@ TEST(TransformationTests, GRUSequenceConversionTest) { } { - const auto X = std::make_shared(ngraph::element::f32, + const auto X = std::make_shared(ngraph::element::f32, ngraph::Shape{batch_size, 1, input_size}); const auto W = - std::make_shared(ngraph::element::f32, + std::make_shared(ngraph::element::f32, ngraph::Shape{num_directions, gates_count * hidden_size, input_size}); const auto R = - std::make_shared(ngraph::element::f32, + std::make_shared(ngraph::element::f32, ngraph::Shape{num_directions, gates_count * hidden_size, hidden_size}); - const auto H_t = std::make_shared(ngraph::element::f32, + const auto H_t = std::make_shared(ngraph::element::f32, ngraph::Shape{batch_size, num_directions, hidden_size}); - const auto B = std::make_shared(ngraph::element::f32, + const auto B = std::make_shared(ngraph::element::f32, ngraph::Shape{num_directions, gates_count * hidden_size}); - const auto seq_len = std::make_shared(ngraph::element::i32, ngraph::Shape{batch_size}, 1); - auto axis_1 = ngraph::opset4::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {1}); - auto in_1 = std::make_shared(H_t, axis_1); - auto concat = std::make_shared(ngraph::NodeVector({W, R}), 2); - auto axis_2 = ngraph::opset4::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {0}); - auto in_3 = std::make_shared(concat->output(0), axis_2); - auto in_4 = std::make_shared(B, axis_2); + const auto seq_len = std::make_shared(ngraph::element::i32, ngraph::Shape{batch_size}, 1); + auto axis_1 = ngraph::opset5::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {1}); + auto in_1 = std::make_shared(H_t, axis_1); + auto concat = std::make_shared(ngraph::NodeVector({W, R}), 2); + auto axis_2 = ngraph::opset5::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {0}); + auto in_3 = std::make_shared(concat->output(0), axis_2); + auto in_4 = std::make_shared(B, axis_2); auto sequence_ie = std::make_shared(X, in_1, seq_len, // this input is not supported @@ -94,9 +94,9 @@ TEST(TransformationTests, GRUSequenceConversionTest) { sequence->get_linear_before_reset()); sequence_ie->set_friendly_name("test_sequence"); - auto unsqueeze_axis = ngraph::opset4::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {1}); - auto unsqueeze_1 = std::make_shared(sequence_ie->output(0), unsqueeze_axis); - auto unsqueeze_2 = std::make_shared(sequence_ie->output(1), unsqueeze_axis); + auto unsqueeze_axis = ngraph::opset5::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {1}); + auto unsqueeze_1 = std::make_shared(sequence_ie->output(0), unsqueeze_axis); + auto unsqueeze_2 = std::make_shared(sequence_ie->output(1), unsqueeze_axis); f_ref = std::make_shared(ngraph::NodeVector{unsqueeze_1}, ngraph::ParameterVector{X, H_t}); } auto res = compare_functions(f, f_ref); @@ -112,16 +112,16 @@ TEST(TransformationTests, RNNSequenceConversionTest) { const size_t num_directions = 1; const size_t batch_size = 2; std::shared_ptr f(nullptr), f_ref(nullptr); - std::shared_ptr sequence; + std::shared_ptr sequence; { - auto X = std::make_shared(ngraph::element::f32, ngraph::Shape{batch_size, 1, 3}); - auto H = std::make_shared(ngraph::element::f32, ngraph::Shape{batch_size, num_directions, 3}); - auto W = std::make_shared(ngraph::element::f32, ngraph::Shape{num_directions, 3, 3}); - auto R = std::make_shared(ngraph::element::f32, ngraph::Shape{num_directions, 3, 3}); - auto B = std::make_shared(ngraph::element::f32, ngraph::Shape{num_directions, 3}); - auto seq_len = std::make_shared(ngraph::element::f32, ngraph::Shape{2}); - sequence = std::make_shared(X, H, seq_len, W, R, B, hidden_size, + auto X = std::make_shared(ngraph::element::f32, ngraph::Shape{batch_size, 1, 3}); + auto H = std::make_shared(ngraph::element::f32, ngraph::Shape{batch_size, num_directions, 3}); + auto W = std::make_shared(ngraph::element::f32, ngraph::Shape{num_directions, 3, 3}); + auto R = std::make_shared(ngraph::element::f32, ngraph::Shape{num_directions, 3, 3}); + auto B = std::make_shared(ngraph::element::f32, ngraph::Shape{num_directions, 3}); + auto seq_len = std::make_shared(ngraph::element::f32, ngraph::Shape{2}); + sequence = std::make_shared(X, H, seq_len, W, R, B, hidden_size, ngraph::op::RecurrentSequenceDirection::FORWARD); sequence->set_friendly_name("test_sequence"); @@ -134,18 +134,18 @@ TEST(TransformationTests, RNNSequenceConversionTest) { } { - auto X = std::make_shared(ngraph::element::f32, ngraph::Shape{batch_size, 1, 3}); - auto H = std::make_shared(ngraph::element::f32, ngraph::Shape{batch_size, num_directions, 3}); - auto W = std::make_shared(ngraph::element::f32, ngraph::Shape{num_directions, 3, 3}); - auto R = std::make_shared(ngraph::element::f32, ngraph::Shape{num_directions, 3, 3}); - auto B = std::make_shared(ngraph::element::f32, ngraph::Shape{num_directions, 3}); - auto seq_len = std::make_shared(ngraph::element::f32, ngraph::Shape{batch_size}, 1); - auto axis_1 = ngraph::opset4::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {1}); - auto in_1 = std::make_shared(H, axis_1); - auto concat = std::make_shared(ngraph::NodeVector({W, R}), 2); - auto axis_2 = ngraph::opset4::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {0}); - auto in_3 = std::make_shared(concat->output(0), axis_2); - auto in_4 = std::make_shared(B, axis_2); + auto X = std::make_shared(ngraph::element::f32, ngraph::Shape{batch_size, 1, 3}); + auto H = std::make_shared(ngraph::element::f32, ngraph::Shape{batch_size, num_directions, 3}); + auto W = std::make_shared(ngraph::element::f32, ngraph::Shape{num_directions, 3, 3}); + auto R = std::make_shared(ngraph::element::f32, ngraph::Shape{num_directions, 3, 3}); + auto B = std::make_shared(ngraph::element::f32, ngraph::Shape{num_directions, 3}); + auto seq_len = std::make_shared(ngraph::element::f32, ngraph::Shape{batch_size}, 1); + auto axis_1 = ngraph::opset5::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {1}); + auto in_1 = std::make_shared(H, axis_1); + auto concat = std::make_shared(ngraph::NodeVector({W, R}), 2); + auto axis_2 = ngraph::opset5::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {0}); + auto in_3 = std::make_shared(concat->output(0), axis_2); + auto in_4 = std::make_shared(B, axis_2); auto sequence_ie = std::make_shared(X, in_1, seq_len, @@ -158,9 +158,9 @@ TEST(TransformationTests, RNNSequenceConversionTest) { sequence->get_activations_beta(), sequence->get_clip()); - auto unsqueeze_axis = ngraph::opset4::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {1}); - auto unsqueeze_1 = std::make_shared(sequence_ie->output(0), unsqueeze_axis); - auto unsqueeze_2 = std::make_shared(sequence_ie->output(1), unsqueeze_axis); + auto unsqueeze_axis = ngraph::opset5::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {1}); + auto unsqueeze_1 = std::make_shared(sequence_ie->output(0), unsqueeze_axis); + auto unsqueeze_2 = std::make_shared(sequence_ie->output(1), unsqueeze_axis); sequence_ie->set_friendly_name("test_sequence"); f_ref = std::make_shared(ngraph::NodeVector{unsqueeze_1}, ngraph::ParameterVector{X, H}); } @@ -180,28 +180,28 @@ TEST(TransformationTests, LSTMSequenceConversionTest) { const size_t gates_count = 4; const size_t num_directions = 1; std::shared_ptr f(nullptr), f_ref(nullptr); - std::shared_ptr sequence; + std::shared_ptr sequence; { - const auto X = std::make_shared(ngraph::element::f32, + const auto X = std::make_shared(ngraph::element::f32, ngraph::Shape{batch_size, 10, input_size}); const auto W = - std::make_shared(ngraph::element::f32, + std::make_shared(ngraph::element::f32, ngraph::Shape{num_directions, gates_count * hidden_size, input_size}); const auto R = - std::make_shared(ngraph::element::f32, + std::make_shared(ngraph::element::f32, ngraph::Shape{num_directions, gates_count * hidden_size, hidden_size}); - const auto H_t = std::make_shared(ngraph::element::f32, + const auto H_t = std::make_shared(ngraph::element::f32, ngraph::Shape{batch_size, num_directions, hidden_size}); - const auto C_t = std::make_shared(ngraph::element::f32, + const auto C_t = std::make_shared(ngraph::element::f32, ngraph::Shape{batch_size, num_directions, hidden_size}); - const auto B = std::make_shared(ngraph::element::f32, + const auto B = std::make_shared(ngraph::element::f32, ngraph::Shape{num_directions, gates_count * hidden_size}); - const auto seq_len = std::make_shared(ngraph::element::i32, ngraph::Shape{batch_size}); - sequence = std::make_shared(X, H_t, C_t, seq_len, W, R, B, hidden_size, + const auto seq_len = std::make_shared(ngraph::element::i32, ngraph::Shape{batch_size}); + sequence = std::make_shared(X, H_t, C_t, seq_len, W, R, B, hidden_size, ngraph::op::RecurrentSequenceDirection::FORWARD); sequence->set_friendly_name("test_sequence"); @@ -214,33 +214,33 @@ TEST(TransformationTests, LSTMSequenceConversionTest) { } { - const auto X = std::make_shared(ngraph::element::f32, + const auto X = std::make_shared(ngraph::element::f32, ngraph::Shape{batch_size, 10, input_size}); const auto W = - std::make_shared(ngraph::element::f32, + std::make_shared(ngraph::element::f32, ngraph::Shape{num_directions, gates_count * hidden_size, input_size}); const auto R = - std::make_shared(ngraph::element::f32, + std::make_shared(ngraph::element::f32, ngraph::Shape{num_directions, gates_count * hidden_size, hidden_size}); - const auto H_t = std::make_shared(ngraph::element::f32, + const auto H_t = std::make_shared(ngraph::element::f32, ngraph::Shape{batch_size, num_directions, hidden_size}); - const auto C_t = std::make_shared(ngraph::element::f32, + const auto C_t = std::make_shared(ngraph::element::f32, ngraph::Shape{batch_size, num_directions, hidden_size}); - const auto seq_lenghts = std::make_shared(ngraph::element::f32, + const auto seq_lenghts = std::make_shared(ngraph::element::f32, ngraph::Shape{batch_size}); - const auto B = std::make_shared(ngraph::element::f32, + const auto B = std::make_shared(ngraph::element::f32, ngraph::Shape{num_directions, gates_count * hidden_size}); - // const auto seq_len = std::make_shared(ngraph::element::i32, ngraph::Shape{1}, 1); - auto axis_1 = ngraph::opset4::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {1}); - auto in_1 = std::make_shared(H_t, axis_1); - auto in_2 = std::make_shared(C_t, axis_1); - auto concat = std::make_shared(ngraph::NodeVector({W, R}), 2); - auto axis_2 = ngraph::opset4::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {0}); - auto in_3 = std::make_shared(concat->output(0), axis_2); - auto in_4 = std::make_shared(B, axis_2); + // const auto seq_len = std::make_shared(ngraph::element::i32, ngraph::Shape{1}, 1); + auto axis_1 = ngraph::opset5::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {1}); + auto in_1 = std::make_shared(H_t, axis_1); + auto in_2 = std::make_shared(C_t, axis_1); + auto concat = std::make_shared(ngraph::NodeVector({W, R}), 2); + auto axis_2 = ngraph::opset5::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {0}); + auto in_3 = std::make_shared(concat->output(0), axis_2); + auto in_4 = std::make_shared(B, axis_2); auto sequence_ie = std::make_shared(X, in_1, in_2, @@ -254,10 +254,10 @@ TEST(TransformationTests, LSTMSequenceConversionTest) { sequence->get_activations_beta(), sequence->get_clip()); sequence_ie->set_friendly_name("test_sequence"); - auto unsqueeze_axis = ngraph::opset4::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {1}); - auto unsqueeze_1 = std::make_shared(sequence_ie->output(0), unsqueeze_axis); - auto unsqueeze_2 = std::make_shared(sequence_ie->output(1), unsqueeze_axis); - auto unsqueeze_3 = std::make_shared(sequence_ie->output(2), unsqueeze_axis); + auto unsqueeze_axis = ngraph::opset5::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {1}); + auto unsqueeze_1 = std::make_shared(sequence_ie->output(0), unsqueeze_axis); + auto unsqueeze_2 = std::make_shared(sequence_ie->output(1), unsqueeze_axis); + auto unsqueeze_3 = std::make_shared(sequence_ie->output(2), unsqueeze_axis); f_ref = std::make_shared(ngraph::NodeVector{unsqueeze_1}, ngraph::ParameterVector{X, H_t, C_t}); } diff --git a/inference-engine/tests/functional/inference_engine/transformations/convert_ti_to_sequences_test.cpp b/inference-engine/tests/functional/inference_engine/transformations/convert_ti_to_sequences_test.cpp index f21776fb3f1703..65e24b36aba5e5 100644 --- a/inference-engine/tests/functional/inference_engine/transformations/convert_ti_to_sequences_test.cpp +++ b/inference-engine/tests/functional/inference_engine/transformations/convert_ti_to_sequences_test.cpp @@ -11,7 +11,7 @@ #include #include -#include +#include #include #include #include @@ -25,34 +25,34 @@ using namespace ngraph; TEST(TransformationTests, ConvertTensorIteratorToLSTMSequence) { std::shared_ptr f(nullptr), f_ref(nullptr); { - auto X = std::make_shared(element::f32, Shape{1, 2, 16}); - auto Y = std::make_shared(element::f32, Shape{1, 128}); - auto Z = std::make_shared(element::f32, Shape{1, 128}); + auto X = std::make_shared(element::f32, Shape{1, 2, 16}); + auto Y = std::make_shared(element::f32, Shape{1, 128}); + auto Z = std::make_shared(element::f32, Shape{1, 128}); - auto Xi = std::make_shared(element::f32, Shape{1, 1, 16}); - auto Yi = std::make_shared(element::f32, Shape{1, 128}); - auto Zi = std::make_shared(element::f32, Shape{1, 128}); + auto Xi = std::make_shared(element::f32, Shape{1, 1, 16}); + auto Yi = std::make_shared(element::f32, Shape{1, 128}); + auto Zi = std::make_shared(element::f32, Shape{1, 128}); // Body - auto axis = ngraph::opset4::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {1}); - auto squeeze = std::make_shared(Xi, axis); + auto axis = ngraph::opset5::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {1}); + auto squeeze = std::make_shared(Xi, axis); auto w_val = std::vector(512 * 16, 0); auto r_val = std::vector(512 * 128, 0); auto b_val = std::vector(512, 0); - auto W = ngraph::opset4::Constant::create(ngraph::element::f32, ngraph::Shape{512, 16}, w_val); - auto R = ngraph::opset4::Constant::create(ngraph::element::f32, ngraph::Shape{512, 128}, r_val); - auto B = ngraph::opset4::Constant::create(ngraph::element::f32, ngraph::Shape{512}, b_val); - - auto lstm_cell = std::make_shared(squeeze, Yi, Zi, W, R, B, 128); - auto res_1 = std::make_shared(lstm_cell); - auto axis_unsqueeze = ngraph::opset4::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {1}); - auto unsqueeze = std::make_shared(lstm_cell, axis_unsqueeze); - auto res_2 = std::make_shared(unsqueeze); + auto W = ngraph::opset5::Constant::create(ngraph::element::f32, ngraph::Shape{512, 16}, w_val); + auto R = ngraph::opset5::Constant::create(ngraph::element::f32, ngraph::Shape{512, 128}, r_val); + auto B = ngraph::opset5::Constant::create(ngraph::element::f32, ngraph::Shape{512}, b_val); + + auto lstm_cell = std::make_shared(squeeze, Yi, Zi, W, R, B, 128); + auto res_1 = std::make_shared(lstm_cell); + auto axis_unsqueeze = ngraph::opset5::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {1}); + auto unsqueeze = std::make_shared(lstm_cell, axis_unsqueeze); + auto res_2 = std::make_shared(unsqueeze); auto body = std::make_shared(OutputVector{res_1, res_2}, ParameterVector{Xi, Yi, Zi}); - auto tensor_iterator = std::make_shared(); + auto tensor_iterator = std::make_shared(); tensor_iterator->set_body(body); tensor_iterator->set_invariant_input(Zi, Z); @@ -62,8 +62,8 @@ TEST(TransformationTests, ConvertTensorIteratorToLSTMSequence) { auto out0 = tensor_iterator->get_iter_value(res_1, -1); auto out1 = tensor_iterator->get_concatenated_slices(res_2, 0, 1, 1, -1, 1); - auto res_ti_1 = std::make_shared(tensor_iterator->output(1)); - //auto res_ti_2 = std::make_shared(tensor_iterator->output(0)); + auto res_ti_1 = std::make_shared(tensor_iterator->output(1)); + //auto res_ti_2 = std::make_shared(tensor_iterator->output(0)); f = std::make_shared(ngraph::NodeVector{res_ti_1}, ngraph::ParameterVector{X, Y, Z}); @@ -76,34 +76,34 @@ TEST(TransformationTests, ConvertTensorIteratorToLSTMSequence) { } { - auto X = std::make_shared(element::f32, Shape{1, 2, 16}); - auto Y = std::make_shared(element::f32, Shape{1, 128}); - auto Z = std::make_shared(element::f32, Shape{1, 128}); + auto X = std::make_shared(element::f32, Shape{1, 2, 16}); + auto Y = std::make_shared(element::f32, Shape{1, 128}); + auto Z = std::make_shared(element::f32, Shape{1, 128}); auto w_val = std::vector(512 * 16, 0); auto r_val = std::vector(512 * 128, 0); auto b_val = std::vector(512, 0); - auto W = ngraph::opset4::Constant::create(ngraph::element::f32, ngraph::Shape{512, 16}, w_val); - auto R = ngraph::opset4::Constant::create(ngraph::element::f32, ngraph::Shape{512, 128}, r_val); - auto B = ngraph::opset4::Constant::create(ngraph::element::f32, ngraph::Shape{512}, b_val); + auto W = ngraph::opset5::Constant::create(ngraph::element::f32, ngraph::Shape{512, 16}, w_val); + auto R = ngraph::opset5::Constant::create(ngraph::element::f32, ngraph::Shape{512, 128}, r_val); + auto B = ngraph::opset5::Constant::create(ngraph::element::f32, ngraph::Shape{512}, b_val); - auto axis_1 = ngraph::opset4::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {1}); - auto in_1 = std::make_shared(Y, axis_1); - auto in_2 = std::make_shared(Z, axis_1); + auto axis_1 = ngraph::opset5::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {1}); + auto in_1 = std::make_shared(Y, axis_1); + auto in_2 = std::make_shared(Z, axis_1); - auto axis_2 = ngraph::opset4::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {0}); - auto in_4 = std::make_shared(W, axis_2); - auto in_5 = std::make_shared(R, axis_2); - auto in_6 = std::make_shared(B, axis_2); + auto axis_2 = ngraph::opset5::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {0}); + auto in_4 = std::make_shared(W, axis_2); + auto in_5 = std::make_shared(R, axis_2); + auto in_6 = std::make_shared(B, axis_2); - auto seq_lengths = ngraph::opset4::Constant::create(element::i32, Shape{1}, {2}); - auto lstm_seq = std::make_shared(X, in_1, in_2, seq_lengths, in_4, in_5, in_6, + auto seq_lengths = ngraph::opset5::Constant::create(element::i32, Shape{1}, {2}); + auto lstm_seq = std::make_shared(X, in_1, in_2, seq_lengths, in_4, in_5, in_6, 128, ngraph::op::RecurrentSequenceDirection::FORWARD); - auto axis_out = ngraph::opset4::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {1}); - auto out_0 = std::make_shared(lstm_seq->output(0), axis_out); - auto out_1 = std::make_shared(lstm_seq->output(1), axis_out); - auto out_2 = std::make_shared(lstm_seq->output(1), axis_out); - auto res_ti_1 = std::make_shared(out_0); + auto axis_out = ngraph::opset5::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {1}); + auto out_0 = std::make_shared(lstm_seq->output(0), axis_out); + auto out_1 = std::make_shared(lstm_seq->output(1), axis_out); + auto out_2 = std::make_shared(lstm_seq->output(1), axis_out); + auto res_ti_1 = std::make_shared(out_0); f_ref = std::make_shared(ngraph::NodeVector{res_ti_1}, ngraph::ParameterVector{X, Y, Z}); } @@ -114,32 +114,32 @@ TEST(TransformationTests, ConvertTensorIteratorToLSTMSequence) { TEST(TransformationTests, ConvertTensorIteratorToRNNSequence) { std::shared_ptr f(nullptr), f_ref(nullptr); { - auto X = std::make_shared(element::f32, Shape{1, 2, 16}); - auto Y = std::make_shared(element::f32, Shape{1, 128}); + auto X = std::make_shared(element::f32, Shape{1, 2, 16}); + auto Y = std::make_shared(element::f32, Shape{1, 128}); - auto Xi = std::make_shared(element::f32, Shape{1, 1, 16}); - auto Yi = std::make_shared(element::f32, Shape{1, 128}); + auto Xi = std::make_shared(element::f32, Shape{1, 1, 16}); + auto Yi = std::make_shared(element::f32, Shape{1, 128}); // Body - auto axis = ngraph::opset4::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {1}); - auto squeeze = std::make_shared(Xi, axis); + auto axis = ngraph::opset5::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {1}); + auto squeeze = std::make_shared(Xi, axis); auto w_val = std::vector(128 * 16, 0); auto r_val = std::vector(128 * 128, 0); auto b_val = std::vector(128, 0); - auto W = ngraph::opset4::Constant::create(ngraph::element::f32, ngraph::Shape{128, 16}, w_val); - auto R = ngraph::opset4::Constant::create(ngraph::element::f32, ngraph::Shape{128, 128}, r_val); - auto B = ngraph::opset4::Constant::create(ngraph::element::f32, ngraph::Shape{128}, b_val); - - auto rnn_cell = std::make_shared(squeeze, Yi, W, R, B, 128); - auto res_1 = std::make_shared(rnn_cell); - auto axis_unsqueeze = ngraph::opset4::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {1}); - auto unsqueeze = std::make_shared(rnn_cell, axis_unsqueeze); - auto res_2 = std::make_shared(unsqueeze); + auto W = ngraph::opset5::Constant::create(ngraph::element::f32, ngraph::Shape{128, 16}, w_val); + auto R = ngraph::opset5::Constant::create(ngraph::element::f32, ngraph::Shape{128, 128}, r_val); + auto B = ngraph::opset5::Constant::create(ngraph::element::f32, ngraph::Shape{128}, b_val); + + auto rnn_cell = std::make_shared(squeeze, Yi, W, R, B, 128); + auto res_1 = std::make_shared(rnn_cell); + auto axis_unsqueeze = ngraph::opset5::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {1}); + auto unsqueeze = std::make_shared(rnn_cell, axis_unsqueeze); + auto res_2 = std::make_shared(unsqueeze); auto body = std::make_shared(OutputVector{res_1, res_2}, ParameterVector{Xi, Yi}); - auto tensor_iterator = std::make_shared(); + auto tensor_iterator = std::make_shared(); tensor_iterator->set_body(body); tensor_iterator->set_sliced_input(Xi, X, 0, 1, 1, -1, 1); @@ -148,8 +148,8 @@ TEST(TransformationTests, ConvertTensorIteratorToRNNSequence) { auto out0 = tensor_iterator->get_iter_value(res_1, -1); auto out1 = tensor_iterator->get_concatenated_slices(res_2, 0, 1, 1, -1, 1); - auto res_ti_1 = std::make_shared(tensor_iterator->output(1)); - //auto res_ti_2 = std::make_shared(tensor_iterator->output(0)); + auto res_ti_1 = std::make_shared(tensor_iterator->output(1)); + //auto res_ti_2 = std::make_shared(tensor_iterator->output(0)); f = std::make_shared(ngraph::NodeVector{res_ti_1}, ngraph::ParameterVector{X, Y}); @@ -162,31 +162,31 @@ TEST(TransformationTests, ConvertTensorIteratorToRNNSequence) { } { - auto X = std::make_shared(element::f32, Shape{1, 2, 16}); - auto Y = std::make_shared(element::f32, Shape{1, 128}); + auto X = std::make_shared(element::f32, Shape{1, 2, 16}); + auto Y = std::make_shared(element::f32, Shape{1, 128}); auto w_val = std::vector(128 * 16, 0); auto r_val = std::vector(128 * 128, 0); auto b_val = std::vector(128, 0); - auto W = ngraph::opset4::Constant::create(ngraph::element::f32, ngraph::Shape{128, 16}, w_val); - auto R = ngraph::opset4::Constant::create(ngraph::element::f32, ngraph::Shape{128, 128}, r_val); - auto B = ngraph::opset4::Constant::create(ngraph::element::f32, ngraph::Shape{128}, b_val); + auto W = ngraph::opset5::Constant::create(ngraph::element::f32, ngraph::Shape{128, 16}, w_val); + auto R = ngraph::opset5::Constant::create(ngraph::element::f32, ngraph::Shape{128, 128}, r_val); + auto B = ngraph::opset5::Constant::create(ngraph::element::f32, ngraph::Shape{128}, b_val); - auto axis_1 = ngraph::opset4::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {1}); - auto in_1 = std::make_shared(Y, axis_1); + auto axis_1 = ngraph::opset5::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {1}); + auto in_1 = std::make_shared(Y, axis_1); - auto axis_2 = ngraph::opset4::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {0}); - auto in_3 = std::make_shared(W, axis_2); - auto in_4 = std::make_shared(R, axis_2); - auto in_5 = std::make_shared(B, axis_2); + auto axis_2 = ngraph::opset5::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {0}); + auto in_3 = std::make_shared(W, axis_2); + auto in_4 = std::make_shared(R, axis_2); + auto in_5 = std::make_shared(B, axis_2); - auto seq_lengths = ngraph::opset4::Constant::create(element::i32, Shape{1}, {2}); - auto rnn_sequence = std::make_shared(X, in_1, seq_lengths, in_3, in_4, in_5, + auto seq_lengths = ngraph::opset5::Constant::create(element::i32, Shape{1}, {2}); + auto rnn_sequence = std::make_shared(X, in_1, seq_lengths, in_3, in_4, in_5, 128, ngraph::op::RecurrentSequenceDirection::FORWARD); - auto axis_out = ngraph::opset4::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {1}); - auto out_0 = std::make_shared(rnn_sequence->output(0), axis_out); - auto out_1 = std::make_shared(rnn_sequence->output(1), axis_out); - auto res_ti_1 = std::make_shared(out_0); + auto axis_out = ngraph::opset5::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {1}); + auto out_0 = std::make_shared(rnn_sequence->output(0), axis_out); + auto out_1 = std::make_shared(rnn_sequence->output(1), axis_out); + auto res_ti_1 = std::make_shared(out_0); f_ref = std::make_shared(ngraph::NodeVector{res_ti_1}, ngraph::ParameterVector{X, Y}); } @@ -197,32 +197,32 @@ TEST(TransformationTests, ConvertTensorIteratorToRNNSequence) { TEST(TransformationTests, ConvertTensorIteratorToGRUSequence) { std::shared_ptr f(nullptr), f_ref(nullptr); { - auto X = std::make_shared(element::f32, Shape{1, 2, 16}); - auto Y = std::make_shared(element::f32, Shape{1, 128}); + auto X = std::make_shared(element::f32, Shape{1, 2, 16}); + auto Y = std::make_shared(element::f32, Shape{1, 128}); - auto Xi = std::make_shared(element::f32, Shape{1, 1, 16}); - auto Yi = std::make_shared(element::f32, Shape{1, 128}); + auto Xi = std::make_shared(element::f32, Shape{1, 1, 16}); + auto Yi = std::make_shared(element::f32, Shape{1, 128}); // Body - auto axis = ngraph::opset4::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {1}); - auto squeeze = std::make_shared(Xi, axis); + auto axis = ngraph::opset5::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {1}); + auto squeeze = std::make_shared(Xi, axis); auto w_val = std::vector(384 * 16, 0); auto r_val = std::vector(384 * 128, 0); auto b_val = std::vector(384, 0); - auto W = ngraph::opset4::Constant::create(ngraph::element::f32, ngraph::Shape{384, 16}, w_val); - auto R = ngraph::opset4::Constant::create(ngraph::element::f32, ngraph::Shape{384, 128}, r_val); - auto B = ngraph::opset4::Constant::create(ngraph::element::f32, ngraph::Shape{384}, b_val); - - auto gru_cell = std::make_shared(squeeze, Yi, W, R, B, 128); - auto res_1 = std::make_shared(gru_cell); - auto axis_unsqueeze = ngraph::opset4::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {1}); - auto unsqueeze = std::make_shared(gru_cell, axis_unsqueeze); - auto res_2 = std::make_shared(unsqueeze); + auto W = ngraph::opset5::Constant::create(ngraph::element::f32, ngraph::Shape{384, 16}, w_val); + auto R = ngraph::opset5::Constant::create(ngraph::element::f32, ngraph::Shape{384, 128}, r_val); + auto B = ngraph::opset5::Constant::create(ngraph::element::f32, ngraph::Shape{384}, b_val); + + auto gru_cell = std::make_shared(squeeze, Yi, W, R, B, 128); + auto res_1 = std::make_shared(gru_cell); + auto axis_unsqueeze = ngraph::opset5::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {1}); + auto unsqueeze = std::make_shared(gru_cell, axis_unsqueeze); + auto res_2 = std::make_shared(unsqueeze); auto body = std::make_shared(OutputVector{res_1, res_2}, ParameterVector{Xi, Yi}); - auto tensor_iterator = std::make_shared(); + auto tensor_iterator = std::make_shared(); tensor_iterator->set_body(body); tensor_iterator->set_sliced_input(Xi, X, 0, 1, 1, -1, 1); @@ -231,8 +231,8 @@ TEST(TransformationTests, ConvertTensorIteratorToGRUSequence) { auto out0 = tensor_iterator->get_iter_value(res_1, -1); auto out1 = tensor_iterator->get_concatenated_slices(res_2, 0, 1, 1, -1, 1); - auto res_ti_1 = std::make_shared(tensor_iterator->output(1)); - //auto res_tRNNCelli_2 = std::make_shared(tensor_iterator->output(0)); + auto res_ti_1 = std::make_shared(tensor_iterator->output(1)); + //auto res_tRNNCelli_2 = std::make_shared(tensor_iterator->output(0)); f = std::make_shared(ngraph::NodeVector{res_ti_1}, ngraph::ParameterVector{X, Y}); @@ -245,31 +245,31 @@ TEST(TransformationTests, ConvertTensorIteratorToGRUSequence) { } { - auto X = std::make_shared(element::f32, Shape{1, 2, 16}); - auto Y = std::make_shared(element::f32, Shape{1, 128}); + auto X = std::make_shared(element::f32, Shape{1, 2, 16}); + auto Y = std::make_shared(element::f32, Shape{1, 128}); auto w_val = std::vector(384 * 16, 0); auto r_val = std::vector(384 * 128, 0); auto b_val = std::vector(384, 0); - auto W = ngraph::opset4::Constant::create(ngraph::element::f32, ngraph::Shape{384, 16}, w_val); - auto R = ngraph::opset4::Constant::create(ngraph::element::f32, ngraph::Shape{384, 128}, r_val); - auto B = ngraph::opset4::Constant::create(ngraph::element::f32, ngraph::Shape{384}, b_val); + auto W = ngraph::opset5::Constant::create(ngraph::element::f32, ngraph::Shape{384, 16}, w_val); + auto R = ngraph::opset5::Constant::create(ngraph::element::f32, ngraph::Shape{384, 128}, r_val); + auto B = ngraph::opset5::Constant::create(ngraph::element::f32, ngraph::Shape{384}, b_val); - auto axis_1 = ngraph::opset4::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {1}); - auto in_1 = std::make_shared(Y, axis_1); + auto axis_1 = ngraph::opset5::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {1}); + auto in_1 = std::make_shared(Y, axis_1); - auto axis_2 = ngraph::opset4::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {0}); - auto in_3 = std::make_shared(W, axis_2); - auto in_4 = std::make_shared(R, axis_2); - auto in_5 = std::make_shared(B, axis_2); + auto axis_2 = ngraph::opset5::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {0}); + auto in_3 = std::make_shared(W, axis_2); + auto in_4 = std::make_shared(R, axis_2); + auto in_5 = std::make_shared(B, axis_2); - auto seq_lengths = ngraph::opset4::Constant::create(element::i32, Shape{1}, {2}); - auto gru_sequence = std::make_shared(X, in_1, seq_lengths, in_3, in_4, in_5, + auto seq_lengths = ngraph::opset5::Constant::create(element::i32, Shape{1}, {2}); + auto gru_sequence = std::make_shared(X, in_1, seq_lengths, in_3, in_4, in_5, 128, ngraph::op::RecurrentSequenceDirection::FORWARD); - auto axis_out = ngraph::opset4::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {1}); - auto out_0 = std::make_shared(gru_sequence->output(0), axis_out); - auto out_1 = std::make_shared(gru_sequence->output(1), axis_out); - auto res_ti_1 = std::make_shared(out_0); + auto axis_out = ngraph::opset5::Constant::create(ngraph::element::i64, ngraph::Shape{1}, {1}); + auto out_0 = std::make_shared(gru_sequence->output(0), axis_out); + auto out_1 = std::make_shared(gru_sequence->output(1), axis_out); + auto res_ti_1 = std::make_shared(out_0); f_ref = std::make_shared(ngraph::NodeVector{res_ti_1}, ngraph::ParameterVector{X, Y}); } diff --git a/inference-engine/tests/ngraph_functions/include/ngraph_functions/builders.hpp b/inference-engine/tests/ngraph_functions/include/ngraph_functions/builders.hpp index 22cf1da0077d11..302f3c133d36e5 100644 --- a/inference-engine/tests/ngraph_functions/include/ngraph_functions/builders.hpp +++ b/inference-engine/tests/ngraph_functions/include/ngraph_functions/builders.hpp @@ -11,6 +11,7 @@ #include #include #include +#include #include "ngraph_functions/utils/data_utils.hpp" diff --git a/inference-engine/tests/ngraph_functions/src/gru_cell.cpp b/inference-engine/tests/ngraph_functions/src/gru_cell.cpp index 784daf288796ce..364f0cdaaa8d29 100644 --- a/inference-engine/tests/ngraph_functions/src/gru_cell.cpp +++ b/inference-engine/tests/ngraph_functions/src/gru_cell.cpp @@ -31,7 +31,7 @@ std::shared_ptr makeGRU(const OutputVector& in, } else { std::vector lenghts(in[0].get_shape()[0], in[0].get_shape()[1]); auto seq_lenghts = ngraph::builder::makeConstant(in[0].get_element_type(), constants[3], lenghts, false); - return std::make_shared(in[0], in[1], seq_lenghts, W, R, B, hidden_size, direction, + return std::make_shared(in[0], in[1], seq_lenghts, W, R, B, hidden_size, direction, activations, activations_alpha, activations_beta, clip, linear_before_reset); } } diff --git a/inference-engine/tests/ngraph_functions/src/lstm_cell.cpp b/inference-engine/tests/ngraph_functions/src/lstm_cell.cpp index 944c8b6592a8fa..8ff4c5a5a7f989 100644 --- a/inference-engine/tests/ngraph_functions/src/lstm_cell.cpp +++ b/inference-engine/tests/ngraph_functions/src/lstm_cell.cpp @@ -29,7 +29,7 @@ std::shared_ptr makeLSTM(const std::vector>& } else { std::vector lenghts(in[0].get_shape()[0], in[0].get_shape()[1]); auto seq_lenghts = ngraph::builder::makeConstant(in[0].get_element_type(), constants[3], lenghts, false); - return std::make_shared(in[0], in[1], in[2], seq_lenghts, W, R, B, hidden_size, direction, + return std::make_shared(in[0], in[1], in[2], seq_lenghts, W, R, B, hidden_size, direction, activations_alpha, activations_beta, activations, clip); } } diff --git a/inference-engine/tests/ngraph_functions/src/rnn_cell.cpp b/inference-engine/tests/ngraph_functions/src/rnn_cell.cpp index 0d87ec19d1e216..5234ef458710af 100644 --- a/inference-engine/tests/ngraph_functions/src/rnn_cell.cpp +++ b/inference-engine/tests/ngraph_functions/src/rnn_cell.cpp @@ -29,7 +29,7 @@ std::shared_ptr makeRNN(const OutputVector& in, } else { std::vector lenghts(in[0].get_shape()[0], in[0].get_shape()[1]); auto seq_lenghts = ngraph::builder::makeConstant(in[0].get_element_type(), constants[3], lenghts, false); - return std::make_shared(in[0], in[1], seq_lenghts, W, R, B, hidden_size, direction, + return std::make_shared(in[0], in[1], seq_lenghts, W, R, B, hidden_size, direction, activations, activations_alpha, activations_beta, clip); } } diff --git a/ngraph/core/include/ngraph/opsets/opset.hpp b/ngraph/core/include/ngraph/opsets/opset.hpp index decb769f1fef3d..0b3b585f9cbfe8 100644 --- a/ngraph/core/include/ngraph/opsets/opset.hpp +++ b/ngraph/core/include/ngraph/opsets/opset.hpp @@ -132,4 +132,5 @@ namespace ngraph const NGRAPH_API OpSet& get_opset2(); const NGRAPH_API OpSet& get_opset3(); const NGRAPH_API OpSet& get_opset4(); + const NGRAPH_API OpSet& get_opset5(); } diff --git a/ngraph/core/include/ngraph/opsets/opset5.hpp b/ngraph/core/include/ngraph/opsets/opset5.hpp new file mode 100644 index 00000000000000..73d6394440b620 --- /dev/null +++ b/ngraph/core/include/ngraph/opsets/opset5.hpp @@ -0,0 +1,29 @@ +//***************************************************************************** +// Copyright 2017-2020 Intel Corporation +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +//***************************************************************************** + +#pragma once + +#include "ngraph/ops.hpp" + +namespace ngraph +{ + namespace opset5 + { +#define NGRAPH_OP(a, b) using b::a; +#include "ngraph/opsets/opset5_tbl.hpp" +#undef NGRAPH_OP + } +} diff --git a/ngraph/core/include/ngraph/opsets/opset5_tbl.hpp b/ngraph/core/include/ngraph/opsets/opset5_tbl.hpp new file mode 100644 index 00000000000000..145cb866826564 --- /dev/null +++ b/ngraph/core/include/ngraph/opsets/opset5_tbl.hpp @@ -0,0 +1,169 @@ +//***************************************************************************** +// Copyright 2017-2020 Intel Corporation +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +//***************************************************************************** + +#ifndef NGRAPH_OP +#warning "NGRAPH_OP not defined" +#define NGRAPH_OP(x, y) +#endif + +NGRAPH_OP(Abs, ngraph::op::v0) +NGRAPH_OP(Acos, ngraph::op::v0) +NGRAPH_OP(Add, ngraph::op::v1) +NGRAPH_OP(Asin, ngraph::op::v0) +NGRAPH_OP(Atan, ngraph::op::v0) +NGRAPH_OP(AvgPool, ngraph::op::v1) +NGRAPH_OP(BatchNormInference, ngraph::op::v0) +NGRAPH_OP(BinaryConvolution, ngraph::op::v1) +NGRAPH_OP(Broadcast, ngraph::op::v3) +NGRAPH_OP(Bucketize, ngraph::op::v3) +NGRAPH_OP(CTCGreedyDecoder, ngraph::op::v0) +NGRAPH_OP(Ceiling, ngraph::op::v0) +NGRAPH_OP(Clamp, ngraph::op::v0) +NGRAPH_OP(Concat, ngraph::op::v0) +NGRAPH_OP(Constant, ngraph::op) +NGRAPH_OP(Convert, ngraph::op::v0) +NGRAPH_OP(ConvertLike, ngraph::op::v1) +NGRAPH_OP(Convolution, ngraph::op::v1) +NGRAPH_OP(ConvolutionBackpropData, ngraph::op::v1) +NGRAPH_OP(Cos, ngraph::op::v0) +NGRAPH_OP(Cosh, ngraph::op::v0) +NGRAPH_OP(CumSum, ngraph::op::v0) +NGRAPH_OP(DeformableConvolution, ngraph::op::v1) +NGRAPH_OP(DeformablePSROIPooling, ngraph::op::v1) +NGRAPH_OP(DepthToSpace, ngraph::op::v0) +NGRAPH_OP(DetectionOutput, ngraph::op::v0) +NGRAPH_OP(Divide, ngraph::op::v1) +NGRAPH_OP(Elu, ngraph::op::v0) +NGRAPH_OP(Erf, ngraph::op::v0) +NGRAPH_OP(Equal, ngraph::op::v1) +NGRAPH_OP(Exp, ngraph::op::v0) +NGRAPH_OP(ExtractImagePatches, ngraph::op::v3) +NGRAPH_OP(FakeQuantize, ngraph::op::v0) +NGRAPH_OP(Floor, ngraph::op::v0) +NGRAPH_OP(FloorMod, ngraph::op::v1) +NGRAPH_OP(Gather, ngraph::op::v1) +NGRAPH_OP(GatherTree, ngraph::op::v1) +NGRAPH_OP(Greater, ngraph::op::v1) +NGRAPH_OP(GreaterEqual, ngraph::op::v1) +NGRAPH_OP(GroupConvolution, ngraph::op::v1) +NGRAPH_OP(GroupConvolutionBackpropData, ngraph::op::v1) +NGRAPH_OP(GRN, ngraph::op::v0) +NGRAPH_OP(HardSigmoid, ngraph::op::v0) +NGRAPH_OP(Less, ngraph::op::v1) +NGRAPH_OP(LessEqual, ngraph::op::v1) +NGRAPH_OP(Log, ngraph::op::v0) +NGRAPH_OP(LogicalAnd, ngraph::op::v1) +NGRAPH_OP(LogicalNot, ngraph::op::v1) +NGRAPH_OP(LogicalOr, ngraph::op::v1) +NGRAPH_OP(LogicalXor, ngraph::op::v1) +NGRAPH_OP(LRN, ngraph::op::v0) +NGRAPH_OP(LSTMCell, ngraph::op::v4) +NGRAPH_OP(MatMul, ngraph::op::v0) +NGRAPH_OP(MaxPool, ngraph::op::v1) +NGRAPH_OP(Maximum, ngraph::op::v1) +NGRAPH_OP(Minimum, ngraph::op::v1) +NGRAPH_OP(Mod, ngraph::op::v1) +NGRAPH_OP(Multiply, ngraph::op::v1) +NGRAPH_OP(MVN, ngraph::op::v0) +NGRAPH_OP(Negative, ngraph::op::v0) +NGRAPH_OP(NormalizeL2, ngraph::op::v0) +NGRAPH_OP(NotEqual, ngraph::op::v1) +NGRAPH_OP(OneHot, ngraph::op::v1) +NGRAPH_OP(PRelu, ngraph::op::v0) +NGRAPH_OP(PSROIPooling, ngraph::op::v0) +NGRAPH_OP(Pad, ngraph::op::v1) +NGRAPH_OP(Parameter, ngraph::op::v0) +NGRAPH_OP(Power, ngraph::op::v1) +NGRAPH_OP(PriorBox, ngraph::op::v0) +NGRAPH_OP(PriorBoxClustered, ngraph::op::v0) +NGRAPH_OP(Proposal, ngraph::op::v4) +NGRAPH_OP(Range, ngraph::op::v4) +NGRAPH_OP(Relu, ngraph::op::v0) +NGRAPH_OP(ReduceMax, ngraph::op::v1) +NGRAPH_OP(ReduceLogicalAnd, ngraph::op::v1) +NGRAPH_OP(ReduceLogicalOr, ngraph::op::v1) +NGRAPH_OP(ReduceMean, ngraph::op::v1) +NGRAPH_OP(ReduceMin, ngraph::op::v1) +NGRAPH_OP(ReduceProd, ngraph::op::v1) +NGRAPH_OP(ReduceSum, ngraph::op::v1) +NGRAPH_OP(RegionYolo, ngraph::op::v0) +NGRAPH_OP(ReorgYolo, ngraph::op::v0) +NGRAPH_OP(Reshape, ngraph::op::v1) +NGRAPH_OP(Result, ngraph::op::v0) +NGRAPH_OP(ReverseSequence, ngraph::op::v0) +NGRAPH_OP(ROIPooling, ngraph::op::v0) +NGRAPH_OP(ScatterNDUpdate, ngraph::op::v3) +NGRAPH_OP(Select, ngraph::op::v1) +NGRAPH_OP(Selu, ngraph::op::v0) +NGRAPH_OP(Sign, ngraph::op::v0) +NGRAPH_OP(Sigmoid, ngraph::op::v0) +NGRAPH_OP(Sin, ngraph::op::v0) +NGRAPH_OP(Sinh, ngraph::op::v0) +NGRAPH_OP(Softmax, ngraph::op::v1) +NGRAPH_OP(Sqrt, ngraph::op::v0) +NGRAPH_OP(SpaceToDepth, ngraph::op::v0) +NGRAPH_OP(Split, ngraph::op::v1) +NGRAPH_OP(SquaredDifference, ngraph::op::v0) +NGRAPH_OP(Squeeze, ngraph::op::v0) +NGRAPH_OP(StridedSlice, ngraph::op::v1) +NGRAPH_OP(Subtract, ngraph::op::v1) +NGRAPH_OP(Tan, ngraph::op::v0) +NGRAPH_OP(Tanh, ngraph::op::v0) +NGRAPH_OP(TensorIterator, ngraph::op::v0) +NGRAPH_OP(Tile, ngraph::op::v0) +NGRAPH_OP(Transpose, ngraph::op::v1) +NGRAPH_OP(Unsqueeze, ngraph::op::v0) +NGRAPH_OP(VariadicSplit, ngraph::op::v1) + +// New operations added in opset2 +NGRAPH_OP(Gelu, ngraph::op::v0) +NGRAPH_OP(BatchToSpace, ngraph::op::v1) +NGRAPH_OP(SpaceToBatch, ngraph::op::v1) + +// New operations added in opset3 +NGRAPH_OP(EmbeddingBagPackedSum, ngraph::op::v3) +NGRAPH_OP(EmbeddingSegmentsSum, ngraph::op::v3) +NGRAPH_OP(EmbeddingBagOffsetsSum, ngraph::op::v3) +NGRAPH_OP(GRUCell, ngraph::op::v3) +NGRAPH_OP(NonZero, ngraph::op::v3) +NGRAPH_OP(RNNCell, ngraph::op::v0) +NGRAPH_OP(ROIAlign, ngraph::op::v3) +NGRAPH_OP(ScatterElementsUpdate, ngraph::op::v3) +NGRAPH_OP(ScatterUpdate, ngraph::op::v3) +NGRAPH_OP(ShuffleChannels, ngraph::op::v0) +NGRAPH_OP(ShapeOf, ngraph::op::v3) +NGRAPH_OP(Assign, ngraph::op::v3) +NGRAPH_OP(ReadValue, ngraph::op::v3) +NGRAPH_OP(TopK, ngraph::op::v3) + +// New operations added in opset4 +NGRAPH_OP(Acosh, ngraph::op::v3) +NGRAPH_OP(Asinh, ngraph::op::v3) +NGRAPH_OP(Atanh, ngraph::op::v3) +NGRAPH_OP(CTCLoss, ngraph::op::v4) +NGRAPH_OP(HSwish, ngraph::op::v4) +NGRAPH_OP(Interpolate, ngraph::op::v4) +NGRAPH_OP(Mish, ngraph::op::v4) +NGRAPH_OP(NonMaxSuppression, ngraph::op::v4) +NGRAPH_OP(ReduceL1, ngraph::op::v4) +NGRAPH_OP(ReduceL2, ngraph::op::v4) +NGRAPH_OP(SoftPlus, ngraph::op::v4) +NGRAPH_OP(Swish, ngraph::op::v4) + +// New operations added in opset5 +NGRAPH_OP(LSTMSequence, ngraph::op::v5) +NGRAPH_OP(GRUSequence, ngraph::op::v5) +NGRAPH_OP(RNNSequence, ngraph::op::v5) \ No newline at end of file diff --git a/ngraph/core/src/opsets/opset.cpp b/ngraph/core/src/opsets/opset.cpp index 3986d4666d9bb2..56fdf7dd48c0b6 100644 --- a/ngraph/core/src/opsets/opset.cpp +++ b/ngraph/core/src/opsets/opset.cpp @@ -119,3 +119,22 @@ const ngraph::OpSet& ngraph::get_opset4() } return opset; } + +const ngraph::OpSet& ngraph::get_opset5() +{ + static std::mutex init_mutex; + static bool opset_is_initialized = false; + static OpSet opset; + if (!opset_is_initialized) + { + std::lock_guard guard(init_mutex); + if (!opset_is_initialized) + { +#define NGRAPH_OP(NAME, NAMESPACE) opset.insert(); +#include "ngraph/opsets/opset5_tbl.hpp" +#undef NGRAPH_OP + opset_is_initialized = true; + } + } + return opset; +} \ No newline at end of file diff --git a/ngraph/test/attributes.cpp b/ngraph/test/attributes.cpp index f7f600d51d54a1..a96246601f832b 100644 --- a/ngraph/test/attributes.cpp +++ b/ngraph/test/attributes.cpp @@ -21,6 +21,7 @@ #include "ngraph/opsets/opset1.hpp" #include "ngraph/opsets/opset3.hpp" #include "ngraph/opsets/opset4.hpp" +#include "ngraph/opsets/opset5.hpp" #include "util/visitor.hpp" @@ -1099,7 +1100,7 @@ TEST(attributes, lstm_cell_op) TEST(attributes, lstm_sequence_op) { - FactoryRegistry::get().register_factory(); + FactoryRegistry::get().register_factory(); const size_t batch_size = 4; const size_t num_directions = 2; @@ -1126,7 +1127,7 @@ TEST(attributes, lstm_sequence_op) const std::vector activations = {"tanh", "sigmoid", "tanh"}; const float clip_threshold = 0.5f; - const auto lstm_sequence = make_shared(X, + const auto lstm_sequence = make_shared(X, initial_hidden_state, initial_cell_state, sequence_lengths, @@ -1140,7 +1141,7 @@ TEST(attributes, lstm_sequence_op) activations, clip_threshold); NodeBuilder builder(lstm_sequence); - auto g_lstm_sequence = as_type_ptr(builder.create()); + auto g_lstm_sequence = as_type_ptr(builder.create()); EXPECT_EQ(g_lstm_sequence->get_hidden_size(), lstm_sequence->get_hidden_size()); EXPECT_EQ(g_lstm_sequence->get_activations(), lstm_sequence->get_activations()); diff --git a/ngraph/test/type_prop/gru_sequence.cpp b/ngraph/test/type_prop/gru_sequence.cpp index 105d8e3bb5a43b..47cc47fa89ab00 100644 --- a/ngraph/test/type_prop/gru_sequence.cpp +++ b/ngraph/test/type_prop/gru_sequence.cpp @@ -16,7 +16,7 @@ #include "gtest/gtest.h" #include "ngraph/ngraph.hpp" -#include "ngraph/opsets/opset4.hpp" +#include "ngraph/opsets/opset5.hpp" #include "util/type_prop.hpp" using namespace std; @@ -31,20 +31,20 @@ TEST(type_prop, gru_sequence_forward) const size_t hidden_size = 128; const auto X = - make_shared(element::f32, Shape{batch_size, seq_length, input_size}); - const auto initial_hidden_state = make_shared( + make_shared(element::f32, Shape{batch_size, seq_length, input_size}); + const auto initial_hidden_state = make_shared( element::f32, Shape{batch_size, num_directions, hidden_size}); const auto sequence_lengths = make_shared(element::i32, Shape{batch_size}); - const auto W = make_shared( + const auto W = make_shared( element::f32, Shape{num_directions, 3 * hidden_size, input_size}); - const auto R = make_shared( + const auto R = make_shared( element::f32, Shape{num_directions, 3 * hidden_size, hidden_size}); const auto B = - make_shared(element::f32, Shape{num_directions, 3 * hidden_size}); + make_shared(element::f32, Shape{num_directions, 3 * hidden_size}); const auto direction = op::RecurrentSequenceDirection::FORWARD; - const auto sequence = make_shared( + const auto sequence = make_shared( X, initial_hidden_state, sequence_lengths, W, R, B, hidden_size, direction); EXPECT_EQ(sequence->get_hidden_size(), hidden_size); diff --git a/ngraph/test/type_prop/lstm_sequence.cpp b/ngraph/test/type_prop/lstm_sequence.cpp index 16d628cddf0fa1..756e7d9c90b4ca 100644 --- a/ngraph/test/type_prop/lstm_sequence.cpp +++ b/ngraph/test/type_prop/lstm_sequence.cpp @@ -16,7 +16,7 @@ #include "gtest/gtest.h" #include "ngraph/ngraph.hpp" -#include "ngraph/opsets/opset4.hpp" +#include "ngraph/opsets/opset5.hpp" #include "util/type_prop.hpp" // suppress FusedOp deprecation warnings @@ -41,7 +41,7 @@ struct recurrent_sequence_parameters // // Create and initialize default input test tensors. // -shared_ptr +shared_ptr lstm_seq_tensor_initialization(const recurrent_sequence_parameters& param) { auto batch_size = param.batch_size; @@ -52,20 +52,20 @@ shared_ptr auto et = param.et; const auto X = - make_shared(et, PartialShape{batch_size, seq_length, input_size}); + make_shared(et, PartialShape{batch_size, seq_length, input_size}); const auto initial_hidden_state = - make_shared(et, PartialShape{batch_size, num_directions, hidden_size}); + make_shared(et, PartialShape{batch_size, num_directions, hidden_size}); const auto initial_cell_state = - make_shared(et, PartialShape{batch_size, num_directions, hidden_size}); - const auto sequence_lengths = make_shared(et, PartialShape{batch_size}); - const auto W = make_shared( + make_shared(et, PartialShape{batch_size, num_directions, hidden_size}); + const auto sequence_lengths = make_shared(et, PartialShape{batch_size}); + const auto W = make_shared( et, PartialShape{num_directions, hidden_size * 4, input_size}); - const auto R = make_shared( + const auto R = make_shared( et, PartialShape{num_directions, hidden_size * 4, hidden_size}); const auto B = - make_shared(et, PartialShape{num_directions, hidden_size * 4}); + make_shared(et, PartialShape{num_directions, hidden_size * 4}); - const auto lstm_sequence = make_shared(); + const auto lstm_sequence = make_shared(); lstm_sequence->set_argument(0, X); lstm_sequence->set_argument(1, initial_hidden_state); @@ -87,22 +87,22 @@ TEST(type_prop, lstm_sequence_forward) const size_t hidden_size = 128; const auto X = - make_shared(element::f32, Shape{batch_size, seq_length, input_size}); - const auto initial_hidden_state = make_shared( + make_shared(element::f32, Shape{batch_size, seq_length, input_size}); + const auto initial_hidden_state = make_shared( element::f32, Shape{batch_size, num_directions, hidden_size}); - const auto initial_cell_state = make_shared( + const auto initial_cell_state = make_shared( element::f32, Shape{batch_size, num_directions, hidden_size}); - const auto sequence_lengths = make_shared(element::i32, Shape{batch_size}); - const auto W = make_shared( + const auto sequence_lengths = make_shared(element::i32, Shape{batch_size}); + const auto W = make_shared( element::f32, Shape{num_directions, 4 * hidden_size, input_size}); - const auto R = make_shared( + const auto R = make_shared( element::f32, Shape{num_directions, 4 * hidden_size, hidden_size}); const auto B = - make_shared(element::f32, Shape{num_directions, 4 * hidden_size}); + make_shared(element::f32, Shape{num_directions, 4 * hidden_size}); const auto lstm_direction = op::RecurrentSequenceDirection::FORWARD; - const auto lstm_sequence = make_shared(X, + const auto lstm_sequence = make_shared(X, initial_hidden_state, initial_cell_state, sequence_lengths, @@ -139,25 +139,25 @@ TEST(type_prop, lstm_sequence_bidirectional) const size_t hidden_size = 256; const auto X = - make_shared(element::f32, Shape{batch_size, seq_length, input_size}); - const auto initial_hidden_state = make_shared( + make_shared(element::f32, Shape{batch_size, seq_length, input_size}); + const auto initial_hidden_state = make_shared( element::f32, Shape{batch_size, num_directions, hidden_size}); - const auto initial_cell_state = make_shared( + const auto initial_cell_state = make_shared( element::f32, Shape{batch_size, num_directions, hidden_size}); - const auto sequence_lengths = make_shared(element::i32, Shape{batch_size}); - const auto W = make_shared( + const auto sequence_lengths = make_shared(element::i32, Shape{batch_size}); + const auto W = make_shared( element::f32, Shape{num_directions, 4 * hidden_size, input_size}); - const auto R = make_shared( + const auto R = make_shared( element::f32, Shape{num_directions, 4 * hidden_size, hidden_size}); const auto B = - make_shared(element::f32, Shape{num_directions, 4 * hidden_size}); + make_shared(element::f32, Shape{num_directions, 4 * hidden_size}); - const auto lstm_direction = op::v5::LSTMSequence::direction::BIDIRECTIONAL; + const auto lstm_direction = opset5::LSTMSequence::direction::BIDIRECTIONAL; const std::vector activations_alpha = {2.7, 7.0, 32.367}; const std::vector activations_beta = {0.0, 5.49, 6.0}; const std::vector activations = {"tanh", "sigmoid", "sigmoid"}; - const auto lstm_sequence = make_shared(X, + const auto lstm_sequence = make_shared(X, initial_hidden_state, initial_cell_state, sequence_lengths, @@ -170,7 +170,7 @@ TEST(type_prop, lstm_sequence_bidirectional) activations_beta, activations); EXPECT_EQ(lstm_sequence->get_hidden_size(), hidden_size); - EXPECT_EQ(lstm_sequence->get_direction(), op::v5::LSTMSequence::direction::BIDIRECTIONAL); + EXPECT_EQ(lstm_sequence->get_direction(), opset5::LSTMSequence::direction::BIDIRECTIONAL); EXPECT_EQ(lstm_sequence->get_activations_alpha(), activations_alpha); EXPECT_EQ(lstm_sequence->get_activations_beta(), activations_beta); EXPECT_EQ(lstm_sequence->get_activations()[0], "tanh"); @@ -328,7 +328,7 @@ TEST(type_prop, lstm_sequence_invalid_input_dimension) param.et = element::f32; auto lstm_sequence = lstm_seq_tensor_initialization(param); - auto invalid_rank0_tensor = make_shared(param.et, PartialShape{}); + auto invalid_rank0_tensor = make_shared(param.et, PartialShape{}); // Validate invalid rank0 tensor for all inputs: X, initial_hidden_state, initial_cell_state W, // R, B @@ -352,7 +352,7 @@ TEST(type_prop, lstm_sequence_invalid_input_dynamic_rank) param.hidden_size = 256; param.et = element::f32; - auto check_dynamic_lstm = [](const shared_ptr& lstm) -> bool { + auto check_dynamic_lstm = [](const shared_ptr& lstm) -> bool { return lstm->output(0).get_partial_shape() == PartialShape::dynamic() && lstm->output(1).get_partial_shape() == PartialShape::dynamic() && lstm->output(2).get_partial_shape() == PartialShape::dynamic() && @@ -361,7 +361,7 @@ TEST(type_prop, lstm_sequence_invalid_input_dynamic_rank) auto lstm_sequence = lstm_seq_tensor_initialization(param); auto invalid_dynamic_tensor = - make_shared(param.et, PartialShape::dynamic(Rank::dynamic())); + make_shared(param.et, PartialShape::dynamic(Rank::dynamic())); // Validate invalid dynamic tensor for all inputs: X, initial_hidden_state, initial_cell_state // W, R, B diff --git a/ngraph/test/type_prop/rnn_sequence.cpp b/ngraph/test/type_prop/rnn_sequence.cpp index a3dfb6c5b630cb..94b500dbb02e4c 100644 --- a/ngraph/test/type_prop/rnn_sequence.cpp +++ b/ngraph/test/type_prop/rnn_sequence.cpp @@ -16,7 +16,7 @@ #include "gtest/gtest.h" #include "ngraph/ngraph.hpp" -#include "ngraph/opsets/opset4.hpp" +#include "ngraph/opsets/opset5.hpp" #include "util/type_prop.hpp" using namespace std; @@ -31,20 +31,20 @@ TEST(type_prop, rnn_sequence_forward) const size_t hidden_size = 128; const auto X = - make_shared(element::f32, Shape{batch_size, seq_length, input_size}); - const auto initial_hidden_state = make_shared( + make_shared(element::f32, Shape{batch_size, seq_length, input_size}); + const auto initial_hidden_state = make_shared( element::f32, Shape{batch_size, num_directions, hidden_size}); const auto sequence_lengths = make_shared(element::i32, Shape{batch_size}); - const auto W = make_shared(element::f32, + const auto W = make_shared(element::f32, Shape{num_directions, hidden_size, input_size}); - const auto R = make_shared(element::f32, + const auto R = make_shared(element::f32, Shape{num_directions, hidden_size, hidden_size}); - const auto B = make_shared(element::f32, Shape{num_directions, hidden_size}); + const auto B = make_shared(element::f32, Shape{num_directions, hidden_size}); const auto direction = op::RecurrentSequenceDirection::FORWARD; - const auto sequence = make_shared( + const auto sequence = make_shared( X, initial_hidden_state, sequence_lengths, W, R, B, hidden_size, direction); EXPECT_EQ(sequence->get_hidden_size(), hidden_size); From c3f5e92e5692b20446d478bb423942eab1fcabcd Mon Sep 17 00:00:00 2001 From: Edward Shogulin Date: Fri, 18 Sep 2020 22:33:48 +0300 Subject: [PATCH 46/64] [LPT] WA removal: precision propagation fix --- inference-engine/src/cldnn_engine/cldnn_engine.cpp | 4 ---- inference-engine/src/mkldnn_plugin/mkldnn_plugin.cpp | 4 ---- .../convert_opset1_to_legacy/reshape_fc_fusion.hpp | 7 ------- .../convert_normalizel2_to_normalize_ie.cpp | 4 ---- .../ngraph/op/util/binary_elementwise_arithmetic.hpp | 5 ----- ngraph/core/src/op/util/binary_elementwise_arithmetic.cpp | 5 ----- 6 files changed, 29 deletions(-) diff --git a/inference-engine/src/cldnn_engine/cldnn_engine.cpp b/inference-engine/src/cldnn_engine/cldnn_engine.cpp index d875837f95ace1..e607d7f2e8ae19 100644 --- a/inference-engine/src/cldnn_engine/cldnn_engine.cpp +++ b/inference-engine/src/cldnn_engine/cldnn_engine.cpp @@ -170,10 +170,6 @@ InferenceEngine::ICNNNetwork::Ptr clDNNEngine::CloneAndTransformNetwork(const In .add(LayerTransformation::Params(params).setSupportAsymmetricQuantization(false))); transformer.transform(nGraphFunc); - -#ifdef LPT_SUPPORT - ngraph::op::util::BinaryElementwiseArithmetic::multi_type_global = true; -#endif } { diff --git a/inference-engine/src/mkldnn_plugin/mkldnn_plugin.cpp b/inference-engine/src/mkldnn_plugin/mkldnn_plugin.cpp index 10374037bf0b76..845ee5e83ba718 100644 --- a/inference-engine/src/mkldnn_plugin/mkldnn_plugin.cpp +++ b/inference-engine/src/mkldnn_plugin/mkldnn_plugin.cpp @@ -145,10 +145,6 @@ static void Transformation(ICNNNetwork::Ptr& clonedNetwork, const Config& conf) LayerTransformation::Params(params).setPrecisionsOnActivations({ ngraph::element::u8 }))); transformer.transform(nGraphFunc); - -#ifdef LPT_SUPPORT - ngraph::op::util::BinaryElementwiseArithmetic::multi_type_global = true; -#endif } { diff --git a/inference-engine/src/transformations/include/transformations/convert_opset1_to_legacy/reshape_fc_fusion.hpp b/inference-engine/src/transformations/include/transformations/convert_opset1_to_legacy/reshape_fc_fusion.hpp index 3faa7020794cbb..3c3b0511103e57 100644 --- a/inference-engine/src/transformations/include/transformations/convert_opset1_to_legacy/reshape_fc_fusion.hpp +++ b/inference-engine/src/transformations/include/transformations/convert_opset1_to_legacy/reshape_fc_fusion.hpp @@ -77,18 +77,11 @@ class ngraph::pass::ReshapeFullyConnectedFusion : public ngraph::pass::GraphRewr return false; } -#ifdef LPT_SUPPORT auto new_fc = std::make_shared(reshape->input_value(0), fc->input_value(1), fc->input_value(2), fc->get_shape(), fc->output(0).get_element_type()); -#else - auto new_fc = std::make_shared(reshape->input_value(0), - fc->input_value(1), - fc->input_value(2), - fc->get_shape()); -#endif new_fc->set_friendly_name(fc->get_friendly_name()); ngraph::copy_runtime_info({reshape, fc}, new_fc); diff --git a/inference-engine/src/transformations/src/transformations/convert_opset1_to_legacy/convert_normalizel2_to_normalize_ie.cpp b/inference-engine/src/transformations/src/transformations/convert_opset1_to_legacy/convert_normalizel2_to_normalize_ie.cpp index d0528e9a0d9fb0..1f7254a2ef1aad 100644 --- a/inference-engine/src/transformations/src/transformations/convert_opset1_to_legacy/convert_normalizel2_to_normalize_ie.cpp +++ b/inference-engine/src/transformations/src/transformations/convert_opset1_to_legacy/convert_normalizel2_to_normalize_ie.cpp @@ -94,11 +94,7 @@ ngraph::pass::ConvertNormalizeL2ToLegacyMatcher::ConvertNormalizeL2ToLegacyMatch bool across_channels = !(axis.size() == 1 && axis[0] == 1); bool channel_shared = true; -#ifdef LPT_SUPPORT auto scale = std::make_shared(normalize->output(0).get_element_type(), Shape{1}, std::vector{1.0}); -#else - auto scale = std::make_shared(normalize->get_input_element_type(0), Shape{ 1 }, std::vector{1.0}); -#endif auto normalize_ie = std::make_shared (normalize->input(0).get_source_output(), scale->output(0), diff --git a/ngraph/core/include/ngraph/op/util/binary_elementwise_arithmetic.hpp b/ngraph/core/include/ngraph/op/util/binary_elementwise_arithmetic.hpp index 0a8b34a05b5c14..25d4fd4b4f294f 100644 --- a/ngraph/core/include/ngraph/op/util/binary_elementwise_arithmetic.hpp +++ b/ngraph/core/include/ngraph/op/util/binary_elementwise_arithmetic.hpp @@ -67,10 +67,6 @@ namespace ngraph const AutoBroadcastSpec& autob); public: -#ifdef LPT_SUPPORT - static bool multi_type_global; -#endif - void validate_and_infer_types() override; const AutoBroadcastSpec& get_autob() const override { return m_autob; } @@ -79,7 +75,6 @@ namespace ngraph private: AutoBroadcastSpec m_autob; - void validate_and_infer_elementwise_arithmetic(const op::AutoBroadcastSpec& autob); }; } diff --git a/ngraph/core/src/op/util/binary_elementwise_arithmetic.cpp b/ngraph/core/src/op/util/binary_elementwise_arithmetic.cpp index 3ed84269afe9e1..7f9b4afbeec0c7 100644 --- a/ngraph/core/src/op/util/binary_elementwise_arithmetic.cpp +++ b/ngraph/core/src/op/util/binary_elementwise_arithmetic.cpp @@ -23,10 +23,6 @@ using namespace ngraph; NGRAPH_RTTI_DEFINITION(op::util::BinaryElementwiseArithmetic, "BinaryElementwiseArithmetic", 0); -#ifdef LPT_SUPPORT -bool op::util::BinaryElementwiseArithmetic::multi_type_global = false; -#endif - op::util::BinaryElementwiseArithmetic::BinaryElementwiseArithmetic(const AutoBroadcastSpec& autob) : m_autob(autob) { @@ -44,7 +40,6 @@ void op::util::BinaryElementwiseArithmetic::validate_and_infer_elementwise_arith const op::AutoBroadcastSpec& autob) { auto args_et_pshape = op::util::validate_and_infer_elementwise_args(this, autob); - element::Type& args_et = std::get<0>(args_et_pshape); PartialShape& args_pshape = std::get<1>(args_et_pshape); From 40713e1fad45df1f707f22700e92eb66f9980902 Mon Sep 17 00:00:00 2001 From: Edward Shogulin Date: Fri, 18 Sep 2020 23:17:19 +0300 Subject: [PATCH 47/64] [LPT] ConvertMulOrAddFinally transformation extending --- .../convert_opset1_to_legacy/convert_mul_or_add_finally.hpp | 2 ++ .../lp_transformations/concat_with_split_transformation.cpp | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/inference-engine/src/transformations/include/transformations/convert_opset1_to_legacy/convert_mul_or_add_finally.hpp b/inference-engine/src/transformations/include/transformations/convert_opset1_to_legacy/convert_mul_or_add_finally.hpp index d7a5913ee4235f..46060d3ec84b85 100644 --- a/inference-engine/src/transformations/include/transformations/convert_opset1_to_legacy/convert_mul_or_add_finally.hpp +++ b/inference-engine/src/transformations/include/transformations/convert_opset1_to_legacy/convert_mul_or_add_finally.hpp @@ -200,6 +200,8 @@ ngraph::graph_rewrite_callback get_callback() { power = std::make_shared(data_node, 1., 1., value, lin_op->get_output_element_type(0)); } else if (std::is_same()) { power = std::make_shared(data_node, 1., value, 0., lin_op->get_output_element_type(0)); + } else if (std::is_same()) { + power = std::make_shared(data_node, 1., 1., -value, lin_op->get_output_element_type(0)); } else { return false; } diff --git a/inference-engine/tests/functional/inference_engine/lp_transformations/concat_with_split_transformation.cpp b/inference-engine/tests/functional/inference_engine/lp_transformations/concat_with_split_transformation.cpp index 568c2084872d40..1d57de32c45ef0 100644 --- a/inference-engine/tests/functional/inference_engine/lp_transformations/concat_with_split_transformation.cpp +++ b/inference-engine/tests/functional/inference_engine/lp_transformations/concat_with_split_transformation.cpp @@ -225,7 +225,7 @@ const std::vector testValues = { }, }; -// LPT_SUPPORT: temporary disabled +// TODO: Split/VariadicSplit operations are not supported in ConcatTransformation INSTANTIATE_TEST_CASE_P( DISABLED_LPT, ConcatWithSplitTransformation, From dbc0a4f2dba5d5b253bdabb6b964783d5f504a9f Mon Sep 17 00:00:00 2001 From: Edward Shogulin Date: Sat, 19 Sep 2020 00:16:37 +0300 Subject: [PATCH 48/64] [nGraph] ConvolutionMultiplyFusion rollback (move from legacy to common) --- .../common_optimizations/conv_mul_fusion.cpp | 33 +------------------ 1 file changed, 1 insertion(+), 32 deletions(-) diff --git a/inference-engine/src/transformations/src/transformations/common_optimizations/conv_mul_fusion.cpp b/inference-engine/src/transformations/src/transformations/common_optimizations/conv_mul_fusion.cpp index 585cfbd7676e79..4da727924fc1a5 100644 --- a/inference-engine/src/transformations/src/transformations/common_optimizations/conv_mul_fusion.cpp +++ b/inference-engine/src/transformations/src/transformations/common_optimizations/conv_mul_fusion.cpp @@ -15,27 +15,6 @@ #include -#ifdef LPT_SUPPORT -#include "ngraph/opsets/opset1.hpp" -bool IsConvInLowPrecision(const std::shared_ptr& conv) { - auto isLowPrecision = [](const std::shared_ptr& node, const size_t index) { - const ngraph::element::Type inputType = node->get_input_element_type(index); - return (inputType == ngraph::element::i8) || (inputType == ngraph::element::u8); - }; - - if (isLowPrecision(conv, 0) || isLowPrecision(conv, 1)) { - return true; - } - - const std::shared_ptr subtract = ngraph::as_type_ptr(conv->get_input_node_shared_ptr(0)); - if (subtract == nullptr) { - return false; - } - - return isLowPrecision(subtract, 0) || isLowPrecision(subtract, 1); -} -#endif - NGRAPH_RTTI_DEFINITION(ngraph::pass::ConvolutionMultiplyFusion, "ConvolutionMultiplyFusion", 0); ngraph::pass::ConvolutionMultiplyFusion::ConvolutionMultiplyFusion() { @@ -52,11 +31,6 @@ ngraph::pass::ConvolutionMultiplyFusion::ConvolutionMultiplyFusion() { const auto & m_const = pattern_to_output.at(mul_const); const auto & m_input = pattern_to_output.at(input); const auto & m_conv = pattern_to_output.at(conv).get_node_shared_ptr(); -#ifdef LPT_SUPPORT - if (IsConvInLowPrecision(m_conv)) { - return false; - } -#endif const auto & m_mul = pattern_to_output.at(mul).get_node_shared_ptr(); const auto & channel_dim = m_weights.get_partial_shape()[0].get_length(); @@ -121,11 +95,6 @@ ngraph::pass::GroupConvolutionMultiplyFusion::GroupConvolutionMultiplyFusion() { const auto & m_input = pattern_to_output.at(input); const auto & m_conv = pattern_to_output.at(conv).get_node_shared_ptr(); const auto & m_mul = pattern_to_output.at(mul).get_node_shared_ptr(); -#ifdef LPT_SUPPORT - if (IsConvInLowPrecision(m_conv)) { - return false; - } -#endif const auto & G = m_weights.get_partial_shape()[0].get_length(); const auto & O = m_weights.get_partial_shape()[1].get_length(); @@ -300,4 +269,4 @@ ngraph::pass::GroupConvolutionBackpropDataMultiplyFusion::GroupConvolutionBackpr auto m = std::make_shared(mul, "GroupConvolutionMultiplyFusion"); register_matcher(m, callback); -} +} \ No newline at end of file From a5b4eaaaf95e9b0b47fc30376b6ebce329432f62 Mon Sep 17 00:00:00 2001 From: Edward Shogulin Date: Sat, 19 Sep 2020 00:47:50 +0300 Subject: [PATCH 49/64] [nGraph] ConvertMulAddToScaleShiftOrPower: WA removal --- .../convert_mul_add_to_scaleshift_or_power.cpp | 8 -------- 1 file changed, 8 deletions(-) diff --git a/inference-engine/src/transformations/src/transformations/convert_opset1_to_legacy/convert_mul_add_to_scaleshift_or_power.cpp b/inference-engine/src/transformations/src/transformations/convert_opset1_to_legacy/convert_mul_add_to_scaleshift_or_power.cpp index b9b6d13c5cbee9..9f649ecbb6430d 100644 --- a/inference-engine/src/transformations/src/transformations/convert_opset1_to_legacy/convert_mul_add_to_scaleshift_or_power.cpp +++ b/inference-engine/src/transformations/src/transformations/convert_opset1_to_legacy/convert_mul_add_to_scaleshift_or_power.cpp @@ -137,19 +137,11 @@ void ngraph::pass::ConvertMulAddToScaleShiftOrPower::convert_mul_add_to_scaleshi const auto output_shape = add_node->get_output_partial_shape(0); const auto output_shape_rank = output_shape.rank().get_length(); -// to support 2d, 3d ScaleShift conversion -#ifdef LPT_SUPPORT if (res1 == CONVERSION_RESULT::NONE || res2 == CONVERSION_RESULT::NONE || ((res1 == CONVERSION_RESULT::SCALE_SHIFT || res2 == CONVERSION_RESULT::SCALE_SHIFT) && (output_shape_rank == 1 || output_shape_rank > 4))) { return false; } -#else - if (res1 == CONVERSION_RESULT::NONE || res2 == CONVERSION_RESULT::NONE || - ((res1 == CONVERSION_RESULT::SCALE_SHIFT || res2 == CONVERSION_RESULT::SCALE_SHIFT) && output_shape_rank < 4)) { - return false; - } -#endif bool is_dequantization = (add_node->get_rt_info().count("DEQUANTIZATION") != 0 || mul_node->get_rt_info().count("DEQUANTIZATION") != 0); From e206f1f605d58d49dddb5e77c43a3bad601467ce Mon Sep 17 00:00:00 2001 From: Edward Shogulin Date: Sat, 19 Sep 2020 00:48:18 +0300 Subject: [PATCH 50/64] [nGraph] TypeRelaxed: WA removal --- .../src/transformations/include/ngraph_ops/type_relaxed.hpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/inference-engine/src/transformations/include/ngraph_ops/type_relaxed.hpp b/inference-engine/src/transformations/include/ngraph_ops/type_relaxed.hpp index bd5707101cc2ae..2316f6cd044625 100644 --- a/inference-engine/src/transformations/include/ngraph_ops/type_relaxed.hpp +++ b/inference-engine/src/transformations/include/ngraph_ops/type_relaxed.hpp @@ -12,11 +12,7 @@ #include #include "ngraph/op/op.hpp" - -#ifdef LPT_SUPPORT -#include "ngraph/opsets/opset1.hpp" #include "transformations/low_precision/common/dequantization_op.hpp" -#endif namespace ngraph { namespace op { From 3bd46c0b214323429a363430584454223d3a25b2 Mon Sep 17 00:00:00 2001 From: Evgenya Stepyreva Date: Sat, 19 Sep 2020 15:48:18 +0300 Subject: [PATCH 51/64] [ DOC ] TF FakeQuantWithMinMaxVars(PerChannel) support (#2338) --- docs/MO_DG/prepare_model/Supported_Frameworks_Layers.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/MO_DG/prepare_model/Supported_Frameworks_Layers.md b/docs/MO_DG/prepare_model/Supported_Frameworks_Layers.md index 0f9bc8da7e738e..165fe30d577064 100644 --- a/docs/MO_DG/prepare_model/Supported_Frameworks_Layers.md +++ b/docs/MO_DG/prepare_model/Supported_Frameworks_Layers.md @@ -151,6 +151,8 @@ Standard TensorFlow\* operations: | ExperimentalSparseWeightedSum | CPU only | | ExtractImagePatches | No | | EuclideanNorm | No | +| FakeQuantWithMinMaxVars | No | +| FakeQuantWithMinMaxVarsPerChannel | No | | Fill | No | | Floor | No | | FloorDiv | No | From 7446e53b242e8e899f9b5ad8cadc7a6b87e48ee7 Mon Sep 17 00:00:00 2001 From: Edward Shogulin Date: Sat, 19 Sep 2020 23:02:43 +0300 Subject: [PATCH 52/64] [nGraph] WA removal: TypeRelaxed --- .../include/ngraph_ops/type_relaxed.hpp | 18 ------------------ .../low_precision/transformer.cpp | 19 ++++++++++++++----- .../ngraph_reader/linear_ops_tests.cpp | 5 ++--- .../ngraph_reader/split_tests.cpp | 3 +-- ...convert_sequences_to_sequences_ie_test.cpp | 5 ++--- .../mul_add_conversion_test.cpp | 6 ++---- 6 files changed, 21 insertions(+), 35 deletions(-) diff --git a/inference-engine/src/transformations/include/ngraph_ops/type_relaxed.hpp b/inference-engine/src/transformations/include/ngraph_ops/type_relaxed.hpp index 2316f6cd044625..b11a4f6bc58921 100644 --- a/inference-engine/src/transformations/include/ngraph_ops/type_relaxed.hpp +++ b/inference-engine/src/transformations/include/ngraph_ops/type_relaxed.hpp @@ -184,30 +184,12 @@ void TypeRelaxed::validate_and_infer_types() { } } -#ifdef LPT_SUPPORT - if (is_type(this)) { - // Restore original input data types - for (size_t i = 0; i < BaseOp::get_input_size(); ++i) { - BaseOp::get_input_tensor(i).set_tensor_type(old_input_types[i], BaseOp::get_input_partial_shape(i)); - } - - BaseOp::validate_and_infer_types(); - } else { - BaseOp::validate_and_infer_types(); - - // Restore original input data types - for (size_t i = 0; i < BaseOp::get_input_size(); ++i) { - BaseOp::get_input_tensor(i).set_tensor_type(old_input_types[i], BaseOp::get_input_partial_shape(i)); - } - } -#else BaseOp::validate_and_infer_types(); // Restore original input data types for (size_t i = 0; i < BaseOp::get_input_size(); ++i) { BaseOp::get_input_tensor(i).set_tensor_type(old_input_types[i], BaseOp::get_input_partial_shape(i)); } -#endif // Override (some) output types diff --git a/inference-engine/src/transformations/src/transformations/low_precision/transformer.cpp b/inference-engine/src/transformations/src/transformations/low_precision/transformer.cpp index 84adf3e815d246..b0843fd87ba218 100644 --- a/inference-engine/src/transformations/src/transformations/low_precision/transformer.cpp +++ b/inference-engine/src/transformations/src/transformations/low_precision/transformer.cpp @@ -274,12 +274,21 @@ void make_matcher_type_relaxed(ngraph::pass::GraphRewrite* transformation) { ngraph::graph_rewrite_callback callback = [](ngraph::pattern::Matcher &m) { auto l_node = std::dynamic_pointer_cast(m.get_match_root()); if (!l_node) { - std::cerr << "Error my matcher 1!!!\n"; - return false; + THROW_IE_LPT_EXCEPTION(*l_node) << "unexpected operation type"; + } + + std::vector inputPrecisions; + for (auto& inputs : l_node->inputs()) { + inputPrecisions.push_back(inputs.get_element_type()); } - // std::cerr << "My matcher pass was triggered: " << l_node->get_friendly_name() << " with " << l_node->get_inputs().size() << " inputs\n"; - // TODO: replaces only operation with one output port - auto replacement = std::make_shared>(*l_node, l_node->get_output_element_type(0)); + + std::vector outputPrecisions; + for (auto& output : l_node->outputs()) { + outputPrecisions.push_back(output.get_element_type()); + } + + auto replacement = std::make_shared>(*l_node, inputPrecisions, outputPrecisions); + copy_runtime_info(l_node, replacement); replace_node(l_node, replacement); return true; diff --git a/inference-engine/tests/functional/inference_engine/ngraph_reader/linear_ops_tests.cpp b/inference-engine/tests/functional/inference_engine/ngraph_reader/linear_ops_tests.cpp index 20726d5a3f7531..046c62c6942fe7 100644 --- a/inference-engine/tests/functional/inference_engine/ngraph_reader/linear_ops_tests.cpp +++ b/inference-engine/tests/functional/inference_engine/ngraph_reader/linear_ops_tests.cpp @@ -4,8 +4,7 @@ #include #include "ngraph_reader_tests.hpp" -// LPT_SUPPORT: temporary disabled -TEST_F(NGraphReaderTests, DISABLED_ConvertMulAddToScaleShift) { +TEST_F(NGraphReaderTests, ConvertMulAddToScaleShift) { std::string model = R"V0G0N( @@ -2005,7 +2004,7 @@ TEST_F(NGraphReaderTests, RemoveAdd3) { }); } -TEST_F(NGraphReaderTests, DISABLED_ConvertAddToEltwise2) { +TEST_F(NGraphReaderTests, ConvertAddToEltwise2) { std::string model = R"V0G0N( diff --git a/inference-engine/tests/functional/inference_engine/ngraph_reader/split_tests.cpp b/inference-engine/tests/functional/inference_engine/ngraph_reader/split_tests.cpp index 03d8b8dde1355e..21eb1d2b14d32d 100644 --- a/inference-engine/tests/functional/inference_engine/ngraph_reader/split_tests.cpp +++ b/inference-engine/tests/functional/inference_engine/ngraph_reader/split_tests.cpp @@ -131,8 +131,7 @@ TEST_F(NGraphReaderTests, ReadSplitNetwork) { }); } -// TODO: LPT_SUPPORT -TEST_F(NGraphReaderTests, DISABLED_ReadSplitNetwork2) { +TEST_F(NGraphReaderTests, ReadSplitNetwork2) { std::string model = R"V0G0N( diff --git a/inference-engine/tests/functional/inference_engine/transformations/convert_sequences_to_sequences_ie_test.cpp b/inference-engine/tests/functional/inference_engine/transformations/convert_sequences_to_sequences_ie_test.cpp index 748a045d3cfff8..40c2cbf9ed86e7 100644 --- a/inference-engine/tests/functional/inference_engine/transformations/convert_sequences_to_sequences_ie_test.cpp +++ b/inference-engine/tests/functional/inference_engine/transformations/convert_sequences_to_sequences_ie_test.cpp @@ -173,8 +173,7 @@ TEST(TransformationTests, RNNSequenceConversionTest) { ->input_value(0).get_node_shared_ptr(); } -// LPT_SUPPORT: temporary disabled -TEST(TransformationTests, DISABLED_LSTMSequenceConversionTest) { +TEST(TransformationTests, LSTMSequenceConversionTest) { const size_t batch_size = 2; const size_t input_size = 3; const size_t hidden_size = 3; @@ -201,7 +200,7 @@ TEST(TransformationTests, DISABLED_LSTMSequenceConversionTest) { const auto B = std::make_shared(ngraph::element::f32, ngraph::Shape{num_directions, gates_count * hidden_size}); - const auto seq_len = std::make_shared(ngraph::element::i32, ngraph::Shape{batch_size}); + const auto seq_len = std::make_shared(ngraph::element::f32, ngraph::Shape{batch_size}); sequence = std::make_shared(X, H_t, C_t, seq_len, W, R, B, hidden_size, ngraph::op::RecurrentSequenceDirection::FORWARD); sequence->set_friendly_name("test_sequence"); diff --git a/inference-engine/tests/functional/inference_engine/transformations/mul_add_conversion_test.cpp b/inference-engine/tests/functional/inference_engine/transformations/mul_add_conversion_test.cpp index 8e37a2bd2b3038..8eb6ae6ec955a4 100644 --- a/inference-engine/tests/functional/inference_engine/transformations/mul_add_conversion_test.cpp +++ b/inference-engine/tests/functional/inference_engine/transformations/mul_add_conversion_test.cpp @@ -159,8 +159,7 @@ TEST_P(MulOrAddConversionTests, CompareFunctions) { #define ELTWISE_SUM MulAddConversionTests::get_eltwise_add_reference #define ELTWISE_PROD MulAddConversionTests::get_eltwise_mul_reference -// LPT_SUPPORT: temporary disabled -INSTANTIATE_TEST_CASE_P(DISABLED_MulAddToScaleShift, MulAddConversionTests, testing::Combine( +INSTANTIATE_TEST_CASE_P(MulAddToScaleShift, MulAddConversionTests, testing::Combine( testing::Values(std::make_tuple(InputShape{DYN, 3, 64, 64}, CONST(ngraph::Shape({1, 3, 1, 1}), 0.5), CONST(ngraph::Shape({1, 3, 1, 1}), 0.5)), @@ -233,8 +232,7 @@ INSTANTIATE_TEST_CASE_P(AddToPower, MulOrAddConversionTests, testing::Combine( testing::Values(POWER))); -// LPT_SUPPORT: temporary disabling -INSTANTIATE_TEST_CASE_P(DISABLED_MulAddNegative, MulAddConversionTests, testing::Combine( +INSTANTIATE_TEST_CASE_P(MulAddNegative, MulAddConversionTests, testing::Combine( testing::Values(std::make_tuple(InputShape{DYN, 3, 64}, CONST(ngraph::Shape({1, 3, 1}), 0.5), CONST(ngraph::Shape({1, 3, 1}), 0.5)/*ScaleShift must always be 4D*/), From ac97c83fc2ac298571820a8143df21262e634ea5 Mon Sep 17 00:00:00 2001 From: Edward Shogulin Date: Sat, 19 Sep 2020 23:07:32 +0300 Subject: [PATCH 53/64] [LPT] WA removal: ConcatTransformation --- .../src/transformations/low_precision/concat.cpp | 3 +-- .../low_precision/concat_multi_channels.cpp | 3 +-- .../src/low_precision_transformations/concat_function.cpp | 7 ++++--- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/inference-engine/src/transformations/src/transformations/low_precision/concat.cpp b/inference-engine/src/transformations/src/transformations/low_precision/concat.cpp index 826d02fa96b7c2..6be5c9c559b811 100644 --- a/inference-engine/src/transformations/src/transformations/low_precision/concat.cpp +++ b/inference-engine/src/transformations/src/transformations/low_precision/concat.cpp @@ -194,11 +194,10 @@ bool ConcatTransformation::transform(TransformationContext& context, ngraph::pat if (std::dynamic_pointer_cast(node) != nullptr) { ngraph::pass::low_precision::NetworkHelper::setOutDataPrecisionForTypeRelaxed(node->shared_from_this(), dataPrecision.precision); } else { -#ifdef LPT_SUPPORT + // set precision to explicitly to have updated precision during transformation for (size_t i = 0; i < node->get_output_size(); ++i) { node->set_output_type(i, dataPrecision.precision, node->get_output_partial_shape(i)); } -#endif } } } diff --git a/inference-engine/src/transformations/src/transformations/low_precision/concat_multi_channels.cpp b/inference-engine/src/transformations/src/transformations/low_precision/concat_multi_channels.cpp index 5c4da61e62eb10..d703b9ebfdd582 100644 --- a/inference-engine/src/transformations/src/transformations/low_precision/concat_multi_channels.cpp +++ b/inference-engine/src/transformations/src/transformations/low_precision/concat_multi_channels.cpp @@ -146,11 +146,10 @@ bool ConcatMultiChannelsTransformation::transform(TransformationContext& context if (std::dynamic_pointer_cast(node)) { ngraph::pass::low_precision::NetworkHelper::setOutDataPrecisionForTypeRelaxed(node->shared_from_this(), dataPrecision.precision); } else { -#ifdef LPT_SUPPORT + // set precision to explicitly to have updated precision during transformation for (size_t i = 0; i < node->get_output_size(); ++i) { node->set_output_type(i, dataPrecision.precision, node->get_output_partial_shape(i)); } -#endif } } } diff --git a/inference-engine/tests/ngraph_functions/src/low_precision_transformations/concat_function.cpp b/inference-engine/tests/ngraph_functions/src/low_precision_transformations/concat_function.cpp index 3120824d6ce509..21107611ab5e0c 100644 --- a/inference-engine/tests/ngraph_functions/src/low_precision_transformations/concat_function.cpp +++ b/inference-engine/tests/ngraph_functions/src/low_precision_transformations/concat_function.cpp @@ -616,9 +616,10 @@ std::shared_ptr ConcatFunction::getReferenceWithIntermediate( if (intermediateOpTr != nullptr) { ngraph::pass::low_precision::NetworkHelper::setOutDataPrecisionForTypeRelaxed(intermediateOp, fqOnDataPrecision); } else { -#ifdef LPT_SUPPORT - intermediateOp->set_output_type(0, fqOnDataPrecision, intermediateOp->get_output_partial_shape(0)); -#endif + // set precision to explicitly to have updated precision during transformation + for (size_t i = 0; i < intermediateOp->get_output_size(); ++i) { + intermediateOp->set_output_type(i, fqOnDataPrecision, intermediateOp->get_output_partial_shape(i)); + } } } } From a52f51429bbb7cc8e2e937403dd5cb832fd0d1ac Mon Sep 17 00:00:00 2001 From: Edward Shogulin Date: Sun, 20 Sep 2020 00:00:33 +0300 Subject: [PATCH 54/64] [nGraph] WA removal: Eltwise & ConvertMulOrAddFinally fixes to support LPT --- .../include/ngraph_ops/eltwise.hpp | 6 +++++- .../convert_mul_or_add_finally.hpp | 2 +- .../transformations/src/ngraph_ops/eltwise.cpp | 16 +++++++++------- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/inference-engine/src/transformations/include/ngraph_ops/eltwise.hpp b/inference-engine/src/transformations/include/ngraph_ops/eltwise.hpp index 660c574f43c6a4..0dbda13d1d8310 100644 --- a/inference-engine/src/transformations/include/ngraph_ops/eltwise.hpp +++ b/inference-engine/src/transformations/include/ngraph_ops/eltwise.hpp @@ -22,13 +22,17 @@ class TRANSFORMATIONS_API Eltwise : public Op { Eltwise(const Output& data1, const Output& data2, - const ELTWISE_TYPE eltwise_type); + const ELTWISE_TYPE eltwise_type, + const element::Type output_type = element::undefined); void validate_and_infer_types() override; std::shared_ptr clone_with_new_inputs(const OutputVector& new_args) const override; ELTWISE_TYPE eltwise_type; + +private: + element::Type m_output_type; }; } // namespace op diff --git a/inference-engine/src/transformations/include/transformations/convert_opset1_to_legacy/convert_mul_or_add_finally.hpp b/inference-engine/src/transformations/include/transformations/convert_opset1_to_legacy/convert_mul_or_add_finally.hpp index 46060d3ec84b85..aa4779da1ffc3e 100644 --- a/inference-engine/src/transformations/include/transformations/convert_opset1_to_legacy/convert_mul_or_add_finally.hpp +++ b/inference-engine/src/transformations/include/transformations/convert_opset1_to_legacy/convert_mul_or_add_finally.hpp @@ -59,7 +59,7 @@ bool convert_to_eltwise(std::shared_ptr & node, return false; } - auto eltwise = std::make_shared(data1, data2, et); + auto eltwise = std::make_shared(data1, data2, et, node->output(0).get_element_type()); eltwise->set_friendly_name(node->get_friendly_name()); ngraph::copy_runtime_info(node, eltwise); ngraph::replace_node(node, eltwise); diff --git a/inference-engine/src/transformations/src/ngraph_ops/eltwise.cpp b/inference-engine/src/transformations/src/ngraph_ops/eltwise.cpp index 3801e419a81255..4d1c4fb049ddbf 100644 --- a/inference-engine/src/transformations/src/ngraph_ops/eltwise.cpp +++ b/inference-engine/src/transformations/src/ngraph_ops/eltwise.cpp @@ -15,8 +15,8 @@ using namespace ngraph; constexpr NodeTypeInfo op::Eltwise::type_info; -op::Eltwise::Eltwise(const Output& data1, const Output& data2, const ELTWISE_TYPE eltwise_type) - : Op({data1, data2}), eltwise_type(eltwise_type) { +op::Eltwise::Eltwise(const Output& data1, const Output& data2, const ELTWISE_TYPE eltwise_type, const element::Type output_type) + : Op({data1, data2}), eltwise_type(eltwise_type), m_output_type(output_type) { constructor_validate_and_infer_types(); } @@ -33,11 +33,13 @@ void op::Eltwise::validate_and_infer_types() { element::Type data1_et = get_input_element_type(0); element::Type data2_et = get_input_element_type(1); - element::Type et_result = element::f32;; - - // workaround to support Add with different input precisions - //NODE_VALIDATION_CHECK(this, element::Type::merge(et_result, data1_et, data2_et), - // "Element types for first and second do not match :", data1_et, " and ", data2_et); + element::Type et_result; + if (m_output_type == element::undefined) { + NODE_VALIDATION_CHECK(this, element::Type::merge(et_result, data1_et, data2_et), + "Element types for first and second do not match :", data1_et, " and ", data2_et); + } else { + et_result = m_output_type; + } if (get_input_partial_shape(0).rank().is_dynamic() || get_input_partial_shape(1).rank().is_dynamic()) { From 6f8d4508829ff3db9c51290ffee0cfe0cc36f103 Mon Sep 17 00:00:00 2001 From: Edward Shogulin Date: Sun, 20 Sep 2020 00:26:56 +0300 Subject: [PATCH 55/64] [nGraph] MulAddConversion fix: 2D & 3D ScaleShift are supproted --- .../src/transformations/src/ngraph_ops/eltwise.cpp | 2 +- .../transformations/mul_add_conversion_test.cpp | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/inference-engine/src/transformations/src/ngraph_ops/eltwise.cpp b/inference-engine/src/transformations/src/ngraph_ops/eltwise.cpp index 4d1c4fb049ddbf..2011b034d0b82d 100644 --- a/inference-engine/src/transformations/src/ngraph_ops/eltwise.cpp +++ b/inference-engine/src/transformations/src/ngraph_ops/eltwise.cpp @@ -25,7 +25,7 @@ std::shared_ptr op::Eltwise::clone_with_new_inputs(const OutputVector& new throw ngraph_error("Incorrect number of new arguments"); } - return make_shared(new_args.at(0), new_args.at(1), eltwise_type); + return make_shared(new_args.at(0), new_args.at(1), eltwise_type, m_output_type); } void op::Eltwise::validate_and_infer_types() { diff --git a/inference-engine/tests/functional/inference_engine/transformations/mul_add_conversion_test.cpp b/inference-engine/tests/functional/inference_engine/transformations/mul_add_conversion_test.cpp index 8eb6ae6ec955a4..4b5e67d57b6837 100644 --- a/inference-engine/tests/functional/inference_engine/transformations/mul_add_conversion_test.cpp +++ b/inference-engine/tests/functional/inference_engine/transformations/mul_add_conversion_test.cpp @@ -233,10 +233,7 @@ INSTANTIATE_TEST_CASE_P(AddToPower, MulOrAddConversionTests, testing::Combine( INSTANTIATE_TEST_CASE_P(MulAddNegative, MulAddConversionTests, testing::Combine( - testing::Values(std::make_tuple(InputShape{DYN, 3, 64}, - CONST(ngraph::Shape({1, 3, 1}), 0.5), - CONST(ngraph::Shape({1, 3, 1}), 0.5)/*ScaleShift must always be 4D*/), - std::make_tuple(InputShape{DYN, 3, DYN}, + testing::Values(std::make_tuple(InputShape{DYN, 3, DYN}, CONST(ngraph::Shape({1, 1, 3, 1}), 0.5), CONST(ngraph::Shape({3, 1}), 0.5)/*detect broadcast case*/), std::make_tuple(InputShape{DYN, 3, DYN}, From c52fafb191c225968761c8311a829a51f7bb1089 Mon Sep 17 00:00:00 2001 From: Edward Shogulin Date: Sun, 20 Sep 2020 13:29:11 +0300 Subject: [PATCH 56/64] [nGraph] VisualizeTree extending --- ngraph/core/src/pass/visualize_tree.cpp | 44 +++++++++++++++---------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/ngraph/core/src/pass/visualize_tree.cpp b/ngraph/core/src/pass/visualize_tree.cpp index 9cd28e33ed46d7..8b92550572347c 100644 --- a/ngraph/core/src/pass/visualize_tree.cpp +++ b/ngraph/core/src/pass/visualize_tree.cpp @@ -415,24 +415,29 @@ string pass::VisualizeTree::get_attributes(shared_ptr node) stringstream label; label << "label=\"" << get_node_name(node); - static const bool nvtos = true; - static const bool nvtot = true; + static const bool nvtos = getenv_bool("NGRAPH_VISUALIZE_TREE_OUTPUT_SHAPES"); + static const bool nvtot = getenv_bool("NGRAPH_VISUALIZE_TREE_OUTPUT_TYPES"); + static const bool nvtio = getenv_bool("NGRAPH_VISUALIZE_TREE_IO"); - if (nvtos || nvtot) + if (nvtos || nvtot || nvtio) { - for (const auto& input : node->inputs()) + if (nvtio) { - label << "\\nin" << to_string(input.get_index()) << ": "; - if (nvtot) - label << "{" << input.get_element_type().get_type_name() << "}"; - if (nvtos) - label << pretty_partial_shape(input.get_partial_shape()); - label << ": " << node->get_input_node_ptr(input.get_index())->get_name() << ": out" - << input.get_source_output().get_index(); + for (const auto& input : node->inputs()) + { + label << "\\nin" << to_string(input.get_index()) << ": "; + if (nvtot) + label << "{" << input.get_element_type().get_type_name() << "}"; + if (nvtos) + label << pretty_partial_shape(input.get_partial_shape()); + label << ": " << node->get_input_node_ptr(input.get_index())->get_name() << ": out" + << input.get_source_output().get_index(); + } } for (const auto& output : node->outputs()) { - label << "\\nout" << to_string(output.get_index()) << ": "; + if (nvtio) + label << "\\nout" << to_string(output.get_index()) << ": "; if (nvtot) label << "{" << output.get_element_type().get_type_name() << "}"; if (nvtos) @@ -468,13 +473,18 @@ string pass::VisualizeTree::get_node_name(shared_ptr node) rc += "\\n" + node->get_name(); } rc += "\\n" + std::string(node->get_type_name()); - const auto rt = node->get_rt_info(); - if (!rt.empty()) + + static const bool nvtrti = getenv_bool("NGRAPH_VISUALIZE_TREE_RUNTIME_INFO"); + if (nvtrti) { - rc += "\\nrt info: "; - for (const auto& item : rt) + const auto rt = node->get_rt_info(); + if (!rt.empty()) { - rc += item.first + " "; + rc += "\\nrt info: "; + for (const auto& item : rt) + { + rc += item.first + " "; + } } } return rc; From e29b505b8ac23d33464b30104301c51e6c951f53 Mon Sep 17 00:00:00 2001 From: Edward Shogulin Date: Sun, 20 Sep 2020 13:30:34 +0300 Subject: [PATCH 57/64] [LPT] FakeQuantizeDequantization extending: check element wise dequantization operation --- .../common/fake_quantize_dequantization.hpp | 1 + .../low_precision/common/ie_lpt_exception.hpp | 2 ++ .../common/fake_quantize_dequantization.cpp | 29 ++++++++++++++++++- 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/inference-engine/src/transformations/include/transformations/low_precision/common/fake_quantize_dequantization.hpp b/inference-engine/src/transformations/include/transformations/low_precision/common/fake_quantize_dequantization.hpp index 0edc8ef1056da3..87a4dabb45385d 100644 --- a/inference-engine/src/transformations/include/transformations/low_precision/common/fake_quantize_dequantization.hpp +++ b/inference-engine/src/transformations/include/transformations/low_precision/common/fake_quantize_dequantization.hpp @@ -28,6 +28,7 @@ class FakeQuantizeDequantization { bool empty() const; bool isShared() const; bool isLowPrecision() const; + static bool checkElementwise(const std::shared_ptr& elementwise); Output data; std::shared_ptr convert; diff --git a/inference-engine/src/transformations/include/transformations/low_precision/common/ie_lpt_exception.hpp b/inference-engine/src/transformations/include/transformations/low_precision/common/ie_lpt_exception.hpp index e1fbc36dd61633..a426b2b8fe0e6d 100644 --- a/inference-engine/src/transformations/include/transformations/low_precision/common/ie_lpt_exception.hpp +++ b/inference-engine/src/transformations/include/transformations/low_precision/common/ie_lpt_exception.hpp @@ -4,8 +4,10 @@ #pragma once +#include #include #include +#include /** * @def THROW_TRANSFORMATION_EXCEPTION_LPT diff --git a/inference-engine/src/transformations/src/transformations/low_precision/common/fake_quantize_dequantization.cpp b/inference-engine/src/transformations/src/transformations/low_precision/common/fake_quantize_dequantization.cpp index 2e9ba9c72dbe57..d0ac228855596b 100644 --- a/inference-engine/src/transformations/src/transformations/low_precision/common/fake_quantize_dequantization.cpp +++ b/inference-engine/src/transformations/src/transformations/low_precision/common/fake_quantize_dequantization.cpp @@ -2,9 +2,10 @@ // SPDX-License-Identifier: Apache-2.0 // -#include +#include "transformations/low_precision/common/fake_quantize_dequantization.hpp" #include #include +#include "transformations/low_precision/common/ie_lpt_exception.hpp" namespace ngraph { namespace pass { @@ -47,6 +48,32 @@ bool FakeQuantizeDequantization::isLowPrecision() const { return (data.get_element_type() == element::i8) || (data.get_element_type() == element::u8); } +bool FakeQuantizeDequantization::checkElementwise(const std::shared_ptr& dequantizationElementwise) { + const ngraph::PartialShape partialShape = dequantizationElementwise->get_input_partial_shape(1); + if (partialShape.is_dynamic()) { + return false; + } + + std::shared_ptr constant = as_type_ptr(dequantizationElementwise->get_input_node_shared_ptr(1)); + if (constant == nullptr) { + THROW_IE_LPT_EXCEPTION(*dequantizationElementwise) << "unexpected operation type " << + dequantizationElementwise->get_type_info().name << " on the second branch"; + } + + const ngraph::Shape constShape = constant->get_output_shape(0); + if ((constShape.size() > 5ul)) { + return false; + } + + for (size_t i = 1ul; i < constShape.size(); ++i) { + if (constShape[i] != 1ul) { + return false; + } + } + + return true; +} + } // namespace low_precision } // namespace pass } // namespace ngraph From 4c600dc013d900c6e31a959f4c682ee6f7b2b0ae Mon Sep 17 00:00:00 2001 From: Edward Shogulin Date: Sun, 20 Sep 2020 15:31:44 +0300 Subject: [PATCH 58/64] [LPT] FakeQuantizeDequantization extending: SubtractMultiplyToMultiplyAddTransformation & WeightableLayerTransformation --- .../common/fake_quantize_dequantization.cpp | 27 +++++++++++-- .../subtract_multiply_to_multiply_add.cpp | 33 ++-------------- .../weightable_layer_transformation.cpp | 24 ++++-------- ...ultiply_to_multiply_add_transformation.cpp | 38 ++++++++++++++++++- 4 files changed, 71 insertions(+), 51 deletions(-) diff --git a/inference-engine/src/transformations/src/transformations/low_precision/common/fake_quantize_dequantization.cpp b/inference-engine/src/transformations/src/transformations/low_precision/common/fake_quantize_dequantization.cpp index d0ac228855596b..f61e61ccdb34cb 100644 --- a/inference-engine/src/transformations/src/transformations/low_precision/common/fake_quantize_dequantization.cpp +++ b/inference-engine/src/transformations/src/transformations/low_precision/common/fake_quantize_dequantization.cpp @@ -49,7 +49,7 @@ bool FakeQuantizeDequantization::isLowPrecision() const { } bool FakeQuantizeDequantization::checkElementwise(const std::shared_ptr& dequantizationElementwise) { - const ngraph::PartialShape partialShape = dequantizationElementwise->get_input_partial_shape(1); + const ngraph::PartialShape partialShape = dequantizationElementwise->get_input_partial_shape(0); if (partialShape.is_dynamic()) { return false; } @@ -65,10 +65,31 @@ bool FakeQuantizeDequantization::checkElementwise(const std::shared_ptr op) const { FakeQuantizeDequantization dequantization = get(op); - if (dequantization.empty() || - (dequantization.multiply == nullptr) || - is_type(dequantization.data.get_node_shared_ptr())) { + if (dequantization.empty() || (dequantization.multiply == nullptr) || is_type(dequantization.data.get_node_shared_ptr())) { return false; } @@ -160,34 +158,9 @@ bool SubtractMultiplyToMultiplyAddTransformation::canBeTransformed(const Transfo return false; } - // TODO: check if Convert & Subtract & Multiply are LPT dequantization operations - - if (op->get_output_shape(0).size() < 4ul) { - return false; - } - - // TODO: check if dequantization operations have appropriate Shape for ScaleShift - auto isSupportedByScaleShift = [](const std::shared_ptr eltwise) -> bool { - const ngraph::PartialShape constPartialShape = eltwise->get_input_partial_shape(1); - if (constPartialShape.is_dynamic()) { - return false; - } - - const ngraph::Shape constShape = constPartialShape.to_shape(); - if ((constShape.size() == 0ul) || (constShape.size() == 1ul)) { - return true; - } - - if (constShape.size() < 4ul) { - return false; - } - - return shape_size(constShape) == constShape[1]; - }; - return - ((dequantization.subtract == nullptr) || isSupportedByScaleShift(dequantization.subtract)) && - isSupportedByScaleShift(dequantization.multiply); + ((dequantization.subtract == nullptr) || FakeQuantizeDequantization::checkElementwise(dequantization.subtract)) && + FakeQuantizeDequantization::checkElementwise(dequantization.multiply); } bool SubtractMultiplyToMultiplyAddTransformation::isPrecisionPreserved(std::shared_ptr layer) const noexcept { diff --git a/inference-engine/src/transformations/src/transformations/low_precision/weightable_layer_transformation.cpp b/inference-engine/src/transformations/src/transformations/low_precision/weightable_layer_transformation.cpp index 6adda552d63b0a..06ff627ea25da0 100644 --- a/inference-engine/src/transformations/src/transformations/low_precision/weightable_layer_transformation.cpp +++ b/inference-engine/src/transformations/src/transformations/low_precision/weightable_layer_transformation.cpp @@ -22,31 +22,23 @@ bool WeightableLayerTransformation::canBeTransformed(const TransformationContext } if (isGroup(layer)) { - FakeQuantizeDequantization dequantization = NetworkHelper::getDequantization(layer); + const FakeQuantizeDequantization dequantization = NetworkHelper::getDequantization(layer); if (dequantization.empty()) { return false; } - std::shared_ptr multiplyConst = as_type_ptr(dequantization.multiply->get_input_node_shared_ptr(1)); - const ngraph::Shape constShape = multiplyConst->get_output_shape(0); - if ((constShape.size() != 0) && (constShape.size() != 1ul) && (constShape.size() != 3ul) && (constShape.size() != 4ul)) { + if ((dequantization.multiply != nullptr) && !FakeQuantizeDequantization::checkElementwise(dequantization.multiply)) { return false; } - const ngraph::Shape inputShape = layer->get_input_shape(0); - - const std::vector scales = multiplyConst->cast_vector(); - if (scales.size() != 1ul) { - if ((scales.size() != 1) && (scales.size() != inputShape[1])) { - return false; - } - - if ((inputShape.size() != 4ul) && (inputShape.size() != 5ul)) { - return false; - } - + const std::shared_ptr multiplyConst = as_type_ptr(dequantization.multiply->get_input_node_shared_ptr(1)); + const Shape multiplyConstShape = multiplyConst->get_output_shape(0); + if (!multiplyConstShape.empty() && (multiplyConstShape.size() != 1ul)) { const size_t groupsCount = NetworkHelper::getGroupsCount(layer); + const ngraph::Shape inputShape = layer->get_input_shape(0); const size_t inputChannelsInGroup = inputShape[1] / groupsCount; + + const std::vector scales = multiplyConst->cast_vector(); for (size_t group = 0; group < groupsCount; ++group) { for (size_t i = 0; i < inputChannelsInGroup; ++i) { size_t index = group * inputChannelsInGroup + i; diff --git a/inference-engine/tests/functional/inference_engine/lp_transformations/subtract_multiply_to_multiply_add_transformation.cpp b/inference-engine/tests/functional/inference_engine/lp_transformations/subtract_multiply_to_multiply_add_transformation.cpp index b7d2078758aee2..9aeacf1b575fd2 100644 --- a/inference-engine/tests/functional/inference_engine/lp_transformations/subtract_multiply_to_multiply_add_transformation.cpp +++ b/inference-engine/tests/functional/inference_engine/lp_transformations/subtract_multiply_to_multiply_add_transformation.cpp @@ -107,7 +107,7 @@ const std::vector testVal LayerTransformation::createParamsU8I8(), { ngraph::element::f32, - {{ngraph::element::f32}, {}, {0.1f}}, + {{}, {}, {0.1f}}, ngraph::element::f32, }, { @@ -124,7 +124,7 @@ const std::vector testVal LayerTransformation::createParamsU8I8(), { ngraph::element::f32, - {{ngraph::element::f32}, {}, {{0.1f, 0.2f, 0.3f}}}, + {{}, {}, {{0.1f, 0.2f, 0.3f}}}, ngraph::element::f32, }, { @@ -237,6 +237,40 @@ const std::vector testVal {} }, }, + // FP32 Multiply {5x1x1} -> Multiply + Subtract {1x5x1x1} + { + {2, 5, 4, 4}, + LayerTransformation::createParamsU8I8(), + { + ngraph::element::f32, + {{}, {}, {{0.1f, 0.2f, 0.3f, 0.4f, 0.5f}, ngraph::element::f32, {5, 1, 1}}}, + ngraph::element::f32, + }, + { + ngraph::element::f32, + {}, + ngraph::element::f32, + {{0.1f, 0.2f, 0.3f, 0.4f, 0.5f}, {ngraph::element::f32}, {5, 1, 1}}, + {{0.f}, {ngraph::element::f32}} + }, + }, + // FP32 Multiply {5x1x2} + { + {2, 5, 2, 2}, + LayerTransformation::createParamsU8I8(), + { + ngraph::element::f32, + {{}, {}, {{0.1f, 0.2f, 0.3f, 0.4f, 0.5f, 0.6f, 0.7f, 0.8f, 0.9f, 1.f}, ngraph::element::f32, {5, 1, 2}}}, + ngraph::element::f32, + }, + { + ngraph::element::f32, + {{}, {}, {{0.1f, 0.2f, 0.3f, 0.4f, 0.5f, 0.6f, 0.7f, 0.8f, 0.9f, 1.f}, ngraph::element::f32, {5, 1, 2}}}, + ngraph::element::f32, + {}, + {} + }, + }, }; INSTANTIATE_TEST_CASE_P( From 51ef2b23094bfc6e0c2e5a47510c3051d60263a6 Mon Sep 17 00:00:00 2001 From: Edward Shogulin Date: Sun, 20 Sep 2020 16:33:55 +0300 Subject: [PATCH 59/64] [LPT] Convolution + test infrastructure update --- .../multiply_to_group_convolution.cpp | 10 ++-- .../layer_transformation.cpp | 20 ++++++-- .../layer_transformation.cpp | 49 ++++++++++++++++--- .../convolution_transformation.cpp | 6 ++- 4 files changed, 67 insertions(+), 18 deletions(-) diff --git a/inference-engine/src/transformations/src/transformations/low_precision/multiply_to_group_convolution.cpp b/inference-engine/src/transformations/src/transformations/low_precision/multiply_to_group_convolution.cpp index 3cf7dfe59151cf..6717e7452d63ae 100644 --- a/inference-engine/src/transformations/src/transformations/low_precision/multiply_to_group_convolution.cpp +++ b/inference-engine/src/transformations/src/transformations/low_precision/multiply_to_group_convolution.cpp @@ -39,13 +39,12 @@ bool MultiplyToGroupConvolutionTransformation::transform(TransformationContext& const size_t group = outputChannelsCount / groupSize; const size_t weightsSize = outputChannelsCount * inputChannelsCount / group; std::vector weightsBuffer(weightsSize); - std::vector weightsOriginalShiftsBlobBuffer = as_type_ptr(constant)->cast_vector(); const size_t kernelsCount = inputChannelsCount / group; if (group == 1ul) { for (size_t outputChannel = 0ul; outputChannel < outputChannelsCount; ++outputChannel) { for (size_t kernel = 0ul; kernel < kernelsCount; ++kernel) { - const float value = (outputChannel == kernel) ? (updatePrecisions ? 1.f : weightsOriginalShiftsBlobBuffer[outputChannel]) : 0.f; + const float value = (outputChannel == kernel) ? 1.f : 0.f; weightsBuffer[kernelsCount * outputChannel + kernel] = value; } } @@ -55,8 +54,7 @@ bool MultiplyToGroupConvolutionTransformation::transform(TransformationContext& const size_t groupIndex = outputChannel / channelsInGroup; for (size_t kernel = 0ul; kernel < kernelsCount; ++kernel) { const size_t outputChannelIndexInGroup = outputChannel - groupIndex * channelsInGroup; - const float value = (outputChannelIndexInGroup == kernel) ? - (updatePrecisions ? 1.f : weightsOriginalShiftsBlobBuffer[outputChannel]) : 0.f; + const float value = (outputChannelIndexInGroup == kernel) ? 1.f : 0.f; weightsBuffer[kernelsCount * outputChannel + kernel] = value; } } @@ -94,9 +92,7 @@ bool MultiplyToGroupConvolutionTransformation::transform(TransformationContext& lastNode->set_friendly_name(dequantization.subtract->get_friendly_name()); } - if (updatePrecisions) { - lastNode = multiply->copy_with_new_inputs({ lastNode, constant }); - } + lastNode = multiply->copy_with_new_inputs({ lastNode, constant }); replace_node(multiply, lastNode); NetworkHelper::copyInfo(multiply, lastNode); diff --git a/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/low_precision_transformations/layer_transformation.cpp b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/low_precision_transformations/layer_transformation.cpp index e4876ca655ab7d..37efd4f34443f1 100644 --- a/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/low_precision_transformations/layer_transformation.cpp +++ b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/low_precision_transformations/layer_transformation.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include "ngraph_ops/fully_connected.hpp" #include #include @@ -165,10 +166,21 @@ std::shared_ptr LayerTransformation::transformNGraph( return fc_op->input_value(0).get_shape().size() == 3ul; } - return std::dynamic_pointer_cast(node) || - std::dynamic_pointer_cast(node) || - std::dynamic_pointer_cast(node) || - std::dynamic_pointer_cast(node); + if (auto add_op = std::dynamic_pointer_cast(node)) { + return ngraph::is_type(add_op->get_input_node_shared_ptr(0)) || + ngraph::is_type(add_op->get_input_node_shared_ptr(0)) || + ngraph::is_type(add_op->get_input_node_shared_ptr(0)); + } + + return std::dynamic_pointer_cast(node) || + std::dynamic_pointer_cast(node) || + std::dynamic_pointer_cast(node) || + std::dynamic_pointer_cast(node) || + std::dynamic_pointer_cast(node) || + std::dynamic_pointer_cast(node) || + std::dynamic_pointer_cast(node) || + std::dynamic_pointer_cast(node) || + std::dynamic_pointer_cast(node); }; ngraph::pass::Manager manager; diff --git a/inference-engine/tests/functional/plugin/gpu/shared_tests_instances/low_precision_transformations/layer_transformation.cpp b/inference-engine/tests/functional/plugin/gpu/shared_tests_instances/low_precision_transformations/layer_transformation.cpp index 0bac2ac8a3beac..fa12485462d746 100644 --- a/inference-engine/tests/functional/plugin/gpu/shared_tests_instances/low_precision_transformations/layer_transformation.cpp +++ b/inference-engine/tests/functional/plugin/gpu/shared_tests_instances/low_precision_transformations/layer_transformation.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include "ngraph_ops/fully_connected.hpp" #include #include @@ -71,21 +72,57 @@ std::shared_ptr convert(std::shared_ptr clonedNetwork = InferenceEngine::cloneNetwork(net1); if (clonedNetwork->getFunction()) { const auto transformations_callback = [](const std::shared_ptr &node) -> bool { - // DepthToSpace node implementation supports only equal input/output tensors with rank <= 5 // Reshape->Permute->Reshape pattern in theory can change output rank, so this check is added to be sure - // that DepthToSpace impl will handle fused case + // that the following primitives will be handled correctly + // DepthToSpace node implementation supports only equal input/output tensors with rank <= 5 if (auto dtsOp = std::dynamic_pointer_cast(node)) { return dtsOp->input_value(0).get_shape().size() <= 5lu && dtsOp->input_value(0).get_shape().size() == dtsOp->get_output_shape(0).size(); } - // TODO: absent in GPU plugin - if (auto fc_op = std::dynamic_pointer_cast(node)) { - return fc_op->input_value(0).get_shape().size() == 3ul; + // SpaceToDepth node implementation supports only equal input/output tensors with rank <= 5 + if (auto stdOp = std::dynamic_pointer_cast(node)) { + return stdOp->input_value(0).get_shape().size() <= 5lu && stdOp->input_value(0).get_shape().size() == stdOp->get_output_shape(0).size(); + } + + // Reduce node implementation with reduce along features performs better with Reshape->Pooling->Reshape pattern + // Reshape->Pooling->Reshape scenario is also more optimal in case when batch > 1 and network precission is FP16 + if (auto redOp = std::dynamic_pointer_cast(node)) { + auto reduction_axes = redOp->get_reduction_axes().to_vector(); + bool reduce_along_f = redOp->get_reduction_axes().size() == 1 && std::count(reduction_axes.begin(), reduction_axes.end(), 1) != 0; + bool fp16_batch_not_1 = redOp->get_element_type() == ngraph::element::f16 && redOp->input(0).get_shape()[0] != 1; + bool can_use_reduce = !reduce_along_f && !fp16_batch_not_1; + return can_use_reduce; + } + if (auto redOp = std::dynamic_pointer_cast(node)) { + auto reduction_axes = redOp->get_reduction_axes().to_vector(); + bool reduce_along_f = redOp->get_reduction_axes().size() == 1 && std::count(reduction_axes.begin(), reduction_axes.end(), 1) != 0; + bool fp16_batch_not_1 = redOp->get_element_type() == ngraph::element::f16 && redOp->input(0).get_shape()[0] != 1; + bool can_use_reduce = !reduce_along_f && !fp16_batch_not_1; + return can_use_reduce; + } + if (auto redOp = std::dynamic_pointer_cast(node)) { + auto reduction_axes = redOp->get_reduction_axes().to_vector(); + bool reduce_along_f = redOp->get_reduction_axes().size() == 1 && std::count(reduction_axes.begin(), reduction_axes.end(), 1) != 0; + bool fp16_batch_not_1 = redOp->get_element_type() == ngraph::element::f16 && redOp->input(0).get_shape()[0] != 1; + bool can_use_reduce = !reduce_along_f && !fp16_batch_not_1; + return can_use_reduce; + } + + if (auto add_op = std::dynamic_pointer_cast(node)) { + return ngraph::is_type(add_op->get_input_node_shared_ptr(0)) || + ngraph::is_type(add_op->get_input_node_shared_ptr(0)) || + ngraph::is_type(add_op->get_input_node_shared_ptr(0)); } return std::dynamic_pointer_cast(node) || std::dynamic_pointer_cast(node) || - std::dynamic_pointer_cast(node); + std::dynamic_pointer_cast(node) || + std::dynamic_pointer_cast(node) || + std::dynamic_pointer_cast(node) || + std::dynamic_pointer_cast(node) || + std::dynamic_pointer_cast(node) || + std::dynamic_pointer_cast(node) || + std::dynamic_pointer_cast(node); }; auto nGraphFunc = clonedNetwork->getFunction(); // Disable shape inference (WA for generic operations) diff --git a/inference-engine/tests/functional/plugin/shared/src/low_precision_transformations/convolution_transformation.cpp b/inference-engine/tests/functional/plugin/shared/src/low_precision_transformations/convolution_transformation.cpp index 65a72830c1dd4f..ad2ccad3e31ba1 100644 --- a/inference-engine/tests/functional/plugin/shared/src/low_precision_transformations/convolution_transformation.cpp +++ b/inference-engine/tests/functional/plugin/shared/src/low_precision_transformations/convolution_transformation.cpp @@ -118,7 +118,11 @@ void ConvolutionTransformation::validateNGraph() { ASSERT_FALSE(parent == nullptr); const std::string typeName = parent->get_type_name(); - ASSERT_TRUE(typeName == "PowerIE" || typeName == "ConvolutionIE"); + if (param.fakeQuantizeOnData.empty() || param.fakeQuantizeOnWeights.empty()) { + ASSERT_EQ("ConvolutionIE", typeName); + } else { + ASSERT_EQ("ScaleShiftIE", typeName); + } } TEST_P(ConvolutionTransformation, CompareWithRefImpl) { From 0c0ed09e140af38b8b692fee0ab87082df9cfaa5 Mon Sep 17 00:00:00 2001 From: Edward Shogulin Date: Sun, 20 Sep 2020 20:53:58 +0300 Subject: [PATCH 60/64] [LPT] GPU compilation error --- inference-engine/src/cldnn_engine/cldnn_engine.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/inference-engine/src/cldnn_engine/cldnn_engine.cpp b/inference-engine/src/cldnn_engine/cldnn_engine.cpp index aca044a9a4658c..6e68dcf53ed91e 100644 --- a/inference-engine/src/cldnn_engine/cldnn_engine.cpp +++ b/inference-engine/src/cldnn_engine/cldnn_engine.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #include #include @@ -137,6 +138,9 @@ InferenceEngine::ICNNNetwork::Ptr clDNNEngine::CloneAndTransformNetwork(const In // Disable shape inference (WA for generic operations) ::ngraph::op::GenericIE::DisableReshape noReshape(nGraphFunc); + CLDNNPlugin::Config config = _impl->m_config; + const bool enableInt8 = config.enableInt8 && (config.lptVersion == Config::LptVersion::nGraph); + { // Note: instead of running all Conversion Transformations you can make up your own transformation pipeline ngraph::pass::Manager manager; @@ -147,8 +151,10 @@ InferenceEngine::ICNNNetwork::Ptr clDNNEngine::CloneAndTransformNetwork(const In manager.register_pass(); manager.register_pass(); - // [WA part1] Convert quantized FP16 model to FP32 to avoid possible overflow and mixed precision errors - manager.register_pass(ngraph::element::f16, ngraph::element::f32); + if (enableInt8) { + // [WA part1] Convert quantized FP16 model to FP32 to avoid possible overflow and mixed precision errors + manager.register_pass(ngraph::element::f16, ngraph::element::f32); + } manager.set_callback(transformations_callback); manager.run_passes(nGraphFunc); @@ -161,10 +167,8 @@ InferenceEngine::ICNNNetwork::Ptr clDNNEngine::CloneAndTransformNetwork(const In ti_manager.run_passes(nGraphFunc); } - CLDNNPlugin::Config config = _impl->m_config; - using namespace ngraph::pass::low_precision; - if (config.enableInt8 && (config.lptVersion == Config::LptVersion::nGraph)) { + if (enableInt8) { auto params = LayerTransformation::Params( true, // updatePrecisions LayerTransformation::QuantizedTensorAlignment::UpdateLevel, // quantizedTensorAlignmentOnActivations From 292b9eee2a762653a740972e398f06afd11c2421 Mon Sep 17 00:00:00 2001 From: Edward Shogulin Date: Sun, 20 Sep 2020 22:42:23 +0300 Subject: [PATCH 61/64] [nGraph] BatchNorm plugin tests: input tensor definition --- .../plugin/shared/include/single_layer_tests/batch_norm.hpp | 4 +++- .../plugin/shared/src/single_layer_tests/batch_norm.cpp | 6 +++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/inference-engine/tests/functional/plugin/shared/include/single_layer_tests/batch_norm.hpp b/inference-engine/tests/functional/plugin/shared/include/single_layer_tests/batch_norm.hpp index ced8a2e40c0908..9c1cf1c5502a4c 100644 --- a/inference-engine/tests/functional/plugin/shared/include/single_layer_tests/batch_norm.hpp +++ b/inference-engine/tests/functional/plugin/shared/include/single_layer_tests/batch_norm.hpp @@ -21,8 +21,10 @@ class BatchNormLayerTest : public testing::WithParamInterface& obj); + InferenceEngine::Blob::Ptr GenerateInput(const InferenceEngine::InputInfo &info) const override; + protected: void SetUp() override; }; -} // namespace LayerTestsDefinitions \ No newline at end of file +} // namespace LayerTestsDefinitions diff --git a/inference-engine/tests/functional/plugin/shared/src/single_layer_tests/batch_norm.cpp b/inference-engine/tests/functional/plugin/shared/src/single_layer_tests/batch_norm.cpp index 76c52558bc1039..4ce62636070322 100644 --- a/inference-engine/tests/functional/plugin/shared/src/single_layer_tests/batch_norm.cpp +++ b/inference-engine/tests/functional/plugin/shared/src/single_layer_tests/batch_norm.cpp @@ -21,6 +21,10 @@ std::string BatchNormLayerTest::getTestCaseName(const testing::TestParamInfo Date: Sun, 20 Sep 2020 22:43:44 +0300 Subject: [PATCH 62/64] [LPT] LowPrecisionTransformer::isFunctionQuantized was added --- .../low_precision/transformer.hpp | 2 ++ .../low_precision/transformer.cpp | 25 +++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/inference-engine/src/transformations/include/transformations/low_precision/transformer.hpp b/inference-engine/src/transformations/include/transformations/low_precision/transformer.hpp index ff948dc7ade9db..e62c1c48897c47 100644 --- a/inference-engine/src/transformations/include/transformations/low_precision/transformer.hpp +++ b/inference-engine/src/transformations/include/transformations/low_precision/transformer.hpp @@ -173,6 +173,8 @@ class TRANSFORMATIONS_API LowPrecisionTransformer : public IParamsManager, ILaye public: static LowPrecisionTransformations getAllTransformations(const LayerTransformation::Params& params = LayerTransformation::Params()); + static bool isFunctionQuantized(const std::shared_ptr& function); + LowPrecisionTransformer(); LowPrecisionTransformer(const LowPrecisionTransformations& transformations); void transform(std::shared_ptr network); diff --git a/inference-engine/src/transformations/src/transformations/low_precision/transformer.cpp b/inference-engine/src/transformations/src/transformations/low_precision/transformer.cpp index b0843fd87ba218..bd04151a5646b5 100644 --- a/inference-engine/src/transformations/src/transformations/low_precision/transformer.cpp +++ b/inference-engine/src/transformations/src/transformations/low_precision/transformer.cpp @@ -259,6 +259,27 @@ LowPrecisionTransformations LowPrecisionTransformer::getAllTransformations(const return transformer; } +bool LowPrecisionTransformer::isFunctionQuantized(const std::shared_ptr& function) { + std::deque> nodes; + for (auto result : function->get_results()) { + nodes.push_front(result); + } + + while (!nodes.empty()) { + auto node = nodes.front(); + nodes.pop_front(); + + for (size_t i = 0; i < node->inputs().size(); ++i) { + auto parent = node->get_input_node_shared_ptr(i); + if (is_type(parent)) { + return true; + } + nodes.push_front(parent); + } + } + return false; +} + LowPrecisionTransformer::LowPrecisionTransformer(): transformations(LowPrecisionTransformer::getAllTransformations()) {} template @@ -319,6 +340,10 @@ LowPrecisionTransformer::LowPrecisionTransformer(const LowPrecisionTransformatio : transformations(transformations) {} void LowPrecisionTransformer::transform(std::shared_ptr network) { + if (!isFunctionQuantized(network)) { + return; + } + transformations.setParamsManager(this); transformations.setLayerTransformationsManager(this); From 143673a3e25e2dd0300fae675465cdaa5f41a518 Mon Sep 17 00:00:00 2001 From: Edward Shogulin Date: Mon, 21 Sep 2020 00:19:34 +0300 Subject: [PATCH 63/64] [nGraph] WA final cleanup --- .../include/ngraph_ops/convolution_ie.hpp | 5 ++-- .../include/ngraph_ops/power.hpp | 4 --- .../include/ngraph_ops/scaleshift.hpp | 6 ++--- .../src/ngraph_ops/convolution_ie.cpp | 4 +-- .../transformations/src/ngraph_ops/power.cpp | 6 ----- .../src/ngraph_ops/scaleshift.cpp | 25 +------------------ ngraph/core/include/ngraph/node.hpp | 9 +++---- 7 files changed, 11 insertions(+), 48 deletions(-) diff --git a/inference-engine/src/transformations/include/ngraph_ops/convolution_ie.hpp b/inference-engine/src/transformations/include/ngraph_ops/convolution_ie.hpp index c49418cb367438..9dd5feb3164ce4 100644 --- a/inference-engine/src/transformations/include/ngraph_ops/convolution_ie.hpp +++ b/inference-engine/src/transformations/include/ngraph_ops/convolution_ie.hpp @@ -62,7 +62,7 @@ class TRANSFORMATIONS_API ConvolutionIE : public Op { const size_t& group = 1, const PadType& auto_pad = PadType::EXPLICIT); -#ifdef LPT_SUPPORT + // KMB compilation support ConvolutionIE(const Output& data_batch, const Output& filters, const Strides& strides, @@ -72,6 +72,7 @@ class TRANSFORMATIONS_API ConvolutionIE : public Op { const size_t& group = 1, const PadType& auto_pad = PadType::EXPLICIT); + // KMB compilation support ConvolutionIE(const Output& data_batch, const Output& filters, const Output& bias, @@ -81,7 +82,7 @@ class TRANSFORMATIONS_API ConvolutionIE : public Op { const CoordinateDiff& pads_end, const size_t& group = 1, const PadType& auto_pad = PadType::EXPLICIT); -#endif + void validate_and_infer_types() override; diff --git a/inference-engine/src/transformations/include/ngraph_ops/power.hpp b/inference-engine/src/transformations/include/ngraph_ops/power.hpp index 96ae703a7be4b8..588f82ed59abdb 100644 --- a/inference-engine/src/transformations/include/ngraph_ops/power.hpp +++ b/inference-engine/src/transformations/include/ngraph_ops/power.hpp @@ -25,10 +25,6 @@ class TRANSFORMATIONS_API PowerIE : public Op { std::shared_ptr clone_with_new_inputs(const OutputVector& new_args) const override; - void set_output_type(size_t i, - const element::Type& element_type, - const PartialShape& pshape) override; - float scale, power, shift; private: diff --git a/inference-engine/src/transformations/include/ngraph_ops/scaleshift.hpp b/inference-engine/src/transformations/include/ngraph_ops/scaleshift.hpp index 21f9e5f5aa6028..0a7c5fed1e6103 100644 --- a/inference-engine/src/transformations/include/ngraph_ops/scaleshift.hpp +++ b/inference-engine/src/transformations/include/ngraph_ops/scaleshift.hpp @@ -25,11 +25,9 @@ class TRANSFORMATIONS_API ScaleShiftIE : public Op { void validate_and_infer_types() override; - void set_output_type(size_t i, - const element::Type& element_type, - const PartialShape& pshape) override; - std::shared_ptr clone_with_new_inputs(const OutputVector& new_args) const override; + +private: element::Type output_type; }; diff --git a/inference-engine/src/transformations/src/ngraph_ops/convolution_ie.cpp b/inference-engine/src/transformations/src/ngraph_ops/convolution_ie.cpp index 6e9e7a6a90e019..43e8db7e2d99c7 100644 --- a/inference-engine/src/transformations/src/ngraph_ops/convolution_ie.cpp +++ b/inference-engine/src/transformations/src/ngraph_ops/convolution_ie.cpp @@ -57,7 +57,7 @@ op::ConvolutionIE::ConvolutionIE(const Output& data_batch, constructor_validate_and_infer_types(); } -#ifdef LPT_SUPPORT +// KMB compilation support op::ConvolutionIE::ConvolutionIE(const Output& data_batch, const Output& filters, const Strides& strides, @@ -77,6 +77,7 @@ op::ConvolutionIE::ConvolutionIE(const Output& data_batch, constructor_validate_and_infer_types(); } +// KMB compilation support op::ConvolutionIE::ConvolutionIE(const Output& data_batch, const Output& filters, const Output& bias, @@ -96,7 +97,6 @@ op::ConvolutionIE::ConvolutionIE(const Output& data_batch, , m_output_type(element::undefined) { constructor_validate_and_infer_types(); } -#endif void op::ConvolutionIE::validate_and_infer_types() { PartialShape data_batch_shape = get_input_partial_shape(0); diff --git a/inference-engine/src/transformations/src/ngraph_ops/power.cpp b/inference-engine/src/transformations/src/ngraph_ops/power.cpp index 618d6509958051..1b3b3be4e79c60 100644 --- a/inference-engine/src/transformations/src/ngraph_ops/power.cpp +++ b/inference-engine/src/transformations/src/ngraph_ops/power.cpp @@ -27,12 +27,6 @@ std::shared_ptr op::PowerIE::clone_with_new_inputs(const OutputVector& new return make_shared(new_args.at(0), this->power, this->scale, this->shift, this->m_output_type); } -void op::PowerIE::set_output_type(size_t i, - const element::Type& element_type, - const PartialShape& pshape) { - Op::set_output_type(i, m_output_type == element::undefined ? element_type : m_output_type, pshape); -} - void op::PowerIE::validate_and_infer_types() { set_output_type(0, m_output_type == element::undefined ? get_input_element_type(0) : m_output_type, get_input_partial_shape(0)); } diff --git a/inference-engine/src/transformations/src/ngraph_ops/scaleshift.cpp b/inference-engine/src/transformations/src/ngraph_ops/scaleshift.cpp index d184b7c62b12f2..a5da41c3e43a8b 100644 --- a/inference-engine/src/transformations/src/ngraph_ops/scaleshift.cpp +++ b/inference-engine/src/transformations/src/ngraph_ops/scaleshift.cpp @@ -14,25 +14,8 @@ using namespace ngraph; constexpr NodeTypeInfo op::ScaleShiftIE::type_info; -element::Type getMaxBitwidth(const std::vector& types) { - if (types.empty()) { - return element::undefined; - } - - element::Type maxType = types[0]; - for (size_t i = 1; i < types.size(); ++i) { - if (types[i].bitwidth() > maxType.bitwidth()) { - maxType = types[i]; - } - } - return maxType; -} - op::ScaleShiftIE::ScaleShiftIE(const Output& data_batch, const Output& weights, const Output& bias, const element::Type output_type) : Op({data_batch, weights, bias}), output_type(output_type) { - if (this->output_type == element::undefined) { - this->output_type = getMaxBitwidth({ data_batch.get_element_type(), weights.get_element_type(), bias.get_element_type() }); - } constructor_validate_and_infer_types(); } @@ -46,7 +29,7 @@ std::shared_ptr op::ScaleShiftIE::clone_with_new_inputs(const OutputVector void op::ScaleShiftIE::validate_and_infer_types() { // Check that weights and biases has the same type - element::Type data_et = get_input_element_type(0); + element::Type data_et = output_type == element::undefined ? get_input_element_type(0) : output_type; element::Type weights_et = get_input_element_type(1); element::Type biases_et = get_input_element_type(2); @@ -57,9 +40,3 @@ void op::ScaleShiftIE::validate_and_infer_types() { set_output_type(0, data_et, get_input_partial_shape(0)); } - -void op::ScaleShiftIE::set_output_type(size_t i, - const element::Type& element_type, - const PartialShape& pshape) { - Op::set_output_type(i, output_type == element::undefined ? element_type : output_type, pshape); -} diff --git a/ngraph/core/include/ngraph/node.hpp b/ngraph/core/include/ngraph/node.hpp index 27a193d877f780..31c2ca2e4cc0b7 100644 --- a/ngraph/core/include/ngraph/node.hpp +++ b/ngraph/core/include/ngraph/node.hpp @@ -45,9 +45,6 @@ #include "ngraph/strides.hpp" #include "ngraph/type.hpp" -// turn it off if you are a real Man -#define LPT_SUPPORT - namespace ngraph { template @@ -228,9 +225,9 @@ namespace ngraph /// Sets/replaces the arguments with new arguments. void set_argument(size_t position, const Output& argument); - virtual void set_output_type(size_t i, - const element::Type& element_type, - const PartialShape& pshape); + void set_output_type(size_t i, + const element::Type& element_type, + const PartialShape& pshape); /// Sets the number of outputs void set_output_size(size_t output_size); From 70975d67563c7e010d50ab56bd100e2e740cccb0 Mon Sep 17 00:00:00 2001 From: Edward Shogulin Date: Mon, 21 Sep 2020 00:54:31 +0300 Subject: [PATCH 64/64] [nGraph] ScaleShiftIE quick fix --- .../src/ngraph_ops/scaleshift.cpp | 17 +++++++++++++++++ .../convert_power_to_power_ie.cpp | 4 ++-- .../convert_sqrt_to_power_ie.cpp | 2 +- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/inference-engine/src/transformations/src/ngraph_ops/scaleshift.cpp b/inference-engine/src/transformations/src/ngraph_ops/scaleshift.cpp index a5da41c3e43a8b..93384c741f0963 100644 --- a/inference-engine/src/transformations/src/ngraph_ops/scaleshift.cpp +++ b/inference-engine/src/transformations/src/ngraph_ops/scaleshift.cpp @@ -14,8 +14,25 @@ using namespace ngraph; constexpr NodeTypeInfo op::ScaleShiftIE::type_info; +element::Type getMaxBitwidth(const std::vector& types) { + if (types.empty()) { + return element::undefined; + } + + element::Type maxType = types[0]; + for (size_t i = 1; i < types.size(); ++i) { + if (types[i].bitwidth() > maxType.bitwidth()) { + maxType = types[i]; + } + } + return maxType; +} + op::ScaleShiftIE::ScaleShiftIE(const Output& data_batch, const Output& weights, const Output& bias, const element::Type output_type) : Op({data_batch, weights, bias}), output_type(output_type) { + if (this->output_type == element::undefined) { + this->output_type = getMaxBitwidth({ data_batch.get_element_type(), weights.get_element_type(), bias.get_element_type() }); + } constructor_validate_and_infer_types(); } diff --git a/inference-engine/src/transformations/src/transformations/convert_opset1_to_legacy/convert_power_to_power_ie.cpp b/inference-engine/src/transformations/src/transformations/convert_opset1_to_legacy/convert_power_to_power_ie.cpp index 86b54f348a8f21..23943fdfac55da 100644 --- a/inference-engine/src/transformations/src/transformations/convert_opset1_to_legacy/convert_power_to_power_ie.cpp +++ b/inference-engine/src/transformations/src/transformations/convert_opset1_to_legacy/convert_power_to_power_ie.cpp @@ -33,7 +33,7 @@ ngraph::pass::ConvertPowerToPowerIEMatcher::ConvertPowerToPowerIEMatcher() { return false; } - auto power_ie = std::make_shared(power->input(0).get_source_output(), value, 1, 0); + auto power_ie = std::make_shared(power->input(0).get_source_output(), value, 1, 0, power->output(0).get_element_type()); power_ie->set_friendly_name(power->get_friendly_name()); ngraph::copy_runtime_info(power, power_ie); ngraph::replace_node(power, power_ie); @@ -44,4 +44,4 @@ ngraph::pass::ConvertPowerToPowerIEMatcher::ConvertPowerToPowerIEMatcher() { auto m = std::make_shared(power, "ConvertPowerToPowerIE"); this->register_matcher(m, callback); -} \ No newline at end of file +} diff --git a/inference-engine/src/transformations/src/transformations/convert_opset1_to_legacy/convert_sqrt_to_power_ie.cpp b/inference-engine/src/transformations/src/transformations/convert_opset1_to_legacy/convert_sqrt_to_power_ie.cpp index 2e677ab4e24ac4..78eff529d82fed 100644 --- a/inference-engine/src/transformations/src/transformations/convert_opset1_to_legacy/convert_sqrt_to_power_ie.cpp +++ b/inference-engine/src/transformations/src/transformations/convert_opset1_to_legacy/convert_sqrt_to_power_ie.cpp @@ -25,7 +25,7 @@ ngraph::pass::ConvertSqrtToPowerIEMatcher::ConvertSqrtToPowerIEMatcher() { if (!sqrt) { return false; } - auto power_ie = std::make_shared(sqrt->input(0).get_source_output(), 0.5f, 1, 0); + auto power_ie = std::make_shared(sqrt->input(0).get_source_output(), 0.5f, 1, 0, sqrt->output(0).get_element_type()); power_ie->set_friendly_name(sqrt->get_friendly_name()); ngraph::copy_runtime_info(sqrt, power_ie); ngraph::replace_node(sqrt, power_ie);