Skip to content

Commit

Permalink
Openvino cmake config (openvinotoolkit#7419)
Browse files Browse the repository at this point in the history
* Added OpenVINOConfig.cmake

* OpenVINOConfig.cmake part 2

* Trying to fix cmake generation

* Fixes

* Export frontends as well

* Fixed condition

* Added OpenVINO cmake package usage: docs, C samples

* Use more OpenVINO config

* Install OpenVINOConfig.cmake

* Trying to fix private plugins

* Trying to fix .tox

* Trying to fix ARM

* Fixed samples build

* Explicit ngraph duplicated targets

* Fixed fuzzing tests build

* Added IR frontend installation

* Removed install directory for IE reader

* Removed IR frontend from export list

* Reverted ngraph_DIR

* Try to fix .tox

* Fixed ieFuncTests with ONNX extensions

* Attempt #2

* Trying to fix ngraph setup.py

* Fix

* Trying to fix ONNX ngraph .tox CI

* Trying to remove spaces

* Fixed ngraph_DIR -> OpenVINO_DIR

* Removed junk files

* Try to fix ngraph wheel

* Try to fix ie_wheel

* Try to fix ngraph wheel
  • Loading branch information
ilya-lavrenov authored Sep 10, 2021
1 parent deeb964 commit a952540
Show file tree
Hide file tree
Showing 51 changed files with 523 additions and 174 deletions.
2 changes: 1 addition & 1 deletion .ci/openvino-onnx/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ RUN make -j $(nproc) install

# Run tests via tox
WORKDIR /openvino/runtime/bindings/python
ENV ngraph_DIR=/openvino/dist/deployment_tools/ngraph
ENV OpenVINO_DIR=/openvino/dist/deployment_tools/inference_engine/share
ENV LD_LIBRARY_PATH=/openvino/dist/deployment_tools/ngraph/lib
ENV PYTHONPATH=/openvino/bin/intel64/${BUILD_TYPE}/lib/python_api/python3.8:${PYTHONPATH}
CMD tox
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ message (STATUS "CMAKE_BUILD_TYPE ...................... " ${CMAKE_BUILD_TYPE})

# remove file with exported developer targets to force its regeneration
file(REMOVE "${CMAKE_BINARY_DIR}/InferenceEngineTargets.cmake")
file(REMOVE "${CMAKE_BINARY_DIR}/OpenVINOTargets.cmake")
foreach(component IN LISTS openvino_export_components)
file(REMOVE "${CMAKE_BINARY_DIR}/${component}_dev_targets.cmake")
unset(${component} CACHE)
Expand Down Expand Up @@ -83,13 +84,14 @@ include(cmake/test_model_zoo.cmake)
add_subdirectory(thirdparty)
add_subdirectory(openvino)
add_subdirectory(ngraph)

add_subdirectory(runtime)
add_subdirectory(inference-engine)

# for Template plugin
openvino_developer_export_targets(COMPONENT ngraph TARGETS ngraph_backend interpreter_backend)
include(cmake/extra_modules.cmake)

add_subdirectory(runtime)
add_subdirectory(model-optimizer)
add_subdirectory(docs)
add_subdirectory(tools)
Expand Down
19 changes: 19 additions & 0 deletions cmake/templates/InferenceEngineConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,25 @@ _ie_find_dependency(ngraph
if(NOT TARGET inference_engine)
set(_ie_as_external_package ON)
include("${CMAKE_CURRENT_LIST_DIR}/InferenceEngineTargets.cmake")

# create targets with old names for compatibility
if(TARGET IE::runtime AND NOT TARGET IE::inference_engine)
add_library(IE::inference_engine INTERFACE IMPORTED)
set_target_properties(IE::inference_engine PROPERTIES
INTERFACE_LINK_LIBRARIES IE::runtime)
endif()

if(TARGET IE::core AND NOT TARGET ngraph::ngraph)
add_library(IE::ngraph INTERFACE IMPORTED)
set_target_properties(IE::ngraph PROPERTIES
INTERFACE_LINK_LIBRARIES IE::core)
endif()

if(TARGET IE::runtime::c AND NOT TARGET IE::inference_engine_c_api)
add_library(IE::inference_engine_c_api INTERFACE IMPORTED)
set_target_properties(IE::inference_engine_c_api PROPERTIES
INTERFACE_LINK_LIBRARIES IE::runtime::c)
endif()
endif()

# mark components as available
Expand Down
11 changes: 9 additions & 2 deletions cmake/templates/InferenceEngineDeveloperPackageConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,17 @@ find_dependency(InferenceEngine
NO_CMAKE_FIND_ROOT_PATH
NO_DEFAULT_PATH)

find_dependency(OpenVINO
PATHS "${CMAKE_CURRENT_LIST_DIR}"
NO_CMAKE_FIND_ROOT_PATH
NO_DEFAULT_PATH)

# WA for cmake: it exports ngraph as IE::ngraph in the IE export list
# while we already have ngraph export in its own export list as ngraph::ngraph
set_property(TARGET ngraph::ngraph PROPERTY IMPORTED_GLOBAL TRUE)
add_library(IE::ngraph ALIAS ngraph::ngraph)
if(TARGET ngraph::ngraph AND NOT TARGET IE::ngraph)
add_library(IE::ngraph INTERFACE IMPORTED)
set_target_properties(IE::ngraph PROPERTIES INTERFACE_LINK_LIBRARIES ngraph::ngraph)
endif()

foreach(component @openvino_export_components@)
include("${CMAKE_CURRENT_LIST_DIR}/${component}_dev_targets.cmake")
Expand Down
21 changes: 21 additions & 0 deletions cmake/templates/OpenVINOConfig-version.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright (C) 2018-2021 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
#

set(PACKAGE_VERSION_MAJOR @IE_VERSION_MAJOR@)
set(PACKAGE_VERSION_MINOR @IE_VERSION_MINOR@)
set(PACKAGE_VERSION_PATCH @IE_VERSION_PATCH@)
set(PACKAGE_VERSION "${PACKAGE_VERSION_MAJOR}.${PACKAGE_VERSION_MINOR}.${PACKAGE_VERSION_PATCH}")

set(PACKAGE_VERSION_EXACT False)
set(PACKAGE_VERSION_COMPATIBLE False)

if(PACKAGE_FIND_VERSION VERSION_EQUAL PACKAGE_VERSION)
set(PACKAGE_VERSION_EXACT True)
set(PACKAGE_VERSION_COMPATIBLE True)
endif()

if(PACKAGE_FIND_VERSION_MAJOR EQUAL PACKAGE_VERSION_MAJOR AND
PACKAGE_FIND_VERSION VERSION_LESS PACKAGE_VERSION)
set(PACKAGE_VERSION_COMPATIBLE True)
endif()
203 changes: 203 additions & 0 deletions cmake/templates/OpenVINOConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
# Copyright (C) 2018-2021 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
#
# FindOpenVINO
# ------
#
# Provides OpenVINO runtime for model creation and inference, frontend libraries
# to convert models from framework specific formats.
#
# The following components are supported:
#
# * `Runtime`: OpenVINO C++ and C Core & Inference Runtime, frontend manager
# * `ONNX`: OpenVINO ONNX frontend
# * `PaddlePaddle`: OpenVINO PaddlePaddle frontend
#
# If no components are specified, `Runtime` component is provided:
#
# find_package(OpenVINO REQUIRED) # only Runtime component
#
# If specific components are required:
#
# find_package(OpenVINO REQUIRED COMPONENTS Runtime ONNX)
#
# Imported Targets:
# ------
#
# Runtime targets:
#
# `openvino::runtime`
# The OpenVINO C++ Core & Inference Runtime
#
# `openvino::runtime::c`
# The OpenVINO C Inference Runtime
#
# `openvino::core`
# The OpenVINO C++ Core Runtime
#
# Frontend specific targets:
#
# `openvino::frontend::manager`
# OpenVINO frontend manager
#
# `openvino::frontend::onnx`
# ONNX FrontEnd target (optional)
#
# `openvino::frontend::paddlepaddle`
# PaddlePaddle FrontEnd target (optional)
#
# Result variables:
# ------
#
# The module sets the following variables in your project:
#
# `OpenVINO_FOUND`
# System has OpenVINO Runtime installed
#
# `OpenVINO_Runtime_FOUND`
# OpenVINO C++ Core & Inference Runtime is available
#
# `OpenVINO_Frontend_ONNX_FOUND`
# OpenVINO ONNX frontend is available
#
# `OpenVINO_Frontend_PaddlePaddle_FOUND`
# OpenVINO PaddlePaddle frontend is available
#
# OpenVINO version variables:
#
# `OpenVINO_VERSION_MAJOR`
# Major version component
#
# `OpenVINO_VERSION_MINOR`
# minor version component
#
# `OpenVINO_VERSION_PATCH`
# Patch version component
#

@PACKAGE_INIT@

#
# Common functions
#

if(NOT DEFINED CMAKE_FIND_PACKAGE_NAME)
set(CMAKE_FIND_PACKAGE_NAME OpenVINO)
set(_need_package_name_reset ON)
endif()

# we have to use our own version of find_dependency because of support cmake 3.7
macro(_ov_find_dependency dep)
set(cmake_fd_quiet_arg)
if(${CMAKE_FIND_PACKAGE_NAME}_FIND_QUIETLY)
set(cmake_fd_quiet_arg QUIET)
endif()
set(cmake_fd_required_arg)
if(${CMAKE_FIND_PACKAGE_NAME}_FIND_REQUIRED)
set(cmake_fd_required_arg REQUIRED)
endif()

get_property(cmake_fd_alreadyTransitive GLOBAL PROPERTY
_CMAKE_${dep}_TRANSITIVE_DEPENDENCY)

find_package(${dep} ${ARGN}
${cmake_fd_quiet_arg}
${cmake_fd_required_arg})

if(NOT DEFINED cmake_fd_alreadyTransitive OR cmake_fd_alreadyTransitive)
set_property(GLOBAL PROPERTY _CMAKE_${dep}_TRANSITIVE_DEPENDENCY TRUE)
endif()

if(NOT ${dep}_FOUND)
set(${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE "${CMAKE_FIND_PACKAGE_NAME} could not be found because dependency ${dep} could not be found.")
set(${CMAKE_FIND_PACKAGE_NAME}_FOUND False)
return()
endif()

set(cmake_fd_required_arg)
set(cmake_fd_quiet_arg)
endmacro()

function(_ov_target_no_deprecation_error)
if(NOT MSVC)
if(CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
set(flags "-diag-warning=1786")
else()
set(flags "-Wno-error=deprecated-declarations")
endif()
if(CMAKE_CROSSCOMPILING)
set_target_properties(${ARGV} PROPERTIES
INTERFACE_LINK_OPTIONS "-Wl,--allow-shlib-undefined")
endif()

set_target_properties(${ARGV} PROPERTIES INTERFACE_COMPILE_OPTIONS ${flags})
endif()
endfunction()

#
# OpenVINO config
#

# need to store current PACKAGE_PREFIX_DIR, because it's overwritten by sub-package one
set(_ov_package_prefix_dir "${PACKAGE_PREFIX_DIR}")

set(THREADING "@THREADING@")
if(THREADING STREQUAL "TBB" OR THREADING STREQUAL "TBB_AUTO" AND NOT TBB_FOUND)
set_and_check(_tbb_dir "@PACKAGE_IE_TBB_DIR@")
_ov_find_dependency(TBB
COMPONENTS tbb tbbmalloc
CONFIG
PATHS ${TBBROOT}/cmake
${_tbb_dir}
NO_CMAKE_FIND_ROOT_PATH
NO_DEFAULT_PATH)
endif()

if(NOT TARGET inference_engine)
set(_ov_as_external_package ON)
include("${CMAKE_CURRENT_LIST_DIR}/OpenVINOTargets.cmake")
endif()

#
# Components
#

set(${CMAKE_FIND_PACKAGE_NAME}_Runtime_FOUND ON)

set(${CMAKE_FIND_PACKAGE_NAME}_ONNX_FOUND @NGRAPH_ONNX_FRONTEND_ENABLE@)
set(${CMAKE_FIND_PACKAGE_NAME}_PaddlePaddle_FOUND @NGRAPH_PDPD_FRONTEND_ENABLE@)

set(${CMAKE_FIND_PACKAGE_NAME}_Frontend_ONNX_FOUND ${${CMAKE_FIND_PACKAGE_NAME}_ONNX_FOUND})
set(${CMAKE_FIND_PACKAGE_NAME}_Frontend_PaddlePaddle_FOUND ${${CMAKE_FIND_PACKAGE_NAME}_PaddlePaddle_FOUND})

# if no components specified, only Runtime is provided
if(NOT ${CMAKE_FIND_PACKAGE_NAME}_FIND_COMPONENTS)
set(${CMAKE_FIND_PACKAGE_NAME}_FIND_COMPONENTS Runtime)
endif()

#
# Apply common functions
#

foreach(target openvino::runtime openvino::runtime::c openvino::core
openvino::frontend::manager openvino::frontend::onnx
openvino::frontend::paddlepaddle)
if(TARGET ${target} AND _ov_as_external_package)
_ov_target_no_deprecation_error(${target})
endif()
endforeach()
unset(_ov_as_external_package)

# restore PACKAGE_PREFIX_DIR
set(PACKAGE_PREFIX_DIR ${_ov_package_prefix_dir})
unset(_ov_package_prefix_dir)

check_required_components(${CMAKE_FIND_PACKAGE_NAME})

if(_need_package_name_reset)
unset(CMAKE_FIND_PACKAGE_NAME)
unset(_need_package_name_reset)
endif()

unset(${CMAKE_FIND_PACKAGE_NAME}_PaddlePaddle_FOUND)
unset(${CMAKE_FIND_PACKAGE_NAME}_ONNX_FOUND)
32 changes: 28 additions & 4 deletions cmake/templates/ngraphConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -39,26 +39,50 @@

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

# create targets with old names for compatibility
if(TARGET ngraph::core AND NOT TARGET ngraph::ngraph)
add_library(ngraph::ngraph INTERFACE IMPORTED)
set_target_properties(ngraph::ngraph PROPERTIES
INTERFACE_LINK_LIBRARIES ngraph::core)
endif()

if(TARGET ngraph::frontend::manager AND NOT TARGET ngraph::frontend_manager)
add_library(ngraph::frontend_manager INTERFACE IMPORTED)
set_target_properties(ngraph::frontend_manager PROPERTIES
INTERFACE_LINK_LIBRARIES ngraph::frontend::manager)
endif()

if(TARGET ngraph::frontend::onnx AND NOT TARGET ngraph::onnx_ngraph_frontend)
add_library(ngraph::onnx_ngraph_frontend INTERFACE IMPORTED)
set_target_properties(ngraph::onnx_ngraph_frontend PROPERTIES
INTERFACE_LINK_LIBRARIES ngraph::frontend::onnx)
endif()

if(TARGET ngraph::frontend::paddlepaddle AND NOT TARGET ngraph::paddlepaddle_ngraph_frontend)
add_library(ngraph::paddlepaddle_ngraph_frontend INTERFACE IMPORTED)
set_target_properties(ngraph::paddlepaddle_ngraph_frontend PROPERTIES
INTERFACE_LINK_LIBRARIES ngraph::frontend::paddlepaddle)
endif()
endif()

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

set(ngraph_onnx_ngraph_frontend_FOUND @NGRAPH_ONNX_FRONTEND_ENABLE@)

# ngraph::onnx_importer target and variables are deprecated
set(ngraph_onnx_importer_FOUND @NGRAPH_ONNX_FRONTEND_ENABLE@)
if(ngraph_onnx_importer_FOUND)
set(ONNX_IMPORTER_LIBRARIES ngraph::onnx_ngraph_frontend)
# ngraph::onnx_importer target and variables are deprecated
# but need to create a dummy target for BW compatibility
if(NOT TARGET ngraph::onnx_importer)
add_library(ngraph::onnx_importer INTERFACE IMPORTED)
set_target_properties(ngraph::onnx_importer PROPERTIES
INTERFACE_LINK_LIBRARIES ngraph::onnx_ngraph_frontend
)
INTERFACE_LINK_LIBRARIES ngraph::onnx_ngraph_frontend)
endif()
endif()

set(ngraph_paddlepaddle_frontend_FOUND @NGRAPH_PDPD_FRONTEND_ENABLE@)
set(ir_frontend_FOUND @IR_FRONTEND_ENABLE@)

check_required_components(ngraph)
18 changes: 5 additions & 13 deletions docs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,12 @@ if(NOT ENABLE_DOCKER)

add_subdirectory(snippets)

# Detect nGraph
find_package(ngraph QUIET
PATHS "${CMAKE_BINARY_DIR}/ngraph"
NO_DEFAULT_PATH)
if(NOT ngraph_FOUND)
set(ngraph_DIR ${CMAKE_BINARY_DIR}/ngraph)
endif()

# Detect InferenceEngine
find_package(InferenceEngine QUIET
# Detect OpenVINO
find_package(OpenVINO QUIET
PATHS "${CMAKE_BINARY_DIR}"
NO_DEFAULT_PATH)
if(NOT InferenceEngine_FOUND)
set(InferenceEngine_DIR ${CMAKE_BINARY_DIR})
if(NOT OpenVINO_FOUND)
set(OpenVINO_DIR ${CMAKE_BINARY_DIR})
endif()

if(NGRAPH_ONNX_FRONTEND_ENABLE)
Expand Down Expand Up @@ -72,7 +64,7 @@ function(build_docs)
set(C_API "${IE_SOURCE_DIR}/ie_bridges/c/include")
set(PLUGIN_API_DIR "${DOCS_BUILD_DIR}/IE_PLUGIN_DG")
set(NGRAPH_DIR "${OpenVINO_SOURCE_DIR}/ngraph")
set(NGRAPH_PY_DIR "${NGRAPH_DIR}/python/src/ngraph/")
set(NGRAPH_PY_DIR "${OpenVINO_SOURCE_DIR}/runtime/bindings/python/src/compatibility/ngraph/")
set(NGRAPH_CPP_DIR "${NGRAPH_DIR}/core/include/" "${NGRAPH_DIR}/frontend/onnx_import/include")

# Preprocessing scripts
Expand Down
Loading

0 comments on commit a952540

Please sign in to comment.