Skip to content

Commit 5c2e66d

Browse files
Re-sync with internal repository (#2)
Co-authored-by: Facebook Community Bot <[email protected]>
1 parent 8a5d102 commit 5c2e66d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+6352
-0
lines changed

backends/backends.bzl

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
def get_all_cpu_backend_targets():
2+
"""Returns a list of all CPU backend targets.
3+
4+
For experimenting and testing, not for production, since it will typically
5+
include more than necessary for a particular product.
6+
"""
7+
return [
8+
"//executorch/backends/xnnpack:xnnpack_backend",
9+
"//executorch/backends/qnnpack:qnnpack_backend",
10+
]
11+
12+
def get_all_cpu_aot_and_backend_targets():
13+
"""Returns a list of all CPU backend targets with aot (ahead of time).
14+
15+
For experimenting and testing, not for production, since it will typically
16+
include more than necessary for a particular product.
17+
"""
18+
return [
19+
"//executorch/backends/xnnpack:xnnpack_preprocess",
20+
"//executorch/backends/xnnpack/partition:xnnpack_partitioner",
21+
"//executorch/backends/qnnpack:qnnpack_preprocess",
22+
"//executorch/backends/qnnpack/partition:qnnpack_partitioner",
23+
] + get_all_cpu_backend_targets()

backends/qnnpack/targets.bzl

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
load(
2+
"@fbsource//tools/build_defs:default_platform_defs.bzl",
3+
"ANDROID",
4+
"APPLE",
5+
"CXX",
6+
)
7+
load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime")
8+
9+
def define_common_targets():
10+
runtime.genrule(
11+
name = "gen_qnnpack_schema",
12+
srcs = [
13+
"serialization/schema.fbs",
14+
],
15+
# We're only generating a single file, so it seems like we could use
16+
# `out`, but `flatc` takes a directory as a parameter, not a single
17+
# file. Use `outs` so that `${OUT}` is expanded as the containing
18+
# directory instead of the file itself.
19+
outs = {
20+
"qnnpack_schema_generated.h": ["schema_generated.h"],
21+
},
22+
cmd = " ".join([
23+
"$(exe fbsource//third-party/flatbuffers/fbsource_namespace:flatc)",
24+
"--cpp",
25+
"--cpp-std c++11",
26+
"--scoped-enums",
27+
"-o ${OUT}",
28+
"${SRCS}",
29+
]),
30+
default_outs = ["."],
31+
)
32+
33+
runtime.cxx_library(
34+
name = "qnnpack_schema",
35+
srcs = [],
36+
exported_headers = {
37+
"qnnpack_schema_generated.h": ":gen_qnnpack_schema[qnnpack_schema_generated.h]",
38+
},
39+
exported_deps = [
40+
"fbsource//third-party/flatbuffers/fbsource_namespace:flatbuffers-api",
41+
],
42+
)
43+
44+
for aten_mode in (True, False):
45+
aten_suffix = "_aten" if aten_mode else ""
46+
runtime.cxx_library(
47+
name = "qnnpack_utils" + aten_suffix,
48+
srcs = [
49+
"utils/utils.cpp",
50+
],
51+
exported_headers = ["utils/utils.h"],
52+
deps = [
53+
"//executorch/core/kernel_types:kernel_types" + aten_suffix,
54+
"//executorch/backends:backend",
55+
],
56+
visibility = [
57+
"//executorch/backends/qnnpack/test/...",
58+
"//executorch/backends/xnnpack/...",
59+
"@EXECUTORCH_CLIENTS",
60+
],
61+
)
62+
63+
runtime.cxx_library(
64+
name = "qnnpack_backend",
65+
srcs = [
66+
"QNNPackBackend.cpp",
67+
],
68+
headers = [
69+
"executor/QNNExecutor.h",
70+
],
71+
resources = [
72+
"serialization/schema.fbs",
73+
],
74+
visibility = [
75+
"//executorch/backends:backend_lib",
76+
"//executorch/backends/qnnpack/test/...",
77+
"//executorch/backends/test/...",
78+
"//executorch/pybindings/...",
79+
"@EXECUTORCH_CLIENTS",
80+
],
81+
deps = [
82+
"//executorch/core/kernel_types/util:scalar_type_util",
83+
"//executorch/core/kernel_types/util:tensor_util",
84+
"//executorch/backends:backend",
85+
"//executorch/threadpool:threadpool",
86+
"//executorch/util:memory_utils",
87+
":qnnpack_schema",
88+
":qnnpack_utils",
89+
],
90+
platforms = [
91+
ANDROID,
92+
APPLE,
93+
CXX,
94+
],
95+
fbcode_deps = [
96+
"//caffe2/aten/src/ATen/native/quantized/cpu/qnnpack:pytorch_qnnpack",
97+
],
98+
xplat_deps = [
99+
"//xplat/caffe2/aten/src/ATen/native/quantized/cpu/qnnpack:pytorch_qnnpack",
100+
],
101+
# XnnpackBackend.cpp needs to compile with executor as whole
102+
# @lint-ignore BUCKLINT: Avoid `link_whole=True` (https://fburl.com/avoid-link-whole)
103+
link_whole = True,
104+
)

backends/qnnpack/test/targets.bzl

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
load(
2+
"@fbsource//tools/build_defs:default_platform_defs.bzl",
3+
"ANDROID",
4+
"APPLE",
5+
"CXX",
6+
)
7+
load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime")
8+
9+
def define_common_targets():
10+
runtime.cxx_test(
11+
name = "qnnpack_utils_test",
12+
srcs = ["test_utils.cpp"],
13+
fbcode_deps = [
14+
"//caffe2:ATen-cpu",
15+
],
16+
xplat_deps = [
17+
"//caffe2:aten_cpu",
18+
],
19+
platforms = [ANDROID, APPLE, CXX],
20+
deps = [
21+
"//executorch/core/kernel_types/testing:tensor_util",
22+
"//executorch/core/kernel_types/util:scalar_type_util",
23+
"//executorch/util:aten_bridge",
24+
"//executorch/backends/qnnpack:qnnpack_utils",
25+
],
26+
)

backends/targets.bzl

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime")
2+
3+
def define_common_targets():
4+
"""Defines targets that should be shared between fbcode and xplat.
5+
6+
The directory containing this targets.bzl file should also contain both
7+
TARGETS and BUCK files that call this function.
8+
"""
9+
10+
for aten_mode in (True, False):
11+
aten_suffix = ("_aten" if aten_mode else "")
12+
runtime.cxx_library(
13+
name = "backend" + aten_suffix,
14+
srcs = [
15+
"backend.cpp",
16+
],
17+
exported_headers = [
18+
"backend.h",
19+
],
20+
preprocessor_flags = ["-DUSE_ATEN_LIB"] if aten_mode else [],
21+
visibility = [
22+
"//executorch/...",
23+
"//executorch/test/...",
24+
"@EXECUTORCH_CLIENTS",
25+
],
26+
exported_deps = [
27+
"//executorch/core:core",
28+
"//executorch/core/values:executor_values" + aten_suffix,
29+
"//executorch/core:freeable_buffer",
30+
"//executorch/executor:memory_manager",
31+
"//executorch/profiler:profiler",
32+
],
33+
)

backends/test/demos/rpc/targets.bzl

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
load(
2+
"@fbsource//tools/build_defs:default_platform_defs.bzl",
3+
"ANDROID",
4+
"CXX",
5+
)
6+
load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime")
7+
load("@fbsource//xplat/executorch/pybindings:targets.bzl", "MODELS_ALL_OPS_LEAN_MODE_GENERATED_LIB")
8+
9+
def define_common_targets():
10+
"""Defines targets that should be shared between fbcode and xplat.
11+
12+
The directory containing this targets.bzl file should also contain both
13+
TARGETS and BUCK files that call this function.
14+
"""
15+
16+
runtime.cxx_library(
17+
name = "executor_backend",
18+
srcs = [
19+
"ExecutorBackend.cpp",
20+
],
21+
exported_headers = [
22+
"ExecutorBackend.h",
23+
],
24+
platforms = [ANDROID, CXX],
25+
deps = [
26+
"//executorch/executor:executor",
27+
"//executorch/kernels/portable:generated_lib",
28+
"//executorch/backends:backend",
29+
"//executorch/util:embedded_data_loader",
30+
"//executorch/util:util",
31+
] + MODELS_ALL_OPS_LEAN_MODE_GENERATED_LIB,
32+
exported_deps = [
33+
"//executorch/core:core",
34+
],
35+
)
36+
37+
runtime.cxx_library(
38+
name = "executor_backend_register",
39+
srcs = [
40+
"ExecutorBackendRegister.cpp",
41+
],
42+
deps = [
43+
":executor_backend",
44+
"//executorch/backends:backend",
45+
"//executorch/core:core",
46+
],
47+
platforms = [ANDROID, CXX],
48+
)

backends/xnnpack/targets.bzl

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime")
2+
3+
def define_common_targets():
4+
runtime.genrule(
5+
name = "gen_xnnpack_schema",
6+
srcs = [
7+
"serialization/schema.fbs",
8+
],
9+
# We're only generating a single file, so it seems like we could use
10+
# `out`, but `flatc` takes a directory as a parameter, not a single
11+
# file. Use `outs` so that `${OUT}` is expanded as the containing
12+
# directory instead of the file itself.
13+
outs = {
14+
"xnnpack_schema_generated.h": ["schema_generated.h"],
15+
},
16+
cmd = " ".join([
17+
"$(exe fbsource//third-party/flatbuffers/fbsource_namespace:flatc)",
18+
"--cpp",
19+
"--cpp-std c++11",
20+
"--scoped-enums",
21+
"-o ${OUT}",
22+
"${SRCS}",
23+
]),
24+
default_outs = ["."],
25+
)
26+
27+
runtime.cxx_library(
28+
name = "xnnpack_schema",
29+
srcs = [],
30+
exported_headers = {
31+
"xnnpack_schema_generated.h": ":gen_xnnpack_schema[xnnpack_schema_generated.h]",
32+
},
33+
exported_deps = [
34+
"fbsource//third-party/flatbuffers/fbsource_namespace:flatbuffers-api",
35+
],
36+
)
37+
38+
runtime.cxx_library(
39+
name = "xnnpack_backend",
40+
srcs = native.glob([
41+
"runtime/*.cpp",
42+
]),
43+
headers = native.glob([
44+
"runtime/*.h",
45+
]),
46+
visibility = [
47+
"//executorch/backends:backend_lib",
48+
"//executorch/backends/test/...",
49+
"//executorch/backends/xnnpack/test/...",
50+
"//executorch/pybindings/...",
51+
"@EXECUTORCH_CLIENTS",
52+
],
53+
deps = [
54+
"//xplat/third-party/XNNPACK:XNNPACK",
55+
":xnnpack_schema",
56+
"//executorch/backends:backend",
57+
"//executorch/backends/qnnpack:qnnpack_utils", # TODO Use (1) portable for choose_qparams(), (2) xnnpack for quantize_per_tensor()
58+
"//executorch/threadpool:threadpool",
59+
"//executorch/util:memory_utils",
60+
"//executorch/core/kernel_types/util:tensor_util",
61+
],
62+
# XnnpackBackend.cpp needs to compile with executor as whole
63+
# @lint-ignore BUCKLINT: Avoid `link_whole=True` (https://fburl.com/avoid-link-whole)
64+
link_whole = True,
65+
)

0 commit comments

Comments
 (0)