Skip to content

Set up CMake build for extension/evalue_util #12691

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 74 commits into from
Jul 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
9e3e2e7
Update
swolchok Jul 13, 2025
16f0274
forgot to amend
swolchok Jul 13, 2025
99ec5a7
Update
swolchok Jul 14, 2025
ff3cdb9
Update
swolchok Jul 14, 2025
513de13
Update
swolchok Jul 14, 2025
76db1f1
Update
swolchok Jul 14, 2025
08bffac
Update
swolchok Jul 14, 2025
dff96c8
Update
swolchok Jul 14, 2025
0e2bce6
Update
swolchok Jul 14, 2025
35d8319
Update
swolchok Jul 14, 2025
a31187e
Update
swolchok Jul 15, 2025
dcbce0d
Update
swolchok Jul 15, 2025
bc8f971
Update
swolchok Jul 15, 2025
29d3999
Update
swolchok Jul 15, 2025
7e4040a
Update
swolchok Jul 15, 2025
2dacf6f
Update
swolchok Jul 15, 2025
fb2b775
Update
swolchok Jul 15, 2025
02f19a6
Update
swolchok Jul 15, 2025
225d5a6
Update
swolchok Jul 15, 2025
41bf264
Update
swolchok Jul 16, 2025
f54a8ce
Update
swolchok Jul 16, 2025
e48e6cc
Update
swolchok Jul 16, 2025
a2f14ac
Update
swolchok Jul 16, 2025
c31a4b9
Update
swolchok Jul 17, 2025
4fd7372
Update
swolchok Jul 17, 2025
d650396
Update
swolchok Jul 17, 2025
3bfdade
Update
swolchok Jul 17, 2025
00acd77
Update
swolchok Jul 17, 2025
6946143
Update
swolchok Jul 17, 2025
431ddd8
Update
swolchok Jul 17, 2025
60456ca
Update
swolchok Jul 17, 2025
dcb3ca0
Update
swolchok Jul 18, 2025
3c30b31
Update
swolchok Jul 18, 2025
e9928a7
Update
swolchok Jul 18, 2025
b57678b
Update
swolchok Jul 18, 2025
05effc4
Update
swolchok Jul 18, 2025
f5bcdcc
Update
swolchok Jul 18, 2025
2e21d9a
Update
swolchok Jul 19, 2025
63e4a27
Update
swolchok Jul 19, 2025
4c2e046
rebase
swolchok Jul 19, 2025
0eb3d8d
rebase
swolchok Jul 19, 2025
a451cc3
rebase
swolchok Jul 19, 2025
0d164ce
Update
swolchok Jul 21, 2025
ccd0e2d
Update
swolchok Jul 21, 2025
f9b96eb
Update
swolchok Jul 21, 2025
02d6d67
Update
swolchok Jul 21, 2025
dd18bfe
Update
swolchok Jul 21, 2025
5be4b7b
Update
swolchok Jul 21, 2025
719bb4f
Update
swolchok Jul 21, 2025
a342614
Update
swolchok Jul 21, 2025
d451e7c
Update
swolchok Jul 21, 2025
91fe6ad
Update
swolchok Jul 21, 2025
9e9373a
Update
swolchok Jul 21, 2025
8627bbb
Update
swolchok Jul 22, 2025
995f6fa
Update
swolchok Jul 22, 2025
d2ee588
Update
swolchok Jul 22, 2025
853a128
Update
swolchok Jul 22, 2025
0ffc394
Update
swolchok Jul 22, 2025
a06c916
Merge branch 'main' into gh/swolchok/517/head
swolchok Jul 22, 2025
3d760e0
Update
swolchok Jul 22, 2025
ae4ac22
Update
swolchok Jul 22, 2025
9e04e6a
Update
swolchok Jul 22, 2025
fa557ca
Update
swolchok Jul 22, 2025
5173bf2
Update
swolchok Jul 23, 2025
e6c83db
Update
swolchok Jul 23, 2025
8978c19
Update
swolchok Jul 23, 2025
1cf3567
Update
swolchok Jul 23, 2025
b0d965c
Update
swolchok Jul 23, 2025
d9bf112
Update
swolchok Jul 23, 2025
7852f9a
Update
swolchok Jul 23, 2025
5f9f7c5
Update
swolchok Jul 23, 2025
bdabc9c
Update
swolchok Jul 23, 2025
a9dadf4
Update
swolchok Jul 23, 2025
707e40f
Update
swolchok Jul 23, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .ci/scripts/unittest-linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .ci/scripts/unittest-macos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 "$@"

Expand Down
23 changes: 20 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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}
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions examples/apple/mps/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions examples/apple/mps/test_mps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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" \
Expand Down
3 changes: 2 additions & 1 deletion examples/portable/custom_ops/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
10 changes: 8 additions & 2 deletions examples/qualcomm/executor_runner/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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'"
Expand Down
20 changes: 13 additions & 7 deletions examples/selective_build/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 <executorch/path/to/header.h>".
set(_common_include_directories ${EXECUTORCH_ROOT}/..)
Expand All @@ -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 -------------------------------

Expand All @@ -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 --------------------------------

#
Expand Down Expand Up @@ -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})
29 changes: 29 additions & 0 deletions extension/evalue_util/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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}
)
15 changes: 7 additions & 8 deletions extension/evalue_util/print_evalue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -78,21 +78,20 @@ void print_scalar_list(
executorch::aten::ArrayRef<T> list,
bool print_length = true,
bool elide_inner_items = true) {
long edge_items = elide_inner_items ? get_stream_edge_items(os)
: std::numeric_limits<long>::max();
size_t edge_items = elide_inner_items ? get_stream_edge_items(os)
: std::numeric_limits<long>::max();
if (print_length) {
os << "(len=" << list.size() << ")";
}

// 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<long>(list.size()), edge_items * 2);
num_printed_items = std::min(list.size(), edge_items * 2);
} else {
num_printed_items = static_cast<long>(list.size());
num_printed_items = list.size();
}
wrapping = num_printed_items > kItemsPerLine;
}
Expand Down
8 changes: 7 additions & 1 deletion test/build_size_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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} \
Expand Down
17 changes: 17 additions & 0 deletions tools/cmake/cmake_deps.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -340,6 +351,8 @@ excludes = [
deps = [
"executorch",
"executorch_core",
"extension_evalue_util",
"extension_runner_util",
"extension_threadpool",
"kernels_util_all_deps",
"portable_kernels",
Expand Down Expand Up @@ -376,6 +389,8 @@ excludes = [
deps = [
"executorch",
"executorch_core",
"extension_evalue_util",
"extension_runner_util",
"extension_threadpool",
"kernels_util_all_deps",
"portable_kernels",
Expand Down Expand Up @@ -417,6 +432,8 @@ excludes = [
deps = [
"executorch",
"executorch_core",
"extension_evalue_util",
"extension_runner_util",
"extension_threadpool",
"kernels_util_all_deps",
"xnnpack_backend",
Expand Down
1 change: 1 addition & 0 deletions tools/cmake/executorch-config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 14 additions & 5 deletions tools/cmake/preset/default.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
)

Expand Down
1 change: 1 addition & 0 deletions tools/cmake/preset/linux.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 2 additions & 0 deletions tools/cmake/preset/macos.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Loading