-
Notifications
You must be signed in to change notification settings - Fork 626
Build XNNPACK as an ExternalProject #12425
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
base: main
Are you sure you want to change the base?
Changes from 11 commits
9e3e2e7
16f0274
99ec5a7
ff3cdb9
513de13
76db1f1
08bffac
dff96c8
0e2bce6
a31187e
dcbce0d
fb2b775
c31a4b9
466f669
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,8 @@ on: | |
- examples/**/* | ||
- pyproject.toml | ||
- setup.py | ||
tags: | ||
- ciflow/binaries/* | ||
push: | ||
branches: | ||
- nightly | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,8 @@ on: | |
- examples/**/* | ||
- pyproject.toml | ||
- setup.py | ||
tags: | ||
- ciflow/binaries/* | ||
push: | ||
branches: | ||
- nightly | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,71 +10,83 @@ set(THIRD_PARTY_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/third-party") | |
|
||
# --- XNNPACK | ||
|
||
# Setting this global PIC flag for all XNNPACK targets. This is needed for | ||
# Object libraries within XNNPACK which must be PIC to successfully link this | ||
# static libXNNPACK | ||
set(ORIGINAL_CMAKE_POSITION_INDEPENDENT_CODE_FLAG | ||
${CMAKE_POSITION_INDEPENDENT_CODE} | ||
) | ||
set(CMAKE_POSITION_INDEPENDENT_CODE ON) | ||
|
||
set(XNNPACK_SOURCE_DIR "${THIRD_PARTY_ROOT}/XNNPACK") | ||
set(XNNPACK_INCLUDE_DIR "${XNNPACK_SOURCE_DIR}/include") | ||
set(XNNPACK_LIBRARY_TYPE | ||
"static" | ||
CACHE STRING "" | ||
|
||
include(ExternalProject) | ||
include(GNUInstallDirs) # For CMAKE_INSTALL_LIBDIR | ||
set(XNNPACK_INSTALL_DIR "${CMAKE_CURRENT_BINARY_DIR}/XNNPACK/install") | ||
set(XNNPACK_STATIC_LIB | ||
"${XNNPACK_INSTALL_DIR}/${CMAKE_INSTALL_LIBDIR}/libXNNPACK.a" | ||
) | ||
set(XNNPACK_BUILD_BENCHMARKS | ||
OFF | ||
CACHE BOOL "" | ||
set(XNNPACK_MICROKERNELS_STATIC_LIB | ||
"${XNNPACK_INSTALL_DIR}/${CMAKE_INSTALL_LIBDIR}/libxnnpack-microkernels-prod.a" | ||
) | ||
set(XNNPACK_BUILD_TESTS | ||
OFF | ||
CACHE BOOL "" | ||
get_extra_cmake_args_for_external_project(XNNPACK_EXTRA_CMAKE_ARGS) | ||
ExternalProject_Add( | ||
XNNPACKExternalProject | ||
SOURCE_DIR ${XNNPACK_SOURCE_DIR} | ||
# Not 100% clear on these locations | ||
BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/XNNPACK | ||
INSTALL_DIR ${XNNPACK_INSTALL_DIR} | ||
INSTALL_BYPRODUCTS ${XNNPACK_STATIC_LIB} ${XNNPACK_MICROKERNELS_STATIC_LIB} | ||
CMAKE_ARGS | ||
${XNNPACK_EXTRA_CMAKE_ARGS} | ||
-D | ||
XNNPACK_LIBRARY_TYPE=static | ||
-D | ||
XNNPACK_BUILD_BENCHMARKS=OFF | ||
-D | ||
XNNPACK_BUILD_TESTS=OFF | ||
-D | ||
XNNPACK_ENABLE_AVXVNNI=OFF | ||
# Work around observed failure: | ||
# https://github.com/pytorch/executorch/pull/10362#issuecomment-2906391232 | ||
-D | ||
XNNPACK_ENABLE_AVX512VNNIGFNI=OFF | ||
-D | ||
ENABLE_XNNPACK_WEIGHTS_CACHE=${EXECUTORCH_XNNPACK_ENABLE_WEIGHT_CACHE} | ||
-D | ||
ENABLE_XNNPACK_SHARED_WORKSPACE=${EXECUTORCH_XNNPACK_SHARED_WORKSPACE} | ||
-D | ||
XNNPACK_ENABLE_KLEIDIAI=${EXECUTORCH_XNNPACK_ENABLE_KLEIDIAI} | ||
-D | ||
CMAKE_INSTALL_PREFIX=<INSTALL_DIR> | ||
-D | ||
XNNPACK_BUILD_ALL_MICROKERNELS=OFF | ||
-D | ||
CMAKE_POSITION_INDEPENDENT_CODE=ON | ||
) | ||
set(XNNPACK_ENABLE_AVXVNNI | ||
OFF | ||
CACHE BOOL "" | ||
) | ||
# Work around observed failure: https://github.com/pytorch/executorch/pull/10362#issuecomment-2906391232 | ||
set(XNNPACK_ENABLE_AVX512VNNIGFNI | ||
OFF | ||
CACHE BOOL "") | ||
|
||
if(EXECUTORCH_XNNPACK_ENABLE_KLEIDI) | ||
set(XNNPACK_ENABLE_KLEIDIAI | ||
ON | ||
CACHE BOOL "" | ||
) | ||
else() | ||
set(XNNPACK_ENABLE_KLEIDIAI | ||
OFF | ||
CACHE BOOL "" | ||
) | ||
endif() | ||
add_library(XNNPACK STATIC IMPORTED GLOBAL) | ||
# TODO: this probably doesn't work on Windows. | ||
set_property(TARGET XNNPACK PROPERTY IMPORTED_LOCATION ${XNNPACK_STATIC_LIB}) | ||
|
||
add_dependencies(XNNPACK XNNPACKExternalProject) | ||
|
||
set(XNNPACK_BUILD_ALL_MICROKERNELS | ||
OFF | ||
CACHE BOOL "" | ||
add_library(xnnpack-microkernels-prod STATIC IMPORTED GLOBAL) | ||
set_property( | ||
TARGET xnnpack-microkernels-prod PROPERTY IMPORTED_LOCATION | ||
${XNNPACK_MICROKERNELS_STATIC_LIB} | ||
) | ||
add_subdirectory("${XNNPACK_SOURCE_DIR}") | ||
include_directories(SYSTEM ${XNNPACK_INCLUDE_DIR}) | ||
list(APPEND xnnpack_third_party XNNPACK) | ||
install(TARGETS xnnpack-microkernels-prod | ||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} | ||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} | ||
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) | ||
add_dependencies(xnnpack-microkernels-prod XNNPACKExternalProject) | ||
|
||
set_target_properties( | ||
XNNPACK PROPERTIES INTERFACE_LINK_LIBRARIES xnnpack-microkernels-prod | ||
Comment on lines
+78
to
+79
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh shoot does this mean that any targets that link XNNPACK will also automatically link xnnpack-microkernels-prod as well? So we don't have to explicitly list both XNNPACK and xnnpack-microkernels-prod? I was trying to figure out how to do this for a while, but never figured it out. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. target_link_libraries with visibility PUBLIC or INTERFACE does this for normal libraries, but you need to do it this way for IMPORTED libraries. |
||
) | ||
|
||
install(DIRECTORY ${XNNPACK_INSTALL_DIR}/ DESTINATION ${CMAKE_INSTALL_PREFIX}) | ||
|
||
if(EXECUTORCH_XNNPACK_ENABLE_KLEIDI) | ||
install(TARGETS kleidiai | ||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} | ||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} | ||
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) | ||
add_library(kleidiai SHARED IMPORTED) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i think i merged something that might have conflict here. I just added a check if (TARGET kleidiai) before adding the library There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should be fine I think |
||
find_library( | ||
KLEIDIAI_LIBRARY kleidiai | ||
PATHS "${CMAKE_CURRENT_BINARY_DIR}/XNNPACK/kleidiai-source" | ||
) | ||
if(not KLEIDIAI_LIBRARY) | ||
message(FATAL_ERROR "Can't find KleidiAI") | ||
endif() | ||
install(FILES ${KLEIDIAI_LIBRARY} 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} | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
curious what does this rearrangment do?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just found it weird that we were mutating xnnpack_third_party in cmake/Dependencies.cmake rather than setting it all at once