Skip to content

Commit

Permalink
Build optimized operators lib with -fexceptions
Browse files Browse the repository at this point in the history
Pull Request resolved: #7546

It should be permissible for this library to use exceptions, since it is not required to supported embedded systems.

TODO: presumably we need to manage rollout of the torchgen patch?

ghstack-source-id: 260686358
@exported-using-ghexport

Differential Revision: [D67904052](https://our.internmc.facebook.com/intern/diff/D67904052/)
  • Loading branch information
swolchok committed Jan 8, 2025
1 parent 9d72ca6 commit 99a8848
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .ci/docker/ci_commit_pins/pytorch.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2ea4b56ec872424e486c4fe2d55da061067a2ed3
f0c50a619c282a01ef1ad33690b7ab5e615d9fef
12 changes: 9 additions & 3 deletions build/Codegen.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@
# arguments.
function(gen_selected_ops)
set(arg_names LIB_NAME OPS_SCHEMA_YAML ROOT_OPS INCLUDE_ALL_OPS)
cmake_parse_arguments(GEN "" "" "${arg_names}" ${ARGN})
cmake_parse_arguments(GEN "${options}" "" "${arg_names}" ${ARGN})

message(STATUS "Generating operator lib:")
message(STATUS " LIB_NAME: ${GEN_LIB_NAME}")
message(STATUS " OPS_SCHEMA_YAML: ${GEN_OPS_SCHEMA_YAML}")
message(STATUS " ROOT_OPS: ${GEN_ROOT_OPS}")
message(STATUS " INCLUDE_ALL_OPS: ${GEN_INCLUDE_ALL_OPS}")
message(STATUS " ADD_EXCEPTION_BOUNDARY: ${GEN_ADD_EXCEPTION_BOUNDARY}")

set(_oplist_yaml
${CMAKE_CURRENT_BINARY_DIR}/${GEN_LIB_NAME}/selected_operators.yaml
Expand Down Expand Up @@ -59,13 +60,15 @@ endfunction()
# Invoked as generate_bindings_for_kernels( LIB_NAME lib_name FUNCTIONS_YAML
# functions_yaml CUSTOM_OPS_YAML custom_ops_yaml )
function(generate_bindings_for_kernels)
set(options ADD_EXCEPTION_BOUNDARY)
set(arg_names LIB_NAME FUNCTIONS_YAML CUSTOM_OPS_YAML)
cmake_parse_arguments(GEN "" "${arg_names}" "" ${ARGN})
cmake_parse_arguments(GEN "${options}" "${arg_names}" "" ${ARGN})

message(STATUS "Generating kernel bindings:")
message(STATUS " LIB_NAME: ${GEN_LIB_NAME}")
message(STATUS " FUNCTIONS_YAML: ${GEN_FUNCTIONS_YAML}")
message(STATUS " CUSTOM_OPS_YAML: ${GEN_CUSTOM_OPS_YAML}")
message(STATUS " ADD_EXCEPTION_BOUNDARY: ${GEN_ADD_EXCEPTION_BOUNDARY}")

# Command to generate selected_operators.yaml from custom_ops.yaml.
file(GLOB_RECURSE _codegen_templates "${EXECUTORCH_ROOT}/codegen/templates/*")
Expand Down Expand Up @@ -93,7 +96,10 @@ function(generate_bindings_for_kernels)
--tags-path=${site-packages-out}/torchgen/packaged/ATen/native/tags.yaml
--aten-yaml-path=${site-packages-out}/torchgen/packaged/ATen/native/native_functions.yaml
--op-selection-yaml-path=${_oplist_yaml}
)
)
if(GEN_ADD_EXCEPTION_BOUNDARY)
set(_gen_command "${_gen_command}" --add-exception-boundary)
endif()

set(_gen_command_sources
${_out_dir}/RegisterCodegenUnboxedKernelsEverything.cpp
Expand Down
3 changes: 2 additions & 1 deletion configurations/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ if(EXECUTORCH_BUILD_KERNELS_OPTIMIZED)

generate_bindings_for_kernels(
LIB_NAME "optimized_native_cpu_ops_lib" FUNCTIONS_YAML
${CMAKE_CURRENT_BINARY_DIR}/merged.yaml
${CMAKE_CURRENT_BINARY_DIR}/merged.yaml ADD_EXCEPTION_BOUNDARY
)
message("Generated files ${gen_command_sources}")

Expand All @@ -56,6 +56,7 @@ if(EXECUTORCH_BUILD_KERNELS_OPTIMIZED)
DEPS
executorch
)
target_compile_options(optimized_native_cpu_ops_lib PRIVATE "-fexceptions")

install(TARGETS optimized_native_cpu_ops_lib DESTINATION lib)
endif()
3 changes: 3 additions & 0 deletions kernels/optimized/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ endif()

set(_common_compile_options -Wno-deprecated-declarations)

add_compile_options("-fexceptions")

# Note for apple platform we can rely on Accelerate framework Will come back to
# this
include(${CMAKE_CURRENT_LIST_DIR}/External/EigenBLAS.cmake)
Expand Down Expand Up @@ -55,6 +57,7 @@ gen_selected_ops(LIB_NAME "optimized_ops_lib" OPS_SCHEMA_YAML "${_yaml}")
generate_bindings_for_kernels(
LIB_NAME "optimized_ops_lib" FUNCTIONS_YAML
${CMAKE_CURRENT_SOURCE_DIR}/optimized-oss.yaml
ADD_EXCEPTION_BOUNDARY
)
message("Generated files ${gen_command_sources}")

Expand Down

0 comments on commit 99a8848

Please sign in to comment.