Skip to content

Commit

Permalink
Add ENABLE_KLEIDI_FLAG to use new QP8 Kernels
Browse files Browse the repository at this point in the history
  • Loading branch information
mcr229 committed Sep 14, 2024
1 parent 61a8270 commit 4d96001
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 7 deletions.
13 changes: 8 additions & 5 deletions backends/xnnpack/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,17 @@ if(NOT PYTHON_EXECUTABLE)
resolve_python_executable()
endif()

# 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" OFF
)
# 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" OFF)
# Keeping this OFF by default do 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
24 changes: 23 additions & 1 deletion backends/xnnpack/cmake/Dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,21 @@ 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 ""
)
Expand All @@ -48,6 +62,14 @@ install(TARGETS microkernels-prod
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
${ORIGINAL_CMAKE_POSITION_INDEPENDENT_CODE_FLAG}
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_GEMM
// however this is not currently exposed at top level
// Header
0x00000080);
#else
graph_node->flags());
#endif

ET_CHECK_OR_RETURN_ERROR(
status == xnn_status_success,
Expand Down
1 change: 1 addition & 0 deletions backends/xnnpack/targets.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def define_common_targets():
# "-DENABLE_XNNPACK_PROFILING",
# Uncomment to enable workspace sharing across delegates
# "-DENABLE_XNNPACK_SHARED_WORKSPACE"
# "-DENABLE_XNNPACK_KLEIDI"
],
exported_deps = [
"//executorch/runtime/backend:interface",
Expand Down
3 changes: 3 additions & 0 deletions build/executorch-config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,11 @@ set(lib_list
extension_tensor
extension_threadpool
xnnpack_backend
# Start XNNPACK Lib Deps
XNNPACK
microkernels-prod
kleidiai
# End XNNPACK Lib Deps
cpuinfo
pthreadpool
vulkan_backend
Expand Down
3 changes: 3 additions & 0 deletions examples/models/llama2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ endif()
# XNNPACK
if(TARGET xnnpack_backend)
set(xnnpack_backend_libs xnnpack_backend XNNPACK microkernels-prod)
if(TARGET kleidiai)
list(APPEND xnnpack_backend_libs kleidiai)
endif()
list(APPEND link_libraries ${xnnpack_backend_libs})
target_link_options_shared_lib(xnnpack_backend)
endif()
Expand Down
5 changes: 4 additions & 1 deletion examples/models/llava/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,10 @@ endif()

# XNNPACK
if(TARGET xnnpack_backend)
set(xnnpack_backend_libs xnnpack_backend XNNPACK)
set(xnnpack_backend_libs xnnpack_backend XNNPACK microkernels-prod)
if(TARGET kleidiai)
list(APPEND xnnpack_backend_libs kleidiai)
endif()
list(APPEND link_libraries ${xnnpack_backend_libs})
target_link_options_shared_lib(xnnpack_backend)
endif()
Expand Down

0 comments on commit 4d96001

Please sign in to comment.