From 1cbbafdbe0eddde94e0d77835ee56ff2aadf85f6 Mon Sep 17 00:00:00 2001 From: Changming Sun Date: Fri, 5 Nov 2021 15:27:04 -0700 Subject: [PATCH] Change the default value of onnxruntime_DISABLE_RTTI (#9674) --- cmake/CMakeLists.txt | 11 +++++------ tools/ci_build/build.py | 4 +++- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index f8f4d27849..5ecdcd76c9 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -110,7 +110,7 @@ option(onnxruntime_DISABLE_CONTRIB_OPS "Disable contrib ops" OFF) option(onnxruntime_DISABLE_ML_OPS "Disable traditional ML ops" OFF) option(onnxruntime_DISABLE_SPARSE_TENSORS "Disable sparse tensors data types" OFF) option(onnxruntime_MINIMAL_BUILD "Exclude as much as possible from the build. Support ORT format models. No support for ONNX format models." OFF) -cmake_dependent_option(onnxruntime_DISABLE_RTTI "Disable RTTI" ON "onnxruntime_MINIMAL_BUILD;NOT onnxruntime_ENABLE_PYTHON" OFF) +cmake_dependent_option(onnxruntime_DISABLE_RTTI "Disable RTTI" ON "NOT onnxruntime_ENABLE_PYTHON" OFF) # For now onnxruntime_DISABLE_EXCEPTIONS will only work with onnxruntime_MINIMAL_BUILD, more changes (ONNX, non-CPU EP, ...) are required to run this standalone cmake_dependent_option(onnxruntime_DISABLE_EXCEPTIONS "Disable exception handling. Requires onnxruntime_MINIMAL_BUILD currently." ON "onnxruntime_MINIMAL_BUILD;NOT onnxruntime_ENABLE_PYTHON" OFF) @@ -171,6 +171,10 @@ set(ONNX_CUSTOM_PROTOC_EXECUTABLE "" CACHE STRING "Specify custom protoc executa # pre-build python path option(onnxruntime_PREBUILT_PYTORCH_PATH "Path to pytorch installation dir") +if (onnxruntime_USE_CUDA) + set(onnxruntime_DISABLE_RTTI OFF) +endif() + if (APPLE) if (NOT CMAKE_OSX_ARCHITECTURES) message("Building ONNX Runtime for ${CMAKE_HOST_SYSTEM_PROCESSOR}") @@ -345,11 +349,6 @@ if (onnxruntime_MINIMAL_BUILD) set(onnxruntime_REDUCED_OPS_BUILD ON) - if (NOT onnxruntime_ENABLE_PYTHON) - # Python bindings use typeid so can't automatically disable RTTI in that case - set(onnxruntime_DISABLE_RTTI ON) - endif() - if (MSVC) # turn on LTO (which adds some compiler flags and turns on LTCG) unless it's a Debug build to minimize binary size if (NOT CMAKE_BUILD_TYPE STREQUAL "Debug") diff --git a/tools/ci_build/build.py b/tools/ci_build/build.py index 3dc194c415..8664c99a9c 100644 --- a/tools/ci_build/build.py +++ b/tools/ci_build/build.py @@ -532,6 +532,7 @@ def parse_arguments(): help="Disable contrib ops (reduces binary size)") parser.add_argument("--disable_ml_ops", action='store_true', help="Disable traditional ML ops (reduces binary size)") + # Please note in our CMakeLists.txt this is already default on. But in this file we reverse it to default OFF. parser.add_argument("--disable_rtti", action='store_true', help="Disable RTTI (reduces binary size)") parser.add_argument("--disable_exceptions", action='store_true', help="Disable exceptions to reduce binary size. Requires --minimal_build.") @@ -756,7 +757,8 @@ def generate_build_tree(cmake_path, source_dir, build_dir, cuda_home, cudnn_home "-Donnxruntime_CROSS_COMPILING=" + ("ON" if args.arm64 or args.arm64ec or args.arm else "OFF"), "-Donnxruntime_DISABLE_CONTRIB_OPS=" + ("ON" if args.disable_contrib_ops else "OFF"), "-Donnxruntime_DISABLE_ML_OPS=" + ("ON" if args.disable_ml_ops else "OFF"), - "-Donnxruntime_DISABLE_RTTI=" + ("ON" if args.disable_rtti else "OFF"), + "-Donnxruntime_DISABLE_RTTI=" + ("ON" if args.disable_rtti or (args.minimal_build is not None + and not args.enable_pybind) else "OFF"), "-Donnxruntime_DISABLE_EXCEPTIONS=" + ("ON" if args.disable_exceptions else "OFF"), # Need to use 'is not None' with minimal_build check as it could be an empty list. "-Donnxruntime_MINIMAL_BUILD=" + ("ON" if args.minimal_build is not None else "OFF"),