From 55d1597131d942e462ee1c9b786ab5203e11e7ad Mon Sep 17 00:00:00 2001 From: Michael Nosov Date: Mon, 5 Apr 2021 22:05:30 +0300 Subject: [PATCH 1/3] First unit test for FrontEndManager --- ngraph/CMakeLists.txt | 4 +++ .../frontend_manager/frontend_manager.hpp | 4 +++ .../frontend/generic/src/frontend_manager.cpp | 6 ++++ ngraph/test/CMakeLists.txt | 4 ++- ngraph/test/frontend/frontend_manager.cpp | 31 +++++++++++++++++++ 5 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 ngraph/test/frontend/frontend_manager.cpp diff --git a/ngraph/CMakeLists.txt b/ngraph/CMakeLists.txt index 7bfba968d03ad2..34d74e4a9057fc 100644 --- a/ngraph/CMakeLists.txt +++ b/ngraph/CMakeLists.txt @@ -26,6 +26,10 @@ set(NGRAPH_INCLUDE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/core/include ) +set(FRONTEND_INCLUDE_PATH + ${CMAKE_CURRENT_SOURCE_DIR}/frontend/generic/include +) + if (APPLE) # Enable MACOS_RPATH by default. cmake_policy(SET CMP0042 NEW) diff --git a/ngraph/frontend/generic/include/frontend_manager/frontend_manager.hpp b/ngraph/frontend/generic/include/frontend_manager/frontend_manager.hpp index aecc9f4f7e8b61..dc57441bd6ba51 100644 --- a/ngraph/frontend/generic/include/frontend_manager/frontend_manager.hpp +++ b/ngraph/frontend/generic/include/frontend_manager/frontend_manager.hpp @@ -77,6 +77,8 @@ class NGRAPH_API Place typedef std::shared_ptr Ptr; + virtual ~Place() = default; + /// \brief All associated names (synonyms) that identify this place in the graph in a framework specific way /// \return A vector of strings each representing a name that identifies this place in the graph. /// Can be empty if there are no names associated with this place or name cannot be attached. @@ -158,6 +160,7 @@ class NGRAPH_API InputModel typedef std::shared_ptr Ptr; + virtual ~InputModel() = default; ///// Searching for places ///// @@ -270,6 +273,7 @@ class NGRAPH_API FrontEnd { public: typedef std::shared_ptr Ptr; + virtual ~FrontEnd() = default; virtual InputModel::Ptr loadFromFile (const std::string& path) const; virtual InputModel::Ptr loadFromFiles (const std::vector& paths) const; diff --git a/ngraph/frontend/generic/src/frontend_manager.cpp b/ngraph/frontend/generic/src/frontend_manager.cpp index ab819b55968a4c..8839b1ea07ae05 100644 --- a/ngraph/frontend/generic/src/frontend_manager.cpp +++ b/ngraph/frontend/generic/src/frontend_manager.cpp @@ -490,6 +490,12 @@ namespace ngraph { return m_impl->availableFrontEnds(); } + + void FrontEndManager::registerFrontEnd(const std::string& name, FrontEndFactory creator) + { + m_impl->registerFrontEnd(name, creator); + } + } // namespace frontend } // namespace ngraph diff --git a/ngraph/test/CMakeLists.txt b/ngraph/test/CMakeLists.txt index 60878595b1bfde..4b3fde91242253 100644 --- a/ngraph/test/CMakeLists.txt +++ b/ngraph/test/CMakeLists.txt @@ -47,6 +47,7 @@ set(SRC eval.cpp file_util.cpp float16.cpp + frontend/frontend_manager.cpp graph_rewrite.cpp includes.cpp input_output_assign.cpp @@ -443,6 +444,7 @@ add_executable(unit-test ${SRC}) target_include_directories(unit-test PRIVATE ".") target_include_directories(unit-test PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/runtime) +target_include_directories(unit-test PRIVATE ${FRONTEND_INCLUDE_PATH}) add_definitions("-DCURDIR=\"${CMAKE_CURRENT_SOURCE_DIR}\"") add_definitions("-DJSON_INCLUDES=\"${JSON_INCLUDE_DIR}\"") @@ -492,7 +494,7 @@ if (MSVC) target_compile_options(unit-test PRIVATE "/bigobj") endif() -target_link_libraries(unit-test PRIVATE ie_backend) +target_link_libraries(unit-test PRIVATE ie_backend frontend_manager) if (NGRAPH_ONNX_IMPORT_ENABLE) target_link_libraries(unit-test PRIVATE onnx_importer onnx_editor) diff --git a/ngraph/test/frontend/frontend_manager.cpp b/ngraph/test/frontend/frontend_manager.cpp new file mode 100644 index 00000000000000..e04b00a590e13e --- /dev/null +++ b/ngraph/test/frontend/frontend_manager.cpp @@ -0,0 +1,31 @@ +// Copyright (C) 2018-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include +#include + +#include "gtest/gtest.h" +#include "gmock/gmock.h" + +using namespace ngraph; +using namespace ngraph::frontend; + +class FrontEndMock: public FrontEnd { +public: + FrontEndMock() = default; + ~FrontEndMock() = default; + + MOCK_CONST_METHOD1(loadFromFile, InputModel::Ptr(const std::string&)); + MOCK_CONST_METHOD1(convert, std::shared_ptr(InputModel::Ptr model)); +}; + +TEST(FrontEndManagerTest, testAvailableFrontEnds) +{ + FrontEndManager fem; + ASSERT_NO_THROW(fem.registerFrontEnd("mock", [](FrontEndCapabilities fec) { + return std::make_shared(); + })); + auto frontends = fem.availableFrontEnds(); + ASSERT_NE(std::find(frontends.begin(), frontends.end(), "mock"), frontends.end()); +} \ No newline at end of file From 5e9fa75426a0f5397af35998d44ad52b0626fdb2 Mon Sep 17 00:00:00 2001 From: Michael Nosov Date: Tue, 6 Apr 2021 00:53:06 +0300 Subject: [PATCH 2/3] Fix build for unit tests --- inference-engine/tests/unit/inference_engine/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/inference-engine/tests/unit/inference_engine/CMakeLists.txt b/inference-engine/tests/unit/inference_engine/CMakeLists.txt index 5c38c77b9b7e9a..6fbd68764ece1a 100644 --- a/inference-engine/tests/unit/inference_engine/CMakeLists.txt +++ b/inference-engine/tests/unit/inference_engine/CMakeLists.txt @@ -18,6 +18,7 @@ addIeTargetTest( LINK_LIBRARIES unitTestUtils inference_engine_lp_transformations + frontend_manager ${OpenCV_LIBRARIES} ADD_CPPLINT DEPENDENCIES From d450b4df105dba211ab4590e63d3c88dbe20e93c Mon Sep 17 00:00:00 2001 From: Michael Nosov Date: Tue, 6 Apr 2021 01:29:40 +0300 Subject: [PATCH 3/3] Fixed deprecated tests build --- inference-engine/tests_deprecated/unit/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/inference-engine/tests_deprecated/unit/CMakeLists.txt b/inference-engine/tests_deprecated/unit/CMakeLists.txt index 9746f06602ff2f..d26cb3b3821356 100644 --- a/inference-engine/tests_deprecated/unit/CMakeLists.txt +++ b/inference-engine/tests_deprecated/unit/CMakeLists.txt @@ -139,6 +139,7 @@ target_link_libraries(${TARGET_NAME} PRIVATE inference_engine_transformations inference_engine_lp_transformations inference_engine_snippets + frontend_manager ) if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")