Skip to content

Commit fe04d64

Browse files
committed
Added model API to selective build in OSS
1 parent 30582ab commit fe04d64

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

examples/selective_build/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ option(EXECUTORCH_SELECT_OPS_LIST "Register a list of ops, separated by comma"
6161
option(EXECUTORCH_SELECT_ALL_OPS
6262
"Whether to register all ops defined in portable kernel library." OFF
6363
)
64+
65+
# Option to enable dtype selective build
66+
option(EXECUTORCH_SELECT_OPS_FROM_MODEL "Enable op selection from pte during build." OFF
67+
)
6468
# ------------------------------- OPTIONS END --------------------------------
6569

6670
#
@@ -108,6 +112,8 @@ gen_selected_ops(
108112
"${EXECUTORCH_SELECT_OPS_LIST}"
109113
INCLUDE_ALL_OPS
110114
"${EXECUTORCH_SELECT_ALL_OPS}"
115+
OPS_FROM_MODEL
116+
"${EXECUTORCH_SELECT_OPS_FROM_MODEL}"
111117
)
112118

113119
generate_bindings_for_kernels(

examples/selective_build/test_selective_build.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,28 @@ test_cmake_select_ops_in_yaml() {
161161
rm "./custom_ops_1.pte"
162162
}
163163

164+
test_cmake_select_ops_in_model() {
165+
echo "Exporting MobilenetV2"
166+
${PYTHON_EXECUTABLE} -m examples.portable.scripts.export --model_name="mv2"
167+
local example_dir=examples/selective_build
168+
local build_dir=cmake-out/${example_dir}
169+
retry cmake -DCMAKE_BUILD_TYPE=Release \
170+
-DEXECUTORCH_SELECT_OPS_FROM_MODEL="./mv2.pte" \
171+
-DCMAKE_INSTALL_PREFIX=cmake-out \
172+
-DPYTHON_EXECUTABLE="$PYTHON_EXECUTABLE" \
173+
-B${build_dir} \
174+
${example_dir}
175+
176+
echo "Building ${example_dir}"
177+
cmake --build ${build_dir} -j9 --config Release
178+
179+
echo 'Running selective build test'
180+
${build_dir}/selective_build_test --model_path="./mv2.pte"
181+
182+
echo "Removing mv2.pte"
183+
rm "./mv2.pte"
184+
}
185+
164186
if [[ -z $BUCK ]];
165187
then
166188
BUCK=buck2
@@ -177,6 +199,7 @@ then
177199
test_cmake_select_all_ops
178200
test_cmake_select_ops_in_list
179201
test_cmake_select_ops_in_yaml
202+
test_cmake_select_ops_in_model
180203
elif [[ $1 == "buck2" ]];
181204
then
182205
test_buck2_select_all_ops

tools/cmake/Codegen.cmake

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,20 @@
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)
15+
set(arg_names LIB_NAME OPS_SCHEMA_YAML ROOT_OPS INCLUDE_ALL_OPS OPS_FROM_MODEL)
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

2425
set(_oplist_yaml
2526
${CMAKE_CURRENT_BINARY_DIR}/${GEN_LIB_NAME}/selected_operators.yaml
2627
)
28+
2729
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${GEN_LIB_NAME})
2830

2931
file(GLOB_RECURSE _codegen_tools_srcs "${EXECUTORCH_ROOT}/codegen/tools/*.py")
@@ -43,6 +45,9 @@ function(gen_selected_ops)
4345
if(GEN_INCLUDE_ALL_OPS)
4446
list(APPEND _gen_oplist_command --include_all_operators)
4547
endif()
48+
if(GEN_OPS_FROM_MODEL)
49+
list(APPEND _gen_oplist_command --model_file_path="${GEN_OPS_FROM_MODEL}")
50+
endif()
4651

4752
message("Command - ${_gen_oplist_command}")
4853
add_custom_command(

0 commit comments

Comments
 (0)