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

Kleidi Integration #5162

Closed
wants to merge 1 commit into from
Closed
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
14 changes: 10 additions & 4 deletions backends/xnnpack/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,20 @@ if(NOT PYTHON_EXECUTABLE)
resolve_python_executable()
endif()

# NB: Enabling this will serialize execution of delegate instances.
# This setting may have performance implications.
# NB: Enabling this will serialize execution of delegate instances
# Keeping this OFF by default to maintain existing behavior, to be revisited.
option(EXECUTORCH_XNNPACK_SHARED_WORKSPACE
"Enable workspace sharing across different delegate instances" ON
)
"Enable workspace sharing across different delegate instances" ON)
# Keeping this OFF by default due to regressions in decode
# and model load with kleidi kernels
option(EXECUTORCH_XNNPACK_ENABLE_KLEIDI
"Enable workspace sharing across different delegate instances" OFF)
if(EXECUTORCH_XNNPACK_SHARED_WORKSPACE)
add_definitions(-DENABLE_XNNPACK_SHARED_WORKSPACE)
endif()
if(EXECUTORCH_XNNPACK_ENABLE_KLEIDI)
add_definitions(-DENABLE_XNNPACK_KLEIDI)
endif()

set(_common_include_directories ${EXECUTORCH_ROOT}/..)
set(_common_compile_options -Wno-deprecated-declarations -fPIC)
Expand Down
28 changes: 27 additions & 1 deletion backends/xnnpack/cmake/Dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,39 @@ set(XNNPACK_ENABLE_AVXVNNI
OFF
CACHE BOOL ""
)
set(XNNPACK_ENABLE_KLEIDIAI

if(EXECUTORCH_XNNPACK_ENABLE_KLEIDI)
set(XNNPACK_ENABLE_KLEIDIAI
ON
CACHE BOOL ""
)
else()
set(XNNPACK_ENABLE_KLEIDIAI
OFF
CACHE BOOL ""
)
endif()


set(XNNPACK_BUILD_ALL_MICROKERNELS
OFF
CACHE BOOL ""
)
add_subdirectory("${XNNPACK_SOURCE_DIR}")
include_directories(SYSTEM ${XNNPACK_INCLUDE_DIR})
list(APPEND xnnpack_third_party XNNPACK)
install(TARGETS microkernels-prod
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})


if(EXECUTORCH_XNNPACK_ENABLE_KLEIDI)
install(TARGETS kleidiai
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
endif()

# Revert PIC Flag to what it originally was
set(CMAKE_POSITION_INDEPENDENT_CODE
Expand Down
7 changes: 7 additions & 0 deletions backends/xnnpack/runtime/XNNCompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,14 @@ Error defineConvertNode(
subgraph_ptr,
remapped_ids.at(graph_node->input_id()),
remapped_ids.at(graph_node->output_id()),
#ifdef ENABLE_XNNPACK_KLEIDI
// This maps to XNNPACK's XNN_FLAG_MAYBE_PACK_FOR_QB4W_GEMM
Copy link
Contributor

Choose a reason for hiding this comment

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

perhaps we should fix it in XNNPACK, independent of this PR

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think they want this public yet, since it would cause backwards compatibility issues in the future. This is likely the path until they have a complete qp8 story.

// however this is not currently exposed at top level
// xnnpack.h Header
0x00000100);
#else
graph_node->flags());
#endif

ET_CHECK_OR_RETURN_ERROR(
status == xnn_status_success,
Expand Down
2 changes: 2 additions & 0 deletions backends/xnnpack/targets.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ def define_common_targets():
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",
Expand Down
1 change: 1 addition & 0 deletions backends/xnnpack/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ et_cxx_test(
XNNPACK
pthreadpool
cpuinfo
microkernels-prod
)
target_include_directories(
backends_xnnpack_test
Expand Down
10 changes: 5 additions & 5 deletions backends/xnnpack/test/runtime/test_xnnexecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <executorch/backends/xnnpack/runtime/XNNExecutor.h>
#include <executorch/runtime/core/exec_aten/testing_util/tensor_factory.h>
#include <gtest/gtest.h>
#include <xnnpack/subgraph.h>
#include <xnnpack.h>

using torch::executor::Error;
using torch::executor::EValue;
Expand All @@ -26,7 +26,7 @@ TEST(XNNExecutorTest, ArgumentWithTooManyDimensions) {
std::unique_ptr<xnn_subgraph, decltype(&xnn_delete_subgraph)> auto_subgraph(
subgraph, xnn_delete_subgraph);

auto input_id = XNN_INVALID_NODE_ID;
auto input_id = XNN_INVALID_VALUE_ID;
std::vector<size_t> dims = {
1,
};
Expand All @@ -43,9 +43,9 @@ TEST(XNNExecutorTest, ArgumentWithTooManyDimensions) {
/*external_id=*/0,
/*flags=*/XNN_VALUE_FLAG_EXTERNAL_INPUT,
&input_id));
ASSERT_NE(input_id, XNN_INVALID_NODE_ID);
ASSERT_NE(input_id, XNN_INVALID_VALUE_ID);

auto output_id = XNN_INVALID_NODE_ID;
auto output_id = XNN_INVALID_VALUE_ID;
ASSERT_EQ(
xnn_status_success,
xnn_define_quantized_tensor_value(
Expand All @@ -59,7 +59,7 @@ TEST(XNNExecutorTest, ArgumentWithTooManyDimensions) {
/*external_id=*/0,
/*flags=*/XNN_VALUE_FLAG_EXTERNAL_OUTPUT,
&output_id));
ASSERT_NE(output_id, XNN_INVALID_NODE_ID);
ASSERT_NE(output_id, XNN_INVALID_VALUE_ID);

ASSERT_EQ(
xnn_status_success,
Expand Down
1 change: 1 addition & 0 deletions backends/xnnpack/test/targets.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def define_common_targets():
srcs = ["runtime/test_xnnexecutor.cpp"],
deps = [
third_party_dep("XNNPACK"),
third_party_dep("FP16"),
"//executorch/runtime/core/exec_aten/testing_util:tensor_util",
"//executorch/runtime/core/exec_aten/util:scalar_type_util",
"//executorch/backends/xnnpack:xnnpack_backend",
Expand Down
2 changes: 1 addition & 1 deletion backends/xnnpack/third-party/XNNPACK
Submodule XNNPACK updated 9962 files
213 changes: 0 additions & 213 deletions backends/xnnpack/third-party/generate-xnnpack-wrappers.py

This file was deleted.

Loading
Loading