From 77912ca06e50da435b1793e00b014ab14ad63459 Mon Sep 17 00:00:00 2001 From: Piotr Szmelczynski Date: Tue, 22 Jun 2021 08:44:31 +0200 Subject: [PATCH] Revise negative (#5955) * update spec * add RTTI macro * create visitor test * clean backend test file * add negative to type_prop tests of unary_ops * add validate_and_infer_types method * remove negative from type_propp unary_ops * create negative type_prop tests * remove boolean check from validate_and_infer_types * update supported types in spec * Remove check for signed numeric types * Remove type_prop test cases with non-signed type * Add zero sized negative test to interpreter manifest * Revert "update supported types in spec" This reverts commit a7ac3e4dc85e6d0408858c25d651e5699b6c5f5d. * Revert "update spec" This reverts commit 4c431d753df465e5b8a7bdc1925ed316f6c56a82. * Add minor changes to review op class * Add validation of inputs and outputs in evaluate * Use shape from host tensor to calculate element count * Minor changes in variable names of backend tests * Add SLT case with integer precision * Add operation to list of trusted ops * Address review comments: * Add bf16 precision to evaluate method * Use unary ops typed case tests for type_prop tests * Add end of line to interpreter manifest * Refactored visitor unit test * Fix typo in visitor test name Co-authored-by: ggalieroc --- .../single_layer_tests/activation.cpp | 1 + .../layer_tests_summary/utils/constants.py | 1 + ngraph/core/include/ngraph/op/negative.hpp | 3 +-- ngraph/core/src/op/negative.cpp | 15 +++++++-------- ngraph/test/CMakeLists.txt | 2 ++ ngraph/test/backend/negative.in.cpp | 18 ++++++------------ .../runtime/interpreter/unit_test.manifest | 3 +++ ngraph/test/type_prop/negative.cpp | 9 +++++++++ ngraph/test/visitors/op/ceiling.cpp | 4 ++-- ngraph/test/visitors/op/floor.cpp | 4 ++-- ngraph/test/visitors/op/log.cpp | 4 ++-- ngraph/test/visitors/op/negative.cpp | 13 +++++++++++++ ngraph/test/visitors/op/result.cpp | 4 ++-- ngraph/test/visitors/op/sqrt.cpp | 4 ++-- ngraph/test/visitors/op/squeeze.cpp | 4 ++-- 15 files changed, 55 insertions(+), 34 deletions(-) create mode 100644 ngraph/test/type_prop/negative.cpp create mode 100644 ngraph/test/visitors/op/negative.cpp diff --git a/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/single_layer_tests/activation.cpp b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/single_layer_tests/activation.cpp index 510e4039e2b..51e379a67f1 100644 --- a/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/single_layer_tests/activation.cpp +++ b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/single_layer_tests/activation.cpp @@ -64,6 +64,7 @@ const std::map>> activationTypes // List of operations that should be tested also with integer precision const std::map>> intActivationTypes = { + {Negative, {}}, {Ceiling, {}}, {Sqrt, {}}, {Tanh, {}}, diff --git a/inference-engine/tests/ie_test_utils/functional_test_utils/layer_tests_summary/utils/constants.py b/inference-engine/tests/ie_test_utils/functional_test_utils/layer_tests_summary/utils/constants.py index 7db26eb2895..24e42cd5e04 100644 --- a/inference-engine/tests/ie_test_utils/functional_test_utils/layer_tests_summary/utils/constants.py +++ b/inference-engine/tests/ie_test_utils/functional_test_utils/layer_tests_summary/utils/constants.py @@ -54,6 +54,7 @@ VERIFIED_OP_REFERENCES = [ 'MaxPool-1', 'Mish-4', 'Multiply-1', + 'Negative-1', 'NonMaxSuppression-4', 'NonMaxSuppression-5', 'PSROIPooling-1', diff --git a/ngraph/core/include/ngraph/op/negative.hpp b/ngraph/core/include/ngraph/op/negative.hpp index 69c7d39bdc0..1768a58c010 100644 --- a/ngraph/core/include/ngraph/op/negative.hpp +++ b/ngraph/core/include/ngraph/op/negative.hpp @@ -16,8 +16,7 @@ namespace ngraph class NGRAPH_API Negative : public util::UnaryElementwiseArithmetic { public: - static constexpr NodeTypeInfo type_info{"Negative", 0}; - const NodeTypeInfo& get_type_info() const override { return type_info; } + NGRAPH_RTTI_DECLARATION; /// \brief Constructs a negative operation. Negative() = default; /// \brief Constructs a negative operation. diff --git a/ngraph/core/src/op/negative.cpp b/ngraph/core/src/op/negative.cpp index f670ac19a2e..4ed3c44e53b 100644 --- a/ngraph/core/src/op/negative.cpp +++ b/ngraph/core/src/op/negative.cpp @@ -6,11 +6,12 @@ #include "itt.hpp" #include "ngraph/runtime/host_tensor.hpp" #include "ngraph/runtime/reference/negate.hpp" +#include "ngraph/validation_util.hpp" using namespace std; using namespace ngraph; -constexpr NodeTypeInfo op::Negative::type_info; +NGRAPH_RTTI_DEFINITION(op::v0::Negative, "Negative", 0, util::UnaryElementwiseArithmetic); op::Negative::Negative(const Output& arg) : UnaryElementwiseArithmetic(arg) @@ -48,11 +49,9 @@ namespace negativeop switch (arg0->get_element_type()) { - NGRAPH_TYPE_CASE(evaluate_negative, boolean, arg0, out, count); NGRAPH_TYPE_CASE(evaluate_negative, i32, arg0, out, count); NGRAPH_TYPE_CASE(evaluate_negative, i64, arg0, out, count); - NGRAPH_TYPE_CASE(evaluate_negative, u32, arg0, out, count); - NGRAPH_TYPE_CASE(evaluate_negative, u64, arg0, out, count); + NGRAPH_TYPE_CASE(evaluate_negative, bf16, arg0, out, count); NGRAPH_TYPE_CASE(evaluate_negative, f16, arg0, out, count); NGRAPH_TYPE_CASE(evaluate_negative, f32, arg0, out, count); default: rc = false; break; @@ -64,7 +63,10 @@ namespace negativeop bool op::Negative::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { NGRAPH_OP_SCOPE(v0_Negative_evaluate); - return negativeop::evaluate_negative(inputs[0], outputs[0], shape_size(get_output_shape(0))); + NGRAPH_CHECK(validate_host_tensor_vector(inputs, 1)); + NGRAPH_CHECK(validate_host_tensor_vector(outputs, 1)); + return negativeop::evaluate_negative( + inputs[0], outputs[0], shape_size(outputs[0]->get_shape())); } bool op::Negative::has_evaluate() const @@ -72,11 +74,8 @@ bool op::Negative::has_evaluate() const NGRAPH_OP_SCOPE(v0_Negative_has_evaluate); switch (get_input_element_type(0)) { - case ngraph::element::boolean: case ngraph::element::i32: case ngraph::element::i64: - case ngraph::element::u32: - case ngraph::element::u64: case ngraph::element::f16: case ngraph::element::f32: return true; default: break; diff --git a/ngraph/test/CMakeLists.txt b/ngraph/test/CMakeLists.txt index 278121669a8..2b7757f0527 100644 --- a/ngraph/test/CMakeLists.txt +++ b/ngraph/test/CMakeLists.txt @@ -167,6 +167,7 @@ set(SRC type_prop/mish.cpp type_prop/mod.cpp type_prop/mvn.cpp + type_prop/negative.cpp type_prop/non_max_suppression.cpp type_prop/non_zero.cpp type_prop/normalize.cpp @@ -257,6 +258,7 @@ set(SRC visitors/op/max_pool.cpp visitors/op/mod.cpp visitors/op/mvn.cpp + visitors/op/negative.cpp visitors/op/non_max_suppression.cpp visitors/op/normalize_l2.cpp visitors/op/one_hot.cpp diff --git a/ngraph/test/backend/negative.in.cpp b/ngraph/test/backend/negative.in.cpp index a092fe6f760..01aca08610d 100644 --- a/ngraph/test/backend/negative.in.cpp +++ b/ngraph/test/backend/negative.in.cpp @@ -2,13 +2,6 @@ // SPDX-License-Identifier: Apache-2.0 // -#include -#include -#include -#include -#include -#include - // clang-format off #ifdef ${BACKEND_NAME}_FLOAT_TOLERANCE_BITS #define DEFAULT_FLOAT_TOLERANCE_BITS ${BACKEND_NAME}_FLOAT_TOLERANCE_BITS @@ -49,15 +42,16 @@ NGRAPH_TEST(${BACKEND_NAME}, negative_i32) { auto shape_a = Shape{2, 5}; auto A = make_shared(element::i32, shape_a); - auto relu = make_shared(A); + auto negative = make_shared(A); auto shape_rt = Shape{2, 5}; - auto f = make_shared(relu, ParameterVector{A}); + auto f = make_shared(negative, ParameterVector{A}); std::vector a{1, 8, -8, 17, -2, 1, 8, -8, 17, -1}; + std::vector r{-1, -8, 8, -17, 2, -1, -8, 8, -17, 1}; auto test_case = test::TestCase(f); test_case.add_input(shape_a, a); - test_case.add_expected_output(shape_rt, {-1, -8, 8, -17, 2, -1, -8, 8, -17, 1}); + test_case.add_expected_output(shape_rt, r); test_case.run(); } @@ -65,9 +59,9 @@ NGRAPH_TEST(${BACKEND_NAME}, negative_f32) { auto shape_a = Shape{2, 5}; auto A = make_shared(element::f32, shape_a); - auto relu = make_shared(A); + auto negative = make_shared(A); auto shape_rt = Shape{2, 5}; - auto f = make_shared(relu, ParameterVector{A}); + auto f = make_shared(negative, ParameterVector{A}); std::vector a{1.35f, 8.76f, -8.0f, 17.234f, -2.121f, 1.0f, 8.7f, -8.92f, 17.0f, -1.0f}; diff --git a/ngraph/test/runtime/interpreter/unit_test.manifest b/ngraph/test/runtime/interpreter/unit_test.manifest index 799025f3b92..a76df269cdd 100644 --- a/ngraph/test/runtime/interpreter/unit_test.manifest +++ b/ngraph/test/runtime/interpreter/unit_test.manifest @@ -158,3 +158,6 @@ INTERPRETER.onnx_model_experimental_detectron_roi_feature_extractor # No evaluator for DeformableConv2D onnx_model_deformable_conv_2d + +# No support for unsigned types +INTERPRETER.zero_sized_negative diff --git a/ngraph/test/type_prop/negative.cpp b/ngraph/test/type_prop/negative.cpp new file mode 100644 index 00000000000..68313c2f544 --- /dev/null +++ b/ngraph/test/type_prop/negative.cpp @@ -0,0 +1,9 @@ +// Copyright (C) 2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "unary_ops.hpp" + +using Type = ::testing::Types; + +INSTANTIATE_TYPED_TEST_CASE_P(type_prop_negative, UnaryOperator, Type); diff --git a/ngraph/test/visitors/op/ceiling.cpp b/ngraph/test/visitors/op/ceiling.cpp index 11e71e1e9c6..327fb4ac4b3 100644 --- a/ngraph/test/visitors/op/ceiling.cpp +++ b/ngraph/test/visitors/op/ceiling.cpp @@ -5,7 +5,7 @@ #include "unary_ops.hpp" using Type = ::testing::Types>; -INSTANTIATE_TYPED_TEST_CASE_P(visitor_without_atrribute, +INSTANTIATE_TYPED_TEST_CASE_P(visitor_without_attribute, UnaryOperatorVisitor, Type, - UnaryOperatorTypeName); \ No newline at end of file + UnaryOperatorTypeName); diff --git a/ngraph/test/visitors/op/floor.cpp b/ngraph/test/visitors/op/floor.cpp index 98731229010..be2fb04372b 100644 --- a/ngraph/test/visitors/op/floor.cpp +++ b/ngraph/test/visitors/op/floor.cpp @@ -7,7 +7,7 @@ using Types = ::testing::Types, UnaryOperatorType>; -INSTANTIATE_TYPED_TEST_CASE_P(visitor_without_atrribute, +INSTANTIATE_TYPED_TEST_CASE_P(visitor_without_attribute, UnaryOperatorVisitor, Types, - UnaryOperatorTypeName); \ No newline at end of file + UnaryOperatorTypeName); diff --git a/ngraph/test/visitors/op/log.cpp b/ngraph/test/visitors/op/log.cpp index 5acb4971ba8..84e87eb6db3 100644 --- a/ngraph/test/visitors/op/log.cpp +++ b/ngraph/test/visitors/op/log.cpp @@ -5,7 +5,7 @@ using Types = ::testing::Types, UnaryOperatorType>; -INSTANTIATE_TYPED_TEST_CASE_P(visitor_without_atrribute, +INSTANTIATE_TYPED_TEST_CASE_P(visitor_without_attribute, UnaryOperatorVisitor, Types, - UnaryOperatorTypeName); \ No newline at end of file + UnaryOperatorTypeName); diff --git a/ngraph/test/visitors/op/negative.cpp b/ngraph/test/visitors/op/negative.cpp new file mode 100644 index 00000000000..769a629fad6 --- /dev/null +++ b/ngraph/test/visitors/op/negative.cpp @@ -0,0 +1,13 @@ +// Copyright (C) 2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "unary_ops.hpp" + +using Types = ::testing::Types, + UnaryOperatorType>; + +INSTANTIATE_TYPED_TEST_CASE_P(visitor_without_attribute, + UnaryOperatorVisitor, + Types, + UnaryOperatorTypeName); diff --git a/ngraph/test/visitors/op/result.cpp b/ngraph/test/visitors/op/result.cpp index df01ad5f913..27e0e45e891 100644 --- a/ngraph/test/visitors/op/result.cpp +++ b/ngraph/test/visitors/op/result.cpp @@ -7,7 +7,7 @@ using Types = ::testing::Types, UnaryOperatorType>; -INSTANTIATE_TYPED_TEST_CASE_P(visitor_without_atrribute, +INSTANTIATE_TYPED_TEST_CASE_P(visitor_without_attribute, UnaryOperatorVisitor, Types, - UnaryOperatorTypeName); \ No newline at end of file + UnaryOperatorTypeName); diff --git a/ngraph/test/visitors/op/sqrt.cpp b/ngraph/test/visitors/op/sqrt.cpp index 5e26c542348..1df6ae6420a 100644 --- a/ngraph/test/visitors/op/sqrt.cpp +++ b/ngraph/test/visitors/op/sqrt.cpp @@ -6,7 +6,7 @@ using Types = ::testing::Types, UnaryOperatorType>; -INSTANTIATE_TYPED_TEST_CASE_P(visitor_without_atrribute, +INSTANTIATE_TYPED_TEST_CASE_P(visitor_without_attribute, UnaryOperatorVisitor, Types, - UnaryOperatorTypeName); \ No newline at end of file + UnaryOperatorTypeName); diff --git a/ngraph/test/visitors/op/squeeze.cpp b/ngraph/test/visitors/op/squeeze.cpp index a8b0c2c488c..9c6813af16f 100644 --- a/ngraph/test/visitors/op/squeeze.cpp +++ b/ngraph/test/visitors/op/squeeze.cpp @@ -6,7 +6,7 @@ using Types = ::testing::Types, UnaryOperatorType>; -INSTANTIATE_TYPED_TEST_CASE_P(visitor_without_atrribute, +INSTANTIATE_TYPED_TEST_CASE_P(visitor_without_attribute, UnaryOperatorVisitor, Types, - UnaryOperatorTypeName); \ No newline at end of file + UnaryOperatorTypeName);