Skip to content

Commit 974e2e3

Browse files
larryliu0820facebook-github-bot
authored andcommitted
Properly introduce selective build options (#625)
Summary: Pull Request resolved: #625 Refactor options to do selective build. * `EXECUTORCH_SELECT_ALL_OPS` by default `ON`, will be set to `OFF` if any of the other options is on. * `EXECUTORCH_SELECT_OPS_LIST` by default `OFF` * `EXECUTORCH_SELECT_OPS_YAML` by default `OFF`. This allows these options to be used outside of selective build examples. Reviewed By: digantdesai Differential Revision: D49935141 fbshipit-source-id: b19134b196f5d967da35c64062371745e4530c76
1 parent 86449bf commit 974e2e3

File tree

4 files changed

+30
-20
lines changed

4 files changed

+30
-20
lines changed

CMakeLists.txt

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,19 @@ option(BUILD_SELECTIVE_BUILD_TEST
9494

9595
option(EXECUTORCH_BUILD_SIZE_TEST "Whether to build size test" OFF)
9696

97-
if(BUILD_SELECTIVE_BUILD_TEST)
98-
option(SELECT_ALL_OPS
99-
"Whether to register all ops defined in portable kernel library." OFF)
100-
101-
# Option to register op list
102-
option(SELECT_OPS_LIST "Register the following list of ops" OFF)
103-
104-
# Option to register ops from yaml file
105-
option(SELECT_OPS_YAML "Register all the ops from a given yaml file" OFF)
97+
# Selective build options.
98+
option(EXECUTORCH_SELECT_ALL_OPS
99+
"Whether to register all ops defined in portable kernel library." ON)
100+
101+
# Option to register op list
102+
option(EXECUTORCH_SELECT_OPS_LIST "Register the following list of ops" OFF)
103+
104+
# Option to register ops from yaml file
105+
option(EXECUTORCH_SELECT_OPS_YAML
106+
"Register all the ops from a given yaml file" OFF)
107+
# Do not enable select all ops if any of the other select options is on.
108+
if(EXECUTORCH_SELECT_OPS_LIST OR EXECUTORCH_SELECT_OPS_YAML)
109+
set(EXECUTORCH_SELECT_ALL_OPS OFF)
106110
endif()
107111

108112
# Build xnn_executor_runner which depends on XNNPACK

examples/selective_build/CMakeLists.txt

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,7 @@ include(${EXECUTORCH_ROOT}/build/Codegen.cmake)
2727
# library
2828
#
2929
set(_kernel_lib)
30-
if(SELECT_ALL_OPS)
31-
gen_selected_ops("" "" "${SELECT_ALL_OPS}")
32-
list(APPEND _kernel_lib portable_kernels)
33-
elseif(SELECT_OPS_LIST)
34-
gen_selected_ops("" "${SELECT_OPS_LIST}" "")
35-
list(APPEND _kernel_lib portable_kernels)
36-
elseif(SELECT_OPS_YAML)
30+
if(EXECUTORCH_SELECT_OPS_YAML)
3731
set(_custom_ops_yaml ${EXECUTORCH_ROOT}/examples/custom_ops/custom_ops.yaml)
3832
gen_selected_ops("${_custom_ops_yaml}" "" "")
3933
set(kernel_sources
@@ -47,7 +41,15 @@ elseif(SELECT_OPS_YAML)
4741
target_compile_options(custom_kernels PUBLIC ${_common_compile_options})
4842

4943
list(APPEND _kernel_lib custom_kernels)
44+
else()
45+
list(APPEND _kernel_lib portable_kernels)
5046
endif()
47+
48+
gen_selected_ops(
49+
"${_custom_ops_yaml}"
50+
"${EXECUTORCH_SELECT_OPS_LIST}"
51+
"${EXECUTORCH_SELECT_ALL_OPS}")
52+
5153
generate_bindings_for_kernels(${EXECUTORCH_ROOT}/kernels/portable/functions.yaml
5254
"${_custom_ops_yaml}")
5355
gen_operators_lib("select_build_lib" ${_kernel_lib} executorch)

examples/selective_build/test_selective_build.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ test_cmake_select_all_ops() {
6363
&& retry cmake -DBUCK2="$BUCK" \
6464
-DBUILD_SELECTIVE_BUILD_TEST=ON \
6565
-DCMAKE_BUILD_TYPE=Release \
66-
-DSELECT_ALL_OPS=ON \
66+
-DEXECUTORCH_SELECT_ALL_OPS=ON \
6767
-DPYTHON_EXECUTABLE="$PYTHON_EXECUTABLE" ..)
6868

6969
echo "Build selective build test"
@@ -88,7 +88,7 @@ test_cmake_select_ops_in_list() {
8888
-DMAX_KERNEL_NUM=17 \
8989
-DBUILD_SELECTIVE_BUILD_TEST=ON \
9090
-DCMAKE_BUILD_TYPE=Release \
91-
-DSELECT_OPS_LIST="aten::convolution.out,\
91+
-DEXECUTORCH_SELECT_OPS_LIST="aten::convolution.out,\
9292
aten::_native_batch_norm_legit_no_training.out,aten::hardtanh.out,aten::add.out,\
9393
aten::mean.out,aten::view_copy.out,aten::permute_copy.out,aten::addmm.out,\
9494
aten,aten::clone.out" \
@@ -114,7 +114,7 @@ test_cmake_select_ops_in_yaml() {
114114
&& retry cmake -DBUCK2="$BUCK" \
115115
-DBUILD_SELECTIVE_BUILD_TEST=ON \
116116
-DCMAKE_BUILD_TYPE=Release \
117-
-DSELECT_OPS_YAML=ON \
117+
-DEXECUTORCH_SELECT_OPS_YAML=ON \
118118
-DPYTHON_EXECUTABLE="$PYTHON_EXECUTABLE" ..)
119119

120120
echo "Build selective build test"

kernels/portable/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@ list(FILTER _portable_kernels__srcs EXCLUDE REGEX "test/*.cpp")
3939
list(FILTER _portable_kernels__srcs EXCLUDE REGEX "codegen")
4040
# Generate C++ bindings to register kernels into both PyTorch (for AOT) and
4141
# Executorch (for runtime). Here select all ops in functions.yaml
42-
gen_selected_ops("${CMAKE_CURRENT_LIST_DIR}/functions.yaml" "" "")
42+
if(EXECUTORCH_SELECT_OPS_YAML)
43+
set(_yaml "${CMAKE_CURRENT_LIST_DIR}/functions.yaml")
44+
endif()
45+
gen_selected_ops(
46+
"${_yaml}" "${EXECUTORCH_SELECT_OPS_LIST}" "${EXECUTORCH_SELECT_ALL_OPS}")
4347
# Expect gen_selected_ops output file to be selected_operators.yaml
4448
generate_bindings_for_kernels(${CMAKE_CURRENT_SOURCE_DIR}/functions.yaml "")
4549
message("Generated files ${gen_command_sources}")

0 commit comments

Comments
 (0)