@@ -23,17 +23,19 @@ function(gen_selected_ops)
2323 message (STATUS " OPS_FROM_MODEL: ${GEN_OPS_FROM_MODEL} " )
2424 message (STATUS " DTYPE_SELECTIVE_BUILD: ${GEN_DTYPE_SELECTIVE_BUILD} " )
2525
26+ set (_out_dir ${CMAKE_CURRENT_BINARY_DIR} /${GEN_LIB_NAME} )
27+
2628 if (GEN_DTYPE_SELECTIVE_BUILD)
2729 if (NOT GEN_OPS_FROM_MODEL)
2830 message (FATAL_ERROR " DTYPE_SELECTIVE_BUILD is only support with model API, please pass in a model" )
2931 endif ()
3032 endif ()
3133
3234 set (_oplist_yaml
33- ${CMAKE_CURRENT_BINARY_DIR} / ${GEN_LIB_NAME } /selected_operators.yaml
35+ ${_out_dir } /selected_operators.yaml
3436 )
3537
36- file (MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} / ${GEN_LIB_NAME } )
38+ file (MAKE_DIRECTORY ${_out_dir } )
3739
3840 file (GLOB_RECURSE _codegen_tools_srcs "${EXECUTORCH_ROOT} /codegen/tools/*.py" )
3941
@@ -67,11 +69,11 @@ function(gen_selected_ops)
6769
6870 if (GEN_DTYPE_SELECTIVE_BUILD)
6971 set (_opvariant_h
70- ${CMAKE_CURRENT_BINARY_DIR} / ${GEN_LIB_NAME } /selected_op_variants.h
72+ ${_out_dir } /selected_op_variants.h
7173 )
7274 set (_gen_opvariant_command "${PYTHON_EXECUTABLE} " -m codegen.tools.gen_selected_op_variants
7375 --yaml-file=${_oplist_yaml}
74- --output -dir=${CMAKE_CURRENT_BINARY_DIR} / ${GEN_LIB_NAME } /
76+ --output -dir=${_out_dir } /
7577 )
7678 message ("Command - ${_gen_opvariant_command} " )
7779 add_custom_command (
@@ -215,7 +217,7 @@ function(gen_operators_lib)
215217 set (_out_dir ${CMAKE_CURRENT_BINARY_DIR} /${GEN_LIB_NAME} )
216218 if (GEN_DTYPE_SELECTIVE_BUILD)
217219 set (_opvariant_h
218- ${CMAKE_CURRENT_BINARY_DIR} / ${GEN_LIB_NAME } /selected_op_variants.h
220+ ${_out_dir } /selected_op_variants.h
219221 )
220222 endif ()
221223
@@ -242,13 +244,6 @@ function(gen_operators_lib)
242244 if ("${portable_kernels_check} " IN_LIST GEN_KERNEL_LIBS)
243245 list (REMOVE_ITEM GEN_KERNEL_LIBS ${portable_kernels_check} )
244246
245- # Define portable kernels sources (same as in kernels/portable/CMakeLists.txt)
246- file (GLOB_RECURSE _portable_kernels_srcs
247- "${EXECUTORCH_ROOT} /kernels/portable/cpu/*.cpp"
248- )
249- list (FILTER _portable_kernels_srcs EXCLUDE REGEX "test/*.cpp" )
250- list (FILTER _portable_kernels_srcs EXCLUDE REGEX "codegen" )
251-
252247 # Build kernels_util_all_deps, since later selected_portable_kernels depends on it
253248 list (TRANSFORM _kernels_util_all_deps__srcs PREPEND "${EXECUTORCH_ROOT} /" )
254249 add_library (selected_kernels_util_all_deps ${_kernels_util_all_deps__srcs} )
@@ -258,7 +253,8 @@ function(gen_operators_lib)
258253 target_compile_options (selected_kernels_util_all_deps PUBLIC ${_common_compile_options} )
259254
260255 # Build selected_portable_kernels
261- add_library (selected_portable_kernels ${_portable_kernels_srcs} )
256+ list (TRANSFORM _portable_kernels__srcs PREPEND "${EXECUTORCH_ROOT} /" )
257+ add_library (selected_portable_kernels ${_portable_kernels__srcs} )
262258 target_link_libraries (selected_portable_kernels PRIVATE executorch_core selected_kernels_util_all_deps)
263259 target_compile_options (selected_portable_kernels PUBLIC ${_common_compile_options} )
264260 target_include_directories (selected_portable_kernels PRIVATE ${CMAKE_CURRENT_BINARY_DIR} /${GEN_LIB_NAME} /)
@@ -272,15 +268,14 @@ function(gen_operators_lib)
272268 target_compile_definitions (selected_portable_kernels PRIVATE EXECUTORCH_SELECTIVE_BUILD_DTYPE=1)
273269
274270 target_link_libraries (${GEN_LIB_NAME} PUBLIC selected_portable_kernels)
271+ else ()
272+ message (FATAL_ERROR "Currently dtype selective build is only supported for portable_kernels but {${GEN_KERNEL_LIBS} } were provided!" )
275273 endif ()
276274 endif ()
277275
276+ # After removing portable_kernels, test if there are other kernel libs provided
278277 if (GEN_KERNEL_LIBS)
279- if (GEN_DTYPE_SELECTIVE_BUILD)
280- message (FATAL_ERROR "Currently dtype selective build is only supported for portable_kernels but {${GEN_KERNEL_LIBS} } were provided!" )
281- else ()
282- target_link_libraries (${GEN_LIB_NAME} PUBLIC ${GEN_KERNEL_LIBS} )
283- endif ()
278+ target_link_libraries (${GEN_LIB_NAME} PUBLIC ${GEN_KERNEL_LIBS} )
284279 endif ()
285280 endif ()
286281
0 commit comments