From ee2f99ea89583f0cc5c34fe633dfbe900f4d1741 Mon Sep 17 00:00:00 2001 From: Mateusz Tabaka Date: Tue, 3 Nov 2020 11:12:38 +0100 Subject: [PATCH] Remove using SortType and using Mode from TopK --- .../convert_ngraph_to_cnn_network_tests.cpp | 4 +- .../algebraic_simplification.cpp | 4 +- .../transformations/nop_elimination.cpp | 4 +- .../plugin/cpu/bfloat16/topk_inputs_i32.cpp | 4 +- .../single_layer_tests/topk.cpp | 14 ++-- .../single_layer_tests/topk.cpp | 14 ++-- .../single_layer_tests/topk.cpp | 14 ++-- .../include/single_layer_tests/topk.hpp | 6 +- .../shared/src/single_layer_tests/topk.cpp | 10 +-- ngraph/core/include/ngraph/op/topk.hpp | 23 +++--- .../include/ngraph/runtime/reference/topk.hpp | 14 ++-- ngraph/core/src/op/topk.cpp | 22 +++--- .../onnx_import/utils/arg_min_max_factory.hpp | 2 +- .../frontend/onnx_import/src/op/hardmax.cpp | 4 +- ngraph/frontend/onnx_import/src/op/topk.cpp | 16 ++--- .../src/utils/arg_min_max_factory.cpp | 8 +-- ngraph/test/attributes.cpp | 4 +- ngraph/test/backend/topk.in.cpp | 70 +++++++++---------- ngraph/test/eval.cpp | 6 +- 19 files changed, 120 insertions(+), 123 deletions(-) diff --git a/inference-engine/tests/functional/inference_engine/cnn_network/convert_ngraph_to_cnn_network_tests.cpp b/inference-engine/tests/functional/inference_engine/cnn_network/convert_ngraph_to_cnn_network_tests.cpp index 372c169dd7a..0de254e9064 100644 --- a/inference-engine/tests/functional/inference_engine/cnn_network/convert_ngraph_to_cnn_network_tests.cpp +++ b/inference-engine/tests/functional/inference_engine/cnn_network/convert_ngraph_to_cnn_network_tests.cpp @@ -158,7 +158,7 @@ TEST(ConvertFunctionToCNNNetworkTests, ConvertTopKWithOneInput) { ngraph::Shape const_shape = {}; std::vector val = {5}; auto k = std::make_shared(ngraph::element::i64, const_shape, val); - auto topK = std::make_shared(param, k, 2, ngraph::opset4::TopK::Mode::MAX, ngraph::opset4::TopK::SortType::SORT_VALUES); + auto topK = std::make_shared(param, k, 2, ngraph::op::TopKMode::MAX, ngraph::op::TopKSortType::SORT_VALUES); topK->set_friendly_name("topK"); auto result = std::make_shared(topK->output(1)); @@ -391,4 +391,4 @@ TEST(ConvertFunctionToCNNNetworkTests, NonUniqueNamesParametersNegative) { } catch(InferenceEngine::details::InferenceEngineException & e) { EXPECT_THAT(e.what(), testing::HasSubstr(std::string("Detected two output operations with the same name:"))); } -} \ No newline at end of file +} diff --git a/inference-engine/tests/functional/inference_engine/transformations/algebraic_simplification.cpp b/inference-engine/tests/functional/inference_engine/transformations/algebraic_simplification.cpp index da87dc986f5..1b38faac805 100644 --- a/inference-engine/tests/functional/inference_engine/transformations/algebraic_simplification.cpp +++ b/inference-engine/tests/functional/inference_engine/transformations/algebraic_simplification.cpp @@ -258,7 +258,7 @@ TEST(algebraic_simplification, replace_transpose_with_reshape) { k = make_shared(element::i64, Shape{}, std::vector{shape[last_dim].get_length()}); } A1 = make_shared(param, k, last_dim, - op::v1::TopK::Mode::MAX, op::v1::TopK::SortType::NONE); + op::TopKMode::MAX, op::TopKSortType::NONE); } else { A1 = make_shared(param); } @@ -350,7 +350,7 @@ TEST(algebraic_simplification, gather_3d_indices_constant_axis_1) { shared_ptr A1; if (multiout) { auto last_dim = pshape.rank().get_length() - 1; - A1 = make_shared(A, op::Constant::create(element::i64, {}, {1}), last_dim, op::v1::TopK::Mode::MAX, op::v1::TopK::SortType::NONE); + A1 = make_shared(A, op::Constant::create(element::i64, {}, {1}), last_dim, op::TopKMode::MAX, op::TopKSortType::NONE); } else { A1 = make_shared(A); } diff --git a/inference-engine/tests/functional/inference_engine/transformations/nop_elimination.cpp b/inference-engine/tests/functional/inference_engine/transformations/nop_elimination.cpp index b0a0e3b5728..4d504c69086 100644 --- a/inference-engine/tests/functional/inference_engine/transformations/nop_elimination.cpp +++ b/inference-engine/tests/functional/inference_engine/transformations/nop_elimination.cpp @@ -277,7 +277,7 @@ TEST(nop_elimination, squeeze_unsqueeze_overlap_elimination) { } else { k = make_shared(element::i64, Shape{}, std::vector{shape[last_dim].get_length()}); } - A1 = make_shared(A, k, last_dim, op::v1::TopK::Mode::MAX, op::v1::TopK::SortType::NONE); + A1 = make_shared(A, k, last_dim, op::TopKMode::MAX, op::TopKSortType::NONE); } else { A1 = make_shared(A); } @@ -748,7 +748,7 @@ TEST(nop_elimination, topk_convert_elimination) { auto check_usecase = []() { auto A = make_shared(element::f32, Shape{20, 3, 4}); auto A1 = make_shared(A); - auto B = make_shared(A1, op::Constant::create(element::i64, {}, {10}), 0, op::v1::TopK::Mode::MAX, op::v1::TopK::SortType::NONE); + auto B = make_shared(A1, op::Constant::create(element::i64, {}, {10}), 0, op::TopKMode::MAX, op::TopKSortType::NONE); auto C = make_shared(B->output(0), B->output(0).get_element_type()); auto baseline_f = make_shared(make_shared(C), ParameterVector{A}); auto optimized_f = clone_function(*baseline_f); diff --git a/inference-engine/tests/functional/plugin/cpu/bfloat16/topk_inputs_i32.cpp b/inference-engine/tests/functional/plugin/cpu/bfloat16/topk_inputs_i32.cpp index d3daa9a2067..f8efa96d0df 100644 --- a/inference-engine/tests/functional/plugin/cpu/bfloat16/topk_inputs_i32.cpp +++ b/inference-engine/tests/functional/plugin/cpu/bfloat16/topk_inputs_i32.cpp @@ -92,8 +92,8 @@ protected: // TopK const auto k = make_shared(element::i32, Shape{}, vector{1}); size_t axis = 1; - ngraph::op::v1::TopK::Mode mode = ngraph::op::v1::TopK::Mode::MAX; - ngraph::op::v1::TopK::SortType sort = ngraph::op::v1::TopK::SortType::NONE; + ngraph::op::TopKMode mode = ngraph::op::TopKMode::MAX; + ngraph::op::TopKSortType sort = ngraph::op::TopKSortType::NONE; auto argmaxNode = std::make_shared(convNode, k, axis, mode, sort); argmaxNode->set_friendly_name("TopK_1"); diff --git a/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/single_layer_tests/topk.cpp b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/single_layer_tests/topk.cpp index 6495a9a850f..481e845188f 100644 --- a/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/single_layer_tests/topk.cpp +++ b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/single_layer_tests/topk.cpp @@ -27,15 +27,15 @@ const std::vector k = { 10, }; -const std::vector modes = { - ngraph::opset4::TopK::Mode::MIN, - ngraph::opset4::TopK::Mode::MAX +const std::vector modes = { + ngraph::op::TopKMode::MIN, + ngraph::op::TopKMode::MAX }; -const std::vector sortTypes = { - ngraph::opset4::TopK::SortType::NONE, - ngraph::opset4::TopK::SortType::SORT_INDICES, - ngraph::opset4::TopK::SortType::SORT_VALUES, +const std::vector sortTypes = { + ngraph::op::TopKSortType::NONE, + ngraph::op::TopKSortType::SORT_INDICES, + ngraph::op::TopKSortType::SORT_VALUES, }; diff --git a/inference-engine/tests/functional/plugin/gpu/shared_tests_instances/single_layer_tests/topk.cpp b/inference-engine/tests/functional/plugin/gpu/shared_tests_instances/single_layer_tests/topk.cpp index 7b31962affe..98ccff3a037 100644 --- a/inference-engine/tests/functional/plugin/gpu/shared_tests_instances/single_layer_tests/topk.cpp +++ b/inference-engine/tests/functional/plugin/gpu/shared_tests_instances/single_layer_tests/topk.cpp @@ -27,15 +27,15 @@ const std::vector k = { 10, }; -const std::vector modes = { - ngraph::opset4::TopK::Mode::MIN, - ngraph::opset4::TopK::Mode::MAX +const std::vector modes = { + ngraph::op::TopKMode::MIN, + ngraph::op::TopKMode::MAX }; -const std::vector sortTypes = { - ngraph::opset4::TopK::SortType::NONE, - ngraph::opset4::TopK::SortType::SORT_INDICES, - ngraph::opset4::TopK::SortType::SORT_VALUES, +const std::vector sortTypes = { + ngraph::op::TopKSortType::NONE, + ngraph::op::TopKSortType::SORT_INDICES, + ngraph::op::TopKSortType::SORT_VALUES, }; diff --git a/inference-engine/tests/functional/plugin/myriad/shared_tests_instances/single_layer_tests/topk.cpp b/inference-engine/tests/functional/plugin/myriad/shared_tests_instances/single_layer_tests/topk.cpp index 81803d014e7..036416979c6 100644 --- a/inference-engine/tests/functional/plugin/myriad/shared_tests_instances/single_layer_tests/topk.cpp +++ b/inference-engine/tests/functional/plugin/myriad/shared_tests_instances/single_layer_tests/topk.cpp @@ -27,14 +27,14 @@ const std::vector k = { 10, }; -const std::vector modes = { - ngraph::opset5::TopK::Mode::MIN, - ngraph::opset5::TopK::Mode::MAX +const std::vector modes = { + ngraph::op::TopKMode::MIN, + ngraph::op::TopKMode::MAX }; -const std::vector sortTypes = { - ngraph::opset5::TopK::SortType::SORT_INDICES, - ngraph::opset5::TopK::SortType::SORT_VALUES, +const std::vector sortTypes = { + ngraph::op::TopKSortType::SORT_INDICES, + ngraph::op::TopKSortType::SORT_VALUES, }; INSTANTIATE_TEST_CASE_P(smoke_TopK_IndicesValuesSort, TopKLayerTest, @@ -56,7 +56,7 @@ INSTANTIATE_TEST_CASE_P(smoke_TopK_NoneSort, TopKLayerTest, ::testing::Values(1), ::testing::ValuesIn(axes), ::testing::ValuesIn(modes), - ::testing::Values(ngraph::opset5::TopK::SortType::NONE), + ::testing::Values(ngraph::op::TopKSortType::NONE), ::testing::ValuesIn(netPrecisions), ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), diff --git a/inference-engine/tests/functional/plugin/shared/include/single_layer_tests/topk.hpp b/inference-engine/tests/functional/plugin/shared/include/single_layer_tests/topk.hpp index a20d75f9be0..e502c8016c7 100644 --- a/inference-engine/tests/functional/plugin/shared/include/single_layer_tests/topk.hpp +++ b/inference-engine/tests/functional/plugin/shared/include/single_layer_tests/topk.hpp @@ -14,8 +14,8 @@ namespace LayerTestsDefinitions { typedef std::tuple< int64_t, // keepK int64_t, // axis - ngraph::opset4::TopK::Mode, // mode - ngraph::opset4::TopK::SortType, // sort + ngraph::op::TopKMode, // mode + ngraph::op::TopKSortType, // sort InferenceEngine::Precision, // Net precision InferenceEngine::Precision, // Input precision InferenceEngine::Precision, // Output precision @@ -33,4 +33,4 @@ protected: void SetUp() override; }; -} // namespace LayerTestsDefinitions \ No newline at end of file +} // namespace LayerTestsDefinitions diff --git a/inference-engine/tests/functional/plugin/shared/src/single_layer_tests/topk.cpp b/inference-engine/tests/functional/plugin/shared/src/single_layer_tests/topk.cpp index a16f0fe3052..eae4fbb0fce 100644 --- a/inference-engine/tests/functional/plugin/shared/src/single_layer_tests/topk.cpp +++ b/inference-engine/tests/functional/plugin/shared/src/single_layer_tests/topk.cpp @@ -12,8 +12,8 @@ namespace LayerTestsDefinitions { InferenceEngine::SizeVector inputShape; std::string targetDevice; int64_t keepK, axis; - ngraph::opset4::TopK::Mode mode; - ngraph::opset4::TopK::SortType sort; + ngraph::op::TopKMode mode; + ngraph::op::TopKSortType sort; std::tie(keepK, axis, mode, sort, netPrecision, inPrc, outPrc, inLayout, inputShape, targetDevice) = obj.param; std::ostringstream result; result << "IS=" << CommonTestUtils::vec2str(inputShape) << "_"; @@ -33,8 +33,8 @@ void TopKLayerTest::SetUp() { InferenceEngine::SizeVector inputShape; InferenceEngine::Precision netPrecision; int64_t keepK, axis; - ngraph::opset4::TopK::Mode mode; - ngraph::opset4::TopK::SortType sort; + ngraph::op::TopKMode mode; + ngraph::op::TopKSortType sort; std::tie(keepK, axis, mode, sort, netPrecision, inPrc, outPrc, inLayout, inputShape, targetDevice) = this->GetParam(); auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); @@ -56,4 +56,4 @@ void TopKLayerTest::SetUp() { TEST_P(TopKLayerTest, CompareWithRefsDynamicBath) { Run(); } -} // namespace LayerTestsDefinitions \ No newline at end of file +} // namespace LayerTestsDefinitions diff --git a/ngraph/core/include/ngraph/op/topk.hpp b/ngraph/core/include/ngraph/op/topk.hpp index 8a6b13da13d..c0f5f089b44 100644 --- a/ngraph/core/include/ngraph/op/topk.hpp +++ b/ngraph/core/include/ngraph/op/topk.hpp @@ -33,9 +33,6 @@ namespace ngraph class NGRAPH_API TopK : public Op { public: - using SortType = TopKSortType; - using Mode = TopKMode; - static constexpr NodeTypeInfo type_info{"TopK", 1}; const NodeTypeInfo& get_type_info() const override { return type_info; } /// \brief Constructs a TopK operation @@ -62,8 +59,8 @@ namespace ngraph TopK(const Output& data, const Output& k, const int64_t axis, - const Mode mode, - const SortType sort, + const op::TopKMode mode, + const op::TopKSortType sort, const element::Type& index_element_type = element::i32); bool visit_attributes(AttributeVisitor& visitor) override; @@ -80,10 +77,10 @@ namespace ngraph /// \brief Returns axis value before normalization int64_t get_provided_axis() const { return m_axis; } void set_axis(const int64_t axis); - Mode get_mode() const { return m_mode; } - void set_mode(const Mode mode) { m_mode = mode; } - SortType get_sort_type() const { return m_sort; } - void set_sort_type(const SortType sort) { m_sort = sort; } + op::TopKMode get_mode() const { return m_mode; } + void set_mode(const op::TopKMode mode) { m_mode = mode; } + op::TopKSortType get_sort_type() const { return m_sort; } + void set_sort_type(const op::TopKSortType sort) { m_sort = sort; } element::Type get_index_element_type() const { return m_index_element_type; } void set_index_element_type(const element::Type& index_element_type) { @@ -102,8 +99,8 @@ namespace ngraph protected: int64_t m_axis; uint64_t m_normalized_axis; - Mode m_mode; - SortType m_sort; + op::TopKMode m_mode; + op::TopKSortType m_sort; element::Type m_index_element_type{element::i32}; virtual size_t read_k_from_constant_node(const std::shared_ptr& node, @@ -151,8 +148,8 @@ namespace ngraph TopK(const Output& data, const Output& k, const int64_t axis, - const Mode mode, - const SortType sort, + const op::TopKMode mode, + const op::TopKSortType sort, const element::Type& index_element_type = element::i32); bool visit_attributes(AttributeVisitor& visitor) override; void validate_and_infer_types() override; diff --git a/ngraph/core/reference/include/ngraph/runtime/reference/topk.hpp b/ngraph/core/reference/include/ngraph/runtime/reference/topk.hpp index 4faac42c949..3729c079322 100644 --- a/ngraph/core/reference/include/ngraph/runtime/reference/topk.hpp +++ b/ngraph/core/reference/include/ngraph/runtime/reference/topk.hpp @@ -80,7 +80,7 @@ namespace ngraph size_t axis, size_t k, bool compute_max, - op::v1::TopK::SortType sort = op::v1::TopK::SortType::NONE) + op::TopKSortType sort = op::TopKSortType::NONE) { using namespace std; // reorder source axis visit order and make "axis" inner most @@ -137,13 +137,13 @@ namespace ngraph { switch (sort) { - case op::v1::TopK::SortType::NONE: break; - case op::v1::TopK::SortType::SORT_INDICES: + case op::TopKSortType::NONE: break; + case op::TopKSortType::SORT_INDICES: std::sort(workspace.begin(), workspace.begin() + k, sort_indices_descending); break; - case op::v1::TopK::SortType::SORT_VALUES: + case op::TopKSortType::SORT_VALUES: std::sort(workspace.begin(), workspace.begin() + k, compare_max); break; } @@ -152,13 +152,13 @@ namespace ngraph { switch (sort) { - case op::v1::TopK::SortType::NONE: break; - case op::v1::TopK::SortType::SORT_INDICES: + case op::TopKSortType::NONE: break; + case op::TopKSortType::SORT_INDICES: std::sort(workspace.begin(), workspace.begin() + k, sort_indices_ascending); break; - case op::v1::TopK::SortType::SORT_VALUES: + case op::TopKSortType::SORT_VALUES: std::sort(workspace.begin(), workspace.begin() + k, compare_min); break; } diff --git a/ngraph/core/src/op/topk.cpp b/ngraph/core/src/op/topk.cpp index 17155dc14d2..734ff110f8c 100644 --- a/ngraph/core/src/op/topk.cpp +++ b/ngraph/core/src/op/topk.cpp @@ -41,7 +41,7 @@ namespace topk const size_t axis, const size_t k, const bool compute_max, - const op::v1::TopK::SortType sort) + const op::TopKSortType sort) { using T = typename element_type_traits::value_type; using U = typename element_type_traits::value_type; @@ -72,7 +72,7 @@ namespace topk const size_t axis, const size_t k, const bool max, - const op::v1::TopK::SortType sort, + const op::TopKSortType sort, const element::Type index_et) { bool rc = true; @@ -98,7 +98,7 @@ namespace topk const size_t axis, const size_t k, const bool max, - const op::v1::TopK::SortType sort, + const op::TopKSortType sort, const element::Type index_et) { bool rc = true; @@ -177,8 +177,8 @@ op::v1::TopK::TopK(const Output& data, : Op{{data, k}} , m_axis{axis} , m_normalized_axis{UNKNOWN_NORMALIZED_AXIS} - , m_mode{as_enum(mode)} - , m_sort{as_enum(sort)} + , m_mode{as_enum(mode)} + , m_sort{as_enum(sort)} , m_index_element_type{index_element_type} { constructor_validate_and_infer_types(); @@ -187,8 +187,8 @@ op::v1::TopK::TopK(const Output& data, op::v1::TopK::TopK(const Output& data, const Output& k, const int64_t axis, - const Mode mode, - const SortType sort, + const op::TopKMode mode, + const op::TopKSortType sort, const element::Type& index_element_type) : Op{{data, k}} , m_axis{axis} @@ -404,8 +404,8 @@ bool op::v1::TopK::evaluate(const HostTensorVector& outputs, const HostTensorVec Shape arg_shape = inputs[0]->get_shape(); // 1. get axis, mode ( max/min), sort_type size_t axis = ngraph::normalize_axis(this, m_axis, arg_shape.size()); - bool compute_max = get_mode() == TopKMode::MAX ? true : false; - SortType sort_type = get_sort_type(); + bool compute_max = get_mode() == op::TopKMode::MAX ? true : false; + op::TopKSortType sort_type = get_sort_type(); // 2. get value of k - from constant node or from HT size_t k = 0; @@ -458,8 +458,8 @@ op::v3::TopK::TopK(const Output& data, op::v3::TopK::TopK(const Output& data, const Output& k, const int64_t axis, - const Mode mode, - const SortType sort, + const op::TopKMode mode, + const op::TopKSortType sort, const element::Type& index_element_type) : op::v1::TopK{data, k, axis, mode, sort, index_element_type} { diff --git a/ngraph/frontend/onnx_import/include/onnx_import/utils/arg_min_max_factory.hpp b/ngraph/frontend/onnx_import/include/onnx_import/utils/arg_min_max_factory.hpp index 17f10fe3300..10970aa728e 100644 --- a/ngraph/frontend/onnx_import/include/onnx_import/utils/arg_min_max_factory.hpp +++ b/ngraph/frontend/onnx_import/include/onnx_import/utils/arg_min_max_factory.hpp @@ -45,7 +45,7 @@ namespace ngraph private: std::shared_ptr - make_topk_subgraph(default_opset::TopK::Mode mode) const; + make_topk_subgraph(op::TopKMode mode) const; const std::int64_t m_keep_dims; Output m_input_node; diff --git a/ngraph/frontend/onnx_import/src/op/hardmax.cpp b/ngraph/frontend/onnx_import/src/op/hardmax.cpp index 0f4ea157b58..1b1ed7b397f 100644 --- a/ngraph/frontend/onnx_import/src/op/hardmax.cpp +++ b/ngraph/frontend/onnx_import/src/op/hardmax.cpp @@ -59,8 +59,8 @@ namespace ngraph coerced_tensor, default_opset::Constant::create(ngraph::element::i64, Shape{}, {1}), indices_axis, - default_opset::TopK::Mode::MAX, - default_opset::TopK::SortType::NONE); + ngraph::op::TopKMode::MAX, + ngraph::op::TopKSortType::NONE); const auto on_value = default_opset::Constant::create(ngraph::element::i64, Shape{}, {1}); diff --git a/ngraph/frontend/onnx_import/src/op/topk.cpp b/ngraph/frontend/onnx_import/src/op/topk.cpp index 8dfb1ecb4ec..06732da9d27 100644 --- a/ngraph/frontend/onnx_import/src/op/topk.cpp +++ b/ngraph/frontend/onnx_import/src/op/topk.cpp @@ -70,8 +70,8 @@ namespace ngraph data, k_node, axis, - default_opset::TopK::Mode::MAX, - default_opset::TopK::SortType::SORT_VALUES, + ngraph::op::TopKMode::MAX, + ngraph::op::TopKSortType::SORT_VALUES, element::i64); return {top_k->output(0), top_k->output(1)}; @@ -90,8 +90,8 @@ namespace ngraph data, k, axis, - default_opset::TopK::Mode::MAX, - default_opset::TopK::SortType::SORT_VALUES, + ngraph::op::TopKMode::MAX, + ngraph::op::TopKSortType::SORT_VALUES, element::i64); return {top_k->output(0), top_k->output(1)}; @@ -112,12 +112,12 @@ namespace ngraph const auto sorted = node.get_attribute_value("sorted", 1); // Map attribute values to nGraph enums - const auto sort_type = sorted ? default_opset::TopK::SortType::SORT_VALUES - : default_opset::TopK::SortType::NONE; + const auto sort_type = sorted ? ngraph::op::TopKSortType::SORT_VALUES + : ngraph::op::TopKSortType::NONE; const auto compute_max = static_cast(largest); - const auto mode = compute_max ? default_opset::TopK::Mode::MAX - : default_opset::TopK::Mode::MIN; + const auto mode = compute_max ? ngraph::op::TopKMode::MAX + : ngraph::op::TopKMode::MIN; std::shared_ptr top_k = std::make_shared( data, k, axis, mode, sort_type, element::i64); diff --git a/ngraph/frontend/onnx_import/src/utils/arg_min_max_factory.cpp b/ngraph/frontend/onnx_import/src/utils/arg_min_max_factory.cpp index c8695011ea9..eb41a71beca 100644 --- a/ngraph/frontend/onnx_import/src/utils/arg_min_max_factory.cpp +++ b/ngraph/frontend/onnx_import/src/utils/arg_min_max_factory.cpp @@ -33,21 +33,21 @@ namespace ngraph std::shared_ptr ArgMinMaxFactory::make_arg_max() const { - return make_topk_subgraph(default_opset::TopK::Mode::MAX); + return make_topk_subgraph(ngraph::op::TopKMode::MAX); } std::shared_ptr ArgMinMaxFactory::make_arg_min() const { - return make_topk_subgraph(default_opset::TopK::Mode::MIN); + return make_topk_subgraph(ngraph::op::TopKMode::MIN); } std::shared_ptr - ArgMinMaxFactory::make_topk_subgraph(default_opset::TopK::Mode mode) const + ArgMinMaxFactory::make_topk_subgraph(ngraph::op::TopKMode mode) const { const auto k_node = default_opset::Constant::create(ngraph::element::i64, Shape{}, {1}); const auto topk = std::make_shared( - m_input_node, k_node, m_axis, mode, default_opset::TopK::SortType::NONE); + m_input_node, k_node, m_axis, mode, ngraph::op::TopKSortType::NONE); if (m_keep_dims == 0) { diff --git a/ngraph/test/attributes.cpp b/ngraph/test/attributes.cpp index 64a5a60451d..22719dc9d32 100644 --- a/ngraph/test/attributes.cpp +++ b/ngraph/test/attributes.cpp @@ -1257,8 +1257,8 @@ TEST(attributes, topk_op) auto k = make_shared(element::i32, Shape{}); auto axis = 0; - auto mode = opset1::TopK::Mode::MAX; - auto sort_type = opset1::TopK::SortType::SORT_VALUES; + auto mode = op::TopKMode::MAX; + auto sort_type = op::TopKSortType::SORT_VALUES; auto topk = make_shared(data, k, axis, mode, sort_type); NodeBuilder builder(topk); diff --git a/ngraph/test/backend/topk.in.cpp b/ngraph/test/backend/topk.in.cpp index 6218a430722..660aabbee4b 100644 --- a/ngraph/test/backend/topk.in.cpp +++ b/ngraph/test/backend/topk.in.cpp @@ -65,13 +65,13 @@ NGRAPH_TEST(${BACKEND_NAME}, topk_resnet50) auto B = make_shared(A, op::Constant::create(element::i64, {}, {5}), 1, - op::v1::TopK::Mode::MAX, - op::v1::TopK::SortType::SORT_VALUES); + op::TopKMode::MAX, + op::TopKSortType::SORT_VALUES); auto C = make_shared(A, op::Constant::create(element::i64, {}, {1}), 1, - op::v1::TopK::Mode::MAX, - op::v1::TopK::SortType::SORT_VALUES); + op::TopKMode::MAX, + op::TopKSortType::SORT_VALUES); auto out5_value = B->output(0); auto out5_index = B->output(1); @@ -143,7 +143,7 @@ NGRAPH_TEST(${BACKEND_NAME}, topk_max_sort_none) auto k = op::Constant::create(element::i64, {}, {5}); int64_t axis = 1; auto B = make_shared( - A, k, axis, op::v1::TopK::Mode::MAX, op::v1::TopK::SortType::NONE); + A, k, axis, op::TopKMode::MAX, op::TopKSortType::NONE); auto out_value = B->output(0); auto out_index = B->output(1); auto f = make_shared(OutputVector{out_value, out_index}, ParameterVector{A}); @@ -197,7 +197,7 @@ NGRAPH_TEST(${BACKEND_NAME}, topk_min_sort_none) auto k = op::Constant::create(element::i64, {}, {5}); int64_t axis = 1; auto B = make_shared( - A, k, axis, op::v1::TopK::Mode::MIN, op::v1::TopK::SortType::NONE); + A, k, axis, op::TopKMode::MIN, op::TopKSortType::NONE); auto out_value = B->output(0); auto out_index = B->output(1); auto f = make_shared(OutputVector{out_value, out_index}, ParameterVector{A}); @@ -251,7 +251,7 @@ NGRAPH_TEST(${BACKEND_NAME}, topk_max_sort_value) auto k = op::Constant::create(element::i64, {}, {5}); int64_t axis = 1; auto B = make_shared( - A, k, axis, op::v1::TopK::Mode::MAX, op::v1::TopK::SortType::SORT_VALUES); + A, k, axis, op::TopKMode::MAX, op::TopKSortType::SORT_VALUES); auto out_value = B->output(0); auto out_index = B->output(1); auto f = make_shared(OutputVector{out_value, out_index}, ParameterVector{A}); @@ -301,7 +301,7 @@ NGRAPH_TEST(${BACKEND_NAME}, topk_min_sort_value) auto k = op::Constant::create(element::i64, {}, {5}); int64_t axis = 1; auto B = make_shared( - A, k, axis, op::v1::TopK::Mode::MIN, op::v1::TopK::SortType::SORT_VALUES); + A, k, axis, op::TopKMode::MIN, op::TopKSortType::SORT_VALUES); auto out_value = B->output(0); auto out_index = B->output(1); auto f = make_shared(OutputVector{out_value, out_index}, ParameterVector{A}); @@ -355,7 +355,7 @@ NGRAPH_TEST(${BACKEND_NAME}, topk_max_sort_index) auto k = op::Constant::create(element::i64, {}, {5}); int64_t axis = 1; auto B = make_shared( - A, k, axis, op::v1::TopK::Mode::MAX, op::v1::TopK::SortType::SORT_INDICES); + A, k, axis, op::TopKMode::MAX, op::TopKSortType::SORT_INDICES); auto out_value = B->output(0); auto out_index = B->output(1); auto f = make_shared(OutputVector{out_value, out_index}, ParameterVector{A}); @@ -409,7 +409,7 @@ NGRAPH_TEST(${BACKEND_NAME}, topk_min_sort_index) auto k = op::Constant::create(element::i64, {}, {5}); int64_t axis = 1; auto B = make_shared( - A, k, axis, op::v1::TopK::Mode::MIN, op::v1::TopK::SortType::SORT_INDICES); + A, k, axis, op::TopKMode::MIN, op::TopKSortType::SORT_INDICES); auto out_value = B->output(0); auto out_index = B->output(1); auto f = make_shared(OutputVector{out_value, out_index}, ParameterVector{A}); @@ -463,7 +463,7 @@ NGRAPH_TEST(${BACKEND_NAME}, topk_1d_max_all) auto k = op::Constant::create(element::i64, {}, {6}); int64_t axis = 0; auto B = make_shared( - A, k, axis, op::v1::TopK::Mode::MAX, op::v1::TopK::SortType::SORT_VALUES); + A, k, axis, op::TopKMode::MAX, op::TopKSortType::SORT_VALUES); auto f0 = make_shared(OutputVector{B->output(0)}, ParameterVector{A}); auto f1 = make_shared(OutputVector{B->output(1)}, ParameterVector{A}); @@ -492,7 +492,7 @@ NGRAPH_TEST(${BACKEND_NAME}, topk_1d_i32_max_all) auto k = op::Constant::create(element::i64, {}, {6}); int64_t axis = 0; auto B = make_shared( - A, k, axis, op::v1::TopK::Mode::MAX, op::v1::TopK::SortType::SORT_VALUES); + A, k, axis, op::TopKMode::MAX, op::TopKSortType::SORT_VALUES); auto f0 = make_shared(OutputVector{B->output(0)}, ParameterVector{A}); auto f1 = make_shared(OutputVector{B->output(1)}, ParameterVector{A}); @@ -520,7 +520,7 @@ NGRAPH_TEST(${BACKEND_NAME}, topk_1d_max_partial) auto k = op::Constant::create(element::i64, {}, {3}); int64_t axis = 0; auto B = make_shared( - A, k, axis, op::v1::TopK::Mode::MAX, op::v1::TopK::SortType::SORT_VALUES); + A, k, axis, op::TopKMode::MAX, op::TopKSortType::SORT_VALUES); auto f0 = make_shared(OutputVector{B->output(0)}, ParameterVector{A}); auto f1 = make_shared(OutputVector{B->output(1)}, ParameterVector{A}); @@ -549,7 +549,7 @@ NGRAPH_TEST(${BACKEND_NAME}, topk_1d_max_one) auto k = op::Constant::create(element::i64, {}, {1}); int64_t axis = 0; auto B = make_shared( - A, k, axis, op::v1::TopK::Mode::MAX, op::v1::TopK::SortType::SORT_VALUES); + A, k, axis, op::TopKMode::MAX, op::TopKSortType::SORT_VALUES); auto f0 = make_shared(OutputVector{B->output(0)}, ParameterVector{A}); auto f1 = make_shared(OutputVector{B->output(1)}, ParameterVector{A}); @@ -578,7 +578,7 @@ NGRAPH_TEST(${BACKEND_NAME}, topk_1d_min_all) auto k = op::Constant::create(element::i64, {}, {6}); int64_t axis = 0; auto B = make_shared( - A, k, axis, op::v1::TopK::Mode::MIN, op::v1::TopK::SortType::SORT_VALUES); + A, k, axis, op::TopKMode::MIN, op::TopKSortType::SORT_VALUES); auto f0 = make_shared(OutputVector{B->output(0)}, ParameterVector{A}); auto f1 = make_shared(OutputVector{B->output(1)}, ParameterVector{A}); @@ -607,7 +607,7 @@ NGRAPH_TEST(${BACKEND_NAME}, topk_1d_min_partial) auto k = op::Constant::create(element::i64, {}, {3}); int64_t axis = 0; auto B = make_shared( - A, k, axis, op::v1::TopK::Mode::MIN, op::v1::TopK::SortType::SORT_VALUES); + A, k, axis, op::TopKMode::MIN, op::TopKSortType::SORT_VALUES); auto f0 = make_shared(OutputVector{B->output(0)}, ParameterVector{A}); auto f1 = make_shared(OutputVector{B->output(1)}, ParameterVector{A}); @@ -636,7 +636,7 @@ NGRAPH_TEST(${BACKEND_NAME}, topk_1d_min_one) auto k = op::Constant::create(element::i64, {}, {1}); int64_t axis = 0; auto B = make_shared( - A, k, axis, op::v1::TopK::Mode::MIN, op::v1::TopK::SortType::SORT_VALUES); + A, k, axis, op::TopKMode::MIN, op::TopKSortType::SORT_VALUES); auto f0 = make_shared(OutputVector{B->output(0)}, ParameterVector{A}); auto f1 = make_shared(OutputVector{B->output(1)}, ParameterVector{A}); @@ -665,7 +665,7 @@ NGRAPH_TEST(${BACKEND_NAME}, topk_3d_max_all) auto k = op::Constant::create(element::i64, {}, {3}); int64_t axis = 1; auto B = make_shared( - A, k, axis, op::v1::TopK::Mode::MAX, op::v1::TopK::SortType::SORT_VALUES); + A, k, axis, op::TopKMode::MAX, op::TopKSortType::SORT_VALUES); auto f0 = make_shared(OutputVector{B->output(0)}, ParameterVector{A}); auto f1 = make_shared(OutputVector{B->output(1)}, ParameterVector{A}); @@ -695,7 +695,7 @@ NGRAPH_TEST(${BACKEND_NAME}, topk_int64) auto k = op::Constant::create(element::i64, {}, {3}); int64_t axis = 1; auto B = make_shared( - A, k, axis, op::v1::TopK::Mode::MAX, op::v1::TopK::SortType::SORT_VALUES, element::i64); + A, k, axis, op::TopKMode::MAX, op::TopKSortType::SORT_VALUES, element::i64); auto f0 = make_shared(OutputVector{B->output(0)}, ParameterVector{A}); auto f1 = make_shared(OutputVector{B->output(1)}, ParameterVector{A}); @@ -725,7 +725,7 @@ NGRAPH_TEST(${BACKEND_NAME}, topk_5d_max_partial) auto k = op::Constant::create(element::i64, {}, {2}); int64_t axis = 1; auto B = make_shared( - A, k, axis, op::v1::TopK::Mode::MAX, op::v1::TopK::SortType::SORT_VALUES); + A, k, axis, op::TopKMode::MAX, op::TopKSortType::SORT_VALUES); auto f0 = make_shared(OutputVector{B->output(0)}, ParameterVector{A}); auto f1 = make_shared(OutputVector{B->output(1)}, ParameterVector{A}); @@ -791,7 +791,7 @@ NGRAPH_TEST(${BACKEND_NAME}, topk_3d_max_partial) auto k = op::Constant::create(element::i64, {}, {2}); int64_t axis = 1; auto B = make_shared( - A, k, axis, op::v1::TopK::Mode::MAX, op::v1::TopK::SortType::SORT_VALUES); + A, k, axis, op::TopKMode::MAX, op::TopKSortType::SORT_VALUES); auto f0 = make_shared(OutputVector{B->output(0)}, ParameterVector{A}); auto f1 = make_shared(OutputVector{B->output(1)}, ParameterVector{A}); @@ -821,7 +821,7 @@ NGRAPH_TEST(${BACKEND_NAME}, topk_3d_max_one) auto k = op::Constant::create(element::i64, {}, {1}); int64_t axis = 1; auto B = make_shared( - A, k, axis, op::v1::TopK::Mode::MAX, op::v1::TopK::SortType::SORT_VALUES); + A, k, axis, op::TopKMode::MAX, op::TopKSortType::SORT_VALUES); auto f0 = make_shared(OutputVector{B->output(0)}, ParameterVector{A}); auto f1 = make_shared(OutputVector{B->output(1)}, ParameterVector{A}); @@ -850,7 +850,7 @@ NGRAPH_TEST(${BACKEND_NAME}, topk_3d_min_all) auto k = op::Constant::create(element::i64, {}, {3}); int64_t axis = 1; auto B = make_shared( - A, k, axis, op::v1::TopK::Mode::MIN, op::v1::TopK::SortType::SORT_VALUES); + A, k, axis, op::TopKMode::MIN, op::TopKSortType::SORT_VALUES); auto f0 = make_shared(OutputVector{B->output(0)}, ParameterVector{A}); auto f1 = make_shared(OutputVector{B->output(1)}, ParameterVector{A}); @@ -880,7 +880,7 @@ NGRAPH_TEST(${BACKEND_NAME}, topk_3d_min_partial) auto k = op::Constant::create(element::i64, {}, {2}); int64_t axis = 1; auto B = make_shared( - A, k, axis, op::v1::TopK::Mode::MIN, op::v1::TopK::SortType::SORT_VALUES); + A, k, axis, op::TopKMode::MIN, op::TopKSortType::SORT_VALUES); auto f0 = make_shared(OutputVector{B->output(0)}, ParameterVector{A}); auto f1 = make_shared(OutputVector{B->output(1)}, ParameterVector{A}); @@ -910,7 +910,7 @@ NGRAPH_TEST(${BACKEND_NAME}, topk_3d_min_one) auto k = op::Constant::create(element::i64, {}, {1}); int64_t axis = 1; auto B = make_shared( - A, k, axis, op::v1::TopK::Mode::MIN, op::v1::TopK::SortType::SORT_VALUES); + A, k, axis, op::TopKMode::MIN, op::TopKSortType::SORT_VALUES); auto f0 = make_shared(OutputVector{B->output(0)}, ParameterVector{A}); auto f1 = make_shared(OutputVector{B->output(1)}, ParameterVector{A}); @@ -939,7 +939,7 @@ NGRAPH_TEST(${BACKEND_NAME}, topk_2d_max_all) auto k = op::Constant::create(element::i64, {}, {4}); int64_t axis = 0; auto B = make_shared( - A, k, axis, op::v1::TopK::Mode::MAX, op::v1::TopK::SortType::SORT_VALUES); + A, k, axis, op::TopKMode::MAX, op::TopKSortType::SORT_VALUES); auto f0 = make_shared(OutputVector{B->output(0)}, ParameterVector{A}); auto f1 = make_shared(OutputVector{B->output(1)}, ParameterVector{A}); @@ -969,7 +969,7 @@ NGRAPH_TEST(${BACKEND_NAME}, topk_2d_max_partial) auto k = op::Constant::create(element::i64, {}, {2}); int64_t axis = 0; auto B = make_shared( - A, k, axis, op::v1::TopK::Mode::MAX, op::v1::TopK::SortType::SORT_VALUES); + A, k, axis, op::TopKMode::MAX, op::TopKSortType::SORT_VALUES); auto f0 = make_shared(OutputVector{B->output(0)}, ParameterVector{A}); auto f1 = make_shared(OutputVector{B->output(1)}, ParameterVector{A}); @@ -999,7 +999,7 @@ NGRAPH_TEST(${BACKEND_NAME}, topk_2d_max_one) auto k = op::Constant::create(element::i64, {}, {1}); int64_t axis = 0; auto B = make_shared( - A, k, axis, op::v1::TopK::Mode::MAX, op::v1::TopK::SortType::SORT_VALUES); + A, k, axis, op::TopKMode::MAX, op::TopKSortType::SORT_VALUES); auto f0 = make_shared(OutputVector{B->output(0)}, ParameterVector{A}); auto f1 = make_shared(OutputVector{B->output(1)}, ParameterVector{A}); @@ -1028,7 +1028,7 @@ NGRAPH_TEST(${BACKEND_NAME}, topk_2d_max_one_with_equal_values) auto k = op::Constant::create(element::i64, {}, {1}); int64_t axis = 1; auto B = make_shared( - A, k, axis, op::v1::TopK::Mode::MAX, op::v1::TopK::SortType::SORT_VALUES); + A, k, axis, op::TopKMode::MAX, op::TopKSortType::SORT_VALUES); auto f0 = make_shared(OutputVector{B->output(0)}, ParameterVector{A}); auto f1 = make_shared(OutputVector{B->output(1)}, ParameterVector{A}); @@ -1057,7 +1057,7 @@ NGRAPH_TEST(${BACKEND_NAME}, topk_2d_min_all) auto k = op::Constant::create(element::i64, {}, {4}); int64_t axis = 0; auto B = make_shared( - A, k, axis, op::v1::TopK::Mode::MIN, op::v1::TopK::SortType::SORT_VALUES); + A, k, axis, op::TopKMode::MIN, op::TopKSortType::SORT_VALUES); auto f0 = make_shared(OutputVector{B->output(0)}, ParameterVector{A}); auto f1 = make_shared(OutputVector{B->output(1)}, ParameterVector{A}); @@ -1087,7 +1087,7 @@ NGRAPH_TEST(${BACKEND_NAME}, topk_2d_min_partial) auto k = op::Constant::create(element::i64, {}, {2}); int64_t axis = 0; auto B = make_shared( - A, k, axis, op::v1::TopK::Mode::MIN, op::v1::TopK::SortType::SORT_VALUES); + A, k, axis, op::TopKMode::MIN, op::TopKSortType::SORT_VALUES); auto f0 = make_shared(OutputVector{B->output(0)}, ParameterVector{A}); auto f1 = make_shared(OutputVector{B->output(1)}, ParameterVector{A}); @@ -1116,7 +1116,7 @@ NGRAPH_TEST(${BACKEND_NAME}, topk_2d_min_one) auto k = op::Constant::create(element::i64, {}, {1}); int64_t axis = 0; auto B = make_shared( - A, k, axis, op::v1::TopK::Mode::MIN, op::v1::TopK::SortType::NONE); + A, k, axis, op::TopKMode::MIN, op::TopKSortType::NONE); auto f0 = make_shared(OutputVector{B->output(0)}, ParameterVector{A}); auto f1 = make_shared(OutputVector{B->output(1)}, ParameterVector{A}); @@ -1145,7 +1145,7 @@ NGRAPH_TEST(${BACKEND_NAME}, topk_3d_large_input_max) auto k = op::Constant::create(element::i64, {}, {10}); int64_t axis = 1; auto B = make_shared( - A, k, axis, op::v1::TopK::Mode::MAX, op::v1::TopK::SortType::SORT_VALUES); + A, k, axis, op::TopKMode::MAX, op::TopKSortType::SORT_VALUES); auto interp_f_0 = make_shared(OutputVector{B->output(0)}, ParameterVector{A}); auto interp_f_1 = make_shared(OutputVector{B->output(1)}, ParameterVector{A}); @@ -1185,7 +1185,7 @@ NGRAPH_TEST(${BACKEND_NAME}, topk_3d_large_input_min) auto k = op::Constant::create(element::i64, {}, {10}); int64_t axis = 1; auto B = make_shared( - A, k, axis, op::v1::TopK::Mode::MIN, op::v1::TopK::SortType::SORT_VALUES); + A, k, axis, op::TopKMode::MIN, op::TopKSortType::SORT_VALUES); auto interp_f_0 = make_shared(OutputVector{B->output(0)}, ParameterVector{A}); auto interp_f_1 = make_shared(OutputVector{B->output(1)}, ParameterVector{A}); @@ -1225,7 +1225,7 @@ NGRAPH_TEST(${BACKEND_NAME}, topk_3d_single_output) auto k = op::Constant::create(element::i64, {}, {2}); int64_t axis = 1; auto B = make_shared( - A, k, axis, op::v1::TopK::Mode::MIN, op::v1::TopK::SortType::SORT_VALUES); + A, k, axis, op::TopKMode::MIN, op::TopKSortType::SORT_VALUES); auto f0 = make_shared(OutputVector{B->output(1)}, ParameterVector{A}); auto backend = runtime::Backend::create("${BACKEND_NAME}"); diff --git a/ngraph/test/eval.cpp b/ngraph/test/eval.cpp index 926d6e0e355..bfb42a3591b 100644 --- a/ngraph/test/eval.cpp +++ b/ngraph/test/eval.cpp @@ -1675,7 +1675,7 @@ TEST(eval, topk_v1_dyn_k0) element::Type result_et{element::i32}; auto B = make_shared( - A, k, 1, op::v1::TopK::Mode::MAX, op::v1::TopK::SortType::SORT_VALUES, result_et); + A, k, 1, op::TopKMode::MAX, op::TopKSortType::SORT_VALUES, result_et); auto fun = make_shared(OutputVector{B->output(0), B->output(1)}, ParameterVector{A, k}); @@ -1764,7 +1764,7 @@ TEST(eval, topk_v1_param_dyn_k2) element::Type result_et{element::i32}; auto B = make_shared( - A, k, axis, op::v1::TopK::Mode::MAX, op::v1::TopK::SortType::SORT_VALUES, result_et); + A, k, axis, op::TopKMode::MAX, op::TopKSortType::SORT_VALUES, result_et); auto fun = make_shared(OutputVector{B->output(0), B->output(1)}, ParameterVector{A, k}); @@ -1797,7 +1797,7 @@ TEST(eval, topk_v1_param_dyn_k0) element::Type result_et{element::i32}; auto B = make_shared( - A, k, 1, op::v1::TopK::Mode::MAX, op::v1::TopK::SortType::SORT_VALUES, result_et); + A, k, 1, op::TopKMode::MAX, op::TopKSortType::SORT_VALUES, result_et); auto fun = make_shared(OutputVector{B->output(0), B->output(1)}, ParameterVector{A, k});