From 4354023913a9f84a04a5dec25ce80a5fd92e1e78 Mon Sep 17 00:00:00 2001 From: Changming Sun Date: Mon, 2 Dec 2019 22:25:41 -0800 Subject: [PATCH] Make link time optimization work on Linux (#2477) --- cmake/CMakeLists.txt | 14 ++++++++------ cmake/onnxruntime_common.cmake | 2 +- cmake/onnxruntime_unittests.cmake | 9 ++++++--- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index eba8c0a0bd..5c8a6c4ec7 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -73,7 +73,7 @@ option(onnxruntime_ENABLE_MICROSOFT_INTERNAL "Use this option to enable/disable option(onnxruntime_USE_NUPHAR "Build with Nuphar" OFF) option(onnxruntime_USE_BRAINSLICE "Build with BrainSlice" OFF) option(onnxruntime_USE_TENSORRT "Build with TensorRT support" OFF) -option(onnxruntime_ENABLE_LTO "Enable link time optimization" ON) +option(onnxruntime_ENABLE_LTO "Enable link time optimization" OFF) option(onnxruntime_CROSS_COMPILING "Cross compiling onnx runtime" OFF) option(onnxruntime_BUILD_SERVER "Build ONNX Runtime Server" OFF) option(onnxruntime_USE_FULL_PROTOBUF "Use full protobuf" OFF) @@ -121,17 +121,19 @@ if(onnxruntime_USE_OPENMP) endif() if(onnxruntime_ENABLE_LTO) #TODO: figure out why nsync doesn't work - if(onnxruntime_USE_NSYNC) - message(WARNING "IPO is not supported when nsync is in use") - set(onnxruntime_ENABLE_LTO OFF) - else() + include(CheckIPOSupported) check_ipo_supported(RESULT ipo_enabled OUTPUT ipo_output) if(NOT ipo_enabled) message(WARNING "IPO is not supported by this compiler") set(onnxruntime_ENABLE_LTO OFF) endif() - endif() + if(UNIX) + set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -flto") + set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -flto") + set (CMAKE_LDFLAGS "${CMAKE_CXX_FLAGS} -flto") + set (CMAKE_INTERPROCEDURAL_OPTIMIZATION ON) + endif() endif() diff --git a/cmake/onnxruntime_common.cmake b/cmake/onnxruntime_common.cmake index 12180fd25a..1cbced43f7 100644 --- a/cmake/onnxruntime_common.cmake +++ b/cmake/onnxruntime_common.cmake @@ -70,7 +70,7 @@ onnxruntime_add_include_to_target(onnxruntime_common date_interface) target_include_directories(onnxruntime_common PRIVATE ${CMAKE_CURRENT_BINARY_DIR} ${ONNXRUNTIME_ROOT} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/external/nsync/public") if(onnxruntime_USE_NSYNC) - target_compile_definitions(onnxruntime_common PUBLIC USE_NSYNC) + target_compile_definitions(onnxruntime_common PUBLIC USE_NSYNC NSYNC_ATOMIC_CPP11) endif() target_include_directories(onnxruntime_common PUBLIC ${eigen_INCLUDE_DIRS}) diff --git a/cmake/onnxruntime_unittests.cmake b/cmake/onnxruntime_unittests.cmake index 0d9b7bbf1d..4b87bc2374 100644 --- a/cmake/onnxruntime_unittests.cmake +++ b/cmake/onnxruntime_unittests.cmake @@ -251,8 +251,13 @@ if (onnxruntime_ENABLE_MICROSOFT_INTERNAL) include(onnxruntime_unittests_internal.cmake) endif() +if (onnxruntime_ENABLE_LANGUAGE_INTEROP_OPS) + set(ONNXRUNTIME_INTEROP_TEST_LIBS PRIVATE onnxruntime_language_interop onnxruntime_pyop) +endif() + set(ONNXRUNTIME_TEST_LIBS onnxruntime_session + ${ONNXRUNTIME_INTEROP_TEST_LIBS} ${onnxruntime_libs} ${PROVIDERS_CUDA} ${PROVIDERS_MKLDNN} @@ -414,15 +419,13 @@ endif() # SingleUnitTestProject # standalone test for inference session without environment # the normal test executables set up a default runtime environment, which we don't want here -if(NOT ipo_enabled) - #TODO: figure out why this test doesn't work with gcc LTO AddTest( TARGET onnxruntime_test_framework_session_without_environment_standalone SOURCES "${TEST_SRC_DIR}/framework/inference_session_without_environment/inference_session_without_environment_standalone_test.cc" "${TEST_SRC_DIR}/framework/test_main.cc" LIBS onnxruntime_test_utils ${ONNXRUNTIME_TEST_LIBS} DEPENDS ${onnxruntime_EXTERNAL_DEPENDENCIES} ) -endif() + # # onnxruntime_ir_graph test data