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 commita7ac3e4dc8
. * Revert "update spec" This reverts commit4c431d753d
. * 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 <gabriele.galiero.casay@intel.com>
This commit is contained in:
parent
6926d5d639
commit
77912ca06e
@ -64,6 +64,7 @@ const std::map<ActivationTypes, std::vector<std::vector<float>>> activationTypes
|
||||
|
||||
// List of operations that should be tested also with integer precision
|
||||
const std::map<ActivationTypes, std::vector<std::vector<float>>> intActivationTypes = {
|
||||
{Negative, {}},
|
||||
{Ceiling, {}},
|
||||
{Sqrt, {}},
|
||||
{Tanh, {}},
|
||||
|
@ -54,6 +54,7 @@ VERIFIED_OP_REFERENCES = [
|
||||
'MaxPool-1',
|
||||
'Mish-4',
|
||||
'Multiply-1',
|
||||
'Negative-1',
|
||||
'NonMaxSuppression-4',
|
||||
'NonMaxSuppression-5',
|
||||
'PSROIPooling-1',
|
||||
|
@ -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.
|
||||
|
@ -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<Node>& 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;
|
||||
|
@ -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
|
||||
|
@ -2,13 +2,6 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#include <algorithm>
|
||||
#include <cinttypes>
|
||||
#include <cmath>
|
||||
#include <cstdlib>
|
||||
#include <random>
|
||||
#include <string>
|
||||
|
||||
// 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<op::Parameter>(element::i32, shape_a);
|
||||
auto relu = make_shared<op::Negative>(A);
|
||||
auto negative = make_shared<op::Negative>(A);
|
||||
auto shape_rt = Shape{2, 5};
|
||||
auto f = make_shared<Function>(relu, ParameterVector{A});
|
||||
auto f = make_shared<Function>(negative, ParameterVector{A});
|
||||
|
||||
std::vector<int32_t> a{1, 8, -8, 17, -2, 1, 8, -8, 17, -1};
|
||||
std::vector<int32_t> r{-1, -8, 8, -17, 2, -1, -8, 8, -17, 1};
|
||||
|
||||
auto test_case = test::TestCase<TestEngine>(f);
|
||||
test_case.add_input<int32_t>(shape_a, a);
|
||||
test_case.add_expected_output<int32_t>(shape_rt, {-1, -8, 8, -17, 2, -1, -8, 8, -17, 1});
|
||||
test_case.add_expected_output<int32_t>(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<op::Parameter>(element::f32, shape_a);
|
||||
auto relu = make_shared<op::Negative>(A);
|
||||
auto negative = make_shared<op::Negative>(A);
|
||||
auto shape_rt = Shape{2, 5};
|
||||
auto f = make_shared<Function>(relu, ParameterVector{A});
|
||||
auto f = make_shared<Function>(negative, ParameterVector{A});
|
||||
|
||||
std::vector<float> a{1.35f, 8.76f, -8.0f, 17.234f, -2.121f, 1.0f, 8.7f, -8.92f, 17.0f, -1.0f};
|
||||
|
||||
|
@ -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
|
||||
|
9
ngraph/test/type_prop/negative.cpp
Normal file
9
ngraph/test/type_prop/negative.cpp
Normal file
@ -0,0 +1,9 @@
|
||||
// Copyright (C) 2021 Intel Corporation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#include "unary_ops.hpp"
|
||||
|
||||
using Type = ::testing::Types<ngraph::op::Negative>;
|
||||
|
||||
INSTANTIATE_TYPED_TEST_CASE_P(type_prop_negative, UnaryOperator, Type);
|
@ -5,7 +5,7 @@
|
||||
#include "unary_ops.hpp"
|
||||
using Type = ::testing::Types<UnaryOperatorType<ngraph::op::v0::Ceiling, element::f32>>;
|
||||
|
||||
INSTANTIATE_TYPED_TEST_CASE_P(visitor_without_atrribute,
|
||||
INSTANTIATE_TYPED_TEST_CASE_P(visitor_without_attribute,
|
||||
UnaryOperatorVisitor,
|
||||
Type,
|
||||
UnaryOperatorTypeName);
|
||||
UnaryOperatorTypeName);
|
||||
|
@ -7,7 +7,7 @@
|
||||
using Types = ::testing::Types<UnaryOperatorType<ngraph::op::v0::Floor, element::f32>,
|
||||
UnaryOperatorType<ngraph::op::v0::Floor, element::f16>>;
|
||||
|
||||
INSTANTIATE_TYPED_TEST_CASE_P(visitor_without_atrribute,
|
||||
INSTANTIATE_TYPED_TEST_CASE_P(visitor_without_attribute,
|
||||
UnaryOperatorVisitor,
|
||||
Types,
|
||||
UnaryOperatorTypeName);
|
||||
UnaryOperatorTypeName);
|
||||
|
@ -5,7 +5,7 @@
|
||||
using Types = ::testing::Types<UnaryOperatorType<ngraph::op::v0::Log, element::f32>,
|
||||
UnaryOperatorType<ngraph::op::v0::Log, element::f16>>;
|
||||
|
||||
INSTANTIATE_TYPED_TEST_CASE_P(visitor_without_atrribute,
|
||||
INSTANTIATE_TYPED_TEST_CASE_P(visitor_without_attribute,
|
||||
UnaryOperatorVisitor,
|
||||
Types,
|
||||
UnaryOperatorTypeName);
|
||||
UnaryOperatorTypeName);
|
||||
|
13
ngraph/test/visitors/op/negative.cpp
Normal file
13
ngraph/test/visitors/op/negative.cpp
Normal file
@ -0,0 +1,13 @@
|
||||
// Copyright (C) 2021 Intel Corporation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#include "unary_ops.hpp"
|
||||
|
||||
using Types = ::testing::Types<UnaryOperatorType<ngraph::op::v0::Negative, element::f32>,
|
||||
UnaryOperatorType<ngraph::op::v0::Negative, element::i32>>;
|
||||
|
||||
INSTANTIATE_TYPED_TEST_CASE_P(visitor_without_attribute,
|
||||
UnaryOperatorVisitor,
|
||||
Types,
|
||||
UnaryOperatorTypeName);
|
@ -7,7 +7,7 @@
|
||||
using Types = ::testing::Types<UnaryOperatorType<ngraph::op::v0::Result, element::f32>,
|
||||
UnaryOperatorType<ngraph::op::v0::Result, element::f16>>;
|
||||
|
||||
INSTANTIATE_TYPED_TEST_CASE_P(visitor_without_atrribute,
|
||||
INSTANTIATE_TYPED_TEST_CASE_P(visitor_without_attribute,
|
||||
UnaryOperatorVisitor,
|
||||
Types,
|
||||
UnaryOperatorTypeName);
|
||||
UnaryOperatorTypeName);
|
||||
|
@ -6,7 +6,7 @@
|
||||
using Types = ::testing::Types<UnaryOperatorType<ngraph::op::v0::Sqrt, element::f32>,
|
||||
UnaryOperatorType<ngraph::op::v0::Sqrt, element::f16>>;
|
||||
|
||||
INSTANTIATE_TYPED_TEST_CASE_P(visitor_without_atrribute,
|
||||
INSTANTIATE_TYPED_TEST_CASE_P(visitor_without_attribute,
|
||||
UnaryOperatorVisitor,
|
||||
Types,
|
||||
UnaryOperatorTypeName);
|
||||
UnaryOperatorTypeName);
|
||||
|
@ -6,7 +6,7 @@
|
||||
using Types = ::testing::Types<UnaryOperatorType<ngraph::op::v0::Squeeze, element::f32>,
|
||||
UnaryOperatorType<ngraph::op::v0::Squeeze, element::f16>>;
|
||||
|
||||
INSTANTIATE_TYPED_TEST_CASE_P(visitor_without_atrribute,
|
||||
INSTANTIATE_TYPED_TEST_CASE_P(visitor_without_attribute,
|
||||
UnaryOperatorVisitor,
|
||||
Types,
|
||||
UnaryOperatorTypeName);
|
||||
UnaryOperatorTypeName);
|
||||
|
Loading…
Reference in New Issue
Block a user