Skip to content

Commit 24d8bab

Browse files
Build QNN backend on linux: add CXX platform and qnn_executorch_backend_aot host target (#19889) (#19889)
Summary: Make the QNN backend buildable on linux hosts so that AOT / offline use cases (compilation, validation, host-side testing against the simulator) can link against the QnnExecuTorchBackend without an android target. Two changes: 1. Add `CXX` to `platforms = [ANDROID]` on the QNN backend BUCK targets (5 sites across `backends/qualcomm/runtime/`, `backends/qualcomm/aot/wrappers/`, and the top-level `backends/qualcomm/targets.bzl`). The QNN runtime sources have no android-specific code (`__ANDROID__`, `fastrpc`, `dlopen` are not referenced), so expanding the platform set is a one-line tag change and the ANDROID behavior is unchanged. 2. Add `qnn_executorch_backend_aot` in `backends/qualcomm/targets.bzl`. Mirrors the structure of the existing `qnn_executorch_backend` (on-device) but depends on the host `:runtime` target instead of `:runtime_android_build`. The host runtime bundles the QNN offline-compile libraries as a Buck resource, so consumers linking the AOT variant get the libs in their dlopen search path without manual setup. Registers `"QnnBackend"` via the same link-whole static initializer as the on-device variant. Differential Revision: D105761976
1 parent a6305cb commit 24d8bab

3 files changed

Lines changed: 35 additions & 5 deletions

File tree

backends/qualcomm/aot/wrappers/targets.bzl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
load(
22
"@fbsource//tools/build_defs:default_platform_defs.bzl",
33
"ANDROID",
4+
"CXX",
45
)
56
load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime")
67
load("@fbsource//xplat/executorch/backends/qualcomm/third-party:third_party_libs.bzl", "qnn_third_party_dep")
@@ -20,7 +21,7 @@ def define_common_targets():
2021
"*.h",
2122
]),
2223
define_static_target = True,
23-
platforms = [ANDROID],
24+
platforms = [ANDROID, CXX],
2425
visibility = ["PUBLIC"],
2526
deps = [
2627
qnn_third_party_dep("api"),

backends/qualcomm/runtime/targets.bzl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
load(
22
"@fbsource//tools/build_defs:default_platform_defs.bzl",
33
"ANDROID",
4+
"CXX",
45
)
56
load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime")
67
load("@fbsource//xplat/executorch/backends/qualcomm/third-party:third_party_libs.bzl", "qnn_third_party_dep")
@@ -21,7 +22,7 @@ def define_common_targets():
2122
"Logging.h",
2223
],
2324
define_static_target = True,
24-
platforms = [ANDROID],
25+
platforms = [ANDROID, CXX],
2526
visibility = ["PUBLIC"],
2627
deps = [
2728
qnn_third_party_dep("api"),
@@ -91,7 +92,7 @@ def define_common_targets():
9192
),
9293
define_static_target = True,
9394
link_whole = True, # needed for executorch/examples/models/llama:main to register QnnBackend
94-
platforms = [ANDROID],
95+
platforms = [ANDROID, CXX],
9596
visibility = ["PUBLIC"],
9697
resources = ({
9798
"qnn_lib": qnn_third_party_dep("qnn_offline_compile_libs"),

backends/qualcomm/targets.bzl

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
load(
22
"@fbsource//tools/build_defs:default_platform_defs.bzl",
33
"ANDROID",
4+
"CXX",
45
)
56
load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime")
67
load("@fbsource//xplat/executorch/backends/qualcomm/third-party:third_party_libs.bzl", "qnn_third_party_dep")
@@ -69,7 +70,7 @@ def define_common_targets():
6970
},
7071
exported_external_deps = ["flatbuffers-api"],
7172
define_static_target = True,
72-
platforms = [ANDROID],
73+
platforms = [ANDROID, CXX],
7374
)
7475

7576
runtime.cxx_library(
@@ -87,5 +88,32 @@ def define_common_targets():
8788
exported_deps = [
8889
":schema",
8990
],
90-
platforms = [ANDROID],
91+
platforms = [ANDROID, CXX],
92+
)
93+
94+
# Host-side AOT variant of qnn_executorch_backend. Pulls in the QNN
95+
# offline-compile libraries as a Buck resource (via :runtime, which
96+
# itself depends on qnn_third_party_dep("qnn_offline_compile_libs")),
97+
# so a host-side gtest or runner can dlopen the QNN libraries
98+
# without a manual path setup.
99+
#
100+
# Mirrors qnn_executorch_backend's structure but swaps the on-device
101+
# runtime_android_build dep for the host runtime which bundles the
102+
# x86 simulator libraries as a Buck resource.
103+
runtime.cxx_library(
104+
name = "qnn_executorch_backend_aot",
105+
srcs = [],
106+
headers = [],
107+
define_static_target = True,
108+
visibility = ["PUBLIC"],
109+
deps = [
110+
qnn_third_party_dep("api"),
111+
"//executorch/runtime/backend:interface",
112+
"//executorch/runtime/core:core",
113+
"//executorch/backends/qualcomm/runtime:runtime",
114+
],
115+
exported_deps = [
116+
":schema",
117+
],
118+
platforms = [ANDROID, CXX],
91119
)

0 commit comments

Comments
 (0)