Skip to content

Commit 7d0e954

Browse files
pytorchbotswolchok
andauthored
Switch fbcode builds of ExecuTorch and PyTorch to fbsource sleef (#11352)
This PR was created by the merge bot to help merge the original PR into the main branch. ghstack PR number: #11261 by @swolchok ^ Please use this as the source of truth for the PR details, comments, and reviews ghstack PR base: https://github.com/pytorch/executorch/tree/gh/swolchok/442/base ghstack PR head: https://github.com/pytorch/executorch/tree/gh/swolchok/442/head Merge bot PR base: https://github.com/pytorch/executorch/tree/main Merge bot PR head: https://github.com/pytorch/executorch/tree/gh/swolchok/442/orig @diff-train-skip-merge Co-authored-by: Scott Wolchok <swolchok@meta.com>
1 parent ca39d86 commit 7d0e954

File tree

3 files changed

+62
-42
lines changed

3 files changed

+62
-42
lines changed

kernels/optimized/lib_defs.bzl

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,6 @@ def get_preprocessor_flags():
111111
return preprocessor_flags
112112

113113

114-
# Currently, having a dependency on fbsource//third-party/sleef:sleef may cause
115-
# duplicate symbol errors when linking fbcode targets in opt mode that also
116-
# depend on ATen. This is because ATen accesses sleef via the third-party folder
117-
# in caffe2 (caffe2/third-party//sleef:sleef).
118114
# TODO(ssjia): Enable -DCPU_CAPABILITY_AVX2 in fbcode, which requires sleef.
119115
def define_libs(is_fbcode=False):
120116
runtime.cxx_library(

runtime/core/portable_type/c10/c10/targets.bzl

Lines changed: 56 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,47 @@
11
load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime", "is_arvr_mode")
22

3-
def get_sleef_preprocessor_flags():
3+
def get_preprocessor_flags(is_fbcode):
4+
flags = ["-DSTANDALONE_TORCH_HEADER"]
45
if runtime.is_oss:
5-
return []
6-
return ["-DAT_BUILD_ARM_VEC256_WITH_SLEEF"]
6+
return flags
7+
arm64_flags = [
8+
"-DCPU_CAPABILITY_DEFAULT",
9+
]
10+
if is_fbcode:
11+
# TODO: enable Sleef in xplat?
12+
arm64_flags = arm64_flags + ["-DAT_BUILD_ARM_VEC256_WITH_SLEEF"]
13+
14+
x86_avx2_flags = [
15+
"-DCPU_CAPABILITY_AVX2",
16+
"-DHAVE_AVX2_CPU_DEFINITION",
17+
]
18+
default_flags = [
19+
"-DCPU_CAPABILITY_DEFAULT",
20+
]
21+
fbcode_flags = select({
22+
"ovr_config//cpu:x86_64": x86_avx2_flags,
23+
"ovr_config//cpu:arm64": arm64_flags,
24+
"DEFAULT": default_flags,
25+
})
26+
non_fbcode_flags = select({
27+
"ovr_config//cpu/x86:avx2": x86_avx2_flags,
28+
"ovr_config//cpu:arm64": arm64_flags,
29+
"DEFAULT": default_flags,
30+
})
31+
return flags + ["-DET_USE_PYTORCH_HEADERS"] + (fbcode_flags if is_fbcode else non_fbcode_flags)
732

33+
def get_sleef_deps():
34+
if runtime.is_oss:
35+
return []
36+
return select({
37+
"DEFAULT": [],
38+
"ovr_config//cpu:x86_64": [
39+
"fbsource//third-party/sleef:sleef",
40+
],
41+
"ovr_config//cpu:arm64": [
42+
"fbsource//third-party/sleef:sleef",
43+
],
44+
})
845

946
def define_common_targets():
1047
"""Defines targets that should be shared between fbcode and xplat.
@@ -54,42 +91,30 @@ def define_common_targets():
5491
name = "aten_headers_for_executorch",
5592
srcs = [],
5693
visibility = ["//executorch/kernels/optimized/...", "@EXECUTORCH_CLIENTS"],
94+
# select() on ovr_config//runtime:fbcode does not work
95+
# properly in all cases. I have seen
96+
# //xplat/executorch/runtime/core/portable_type/c10/c10:aten_headers_for_executorch
97+
# pass such a select in (at least) arvr mode. Going back to
98+
# fbcode_exported_deps accordingly.
5799
exported_deps = select({
58100
"DEFAULT": [],
59101
"ovr_config//cpu:arm64": [
60102
"fbsource//third-party/sleef:sleef",
61103
] if not runtime.is_oss else [],
62-
# fbsource//third-party/sleef:sleef currently fails to
63-
# link with missing symbols, hence the fbcode-specific dep below.
64104
}),
105+
xplat_exported_deps = [
106+
"//xplat/caffe2:aten_header",
107+
"//xplat/caffe2/c10:c10_headers",
108+
("//xplat/caffe2:ovrsource_aten_Config.h"
109+
if is_arvr_mode() else "//xplat/caffe2:generated_aten_config_header"),
110+
], # + get_sleef_deps(), # TODO: enable Sleef in xplat?
65111
fbcode_exported_deps = ([
66112
"//caffe2:aten-headers-cpu",
67113
"//caffe2:generated-config-header",
68114
"//caffe2/c10:c10_headers",
69-
] + select({
70-
"DEFAULT": [],
71-
"ovr_config//cpu:x86_64": [
72-
"third-party//sleef:sleef",
73-
]
74-
})) if not runtime.is_oss else [],
75-
fbcode_exported_preprocessor_flags = [
76-
# We don't -DCPU_CAPABILITY=AVX2 because that trips
77-
# -Wmacro-redefined, and we only care about getting
78-
# reasonable vectorization and Sleef support.
79-
"-DCPU_CAPABILITY_AVX2",
80-
"-DET_USE_PYTORCH_HEADERS",
81-
"-DHAVE_AVX2_CPU_DEFINITION",
82-
"-DSTANDALONE_TORCH_HEADER",
83-
] + get_sleef_preprocessor_flags(),
84-
xplat_exported_deps = [
85-
"//xplat/caffe2:aten_header",
86-
"//xplat/caffe2/c10:c10_headers",
87-
] + ["//xplat/caffe2:ovrsource_aten_Config.h" if is_arvr_mode() else "//xplat/caffe2:generated_aten_config_header",],
88-
exported_preprocessor_flags = select({
89-
# Intentionally punting on non-fbcode x86 sleef support
90-
# for now because of fbsource//third-party/sleef:sleef
91-
# linker failure.
92-
"ovr_config//cpu:arm64": get_sleef_preprocessor_flags(),
93-
"DEFAULT": [],
94-
}) + ["-DSTANDALONE_TORCH_HEADER"] + ([] if runtime.is_oss else ["-DET_USE_PYTORCH_HEADERS"]),
115+
] + get_sleef_deps()) if not runtime.is_oss else [],
116+
exported_preprocessor_flags = get_preprocessor_flags(is_fbcode=False)
117+
+ ([] if runtime.is_oss else ["-DET_USE_PYTORCH_HEADERS"]),
118+
fbcode_exported_preprocessor_flags = get_preprocessor_flags(is_fbcode=True)
119+
+ ([] if runtime.is_oss else ["-DET_USE_PYTORCH_HEADERS"]),
95120
)

shim_et/xplat/executorch/kernels/optimized/lib_defs.bzl

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,14 @@ def get_vec_cxx_preprocessor_flags():
6969
return preprocessor_flags
7070

7171
def get_vec_fbcode_preprocessor_flags():
72-
preprocessor_flags = [
73-
"-DCPU_CAPABILITY_AVX2",
74-
]
72+
preprocessor_flags = select({
73+
"ovr_config//cpu/x86:avx2": [
74+
"-DCPU_CAPABILITY_AVX2",
75+
],
76+
"DEFAULT": [],
77+
})
7578
return preprocessor_flags
7679

77-
# Currently, having a dependency on fbsource//third-party/sleef:sleef may cause
78-
# duplicate symbol errors when linking fbcode targets in opt mode that also
79-
# depend on ATen. This is because ATen accesses sleef via the third-party folder
80-
# in caffe2 (caffe2/third-party//sleef:sleef).
8180
# TODO(ssjia): Enable -DCPU_CAPABILITY_AVX2 in fbcode, which requires sleef.
8281
def define_libs():
8382
runtime.cxx_library(

0 commit comments

Comments
 (0)