Skip to content

Commit cfefd2c

Browse files
authored
Set up CMake build for extension/evalue_util (#12691)
It didn't have one. Now it does.
1 parent 1cd4ac0 commit cfefd2c

File tree

15 files changed

+119
-27
lines changed

15 files changed

+119
-27
lines changed

.ci/scripts/unittest-linux.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ if [[ "$BUILD_TOOL" == "cmake" ]]; then
2222

2323
# We need the runner to test the built library.
2424
PYTHON_EXECUTABLE=python \
25-
CMAKE_ARGS="-DEXECUTORCH_BUILD_EXECUTOR_RUNNER=ON -DEXECUTORCH_BUILD_TESTS=ON" \
25+
CMAKE_ARGS="-DEXECUTORCH_BUILD_EXTENSION_EVALUE_UTIL=ON -DEXECUTORCH_BUILD_EXTENSION_RUNNER_UTIL=ON -DEXECUTORCH_BUILD_EXECUTOR_RUNNER=ON -DEXECUTORCH_BUILD_TESTS=ON" \
2626
.ci/scripts/setup-linux.sh "$@"
2727

2828
.ci/scripts/unittest-linux-cmake.sh

.ci/scripts/unittest-macos.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ trap 'rm -rfv ${TMP_DIR}' EXIT
2222
# Setup MacOS dependencies as there is no Docker support on MacOS atm
2323
# We need the runner to test the built library.
2424
PYTHON_EXECUTABLE=python \
25-
CMAKE_ARGS="-DEXECUTORCH_BUILD_EXECUTOR_RUNNER=ON -DEXECUTORCH_BUILD_TESTS=ON" \
25+
CMAKE_ARGS="-DEXECUTORCH_BUILD_EXTENSION_EVALUE_UTIL=ON -DEXECUTORCH_BUILD_EXTENSION_RUNNER_UTIL=ON -DEXECUTORCH_BUILD_EXECUTOR_RUNNER=ON -DEXECUTORCH_BUILD_TESTS=ON" \
2626
${CONDA_RUN} --no-capture-output \
2727
.ci/scripts/setup-macos.sh "$@"
2828

CMakeLists.txt

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,16 @@ if(EXECUTORCH_BUILD_EXTENSION_DATA_LOADER)
548548
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/extension/data_loader)
549549
endif()
550550

551+
if(EXECUTORCH_BUILD_EXTENSION_EVALUE_UTIL)
552+
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/extension/evalue_util)
553+
install(
554+
DIRECTORY extension/evalue_util/
555+
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/executorch/extension/evalue_util
556+
FILES_MATCHING
557+
PATTERN "*.h"
558+
)
559+
endif()
560+
551561
if(EXECUTORCH_BUILD_EXTENSION_FLAT_TENSOR)
552562
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/extension/flat_tensor)
553563
endif()
@@ -576,6 +586,12 @@ endif()
576586

577587
if(EXECUTORCH_BUILD_EXTENSION_RUNNER_UTIL)
578588
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/extension/runner_util)
589+
install(
590+
DIRECTORY extension/runner_util/
591+
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/executorch/extension/runner_util
592+
FILES_MATCHING
593+
PATTERN "*.h"
594+
)
579595
endif()
580596

581597
if(EXECUTORCH_BUILD_EXTENSION_TENSOR)
@@ -651,8 +667,7 @@ if(EXECUTORCH_BUILD_PYBIND)
651667

