Skip to content

Commit

Permalink
LTO for frontends and python (#12890)
Browse files Browse the repository at this point in the history
  • Loading branch information
ilya-lavrenov authored Sep 5, 2022
1 parent 57a9d7c commit 8367658
Show file tree
Hide file tree
Showing 14 changed files with 27 additions and 15 deletions.
4 changes: 4 additions & 0 deletions cmake/developer_package/frontends/frontends.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@ macro(ov_add_frontend)
"-DGetAPIVersion=GetAPIVersion${OV_FRONTEND_NAME}")
endif()

# enable LTO
set_target_properties(${TARGET_NAME} PROPERTIES
INTERPROCEDURAL_OPTIMIZATION_RELEASE ${ENABLE_LTO})

if(OV_FRONTEND_SKIP_NCC_STYLE)
# frontend's CMakeLists.txt must define its own custom 'ov_ncc_naming_style' step
else()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ set_source_files_properties(${PYX_SOURCES} PROPERTIES CYTHON_IS_CXX ON)

cython_add_module(${TARGET_NAME} ${SOURCES})
ov_python_disable_intel_warnings(${TARGET_NAME})
set_target_properties(${TARGET_NAME} PROPERTIES INTERPROCEDURAL_OPTIMIZATION_RELEASE ${ENABLE_LTO})

