Skip to content

Re-sync with internal repository #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions backends/backends.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
def get_all_cpu_backend_targets():
"""Returns a list of all CPU backend targets.

For experimenting and testing, not for production, since it will typically
include more than necessary for a particular product.
"""
return [
"//executorch/backends/xnnpack:xnnpack_backend",
"//executorch/backends/qnnpack:qnnpack_backend",
]

def get_all_cpu_aot_and_backend_targets():
"""Returns a list of all CPU backend targets with aot (ahead of time).

For experimenting and testing, not for production, since it will typically
include more than necessary for a particular product.
"""
return [
"//executorch/backends/xnnpack:xnnpack_preprocess",
"//executorch/backends/xnnpack/partition:xnnpack_partitioner",
"//executorch/backends/qnnpack:qnnpack_preprocess",
"//executorch/backends/qnnpack/partition:qnnpack_partitioner",
] + get_all_cpu_backend_targets()
104 changes: 104 additions & 0 deletions backends/qnnpack/targets.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
load(
"@fbsource//tools/build_defs:default_platform_defs.bzl",
"ANDROID",
"APPLE",
"CXX",
)
load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime")

def define_common_targets():
runtime.genrule(
name = "gen_qnnpack_schema",
srcs = [
"serialization/schema.fbs",
],
# We're only generating a single file, so it seems like we could use
# `out`, but `flatc` takes a directory as a parameter, not a single
# file. Use `outs` so that `${OUT}` is expanded as the containing
# directory instead of the file itself.
outs = {
"qnnpack_schema_generated.h": ["schema_generated.h"],
},
cmd = " ".join([
"$(exe fbsource//third-party/flatbuffers/fbsource_namespace:flatc)",
"--cpp",
"--cpp-std c++11",
"--scoped-enums",
"-o ${OUT}",
"${SRCS}",
]),
default_outs = ["."],
)

runtime.cxx_library(
name = "qnnpack_schema",
srcs = [],
exported_headers = {
"qnnpack_schema_generated.h": ":gen_qnnpack_schema[qnnpack_schema_generated.h]",
},
exported_deps = [
"fbsource//third-party/flatbuffers/fbsource_namespace:flatbuffers-api",
],
)

for aten_mode in (True, False):
aten_suffix = "_aten" if aten_mode else ""
runtime.cxx_library(
name = "qnnpack_utils" + aten_suffix,
srcs = [
"utils/utils.cpp",
],
exported_headers = ["utils/utils.h"],
deps = [
"//executorch/core/kernel_types:kernel_types" + aten_suffix,
"//executorch/backends:backend",
],
visibility = [
"//executorch/backends/qnnpack/test/...",
"//executorch/backends/xnnpack/...",
"@EXECUTORCH_CLIENTS",
],
)

runtime.cxx_library(
name = "qnnpack_backend",
srcs = [
"QNNPackBackend.cpp",
],
headers = [
"executor/QNNExecutor.h",
],
resources = [
"serialization/schema.fbs",
],
visibility = [
"//executorch/backends:backend_lib",
"//executorch/backends/qnnpack/test/...",
"//executorch/backends/test/...",
"//executorch/pybindings/...",
"@EXECUTORCH_CLIENTS",
],
deps = [
"//executorch/core/kernel_types/util:scalar_type_util",
"//executorch/core/kernel_types/util:tensor_util",
"//executorch/backends:backend",
"//executorch/threadpool:threadpool",
"//executorch/util:memory_utils",
":qnnpack_schema",
":qnnpack_utils",
],
platforms = [
ANDROID,
APPLE,
CXX,
],
fbcode_deps = [
"//caffe2/aten/src/ATen/native/quantized/cpu/qnnpack:pytorch_qnnpack",
],
xplat_deps = [
"//xplat/caffe2/aten/src/ATen/native/quantized/cpu/qnnpack:pytorch_qnnpack",
],
# XnnpackBackend.cpp needs to compile with executor as whole
# @lint-ignore BUCKLINT: Avoid `link_whole=True` (https://fburl.com/avoid-link-whole)
link_whole = True,
)
26 changes: 26 additions & 0 deletions backends/qnnpack/test/targets.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
load(
"@fbsource//tools/build_defs:default_platform_defs.bzl",
"ANDROID",
"APPLE",
"CXX",
)
load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime")

def define_common_targets():
runtime.cxx_test(
name = "qnnpack_utils_test",
srcs = ["test_utils.cpp"],
fbcode_deps = [
"//caffe2:ATen-cpu",
],
xplat_deps = [
"//caffe2:aten_cpu",
],
platforms = [ANDROID, APPLE, CXX],
deps = [
"//executorch/core/kernel_types/testing:tensor_util",
"//executorch/core/kernel_types/util:scalar_type_util",
"//executorch/util:aten_bridge",
"//executorch/backends/qnnpack:qnnpack_utils",
],
)
33 changes: 33 additions & 0 deletions backends/targets.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime")

