Skip to content

Commit ed4c08d

Browse files
committed
Support for model API
1 parent 2236350 commit ed4c08d

File tree

4 files changed

+23
-20
lines changed

4 files changed

+23
-20
lines changed

examples/selective_build/CMakeLists.txt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ option(EXECUTORCH_SELECT_ALL_OPS
6262
"Whether to register all ops defined in portable kernel library." OFF
6363
)
6464

65+
# Option to enable dtype selective build
66+
option(EXECUTORCH_SELECT_OPS_FROM_MODEL "Enable op selection from pte during build." OFF
67+
)
68+
6569
# Option to enable dtype selective build
6670
option(EXECUTORCH_DTYPE_SELECTIVE_BUILD "Enable dtype selection during build." OFF
6771
)
@@ -84,11 +88,8 @@ include(${EXECUTORCH_SRCS_FILE})
8488
#
8589
set(_kernel_lib)
8690
if(EXECUTORCH_SELECT_OPS_YAML)
87-
# set(_custom_ops_yaml
88-
# ${EXECUTORCH_ROOT}/examples/portable/custom_ops/custom_ops.yaml
89-
# )
9091
set(_custom_ops_yaml
91-
${EXECUTORCH_ROOT}/mv2_schema.yaml
92+
${EXECUTORCH_ROOT}/examples/portable/custom_ops/custom_ops.yaml
9293
)
9394
set(kernel_sources
9495
${EXECUTORCH_ROOT}/examples/portable/custom_ops/custom_ops_1_out.cpp
@@ -115,6 +116,8 @@ gen_selected_ops(
115116
"${EXECUTORCH_SELECT_OPS_LIST}"
116117
INCLUDE_ALL_OPS
117118
"${EXECUTORCH_SELECT_ALL_OPS}"
119+
OPS_FROM_MODEL
120+
"${EXECUTORCH_SELECT_OPS_FROM_MODEL}"
118121
DTYPE_SELECT
119122
"${EXECUTORCH_DTYPE_SELECTIVE_BUILD}"
120123
)

examples/selective_build/test_selective_build.sh

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,8 @@ test_cmake_select_ops_in_list() {
119119
# set MAX_KERNEL_NUM=22: 19 primops, add, mul
120120
rm -rf ${build_dir}
121121
retry cmake -DCMAKE_BUILD_TYPE=Release \
122-
-DMAX_KERNEL_NUM=22 \
123-
-DEXECUTORCH_SELECT_OPS_LIST="aten::convolution.out,\
124-
aten::_native_batch_norm_legit_no_training.out,aten::hardtanh.out,aten::add.out,\
125-
aten::mean.out,aten::view_copy.out,aten::permute_copy.out,aten::addmm.out,\
126-
aten,aten::clone.out" \
122+
-DEXECUTORCH_SELECT_OPS_FROM_MODEL="./mv2.pte" \
123+
-DEXECUTORCH_OPTIMIZE_SIZE=ON \
127124
-DEXECUTORCH_DTYPE_SELECTIVE_BUILD=ON \
128125
-DCMAKE_INSTALL_PREFIX=cmake-out \
129126
-DPYTHON_EXECUTABLE="$PYTHON_EXECUTABLE" \
@@ -169,9 +166,9 @@ test_cmake_select_ops_and_dtype() {
169166
${PYTHON_EXECUTABLE} -m examples.portable.scripts.export --model_name="mv2"
170167
local example_dir=examples/selective_build
171168
local build_dir=cmake-out/${example_dir}
172-
rm -rf ${build_dir}
173169
retry cmake -DCMAKE_BUILD_TYPE=Release \
174-
-DEXECUTORCH_SELECT_OPS_YAML=ON \
170+
-DEXECUTORCH_SELECT_OPS_FROM_MODEL="./mv2.pte" \
171+
-DEXECUTORCH_OPTIMIZE_SIZE=ON \
175172
-DEXECUTORCH_DTYPE_SELECTIVE_BUILD=ON \
176173
-DCMAKE_INSTALL_PREFIX=cmake-out \
177174
-DPYTHON_EXECUTABLE="$PYTHON_EXECUTABLE" \
@@ -182,7 +179,7 @@ test_cmake_select_ops_and_dtype() {
182179
cmake --build ${build_dir} -j9 --config Release
183180

184181
echo 'Running selective build test'
185-
${build_dir}/selective_build_test --model_path="./mv2.pte" --ops_schema_yaml_target="./mv2_schema.yaml"
182+
${build_dir}/selective_build_test --model_path="./mv2.pte"
186183

187184
echo "Removing mv2.pte"
188185
rm "./mv2.pte"
@@ -202,9 +199,9 @@ if [[ $1 == "cmake" ]];
202199
then
203200
cmake_install_executorch_lib
204201
# test_cmake_select_all_ops
205-
# test_cmake_select_ops_in_list
202+
test_cmake_select_ops_in_list
206203
# test_cmake_select_ops_in_yaml
207-
test_cmake_select_ops_and_dtype
204+
# test_cmake_select_ops_and_dtype
208205
elif [[ $1 == "buck2" ]];
209206
then
210207
test_buck2_select_all_ops

test/build_size_test.sh

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ cmake_install_executorch_lib() {
2929
-DCMAKE_BUILD_TYPE=Release \
3030
-DEXECUTORCH_BUILD_EXECUTOR_RUNNER=OFF \
3131
-DEXECUTORCH_OPTIMIZE_SIZE=ON \
32+
-DEXECUTORCH_SELECTIVE_BUILD_DTYPE=ON \
3233
-DPYTHON_EXECUTABLE="$PYTHON_EXECUTABLE" \
3334
${EXTRA_BUILD_ARGS} \
3435
-Bcmake-out .
@@ -44,11 +45,9 @@ test_cmake_size_test() {
4445
echo "Build size test"
4546
cmake --build cmake-out/test -j9 --config Release
4647

47-
echo 'ExecuTorch with no ops binary size, unstripped:'
48-
ls -al cmake-out/test/size_test
49-
50-
echo 'ExecuTorch with portable ops binary size, unstripped:'
51-
ls -al cmake-out/test/size_test_all_ops
48+
strip cmake-out/test/size_test
49+
strip cmake-out/test/size_test_all_ops
50+
ls -lah cmake-out/test/
5251
}
5352

5453
if [[ -z $PYTHON_EXECUTABLE ]]; then

tools/cmake/Codegen.cmake

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@
1212
include(${EXECUTORCH_ROOT}/tools/cmake/Utils.cmake)
1313

1414
function(gen_selected_ops)
15-
set(arg_names LIB_NAME OPS_SCHEMA_YAML ROOT_OPS INCLUDE_ALL_OPS DTYPE_SELECT)
15+
set(arg_names LIB_NAME OPS_SCHEMA_YAML ROOT_OPS INCLUDE_ALL_OPS OPS_FROM_MODEL DTYPE_SELECT)
1616
cmake_parse_arguments(GEN "" "" "${arg_names}" ${ARGN})
1717

1818
message(STATUS "Generating operator lib:")
1919
message(STATUS " LIB_NAME: ${GEN_LIB_NAME}")
2020
message(STATUS " OPS_SCHEMA_YAML: ${GEN_OPS_SCHEMA_YAML}")
2121
message(STATUS " ROOT_OPS: ${GEN_ROOT_OPS}")
2222
message(STATUS " INCLUDE_ALL_OPS: ${GEN_INCLUDE_ALL_OPS}")
23+
message(STATUS " OPS_FROM_MODEL: ${GEN_OPS_FROM_MODEL}")
2324
message(STATUS " DTYPE_SELECT: ${GEN_DTYPE_SELECT}")
2425

2526
set(_oplist_yaml
@@ -45,6 +46,9 @@ function(gen_selected_ops)
4546
if(GEN_INCLUDE_ALL_OPS)
4647
list(APPEND _gen_oplist_command --include_all_operators)
4748
endif()
49+
if(GEN_OPS_FROM_MODEL)
50+
list(APPEND _gen_oplist_command --model_file_path="${GEN_OPS_FROM_MODEL}")
51+
endif()
4852

4953
message("Command - ${_gen_oplist_command}")
5054
add_custom_command(

0 commit comments

Comments
 (0)