Skip to content

Commit 563ed0f

Browse files
committed
Testing, mv2.pte, seems like yaml does not include all the needed dtypes
1 parent 436abfa commit 563ed0f

File tree

5 files changed

+60
-27
lines changed

5 files changed

+60
-27
lines changed

examples/selective_build/CMakeLists.txt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ 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)
36+
set(_common_compile_options -Wno-deprecated-declarations -fPIC -ffunction-sections -fdata-sections)
3737

3838
# Let files say "include <executorch/path/to/header.h>".
3939
set(_common_include_directories ${EXECUTORCH_ROOT}/..)
@@ -129,7 +129,14 @@ generate_bindings_for_kernels(
129129
)
130130

131131
gen_operators_lib(
132-
LIB_NAME "select_build_lib" KERNEL_LIBS ${_kernel_lib} DEPS executorch_core
132+
LIB_NAME
133+
"select_build_lib"
134+
KERNEL_LIBS
135+
${_kernel_lib}
136+
DEPS
137+
executorch_core
138+
DTYPE_SELECTIVE_BUILD
139+
"${EXECUTORCH_DTYPE_SELECTIVE_BUILD}"
133140
)
134141

135142
list(TRANSFORM _executor_runner__srcs PREPEND "${EXECUTORCH_ROOT}/")

examples/selective_build/test_selective_build.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,10 @@ test_cmake_select_ops_in_model() {
191191
local example_dir=examples/selective_build
192192
local build_dir=cmake-out/${example_dir}
193193
rm -rf ${build_dir}
194-
retry cmake -DCMAKE_BUILD_TYPE=$CMAKE_BUILD_TYPE \
194+
retry cmake -DCMAKE_BUILD_TYPE="$CMAKE_BUILD_TYPE" \
195195
-DEXECUTORCH_SELECT_OPS_FROM_MODEL="./mv2.pte" \
196+
-DEXECUTORCH_DTYPE_SELECTIVE_BUILD=ON \
197+
-DEXECUTORCH_OPTIMIZE_SIZE=ON \
196198
-DCMAKE_INSTALL_PREFIX=cmake-out \
197199
-DPYTHON_EXECUTABLE="$PYTHON_EXECUTABLE" \
198200
-B${build_dir} \
@@ -204,8 +206,8 @@ test_cmake_select_ops_in_model() {
204206
echo 'Running selective build test'
205207
${build_dir}/selective_build_test --model_path="./mv2.pte"
206208

207-
echo "Removing mv2.pte"
208-
rm "./mv2.pte"
209+
# echo "Removing mv2.pte"
210+
# rm "./mv2.pte"
209211
}
210212

211213
if [[ -z $BUCK ]];

kernels/portable/cpu/selective_build.h

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,34 +20,42 @@ inline constexpr bool should_include_kernel_dtype(
2020
const char *operator_name,
2121
executorch::aten::ScalarType scalar_type
2222
) {
23-
return ((executorch::aten::string_view(operator_name).compare("add.out") == 0)
24-
&& (scalar_type == executorch::aten::ScalarType::Float || scalar_type == executorch::aten::ScalarType::Int));
25-
// || ((executorch::aten::string_view(operator_name).compare("mul.out") == 0)
23+
// return (((std::string_view(operator_name).compare("add.out") == 0))
2624
// && (scalar_type == executorch::aten::ScalarType::Float));
27-
// || ((executorch::aten::string_view(operator_name).compare("sub.out") == 0)
28-
// && (true));
29-
}
30-
31-
//inline constexpr bool should_include_kernel_dtype(
32-
// const char *operator_name,
33-
// executorch::aten::ScalarType scalar_type
34-
//) {
3525
// return ((executorch::aten::string_view(operator_name).compare("add.out") == 0)
3626
// && (true))
3727
// || ((executorch::aten::string_view(operator_name).compare("mm.out") == 0)
3828
// && (true));
3929
//}
30+
31+
32+
return ((std::string_view(operator_name).compare("_native_batch_norm_legit_no_training.out") == 0)
33+
&& (scalar_type == executorch::aten::ScalarType::Float))
34+
|| ((std::string_view(operator_name).compare("add.out") == 0)
35+
&& (scalar_type == executorch::aten::ScalarType::Float))
36+
|| ((std::string_view(operator_name).compare("addmm.out") == 0)
37+
&& (scalar_type == executorch::aten::ScalarType::Float))
38+
|| ((std::string_view(operator_name).compare("clone.out") == 0)
39+
&& (scalar_type == executorch::aten::ScalarType::Float))
40+
|| ((std::string_view(operator_name).compare("convolution.out") == 0)
41+
&& (scalar_type == executorch::aten::ScalarType::Float))
42+
|| ((std::string_view(operator_name).compare("hardtanh.out") == 0)
43+
&& (scalar_type == executorch::aten::ScalarType::Float))
44+
//|| ((std::string_view(operator_name).compare("hardtanh.out") == 0)
45+
// && (scalar_type == executorch::aten::ScalarType::Double))
46+
|| ((std::string_view(operator_name).compare("mean.out") == 0)
47+
&& (scalar_type == executorch::aten::ScalarType::Float))
48+
|| ((std::string_view(operator_name).compare("mean_dim.out") == 0)
49+
&& (scalar_type == executorch::aten::ScalarType::Float))
50+
|| ((std::string_view(operator_name).compare("permute_copy.out") == 0)
51+
&& (scalar_type == executorch::aten::ScalarType::Float));
52+
}
4053
/*
4154
inline constexpr bool should_include_kernel_dtype(
4255
const char* ,//operator_name,
4356
executorch::aten::ScalarType //scalar_type*
4457
) {
4558
return true;
46-
47-
// return ((executorch::aten::string_view(operator_name).compare("my_ops::mul3.out") == 0)
48-
// && (true))
49-
// || ((executorch::aten::string_view(operator_name).compare("my_ops::mul4.out") == 0)
50-
// && (true));
5159
}
5260
*/
5361
#endif

