Skip to content

Commit

Permalink
Merge onnx_importer to onnx_ngraph_frontend (openvinotoolkit#6825)
Browse files Browse the repository at this point in the history
* Merge onnx_importer to onnx_ngraph_frontend

* address review comments

* use onnx_ngraph_frontend in docs/template_extension

* link onnx_ngraph_frontend instead of onnx_importer

* switch onnxruntime branch to rel-1.8.1_ov_2022.1 in https://github.com/intel/onnxruntime

* Remove pip install cmake since the 1.8.1 release doesnt require it

* add alias

* set IMPORTED_GLOBAL

Co-authored-by: Ilya Lavrenov <[email protected]>
  • Loading branch information
2 people authored and andrei-cv committed Aug 30, 2021
1 parent a04ccb6 commit efc89a2
Show file tree
Hide file tree
Showing 334 changed files with 186 additions and 349 deletions.
1 change: 0 additions & 1 deletion .ci/azure/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ jobs:
-DPYTHON_EXECUTABLE=/usr/bin/python3.8
-DENABLE_WHEEL=ON
-DENABLE_TESTS=ON
-DNGRAPH_ONNX_IMPORT_ENABLE=ON
-DNGRAPH_ONNX_FRONTEND_ENABLE=ON
-DENABLE_FASTER_BUILD=ON
-DENABLE_STRICT_DEPENDENCIES=OFF
Expand Down
1 change: 0 additions & 1 deletion .ci/azure/linux_onnxruntime.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ jobs:
-DENABLE_PROFILING_ITT=OFF
-DENABLE_SAMPLES=OFF
-DENABLE_SPEECH_DEMO=OFF
-DNGRAPH_ONNX_IMPORT_ENABLE=ON
-DNGRAPH_ONNX_FRONTEND_ENABLE=ON
-DNGRAPH_DEBUG_ENABLE=OFF
$(REPO_DIR)
Expand Down
1 change: 0 additions & 1 deletion .ci/openvino-onnx/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ RUN cmake .. \
-DENABLE_SPEECH_DEMO=OFF \
-DENABLE_PYTHON=ON \
-DPYTHON_EXECUTABLE=/usr/bin/python3 \
-DNGRAPH_ONNX_IMPORT_ENABLE=ON \
-DNGRAPH_ONNX_FRONTEND_ENABLE=ON \
-DNGRAPH_DEBUG_ENABLE=OFF \
-DCMAKE_INSTALL_PREFIX=/openvino/dist \
Expand Down
15 changes: 4 additions & 11 deletions cmake/coverage.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,10 @@ ie_coverage_extract(INPUT "openvino" OUTPUT "ngraph"
ie_coverage_genhtml(INFO_FILE "ngraph"
PREFIX "${OV_COVERAGE_BASE_DIRECTORY}")

if(NGRAPH_ONNX_IMPORT_ENABLE)
ie_coverage_extract(INPUT "openvino" OUTPUT "onnx_importer"
PATTERNS "${OV_COVERAGE_BASE_DIRECTORY}/ngraph/frontend/onnx/onnx_common*"
"${OV_COVERAGE_BASE_DIRECTORY}/ngraph/frontend/onnx/onnx_import*")
ie_coverage_genhtml(INFO_FILE "onnx_importer"
PREFIX "${OV_COVERAGE_BASE_DIRECTORY}")
endif()

if(NGRAPH_ONNX_FRONTEND_ENABLE)
ie_coverage_extract(INPUT "openvino" OUTPUT "onnx_ngraph_frontend"
PATTERNS "${OV_COVERAGE_BASE_DIRECTORY}/ngraph/frontend/onnx/frontend*")
ie_coverage_genhtml(INFO_FILE "onnx_ngraph_frontend"
ie_coverage_extract(INPUT "openvino" OUTPUT "onnx"
PATTERNS "${OV_COVERAGE_BASE_DIRECTORY}/ngraph/frontend/onnx/*"
"${OV_COVERAGE_BASE_DIRECTORY}/ngraph/frontend/onnx/*")
ie_coverage_genhtml(INFO_FILE "onnx"
PREFIX "${OV_COVERAGE_BASE_DIRECTORY}")
endif()
7 changes: 3 additions & 4 deletions cmake/features.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,12 @@ else()
set(protoc_available ON)
endif()

ie_dependent_option(NGRAPH_ONNX_IMPORT_ENABLE "Enable ONNX importer" ON "protoc_available" OFF)
ie_dependent_option(NGRAPH_ONNX_FRONTEND_ENABLE "Enable ONNX FrontEnd" OFF "NGRAPH_ONNX_IMPORT_ENABLE" OFF)
ie_dependent_option(NGRAPH_ONNX_FRONTEND_ENABLE "Enable ONNX FrontEnd" ON "protoc_available" OFF)
ie_dependent_option(NGRAPH_PDPD_FRONTEND_ENABLE "Enable PaddlePaddle FrontEnd" ON "protoc_available" OFF)
ie_dependent_option(NGRAPH_USE_PROTOBUF_LITE "Compiles and links with protobuf-lite" ON
"NGRAPH_ONNX_IMPORT_ENABLE" OFF)
"NGRAPH_ONNX_FRONTEND_ENABLE" OFF)
ie_dependent_option(NGRAPH_USE_SYSTEM_PROTOBUF "Use system protobuf" OFF
"NGRAPH_ONNX_IMPORT_ENABLE OR NGRAPH_PDPD_FRONTEND_ENABLE" OFF)
"NGRAPH_ONNX_FRONTEND_ENABLE OR NGRAPH_PDPD_FRONTEND_ENABLE" OFF)
ie_dependent_option(NGRAPH_UNIT_TEST_ENABLE "Enables ngraph unit tests" ON "ENABLE_TESTS;NOT ANDROID" OFF)
ie_dependent_option(NGRAPH_UNIT_TEST_BACKENDS_ENABLE "Control the building of unit tests using backends" ON
"NGRAPH_UNIT_TEST_ENABLE" OFF)
Expand Down
25 changes: 18 additions & 7 deletions cmake/templates/ngraphConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -28,28 +28,39 @@
#
# ngraph::frontend_manager - nGraph frontend manager
#
# ngraph_onnx_importer_FOUND - True if the system has onnx_importer library
# ngraph::onnx_importer - ONNX importer target (optional)
# ONNX_IMPORTER_LIBRARIES - ONNX importer libraries
# ngraph_onnx_ngraph_frontend_FOUND - True if the system has onnx_ngraph_frontend library
# ngraph::onnx_ngraph_frontend - ONNX FrontEnd target (optional)
#
# ngraph_paddlepaddle_frontend_FOUND - True if the system has PDPD frontend
# ngraph::paddlepaddle_ngraph_frontend - nGraph PDPD frontend (optional)
#

@PACKAGE_INIT@

function(set_imported_global target)
get_target_property(IS_IMPORTED_GLOBAL ${target} IMPORTED_GLOBAL)
if (NOT IS_IMPORTED_GLOBAL)
set_target_properties(${target} PROPERTIES IMPORTED_GLOBAL TRUE)
endif()
endfunction()

if(NOT TARGET ngraph)
include("${CMAKE_CURRENT_LIST_DIR}/ngraphTargets.cmake")
set_imported_global(ngraph::ngraph)
set_imported_global(ngraph::frontend_manager)
endif()

set(ngraph_ngraph_FOUND ON)
set(NGRAPH_LIBRARIES ngraph::ngraph)

set(ngraph_onnx_importer_FOUND @NGRAPH_ONNX_IMPORT_ENABLE@)
if(ngraph_onnx_importer_FOUND)
set(ONNX_IMPORTER_LIBRARIES ngraph::onnx_importer)
set(ngraph_onnx_ngraph_frontend_FOUND @NGRAPH_ONNX_FRONTEND_ENABLE@)
if (ngraph_onnx_ngraph_frontend_FOUND AND NOT TARGET onnx_ngraph_frontend AND NOT TARGET ngraph::onnx_importer)
set_imported_global(ngraph::onnx_ngraph_frontend)
add_library(ngraph::onnx_importer ALIAS ngraph::onnx_ngraph_frontend)
endif()

set(ngraph_paddlepaddle_frontend_FOUND @NGRAPH_PDPD_FRONTEND_ENABLE@)
if(ngraph_paddlepaddle_frontend_FOUND AND NOT TARGET paddlepaddle_ngraph_frontend)
set_imported_global(ngraph::paddlepaddle_ngraph_frontend)
endif()

check_required_components(ngraph)
4 changes: 2 additions & 2 deletions cmake/test_model_zoo.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function(ov_model_convert SRC DST OUT)
get_filename_component(name_we "${in_file}" NAME_WE)
set(model_source_dir "${SRC}/${rel_dir}")

if(NOT NGRAPH_ONNX_IMPORT_ENABLE AND ext MATCHES "^\\.(onnx|prototxt)$")
if(NOT NGRAPH_ONNX_FRONTEND_ENABLE AND ext MATCHES "^\\.(onnx|prototxt)$")
# don't copy / process ONNX / prototxt files
continue()
endif()
Expand Down Expand Up @@ -78,7 +78,7 @@ ov_model_convert("${OpenVINO_SOURCE_DIR}/${rel_path}"
ie_onnx_import_out_files)

if(ENABLE_TESTS)
if(NGRAPH_ONNX_IMPORT_ENABLE AND ENABLE_REQUIREMENTS_INSTALL)
if(NGRAPH_ONNX_FRONTEND_ENABLE AND ENABLE_REQUIREMENTS_INSTALL)
find_package(PythonInterp 3 REQUIRED)

get_filename_component(PYTHON_EXEC_DIR ${PYTHON_EXECUTABLE} DIRECTORY)
Expand Down
2 changes: 1 addition & 1 deletion docs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ if(NOT ENABLE_DOCKER)
set(InferenceEngine_DIR ${CMAKE_BINARY_DIR})
endif()

if(NGRAPH_ONNX_IMPORT_ENABLE)
if(NGRAPH_ONNX_FRONTEND_ENABLE)
add_subdirectory(onnx_custom_op)
endif()
add_subdirectory(template_extension)
Expand Down
7 changes: 3 additions & 4 deletions docs/IE_DG/Extensibility_DG/Custom_ONNX_Ops.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,9 @@ The example below demonstrates how to unregister an operator from the destructor
## Requirements for Building with CMake

A program that uses the `register_operator` functionality requires `ngraph` and `onnx_importer` libraries in addition to the Inference Engine.
The `onnx_importer` is a component of the `ngraph` package , so `find_package(ngraph REQUIRED COMPONENTS onnx_importer)` can find both.
The `ngraph` package exposes two variables, `${NGRAPH_LIBRARIES}` and `${ONNX_IMPORTER_LIBRARIES}`, which reference the `ngraph` and `onnx_importer` libraries.
Those variables need to be passed to the `target_link_libraries` command in the CMakeLists.txt file.
A program that uses the `register_operator` functionality requires `ngraph::ngraph` and `ngraph::onnx_ngraph_frontend` libraries in addition to the Inference Engine.
The `onnx_ngraph_frontend` is a component of the `ngraph` package , so `find_package(ngraph REQUIRED COMPONENTS onnx_ngraph_frontend)` can find both.
Those libraries need to be passed to the `target_link_libraries` command in the CMakeLists.txt file.

See CMakeLists.txt below for reference:
@snippet onnx_custom_op/CMakeLists.txt cmake:onnx_custom_op
4 changes: 2 additions & 2 deletions docs/onnx_custom_op/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ set(CMAKE_CXX_STANDARD 11)

set(TARGET_NAME "onnx_custom_op")

find_package(ngraph REQUIRED COMPONENTS onnx_importer)
find_package(ngraph REQUIRED COMPONENTS onnx_ngraph_frontend)

add_library(${TARGET_NAME} STATIC onnx_custom_op.cpp onnx_custom_op.hpp)

target_link_libraries(${TARGET_NAME} PUBLIC ${NGRAPH_LIBRARIES} ${ONNX_IMPORTER_LIBRARIES})
target_link_libraries(${TARGET_NAME} PUBLIC ngraph::ngraph ngraph::onnx_ngraph_frontend)
# [cmake:onnx_custom_op]

# Enable code style check
Expand Down
4 changes: 2 additions & 2 deletions docs/snippets/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ if(OpenCV_FOUND)
target_link_libraries(${TARGET_NAME} PRIVATE opencv_core)
endif()

if(NGRAPH_ONNX_IMPORT_ENABLE)
target_link_libraries(${TARGET_NAME} PRIVATE onnx_importer)
if(NGRAPH_ONNX_FRONTEND_ENABLE)
target_link_libraries(${TARGET_NAME} PRIVATE onnx_ngraph_frontend)
endif()

if(NOT MSVC)
Expand Down
8 changes: 4 additions & 4 deletions docs/template_extension/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ set(CMAKE_CXX_STANDARD 11)

set(TARGET_NAME "template_extension")

find_package(ngraph REQUIRED OPTIONAL_COMPONENTS onnx_importer)
find_package(ngraph REQUIRED OPTIONAL_COMPONENTS onnx_ngraph_frontend)
find_package(InferenceEngine REQUIRED)
find_package(OpenCV QUIET COMPONENTS core)

Expand All @@ -28,9 +28,9 @@ target_compile_definitions(${TARGET_NAME} PRIVATE IMPLEMENT_INFERENCE_EXTENSION_
target_link_libraries(${TARGET_NAME} PRIVATE IE::inference_engine
${NGRAPH_LIBRARIES})

if (ngraph_onnx_importer_FOUND)
target_link_libraries(${TARGET_NAME} PRIVATE ${ONNX_IMPORTER_LIBRARIES})
target_compile_definitions(${TARGET_NAME} PRIVATE NGRAPH_ONNX_IMPORT_ENABLED)
if (ngraph_onnx_ngraph_frontend_FOUND)
target_link_libraries(${TARGET_NAME} PRIVATE ngraph::onnx_ngraph_frontend)
target_compile_definitions(${TARGET_NAME} PRIVATE NGRAPH_ONNX_FRONTEND_ENABLED)
endif()
# [cmake:extension]

Expand Down
8 changes: 4 additions & 4 deletions docs/template_extension/extension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# include "fft_op.hpp"
#endif
#include <ngraph/ngraph.hpp>
#ifdef NGRAPH_ONNX_IMPORT_ENABLED
#ifdef NGRAPH_ONNX_FRONTEND_ENABLED
# include <onnx_import/onnx_utils.hpp>
#endif

Expand All @@ -24,7 +24,7 @@ using namespace TemplateExtension;

//! [extension:ctor]
Extension::Extension() {
#ifdef NGRAPH_ONNX_IMPORT_ENABLED
#ifdef NGRAPH_ONNX_FRONTEND_ENABLED
ngraph::onnx_import::register_operator(Operation::type_info.name,
1,
"custom_domain",
Expand All @@ -49,12 +49,12 @@ Extension::Extension() {

//! [extension:dtor]
Extension::~Extension() {
#ifdef NGRAPH_ONNX_IMPORT_ENABLED
#ifdef NGRAPH_ONNX_FRONTEND_ENABLED
ngraph::onnx_import::unregister_operator(Operation::type_info.name, 1, "custom_domain");
# ifdef OPENCV_IMPORT_ENABLED
ngraph::onnx_import::unregister_operator(FFTOp::type_info.name, 1, "custom_domain");
# endif // OPENCV_IMPORT_ENABLED
#endif // NGRAPH_ONNX_IMPORT_ENABLED
#endif // NGRAPH_ONNX_FRONTEND_ENABLED
}
//! [extension:dtor]

Expand Down
2 changes: 1 addition & 1 deletion inference-engine/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@ add_custom_target(ie_libraries ALL
inference_engine_ir_v7_reader inference_engine_ir_reader
inference_engine_lp_transformations inference_engine_snippets)

if(NGRAPH_ONNX_IMPORT_ENABLE)
if(NGRAPH_ONNX_FRONTEND_ENABLE)
add_dependencies(ie_libraries inference_engine_onnx_reader)
endif()
2 changes: 1 addition & 1 deletion inference-engine/src/readers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ add_cpplint_target(${TARGET_NAME}_cpplint FOR_SOURCES ${reader_api_hpp})
add_subdirectory(ir_reader)
add_subdirectory(ir_reader_v7)

if(NGRAPH_ONNX_IMPORT_ENABLE)
if(NGRAPH_ONNX_FRONTEND_ENABLE)
add_subdirectory(onnx_reader)
endif()
2 changes: 1 addition & 1 deletion inference-engine/src/readers/onnx_reader/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ target_include_directories(${TARGET_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})

target_compile_definitions(${TARGET_NAME} PRIVATE IMPLEMENT_INFERENCE_ENGINE_PLUGIN)

target_link_libraries(${TARGET_NAME} PRIVATE inference_engine_reader_api onnx_importer inference_engine)
target_link_libraries(${TARGET_NAME} PRIVATE inference_engine_reader_api onnx_ngraph_frontend inference_engine)

ie_add_api_validator_post_build_step(TARGET ${TARGET_NAME})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ set(DEPENDENCIES
test_model_zoo
)

if (NOT NGRAPH_ONNX_IMPORT_ENABLE)
if (NOT NGRAPH_ONNX_FRONTEND_ENABLE)
list(APPEND EXCLUDED_SOURCE_PATHS "${CMAKE_CURRENT_SOURCE_DIR}/onnx_reader")
endif()

Expand All @@ -56,9 +56,9 @@ addIeTargetTest(

set_ie_threading_interface_for(${TARGET_NAME})

if(NGRAPH_ONNX_IMPORT_ENABLE)
if(NGRAPH_ONNX_FRONTEND_ENABLE)
target_compile_definitions(${TARGET_NAME} PRIVATE
NGRAPH_ONNX_IMPORT_ENABLE
NGRAPH_ONNX_FRONTEND_ENABLE
ONNX_TEST_MODELS="${TEST_MODEL_ZOO}/onnx_reader/models/")
add_dependencies(${TARGET_NAME} inference_engine_onnx_reader)
endif()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ TEST_F(CustomOpsSerializationTest, CustomOpUser_MO) {
ASSERT_TRUE(success) << message;
}

#ifdef NGRAPH_ONNX_IMPORT_ENABLE
#ifdef NGRAPH_ONNX_FRONTEND_ENABLE

TEST_F(CustomOpsSerializationTest, CustomOpUser_ONNXImporter) {
const std::string model = CommonTestUtils::getModelFromTestModelZoo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class SerializationDeterministicityTest : public ::testing::Test {
}
};

#ifdef NGRAPH_ONNX_IMPORT_ENABLE
#ifdef NGRAPH_ONNX_FRONTEND_ENABLE

TEST_F(SerializationDeterministicityTest, BasicModel) {
const std::string model = CommonTestUtils::getModelFromTestModelZoo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ INSTANTIATE_TEST_SUITE_P(IRSerialization, SerializationTest,
std::make_tuple("loop_2d_add.xml", "loop_2d_add.bin"),
std::make_tuple("nms5_dynamism.xml", "nms5_dynamism.bin")));

#ifdef NGRAPH_ONNX_IMPORT_ENABLE
#ifdef NGRAPH_ONNX_FRONTEND_ENABLE

INSTANTIATE_TEST_SUITE_P(ONNXSerialization, SerializationTest,
testing::Values(std::make_tuple("add_abc.onnx", ""),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ target_link_libraries(cpuSpecificRtInfo PRIVATE ngraph)
set(INCLUDES ${CMAKE_CURRENT_SOURCE_DIR} ${IE_MAIN_SOURCE_DIR}/src/mkldnn_plugin)
set(DEPENDENCIES MKLDNNPlugin AutoPlugin)
set(LINK_LIBRARIES funcSharedTests cpuSpecificRtInfo)
if (NGRAPH_ONNX_IMPORT_ENABLE)
if (NGRAPH_ONNX_FRONTEND_ENABLE)
list(APPEND INCLUDES "${OpenVINO_SOURCE_DIR}/docs/onnx_custom_op")
list(APPEND LINK_LIBRARIES onnx_custom_op)
list(APPEND DEPENDENCIES template_extension onnx_custom_op)
Expand Down
2 changes: 1 addition & 1 deletion inference-engine/tests/unit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ if (ENABLE_MYRIAD)
add_subdirectory(vpu)
endif ()

if(NGRAPH_ONNX_IMPORT_ENABLE)
if(NGRAPH_ONNX_FRONTEND_ENABLE)
add_subdirectory(frontends/onnx_import)
endif()
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ addIeTargetTest(
gtest
gtest_main
commonTestUtils
onnx_importer
onnx_ngraph_frontend
DEFINES
ONNX_MODELS_DIR=\"${TEST_MODEL_ZOO}/onnx_import\"
ADD_CPPLINT
Expand Down
2 changes: 1 addition & 1 deletion ngraph/frontend/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ set(FRONTEND_INSTALL_INCLUDE "${NGRAPH_INSTALL_INCLUDE}/ngraph/frontend")

add_subdirectory(frontend_manager)

if (NGRAPH_ONNX_IMPORT_ENABLE)
if (NGRAPH_ONNX_FRONTEND_ENABLE)
add_subdirectory(onnx)
endif()

Expand Down
5 changes: 1 addition & 4 deletions ngraph/frontend/onnx/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,4 @@
#

add_subdirectory(onnx_common)
add_subdirectory(onnx_import)
if (NGRAPH_ONNX_FRONTEND_ENABLE)
add_subdirectory(frontend)
endif()
add_subdirectory(frontend)
Loading

0 comments on commit efc89a2

Please sign in to comment.