Skip to content

Commit 5714d2e

Browse files
committed
Build optimized operators lib with -fexceptions
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: 260556841 @exported-using-ghexport Differential Revision: [D67904052](https://our.internmc.facebook.com/intern/diff/D67904052/)
1 parent 6477368 commit 5714d2e

File tree

4 files changed

+15
-5
lines changed

4 files changed

+15
-5
lines changed

.ci/docker/ci_commit_pins/pytorch.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2ea4b56ec872424e486c4fe2d55da061067a2ed3
1+
f0c50a619c282a01ef1ad33690b7ab5e615d9fef

build/Codegen.cmake

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@
1111
# arguments.
1212
function(gen_selected_ops)
1313
set(arg_names LIB_NAME OPS_SCHEMA_YAML ROOT_OPS INCLUDE_ALL_OPS)
14-
cmake_parse_arguments(GEN "" "" "${arg_names}" ${ARGN})
14+
cmake_parse_arguments(GEN "${options}" "" "${arg_names}" ${ARGN})
1515

1616
message(STATUS "Generating operator lib:")
1717
message(STATUS " LIB_NAME: ${GEN_LIB_NAME}")
1818
message(STATUS " OPS_SCHEMA_YAML: ${GEN_OPS_SCHEMA_YAML}")
1919
message(STATUS " ROOT_OPS: ${GEN_ROOT_OPS}")
2020
message(STATUS " INCLUDE_ALL_OPS: ${GEN_INCLUDE_ALL_OPS}")
21+
message(STATUS " ADD_EXCEPTION_BOUNDARY: ${GEN_ADD_EXCEPTION_BOUNDARTY}")
2122

2223
set(_oplist_yaml
2324
${CMAKE_CURRENT_BINARY_DIR}/${GEN_LIB_NAME}/selected_operators.yaml
@@ -59,13 +60,15 @@ endfunction()
5960
# Invoked as generate_bindings_for_kernels( LIB_NAME lib_name FUNCTIONS_YAML
6061
# functions_yaml CUSTOM_OPS_YAML custom_ops_yaml )
6162
function(generate_bindings_for_kernels)
63+
set(options ADD_EXCEPTION_BOUNDARY)
6264
set(arg_names LIB_NAME FUNCTIONS_YAML CUSTOM_OPS_YAML)
63-
cmake_parse_arguments(GEN "" "${arg_names}" "" ${ARGN})
65+
cmake_parse_arguments(GEN "${options}" "${arg_names}" "" ${ARGN})
6466

6567
message(STATUS "Generating kernel bindings:")
6668
message(STATUS " LIB_NAME: ${GEN_LIB_NAME}")
6769
message(STATUS " FUNCTIONS_YAML: ${GEN_FUNCTIONS_YAML}")
6870
message(STATUS " CUSTOM_OPS_YAML: ${GEN_CUSTOM_OPS_YAML}")
71+
message(STATUS " ADD_EXCEPTION_BOUNDARY: ${GEN_ADD_EXCEPTION_BOUNDARY}")
6972

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

98104
set(_gen_command_sources
99105
${_out_dir}/RegisterCodegenUnboxedKernelsEverything.cpp

configurations/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ if(EXECUTORCH_BUILD_KERNELS_OPTIMIZED)
4242

4343
generate_bindings_for_kernels(
4444
LIB_NAME "optimized_native_cpu_ops_lib" FUNCTIONS_YAML
45-
${CMAKE_CURRENT_BINARY_DIR}/merged.yaml
45+
${CMAKE_CURRENT_BINARY_DIR}/merged.yaml ADD_EXCEPTION_BOUNDARY
4646
)
4747
message("Generated files ${gen_command_sources}")
4848

@@ -56,6 +56,7 @@ if(EXECUTORCH_BUILD_KERNELS_OPTIMIZED)
5656
DEPS
5757
executorch
5858
)
59+
target_compile_options(optimized_native_cpu_ops_lib PRIVATE "-fexceptions")
5960

6061
install(TARGETS optimized_native_cpu_ops_lib DESTINATION lib)
6162
endif()

kernels/optimized/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ endif()
2323

2424
set(_common_compile_options -Wno-deprecated-declarations)
2525

26+
add_compile_options("-fexceptions")
27+
2628
# Note for apple platform we can rely on Accelerate framework Will come back to
2729
# this
2830
include(${CMAKE_CURRENT_LIST_DIR}/External/EigenBLAS.cmake)
@@ -55,6 +57,7 @@ gen_selected_ops(LIB_NAME "optimized_ops_lib" OPS_SCHEMA_YAML "${_yaml}")
5557
generate_bindings_for_kernels(
5658
LIB_NAME "optimized_ops_lib" FUNCTIONS_YAML
5759
${CMAKE_CURRENT_SOURCE_DIR}/optimized-oss.yaml
60+
ADD_EXCEPTION_BOUNDARY
5861
)
5962
message("Generated files ${gen_command_sources}")
6063

0 commit comments

Comments
 (0)