Skip to content

Commit

Permalink
Add QnnBackend dependency to the ET main test binary app in buck for …
Browse files Browse the repository at this point in the history
…Android OS

Differential Revision: D61314481

Pull Request resolved: pytorch#4732
  • Loading branch information
derekxu committed Aug 15, 2024
1 parent c4ccad3 commit ba2ff63
Show file tree
Hide file tree
Showing 9 changed files with 253 additions and 1 deletion.
6 changes: 5 additions & 1 deletion backends/qualcomm/TARGETS
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
# This file needs to exist to avoid build system breakage, see https://fburl.com/workplace/jtdlgdmd
load(":targets.bzl", "define_common_targets")

oncall("executorch")

define_common_targets()
5 changes: 5 additions & 0 deletions backends/qualcomm/aot/ir/TARGETS
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
load(":targets.bzl", "define_common_targets")

oncall("executorch")

define_common_targets()
66 changes: 66 additions & 0 deletions backends/qualcomm/aot/ir/targets.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
load(
"@fbsource//tools/build_defs:default_platform_defs.bzl",
"ANDROID",
)
load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime")
load("@fbsource//xplat/executorch/backends/qualcomm:targets.bzl", "generate_schema_header")

QCIR_NAME = "qcir"
INPUT_QCIR = QCIR_NAME + ".fbs"
OUTPUT_QCIR_HEADER = QCIR_NAME + "_generated.h"
QCIR_GEN_RULE_NAME = "qcir_generated"

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.
"""

generate_schema_header(
QCIR_GEN_RULE_NAME,
[INPUT_QCIR],
[OUTPUT_QCIR_HEADER],
OUTPUT_QCIR_HEADER,
)

# Header-only library target with the generate executorch program schema header.
runtime.cxx_library(
name = "qcir_schema",
srcs = [],
exported_headers = {
OUTPUT_QCIR_HEADER: ":{}[{}]".format(QCIR_GEN_RULE_NAME, OUTPUT_QCIR_HEADER),
},
visibility = [
# Lock this down as tightly as possible to ensure that flatbuffers
# are an implementation detail. Ideally this list would only include
# //executorch/runtime/executor/...
"//executorch/backends/qualcomm/...",
"//executorch/backends/qualcomm/aot/ir/...",
],
exported_external_deps = ["flatbuffers-api"],
define_static_target = True,
platforms = [ANDROID],
)


runtime.cxx_library(
name = "qcir_utils",
srcs = [
"qcir_utils.cpp",
],
exported_headers = [
"qcir_utils.h",
],
define_static_target = True,
platforms = [ANDROID],
visibility = ["@EXECUTORCH_CLIENTS"],
deps = [
"fbsource//third-party/qualcomm/qnn:api",
"//executorch/runtime/backend:interface",
"//executorch/runtime/core:core",
"//executorch/backends/qualcomm/aot/wrappers:wrappers",
],
exported_deps = [
":qcir_schema",
],
)
5 changes: 5 additions & 0 deletions backends/qualcomm/aot/wrappers/TARGETS
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
load(":targets.bzl", "define_common_targets")

oncall("executorch")

define_common_targets()
32 changes: 32 additions & 0 deletions backends/qualcomm/aot/wrappers/targets.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
load(
"@fbsource//tools/build_defs:default_platform_defs.bzl",
"ANDROID",
)
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.
"""
runtime.cxx_library(
name = "wrappers",
srcs = glob([
"*.cpp",
]),
exported_headers = glob([
"*.h",
]),
define_static_target = True,
platforms = [ANDROID],
visibility = ["@EXECUTORCH_CLIENTS"],
deps = [
"fbsource//third-party/qualcomm/qnn:api",
"//executorch/runtime/backend:interface",
"//executorch/runtime/core:core",
],
exported_deps = [
"//executorch/backends/qualcomm/runtime:logging",
],
)
5 changes: 5 additions & 0 deletions backends/qualcomm/runtime/TARGETS
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
load(":targets.bzl", "define_common_targets")

oncall("executorch")

