Skip to content

Commit 6972848

Browse files
committed
Adding support for dtye selection from dictionary API
1 parent 69f3da0 commit 6972848

File tree

3 files changed

+43
-5
lines changed

3 files changed

+43
-5
lines changed

examples/selective_build/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ option(EXECUTORCH_SELECT_ALL_OPS
6666
"Whether to register all ops defined in portable kernel library." OFF
6767
)
6868

69+
# Option to enable parsing ops and dtypes from json formatted dictionary
70+
option(EXECUTORCH_SELECT_OPS_FROM_DICT
71+
"Enable op selection from json formattting string during build." OFF
72+
)
73+
6974
# Option to enable parsing ops and dtypes directly from model pte file
7075
option(EXECUTORCH_SELECT_OPS_FROM_MODEL
7176
"Enable op selection from pte during build." OFF
@@ -121,6 +126,8 @@ gen_selected_ops(
121126
"${EXECUTORCH_SELECT_OPS_LIST}"
122127
INCLUDE_ALL_OPS
123128
"${EXECUTORCH_SELECT_ALL_OPS}"
129+
OPS_FROM_DICT
130+
"${EXECUTORCH_SELECT_OPS_FROM_DICT}"
124131
OPS_FROM_MODEL
125132
"${EXECUTORCH_SELECT_OPS_FROM_MODEL}"
126133
DTYPE_SELECTIVE_BUILD

examples/selective_build/test_selective_build.sh

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

164+
test_cmake_select_ops_in_dict() {
165+
echo "Exporting MobilenetV2"
166+
${PYTHON_EXECUTABLE} -m examples.portable.scripts.export --model_name="add"
167+
168+
local example_dir=examples/selective_build
169+
local build_dir=cmake-out/${example_dir}
170+
# set MAX_KERNEL_NUM=22: 19 primops, add, mul
171+
rm -rf ${build_dir}
172+
retry cmake -DCMAKE_BUILD_TYPE=Release \
173+
-DMAX_KERNEL_NUM=22 \
174+
-DEXECUTORCH_SELECT_OPS_LIST='{"aten::add": [Scalar.Float.name]}'
175+
-DCMAKE_INSTALL_PREFIX=cmake-out \
176+
-DPYTHON_EXECUTABLE="$PYTHON_EXECUTABLE" \
177+
-B${build_dir} \
178+
${example_dir}
179+
180+
echo "Building ${example_dir}"
181+
cmake --build ${build_dir} -j9 --config Release
182+
183+
echo 'Running selective build test'
184+
${build_dir}/selective_build_test --model_path="./mv2.pte"
185+
186+
echo "Removing mv2.pte"
187+
rm "./mv2.pte"
188+
}
189+
164190
test_cmake_select_ops_in_model() {
165191
local model_name="add_mul"
166192
local model_export_name="${model_name}.pte"
@@ -206,10 +232,11 @@ fi
206232
if [[ $1 == "cmake" ]];
207233
then
208234
cmake_install_executorch_lib $CMAKE_BUILD_TYPE
209-
test_cmake_select_all_ops
210-
test_cmake_select_ops_in_list
211-
test_cmake_select_ops_in_yaml
212-
test_cmake_select_ops_in_model
235+
#test_cmake_select_all_ops
236+
#test_cmake_select_ops_in_list
237+
#test_cmake_select_ops_in_yaml
238+
#test_cmake_select_ops_in_model
239+
test_cmake_select_ops_in_dict
213240
elif [[ $1 == "buck2" ]];
214241
then
215242
test_buck2_select_all_ops

tools/cmake/Codegen.cmake

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
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 OPS_FROM_MODEL DTYPE_SELECTIVE_BUILD)
15+
set(arg_names LIB_NAME OPS_SCHEMA_YAML ROOT_OPS INCLUDE_ALL_OPS OPS_FROM_MODEL OPS_FROM_DICT DTYPE_SELECTIVE_BUILD)
1616
cmake_parse_arguments(GEN "" "" "${arg_names}" ${ARGN})
1717

1818
message(STATUS "Generating selected operator lib:")
@@ -21,6 +21,7 @@ function(gen_selected_ops)
2121
message(STATUS " ROOT_OPS: ${GEN_ROOT_OPS}")
2222
message(STATUS " INCLUDE_ALL_OPS: ${GEN_INCLUDE_ALL_OPS}")
2323
message(STATUS " OPS_FROM_MODEL: ${GEN_OPS_FROM_MODEL}")
24+
message(STATUS " OPS_FROM_DICT: ${GEN_OPS_FROM_DICT}")
2425
message(STATUS " DTYPE_SELECTIVE_BUILD: ${GEN_DTYPE_SELECTIVE_BUILD}")
2526

2627
set(_out_dir ${CMAKE_CURRENT_BINARY_DIR}/${GEN_LIB_NAME})
@@ -54,6 +55,9 @@ function(gen_selected_ops)
5455
if(GEN_INCLUDE_ALL_OPS)
5556
list(APPEND _gen_oplist_command --include_all_operators)
5657
endif()
58+
if(GEN_OPS_FROM_DICT)
59+
list(APPEND _gen_oplist_command --ops_dict="${GEN_OPS_FROM_DICT}")
60+
endif()
5761
if(GEN_OPS_FROM_MODEL)
5862
list(APPEND _gen_oplist_command --model_file_path="${GEN_OPS_FROM_MODEL}")
5963
endif()

0 commit comments

Comments
 (0)