From 26e473e769b5aa3c32ca866ef14eaced224bcd50 Mon Sep 17 00:00:00 2001 From: Megvii Engine Team Date: Fri, 18 Sep 2020 08:17:06 +0800 Subject: [PATCH] fix(whl/linux): reduce external megengine whl package size GitOrigin-RevId: 3528af8baeab4ed47eee04107665610e9ababdc9 --- CMakeLists.txt | 2 ++ imperative/CMakeLists.txt | 13 ++++++++++++- src/CMakeLists.txt | 2 +- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0179b0b43..83a48da4d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -53,9 +53,11 @@ option(MGE_WITH_DISTRIBUTED "Build with distributed support" ON) option(MGE_BUILD_IMPERATIVE_RT "Build _imperative_rt Python Module " ON) option(MGE_BUILD_SDK "Build load_and_run" ON) option(MGE_INFERENCE_ONLY "Build inference only library." OFF) +option(MGE_WITH_PYTHON_MODULE "Build MegEngine legacy Python Module." OFF) option(MGE_WITH_MKLDNN "Enable Intel MKL_DNN support," ON) option(MGE_WITH_ROCM "Enable ROCM support" OFF) + if(NOT ${MGE_BIN_REDUCE} STREQUAL "") message("build with BIN REDUCE") if(MGE_WITH_MINIMUM_SIZE) diff --git a/imperative/CMakeLists.txt b/imperative/CMakeLists.txt index a594206f2..910f5bb42 100644 --- a/imperative/CMakeLists.txt +++ b/imperative/CMakeLists.txt @@ -60,7 +60,18 @@ elseif (MSVC OR WIN32) message("-- CMAKE_MSVC_RUNTIME_LIBRARY: ${CMAKE_MSVC_RUNTIME_LIBRARY}") set_target_properties(${MODULE_NAME} PROPERTIES MSVC_RUNTIME_LIBRARY "${CMAKE_MSVC_RUNTIME_LIBRARY}") else() - target_link_libraries(${MODULE_NAME} PRIVATE megengine_export -Wl,--version-script=${VERSION_SCRIPT}) + if (MGE_WITH_PYTHON_MODULE) + # use to fix runtime crash when build both mgb(MGE_WITH_PYTHON_MODULE) and imperative(MGE_BUILD_IMPERATIVE_RT) + target_link_libraries(${MODULE_NAME} PRIVATE megengine_export -Wl,--version-script=${VERSION_SCRIPT}) + else() + # use to reduce whl size by depend on megbrain/dnn directly, caused by cmake create two cuda fatbin + # elf section on both megengine_export and target which depend on megengine_export + target_link_libraries(${MODULE_NAME} PRIVATE megbrain megdnn -Wl,--version-script=${VERSION_SCRIPT}) + if (MGE_WITH_DISTRIBUTED) + message("-- Imperative configured to link megray") + target_link_libraries(${MODULE_NAME} PRIVATE megray) + endif() + endif() endif() target_include_directories(${MODULE_NAME} PUBLIC src/include PRIVATE ${PYTHON_INCLUDE_DIRS} ${NUMPY_INCLUDE_DIR}) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d380d389e..ef96423eb 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -189,7 +189,7 @@ if(MGE_BUILD_IMPERATIVE_RT add_library(megengine_export SHARED) target_link_libraries(megengine_export PUBLIC megbrain megdnn) if (MGE_WITH_DISTRIBUTED) - message("megengine_export configured to link megray") + message("-- megengine_export configured to link megray") target_link_libraries(megengine_export PUBLIC megray) endif() endif() -- GitLab