Skip to content
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

Enable xnnpack in aten mode #9049

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
11 changes: 9 additions & 2 deletions backends/xnnpack/runtime/XNNExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,18 @@ ET_NODISCARD Error XNNExecutor::prepare_args(EValue** args) {
Tensor* tensor = &args[ext_id]->toTensor();
externals_[i].data = tensor->mutable_data_ptr<float>();

executorch::aten::DimOrderType dim_order[kTensorDimensionLimit];

// Reshape runtime inputs
if (i < input_ids_.size()) {
size_t num_dims = tensor->dim();
Error err = runtime::get_dim_order(*tensor, dim_order, num_dims);
ET_CHECK_OR_RETURN_ERROR(
err == Error::Ok,
Internal,
"Failed to retrieve dim order from tensor!");
ET_CHECK_OR_RETURN_ERROR(
is_contiguous_dim_order(tensor->dim_order().data(), tensor->dim()),
is_contiguous_dim_order(dim_order, tensor->dim()),
Internal,
"Expecting default dim_order but got a non default dim_order tensor for external input %u",
i);
Expand Down Expand Up @@ -220,7 +227,7 @@ ET_NODISCARD Error XNNExecutor::resize_outputs(EValue** args) const {
expected_output_size, static_cast<size_t>(num_dim)};

ET_LOG(Debug, "Resizing output tensor to a new shape");
Error err = resize_tensor(*out_tensor, output_size);
Error err = runtime::resize_tensor(*out_tensor, output_size);
if (err != Error::Ok) {
ET_LOG(Error, "Failed to resize output tensor for XNNExecutor");
return err;
Expand Down
78 changes: 40 additions & 38 deletions backends/xnnpack/targets.bzl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
load("@fbsource//xplat/executorch/backends/xnnpack/third-party:third_party_libs.bzl", "third_party_dep")
load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime")
load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "get_aten_mode_options", "runtime")

def _get_preprocessor_flags():
"""
Expand Down Expand Up @@ -33,40 +33,42 @@ def define_common_targets():
],
)

runtime.cxx_library(
name = "xnnpack_backend",
srcs = native.glob([
"runtime/*.cpp",
"runtime/profiling/*.cpp",
]),
headers = native.glob([
"runtime/*.h",
"runtime/profiling/*.h",
]),
visibility = [
"//executorch/exir/backend:backend_lib",
"//executorch/exir/backend/test/...",
"//executorch/backends/xnnpack/test/...",
"//executorch/extension/pybindings/...",
"@EXECUTORCH_CLIENTS",
],
preprocessor_flags = [
# Uncomment to enable per operator timings
# "-DENABLE_XNNPACK_PROFILING",
# Uncomment to enable using KleidiAI Kernels
# "-DENABLE_XNNPACK_KLEIDI"
] + _get_preprocessor_flags(),
exported_deps = [
"//executorch/runtime/backend:interface",
],
deps = [
third_party_dep("XNNPACK"),
"//executorch/backends/xnnpack/serialization:xnnpack_flatbuffer_header",
"//executorch/extension/threadpool:threadpool",
"//executorch/runtime/core/exec_aten/util:tensor_util",
"//executorch/runtime/executor:pte_data_map"
],
# 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,
)
for aten_mode in get_aten_mode_options():
Copy link
Contributor

@digantdesai digantdesai Mar 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dejvu can't remember why we disabled aten-mode anymore, good luck :)

aten_suffix = "_aten" if aten_mode else ""
runtime.cxx_library(
name = "xnnpack_backend" + aten_suffix,
srcs = native.glob([
"runtime/*.cpp",
"runtime/profiling/*.cpp",
]),
headers = native.glob([
"runtime/*.h",
"runtime/profiling/*.h",
]),
visibility = [
"//executorch/exir/backend:backend_lib",
"//executorch/exir/backend/test/...",
"//executorch/backends/xnnpack/test/...",
"//executorch/extension/pybindings/...",
"@EXECUTORCH_CLIENTS",
],
preprocessor_flags = [
# Uncomment to enable per operator timings
# "-DENABLE_XNNPACK_PROFILING",
# Uncomment to enable using KleidiAI Kernels
# "-DENABLE_XNNPACK_KLEIDI"
] + _get_preprocessor_flags(),
exported_deps = [
"//executorch/runtime/backend:interface",
],
deps = [
third_party_dep("XNNPACK"),
"//executorch/backends/xnnpack/serialization:xnnpack_flatbuffer_header",
"//executorch/extension/threadpool:threadpool",
"//executorch/runtime/core/exec_aten/util:tensor_util" + aten_suffix,
"//executorch/runtime/executor:pte_data_map"
],
# 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