define_common_targets()
67 changes: 67 additions & 0 deletions backends/qualcomm/runtime/targets.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
load(
"@fbsource//tools/build_defs:default_platform_defs.bzl",
"ANDROID",
)
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.
"""

runtime.cxx_library(
name = "logging",
srcs = [
"Logging.cpp",
],
exported_headers = [
"Logging.h",
],
define_static_target = True,
platforms = [ANDROID],
visibility = ["@EXECUTORCH_CLIENTS"],
deps = [
"fbsource//third-party/qualcomm/qnn:api",
"//executorch/runtime/backend:interface",
"//executorch/runtime/core:core",
],
exported_deps = [
"//executorch/backends/qualcomm:schema",
],
)

runtime.cxx_library(
name = "runtime",
srcs = glob(
[
"*.cpp",
"backends/*.cpp",
"backends/htpbackend/*.cpp",
"backends/htpbackend/aarch64/*.cpp",
],
exclude = ["Logging.cpp"],
),
exported_headers = glob(
[
"*.h",
"backends/*.h",
"backends/htpbackend/*.h",
],
exclude = ["Logging.h"],
),
define_static_target = True,
link_whole = True, # needed for executorch/examples/models/llama2:main to register QnnBackend
platforms = [ANDROID],
visibility = ["@EXECUTORCH_CLIENTS"],
deps = [
"fbsource//third-party/qualcomm/qnn:api",
":logging",
"//executorch/backends/qualcomm:schema",
"//executorch/backends/qualcomm/aot/ir:qcir_utils",
"//executorch/backends/qualcomm/aot/wrappers:wrappers",
"//executorch/runtime/backend:interface",
"//executorch/runtime/core:core",
],
)
67 changes: 67 additions & 0 deletions backends/qualcomm/targets.bzl
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
load(
"@fbsource//tools/build_defs:default_platform_defs.bzl",
"ANDROID",
)
load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime")


# Construct the input and output file names. All input and output files rely on scalar_type file.
SCHEMA_NAME = "schema"

INPUT_SCHEMA = "serialization/" + SCHEMA_NAME + ".fbs"

OUTPUT_SCHEMA_HEADER = SCHEMA_NAME + "_generated.h"

SCHEMA_GEN_RULE_NAME = "schema_generated"

SCHEMA_LIRRARY_NAME = SCHEMA_NAME

def generate_schema_header(rule_name, srcs, headers, default_header):
"""Generate header file given flatbuffer schema
"""
Expand All @@ -26,3 +41,55 @@ def generate_schema_header(rule_name, srcs, headers, default_header):
]),
visibility = [], # Private
)

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.
"""

generate_schema_header(
SCHEMA_GEN_RULE_NAME,
[INPUT_SCHEMA],
[OUTPUT_SCHEMA_HEADER],
OUTPUT_SCHEMA_HEADER,
)
# Header-only library target with the generate executorch program schema header.
runtime.cxx_library(
name = "schema",
srcs = [],
visibility = [
# Lock this down as tightly as possible to ensure that flatbuffers
# are an implementation detail. Ideally this list would only include
# //executorch/runtime/executor/...
"//executorch/codegen/tools/...",
"//executorch/runtime/executor/...",
"//executorch/backends/qualcomm/...",
"//executorch/backends/qualcomm/runtime/...",
],
exported_headers = {
OUTPUT_SCHEMA_HEADER: ":{}[{}]".format(SCHEMA_GEN_RULE_NAME, OUTPUT_SCHEMA_HEADER),
},
exported_external_deps = ["flatbuffers-api"],
define_static_target = True,
platforms = [ANDROID],
)


runtime.cxx_library(
name = "qnn_executorch_backend",
srcs = [],
headers = [],
define_static_target = True,
visibility = ["@EXECUTORCH_CLIENTS"],
deps = [
"fbsource//third-party/qualcomm/qnn:api",
"//executorch/runtime/backend:interface",
"//executorch/runtime/core:core",
"//executorch/backends/qualcomm/runtime:runtime",
],
exported_deps = [
":schema",
],
)
1 change: 1 addition & 0 deletions examples/models/llama2/runner/targets.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def define_common_targets():
visibility = [
"@EXECUTORCH_CLIENTS",
],
# qnn_executorch_backend can be added below //executorch/backends/qualcomm:qnn_executorch_backend
exported_deps = [
"//executorch/backends/xnnpack:xnnpack_backend",
"//executorch/extension/llm/runner:stats",
Expand Down

0 comments on commit ba2ff63

Please sign in to comment.