Skip to content

Commit 70e8201

Browse files
committed
Update on "[Executorch][llm] Compile custom op with -O2"
This enable some optimizations for inlining vectorized lib functions Differential Revision: [D64910576](https://our.internmc.facebook.com/intern/diff/D64910576/) [ghstack-poisoned]
2 parents 82a344e + d7b7aef commit 70e8201

File tree

3 files changed

+26
-45
lines changed

3 files changed

+26
-45
lines changed

extension/llm/custom_ops/targets.bzl

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime")
2+
load(
3+
"@fbsource//xplat/executorch/kernels/portable:op_registration_util.bzl",
4+
"get_compiler_optimization_flags",
5+
)
6+
27

38
def define_common_targets():
49
"""Defines targets that should be shared between fbcode and xplat.
@@ -34,21 +39,7 @@ def define_common_targets():
3439
"//executorch/kernels/portable/cpu/util:reduce_util",
3540
"//executorch/extension/llm/custom_ops/spinquant:fast_hadamard_transform",
3641
],
37-
compiler_flags = ["-Wno-missing-prototypes", "-Wno-global-constructors"] + select({
38-
"DEFAULT": [],
39-
"ovr_config//os:android-arm64": [
40-
"-O2",
41-
] if not runtime.is_oss else [],
42-
"ovr_config//os:iphoneos": [
43-
"-O2",
44-
] if not runtime.is_oss else [],
45-
"ovr_config//os:macos-arm64": [
46-
"-O2",
47-
] if not runtime.is_oss else [],
48-
"ovr_config//os:macos-x86_64": [
49-
"-O2",
50-
] if not runtime.is_oss else [],
51-
}),
42+
compiler_flags = ["-Wno-missing-prototypes", "-Wno-global-constructors"] + get_compiler_optimization_flags(),
5243
visibility = [
5344
"//executorch/...",
5445
"//executorch/extension/llm/custom_ops/...",

kernels/optimized/lib_defs.bzl

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,23 @@ def get_vec_fbcode_preprocessor_flags():
3939
]
4040
return preprocessor_flags
4141

42+
def get_compiler_optimization_flags():
43+
if not runtime.is_oss:
44+
compiler_flags = select({
45+
"DEFAULT": [],
46+
"ovr_config//os:android-arm64": [
47+
"-O2",
48+
],
49+
"ovr_config//os:iphoneos": [
50+
"-O2",
51+
],
52+
"ovr_config//os:macos-arm64": [
53+
"-O2",
54+
],
55+
})
56+
return compiler_flags
57+
return []
58+
4259
# Currently, having a dependency on fbsource//third-party/sleef:sleef may cause
4360
# duplicate symbol errors when linking fbcode targets in opt mode that also
4461
# depend on ATen. This is because ATen accesses sleef via the third-party folder
@@ -121,21 +138,7 @@ def define_libs():
121138
exported_headers = native.glob([
122139
"blas/**/*.h",
123140
]),
124-
compiler_flags = select({
125-
"DEFAULT": [],
126-
"ovr_config//os:android-arm64": [
127-
"-O2",
128-
] if not runtime.is_oss else [],
129-
"ovr_config//os:iphoneos": [
130-
"-O2",
131-
] if not runtime.is_oss else [],
132-
"ovr_config//os:macos-arm64": [
133-
"-O2",
134-
] if not runtime.is_oss else [],
135-
"ovr_config//os:macos-x86_64": [
136-
"-O2",
137-
] if not runtime.is_oss else [],
138-
}),
141+
compiler_flags = get_compiler_optimization_flags(),
139142
header_namespace = "executorch/kernels/optimized",
140143
visibility = [
141144
"//executorch/...",

kernels/optimized/op_registration_util.bzl

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ load("@fbsource//xplat/executorch/build:selects.bzl", "selects")
33
load(
44
"@fbsource//xplat/executorch/kernels/optimized:lib_defs.bzl",
55
"get_vec_android_preprocessor_flags",
6+
"get_compiler_optimization_flags",
67
)
78

89
def op_target(name, deps = []):
@@ -87,21 +88,7 @@ def define_op_library(name, deps):
8788
],
8889
# kernels often have helpers with no prototypes just disabling the warning here as the headers
8990
# are codegend and linked in later
90-
compiler_flags = ["-Wno-missing-prototypes"] + select({
91-
"DEFAULT": [],
92-
"ovr_config//os:android": [
93-
"-O2",
94-
] if not runtime.is_oss else [],
95-
"ovr_config//os:iphoneos": [
96-
"-O2",
97-
] if not runtime.is_oss else [],
98-
"ovr_config//os:macos-arm64": [
99-
"-O2",
100-
] if not runtime.is_oss else [],
101-
"ovr_config//os:macos-x86_64": [
102-
"-O2",
103-
] if not runtime.is_oss else [],
104-
}),
91+
compiler_flags = ["-Wno-missing-prototypes"] + get_compiler_optimization_flags(),
10592
deps = [
10693
"//executorch/runtime/kernel:kernel_includes",
10794
] + augmented_deps,

0 commit comments

Comments
 (0)