From b3050c268aa27bfc813581a8adbb612c9e4a5144 Mon Sep 17 00:00:00 2001 From: Wilson Seok Date: Thu, 23 Sep 2021 21:19:45 -0700 Subject: [PATCH] Migrate acos operation from ngraph backend test to template plugin reference test (#7461) * Remove fp16 of Convert layer test from skip_tests.config.cpp as it works now * update repo * add acos in template plugin reference test * Create visitor API test for target operation Acos-1 * remove acos backend test * remove acos backend test * add test casses of int ata type * remove boolean from acos evaluate --- .../tests/functional/op_reference/acos.cpp | 87 +++++++++++++++++++ ngraph/core/src/op/acos.cpp | 2 - ngraph/test/CMakeLists.txt | 2 +- ngraph/test/backend/acos.in.cpp | 54 ------------ ngraph/test/visitors/op/acos.cpp | 9 ++ 5 files changed, 97 insertions(+), 57 deletions(-) create mode 100644 docs/template_plugin/tests/functional/op_reference/acos.cpp delete mode 100644 ngraph/test/backend/acos.in.cpp create mode 100644 ngraph/test/visitors/op/acos.cpp diff --git a/docs/template_plugin/tests/functional/op_reference/acos.cpp b/docs/template_plugin/tests/functional/op_reference/acos.cpp new file mode 100644 index 00000000000..a3d66bc1b0e --- /dev/null +++ b/docs/template_plugin/tests/functional/op_reference/acos.cpp @@ -0,0 +1,87 @@ +// Copyright (C) 2018-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include + +#include +#include +#include +#include +#include + +#include "base_reference_test.hpp" + +using namespace ngraph; + +namespace reference_tests { +namespace { + +struct AcosParams { + Tensor input; + Tensor expected; +}; + +struct Builder : ParamsBuilder { + REFERENCE_TESTS_ADD_SET_PARAM(Builder, input); + REFERENCE_TESTS_ADD_SET_PARAM(Builder, expected); +}; + +class ReferenceAcosLayerTest : public testing::TestWithParam, public CommonReferenceTest { +public: + void SetUp() override { + auto params = GetParam(); + function = CreateFunction(params.input.shape, params.input.type); + inputData = {params.input.data}; + refOutData = {params.expected.data}; + } + static std::string getTestCaseName(const testing::TestParamInfo& obj) { + auto param = obj.param; + std::ostringstream result; + result << "shape=" << param.input.shape << "_"; + result << "type=" << param.input.type; + return result.str(); + } + +private: + static std::shared_ptr CreateFunction(const Shape& shape, const element::Type& type) { + const auto in = std::make_shared(type, shape); + const auto acos = std::make_shared(in); + return std::make_shared(NodeVector {acos}, ParameterVector {in}); + } +}; + +TEST_P(ReferenceAcosLayerTest, AcosWithHardcodedRefs) { + Exec(); +} + +} // namespace + +INSTANTIATE_TEST_SUITE_P( + smoke_Acos_With_Hardcoded_Refs, ReferenceAcosLayerTest, + ::testing::Values(Builder {} + .input({{11}, element::f16, std::vector {-1.f, -0.75f, -0.5f, -0.25f, -0.125f, + 0.f, 0.125f, 0.25f, 0.5f, 0.75f, 1.f}}) + .expected({{11}, element::f16, std::vector {3.14159265f, 2.41885841f, 2.09439510f, 1.82347658f, 1.69612416f, + 1.57079633f, 1.44546850f, 1.31811607f, 1.04719755f, 0.72273425f, + 0.00000000f}}), + Builder {} + .input({{11}, element::f32, std::vector {-1.f, -0.75f, -0.5f, -0.25f, -0.125f, + 0.f, 0.125f, 0.25f, 0.5f, 0.75f, 1.f}}) + .expected({{11}, element::f32, std::vector {3.14159265f, 2.41885841f, 2.09439510f, 1.82347658f, 1.69612416f, + 1.57079633f, 1.44546850f, 1.31811607f, 1.04719755f, 0.72273425f, + 0.00000000f}}), + Builder {} + .input({{3}, element::i32, std::vector {-1, 0, 1}}) + .expected({{3}, element::i32, std::vector {3, 1, 0}}), + Builder {} + .input({{3}, element::i64, std::vector {-1, 0, 1}}) + .expected({{3}, element::i64, std::vector {3, 1, 0}}), + Builder {} + .input({{2}, element::u32, std::vector {0, 1}}) + .expected({{2}, element::u32, std::vector {1, 0}}), + Builder {} + .input({{2}, element::u64, std::vector {0, 1}}) + .expected({{2}, element::u64, std::vector {1, 0}})), + ReferenceAcosLayerTest::getTestCaseName); +} // namespace reference_tests \ No newline at end of file diff --git a/ngraph/core/src/op/acos.cpp b/ngraph/core/src/op/acos.cpp index c0ee6ec4920..aec704e1d2a 100644 --- a/ngraph/core/src/op/acos.cpp +++ b/ngraph/core/src/op/acos.cpp @@ -43,7 +43,6 @@ bool evaluate_acos(const ov::HostTensorPtr& arg0, const ov::HostTensorPtr& out, out->set_unary(arg0); switch (arg0->get_element_type()) { - NGRAPH_TYPE_CASE(evaluate_acos, boolean, arg0, out, count); NGRAPH_TYPE_CASE(evaluate_acos, i32, arg0, out, count); NGRAPH_TYPE_CASE(evaluate_acos, i64, arg0, out, count); NGRAPH_TYPE_CASE(evaluate_acos, u32, arg0, out, count); @@ -72,7 +71,6 @@ bool ov::op::v0::Acos::has_evaluate() const { case ngraph::element::u64: case ngraph::element::f16: case ngraph::element::f32: - case ngraph::element::boolean: return true; default: break; diff --git a/ngraph/test/CMakeLists.txt b/ngraph/test/CMakeLists.txt index 5610a1228e3..411e1ac6a02 100644 --- a/ngraph/test/CMakeLists.txt +++ b/ngraph/test/CMakeLists.txt @@ -245,6 +245,7 @@ set(SRC visitors/partial_shape.cpp visitors/user_op.cpp visitors/value_map.cpp + visitors/op/acos.cpp visitors/op/acosh.cpp visitors/op/adaptive_avg_pool.cpp visitors/op/adaptive_max_pool.cpp @@ -411,7 +412,6 @@ add_subdirectory(util) set(MULTI_TEST_SRC backend/abc.in.cpp backend/abs.in.cpp - backend/acos.in.cpp backend/adaptive_avg_pool.in.cpp backend/adaptive_max_pool.in.cpp backend/add.in.cpp diff --git a/ngraph/test/backend/acos.in.cpp b/ngraph/test/backend/acos.in.cpp deleted file mode 100644 index 2867e5f9457..00000000000 --- a/ngraph/test/backend/acos.in.cpp +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright (C) 2018-2021 Intel Corporation -// 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 -#endif - -#ifdef ${BACKEND_NAME}_DOUBLE_TOLERANCE_BITS -#define DEFAULT_DOUBLE_TOLERANCE_BITS ${BACKEND_NAME}_DOUBLE_TOLERANCE_BITS -#endif -// clang-format on - -#include "gtest/gtest.h" -#include "ngraph/ngraph.hpp" -#include "util/engine/test_engines.hpp" -#include "util/test_case.hpp" -#include "util/test_control.hpp" - -using namespace std; -using namespace ngraph; - -static string s_manifest = "${MANIFEST}"; -using TestEngine = test::ENGINE_CLASS_NAME(${BACKEND_NAME}); - -NGRAPH_TEST(${BACKEND_NAME}, acos) { - Shape shape{11}; - auto A = make_shared(element::f32, shape); - auto f = make_shared(make_shared(A), ParameterVector{A}); - - auto test_case = test::TestCase(f); - test_case.add_input({-1.f, -0.75f, -0.5f, -0.25f, -0.125f, 0.f, 0.125f, 0.25f, 0.5f, 0.75f, 1.f}); - test_case.add_expected_output(shape, - {3.14159265f, - 2.41885841f, - 2.09439510f, - 1.82347658f, - 1.69612416f, - 1.57079633f, - 1.44546850f, - 1.31811607f, - 1.04719755f, - 0.72273425f, - 0.00000000f}); - test_case.run(); -} diff --git a/ngraph/test/visitors/op/acos.cpp b/ngraph/test/visitors/op/acos.cpp new file mode 100644 index 00000000000..6eec02ffd6e --- /dev/null +++ b/ngraph/test/visitors/op/acos.cpp @@ -0,0 +1,9 @@ +// Copyright (C) 2018-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "unary_ops.hpp" + +using Type = ::testing::Types>; + +INSTANTIATE_TYPED_TEST_SUITE_P(visitor_without_attribute, UnaryOperatorVisitor, Type, UnaryOperatorTypeName);