Files
openvino/ngraph/test/build_graph.cpp

562 lines
22 KiB
C++
Raw Normal View History

// Copyright (C) 2018-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include "gtest/gtest.h"
#include "ngraph/builder/autobroadcast.hpp"
#include "ngraph/file_util.hpp"
#include "ngraph/ngraph.hpp"
#include "ngraph/opsets/opset5.hpp"
#include "ngraph/opsets/opset7.hpp"
#include "util/test_tools.hpp"
#include <memory>
#include <util/type_prop.hpp>
NGRAPH_SUPPRESS_DEPRECATED_START
using namespace std;
using namespace ngraph;
TEST(build_graph, build_simple)
{
// Function with 4 parameters
auto arg0 = make_shared<op::Parameter>(element::f32, Shape{7, 3});
auto arg1 = make_shared<op::Parameter>(element::f32, Shape{3});
auto arg2 = make_shared<op::Parameter>(element::f32, Shape{32, 7});
auto arg3 = make_shared<op::Parameter>(element::f32, Shape{32, 7});
auto broadcast_1 = builder::opset1::make_broadcast(arg3, Shape{10, 32, 7}, AxisSet{0});
auto b1 = builder::opset1::make_broadcast(arg3, Shape{10, 32, 7}, AxisSet{0});
auto dot = make_shared<op::MatMul>(arg2, arg0);
ASSERT_EQ(dot->input_value(0).get_node_shared_ptr(), arg2);
ASSERT_EQ(dot->input_value(1).get_node_shared_ptr(), arg0);
auto cluster_0 = make_shared<Function>(dot, ParameterVector{arg0, arg1, arg2, arg3});
ASSERT_EQ(cluster_0->get_output_op(0)->input_value(0).get_node_shared_ptr(), dot);
}
TEST(build_graph, literal)
{
// float scalar from a float
// auto float0 = FloatConstant::make(3.0);
vector<float> float_t{3.0};
auto float0 = make_shared<op::Constant>(element::f32, Shape{1}, float_t);
ASSERT_EQ(float0->get_vector<float>(), std::vector<float>{3.0});
ASSERT_EQ(float0->get_element_type(), element::f32);
ASSERT_EQ(float0->get_shape(), Shape{1});
auto d = make_shared<op::MatMul>(float0, float0);
ASSERT_EQ(d->input_values().at(0).get_node_shared_ptr(), float0);
ASSERT_EQ(d->input_values().at(1).get_node_shared_ptr(), float0);
vector<int32_t> int32{3};
auto int32_0 = make_shared<op::Constant>(element::i32, Shape{}, int32);
ASSERT_EQ(int32_0->get_vector<int32_t>(), std::vector<int>{3});
ASSERT_EQ(int32_0->get_element_type(), element::i32);
ASSERT_EQ(int32_0->get_shape(), Shape{});
}
TEST(build_graph, tensor)
{
// float scalar from a float
// auto float0 = FloatConstant::make(3.0);
Shape shape{2, 3};
vector<float> float_t(shape_size(shape), 0);
auto float0 = make_shared<op::Constant>(element::f32, shape, float_t);
ASSERT_EQ(float0->get_element_type(), element::f32);
ASSERT_EQ(float0->get_shape(), shape);
Remove opset0 support and undesired passes from Interpreter backend (#1469) * Move evaluate() interface from some OPs to Interpreter * commit * Move shuffle channels reference to OP's evaluate * Add some operations missed in evaluate_node * Fix select references invocation from evaluate_node() * Activation refs (#2) * HardSigmoid * Elu * Selu * Gelu * Move to test runtime * Rollback donwgrade passes delition * Initial batch to space refs * Return opset1_upgrade * WIP: Add space to batch evaluate * Fix space to batch * add evaluates function in evaluates_map (#4) * Add space to batch evaluate * Fix crop in batch to space references * Remove vectors reallocation in evaluates for b2s and s2b * . * Add SpaceToDepth evaluate * Add depth to space evaluate * Remove code duplication depth to space evaluate * Fix some failed layer tests * Ngraph test (#3) * Remove some v0 ops & fix some tests * Fixes BatchNorm * Next * dd * s * Add dot & replace slice refs * d * dkj * Review fixes part 1 * Fixes. Part 2 * Fixes. Part 3 * Enable cells refs in evaluate map * Fix some failed layer tests * Some more fixes * Fix code style (#6) * Tests (#7) * PriorBox * Mod * NormilizeL2 * Update prior_box.hpp * Fix one hot ref call * . * Select (#8) * Select * Fix code style * Fix select messages * ReverseSeq (#9) * ReverseSeq * Select * ExtractImagePatches, Seqence * Fix Code Style * remove extra * Remove etra line@ * Add fake quantize reference * Align convolution layer tests instantiations with updated definition * Disabled some failed LPT tests * Disabled some failed LPT tests * Remove undesired changes * Update unit-test manifests + some code cleanup * Fix code style (#10) * Normalize L2 refs support (from PR #2327) * Fix code style * Apply review comments. Part 1 (#11) * Apply first part of review comments * Update onnx_import.in.cpp * Remove redundant reshape from shuffle_channels evaluate * Decompose GroupConvolution * [IE Ngraph] Fix some operation inheritance (#13) * [IE TESTS] Depth2Space * Space2Depth * ShuffleChannels * Fix ode style * Fix code style * [IE NGraph] Remove decompose op (#14) * . * Fix loosing control dependency in replace_node * Fix loosing control dependency in replace_node * Fix code style * Fix FQ references build on windows * Fix code style * Apply comments (#15) * [Ie Ngraph] Remove using v1::Add * [Ie Ngraph] Remove using v1::Mutliply * [Ie Ngraph] Remove using v1::Subtract * [Ie Ngraph] Remove using v1::Divide * [Ie Ngraph] Remove using v1::Equal * [Ie Ngraph] Remove using v1::Greater * [Ie Ngraph] Remove using v1::Greater_eq * [Ie Ngraph] Remove using v1::Less * [Ie Ngraph] Remove using v1::LessEq * [Ie Ngraph] Remove using operator+ * [Ie Ngraph] Remove using operator/ * [Ie Ngraph] Remove using operator* * [Ie Ngraph] Remove using operator- * Fix code style * Ci (#16) * Fix CentOS compilation * Revert ngraph::op::vo::Multiply removing due to OpenCV * Android fix (#17) * fix failures * Fix code style * Add (#18) * Android fix * Add * Add in opset1 upgrade pass * Add in opset1 upgrade pass * Remove v0::Add, Reverted removing v0::Multiply (#19) * Remove overloaded math operators from PyNgraph * Remove overloaded math operators from PyNgraph * Fix gna tests (#20) * Fix gna tests * Squashed commit of the following: commit 565b504c1cb8d4f21bc0cb45836e9e473a2b871e Author: Alexander Zhogov <alexander.zhogov@intel.com> Date: Tue Oct 13 13:27:34 2020 +0300 GitHub CI: Add files_size.yml (#2570) * GitHub CI: Add files_size.yml * Update job name commit ab0fb298530152f25c7a8c5cc5ee3d6ba03d6516 Author: Vladislav Vinogradov <vlad.vinogradov@intel.com> Date: Tue Oct 13 11:37:30 2020 +0300 [IE][BUILD] Fix C5208 warning under Windows (#2628) * C++ feature in C `typedef struct` code. * The warning can be promoted to error in dependent projects. C5208: unnamed class used in typedef name cannot declare members other than non-static data members, member enumerations, or member classes commit 15a338e89ba9336038e836c7fb086cdd4fed1d7a Author: helmutg <helmut@subdivi.de> Date: Mon Oct 12 22:24:24 2020 +0200 add build option USE_SYSTEM_PUGIXML (#2502) It allows skipping inference-engine/thirdparty/pugixml and using the system copy instead. Thanks to @Osse for helping understand cmake scoping rules. Co-authored-by: Helmut Grohne <helmut.grohne@intenta.de> commit 7ac8cd858617dd558b66b86df56aea151941288c Author: Alexander Zhogov <alexander.zhogov@intel.com> Date: Mon Oct 12 19:23:00 2020 +0300 Azure CI: Fix nGraph ONNX commit 3a2e33962ce445369d718a8fbd36fb8e69dd5363 Author: Alexander Zhogov <alexander.zhogov@intel.com> Date: Mon Oct 12 19:20:28 2020 +0300 Azure CI: Disable steps in nGraph ONNX commit 5835974fad10b28e6b530317a2cbbd62ec2bff8d Author: azhogov <alexander.zhogov@intel.com> Date: Mon Oct 12 18:46:14 2020 +0300 Azure CI: Add linux_ngraph_onnx.yml * LRN Reference (#21) * Disable failed tests on ia32 * Remove redundant broadcast from MVN ref * Fix missed GatherND in opset_int_tbl + code style * Remove one extra temporary buffer from MVN ref * Merge master (#22) * Leaky relu transformation refactor (#2640) * Refactored LeakyRelu transformation * Added unit test for LeakyRelu transformation + removed duplicate test function valued_const * nGraph implementation of NMS-5 (without `evaluate()`) (#2651) * Written nGraph NMS-5 without evaluate(). * Used NGRAPH_RTTI_DECLARATION. * setupvars.sh: Updated setting pyenv error to warning. (#2663) * Fix itt build (#2662) * Loop-5 operation specification (#2291) The Loop-5 operation specification * Time tests improvements (#2642) * Remove extra functions from run_timetest.py * Add `log.debug` of raw and aggregated statistics in run_timetest.py * Implement storing of models locally for test_timetest.py * Fixed CVS-35316 (#2072) * Extend MO for operation GatherND (#2540) * Extend MO for operation GatherND * Update documentation * Rename GatherNd.py to gathernd.py Signed-off-by: Roman Kazantsev <roman.kazantsev@intel.com> * Add hsigmoid op to ngraph (#2647) * [IE CLDNN] Fixes for GatherTree and ReverseSequence (#2660) * ReorgYolo reference implementation (#2384) * Align ReorgYolo to the spec (vector strides -> int stride) * ReorgYolo ref impl * ReorgYolo evaluate method * ReorgYolo tests * Tests update * Style apply * Add some coments * Code refactor * Comment update * Style apply * Build fix, mark evaluate as override * Revert "Align ReorgYolo to the spec (vector strides -> int stride)" * Use int_executable instead of evaluate * Use char* instead of templates * Code refactor * Comment update * Code review comment * Add constructor aligned with spec * Update shape validation * Update attributes tests * Add type_prop tests * Update backend tests * Add single layer tests * Update the spec * Remove wrong transformation test * Add ReorgYolo to evaluates_map * code style Co-authored-by: Evgeny Lazarev <evgeny.lazarev@intel.com> Co-authored-by: Vladimir Gavrilov <vladimir.gavrilov@intel.com> Co-authored-by: Artyom Anokhov <artyom.anokhov@intel.com> Co-authored-by: Andrey Somsikov <andrey.somsikov@intel.com> Co-authored-by: Vitaliy Urusovskij <vitaliy.urusovskij@intel.com> Co-authored-by: Anastasiya Ageeva <anastasiya.ageeva@intel.com> Co-authored-by: Roman Kazantsev <roman.kazantsev@intel.com> Co-authored-by: iliya mironov <iliya.mironov@intel.com> Co-authored-by: Vladimir Paramuzov <vladimir.paramuzov@intel.com> Co-authored-by: Katarzyna Mitrus <katarzyna.mitrus@intel.com> * RegionYolo * Apply review comments * Merge remote-tracking branch 'upstream/master' into update_evaluates # Conflicts: # ngraph/core/src/op/mvn.cpp # ngraph/test/backend/fused_op.in.cpp # ngraph/test/runtime/ie/unit_test.manifest # ngraph/test/runtime/interpreter/int_executable.hpp # ngraph/test/runtime/interpreter/opset_int_tbl.hpp # ngraph/test/runtime/interpreter/unit_test.manifest # ngraph/test/runtime/opset0_tbl.hpp * Apply code style * Apply comments * Apply code style * Fix RegionYolo evaluate redefinition * Removed defines from evaluates map * Apply code style * Fix MVN ref * rename select reference argument * Fix code style * Fix Fake Quantize references calculation (#24) * Fix MVN ref * Fix MVN & adding NMS * Fix TI * Temporary relax comparison threshold for FQ SLT * Fix GPU LPT Tests * Add explicit rounding mode seetting in FQ references * Apply code style * Rollback op_is test deletion * Apply code style * Fix merge conflict resolving issues * Apply code style Co-authored-by: Irina Efode <irina.efode@intel.com> Co-authored-by: Anton Zaytsev <anton.zaytsev@intel.com> Co-authored-by: Evgeny Lazarev <evgeny.lazarev@intel.com> Co-authored-by: Vladimir Gavrilov <vladimir.gavrilov@intel.com> Co-authored-by: Artyom Anokhov <artyom.anokhov@intel.com> Co-authored-by: Andrey Somsikov <andrey.somsikov@intel.com> Co-authored-by: Vitaliy Urusovskij <vitaliy.urusovskij@intel.com> Co-authored-by: Anastasiya Ageeva <anastasiya.ageeva@intel.com> Co-authored-by: Roman Kazantsev <roman.kazantsev@intel.com> Co-authored-by: iliya mironov <iliya.mironov@intel.com> Co-authored-by: Vladimir Paramuzov <vladimir.paramuzov@intel.com> Co-authored-by: Katarzyna Mitrus <katarzyna.mitrus@intel.com>
2020-12-03 12:36:34 +03:00
auto d = make_shared<op::v1::Add>(float0, float0);
ASSERT_EQ(d->input_values().at(0).get_node_shared_ptr(), float0);
ASSERT_EQ(d->input_values().at(1).get_node_shared_ptr(), float0);
Shape ishape{3, 5};
vector<int32_t> idata(shape_size(ishape), 0);
auto int32_0 = make_shared<op::Constant>(element::i32, ishape, idata);
ASSERT_EQ(int32_0->get_element_type(), element::i32);
ASSERT_EQ(int32_0->get_shape(), ishape);
}
// Check functions with undeclared parameters
TEST(build_graph, function_undeclared_parameters)
{
// Function with 4 parameters
auto arg0 = make_shared<op::Parameter>(element::f32, Shape{7, 3});
auto arg1 = make_shared<op::Parameter>(element::f32, Shape{3});
auto arg2 = make_shared<op::Parameter>(element::f32, Shape{32, 7});
auto arg3 = make_shared<op::Parameter>(element::f32, Shape{32, 7});
auto broadcast_1 = builder::opset1::make_broadcast(arg3, Shape{10, 32, 7}, AxisSet{0});
auto b1 = builder::opset1::make_broadcast(arg3, Shape{10, 32, 7}, AxisSet{0});
auto dot = make_shared<op::MatMul>(arg2, arg0);
ASSERT_EQ(dot->input_values()[0].get_node_shared_ptr(), arg2);
ASSERT_EQ(dot->input_values()[1].get_node_shared_ptr(), arg0);
try
{
auto f = make_shared<Function>(dot, ParameterVector{arg0, arg1, arg3});
f->get_ops();
// Should have thrown, so fail if it didn't
FAIL() << "Undeclared parameter not detected.";
}
catch (const ngraph_error& error)
{
EXPECT_HAS_SUBSTRING(error.what(), std::string("Function references undeclared parameter"));
}
catch (...)
{
FAIL() << "Function construction failed for unexpected reason";
}
}
// Check no-arg construction
TEST(build_graph, no_arg_construction)
{
// The ops
// Parameters aren't converted yet
auto arg0 = make_shared<op::Parameter>(element::f32, Shape{7});
auto arg1 = make_shared<op::Parameter>(element::f32, Shape{7});
auto arg2 = make_shared<op::Parameter>(element::f32, Shape{7});
auto arg3 = make_shared<op::Parameter>(element::f32, Shape{7});
Remove opset0 support and undesired passes from Interpreter backend (#1469) * Move evaluate() interface from some OPs to Interpreter * commit * Move shuffle channels reference to OP's evaluate * Add some operations missed in evaluate_node * Fix select references invocation from evaluate_node() * Activation refs (#2) * HardSigmoid * Elu * Selu * Gelu * Move to test runtime * Rollback donwgrade passes delition * Initial batch to space refs * Return opset1_upgrade * WIP: Add space to batch evaluate * Fix space to batch * add evaluates function in evaluates_map (#4) * Add space to batch evaluate * Fix crop in batch to space references * Remove vectors reallocation in evaluates for b2s and s2b * . * Add SpaceToDepth evaluate * Add depth to space evaluate * Remove code duplication depth to space evaluate * Fix some failed layer tests * Ngraph test (#3) * Remove some v0 ops & fix some tests * Fixes BatchNorm * Next * dd * s * Add dot & replace slice refs * d * dkj * Review fixes part 1 * Fixes. Part 2 * Fixes. Part 3 * Enable cells refs in evaluate map * Fix some failed layer tests * Some more fixes * Fix code style (#6) * Tests (#7) * PriorBox * Mod * NormilizeL2 * Update prior_box.hpp * Fix one hot ref call * . * Select (#8) * Select * Fix code style * Fix select messages * ReverseSeq (#9) * ReverseSeq * Select * ExtractImagePatches, Seqence * Fix Code Style * remove extra * Remove etra line@ * Add fake quantize reference * Align convolution layer tests instantiations with updated definition * Disabled some failed LPT tests * Disabled some failed LPT tests * Remove undesired changes * Update unit-test manifests + some code cleanup * Fix code style (#10) * Normalize L2 refs support (from PR #2327) * Fix code style * Apply review comments. Part 1 (#11) * Apply first part of review comments * Update onnx_import.in.cpp * Remove redundant reshape from shuffle_channels evaluate * Decompose GroupConvolution * [IE Ngraph] Fix some operation inheritance (#13) * [IE TESTS] Depth2Space * Space2Depth * ShuffleChannels * Fix ode style * Fix code style * [IE NGraph] Remove decompose op (#14) * . * Fix loosing control dependency in replace_node * Fix loosing control dependency in replace_node * Fix code style * Fix FQ references build on windows * Fix code style * Apply comments (#15) * [Ie Ngraph] Remove using v1::Add * [Ie Ngraph] Remove using v1::Mutliply * [Ie Ngraph] Remove using v1::Subtract * [Ie Ngraph] Remove using v1::Divide * [Ie Ngraph] Remove using v1::Equal * [Ie Ngraph] Remove using v1::Greater * [Ie Ngraph] Remove using v1::Greater_eq * [Ie Ngraph] Remove using v1::Less * [Ie Ngraph] Remove using v1::LessEq * [Ie Ngraph] Remove using operator+ * [Ie Ngraph] Remove using operator/ * [Ie Ngraph] Remove using operator* * [Ie Ngraph] Remove using operator- * Fix code style * Ci (#16) * Fix CentOS compilation * Revert ngraph::op::vo::Multiply removing due to OpenCV * Android fix (#17) * fix failures * Fix code style * Add (#18) * Android fix * Add * Add in opset1 upgrade pass * Add in opset1 upgrade pass * Remove v0::Add, Reverted removing v0::Multiply (#19) * Remove overloaded math operators from PyNgraph * Remove overloaded math operators from PyNgraph * Fix gna tests (#20) * Fix gna tests * Squashed commit of the following: commit 565b504c1cb8d4f21bc0cb45836e9e473a2b871e Author: Alexander Zhogov <alexander.zhogov@intel.com> Date: Tue Oct 13 13:27:34 2020 +0300 GitHub CI: Add files_size.yml (#2570) * GitHub CI: Add files_size.yml * Update job name commit ab0fb298530152f25c7a8c5cc5ee3d6ba03d6516 Author: Vladislav Vinogradov <vlad.vinogradov@intel.com> Date: Tue Oct 13 11:37:30 2020 +0300 [IE][BUILD] Fix C5208 warning under Windows (#2628) * C++ feature in C `typedef struct` code. * The warning can be promoted to error in dependent projects. C5208: unnamed class used in typedef name cannot declare members other than non-static data members, member enumerations, or member classes commit 15a338e89ba9336038e836c7fb086cdd4fed1d7a Author: helmutg <helmut@subdivi.de> Date: Mon Oct 12 22:24:24 2020 +0200 add build option USE_SYSTEM_PUGIXML (#2502) It allows skipping inference-engine/thirdparty/pugixml and using the system copy instead. Thanks to @Osse for helping understand cmake scoping rules. Co-authored-by: Helmut Grohne <helmut.grohne@intenta.de> commit 7ac8cd858617dd558b66b86df56aea151941288c Author: Alexander Zhogov <alexander.zhogov@intel.com> Date: Mon Oct 12 19:23:00 2020 +0300 Azure CI: Fix nGraph ONNX commit 3a2e33962ce445369d718a8fbd36fb8e69dd5363 Author: Alexander Zhogov <alexander.zhogov@intel.com> Date: Mon Oct 12 19:20:28 2020 +0300 Azure CI: Disable steps in nGraph ONNX commit 5835974fad10b28e6b530317a2cbbd62ec2bff8d Author: azhogov <alexander.zhogov@intel.com> Date: Mon Oct 12 18:46:14 2020 +0300 Azure CI: Add linux_ngraph_onnx.yml * LRN Reference (#21) * Disable failed tests on ia32 * Remove redundant broadcast from MVN ref * Fix missed GatherND in opset_int_tbl + code style * Remove one extra temporary buffer from MVN ref * Merge master (#22) * Leaky relu transformation refactor (#2640) * Refactored LeakyRelu transformation * Added unit test for LeakyRelu transformation + removed duplicate test function valued_const * nGraph implementation of NMS-5 (without `evaluate()`) (#2651) * Written nGraph NMS-5 without evaluate(). * Used NGRAPH_RTTI_DECLARATION. * setupvars.sh: Updated setting pyenv error to warning. (#2663) * Fix itt build (#2662) * Loop-5 operation specification (#2291) The Loop-5 operation specification * Time tests improvements (#2642) * Remove extra functions from run_timetest.py * Add `log.debug` of raw and aggregated statistics in run_timetest.py * Implement storing of models locally for test_timetest.py * Fixed CVS-35316 (#2072) * Extend MO for operation GatherND (#2540) * Extend MO for operation GatherND * Update documentation * Rename GatherNd.py to gathernd.py Signed-off-by: Roman Kazantsev <roman.kazantsev@intel.com> * Add hsigmoid op to ngraph (#2647) * [IE CLDNN] Fixes for GatherTree and ReverseSequence (#2660) * ReorgYolo reference implementation (#2384) * Align ReorgYolo to the spec (vector strides -> int stride) * ReorgYolo ref impl * ReorgYolo evaluate method * ReorgYolo tests * Tests update * Style apply * Add some coments * Code refactor * Comment update * Style apply * Build fix, mark evaluate as override * Revert "Align ReorgYolo to the spec (vector strides -> int stride)" * Use int_executable instead of evaluate * Use char* instead of templates * Code refactor * Comment update * Code review comment * Add constructor aligned with spec * Update shape validation * Update attributes tests * Add type_prop tests * Update backend tests * Add single layer tests * Update the spec * Remove wrong transformation test * Add ReorgYolo to evaluates_map * code style Co-authored-by: Evgeny Lazarev <evgeny.lazarev@intel.com> Co-authored-by: Vladimir Gavrilov <vladimir.gavrilov@intel.com> Co-authored-by: Artyom Anokhov <artyom.anokhov@intel.com> Co-authored-by: Andrey Somsikov <andrey.somsikov@intel.com> Co-authored-by: Vitaliy Urusovskij <vitaliy.urusovskij@intel.com> Co-authored-by: Anastasiya Ageeva <anastasiya.ageeva@intel.com> Co-authored-by: Roman Kazantsev <roman.kazantsev@intel.com> Co-authored-by: iliya mironov <iliya.mironov@intel.com> Co-authored-by: Vladimir Paramuzov <vladimir.paramuzov@intel.com> Co-authored-by: Katarzyna Mitrus <katarzyna.mitrus@intel.com> * RegionYolo * Apply review comments * Merge remote-tracking branch 'upstream/master' into update_evaluates # Conflicts: # ngraph/core/src/op/mvn.cpp # ngraph/test/backend/fused_op.in.cpp # ngraph/test/runtime/ie/unit_test.manifest # ngraph/test/runtime/interpreter/int_executable.hpp # ngraph/test/runtime/interpreter/opset_int_tbl.hpp # ngraph/test/runtime/interpreter/unit_test.manifest # ngraph/test/runtime/opset0_tbl.hpp * Apply code style * Apply comments * Apply code style * Fix RegionYolo evaluate redefinition * Removed defines from evaluates map * Apply code style * Fix MVN ref * rename select reference argument * Fix code style * Fix Fake Quantize references calculation (#24) * Fix MVN ref * Fix MVN & adding NMS * Fix TI * Temporary relax comparison threshold for FQ SLT * Fix GPU LPT Tests * Add explicit rounding mode seetting in FQ references * Apply code style * Rollback op_is test deletion * Apply code style * Fix merge conflict resolving issues * Apply code style Co-authored-by: Irina Efode <irina.efode@intel.com> Co-authored-by: Anton Zaytsev <anton.zaytsev@intel.com> Co-authored-by: Evgeny Lazarev <evgeny.lazarev@intel.com> Co-authored-by: Vladimir Gavrilov <vladimir.gavrilov@intel.com> Co-authored-by: Artyom Anokhov <artyom.anokhov@intel.com> Co-authored-by: Andrey Somsikov <andrey.somsikov@intel.com> Co-authored-by: Vitaliy Urusovskij <vitaliy.urusovskij@intel.com> Co-authored-by: Anastasiya Ageeva <anastasiya.ageeva@intel.com> Co-authored-by: Roman Kazantsev <roman.kazantsev@intel.com> Co-authored-by: iliya mironov <iliya.mironov@intel.com> Co-authored-by: Vladimir Paramuzov <vladimir.paramuzov@intel.com> Co-authored-by: Katarzyna Mitrus <katarzyna.mitrus@intel.com>
2020-12-03 12:36:34 +03:00
auto add0 = make_shared<op::v1::Add>();
auto abs0 = make_shared<op::Abs>();
auto acos0 = make_shared<op::Acos>();
Remove opset0 support and undesired passes from Interpreter backend (#1469) * Move evaluate() interface from some OPs to Interpreter * commit * Move shuffle channels reference to OP's evaluate * Add some operations missed in evaluate_node * Fix select references invocation from evaluate_node() * Activation refs (#2) * HardSigmoid * Elu * Selu * Gelu * Move to test runtime * Rollback donwgrade passes delition * Initial batch to space refs * Return opset1_upgrade * WIP: Add space to batch evaluate * Fix space to batch * add evaluates function in evaluates_map (#4) * Add space to batch evaluate * Fix crop in batch to space references * Remove vectors reallocation in evaluates for b2s and s2b * . * Add SpaceToDepth evaluate * Add depth to space evaluate * Remove code duplication depth to space evaluate * Fix some failed layer tests * Ngraph test (#3) * Remove some v0 ops & fix some tests * Fixes BatchNorm * Next * dd * s * Add dot & replace slice refs * d * dkj * Review fixes part 1 * Fixes. Part 2 * Fixes. Part 3 * Enable cells refs in evaluate map * Fix some failed layer tests * Some more fixes * Fix code style (#6) * Tests (#7) * PriorBox * Mod * NormilizeL2 * Update prior_box.hpp * Fix one hot ref call * . * Select (#8) * Select * Fix code style * Fix select messages * ReverseSeq (#9) * ReverseSeq * Select * ExtractImagePatches, Seqence * Fix Code Style * remove extra * Remove etra line@ * Add fake quantize reference * Align convolution layer tests instantiations with updated definition * Disabled some failed LPT tests * Disabled some failed LPT tests * Remove undesired changes * Update unit-test manifests + some code cleanup * Fix code style (#10) * Normalize L2 refs support (from PR #2327) * Fix code style * Apply review comments. Part 1 (#11) * Apply first part of review comments * Update onnx_import.in.cpp * Remove redundant reshape from shuffle_channels evaluate * Decompose GroupConvolution * [IE Ngraph] Fix some operation inheritance (#13) * [IE TESTS] Depth2Space * Space2Depth * ShuffleChannels * Fix ode style * Fix code style * [IE NGraph] Remove decompose op (#14) * . * Fix loosing control dependency in replace_node * Fix loosing control dependency in replace_node * Fix code style * Fix FQ references build on windows * Fix code style * Apply comments (#15) * [Ie Ngraph] Remove using v1::Add * [Ie Ngraph] Remove using v1::Mutliply * [Ie Ngraph] Remove using v1::Subtract * [Ie Ngraph] Remove using v1::Divide * [Ie Ngraph] Remove using v1::Equal * [Ie Ngraph] Remove using v1::Greater * [Ie Ngraph] Remove using v1::Greater_eq * [Ie Ngraph] Remove using v1::Less * [Ie Ngraph] Remove using v1::LessEq * [Ie Ngraph] Remove using operator+ * [Ie Ngraph] Remove using operator/ * [Ie Ngraph] Remove using operator* * [Ie Ngraph] Remove using operator- * Fix code style * Ci (#16) * Fix CentOS compilation * Revert ngraph::op::vo::Multiply removing due to OpenCV * Android fix (#17) * fix failures * Fix code style * Add (#18) * Android fix * Add * Add in opset1 upgrade pass * Add in opset1 upgrade pass * Remove v0::Add, Reverted removing v0::Multiply (#19) * Remove overloaded math operators from PyNgraph * Remove overloaded math operators from PyNgraph * Fix gna tests (#20) * Fix gna tests * Squashed commit of the following: commit 565b504c1cb8d4f21bc0cb45836e9e473a2b871e Author: Alexander Zhogov <alexander.zhogov@intel.com> Date: Tue Oct 13 13:27:34 2020 +0300 GitHub CI: Add files_size.yml (#2570) * GitHub CI: Add files_size.yml * Update job name commit ab0fb298530152f25c7a8c5cc5ee3d6ba03d6516 Author: Vladislav Vinogradov <vlad.vinogradov@intel.com> Date: Tue Oct 13 11:37:30 2020 +0300 [IE][BUILD] Fix C5208 warning under Windows (#2628) * C++ feature in C `typedef struct` code. * The warning can be promoted to error in dependent projects. C5208: unnamed class used in typedef name cannot declare members other than non-static data members, member enumerations, or member classes commit 15a338e89ba9336038e836c7fb086cdd4fed1d7a Author: helmutg <helmut@subdivi.de> Date: Mon Oct 12 22:24:24 2020 +0200 add build option USE_SYSTEM_PUGIXML (#2502) It allows skipping inference-engine/thirdparty/pugixml and using the system copy instead. Thanks to @Osse for helping understand cmake scoping rules. Co-authored-by: Helmut Grohne <helmut.grohne@intenta.de> commit 7ac8cd858617dd558b66b86df56aea151941288c Author: Alexander Zhogov <alexander.zhogov@intel.com> Date: Mon Oct 12 19:23:00 2020 +0300 Azure CI: Fix nGraph ONNX commit 3a2e33962ce445369d718a8fbd36fb8e69dd5363 Author: Alexander Zhogov <alexander.zhogov@intel.com> Date: Mon Oct 12 19:20:28 2020 +0300 Azure CI: Disable steps in nGraph ONNX commit 5835974fad10b28e6b530317a2cbbd62ec2bff8d Author: azhogov <alexander.zhogov@intel.com> Date: Mon Oct 12 18:46:14 2020 +0300 Azure CI: Add linux_ngraph_onnx.yml * LRN Reference (#21) * Disable failed tests on ia32 * Remove redundant broadcast from MVN ref * Fix missed GatherND in opset_int_tbl + code style * Remove one extra temporary buffer from MVN ref * Merge master (#22) * Leaky relu transformation refactor (#2640) * Refactored LeakyRelu transformation * Added unit test for LeakyRelu transformation + removed duplicate test function valued_const * nGraph implementation of NMS-5 (without `evaluate()`) (#2651) * Written nGraph NMS-5 without evaluate(). * Used NGRAPH_RTTI_DECLARATION. * setupvars.sh: Updated setting pyenv error to warning. (#2663) * Fix itt build (#2662) * Loop-5 operation specification (#2291) The Loop-5 operation specification * Time tests improvements (#2642) * Remove extra functions from run_timetest.py * Add `log.debug` of raw and aggregated statistics in run_timetest.py * Implement storing of models locally for test_timetest.py * Fixed CVS-35316 (#2072) * Extend MO for operation GatherND (#2540) * Extend MO for operation GatherND * Update documentation * Rename GatherNd.py to gathernd.py Signed-off-by: Roman Kazantsev <roman.kazantsev@intel.com> * Add hsigmoid op to ngraph (#2647) * [IE CLDNN] Fixes for GatherTree and ReverseSequence (#2660) * ReorgYolo reference implementation (#2384) * Align ReorgYolo to the spec (vector strides -> int stride) * ReorgYolo ref impl * ReorgYolo evaluate method * ReorgYolo tests * Tests update * Style apply * Add some coments * Code refactor * Comment update * Style apply * Build fix, mark evaluate as override * Revert "Align ReorgYolo to the spec (vector strides -> int stride)" * Use int_executable instead of evaluate * Use char* instead of templates * Code refactor * Comment update * Code review comment * Add constructor aligned with spec * Update shape validation * Update attributes tests * Add type_prop tests * Update backend tests * Add single layer tests * Update the spec * Remove wrong transformation test * Add ReorgYolo to evaluates_map * code style Co-authored-by: Evgeny Lazarev <evgeny.lazarev@intel.com> Co-authored-by: Vladimir Gavrilov <vladimir.gavrilov@intel.com> Co-authored-by: Artyom Anokhov <artyom.anokhov@intel.com> Co-authored-by: Andrey Somsikov <andrey.somsikov@intel.com> Co-authored-by: Vitaliy Urusovskij <vitaliy.urusovskij@intel.com> Co-authored-by: Anastasiya Ageeva <anastasiya.ageeva@intel.com> Co-authored-by: Roman Kazantsev <roman.kazantsev@intel.com> Co-authored-by: iliya mironov <iliya.mironov@intel.com> Co-authored-by: Vladimir Paramuzov <vladimir.paramuzov@intel.com> Co-authored-by: Katarzyna Mitrus <katarzyna.mitrus@intel.com> * RegionYolo * Apply review comments * Merge remote-tracking branch 'upstream/master' into update_evaluates # Conflicts: # ngraph/core/src/op/mvn.cpp # ngraph/test/backend/fused_op.in.cpp # ngraph/test/runtime/ie/unit_test.manifest # ngraph/test/runtime/interpreter/int_executable.hpp # ngraph/test/runtime/interpreter/opset_int_tbl.hpp # ngraph/test/runtime/interpreter/unit_test.manifest # ngraph/test/runtime/opset0_tbl.hpp * Apply code style * Apply comments * Apply code style * Fix RegionYolo evaluate redefinition * Removed defines from evaluates map * Apply code style * Fix MVN ref * rename select reference argument * Fix code style * Fix Fake Quantize references calculation (#24) * Fix MVN ref * Fix MVN & adding NMS * Fix TI * Temporary relax comparison threshold for FQ SLT * Fix GPU LPT Tests * Add explicit rounding mode seetting in FQ references * Apply code style * Rollback op_is test deletion * Apply code style * Fix merge conflict resolving issues * Apply code style Co-authored-by: Irina Efode <irina.efode@intel.com> Co-authored-by: Anton Zaytsev <anton.zaytsev@intel.com> Co-authored-by: Evgeny Lazarev <evgeny.lazarev@intel.com> Co-authored-by: Vladimir Gavrilov <vladimir.gavrilov@intel.com> Co-authored-by: Artyom Anokhov <artyom.anokhov@intel.com> Co-authored-by: Andrey Somsikov <andrey.somsikov@intel.com> Co-authored-by: Vitaliy Urusovskij <vitaliy.urusovskij@intel.com> Co-authored-by: Anastasiya Ageeva <anastasiya.ageeva@intel.com> Co-authored-by: Roman Kazantsev <roman.kazantsev@intel.com> Co-authored-by: iliya mironov <iliya.mironov@intel.com> Co-authored-by: Vladimir Paramuzov <vladimir.paramuzov@intel.com> Co-authored-by: Katarzyna Mitrus <katarzyna.mitrus@intel.com>
2020-12-03 12:36:34 +03:00
auto add1 = make_shared<op::v1::Add>();
add0->set_argument(1, arg0);
add0->set_argument(0, arg1);
abs0->set_argument(0, add0);
acos0->set_argument(0, add0);
add1->set_argument(0, acos0);
add1->set_argument(1, abs0);
NodeVector ops{arg0, arg1, add0, abs0, acos0, add1};
validate_nodes_and_infer_types(ops);
ASSERT_EQ(add1->get_output_shape(0), Shape{7});
}
TEST(build_graph, multi_output_split_dynamic)
{
const auto data = make_shared<op::Parameter>(element::f32, PartialShape::dynamic());
const auto axis = op::Constant::create(element::i64, Shape{}, {1});
const auto split = make_shared<op::v1::Split>(data, axis, 2);
auto abs = make_shared<op::Abs>(split->output(1));
EXPECT_TRUE(abs->get_output_partial_shape(0).same_scheme(PartialShape::dynamic()));
auto new_parameter = make_shared<op::Parameter>(element::f32, Shape{2, 4});
split->input(0).replace_source_output(new_parameter->output(0));
auto f = make_shared<Function>(abs, ParameterVector{new_parameter});
f->validate_nodes_and_infer_types();
EXPECT_EQ(abs->get_shape(), (Shape{2, 2}));
}
TEST(build_graph, function_revalidate_and_infer)
{
auto arg = make_shared<op::Parameter>(element::f32, Shape{2, 4, 6, 8});
auto pattern = op::Constant::create(element::i64, Shape{6}, {1, 3, 16, 2, 2, 2});
auto r = make_shared<op::v1::Reshape>(arg, pattern, true);
auto relu = make_shared<op::Relu>(r);
auto f = make_shared<Function>(relu, ParameterVector{arg});
EXPECT_EQ(r->get_output_element_type(0), element::f32);
EXPECT_EQ(r->get_output_shape(0), (Shape{1, 3, 16, 2, 2, 2}));
EXPECT_EQ(f->get_output_shape(0), (Shape{1, 3, 16, 2, 2, 2}));
auto new_pattern = op::Constant::create(element::i64, Shape{2}, {32, 12});
r->input(1).replace_source_output(new_pattern->output(0));
f->validate_nodes_and_infer_types();
EXPECT_EQ(r->get_output_shape(0), (Shape{32, 12}));
EXPECT_EQ(f->get_output_shape(0), (Shape{32, 12}));
}
TEST(build_graph, default_output_checks)
{
try
{
std::shared_ptr<Node> empty;
auto nullout = Output<Node>(empty);
}
catch (...)
{
FAIL() << "nullptr initialization of Output failed";
}
}
TEST(build_graph, build_graph_with_sink)
{
auto arg = make_shared<op::Parameter>(element::f32, Shape{2, 4});
auto init_const = op::Constant::create(element::f32, Shape{2, 2}, {0, 0, 0, 0});
auto read = make_shared<opset5::ReadValue>(init_const, "v0");
std::vector<shared_ptr<Node>> args = {arg, read};
auto pattern = make_shared<op::Concat>(args, 1);
auto res = make_shared<op::Result>(pattern);
const auto axis = op::Constant::create(element::i64, Shape{}, {1});
auto crop = make_shared<op::v1::Split>(pattern, axis, 3);
auto assign = make_shared<opset5::Assign>(crop, "v0");
auto f = make_shared<Function>(ResultVector({res}), SinkVector({assign}), ParameterVector{arg});
SinkVector sinks = f->get_sinks();
EXPECT_EQ(sinks.size(), 1);
EXPECT_EQ(sinks[0], assign);
NodeVector nodes = f->get_ops();
EXPECT_EQ(nodes.size(), 8);
}
TEST(build_graph, build_graph_with_sink_output_ctor)
{
auto arg = make_shared<op::Parameter>(element::f32, Shape{2, 4});
auto init_const = op::Constant::create(element::f32, Shape{2, 2}, {0, 0, 0, 0});
auto read = make_shared<opset5::ReadValue>(init_const, "v0");
std::vector<shared_ptr<Node>> args = {arg, read};
auto pattern = make_shared<op::Concat>(args, 1);
auto res = make_shared<op::Result>(pattern);
const auto axis = op::Constant::create(element::i64, Shape{}, {1});
auto crop = make_shared<op::v1::Split>(pattern, axis, 3);
auto assign = make_shared<opset5::Assign>(crop, "v0");
auto f = make_shared<Function>(
OutputVector({pattern->output(0)}), SinkVector({assign}), ParameterVector{arg});
SinkVector sinks = f->get_sinks();
EXPECT_EQ(sinks.size(), 1);
EXPECT_EQ(sinks[0], assign);
NodeVector nodes = f->get_ops();
EXPECT_EQ(nodes.size(), 8);
}
TEST(build_graph, build_graph_with_add_sink)
{
auto arg = make_shared<op::Parameter>(element::f32, Shape{2, 4});
auto init_const = op::Constant::create(element::f32, Shape{2, 2}, {0, 0, 0, 0});
auto read = make_shared<opset5::ReadValue>(init_const, "v0");
std::vector<shared_ptr<Node>> args = {arg, read};
auto pattern = make_shared<op::Concat>(args, 1);
auto res = make_shared<op::Result>(pattern);
const auto axis = op::Constant::create(element::i64, Shape{}, {1});
auto crop = make_shared<op::v1::Split>(pattern, axis, 3);
auto assign = make_shared<opset5::Assign>(crop, "v0");
auto f = make_shared<Function>(ResultVector({res}), ParameterVector{arg});
NodeVector nodes = f->get_ops();
EXPECT_EQ(nodes.size(), 5);
SinkVector sinks = f->get_sinks();
EXPECT_EQ(sinks.size(), 0);
f->add_sinks(SinkVector({assign}));
sinks = f->get_sinks();
EXPECT_EQ(sinks.size(), 1);
EXPECT_EQ(sinks[0], assign);
nodes = f->get_ops();
EXPECT_EQ(nodes.size(), 8);
}
TEST(build_graph, build_graph_with_wrong_remove_sink)
{
auto arg = make_shared<op::Parameter>(element::f32, Shape{2, 4});
auto init_const = op::Constant::create(element::f32, Shape{2, 2}, {0, 0, 0, 0});
auto read = make_shared<opset5::ReadValue>(init_const, "v0");
std::vector<shared_ptr<Node>> args = {arg, read};
auto pattern = make_shared<op::Concat>(args, 1);
auto res = make_shared<op::Result>(pattern);
const auto axis = op::Constant::create(element::i64, Shape{}, {1});
auto crop = make_shared<op::v1::Split>(pattern, axis, 3);
auto assign = make_shared<opset5::Assign>(crop, "v0");
auto f = make_shared<Function>(ResultVector({res}), SinkVector({assign}), ParameterVector{arg});
SinkVector sinks = f->get_sinks();
EXPECT_EQ(sinks.size(), 1);
EXPECT_EQ(sinks[0], assign);
f->remove_sink(assign);
sinks = f->get_sinks();
EXPECT_EQ(sinks.size(), 0);
auto nodes = f->get_ops();
EXPECT_EQ(nodes.size(), 5);
}
TEST(build_graph, build_graph_with_remove_sink)
{
auto arg = make_shared<op::Parameter>(element::f32, Shape{2, 4});
auto init_const = op::Constant::create(element::f32, Shape{2, 2}, {0, 0, 0, 0});
auto read = make_shared<opset5::ReadValue>(init_const, "v0");
std::vector<shared_ptr<Node>> args = {arg, read};
auto pattern = make_shared<op::Concat>(args, 1);
auto res = make_shared<op::Result>(pattern);
const auto axis = op::Constant::create(element::i64, Shape{}, {1});
auto crop = make_shared<op::v1::Split>(pattern, axis, 3);
auto assign = make_shared<opset5::Assign>(crop, "v0");
auto f = make_shared<Function>(ResultVector({res}), SinkVector({assign}), ParameterVector{arg});
pattern->input(1).replace_source_output(arg);
SinkVector sinks = f->get_sinks();
EXPECT_EQ(sinks.size(), 1);
EXPECT_EQ(sinks[0], assign);
f->remove_sink(assign);
sinks = f->get_sinks();
EXPECT_EQ(sinks.size(), 0);
auto nodes = f->get_ops();
EXPECT_EQ(nodes.size(), 3);
}
TEST(build_graph, build_graph_with_add_result)
{
auto arg = make_shared<op::Parameter>(element::f32, Shape{2, 4});
auto init_const = op::Constant::create(element::f32, Shape{2, 2}, {0, 0, 0, 0});
auto read = make_shared<opset5::ReadValue>(init_const, "v0");
std::vector<shared_ptr<Node>> args = {arg, read};
auto pattern = make_shared<op::Concat>(args, 1);
auto res = make_shared<op::Result>(pattern);
const auto axis = op::Constant::create(element::i64, Shape{}, {1});
auto crop = make_shared<op::v1::Split>(pattern, axis, 3);
auto res2 = make_shared<op::Result>(crop, "v0");
auto f = make_shared<Function>(ResultVector({res}), ParameterVector{arg});
NodeVector nodes = f->get_ops();
EXPECT_EQ(nodes.size(), 5);
ResultVector results = f->get_results();
EXPECT_EQ(results.size(), 1);
f->add_results(ResultVector({res2}));
results = f->get_results();
EXPECT_EQ(results.size(), 2);
EXPECT_EQ(results[1], res2);
nodes = f->get_ops();
EXPECT_EQ(nodes.size(), 8);
}
TEST(build_graph, build_graph_with_remove_result)
{
auto arg = make_shared<op::Parameter>(element::f32, Shape{2, 4});
auto init_const = op::Constant::create(element::f32, Shape{2, 2}, {0, 0, 0, 0});
auto read = make_shared<opset5::ReadValue>(init_const, "v0");
std::vector<shared_ptr<Node>> args = {arg, read};
auto pattern = make_shared<op::Concat>(args, 1);
auto res = make_shared<op::Result>(pattern);
const auto axis = op::Constant::create(element::i64, Shape{}, {1});
auto crop = make_shared<op::v1::Split>(pattern, axis, 3);
auto res2 = make_shared<op::Result>(crop, "v0");
auto f = make_shared<Function>(ResultVector({res, res2}), ParameterVector{arg});
NodeVector nodes = f->get_ops();
EXPECT_EQ(nodes.size(), 8);
ResultVector results = f->get_results();
EXPECT_EQ(results.size(), 2);
f->remove_result(res2);
results = f->get_results();
EXPECT_EQ(results.size(), 1);
nodes = f->get_ops();
EXPECT_EQ(nodes.size(), 5);
}
TEST(build_graph, build_graph_with_add_parameter)
{
auto arg = make_shared<op::Parameter>(element::f32, Shape{2, 4});
auto arg2 = make_shared<op::Parameter>(element::f32, Shape{2, 2});
auto init_const = op::Constant::create(element::f32, Shape{2, 2}, {0, 0, 0, 0});
auto read = make_shared<opset5::ReadValue>(init_const, "v0");
std::vector<shared_ptr<Node>> args = {arg, read};
auto pattern = make_shared<op::Concat>(args, 1);
auto res = make_shared<op::Result>(pattern);
const auto axis = op::Constant::create(element::i64, Shape{}, {1});
auto crop = make_shared<op::v1::Split>(pattern, axis, 3);
auto res2 = make_shared<op::Result>(crop, "v0");
auto f = make_shared<Function>(ResultVector({res, res2}), ParameterVector{arg});
NodeVector nodes = f->get_ops();
EXPECT_EQ(nodes.size(), 8);
ParameterVector params = f->get_parameters();
EXPECT_EQ(params.size(), 1);
pattern->input(1).replace_source_output(arg2->output(0));
f->add_parameters(ParameterVector({arg2}));
params = f->get_parameters();
EXPECT_EQ(params.size(), 2);
EXPECT_EQ(params[1], arg2);
nodes = f->get_ops();
EXPECT_EQ(nodes.size(), 7);
}
TEST(build_graph, build_graph_with_remove_parameter)
{
auto arg = make_shared<op::Parameter>(element::f32, Shape{2, 4});
auto arg2 = make_shared<op::Parameter>(element::f32, Shape{2, 2});
auto init_const = op::Constant::create(element::f32, Shape{2, 2}, {0, 0, 0, 0});
auto read = make_shared<opset5::ReadValue>(init_const, "v0");
std::vector<shared_ptr<Node>> args = {arg, arg2};
auto pattern = make_shared<op::Concat>(args, 1);
auto res = make_shared<op::Result>(pattern);
const auto axis = op::Constant::create(element::i64, Shape{}, {1});
auto crop = make_shared<op::v1::Split>(pattern, axis, 3);
auto res2 = make_shared<op::Result>(crop, "v0");
auto f = make_shared<Function>(ResultVector({res, res2}), ParameterVector{arg, arg2});
NodeVector nodes = f->get_ops();
EXPECT_EQ(nodes.size(), 7);
ParameterVector params = f->get_parameters();
EXPECT_EQ(params.size(), 2);
pattern->input(1).replace_source_output(read->output(0));
f->remove_parameter(arg2);
params = f->get_parameters();
EXPECT_EQ(params.size(), 1);
nodes = f->get_ops();
EXPECT_EQ(nodes.size(), 8);
}
TEST(build_graph, build_graph_with_remove_parameter_indexing)
{
auto arg = make_shared<op::Parameter>(element::f32, Shape{2, 4});
auto arg2 = make_shared<op::Parameter>(element::f32, Shape{2, 2});
auto init_const = op::Constant::create(element::f32, Shape{2, 2}, {0, 0, 0, 0});
auto read = make_shared<opset5::ReadValue>(init_const, "v0");
auto assign = make_shared<opset5::Assign>(read, "v0");
assign->add_control_dependency(read);
std::vector<shared_ptr<Node>> args = {arg2, arg};
auto pattern = make_shared<op::Concat>(args, 1);
auto res = make_shared<op::Result>(pattern);
const auto axis = op::Constant::create(element::i64, Shape{}, {1});
auto crop = make_shared<op::v1::Split>(pattern, axis, 3);
auto res2 = make_shared<op::Result>(crop, "v0");
auto f = make_shared<Function>(ResultVector({res, res2}), ParameterVector{arg2, arg});
NodeVector nodes = f->get_ops();
EXPECT_EQ(nodes.size(), 7);
ParameterVector params = f->get_parameters();
EXPECT_EQ(params.size(), 2);
pattern->input(0).replace_source_output(read->output(0));
f->remove_parameter(arg2);
f->add_sinks(SinkVector{assign});
params = f->get_parameters();
EXPECT_EQ(params.size(), 1);
nodes = f->get_ops();
EXPECT_EQ(nodes.size(), 9);
f->validate_nodes_and_infer_types();
}
TEST(build_graph, build_graph_parameters_autodetection)
{
// Function with 4 parameters
using namespace opset7;
auto arg0 = make_shared<Parameter>(element::f32, Shape{7, 3});
auto arg1 = make_shared<Parameter>(element::f32, Shape{3});
auto arg2 = make_shared<Parameter>(element::f32, Shape{32, 7});
auto arg3 = make_shared<Parameter>(element::f32, Shape{32, 7});
auto broadcast_1 = builder::opset1::make_broadcast(arg3, Shape{10, 32, 7}, AxisSet{0});
auto b1 = builder::opset1::make_broadcast(arg3, Shape{10, 32, 7}, AxisSet{0});
auto dot = make_shared<MatMul>(arg2, arg0);
auto f = make_shared<Function>(OutputVector{dot});
EXPECT_EQ(f->get_parameters().size(), 2);
}
TEST(build_graph, build_graph_parameters_variables_autodetection)
{
using namespace opset7;
auto arg = make_shared<Parameter>(element::f32, Shape{2, 4});
auto arg2 = make_shared<Parameter>(element::f32, Shape{2, 2});
auto init_const = Constant::create(element::f32, Shape{2, 2}, {0, 0, 0, 0});
auto variable = make_shared<Variable>(VariableInfo{PartialShape::dynamic(), element::dynamic, "v0"});
auto read = make_shared<ReadValue>(init_const, variable);
auto assign = make_shared<Assign>(read, variable);
assign->add_control_dependency(read);
std::vector<shared_ptr<Node>> args = {arg2, arg};
auto pattern = make_shared<Concat>(args, 1);
auto res = make_shared<Result>(pattern);
const auto axis = Constant::create(element::i64, Shape{}, {1});
auto crop = make_shared<Split>(pattern, axis, 3);
auto res2 = make_shared<Result>(crop, "v0");
auto f = make_shared<Function>(OutputVector{res, res2}, SinkVector{assign});
NodeVector nodes = f->get_ops();
EXPECT_EQ(nodes.size(), 10);
ParameterVector params = f->get_parameters();
EXPECT_EQ(params.size(), 2);
VariableVector variables = f->get_variables();
EXPECT_EQ(variables.size(), 1);
}
TEST(build_graph, build_graph_variables_ctors)
{
using namespace opset7;
auto arg = make_shared<Parameter>(element::f32, Shape{2, 4});
auto arg2 = make_shared<Parameter>(element::f32, Shape{2, 2});
auto init_const = Constant::create(element::f32, Shape{2, 2}, {0, 0, 0, 0});
auto variable = make_shared<Variable>(VariableInfo{PartialShape::dynamic(), element::dynamic, "v0"});
auto read = make_shared<ReadValue>(init_const, variable);
auto assign = make_shared<Assign>(read, variable);
assign->add_control_dependency(read);
std::vector<shared_ptr<Node>> args = {arg2, arg};
auto pattern = make_shared<Concat>(args, 1);
auto res = make_shared<Result>(pattern);
const auto axis = Constant::create(element::i64, Shape{}, {1});
auto crop = make_shared<Split>(pattern, axis, 3);
auto res2 = make_shared<Result>(crop, "v0");
{
auto f = make_shared<Function>(OutputVector{res, res2}, SinkVector{assign},
ParameterVector{arg, arg2}, VariableVector{variable});
NodeVector nodes = f->get_ops();
EXPECT_EQ(nodes.size(), 10);
ParameterVector params = f->get_parameters();
EXPECT_EQ(params.size(), 2);
VariableVector variables = f->get_variables();
EXPECT_EQ(variables.size(), 1);
}
// autodetect variables
{
auto f = make_shared<Function>(OutputVector{res, res2}, SinkVector{assign},
ParameterVector{arg, arg2});
NodeVector nodes = f->get_ops();
EXPECT_EQ(nodes.size(), 10);
ParameterVector params = f->get_parameters();
EXPECT_EQ(params.size(), 2);
VariableVector variables = f->get_variables();
EXPECT_EQ(variables.size(), 1);
}
}
TEST(build_graph, build_graph_unregistred_variables)
{
using namespace opset7;
auto arg = make_shared<Parameter>(element::f32, Shape{2, 4});
auto arg2 = make_shared<Parameter>(element::f32, Shape{2, 2});
auto init_const = Constant::create(element::f32, Shape{2, 2}, {0, 0, 0, 0});
auto variable = make_shared<Variable>(VariableInfo{PartialShape::dynamic(), element::dynamic, "v0"});
auto variable_2 = make_shared<Variable>(VariableInfo{PartialShape::dynamic(), element::dynamic, "v1"});
auto read = make_shared<ReadValue>(init_const, variable);
auto read_2 = make_shared<ReadValue>(init_const, variable_2);
auto assign = make_shared<Assign>(read, variable);
auto assign_2 = make_shared<Assign>(read_2, variable_2);
assign->add_control_dependency(read);
std::vector<shared_ptr<Node>> args = {arg2, arg};
auto pattern = make_shared<Concat>(args, 1);
auto res = make_shared<Result>(pattern);
const auto axis = Constant::create(element::i64, Shape{}, {1});
auto crop = make_shared<Split>(pattern, axis, 3);
auto res2 = make_shared<Result>(crop, "v0");
EXPECT_ANY_THROW(make_shared<Function>(OutputVector{res, res2}, SinkVector{assign, assign_2},
ParameterVector{arg, arg2}, VariableVector{variable}));
}