Revise Result Op (#5637)

* Add type prop tests for shape and type propagation

* Add visitor test

* Add SLT test class for result op

* Add SSLT for result op

* Add CPU SLT

* Add backend test

* Applying review comments - fix typo in slt, replace type info with NGRAPH_RTTI_DEFINITION

* Applying changes after review comments

* Add result to trusted ops list

* fix adding redundant nodes in slt
This commit is contained in:
Bartosz Lesniewski authored and GitHub committed 2021-05-25 07:06:04 +03:00
1 parent 11af0bd904
commit 2d0707dd1a
12 files changed
+242 -3

No files matched your search

@@ -0,0 +1,34 @@
// Copyright (C) 2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include <vector>
#include "shared_test_classes/single_layer/result.hpp"
using namespace ngraph;
using namespace LayerTestsDefinitions;
namespace {
TEST_P(ResultLayerTest, Serialize) {
Serialize();
}
std::vector<InferenceEngine::SizeVector> inputDims = {
{7}, {1000}, {3, 5}, {65, 33}, {33, 65},
{1, 1000}, {223, 217, 21}, {3, 4, 5, 1}, {3, 4, 1, 5, 1}};
std::vector<InferenceEngine::Precision> inputPrecisions = {
InferenceEngine::Precision::U8, InferenceEngine::Precision::FP32,
InferenceEngine::Precision::I32,
};
ConfigMap config;
INSTANTIATE_TEST_CASE_P(
smoke_ResultLayerTest, ResultLayerTest,
::testing::Combine(::testing::ValuesIn(inputDims),
::testing::ValuesIn(inputPrecisions),
::testing::Values(CommonTestUtils::DEVICE_CPU),
::testing::Values(config)));
} // namespace
@@ -0,0 +1,31 @@
// Copyright (C) 2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include <vector>
#include "shared_test_classes/single_layer/result.hpp"
using namespace LayerTestsDefinitions;
using namespace InferenceEngine;
namespace {
std::vector<InferenceEngine::SizeVector> inputDims = {
{7}, {1000}, {3, 5}, {65, 33}, {33, 65},
{1, 1000}, {223, 217, 21}, {3, 4, 5, 1}, {3, 4, 1, 5, 1}};
std::vector<InferenceEngine::Precision> inputPrecisions = {
InferenceEngine::Precision::U8, InferenceEngine::Precision::FP32,
InferenceEngine::Precision::I32,
};
ConfigMap config;
INSTANTIATE_TEST_CASE_P(
smoke_ResultLayerTest, ResultLayerTest,
::testing::Combine(::testing::ValuesIn(inputDims),
::testing::ValuesIn(inputPrecisions),
::testing::Values(CommonTestUtils::DEVICE_CPU),
::testing::Values(config)),
ResultLayerTest::getTestCaseName);
} // namespace
@@ -0,0 +1,14 @@
// Copyright (C) 2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include <vector>
#include "shared_test_classes/single_layer/result.hpp"
namespace LayerTestsDefinitions {
TEST_P(ResultLayerTest, CompareWithRefs) {
Run();
}
} // namespace LayerTestsDefinitions
@@ -0,0 +1,35 @@
// Copyright (C) 2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include <memory>
#include <string>
#include <tuple>
#include <vector>
#include "shared_test_classes/base/layer_test_utils.hpp"
#include "ngraph_functions/builders.hpp"
#include "ngraph_functions/utils/ngraph_helpers.hpp"
namespace LayerTestsDefinitions {
using ConfigMap = typename std::map<std::string, std::string>;
using ResultTestParamSet = typename std::tuple<
InferenceEngine::SizeVector, // Input shapes
InferenceEngine::Precision, // Input precision
LayerTestsUtils::TargetDevice, // Device name
ConfigMap>; // Additional network configuration
class ResultLayerTest : public testing::WithParamInterface<ResultTestParamSet>,
virtual public LayerTestsUtils::LayerTestsCommon {
public:
static std::string getTestCaseName(testing::TestParamInfo<ResultTestParamSet> obj);
protected:
void SetUp() override;
};
} // namespace LayerTestsDefinitions
@@ -0,0 +1,35 @@
// Copyright (C) 2018-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include "shared_test_classes/single_layer/result.hpp"
namespace LayerTestsDefinitions {
std::string ResultLayerTest::getTestCaseName(testing::TestParamInfo<ResultTestParamSet> obj) {
std::vector<size_t> inputShape;
InferenceEngine::Precision inputPrecision;
std::string targetDevice;
ConfigMap additionalConfig;
std::tie(inputShape, inputPrecision, targetDevice, additionalConfig) = obj.param;
std::ostringstream result;
result << "IS=" << CommonTestUtils::vec2str(inputShape) << "_";
result << "inPRC=" << inputPrecision.name() << "_";
result << "targetDevice=" << targetDevice;
return result.str();
}
void ResultLayerTest::SetUp() {
std::vector<size_t> inputShape;
InferenceEngine::Precision inputPrecision;
std::string targetDevice;
ConfigMap additionalConfig;
std::tie(inputShape, inputPrecision, targetDevice, additionalConfig) = GetParam();
auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(inputPrecision);
auto params = ngraph::builder::makeParams(ngPrc, {inputShape});
const ngraph::ResultVector results{std::make_shared<ngraph::opset1::Result>(params[0])};
function = std::make_shared<ngraph::Function>(results, params, "result");
}
} // namespace LayerTestsDefinitions
@@ -71,6 +71,7 @@ VERIFIED_OP_REFERENCES = [
'RegionYOLO-1',
'Relu-1',
'ReorgYOLO-2',
'Result-1'
'Round-5',
'ScatterNDUpdate-4',
'ShapeOf-1',
+2 -2
View File
@@ -17,8 +17,8 @@ namespace ngraph
class NGRAPH_API Result : public Op
{
public:
static constexpr NodeTypeInfo type_info{"Result", 0};
const NodeTypeInfo& get_type_info() const override { return type_info; }
NGRAPH_RTTI_DECLARATION;
/// \brief Allows a value to be used as a function result.
Result() = default;
/// \brief Allows a value to be used as a function result.
+1 -1
View File
@@ -14,7 +14,7 @@
using namespace std;
using namespace ngraph;
constexpr NodeTypeInfo op::Result::type_info;
NGRAPH_RTTI_DEFINITION(op::v0::Result, "Result", 0);
op::Result::Result(const Output<Node>& arg, bool needs_default_layout)
: Op({arg})
+3
View File
@@ -173,6 +173,7 @@ set(SRC
type_prop/reduce_l2.cpp
type_prop/reorg_yolo.cpp
type_prop/reshape.cpp
type_prop/result.cpp
type_prop/reverse.cpp
type_prop/reverse_sequence.cpp
type_prop/roi_align.cpp
@@ -256,6 +257,7 @@ set(SRC
visitors/op/region_yolo.cpp
visitors/op/reorg_yolo.cpp
visitors/op/reshape.cpp
visitors/op/result.cpp
visitors/op/reverse.cpp
visitors/op/reverse_sequence.cpp
visitors/op/rnn_cell.cpp
@@ -405,6 +407,7 @@ set(MULTI_TEST_SRC
backend/relu.in.cpp
backend/reorg_yolo.in.cpp
backend/reshape.in.cpp
backend/result.in.cpp
backend/reverse_sequence.in.cpp
backend/reverse.in.cpp
backend/roi_pooling.in.cpp
+29
View File
@@ -0,0 +1,29 @@
// Copyright (C) 2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include "gtest/gtest.h"
#include "ngraph/op/result.hpp"
#include "util/engine/test_engines.hpp"
#include "util/test_case.hpp"
#include "util/test_control.hpp"
using namespace ngraph;
static std::string s_manifest = "${MANIFEST}";
using TestEngine = test::ENGINE_CLASS_NAME(${BACKEND_NAME});
NGRAPH_TEST(${BACKEND_NAME}, result)
{
Shape shape_a{2, 2};
auto a = std::make_shared<op::Parameter>(element::f32, shape_a);
auto f = std::make_shared<Function>(std::make_shared<op::v0::Result>(a), ParameterVector{a});
std::vector<float> a_values{1, 2, 3, 5};
auto test_case = test::TestCase<TestEngine>(f);
test_case.add_input<float>(a_values);
test_case.add_expected_output<float>(shape_a, a_values);
test_case.run();
}
+32
View File
@@ -0,0 +1,32 @@
// Copyright (C) 2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include "gtest/gtest.h"
#include "ngraph/ngraph.hpp"
#include "ngraph/opsets/opset1.hpp"
#include "util/type_prop.hpp"
using namespace std;
using namespace ngraph;
TEST(type_prop, result)
{
const auto arg_shape =Shape{1, 2, 3, 4, 5};
auto arg = make_shared<opset1::Constant>(element::f32, arg_shape);
auto result = make_shared<opset1::Result>(arg);
EXPECT_EQ(result->get_output_element_type(0), element::f32);
EXPECT_EQ(result->get_output_shape(0), arg_shape);
}
TEST(type_prop, result_dynamic_shape)
{
auto arg = make_shared<opset1::Parameter>(element::f32, PartialShape::dynamic());
auto result = make_shared<opset1::Result>(arg);
EXPECT_EQ(result->get_output_element_type(0), element::f32);
EXPECT_TRUE(result->get_output_partial_shape(0).same_scheme(PartialShape::dynamic()));
}
+25
View File
@@ -0,0 +1,25 @@
// Copyright (C) 2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include "gtest/gtest.h"
#include "ngraph/ngraph.hpp"
#include "ngraph/opsets/opset1.hpp"
#include "util/visitor.hpp"
using namespace std;
using namespace ngraph;
using ngraph::test::NodeBuilder;
using ngraph::test::ValueMap;
TEST(attributes, result)
{
NodeBuilder::get_ops().register_factory<opset1::Squeeze>();
const auto data_node = make_shared<op::Parameter>(element::f32, Shape{1});
const auto result = make_shared<op::Result>(data_node);
NodeBuilder builder(result);
const auto expected_attr_count = 0;
EXPECT_EQ(builder.get_value_map_size(), expected_attr_count);
}