Skip to content

Commit

Permalink
[TEST] Keep assign node in exec_graph_info
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Peskov <[email protected]>
  • Loading branch information
AlexPeskov committed Aug 12, 2020
1 parent fd47625 commit 034c883
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright (C) 2020 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//

#include "execution_graph_tests/keep_assing.hpp"
#include "common_test_utils/test_constants.hpp"

using namespace LayerTestsDefinitions;

namespace {

INSTANTIATE_TEST_CASE_P(KeepAssign, ExecGraphKeepAssignNode,
::testing::Values(CommonTestUtils::DEVICE_CPU),
ExecGraphKeepAssignNode::getTestCaseName);

} // namespace
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright (C) 2020 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//

#include "gtest/gtest.h"

namespace LayerTestsDefinitions {

class ExecGraphKeepAssignNode : public testing::TestWithParam<std::string> {
public:
static std::string getTestCaseName(testing::TestParamInfo<std::string> obj);
};

} // namespace LayerTestsDefinitions
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// Copyright (C) 2020 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//

#include "execution_graph_tests/keep_assing.hpp"

#include <ngraph/ngraph.hpp>
#include <inference_engine.hpp>

namespace LayerTestsDefinitions {

std::string ExecGraphKeepAssignNode::getTestCaseName(testing::TestParamInfo<std::string> obj) {
std::string targetDevice = obj.param;
return "Dev=" + targetDevice;
}

/**
* Assign/MemoryOutput operation node may hanging in air (leaf, has no consumer).
* So exec graph may lose it. Will check that it's present in dumped exec graph.
*/
TEST_P(ExecGraphKeepAssignNode, KeepAssignNode) {
auto device_name = this->GetParam();
ngraph::Shape shape = {3, 2};
ngraph::element::Type type = ngraph::element::f32;

using std::make_shared;
using namespace ngraph::op;

// Some simple graph with Memory(Assign) node // in read //
auto input = make_shared<Parameter>(type, shape); // | \ / //
auto mem_i = make_shared<Constant>(type, shape, 0); // | mul //
auto mem_r = make_shared<ReadValue>(mem_i, "id"); // | / \ //
auto mul = make_shared<Multiply>(mem_r, input); // sum assign //
auto mem_w = make_shared<Assign>(mul, "id"); // | //
auto sum = make_shared<Add>(mul, input); // out //

mem_w->add_control_dependency(mem_r);
sum->add_control_dependency(mem_w);

auto function = std::make_shared<ngraph::Function>(
ngraph::NodeVector {sum},
ngraph::ParameterVector {input},
"SimpleNet");

// Load into plugin and get exec graph
auto ie = InferenceEngine::Core();
auto net = InferenceEngine::CNNNetwork(function);
auto exec_net = ie.LoadNetwork(net, device_name);
auto exec_graph = exec_net.GetExecGraphInfo();
auto exec_ops = exec_graph.getFunction()->get_ops();

// Check Memory(Assign) node existence
bool assign_node_found;
for (auto &node : exec_ops) {
auto var = node->get_rt_info()["layerType"];
auto s_val = std::dynamic_pointer_cast<ngraph::VariantImpl<std::string>>(var);

if (s_val->get() == "MemoryOutput") {
assign_node_found = true;
break;
}
}
ASSERT_TRUE(assign_node_found);
}

} // namespace LayerTestsDefinitions

0 comments on commit 034c883

Please sign in to comment.