Skip to content

Commit aa1194c

Browse files
tarun292facebook-github-bot
authored andcommitted
Enable xnnpack in aten mode (#9049)
Summary: This diff enables XNNPack delegate in ATen mode resolving some compilation issues and also making sure that the deps that XNNPack depends on are portable + aten friendly. Differential Revision: D70704202
1 parent 6099020 commit aa1194c

File tree

2 files changed

+48
-39
lines changed

2 files changed

+48
-39
lines changed

backends/xnnpack/runtime/XNNExecutor.cpp

+9-2
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,18 @@ ET_NODISCARD Error XNNExecutor::prepare_args(EValue** args) {
8888
Tensor* tensor = &args[ext_id]->toTensor();
8989
externals_[i].data = tensor->mutable_data_ptr<float>();
9090

91+
executorch::aten::DimOrderType dim_order[kTensorDimensionLimit];
92+
9193
// Reshape runtime inputs
9294
if (i < input_ids_.size()) {
9395
size_t num_dims = tensor->dim();
96+
Error err = runtime::get_dim_order(*tensor, dim_order, num_dims);
97+
ET_CHECK_OR_RETURN_ERROR(
98+
err == Error::Ok,
99+
Internal,
100+
"Failed to retrieve dim order from tensor!");
94101
ET_CHECK_OR_RETURN_ERROR(
95-
is_contiguous_dim_order(tensor->dim_order().data(), tensor->dim()),
102+
is_contiguous_dim_order(dim_order, tensor->dim()),
96103
Internal,
97104
"Expecting default dim_order but got a non default dim_order tensor for external input %u",
98105
i);
@@ -213,7 +220,7 @@ ET_NODISCARD Error XNNExecutor::resize_outputs(EValue** args) const {
213220
expected_output_size, static_cast<size_t>(num_dim)};
214221

215222
ET_LOG(Debug, "Resizing output tensor to a new shape");
216-
Error err = resize_tensor(*out_tensor, output_size);
223+
Error err = runtime::resize_tensor(*out_tensor, output_size);
217224
if (err != Error::Ok) {
218225
ET_LOG(Error, "Failed to resize output tensor for XNNExecutor");
219226
return err;

backends/xnnpack/targets.bzl

+39-37
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
load("@fbsource//xplat/executorch/backends/xnnpack/third-party:third_party_libs.bzl", "third_party_dep")
2-
load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime")
2+
load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "get_aten_mode_options", "runtime")
33

44
def _get_preprocessor_flags():
55
"""
@@ -29,39 +29,41 @@ def define_common_targets():
2929
],
3030
)
3131

32-
runtime.cxx_library(
33-
name = "xnnpack_backend",
34-
srcs = native.glob([
35-
"runtime/*.cpp",
36-
"runtime/profiling/*.cpp",
37-
]),
38-
headers = native.glob([
39-
"runtime/*.h",
40-
"runtime/profiling/*.h",
41-
]),
42-
visibility = [
43-
"//executorch/exir/backend:backend_lib",
44-
"//executorch/exir/backend/test/...",
45-
"//executorch/backends/xnnpack/test/...",
46-
"//executorch/extension/pybindings/...",
47-
"@EXECUTORCH_CLIENTS",
48-
],
49-
preprocessor_flags = [
50-
# Uncomment to enable per operator timings
51-
# "-DENABLE_XNNPACK_PROFILING",
52-
# Uncomment to enable using KleidiAI Kernels
53-
# "-DENABLE_XNNPACK_KLEIDI"
54-
] + _get_preprocessor_flags(),
55-
exported_deps = [
56-
"//executorch/runtime/backend:interface",
57-
],
58-
deps = [
59-
third_party_dep("XNNPACK"),
60-
"//executorch/backends/xnnpack/serialization:xnnpack_flatbuffer_header",
61-
"//executorch/extension/threadpool:threadpool",
62-
"//executorch/runtime/core/exec_aten/util:tensor_util",
63-
],
64-
# XnnpackBackend.cpp needs to compile with executor as whole
65-
# @lint-ignore BUCKLINT: Avoid `link_whole=True` (https://fburl.com/avoid-link-whole)
66-
link_whole = True,
67-
)
32+
for aten_mode in get_aten_mode_options():
33+
aten_suffix = "_aten" if aten_mode else ""
34+
runtime.cxx_library(
35+
name = "xnnpack_backend" + aten_suffix,
36+
srcs = native.glob([
37+
"runtime/*.cpp",
38+
"runtime/profiling/*.cpp",
39+
]),
40+
headers = native.glob([
41+
"runtime/*.h",
42+
"runtime/profiling/*.h",
43+
]),
44+
visibility = [
45+
"//executorch/exir/backend:backend_lib",
46+
"//executorch/exir/backend/test/...",
47+
"//executorch/backends/xnnpack/test/...",
48+
"//executorch/extension/pybindings/...",
49+
"@EXECUTORCH_CLIENTS",
50+
],
51+
preprocessor_flags = [
52+
# Uncomment to enable per operator timings
53+
# "-DENABLE_XNNPACK_PROFILING",
54+
# Uncomment to enable using KleidiAI Kernels
55+
# "-DENABLE_XNNPACK_KLEIDI"
56+
] + _get_preprocessor_flags(),
57+
exported_deps = [
58+
"//executorch/runtime/backend:interface",
59+
],
60+
deps = [
61+
third_party_dep("XNNPACK"),
62+
"//executorch/backends/xnnpack/serialization:xnnpack_flatbuffer_header",
63+
"//executorch/extension/threadpool:threadpool",
64+
"//executorch/runtime/core/exec_aten/util:tensor_util" + aten_suffix,
65+
],
66+
# XnnpackBackend.cpp needs to compile with executor as whole
67+
# @lint-ignore BUCKLINT: Avoid `link_whole=True` (https://fburl.com/avoid-link-whole)
68+
link_whole = True,
69+
)

0 commit comments

Comments
 (0)