Skip to content

Commit

Permalink
Enabled LTO for ONNX FE (#6878)
Browse files Browse the repository at this point in the history
* Fixed Windows public precommit

* ONNX LTO
  • Loading branch information
ilya-lavrenov authored Aug 2, 2021
1 parent 0af234b commit eabec38
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 29 deletions.
1 change: 0 additions & 1 deletion cmake/developer_package/compile_flags/os_flags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,6 @@ else()
if(APPLE)
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-dead_strip")
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,-dead_strip")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-dead_strip")
elseif(LINUX)
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--gc-sections -Wl,--exclude-libs,ALL")
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,--gc-sections -Wl,--exclude-libs,ALL")
Expand Down
2 changes: 0 additions & 2 deletions ngraph/frontend/onnx/onnx_common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
# SPDX-License-Identifier: Apache-2.0
#

set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE OFF)

set(TARGET_NAME "onnx_common")

file(GLOB_RECURSE LIBRARY_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp)
Expand Down
1 change: 0 additions & 1 deletion ngraph/frontend/onnx/onnx_import/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# SPDX-License-Identifier: Apache-2.0
#

set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE OFF)
set(ONNX_OPSET_VERSION 13 CACHE INTERNAL "Supported version of ONNX operator set")

file(GLOB_RECURSE LIBRARY_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp)
Expand Down
5 changes: 5 additions & 0 deletions ngraph/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,11 @@ if (NGRAPH_ONNX_IMPORT_ENABLE)
target_include_directories(unit-test PRIVATE ${ONNX_IMPORTER_SRC_DIR}/src)

target_link_libraries(unit-test PRIVATE onnx_importer)
if (LINUX)
target_link_options(unit-test PRIVATE -Wl,--exclude-libs,ALL)
elseif(APPLE)
target_link_options(unit-test PRIVATE -Wl,-dead_strip)
endif()
endif()

install(TARGETS unit-test
Expand Down
6 changes: 2 additions & 4 deletions thirdparty/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,10 @@ if(NGRAPH_PDPD_FRONTEND_ENABLE OR NGRAPH_ONNX_IMPORT_ENABLE)
endif()
find_package(Protobuf 3.9.0 REQUIRED)
set(Protobuf_LITE_LIBRARIES protobuf::libprotobuf-lite)
set(Protobuf_LIBRARIES protobuf::libprotobuf)
set(SYSTEM_PROTOC protobuf::protoc)
set(PROTOC_EXECUTABLE ${SYSTEM_PROTOC})

foreach(target ${SYSTEM_PROTOC} ${Protobuf_LIBRARIES} ${Protobuf_LITE_LIBRARIES})
foreach(target ${SYSTEM_PROTOC} ${Protobuf_LITE_LIBRARIES})
set_property(TARGET ${target} PROPERTY IMPORTED_GLOBAL TRUE)
endforeach()
else()
Expand All @@ -148,12 +147,11 @@ if(NGRAPH_PDPD_FRONTEND_ENABLE OR NGRAPH_ONNX_IMPORT_ENABLE)
# forward variables used in the other places
set(SYSTEM_PROTOC ${SYSTEM_PROTOC} PARENT_SCOPE)
set(PROTOC_EXECUTABLE ${PROTOC_EXECUTABLE} PARENT_SCOPE)
set(Protobuf_LIBRARIES ${Protobuf_LIBRARIES} PARENT_SCOPE)
set(Protobuf_LITE_LIBRARIES ${Protobuf_LITE_LIBRARIES} PARENT_SCOPE)
set(Protobuf_INCLUDE_DIRS ${Protobuf_INCLUDE_DIRS} PARENT_SCOPE)

# set public / interface compile options
foreach(target IN LISTS Protobuf_LITE_LIBRARIES Protobuf_LIBRARIES)
foreach(target IN LISTS Protobuf_LITE_LIBRARIES)
set(link_type PUBLIC)
if(NGRAPH_USE_SYSTEM_PROTOBUF)
set(link_type INTERFACE)
Expand Down
3 changes: 1 addition & 2 deletions thirdparty/onnx/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
# SPDX-License-Identifier: Apache-2.0
#

set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE OFF)

#------------------------------------------------------------------------------
# Configure and install libonnx ...
#------------------------------------------------------------------------------

set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE OFF)
set(NGRAPH_ONNX_NAMESPACE ngraph_onnx)
set(BUILD_SHARED_LIBS OFF)

Expand Down
26 changes: 7 additions & 19 deletions thirdparty/protobuf/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
# Configure Google Protobuf ...
#------------------------------------------------------------------------------

set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE OFF)
set(BUILD_SHARED_LIBS OFF)

if(SUGGEST_OVERRIDE_SUPPORTED)
Expand Down Expand Up @@ -58,32 +57,22 @@ target_include_directories(libprotobuf-lite SYSTEM PRIVATE "${Protobuf_INCLUDE_D
if(CMAKE_COMPILER_IS_GNUCXX OR OV_COMPILER_IS_CLANG OR
CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
if(protobuf_BUILD_PROTOC_BINARIES)
set_target_properties(protoc libprotoc PROPERTIES
list(APPEND _protoc_libs protoc libprotoc libprotobuf)
set_target_properties(${_protoc_libs} PROPERTIES
CXX_VISIBILITY_PRESET default
C_VISIBILITY_PRESET default
VISIBILITY_INLINES_HIDDEN OFF)
list(APPEND _protobuf_libs protoc libprotoc)
VISIBILITY_INLINES_HIDDEN OFF
INTERPROCEDURAL_OPTIMIZATION_RELEASE OFF)
endif()
ov_disable_all_warnings(${_protobuf_libs} libprotobuf libprotobuf-lite)
endif()

if(NGRAPH_USE_PROTOBUF_LITE)
# if only libprotobuf-lite is used, both libprotobuf and libprotobuf-lite are built
# libprotoc target needs symbols from libprotobuf, even in libprotobuf-lite configuration
set_target_properties(libprotobuf PROPERTIES
CXX_VISIBILITY_PRESET default
C_VISIBILITY_PRESET default
VISIBILITY_INLINES_HIDDEN OFF)
ov_disable_all_warnings(${_protoc_libs} libprotobuf-lite)
set_target_properties(libprotobuf-lite PROPERTIES
INTERPROCEDURAL_OPTIMIZATION_RELEASE ${ENABLE_LTO})
endif()

if(protobuf_VERSION VERSION_LESS "3.9" AND NGRAPH_USE_PROTOBUF_LITE)
message(FATAL_ERROR "Minimum supported version of protobuf-lite library is 3.9.0 (provided ${protobuf_VERSION})")
endif()

if(ENABLE_LTO AND protobuf_VERSION VERSION_GREATER_EQUAL "3.8")
message(WARNING "Protobuf in version 3.8.0+ can throw runtime exceptions if LTO is enabled.")
endif()

if(CMAKE_CROSSCOMPILING AND NOT PROTOC_VERSION VERSION_EQUAL protobuf_VERSION)
message(WARNING "system protobuf version does not match with the compiled one, please update system protobuf or submodule")
endif()
Expand All @@ -98,5 +87,4 @@ endif()

set(protobuf_VERSION ${protobuf_VERSION} PARENT_SCOPE)
set(Protobuf_LITE_LIBRARIES libprotobuf-lite PARENT_SCOPE)
set(Protobuf_LIBRARIES libprotobuf-lite PARENT_SCOPE)
set(Protobuf_INCLUDE_DIRS ${Protobuf_INCLUDE_DIRS} PARENT_SCOPE)

0 comments on commit eabec38

Please sign in to comment.