-
Notifications
You must be signed in to change notification settings - Fork 0
AQLM custom kernels for Android #1
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: v0.3.0_branch
Are you sure you want to change the base?
Changes from all commits
a562b76
7c3e191
db94aba
97c86e3
008f9c3
0645fee
4389601
cade4c3
3ad5904
94d4544
3156fc2
91b1378
8d1053b
b478f06
2bfd66f
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 |
---|---|---|
|
@@ -467,6 +467,9 @@ if(EXECUTORCH_BUILD_KERNELS_CUSTOM) | |
add_subdirectory( | ||
${CMAKE_CURRENT_SOURCE_DIR}/examples/models/llama2/custom_ops | ||
) | ||
add_subdirectory( | ||
${CMAKE_CURRENT_SOURCE_DIR}/examples/models/llama2/aqlm | ||
) | ||
endif() | ||
|
||
if(EXECUTORCH_BUILD_KERNELS_OPTIMIZED) | ||
|
@@ -633,13 +636,16 @@ if(EXECUTORCH_BUILD_PYBIND) | |
# TODO(larryliu): Fix macOS 2 dylibs having 2 sets of static variables issue | ||
if(EXECUTORCH_BUILD_KERNELS_CUSTOM_AOT AND NOT APPLE) | ||
list(APPEND _dep_libs custom_ops_aot_lib) | ||
list(APPEND _dep_libs aqlm_aot_lib) | ||
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. Add torch bindings for AQLM to the |
||
endif() | ||
# TODO(laryliu): Fix linux duplicate registation problem. In GH CI worker | ||
# libcustom_ops.a doesn't dedup with the one indirectly linked from | ||
# libcustom_ops_aot_lib.a | ||
if(EXECUTORCH_BUILD_KERNELS_CUSTOM AND APPLE) | ||
target_link_options_shared_lib(custom_ops) | ||
list(APPEND _dep_libs custom_ops) | ||
target_link_options_shared_lib(aqlm) | ||
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. Force the linkage of core |
||
list(APPEND _dep_libs aqlm) | ||
endif() | ||
# compile options for pybind | ||
set(_pybind_compile_options | ||
|
@@ -699,7 +705,7 @@ if(EXECUTORCH_BUILD_PYBIND) | |
PROPERTIES # Assume that this library will be installed in | ||
# `site-packages/executorch/extension/pybindings`, and that | ||
# the custom_ops_aot_lib should be found with relative path. | ||
BUILD_RPATH "$ORIGIN:$ORIGIN/../../examples/models/llama2/custom_ops" | ||
BUILD_RPATH "$ORIGIN:$ORIGIN/../../examples/models/llama2/custom_ops:$ORIGIN/../../examples/models/llama2/aqlm" | ||
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. IDK |
||
) | ||
endif() | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -87,6 +87,7 @@ endif() | |
# custom ops library | ||
if(EXECUTORCH_BUILD_KERNELS_CUSTOM) | ||
add_subdirectory(custom_ops) | ||
add_subdirectory(aqlm) | ||
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. Traverse the subdirectory containing the AQLM code. |
||
endif() | ||
|
||
# llama_runner library | ||
|
@@ -129,6 +130,9 @@ list(APPEND link_libraries quantized_kernels quantized_ops_lib) | |
if(EXECUTORCH_BUILD_KERNELS_CUSTOM) | ||
target_link_options_shared_lib(custom_ops) | ||
list(APPEND link_libraries custom_ops) | ||
|
||
target_link_options_shared_lib(aqlm) | ||
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. Force the linkage of core |
||
list(APPEND link_libraries aqlm) | ||
endif() | ||
|
||
set(XNNPACK_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../../../backends/xnnpack) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
# Copyright (c) Meta Platforms, Inc. and affiliates. | ||
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. Mostly copied from |
||
# All rights reserved. | ||
# | ||
# This source code is licensed under the BSD-style license found in the | ||
# LICENSE file in the root directory of this source tree. | ||
|
||
cmake_minimum_required(VERSION 3.19) | ||
|
||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON) | ||
if(NOT CMAKE_CXX_STANDARD) | ||
set(CMAKE_CXX_STANDARD 17) | ||
endif() | ||
|
||
if(NOT PYTHON_EXECUTABLE) | ||
set(PYTHON_EXECUTABLE python3) | ||
endif() | ||
|
||
# Source root directory for executorch. | ||
if(NOT EXECUTORCH_ROOT) | ||
set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../../../..) | ||
endif() | ||
|
||
set(_common_compile_options -Wno-deprecated-declarations -fPIC) | ||
|
||
include(${EXECUTORCH_ROOT}/build/Utils.cmake) | ||
include(${EXECUTORCH_ROOT}/build/Codegen.cmake) | ||
|
||
# | ||
# The `_<target>_srcs` lists are defined by including ${EXECUTORCH_SRCS_FILE}. | ||
# | ||
set(EXECUTORCH_SRCS_FILE | ||
"${CMAKE_CURRENT_BINARY_DIR}/../../../../executorch_srcs.cmake" | ||
) | ||
|
||
extract_sources(${EXECUTORCH_SRCS_FILE}) | ||
|
||
include(${EXECUTORCH_SRCS_FILE}) | ||
|
||
# Let files say "include <executorch/path/to/header.h>". | ||
set(_common_include_directories ${EXECUTORCH_ROOT}/..) | ||
|
||
# Custom op libraries | ||
set(aqlm_libs executorch_no_prim_ops) | ||
list(APPEND aqlm_libs pthreadpool) | ||
list(APPEND aqlm_libs cpuinfo) | ||
list(APPEND aqlm_libs cpublas) | ||
list(APPEND aqlm_libs eigen_blas) | ||
|
||
set(_aqlm__srcs examples/models/llama2/aqlm/lut_kernel.h examples/models/llama2/aqlm/lut_kernel.cpp) | ||
list(TRANSFORM _aqlm__srcs PREPEND "${EXECUTORCH_ROOT}/") | ||
|
||
|
||
|
||
message("HERE: AQLM SOURCES: ${_aqlm__srcs}") | ||
|
||
# TODO: Consider moving xnnpack/threadpool in a separate lib since it's now used | ||
# by custom ops too. | ||
if(NOT EXECUTORCH_BUILD_XNNPACK) | ||
list( | ||
APPEND | ||
_aqlm__srcs | ||
"${CMAKE_CURRENT_SOURCE_DIR}/../../../../backends/xnnpack/threadpool/threadpool.cpp" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/../../../../backends/xnnpack/threadpool/threadpool_guard.cpp" | ||
) | ||
else() | ||
list(APPEND aqlm_libs xnnpack_backend) | ||
endif() | ||
|
||
find_package(OpenMP REQUIRED) | ||
# list(APPEND aqlm_libs OpenMP::OpenMP_CXX) | ||
list(APPEND aqlm_libs omp) | ||
|
||
add_library(aqlm ${_aqlm__srcs}) | ||
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. A library containing core AQLM ops and a |
||
|
||
# Enable optimization | ||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}") | ||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}") | ||
|
||
target_include_directories(aqlm PUBLIC "${_common_include_directories}") | ||
target_include_directories( | ||
aqlm PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/../../../../include" | ||
) | ||
target_link_libraries(aqlm PUBLIC ${aqlm_libs} -fopenmp -static-openmp) | ||
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. Additional flags for OMP to link on Android |
||
|
||
target_compile_options( | ||
aqlm PUBLIC ${_common_compile_options} -DET_USE_THREADPOOL | ||
) | ||
|
||
install(TARGETS aqlm DESTINATION lib) | ||
|
||
if(EXECUTORCH_BUILD_KERNELS_CUSTOM_AOT) | ||
# Add a AOT library | ||
find_package(Torch CONFIG REQUIRED) | ||
add_library( | ||
aqlm_aot_lib SHARED ${CMAKE_CURRENT_SOURCE_DIR}/lut_kernel_pytorch.cpp | ||
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. A library to be loaded into PyTorch with |
||
) | ||
target_include_directories( | ||
aqlm_aot_lib PUBLIC "${_common_include_directories}" | ||
) | ||
target_include_directories( | ||
aqlm_aot_lib | ||
PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/../../../../include" | ||
) | ||
target_link_libraries(aqlm_aot_lib PUBLIC aqlm torch) | ||
target_compile_options( | ||
aqlm_aot_lib PUBLIC -Wno-deprecated-declarations -fPIC -frtti | ||
-fexceptions | ||
) | ||
|
||
install(TARGETS aqlm_aot_lib DESTINATION lib) | ||
endif() |
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.
Instruct CMake to traverse the subdirectory containing the AQLM kernels. Keeping the directory in the same CMake tree makes it easier to link those cutom operators libs.