-
Notifications
You must be signed in to change notification settings - Fork 10k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
zhou.weiguo
committed
Apr 25, 2024
1 parent
180ab5f
commit eff9669
Showing
9 changed files
with
242 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
out | ||
android-ndk-r26c* | ||
test-qnn* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
cmake_minimum_required(VERSION 3.22.1) | ||
project(ggml-qnn) | ||
|
||
set(CMAKE_VERBOSE_MAKEFILE on) | ||
set(CMAKE_CXX_STANDARD 17) | ||
set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
set(CMAKE_POSITION_INDEPENDENT_CODE ON) | ||
|
||
set(TARGET_SNAPDRAGON_8_GEN3 OFF) | ||
|
||
set(LLAMACPP_SRC_PATH ${PROJECT_ROOT_PATH}) | ||
set(QNN_INC_PATH ${QNN_SDK_PATH}/include/QNN) | ||
set(QNN_LIB_PATH ${QNN_SDK_PATH}/lib/aarch64-android) | ||
|
||
include_directories(${QNN_INC_PATH}) | ||
include_directories(${LLAMACPP_SRC_PATH}) | ||
include_directories(${LLAMACPP_SRC_PATH}/common) | ||
|
||
set(SOURCE_FILES | ||
${LLAMACPP_SRC_PATH}/ggml.c | ||
${LLAMACPP_SRC_PATH}/ggml-alloc.c | ||
${LLAMACPP_SRC_PATH}/ggml-backend.c | ||
${LLAMACPP_SRC_PATH}/ggml-quants.c | ||
${LLAMACPP_SRC_PATH}/ggml-qnn.cpp | ||
${LLAMACPP_SRC_PATH}/tests/test-backend-ops.cpp | ||
) | ||
|
||
|
||
message("PROJECT_ROOT_PATH : ${PROJECT_ROOT_PATH}") | ||
message("LLAMACPP_SRC_PATH : ${LLAMACPP_SRC_PATH}") | ||
message("QNN_SDK_PATH : ${QNN_SDK_PATH}") | ||
message("QNN_INC_PATH : ${QNN_INC_PATH}") | ||
message("QNN_LIB_PATH : ${QNN_LIB_PATH}") | ||
message("target name : ${TARGET_NAME}") | ||
|
||
|
||
add_definitions(-DTARGET_ANDROID) | ||
add_definitions(-D__ARM_NEON) | ||
add_definitions(-DGGML_USE_QNN) | ||
|
||
add_definitions(-DNDEBUG) | ||
add_definitions(-O3) | ||
|
||
if (TARGET_SNAPDRAGON_8_GEN3) | ||
add_definitions(-march=armv8.7-a) | ||
add_definitions(-mcpu=cortex-x1) | ||
add_definitions(-mtune=cortex-x1) | ||
|
||
else() | ||
|
||
# the below build optimization might be works well on ALL mainstream Android phones | ||
add_definitions(-mcpu=cortex-a72) | ||
|
||
endif() | ||
|
||
add_compile_options("-Wall" "-Wno-sign-compare") | ||
|
||
if (GGML_JNI_QNN) | ||
file(GLOB allPrebuiltQNNLibs "${QNN_LIB_PATH}/libQnn*.so") | ||
|
||
#file(COPY ${allPrebuiltQNNLibs} DESTINATION ${PREBUILT_LIB_PATH}/ ) | ||
|
||
endif() | ||
|
||
find_library(LOG_LIB log) | ||
|
||
add_library(QNNCpu | ||
SHARED | ||
IMPORTED) | ||
|
||
set_target_properties(QNNCpu | ||
PROPERTIES | ||
IMPORTED_LOCATION | ||
${PREBUILT_LIB_PATH}/libQnnCpu.so) | ||
|
||
link_libraries(${LOG_LIB} android) | ||
|
||
add_executable(${TARGET_NAME} | ||
${SOURCE_FILES} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
#modify following lines to adapt to local dev envs | ||
PROJECT_ROOT_PATH=~/github/llama.cpp/ | ||
#https://qpm.qualcomm.com/#/main/tools/details/qualcomm_ai_engine_direct | ||
#https://developer.qualcomm.com/software/hexagon-dsp-sdk/tools | ||
QNN_SDK_PATH=/opt/qcom/aistack/qnn/2.20.0.240223/ | ||
|
||
|
||
ANDROID_NDK=`pwd`/android-ndk-r26c | ||
TARGET=ggml-qnn-test | ||
|
||
|
||
function dump_vars() | ||
{ | ||
echo -e "PROJECT_ROOT_PATH: ${PROJECT_ROOT_PATH}" | ||
echo -e "ANDROID_NDK: ${ANDROID_NDK}" | ||
echo -e "QNN_SDK_PATH: ${QNN_SDK_PATH}" | ||
} | ||
|
||
|
||
function show_pwd() | ||
{ | ||
echo -e "current working path:$(pwd)\n" | ||
} | ||
|
||
|
||
function check_and_download_ndk() | ||
{ | ||
is_android_ndk_exist=1 | ||
|
||
if [ ! -d ${ANDROID_NDK} ]; then | ||
is_android_ndk_exist=0 | ||
fi | ||
|
||
if [ ! -f ${ANDROID_NDK}/build/cmake/android.toolchain.cmake ]; then | ||
is_android_ndk_exist=0 | ||
fi | ||
|
||
if [ ${is_android_ndk_exist} -eq 0 ]; then | ||
|
||
if [ ! -f android-ndk-r26c-linux.zip ]; then | ||
wget --no-config --quiet --show-progress -O android-ndk-r26c-linux.zip https://dl.google.com/android/repository/android-ndk-r26c-linux.zip | ||
fi | ||
|
||
unzip android-ndk-r26c-linux.zip | ||
|
||
if [ $? -ne 0 ]; then | ||
printf "failed to download android ndk to %s \n" "${ANDROID_NDK}" | ||
exit 1 | ||
fi | ||
|
||
printf "android ndk saved to ${ANDROID_NDK} \n\n" | ||
else | ||
printf "android ndk already exist:${ANDROID_NDK} \n\n" | ||
fi | ||
} | ||
|
||
|
||
function build_arm64 | ||
{ | ||
cmake -H. -B./out/arm64-v8a -DPROJECT_ROOT_PATH=${PROJECT_ROOT_PATH} -DTARGET_NAME=${TARGET} -DCMAKE_BUILD_TYPE=${PROJECT_BUILD_TYPE} -DANDROID_ABI=arm64-v8a -DANDROID_PLATFORM=${ANDROID_PLATFORM} -DANDROID_NDK=${ANDROID_NDK} -DCMAKE_TOOLCHAIN_FILE=${ANDROID_NDK}/build/cmake/android.toolchain.cmake -DQNN_SDK_PATH=${QNN_SDK_PATH} | ||
|
||
cd ./out/arm64-v8a | ||
make | ||
|
||
ls -lah ${TARGET} | ||
/bin/cp ${TARGET} ../../ | ||
cd - | ||
} | ||
|
||
|
||
function remove_temp_dir() | ||
{ | ||
if [ -d out ]; then | ||
echo "remove out directory in `pwd`" | ||
rm -rf out | ||
fi | ||
} | ||
|
||
|
||
|
||
show_pwd | ||
check_and_download_ndk | ||
dump_vars | ||
remove_temp_dir | ||
build_arm64 |
Oops, something went wrong.