diff --git a/.ci/scripts/unittest-linux.sh b/.ci/scripts/unittest-linux.sh index d0f107ed338..c6d596eb08a 100755 --- a/.ci/scripts/unittest-linux.sh +++ b/.ci/scripts/unittest-linux.sh @@ -22,7 +22,7 @@ if [[ "$BUILD_TOOL" == "cmake" ]]; then # We need the runner to test the built library. PYTHON_EXECUTABLE=python \ - CMAKE_ARGS="-DEXECUTORCH_BUILD_EXECUTOR_RUNNER=ON -DEXECUTORCH_BUILD_TESTS=ON" \ + CMAKE_ARGS="-DEXECUTORCH_BUILD_EXTENSION_EVALUE_UTIL=ON -DEXECUTORCH_BUILD_EXTENSION_RUNNER_UTIL=ON -DEXECUTORCH_BUILD_EXECUTOR_RUNNER=ON -DEXECUTORCH_BUILD_TESTS=ON" \ .ci/scripts/setup-linux.sh "$@" .ci/scripts/unittest-linux-cmake.sh diff --git a/.ci/scripts/unittest-macos.sh b/.ci/scripts/unittest-macos.sh index 602685117d5..74d1f594207 100755 --- a/.ci/scripts/unittest-macos.sh +++ b/.ci/scripts/unittest-macos.sh @@ -22,7 +22,7 @@ trap 'rm -rfv ${TMP_DIR}' EXIT # Setup MacOS dependencies as there is no Docker support on MacOS atm # We need the runner to test the built library. PYTHON_EXECUTABLE=python \ -CMAKE_ARGS="-DEXECUTORCH_BUILD_EXECUTOR_RUNNER=ON -DEXECUTORCH_BUILD_TESTS=ON" \ +CMAKE_ARGS="-DEXECUTORCH_BUILD_EXTENSION_EVALUE_UTIL=ON -DEXECUTORCH_BUILD_EXTENSION_RUNNER_UTIL=ON -DEXECUTORCH_BUILD_EXECUTOR_RUNNER=ON -DEXECUTORCH_BUILD_TESTS=ON" \ ${CONDA_RUN} --no-capture-output \ .ci/scripts/setup-macos.sh "$@" diff --git a/CMakeLists.txt b/CMakeLists.txt index 8c7d255a5f7..9e6e3f1b727 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -548,6 +548,16 @@ if(EXECUTORCH_BUILD_EXTENSION_DATA_LOADER) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/extension/data_loader) endif() +if(EXECUTORCH_BUILD_EXTENSION_EVALUE_UTIL) + add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/extension/evalue_util) + install( + DIRECTORY extension/evalue_util/ + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/executorch/extension/evalue_util + FILES_MATCHING + PATTERN "*.h" + ) +endif() + if(EXECUTORCH_BUILD_EXTENSION_FLAT_TENSOR) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/extension/flat_tensor) endif() @@ -576,6 +586,12 @@ endif() if(EXECUTORCH_BUILD_EXTENSION_RUNNER_UTIL) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/extension/runner_util) + install( + DIRECTORY extension/runner_util/ + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/executorch/extension/runner_util + FILES_MATCHING + PATTERN "*.h" + ) endif() if(EXECUTORCH_BUILD_EXTENSION_TENSOR) @@ -651,8 +667,7 @@ if(EXECUTORCH_BUILD_PYBIND) # util lib add_library( - util ${CMAKE_CURRENT_SOURCE_DIR}/extension/evalue_util/print_evalue.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/extension/aten_util/aten_bridge.cpp + util ${CMAKE_CURRENT_SOURCE_DIR}/extension/aten_util/aten_bridge.cpp ) target_include_directories( util PUBLIC ${_common_include_directories} ${TORCH_INCLUDE_DIRS} @@ -695,7 +710,9 @@ endif() if(EXECUTORCH_BUILD_EXECUTOR_RUNNER) # Baseline libraries that executor_runner will link against. - set(_executor_runner_libs executorch gflags) + set(_executor_runner_libs executorch extension_evalue_util + extension_runner_util gflags + ) if(EXECUTORCH_BUILD_KERNELS_OPTIMIZED) list(APPEND _executor_runner_libs optimized_native_cpu_ops_lib) diff --git a/examples/apple/mps/CMakeLists.txt b/examples/apple/mps/CMakeLists.txt index 9bad0b4b206..3f61cedec8e 100644 --- a/examples/apple/mps/CMakeLists.txt +++ b/examples/apple/mps/CMakeLists.txt @@ -105,6 +105,8 @@ if(NOT CMAKE_TOOLCHAIN_FILE MATCHES ".*(iOS|ios\.toolchain)\.cmake$") mps_executor_runner bundled_program executorch + extension_evalue_util + extension_runner_util gflags etdump flatccrt diff --git a/examples/apple/mps/test_mps.sh b/examples/apple/mps/test_mps.sh index 555161dd3f7..bca28628473 100755 --- a/examples/apple/mps/test_mps.sh +++ b/examples/apple/mps/test_mps.sh @@ -19,6 +19,8 @@ cmake_install_executorch_devtools_lib() { -DCMAKE_INSTALL_PREFIX=cmake-out \ -DCMAKE_BUILD_TYPE=Release \ -DEXECUTORCH_BUILD_DEVTOOLS=ON \ + -DEXECUTORCH_BUILD_EXTENSION_EVALUE_UTIL=ON \ + -DEXECUTORCH_BUILD_EXTENSION_RUNNER_UTIL=ON \ -DEXECUTORCH_BUILD_MPS=ON \ -DEXECUTORCH_ENABLE_EVENT_TRACER=ON \ -DPYTHON_EXECUTABLE="$PYTHON_EXECUTABLE" \ diff --git a/examples/portable/custom_ops/CMakeLists.txt b/examples/portable/custom_ops/CMakeLists.txt index 5a9a9a11fe6..c4a00e47991 100644 --- a/examples/portable/custom_ops/CMakeLists.txt +++ b/examples/portable/custom_ops/CMakeLists.txt @@ -123,7 +123,8 @@ list(TRANSFORM _executor_runner__srcs PREPEND "${EXECUTORCH_ROOT}/") add_executable(custom_ops_executor_runner ${_executor_runner__srcs}) target_link_libraries( - custom_ops_executor_runner custom_ops_lib executorch gflags + custom_ops_executor_runner custom_ops_lib executorch extension_evalue_util + extension_runner_util gflags ) target_compile_options( custom_ops_executor_runner PUBLIC ${_common_compile_options} diff --git a/examples/qualcomm/executor_runner/CMakeLists.txt b/examples/qualcomm/executor_runner/CMakeLists.txt index 479d0a248be..1d7f6b718f2 100644 --- a/examples/qualcomm/executor_runner/CMakeLists.txt +++ b/examples/qualcomm/executor_runner/CMakeLists.txt @@ -19,8 +19,14 @@ target_include_directories( qnn_executor_runner PUBLIC ${_common_include_directories} ) target_link_libraries( - qnn_executor_runner qnn_executorch_backend full_portable_ops_lib etdump - flatccrt gflags + qnn_executor_runner + qnn_executorch_backend + extension_evalue_util + extension_runner_util + full_portable_ops_lib + etdump + flatccrt + gflags ) set_target_properties( qnn_executor_runner PROPERTIES LINK_FLAGS "-Wl,-rpath='$ORIGIN'" diff --git a/examples/selective_build/CMakeLists.txt b/examples/selective_build/CMakeLists.txt index d52ba00f3a4..3cc5e759ac4 100644 --- a/examples/selective_build/CMakeLists.txt +++ b/examples/selective_build/CMakeLists.txt @@ -33,7 +33,9 @@ if(NOT CMAKE_CXX_STANDARD) # Can't set to 11 due to executor_runner.cpp make_unique endif() -set(_common_compile_options -Wno-deprecated-declarations -fPIC -ffunction-sections -fdata-sections) +set(_common_compile_options -Wno-deprecated-declarations -fPIC + -ffunction-sections -fdata-sections +) # Let files say "include ". set(_common_include_directories ${EXECUTORCH_ROOT}/..) @@ -43,7 +45,9 @@ find_package( gflags REQUIRED PATHS ${CMAKE_CURRENT_BINARY_DIR}/../../third-party ) -target_include_directories(executorch_core INTERFACE ${_common_include_directories}) +target_include_directories( + executorch_core INTERFACE ${_common_include_directories} +) # ------------------------------ OPTIONS BEGIN ------------------------------- @@ -63,12 +67,13 @@ option(EXECUTORCH_SELECT_ALL_OPS ) # Option to enable parsing ops and dtypes directly from model pte file -option(EXECUTORCH_SELECT_OPS_FROM_MODEL "Enable op selection from pte during build." OFF +option(EXECUTORCH_SELECT_OPS_FROM_MODEL + "Enable op selection from pte during build." OFF ) -# Option to enable dtype selective build. Note: must be using selective build model API. -option(EXECUTORCH_DTYPE_SELECTIVE_BUILD "Enable dtype selective build." OFF -) +# Option to enable dtype selective build. Note: must be using selective build +# model API. +option(EXECUTORCH_DTYPE_SELECTIVE_BUILD "Enable dtype selective build." OFF) # ------------------------------- OPTIONS END -------------------------------- # @@ -155,7 +160,8 @@ if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug") target_link_options_gc_sections(selective_build_test) endif() target_link_libraries( - selective_build_test PRIVATE executorch_core gflags select_build_lib + selective_build_test PRIVATE executorch_core extension_evalue_util + extension_runner_util gflags select_build_lib ) executorch_target_link_options_shared_lib(select_build_lib) target_compile_options(selective_build_test PUBLIC ${_common_compile_options}) diff --git a/extension/evalue_util/CMakeLists.txt b/extension/evalue_util/CMakeLists.txt new file mode 100644 index 00000000000..21b89bb2b7b --- /dev/null +++ b/extension/evalue_util/CMakeLists.txt @@ -0,0 +1,29 @@ +# Copyright (c) Meta Platforms, Inc. and affiliates. +# All rights reserved. +# +# This source code is licensed under the BSD-style license found in the +# LICENSE file in the root directory of this source tree. + +# Please this file formatted by running: +# ~~~ +# cmake-format -i CMakeLists.txt +# ~~~ +# Source root directory for executorch. +if(NOT EXECUTORCH_ROOT) + set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../..) +endif() +list(TRANSFORM _extension_evalue_util__srcs PREPEND "${EXECUTORCH_ROOT}/") +add_library(extension_evalue_util ${_extension_evalue_util__srcs}) +target_link_libraries(extension_evalue_util executorch_core) +target_include_directories( + extension_evalue_util PUBLIC ${_common_include_directories} +) +target_compile_options(extension_evalue_util PUBLIC ${_common_compile_options}) + +# Install libraries +install( + TARGETS extension_evalue_util + DESTINATION ${CMAKE_BINARY_DIR}/lib + INCLUDES + DESTINATION ${_common_include_directories} +) diff --git a/extension/evalue_util/print_evalue.cpp b/extension/evalue_util/print_evalue.cpp index 192b51fee5a..32009011012 100644 --- a/extension/evalue_util/print_evalue.cpp +++ b/extension/evalue_util/print_evalue.cpp @@ -39,8 +39,8 @@ int get_edge_items_xalloc() { /// Returns the number of "edge items" to print at the beginning and end of /// lists when using the provided stream. -long get_stream_edge_items(std::ostream& os) { - long edge_items = os.iword(get_edge_items_xalloc()); +size_t get_stream_edge_items(std::ostream& os) { + size_t edge_items = os.iword(get_edge_items_xalloc()); return edge_items <= 0 ? kDefaultEdgeItems : edge_items; } @@ -78,8 +78,8 @@ void print_scalar_list( executorch::aten::ArrayRef list, bool print_length = true, bool elide_inner_items = true) { - long edge_items = elide_inner_items ? get_stream_edge_items(os) - : std::numeric_limits::max(); + size_t edge_items = elide_inner_items ? get_stream_edge_items(os) + : std::numeric_limits::max(); if (print_length) { os << "(len=" << list.size() << ")"; } @@ -87,12 +87,11 @@ void print_scalar_list( // See if we'll be printing enough elements to cause us to wrap. bool wrapping = false; { - long num_printed_items; + size_t num_printed_items; if (elide_inner_items) { - num_printed_items = - std::min(static_cast(list.size()), edge_items * 2); + num_printed_items = std::min(list.size(), edge_items * 2); } else { - num_printed_items = static_cast(list.size()); + num_printed_items = list.size(); } wrapping = num_printed_items > kItemsPerLine; } diff --git a/test/build_size_test.sh b/test/build_size_test.sh index baeef5a849e..9ef615a2bb0 100644 --- a/test/build_size_test.sh +++ b/test/build_size_test.sh @@ -6,7 +6,7 @@ # LICENSE file in the root directory of this source tree. # Build size_test and show the size of it -set -e +set -ex # shellcheck source=/dev/null source "$(dirname "${BASH_SOURCE[0]}")/../.ci/scripts/utils.sh" @@ -23,11 +23,17 @@ cmake_install_executorch_lib() { update_tokenizers_git_submodule local EXTRA_BUILD_ARGS="${@}" + if [[ "$EXTRA_BUILD_ARGS" == *"-DEXECUTORCH_BUILD_ARM_BAREMETAL=ON"* ]]; then + local BUILD_DATA_LOADER="OFF" + else + local BUILD_DATA_LOADER=ON + fi CXXFLAGS="$COMMON_CXXFLAGS" retry cmake -DBUCK2="$BUCK2" \ -DCMAKE_CXX_STANDARD_REQUIRED=ON \ -DCMAKE_INSTALL_PREFIX=cmake-out \ -DCMAKE_BUILD_TYPE=Release \ -DEXECUTORCH_BUILD_EXECUTOR_RUNNER=OFF \ + -DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=${BUILD_DATA_LOADER} \ -DEXECUTORCH_OPTIMIZE_SIZE=ON \ -DPYTHON_EXECUTABLE="$PYTHON_EXECUTABLE" \ ${EXTRA_BUILD_ARGS} \ diff --git a/tools/cmake/cmake_deps.toml b/tools/cmake/cmake_deps.toml index f29d9257d18..50c37ec431c 100644 --- a/tools/cmake/cmake_deps.toml +++ b/tools/cmake/cmake_deps.toml @@ -198,6 +198,17 @@ deps = [ "executorch_core", ] +[targets.extension_evalue_util] +buck_targets = [ + "//extension/evalue_util:print_evalue", +] +filters = [ + ".cpp$", +] +deps = [ + "executorch_core", +] + [targets.extension_flat_tensor_schema] buck_targets = [ "//extension/flat_tensor/serialize:generated_headers", @@ -340,6 +351,8 @@ excludes = [ deps = [ "executorch", "executorch_core", + "extension_evalue_util", + "extension_runner_util", "extension_threadpool", "kernels_util_all_deps", "portable_kernels", @@ -376,6 +389,8 @@ excludes = [ deps = [ "executorch", "executorch_core", + "extension_evalue_util", + "extension_runner_util", "extension_threadpool", "kernels_util_all_deps", "portable_kernels", @@ -417,6 +432,8 @@ excludes = [ deps = [ "executorch", "executorch_core", + "extension_evalue_util", + "extension_runner_util", "extension_threadpool", "kernels_util_all_deps", "xnnpack_backend", diff --git a/tools/cmake/executorch-config.cmake b/tools/cmake/executorch-config.cmake index c3a0ca0b48f..5a92dcbf2ec 100644 --- a/tools/cmake/executorch-config.cmake +++ b/tools/cmake/executorch-config.cmake @@ -71,6 +71,7 @@ set(lib_list qnn_executorch_backend portable_ops_lib custom_ops + extension_evalue_util extension_module extension_module_static extension_runner_util diff --git a/tools/cmake/preset/default.cmake b/tools/cmake/preset/default.cmake index 0500e730b1a..b6626f0a513 100644 --- a/tools/cmake/preset/default.cmake +++ b/tools/cmake/preset/default.cmake @@ -82,10 +82,6 @@ define_overridable_option( define_overridable_option( EXECUTORCH_BUILD_EXTENSION_MODULE "Build the Module extension" BOOL OFF ) -define_overridable_option( - EXECUTORCH_BUILD_EXTENSION_RUNNER_UTIL "Build the Runner Util extension" BOOL - OFF -) define_overridable_option( EXECUTORCH_BUILD_EXTENSION_TENSOR "Build the Tensor extension" BOOL OFF ) @@ -177,6 +173,14 @@ define_overridable_option( EXECUTORCH_BUILD_EXECUTOR_RUNNER "Build the executor_runner executable" BOOL ${_default_executorch_build_executor_runner} ) +define_overridable_option( + EXECUTORCH_BUILD_EXTENSION_EVALUE_UTIL "Build the EValue util extension" BOOL + ${_default_executorch_build_executor_runner} +) +define_overridable_option( + EXECUTORCH_BUILD_EXTENSION_RUNNER_UTIL "Build the Runner Util extension" BOOL + ${_default_executorch_build_executor_runner} +) # NB: Enabling this will serialize execution of delegate instances Keeping this # OFF by default to maintain existing behavior, to be revisited. @@ -213,6 +217,11 @@ check_required_options_on( IF_ON EXECUTORCH_ENABLE_EVENT_TRACER REQUIRES EXECUTORCH_BUILD_DEVTOOLS ) +check_required_options_on( + IF_ON EXECUTORCH_BUILD_EXECUTOR_RUNNER REQUIRES + EXECUTORCH_BUILD_EXTENSION_EVALUE_UTIL + EXECUTORCH_BUILD_EXTENSION_RUNNER_UTIL +) check_required_options_on( IF_ON EXECUTORCH_BUILD_EXTENSION_FLAT_TENSOR REQUIRES EXECUTORCH_BUILD_EXTENSION_DATA_LOADER @@ -249,7 +258,7 @@ check_required_options_on( check_conflicting_options_on( IF_ON EXECUTORCH_BUILD_ARM_BAREMETAL CONFLICTS_WITH - EXECUTORCH_BUILD_EXTENSION_DATA_LOADER EXECUTORCH_BUILD_PTHREADPOOL + EXECUTORCH_BUILD_PTHREADPOOL EXECUTORCH_BUILD_CPUINFO ) diff --git a/tools/cmake/preset/linux.cmake b/tools/cmake/preset/linux.cmake index 99c82f1ec45..e73b24cdd61 100644 --- a/tools/cmake/preset/linux.cmake +++ b/tools/cmake/preset/linux.cmake @@ -7,4 +7,5 @@ include(${PROJECT_SOURCE_DIR}/tools/cmake/preset/llm.cmake) set_overridable_option(EXECUTORCH_BUILD_EXECUTOR_RUNNER ON) +set_overridable_option(EXECUTORCH_BUILD_EXTENSION_EVALUE_UTIL ON) set_overridable_option(EXECUTORCH_BUILD_EXTENSION_RUNNER_UTIL ON) diff --git a/tools/cmake/preset/macos.cmake b/tools/cmake/preset/macos.cmake index 0138b7a3b95..30537d5b531 100644 --- a/tools/cmake/preset/macos.cmake +++ b/tools/cmake/preset/macos.cmake @@ -6,5 +6,7 @@ include(${PROJECT_SOURCE_DIR}/tools/cmake/preset/apple_common.cmake) +set_overridable_option(EXECUTORCH_BUILD_EXTENSION_EVALUE_UTIL ON) +set_overridable_option(EXECUTORCH_BUILD_EXTENSION_RUNNER_UTIL ON) set_overridable_option(EXECUTORCH_BUILD_EXECUTOR_RUNNER ON) set_overridable_option(EXECUTORCH_COREML_BUILD_EXECUTOR_RUNNER ON)