Skip to content

Commit 2252f06

Browse files
authored
[Executorch][Kernels] Build optimized lib with -O2
Differential Revision: D64910575 Pull Request resolved: #6517
1 parent ed258c2 commit 2252f06

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

kernels/optimized/lib_defs.bzl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ load("@fbsource//tools/build_defs:default_platform_defs.bzl", "DEVSERVER_PLATFOR
22
load("@fbsource//tools/build_defs:fb_native_wrapper.bzl", "fb_native")
33
load("@fbsource//xplat/executorch/backends/xnnpack/third-party:third_party_libs.bzl", "third_party_dep")
44
load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime")
5+
load(
6+
"@fbsource//xplat/executorch/kernels/portable:op_registration_util.bzl",
7+
"get_compiler_optimization_flags",
8+
)
59

610
# Because vec exists as a collection of header files, compile and preprocessor
711
# flags applied to the vec target do not have any effect, since no compilation
@@ -121,6 +125,7 @@ def define_libs():
121125
exported_headers = native.glob([
122126
"blas/**/*.h",
123127
]),
128+
compiler_flags = get_compiler_optimization_flags(),
124129
header_namespace = "executorch/kernels/optimized",
125130
visibility = [
126131
"//executorch/...",

kernels/optimized/op_registration_util.bzl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ load(
44
"@fbsource//xplat/executorch/kernels/optimized:lib_defs.bzl",
55
"get_vec_android_preprocessor_flags",
66
)
7+
load(
8+
"@fbsource//xplat/executorch/kernels/portable:op_registration_util.bzl",
9+
"get_compiler_optimization_flags",
10+
)
711

812
def op_target(name, deps = []):
913
"""Registers an optimized implementation for an operator overload group.
@@ -87,7 +91,7 @@ def define_op_library(name, deps):
8791
],
8892
# kernels often have helpers with no prototypes just disabling the warning here as the headers
8993
# are codegend and linked in later
90-
compiler_flags = ["-Wno-missing-prototypes"],
94+
compiler_flags = ["-Wno-missing-prototypes"] + get_compiler_optimization_flags(),
9195
deps = [
9296
"//executorch/runtime/kernel:kernel_includes",
9397
] + augmented_deps,

shim/xplat/executorch/kernels/portable/op_registration_util.bzl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,24 @@
11
load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "is_xplat", "runtime")
22
load("@fbsource//xplat/executorch/build:selects.bzl", "selects")
33

4+
def get_compiler_optimization_flags():
5+
# various ovr_configs are not available in oss
6+
if not runtime.is_oss:
7+
compiler_flags = select({
8+
"DEFAULT": [],
9+
"ovr_config//os:android-arm64": [
10+
"-O2",
11+
],
12+
"ovr_config//os:iphoneos": [
13+
"-O2",
14+
],
15+
"ovr_config//os:macos-arm64": [
16+
"-O2",
17+
],
18+
})
19+
return compiler_flags
20+
return []
21+
422
def op_target(name, deps = [], android_deps = [], _allow_third_party_deps = False, _aten_mode_deps = []):
523
"""Registers an implementation of an operator overload group.
624

0 commit comments

Comments
 (0)