Skip to content

Commit 72814c1

Browse files
committed
[Executorch] Make apple take accelerate path for blas
Pull Request resolved: #6523 For some reason fbobjc_exported_preprocessor_flags does not seems to work. Thus taking 'select' route which seems to work. ghstack-source-id: 251185499 @exported-using-ghexport //oss lint broken on unrelated issue @bypass-github-export-checks @exported-using-ghexport Differential Revision: [D64499608](https://our.internmc.facebook.com/intern/diff/D64499608/)
1 parent bf7874f commit 72814c1

File tree

3 files changed

+50
-13
lines changed

3 files changed

+50
-13
lines changed

kernels/optimized/TARGETS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ load(":targets.bzl", "define_common_targets")
55

66
oncall("executorch")
77

8-
define_common_targets()
8+
define_common_targets(True)

kernels/optimized/lib_defs.bzl

Lines changed: 47 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,56 @@ def get_vec_fbcode_preprocessor_flags():
4343
]
4444
return preprocessor_flags
4545

46+
def get_apple_framework_deps_kwargs(is_fbcode):
47+
# various ovr_configs are not available in oss
48+
if not runtime.is_oss and not is_fbcode:
49+
# Jump through few hoops since 'frameworks' is not a valid kwarg
50+
# for some buck rules
51+
frameworks = {'frameworks': select({
52+
"DEFAULT": [],
53+
"ovr_config//os:iphoneos": ["$SDKROOT/System/Library/Frameworks/Accelerate.framework"],
54+
"ovr_config//os:macos-arm64": ["$SDKROOT/System/Library/Frameworks/Accelerate.framework"],
55+
"ovr_config//os:macos-x86_64": ["$SDKROOT/System/Library/Frameworks/Accelerate.framework"],
56+
})}
57+
return frameworks
58+
return {'fbobjc_frameworks': ["Accelerate"]}
59+
60+
def get_preprocessor_flags():
61+
# various ovr_configs are not available in oss
62+
preprocessor_flags = select({
63+
":linux-x86_64": [
64+
"-DET_BUILD_WITH_BLAS",
65+
] if not runtime.is_oss else [],
66+
"DEFAULT": [],
67+
})
68+
69+
if not runtime.is_oss:
70+
# various ovr_configs are not available in oss
71+
additional_preprocessor_flags = select({
72+
"ovr_config//os:iphoneos": [
73+
"-DET_BUILD_WITH_BLAS",
74+
"-DET_BUILD_FOR_APPLE",
75+
] if not runtime.is_oss else [],
76+
"ovr_config//os:macos-arm64": [
77+
"-DET_BUILD_WITH_BLAS",
78+
"-DET_BUILD_FOR_APPLE",
79+
] if not runtime.is_oss else [],
80+
"ovr_config//os:macos-x86_64": [
81+
"-DET_BUILD_WITH_BLAS",
82+
"-DET_BUILD_FOR_APPLE",
83+
] if not runtime.is_oss else [],
84+
"DEFAULT": [],
85+
})
86+
preprocessor_flags = preprocessor_flags + additional_preprocessor_flags
87+
return preprocessor_flags
88+
89+
4690
# Currently, having a dependency on fbsource//third-party/sleef:sleef may cause
4791
# duplicate symbol errors when linking fbcode targets in opt mode that also
4892
# depend on ATen. This is because ATen accesses sleef via the third-party folder
4993
# in caffe2 (caffe2/third-party//sleef:sleef).
5094
# TODO(ssjia): Enable -DCPU_CAPABILITY_AVX2 in fbcode, which requires sleef.
51-
def define_libs():
95+
def define_libs(is_fbcode=False):
5296
runtime.cxx_library(
5397
name = "libvec",
5498
srcs = [],
@@ -131,12 +175,7 @@ def define_libs():
131175
"//executorch/...",
132176
"@EXECUTORCH_CLIENTS",
133177
],
134-
preprocessor_flags = select({
135-
":linux-x86_64": [
136-
"-DET_BUILD_WITH_BLAS",
137-
] if not runtime.is_oss else [],
138-
"DEFAULT": [],
139-
}),
178+
preprocessor_flags = get_preprocessor_flags(),
140179
fbandroid_platform_preprocessor_flags = [
141180
(
142181
"^android-arm64.*$",
@@ -157,9 +196,6 @@ def define_libs():
157196
"-DET_BUILD_WITH_BLAS",
158197
"-DET_BUILD_FOR_APPLE",
159198
],
160-
fbobjc_frameworks = [
161-
"Accelerate",
162-
],
163199
deps = select({
164200
":linux-x86_64": [mkl_dep] if not runtime.is_oss else [],
165201
"DEFAULT": [],
@@ -169,4 +205,5 @@ def define_libs():
169205
"//executorch/kernels/optimized:libutils",
170206
"//executorch/runtime/core/exec_aten:lib",
171207
],
208+
**get_apple_framework_deps_kwargs(is_fbcode),
172209
)

kernels/optimized/targets.bzl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime")
22
load("@fbsource//xplat/executorch/codegen:codegen.bzl", "et_operator_library", "executorch_generated_lib")
33
load(":lib_defs.bzl", "define_libs")
44

5-
def define_common_targets():
5+
def define_common_targets(is_fbcode=False):
66
"""Defines targets that should be shared between fbcode and xplat.
77
88
The directory containing this targets.bzl file should also contain both
99
TARGETS and BUCK files that call this function.
1010
"""
1111

12-
define_libs()
12+
define_libs(is_fbcode)
1313

1414
runtime.export_file(
1515
name = "optimized.yaml",

0 commit comments

Comments
 (0)