From 238d6f0059c5563afec7459912a9228b281fd7ea Mon Sep 17 00:00:00 2001 From: Scott Wolchok Date: Tue, 7 Jan 2025 10:07:33 -0800 Subject: [PATCH] Build optimized operators lib with -fexceptions 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? Differential Revision: [D67904052](https://our.internmc.facebook.com/intern/diff/D67904052/) [ghstack-poisoned] --- build/Codegen.cmake | 12 +++++++++--- configurations/CMakeLists.txt | 1 + kernels/optimized/CMakeLists.txt | 3 +++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/build/Codegen.cmake b/build/Codegen.cmake index 435b3d24802..abadadd444a 100644 --- a/build/Codegen.cmake +++ b/build/Codegen.cmake @@ -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_BOUNDARTY}") set(_oplist_yaml ${CMAKE_CURRENT_BINARY_DIR}/${GEN_LIB_NAME}/selected_operators.yaml @@ -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/*") @@ -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 diff --git a/configurations/CMakeLists.txt b/configurations/CMakeLists.txt index 9c618001964..e3845a1aa67 100644 --- a/configurations/CMakeLists.txt +++ b/configurations/CMakeLists.txt @@ -44,6 +44,7 @@ if(EXECUTORCH_BUILD_KERNELS_OPTIMIZED) LIB_NAME "optimized_native_cpu_ops_lib" FUNCTIONS_YAML ${CMAKE_CURRENT_BINARY_DIR}/merged.yaml ) + target_compile_options(optimized_native_cpu_ops_lib PRIVATE "-fexceptions") message("Generated files ${gen_command_sources}") # optimized_native_cpu_ops_lib: Register optimized op kernels into the runtime diff --git a/kernels/optimized/CMakeLists.txt b/kernels/optimized/CMakeLists.txt index abdeeb73453..34a869e4076 100644 --- a/kernels/optimized/CMakeLists.txt +++ b/kernels/optimized/CMakeLists.txt @@ -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) @@ -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}")