Skip to content

Commit a508d54

Browse files
committed
Update on "Reuse GELU implementation from PyTorch core"
kernels/optimized doesn't need to support embedded systems, so it can just take a header-only dep on PyTorch. Note that, because we will pick up Sleef internally and ignore it externally thanks to ATen vec, this PR gets to enable optimized GELU in OSS. Testing: CI to make sure this doesn't break mobile build modes; happy to take advice on anything not currently covered that might break. Differential Revision: [D66335522](https://our.internmc.facebook.com/intern/diff/D66335522/) [ghstack-poisoned]
2 parents 747bc96 + 6057a4b commit a508d54

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ if(EXECUTORCH_BUILD_KERNELS_OPTIMIZED)
4444
LIB_NAME "optimized_native_cpu_ops_lib" FUNCTIONS_YAML
4545
${CMAKE_CURRENT_BINARY_DIR}/merged.yaml
4646
)
47+
target_compile_options(optimized_native_cpu_ops_lib PRIVATE "-fexceptions")
4748
message("Generated files ${gen_command_sources}")
4849

4950
# optimized_native_cpu_ops_lib: Register optimized op kernels into the runtime

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)