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

Open
wants to merge 9 commits into
base: gh/swolchok/524/head
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
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
17 changes: 13 additions & 4 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
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