652668
# util lib
653669
add_library(
654-
util ${CMAKE_CURRENT_SOURCE_DIR}/extension/evalue_util/print_evalue.cpp
655-
${CMAKE_CURRENT_SOURCE_DIR}/extension/aten_util/aten_bridge.cpp
670+
util ${CMAKE_CURRENT_SOURCE_DIR}/extension/aten_util/aten_bridge.cpp
656671
)
657672
target_include_directories(
658673
util PUBLIC ${_common_include_directories} ${TORCH_INCLUDE_DIRS}
@@ -695,7 +710,9 @@ endif()
695710

696711
if(EXECUTORCH_BUILD_EXECUTOR_RUNNER)
697712
# Baseline libraries that executor_runner will link against.
698-
set(_executor_runner_libs executorch gflags)
713+
set(_executor_runner_libs executorch extension_evalue_util
714+
extension_runner_util gflags
715+
)
699716

700717
if(EXECUTORCH_BUILD_KERNELS_OPTIMIZED)
701718
list(APPEND _executor_runner_libs optimized_native_cpu_ops_lib)

examples/apple/mps/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ if(NOT CMAKE_TOOLCHAIN_FILE MATCHES ".*(iOS|ios\.toolchain)\.cmake$")
105105
mps_executor_runner
106106
bundled_program
107107
executorch
108+
extension_evalue_util
109+
extension_runner_util
108110
gflags
109111
etdump
110112
flatccrt

examples/apple/mps/test_mps.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ cmake_install_executorch_devtools_lib() {
1919
-DCMAKE_INSTALL_PREFIX=cmake-out \
2020
-DCMAKE_BUILD_TYPE=Release \
2121
-DEXECUTORCH_BUILD_DEVTOOLS=ON \
22+
-DEXECUTORCH_BUILD_EXTENSION_EVALUE_UTIL=ON \
23+
-DEXECUTORCH_BUILD_EXTENSION_RUNNER_UTIL=ON \
2224
-DEXECUTORCH_BUILD_MPS=ON \
2325
-DEXECUTORCH_ENABLE_EVENT_TRACER=ON \
2426
-DPYTHON_EXECUTABLE="$PYTHON_EXECUTABLE" \

examples/portable/custom_ops/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ list(TRANSFORM _executor_runner__srcs PREPEND "${EXECUTORCH_ROOT}/")
123123

124124
add_executable(custom_ops_executor_runner ${_executor_runner__srcs})
125125
target_link_libraries(
126-
custom_ops_executor_runner custom_ops_lib executorch gflags
126+
custom_ops_executor_runner custom_ops_lib executorch extension_evalue_util
127+
extension_runner_util gflags
127128
)
128129
target_compile_options(
129130
custom_ops_executor_runner PUBLIC ${_common_compile_options}

examples/qualcomm/executor_runner/CMakeLists.txt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,14 @@ target_include_directories(
1919
qnn_executor_runner PUBLIC ${_common_include_directories}
2020
)
2121
target_link_libraries(
22-
qnn_executor_runner qnn_executorch_backend full_portable_ops_lib etdump
23-
flatccrt gflags
22+
qnn_executor_runner
23+
qnn_executorch_backend
24+
extension_evalue_util
25+
extension_runner_util
26+
full_portable_ops_lib
27+
etdump
28+
flatccrt
29+
gflags
2430
)
2531
set_target_properties(
2632
qnn_executor_runner PROPERTIES LINK_FLAGS "-Wl,-rpath='$ORIGIN'"

examples/selective_build/CMakeLists.txt

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ if(NOT CMAKE_CXX_STANDARD)
3333
# Can't set to 11 due to executor_runner.cpp make_unique
3434
endif()
3535

36-
set(_common_compile_options -Wno-deprecated-declarations -fPIC -ffunction-sections -fdata-sections)
36+
set(_common_compile_options -Wno-deprecated-declarations -fPIC
37+
-ffunction-sections -fdata-sections
38+
)
3739

3840
# Let files say "include <executorch/path/to/header.h>".
3941
set(_common_include_directories ${EXECUTORCH_ROOT}/..)
@@ -43,7 +45,9 @@ find_package(
4345
gflags REQUIRED PATHS ${CMAKE_CURRENT_BINARY_DIR}/../../third-party
4446
)
4547

46-
target_include_directories(executorch_core INTERFACE ${_common_include_directories})
48+
target_include_directories(
49+
executorch_core INTERFACE ${_common_include_directories}
50+
)
4751

4852
# ------------------------------ OPTIONS BEGIN -------------------------------
4953

@@ -63,12 +67,13 @@ option(EXECUTORCH_SELECT_ALL_OPS
6367
)
6468

6569
# Option to enable parsing ops and dtypes directly from model pte file
66-
option(EXECUTORCH_SELECT_OPS_FROM_MODEL "Enable op selection from pte during build." OFF
70+
option(EXECUTORCH_SELECT_OPS_FROM_MODEL
71+
"Enable op selection from pte during build." OFF
6772
)
6873

69-
# Option to enable dtype selective build. Note: must be using selective build model API.
70-
option(EXECUTORCH_DTYPE_SELECTIVE_BUILD "Enable dtype selective build." OFF
71-
)
74+
# Option to enable dtype selective build. Note: must be using selective build
75+
# model API.
76+
option(EXECUTORCH_DTYPE_SELECTIVE_BUILD "Enable dtype selective build." OFF)
7277
# ------------------------------- OPTIONS END --------------------------------
7378

7479
#
@@ -155,7 +160,8 @@ if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
155160
target_link_options_gc_sections(selective_build_test)
156161
endif()
157162
target_link_libraries(
158-
selective_build_test PRIVATE executorch_core gflags select_build_lib
163+
selective_build_test PRIVATE executorch_core extension_evalue_util
164+
extension_runner_util gflags select_build_lib
159165
)
160166
executorch_target_link_options_shared_lib(select_build_lib)
161167
target_compile_options(selective_build_test PUBLIC ${_common_compile_options})

extension/evalue_util/CMakeLists.txt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Copyright (c) Meta Platforms, Inc. and affiliates.
2+
# All rights reserved.
3+
#
4+
# This source code is licensed under the BSD-style license found in the
5+
# LICENSE file in the root directory of this source tree.
6+
7+
# Please this file formatted by running:
8+
# ~~~
9+
# cmake-format -i CMakeLists.txt
10+
# ~~~
11+
# Source root directory for executorch.
12+
if(NOT EXECUTORCH_ROOT)
13+
set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../..)
14+
endif()
15+
list(TRANSFORM _extension_evalue_util__srcs PREPEND "${EXECUTORCH_ROOT}/")
16+
add_library(extension_evalue_util ${_extension_evalue_util__srcs})
17+
target_link_libraries(extension_evalue_util executorch_core)
18+
target_include_directories(
19+
extension_evalue_util PUBLIC ${_common_include_directories}
20+
)
21+
target_compile_options(extension_evalue_util PUBLIC ${_common_compile_options})
22+
23+
# Install libraries
24+
install(
25+
TARGETS extension_evalue_util
26+
DESTINATION ${CMAKE_BINARY_DIR}/lib
27+
INCLUDES
28+
DESTINATION ${_common_include_directories}
29+
)

extension/evalue_util/print_evalue.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ int get_edge_items_xalloc() {
3939

4040
/// Returns the number of "edge items" to print at the beginning and end of
4141
/// lists when using the provided stream.
42-
long get_stream_edge_items(std::ostream& os) {
43-
long edge_items = os.iword(get_edge_items_xalloc());
42+
size_t get_stream_edge_items(std::ostream& os) {
43+
size_t edge_items = os.iword(get_edge_items_xalloc());
4444
return edge_items <= 0 ? kDefaultEdgeItems : edge_items;
4545
}
4646

@@ -78,21 +78,20 @@ void print_scalar_list(
7878
executorch::aten::ArrayRef<T> list,
7979
bool print_length = true,
8080
bool elide_inner_items = true) {
81-
long edge_items = elide_inner_items ? get_stream_edge_items(os)
82-
: std::numeric_limits<long>::max();
81+
size_t edge_items = elide_inner_items ? get_stream_edge_items(os)
82+
: std::numeric_limits<long>::max();
8383
if (print_length) {
8484
os << "(len=" << list.size() << ")";
8585
}
8686

8787
// See if we'll be printing enough elements to cause us to wrap.
8888
bool wrapping = false;
8989
{
90-
long num_printed_items;
90+
size_t num_printed_items;
9191
if (elide_inner_items) {
92-
num_printed_items =
93-
std::min(static_cast<long>(list.size()), edge_items * 2);
92+
num_printed_items = std::min(list.size(), edge_items * 2);
9493
} else {
95-
num_printed_items = static_cast<long>(list.size());
94+
num_printed_items = list.size();
9695
}
9796
wrapping = num_printed_items > kItemsPerLine;
9897
}

0 commit comments

Comments
 (0)