test/build_size_test.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ cmake_install_executorch_lib() {
2323
update_tokenizers_git_submodule
2424
local EXTRA_BUILD_ARGS="${@}"
2525

26-
CXXFLAGS="$COMMON_CXXFLAGS" retry cmake -DBUCK2="$BUCK2" \
26+
CXXFLAGS="$COMMON_CXXFLAGS" retry cmake \
2727
-DCMAKE_CXX_STANDARD_REQUIRED=ON \
2828
-DCMAKE_INSTALL_PREFIX=cmake-out \
2929
-DCMAKE_BUILD_TYPE=Release \
@@ -44,8 +44,8 @@ test_cmake_size_test() {
4444
echo "Build size test"
4545
cmake --build cmake-out/test -j9 --config Release
4646

47-
strip cmake-out/test/size_test
48-
strip cmake-out/test/size_test_all_ops
47+
#cmake-out/test/size_test
48+
#cmake-out/test/size_test_all_ops
4949
ls -lah cmake-out/test/
5050
}
5151

tools/cmake/Codegen.cmake

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,22 +193,35 @@ endfunction()
193193

194194
# Generate a runtime lib for registering operators in Executorch
195195
function(gen_operators_lib)
196-
set(multi_arg_names LIB_NAME KERNEL_LIBS DEPS)
196+
set(multi_arg_names LIB_NAME KERNEL_LIBS DEPS DTYPE_SELECTIVE_BUILD)
197197
cmake_parse_arguments(GEN "" "" "${multi_arg_names}" ${ARGN})
198198

199199
message("REMOVE_ME-gen_op_lib")
200200
message(STATUS "Generating operator lib:")
201201
message(STATUS " LIB_NAME: ${GEN_LIB_NAME}")
202202
message(STATUS " KERNEL_LIBS: ${GEN_KERNEL_LIBS}")
203203
message(STATUS " DEPS: ${GEN_DEPS}")
204+
message(STATUS " DTYPE_SELECTIVE_BUILD: ${GEN_DTYPE_SELECTIVE_BUILD}")
204205

205206
set(_out_dir ${CMAKE_CURRENT_BINARY_DIR}/${GEN_LIB_NAME})
207+
if(DTYPE_SELECTIVE_BUILD)
208+
set(_opvariant_h
209+
${CMAKE_CURRENT_BINARY_DIR}/${GEN_LIB_NAME}/selected_op_variants.h
210+
)
211+
endif()
206212

207213
add_library(${GEN_LIB_NAME})
214+
215+
set(_srcs_list
216+
${_out_dir}/RegisterCodegenUnboxedKernelsEverything.cpp
217+
${_out_dir}/Functions.h ${_out_dir}/NativeFunctions.h
218+
)
219+
if(DTYPE_SELECTIVE_BUILD)
220+
list(APPEND _srcs_list ${_opvariant_h})
221+
endif()
208222
target_sources(
209223
${GEN_LIB_NAME}
210-
PRIVATE ${_out_dir}/RegisterCodegenUnboxedKernelsEverything.cpp
211-
${_out_dir}/Functions.h ${_out_dir}/NativeFunctions.h
224+
PRIVATE ${_srcs_list}
212225
)
213226
target_link_libraries(${GEN_LIB_NAME} PRIVATE ${GEN_DEPS})
214227
if(GEN_KERNEL_LIBS)
@@ -217,6 +230,9 @@ function(gen_operators_lib)
217230

218231
target_link_options_shared_lib(${GEN_LIB_NAME})
219232
set(_generated_headers ${_out_dir}/Functions.h ${_out_dir}/NativeFunctions.h)
233+
if(DTYPE_SELECTIVE_BUILD)
234+
list(APPEND _generated_headers ${_opvariant_h})
235+
endif()
220236
set_target_properties(
221237
${GEN_LIB_NAME} PROPERTIES PUBLIC_HEADER "${_generated_headers}"
222238
)

0 commit comments

Comments
 (0)