set(INSTALLED_TARGETS ${TARGET_NAME})
list(REMOVE_ITEM PYX_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/ie_api.pyx")
Expand All @@ -34,6 +35,7 @@ foreach(PYX_FILE IN LISTS PYX_SOURCES)
target_link_libraries(${PYX_NAME} PRIVATE openvino::runtime)
list(APPEND INSTALLED_TARGETS ${PYX_NAME})
ie_python_minimal_api(${PYX_NAME})
set_target_properties(${PYX_NAME} PROPERTIES INTERPROCEDURAL_OPTIMIZATION_RELEASE ${ENABLE_LTO})
endforeach()

if(COMMAND ie_add_vs_version_file)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,14 @@ endif()

file(GLOB_RECURSE SOURCES *.cpp)

pybind11_add_module(_${PROJECT_NAME} MODULE ${SOURCES})
pybind11_add_module(_${PROJECT_NAME} MODULE NO_EXTRAS ${SOURCES})

target_include_directories(_${PROJECT_NAME} PRIVATE "../" "${OpenVINO_SOURCE_DIR}/src/common/transformations/include")

target_link_libraries(_${PROJECT_NAME} PRIVATE openvino::runtime)

set_target_properties(_${PROJECT_NAME} PROPERTIES INTERPROCEDURAL_OPTIMIZATION_RELEASE ${ENABLE_LTO})

# perform copy
if(OpenVINO_SOURCE_DIR)
add_custom_command(TARGET _${PROJECT_NAME}
Expand Down
3 changes: 2 additions & 1 deletion src/bindings/python/src/pyopenvino/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ endif()
file(GLOB_RECURSE SOURCES core/*.cpp graph/*.cpp frontend/*.cpp utils/*cpp pyopenvino.cpp)
list(FILTER SOURCES EXCLUDE REGEX frontend/onnx|tensorflow|paddle/* )

pybind11_add_module(${PROJECT_NAME} MODULE ${SOURCES})
pybind11_add_module(${PROJECT_NAME} MODULE NO_EXTRAS ${SOURCES})

if(TARGET offline_transformations)
set(OFFLINE_TRANSFORMATIONS_LIB offline_transformations)
Expand All @@ -77,6 +77,7 @@ endif()

target_include_directories(${PROJECT_NAME} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/..")
target_link_libraries(${PROJECT_NAME} PRIVATE openvino::runtime::dev openvino::runtime ${OFFLINE_TRANSFORMATIONS_LIB})
set_target_properties(${PROJECT_NAME} PROPERTIES INTERPROCEDURAL_OPTIMIZATION_RELEASE ${ENABLE_LTO})

addVersionDefines(pyopenvino.cpp CI_BUILD_NUMBER)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function(frontend_module TARGET FRAMEWORK INSTALL_COMPONENT)

# create target

pybind11_add_module(${TARGET_NAME} MODULE ${SOURCES})
pybind11_add_module(${TARGET_NAME} MODULE NO_EXTRAS ${SOURCES})

add_dependencies(${TARGET_NAME} pyopenvino)
add_dependencies(py_ov_frontends ${TARGET_NAME})
Expand All @@ -28,6 +28,8 @@ function(frontend_module TARGET FRAMEWORK INSTALL_COMPONENT)
"${PYTHON_SOURCE_DIR}/pyopenvino/utils/")
target_link_libraries(${TARGET_NAME} PRIVATE openvino::runtime openvino::frontend::${FRAMEWORK})

set_target_properties(${TARGET_NAME} PROPERTIES INTERPROCEDURAL_OPTIMIZATION_RELEASE ${ENABLE_LTO})

# Compatibility with python 2.7 which has deprecated "register" specifier
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
target_compile_options(${TARGET_NAME} PRIVATE "-Wno-error=register")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ namespace py = pybind11;

using namespace ov::frontend::tensorflow;


void regclass_frontend_tensorflow_ConversionExtension(py::module m) {
py::class_<ConversionExtension, ConversionExtension::Ptr, ov::frontend::ConversionExtensionBase> _ext(
m,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ file(GLOB SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/test_utils.cpp)

# create target

pybind11_add_module(${TARGET_NAME} MODULE ${SOURCES})
pybind11_add_module(${TARGET_NAME} MODULE NO_EXTRAS ${SOURCES})

add_dependencies(${TARGET_NAME} pyopenvino)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ set(PYBIND_FE_SRC ${CMAKE_CURRENT_SOURCE_DIR}/pyngraph_mock_frontend_api.cpp)

source_group("src" FILES ${PYBIND_FE_SRC})

pybind11_add_module(${PYBIND_FE_NAME} MODULE ${PYBIND_FE_SRC})
pybind11_add_module(${PYBIND_FE_NAME} MODULE NO_EXTRAS ${PYBIND_FE_SRC})

set(DEPENDENCIES openvino_mock_py_frontend openvino::runtime)
set(DEFINITIONS IMPLEMENT_OPENVINO_API)
Expand Down
5 changes: 2 additions & 3 deletions src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
# SPDX-License-Identifier: Apache-2.0
#

if(ENABLE_LTO)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE ON)
endif()
# enable LTO globally for all libraries below
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE ${ENABLE_LTO})

add_definitions(-DIN_OV_CORE_LIBRARY)

Expand Down
4 changes: 0 additions & 4 deletions src/frontends/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
# SPDX-License-Identifier: Apache-2.0
#

if(ENABLE_LTO)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE ON)
endif()

add_subdirectory(common)

if(ENABLE_TESTS)
Expand Down
2 changes: 2 additions & 0 deletions src/frontends/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ if(NOT BUILD_SHARED_LIBS)
endif()

target_link_libraries(${TARGET_NAME}_obj PRIVATE openvino::util openvino::core::dev)

# TODO: fix lto
set_target_properties(${TARGET_NAME}_obj PROPERTIES
INTERPROCEDURAL_OPTIMIZATION_RELEASE OFF)

Expand Down
4 changes: 3 additions & 1 deletion src/frontends/common/shutdown_protobuf/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#

set(TARGET_NAME ov_protobuf_shutdown)

add_library(${TARGET_NAME} STATIC shutdown_protobuf.cpp)
target_sources(${TARGET_NAME} INTERFACE shutdown_protobuf.cpp)

target_include_directories(${TARGET_NAME} SYSTEM PRIVATE $<BUILD_INTERFACE:${Protobuf_INCLUDE_DIRS}>)
set_target_properties(${TARGET_NAME} PROPERTIES INTERPROCEDURAL_OPTIMIZATION_RELEASE ${ENABLE_LTO})
3 changes: 2 additions & 1 deletion src/frontends/onnx/onnx_common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ source_group("include" FILES ${PUBLIC_HEADERS} ${PUBLIC_HEADERS})

add_library(${TARGET_NAME} STATIC ${LIBRARY_SRC} ${PUBLIC_HEADERS})

# TODO Add handling ie_faster_build
set_target_properties(${TARGET_NAME} PROPERTIES
INTERPROCEDURAL_OPTIMIZATION_RELEASE ${ENABLE_LTO})

set(ONNX_COMMON_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include)
set(ONNX_COMMON_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ add_subdirectory(${OpenVINO_SOURCE_DIR}/src/bindings/python/thirdparty/pybind11
${CMAKE_CURRENT_BINARY_DIR}/pybind11_build
EXCLUDE_FROM_ALL)

pybind11_add_module(${PYBIND_FE_NAME} MODULE ${PYBIND_FE_SRC})
pybind11_add_module(${PYBIND_FE_NAME} MODULE NO_EXTRAS ${PYBIND_FE_SRC})

target_link_libraries(${PYBIND_FE_NAME} PRIVATE openvino::runtime)
target_link_libraries(${PYBIND_FE_NAME} PRIVATE ${TARGET_FE_NAME})
Expand Down

0 comments on commit 8367658

Please sign in to comment.