def define_common_targets():
"""Defines targets that should be shared between fbcode and xplat.

The directory containing this targets.bzl file should also contain both
TARGETS and BUCK files that call this function.
"""

for aten_mode in (True, False):
aten_suffix = ("_aten" if aten_mode else "")
runtime.cxx_library(
name = "backend" + aten_suffix,
srcs = [
"backend.cpp",
],
exported_headers = [
"backend.h",
],
preprocessor_flags = ["-DUSE_ATEN_LIB"] if aten_mode else [],
visibility = [
"//executorch/...",
"//executorch/test/...",
"@EXECUTORCH_CLIENTS",
],
exported_deps = [
"//executorch/core:core",
"//executorch/core/values:executor_values" + aten_suffix,
"//executorch/core:freeable_buffer",
"//executorch/executor:memory_manager",
"//executorch/profiler:profiler",
],
)
48 changes: 48 additions & 0 deletions backends/test/demos/rpc/targets.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
load(
"@fbsource//tools/build_defs:default_platform_defs.bzl",
"ANDROID",
"CXX",
)
load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime")
load("@fbsource//xplat/executorch/pybindings:targets.bzl", "MODELS_ALL_OPS_LEAN_MODE_GENERATED_LIB")

def define_common_targets():
"""Defines targets that should be shared between fbcode and xplat.

The directory containing this targets.bzl file should also contain both
TARGETS and BUCK files that call this function.
"""

runtime.cxx_library(
name = "executor_backend",
srcs = [
"ExecutorBackend.cpp",
],
exported_headers = [
"ExecutorBackend.h",
],
platforms = [ANDROID, CXX],
deps = [
"//executorch/executor:executor",
"//executorch/kernels/portable:generated_lib",
"//executorch/backends:backend",
"//executorch/util:embedded_data_loader",
"//executorch/util:util",
] + MODELS_ALL_OPS_LEAN_MODE_GENERATED_LIB,
exported_deps = [
"//executorch/core:core",
],
)

runtime.cxx_library(
name = "executor_backend_register",
srcs = [
"ExecutorBackendRegister.cpp",
],
deps = [
":executor_backend",
"//executorch/backends:backend",
"//executorch/core:core",
],
platforms = [ANDROID, CXX],
)
65 changes: 65 additions & 0 deletions backends/xnnpack/targets.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime")

def define_common_targets():
runtime.genrule(
name = "gen_xnnpack_schema",
srcs = [
"serialization/schema.fbs",
],
# We're only generating a single file, so it seems like we could use
# `out`, but `flatc` takes a directory as a parameter, not a single
# file. Use `outs` so that `${OUT}` is expanded as the containing
# directory instead of the file itself.
outs = {
"xnnpack_schema_generated.h": ["schema_generated.h"],
},
cmd = " ".join([
"$(exe fbsource//third-party/flatbuffers/fbsource_namespace:flatc)",
"--cpp",
"--cpp-std c++11",
"--scoped-enums",
"-o ${OUT}",
"${SRCS}",
]),
default_outs = ["."],
)

runtime.cxx_library(
name = "xnnpack_schema",
srcs = [],
exported_headers = {
"xnnpack_schema_generated.h": ":gen_xnnpack_schema[xnnpack_schema_generated.h]",
},
exported_deps = [
"fbsource//third-party/flatbuffers/fbsource_namespace:flatbuffers-api",
],
)

runtime.cxx_library(
name = "xnnpack_backend",
srcs = native.glob([
"runtime/*.cpp",
]),
headers = native.glob([
"runtime/*.h",
]),
visibility = [
"//executorch/backends:backend_lib",
"//executorch/backends/test/...",
"//executorch/backends/xnnpack/test/...",
"//executorch/pybindings/...",
"@EXECUTORCH_CLIENTS",
],
deps = [
"//xplat/third-party/XNNPACK:XNNPACK",
":xnnpack_schema",
"//executorch/backends:backend",
"//executorch/backends/qnnpack:qnnpack_utils", # TODO Use (1) portable for choose_qparams(), (2) xnnpack for quantize_per_tensor()
"//executorch/threadpool:threadpool",
"//executorch/util:memory_utils",
"//executorch/core/kernel_types/util:tensor_util",
],
# XnnpackBackend.cpp needs to compile with executor as whole
# @lint-ignore BUCKLINT: Avoid `link_whole=True` (https://fburl.com/avoid-link-whole)
link_whole = True,
)
Loading