Skip to content

Commit ce67b54

Browse files
kirklandsignfacebook-github-bot
authored andcommitted
MTK Android library integration (#6001)
Summary: Fix some cmake rules, code, and trigger. Pull Request resolved: #6001 Reviewed By: cccclai Differential Revision: D64068879 Pulled By: kirklandsign fbshipit-source-id: 07b63d362f43ed1d4b8337c18efa5b539839efe3
1 parent aa852cc commit ce67b54

File tree

4 files changed

+17
-5
lines changed

4 files changed

+17
-5
lines changed

backends/mediatek/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ include_directories(BEFORE ${CMAKE_CURRENT_SOURCE_DIR}/runtime/include)
2525

2626
# targets
2727
add_library(neuron_backend SHARED)
28+
target_compile_options(neuron_backend PRIVATE "-frtti" "-fexceptions")
2829
target_link_libraries(neuron_backend
2930
PRIVATE
3031
executorch_core
31-
portable_ops_lib
3232
android
3333
log
3434
${NEURON_BUFFER_ALLOCATOR_LIB}

backends/mediatek/runtime/include/NeuronLog.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
#pragma once
1010

11-
#include <api/NeuronAdapter.h>
11+
#include "api/NeuronAdapter.h"
1212

1313
#include <android/log.h>
1414
#include <sys/system_properties.h>

build/build_android_llm_demo.sh

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ build_android_native_library() {
3030
cmake . -DCMAKE_INSTALL_PREFIX="${CMAKE_OUT}" \
3131
-DCMAKE_TOOLCHAIN_FILE="${ANDROID_NDK}/build/cmake/android.toolchain.cmake" \
3232
-DANDROID_ABI="${ANDROID_ABI}" \
33-
-DANDROID_PLATFORM=android-23 \
33+
-DANDROID_PLATFORM=android-26 \
3434
-DEXECUTORCH_ENABLE_LOGGING=ON \
3535
-DEXECUTORCH_LOG_LEVEL=Info \
3636
-DEXECUTORCH_BUILD_XNNPACK=ON \
@@ -42,6 +42,8 @@ build_android_native_library() {
4242
-DEXECUTORCH_BUILD_KERNELS_OPTIMIZED=ON \
4343
-DEXECUTORCH_BUILD_KERNELS_QUANTIZED=ON \
4444
-DEXECUTORCH_BUILD_KERNELS_CUSTOM=ON \
45+
-DEXECUTORCH_BUILD_NEURON="${EXECUTORCH_BUILD_NEURON}" \
46+
-DNEURON_BUFFER_ALLOCATOR_LIB="${NEURON_BUFFER_ALLOCATOR_LIB}" \
4547
-DEXECUTORCH_BUILD_QNN="${EXECUTORCH_BUILD_QNN}" \
4648
-DQNN_SDK_ROOT="${QNN_SDK_ROOT}" \
4749
-DCMAKE_BUILD_TYPE=Release \
@@ -57,10 +59,12 @@ build_android_native_library() {
5759
cmake extension/android \
5860
-DCMAKE_TOOLCHAIN_FILE=${ANDROID_NDK}/build/cmake/android.toolchain.cmake \
5961
-DANDROID_ABI="${ANDROID_ABI}" \
60-
-DANDROID_PLATFORM=android-23 \
62+
-DANDROID_PLATFORM=android-26 \
6163
-DCMAKE_INSTALL_PREFIX="${CMAKE_OUT}" \
6264
-DEXECUTORCH_ENABLE_LOGGING=ON \
6365
-DEXECUTORCH_LOG_LEVEL=Info \
66+
-DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=BOTH \
67+
-DNEURON_BUFFER_ALLOCATOR_LIB="$NEURON_BUFFER_ALLOCATOR_LIB" \
6468
-DEXECUTORCH_BUILD_KERNELS_CUSTOM=ON \
6569
-DEXECUTORCH_BUILD_LLAMA_JNI=ON \
6670
-DCMAKE_BUILD_TYPE=Release \
@@ -84,6 +88,13 @@ build_android_native_library() {
8488
cp "${QNN_SDK_ROOT}"/lib/hexagon-v73/unsigned/libQnnHtpV73Skel.so "${BUILD_AAR_DIR}/jni/${ANDROID_ABI}/"
8589
cp "${QNN_SDK_ROOT}"/lib/hexagon-v75/unsigned/libQnnHtpV75Skel.so "${BUILD_AAR_DIR}/jni/${ANDROID_ABI}/"
8690
fi
91+
92+
# Copy MTK related so library
93+
if [ -n "$NEURON_BUFFER_ALLOCATOR_LIB" ] && [ "$ANDROID_ABI" == "arm64-v8a" ]; then
94+
cp "${CMAKE_OUT}"/backends/mediatek/libneuron_backend.so ${BUILD_AAR_DIR}/jni/${ANDROID_ABI}/
95+
cp "$NEURON_BUFFER_ALLOCATOR_LIB"/libneuron_buffer_allocator.so ${BUILD_AAR_DIR}/jni/${ANDROID_ABI}/
96+
cp "$NEURON_BUFFER_ALLOCATOR_LIB"/libneuronusdk_adapter.mtk.so ${BUILD_AAR_DIR}/jni/${ANDROID_ABI}/
97+
fi
8798
}
8899

89100
build_aar() {
@@ -96,7 +107,7 @@ build_aar() {
96107
# between Java and JNI
97108
find jni -type f -name "libexecutorch_jni.so" -exec bash -c 'mv "$1" "${1/_jni/}"' bash {} \;
98109
# Zip all necessary files into the AAR file
99-
zip -r executorch.aar libs jni/*/libexecutorch.so jni/*/libqnn*.so jni/*/libQnn*.so AndroidManifest.xml
110+
zip -r executorch.aar libs jni/*/libexecutorch.so jni/*/libqnn*.so jni/*/libQnn*.so jni/*/libneuron_backend.so jni/*/libneuron_buffer_allocator.so jni/*/libneuronusdk_adapter.mtk.so AndroidManifest.xml
100111
cp executorch.aar executorch-llama.aar
101112
popd
102113
}

build/executorch-config.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ set(lib_list
4242
${FLATCCRT_LIB}
4343
coremldelegate
4444
mpsdelegate
45+
neuron_backend
4546
qnn_executorch_backend
4647
portable_ops_lib
4748
extension_module

0 commit comments

Comments
 (0)