Enabled LTO for ONNX FE (#6878)

* Fixed Windows public precommit

* ONNX LTO
This commit is contained in:
Ilya Lavrenov 2021-08-02 13:48:33 +03:00 committed by GitHub
parent 0af234b799
commit eabec388e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 15 additions and 29 deletions

View File

@ -331,7 +331,6 @@ else()
if(APPLE) if(APPLE)
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-dead_strip") 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_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,-dead_strip")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-dead_strip")
elseif(LINUX) elseif(LINUX)
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--gc-sections -Wl,--exclude-libs,ALL") 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") set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,--gc-sections -Wl,--exclude-libs,ALL")

View File

@ -2,8 +2,6 @@
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
# #
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE OFF)
set(TARGET_NAME "onnx_common") set(TARGET_NAME "onnx_common")
file(GLOB_RECURSE LIBRARY_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp) file(GLOB_RECURSE LIBRARY_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp)

View File

@ -2,7 +2,6 @@
# SPDX-License-Identifier: Apache-2.0 # 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") set(ONNX_OPSET_VERSION 13 CACHE INTERNAL "Supported version of ONNX operator set")
file(GLOB_RECURSE LIBRARY_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp) file(GLOB_RECURSE LIBRARY_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp)

View File

@ -642,6 +642,11 @@ if (NGRAPH_ONNX_IMPORT_ENABLE)
target_include_directories(unit-test PRIVATE ${ONNX_IMPORTER_SRC_DIR}/src) target_include_directories(unit-test PRIVATE ${ONNX_IMPORTER_SRC_DIR}/src)
target_link_libraries(unit-test PRIVATE onnx_importer) 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() endif()
install(TARGETS unit-test install(TARGETS unit-test

View File

@ -134,11 +134,10 @@ if(NGRAPH_PDPD_FRONTEND_ENABLE OR NGRAPH_ONNX_IMPORT_ENABLE)
endif() endif()
find_package(Protobuf 3.9.0 REQUIRED) find_package(Protobuf 3.9.0 REQUIRED)
set(Protobuf_LITE_LIBRARIES protobuf::libprotobuf-lite) set(Protobuf_LITE_LIBRARIES protobuf::libprotobuf-lite)
set(Protobuf_LIBRARIES protobuf::libprotobuf)
set(SYSTEM_PROTOC protobuf::protoc) set(SYSTEM_PROTOC protobuf::protoc)
set(PROTOC_EXECUTABLE ${SYSTEM_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) set_property(TARGET ${target} PROPERTY IMPORTED_GLOBAL TRUE)
endforeach() endforeach()
else() else()
@ -148,12 +147,11 @@ if(NGRAPH_PDPD_FRONTEND_ENABLE OR NGRAPH_ONNX_IMPORT_ENABLE)
# forward variables used in the other places # forward variables used in the other places
set(SYSTEM_PROTOC ${SYSTEM_PROTOC} PARENT_SCOPE) set(SYSTEM_PROTOC ${SYSTEM_PROTOC} PARENT_SCOPE)
set(PROTOC_EXECUTABLE ${PROTOC_EXECUTABLE} 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_LITE_LIBRARIES ${Protobuf_LITE_LIBRARIES} PARENT_SCOPE)
set(Protobuf_INCLUDE_DIRS ${Protobuf_INCLUDE_DIRS} PARENT_SCOPE) set(Protobuf_INCLUDE_DIRS ${Protobuf_INCLUDE_DIRS} PARENT_SCOPE)
# set public / interface compile options # 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) set(link_type PUBLIC)
if(NGRAPH_USE_SYSTEM_PROTOBUF) if(NGRAPH_USE_SYSTEM_PROTOBUF)
set(link_type INTERFACE) set(link_type INTERFACE)

View File

@ -2,12 +2,11 @@
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
# #
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE OFF)
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
# Configure and install libonnx ... # Configure and install libonnx ...
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE OFF)
set(NGRAPH_ONNX_NAMESPACE ngraph_onnx) set(NGRAPH_ONNX_NAMESPACE ngraph_onnx)
set(BUILD_SHARED_LIBS OFF) set(BUILD_SHARED_LIBS OFF)

View File

@ -6,7 +6,6 @@
# Configure Google Protobuf ... # Configure Google Protobuf ...
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE OFF)
set(BUILD_SHARED_LIBS OFF) set(BUILD_SHARED_LIBS OFF)
if(SUGGEST_OVERRIDE_SUPPORTED) if(SUGGEST_OVERRIDE_SUPPORTED)
@ -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 if(CMAKE_COMPILER_IS_GNUCXX OR OV_COMPILER_IS_CLANG OR
CMAKE_CXX_COMPILER_ID STREQUAL "Intel") CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
if(protobuf_BUILD_PROTOC_BINARIES) 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 CXX_VISIBILITY_PRESET default
C_VISIBILITY_PRESET default C_VISIBILITY_PRESET default
VISIBILITY_INLINES_HIDDEN OFF) VISIBILITY_INLINES_HIDDEN OFF
list(APPEND _protobuf_libs protoc libprotoc) INTERPROCEDURAL_OPTIMIZATION_RELEASE OFF)
endif() endif()
ov_disable_all_warnings(${_protobuf_libs} libprotobuf libprotobuf-lite) ov_disable_all_warnings(${_protoc_libs} libprotobuf-lite)
endif() set_target_properties(libprotobuf-lite PROPERTIES
INTERPROCEDURAL_OPTIMIZATION_RELEASE ${ENABLE_LTO})
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)
endif() endif()
if(protobuf_VERSION VERSION_LESS "3.9" AND NGRAPH_USE_PROTOBUF_LITE) 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})") message(FATAL_ERROR "Minimum supported version of protobuf-lite library is 3.9.0 (provided ${protobuf_VERSION})")
endif() 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) 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") message(WARNING "system protobuf version does not match with the compiled one, please update system protobuf or submodule")
endif() endif()
@ -98,5 +87,4 @@ endif()
set(protobuf_VERSION ${protobuf_VERSION} PARENT_SCOPE) set(protobuf_VERSION ${protobuf_VERSION} PARENT_SCOPE)
set(Protobuf_LITE_LIBRARIES libprotobuf-lite 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) set(Protobuf_INCLUDE_DIRS ${Protobuf_INCLUDE_DIRS} PARENT_SCOPE)