Skip to content

Commit 65dcb04

Browse files
committed
Able to now persist the needed header file
1 parent 563ed0f commit 65dcb04

File tree

4 files changed

+28
-48
lines changed

4 files changed

+28
-48
lines changed

examples/selective_build/CMakeLists.txt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,14 @@ gen_selected_ops(
123123
)
124124

125125
generate_bindings_for_kernels(
126-
LIB_NAME "select_build_lib" FUNCTIONS_YAML
127-
${EXECUTORCH_ROOT}/kernels/portable/functions.yaml CUSTOM_OPS_YAML
126+
LIB_NAME
127+
"select_build_lib"
128+
FUNCTIONS_YAML
129+
${EXECUTORCH_ROOT}/kernels/portable/functions.yaml
130+
CUSTOM_OPS_YAML
128131
"${_custom_ops_yaml}"
132+
DTYPE_SELECTIVE_BUILD
133+
"${EXECUTORCH_DTYPE_SELECTIVE_BUILD}"
129134
)
130135

131136
gen_operators_lib(

examples/selective_build/test_selective_build.sh

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -186,13 +186,15 @@ test_cmake_select_ops_in_yaml() {
186186
}
187187

188188
test_cmake_select_ops_in_model() {
189-
echo "Exporting MobilenetV2"
190-
${PYTHON_EXECUTABLE} -m examples.portable.scripts.export --model_name="mv2"
189+
local model_name="add_mul"
190+
local model_export_name="${model_name}.pte"
191+
echo "Exporting ${model_name}"
192+
${PYTHON_EXECUTABLE} -m examples.portable.scripts.export --model_name="${model_name}"
191193
local example_dir=examples/selective_build
192194
local build_dir=cmake-out/${example_dir}
193195
rm -rf ${build_dir}
194196
retry cmake -DCMAKE_BUILD_TYPE="$CMAKE_BUILD_TYPE" \
195-
-DEXECUTORCH_SELECT_OPS_FROM_MODEL="./mv2.pte" \
197+
-DEXECUTORCH_SELECT_OPS_FROM_MODEL="./${model_export_name}" \
196198
-DEXECUTORCH_DTYPE_SELECTIVE_BUILD=ON \
197199
-DEXECUTORCH_OPTIMIZE_SIZE=ON \
198200
-DCMAKE_INSTALL_PREFIX=cmake-out \
@@ -204,10 +206,10 @@ test_cmake_select_ops_in_model() {
204206
cmake --build ${build_dir} -j9 --config $CMAKE_BUILD_TYPE
205207

206208
echo 'Running selective build test'
207-
${build_dir}/selective_build_test --model_path="./mv2.pte"
209+
${build_dir}/selective_build_test --model_path="./${model_export_name}"
208210

209-
# echo "Removing mv2.pte"
210-
# rm "./mv2.pte"
211+
echo "Removing ${model_export_name}"
212+
rm "./${model_export_name}"
211213
}
212214

213215
if [[ -z $BUCK ]];

kernels/portable/cpu/selective_build.h

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -16,48 +16,12 @@
1616
#include "selected_op_variants.h"
1717
#else
1818
// dummy implementation
19-
inline constexpr bool should_include_kernel_dtype(
20-
const char *operator_name,
21-
executorch::aten::ScalarType scalar_type
22-
) {
23-
// return (((std::string_view(operator_name).compare("add.out") == 0))
24-
// && (scalar_type == executorch::aten::ScalarType::Float));
25-
// return ((executorch::aten::string_view(operator_name).compare("add.out") == 0)
26-
// && (true))
27-
// || ((executorch::aten::string_view(operator_name).compare("mm.out") == 0)
28-
// && (true));
29-
//}
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-
}
53-
/*
5419
inline constexpr bool should_include_kernel_dtype(
5520
const char* ,//operator_name,
5621
executorch::aten::ScalarType //scalar_type*
5722
) {
5823
return true;
5924
}
60-
*/
6125
#endif
6226

6327
namespace torch {

tools/cmake/Codegen.cmake

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,12 @@ function(gen_selected_ops)
7171
--output-dir=${CMAKE_CURRENT_BINARY_DIR}/${GEN_LIB_NAME}/
7272
)
7373
message("Command - ${_gen_opvariant_command}")
74+
message("OUTPUT - ${_opvariant_h}")
7475
add_custom_command(
75-
COMMENT "Generating selected_op_variants.h for ${GEN_LIB_NAME}"
76+
COMMENT "Generating ${_opvariant_h} for ${GEN_LIB_NAME}"
7677
OUTPUT ${_opvariant_h}
7778
COMMAND ${_gen_opvariant_command}
78-
DEPENDS ${_oplist_yaml} ${_codegen_tools_srcs}
79+
DEPENDS ${_oplist_yaml} ${GEN_OPS_SCHEMA_YAML} ${_codegen_tools_srcs}
7980
WORKING_DIRECTORY ${EXECUTORCH_ROOT}
8081
)
8182
endif()
@@ -88,14 +89,15 @@ endfunction()
8889
# functions_yaml CUSTOM_OPS_YAML custom_ops_yaml )
8990
function(generate_bindings_for_kernels)
9091
set(options ADD_EXCEPTION_BOUNDARY)
91-
set(arg_names LIB_NAME FUNCTIONS_YAML CUSTOM_OPS_YAML)
92+
set(arg_names LIB_NAME FUNCTIONS_YAML CUSTOM_OPS_YAML DTYPE_SELECTIVE_BUILD)
9293
cmake_parse_arguments(GEN "${options}" "${arg_names}" "" ${ARGN})
9394

9495
message(STATUS "Generating kernel bindings:")
9596
message(STATUS " LIB_NAME: ${GEN_LIB_NAME}")
9697
message(STATUS " FUNCTIONS_YAML: ${GEN_FUNCTIONS_YAML}")
9798
message(STATUS " CUSTOM_OPS_YAML: ${GEN_CUSTOM_OPS_YAML}")
9899
message(STATUS " ADD_EXCEPTION_BOUNDARY: ${GEN_ADD_EXCEPTION_BOUNDARY}")
100+
message(STATUS " DTYPE_SELECTIVE_BUILD: ${GEN_DTYPE_SELECTIVE_BUILD}")
99101

100102
# Command to generate selected_operators.yaml from custom_ops.yaml.
101103
file(GLOB_RECURSE _codegen_templates "${EXECUTORCH_ROOT}/codegen/templates/*")
@@ -104,6 +106,13 @@ function(generate_bindings_for_kernels)
104106
# By default selective build output is selected_operators.yaml
105107
set(_oplist_yaml ${_out_dir}/selected_operators.yaml)
106108

109+
# If dtype selective build is enable, force header file to be preserved
110+
if(GEN_DTYPE_SELECTIVE_BUILD)
111+
set(_opvariant_h ${_out_dir}/selected_op_variants.h)
112+
else()
113+
set(_opvariant_h "")
114+
endif()
115+
107116
# Command to codegen C++ wrappers to register custom ops to both PyTorch and
108117
# Executorch runtime.
109118
execute_process(
@@ -148,7 +157,7 @@ function(generate_bindings_for_kernels)
148157
COMMENT "Generating code for kernel registration"
149158
OUTPUT ${_gen_command_sources}
150159
COMMAND ${_gen_command}
151-
DEPENDS ${_oplist_yaml} ${GEN_CUSTOM_OPS_YAML}
160+
DEPENDS ${_oplist_yaml} ${_opvariant_h} ${GEN_CUSTOM_OPS_YAML}
152161
${GEN_FUNCTIONS_YAML} ${_codegen_templates}
153162
${_torchgen_srcs}
154163
WORKING_DIRECTORY ${EXECUTORCH_ROOT}

0 commit comments

Comments
 (0)