Skip to content

Commit 24840e6

Browse files
committed
Test another way
1 parent 40caf28 commit 24840e6

File tree

3 files changed

+41
-47
lines changed

3 files changed

+41
-47
lines changed

CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -951,10 +951,6 @@ if(EXECUTORCH_BUILD_VULKAN)
951951
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/backends/vulkan)
952952
endif()
953953

954-
if(ANDROID)
955-
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/extension/android)
956-
endif()
957-
958954
include(Test.cmake)
959955

960956
# Print all summary

extension/android/CMakeLists.txt

Lines changed: 34 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

77
cmake_minimum_required(VERSION 3.24) # 3.24 is required for WHOLE_ARCHIVE
88

9+
project(executorch_jni)
10+
11+
include(ExternalProject)
12+
913
if(NOT EXECUTORCH_ROOT)
1014
set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../..)
1115
endif()
@@ -61,6 +65,36 @@ set_target_properties(fbjni PROPERTIES
6165
IMPORTED_LOCATION "${CMAKE_CURRENT_BINARY_DIR}/third-party/fbjni/prefab/modules/fbjni/libs/android.${ANDROID_ABI}/libfbjni.so"
6266
)
6367

68+
ExternalProject_Add(executorch_root
69+
PREFIX executorch_root
70+
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../.."
71+
CMAKE_ARGS
72+
-DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=TRUE
73+
-DCMAKE_TOOLCHAIN_FILE=${ANDROID_NDK}/build/cmake/android.toolchain.cmake
74+
-DANDROID_ABI=${ANDROID_ABI}
75+
-DANDROID_PLATFORM=android-26
76+
-DBUILD_TESTING=OFF
77+
-DCMAKE_INSTALL_PREFIX=${CMAKE_OUT}
78+
-DEXECUTORCH_ENABLE_LOGGING=ON
79+
-DEXECUTORCH_LOG_LEVEL=Info
80+
-DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=BOTH
81+
-DEXECUTORCH_BUILD_XNNPACK=ON
82+
-DEXECUTORCH_XNNPACK_SHARED_WORKSPACE=ON
83+
-DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON
84+
-DEXECUTORCH_BUILD_EXTENSION_MODULE=ON
85+
-DEXECUTORCH_BUILD_EXTENSION_RUNNER_UTIL=ON
86+
-DEXECUTORCH_BUILD_EXTENSION_TENSOR=ON
87+
-DEXECUTORCH_BUILD_KERNELS_OPTIMIZED=ON
88+
-DEXECUTORCH_BUILD_KERNELS_QUANTIZED=ON
89+
-DEXECUTORCH_BUILD_KERNELS_CUSTOM=${EXECUTORCH_BUILD_EXTENSION_LLM}
90+
-DEXECUTORCH_BUILD_LLAMA_JNI=${EXECUTORCH_BUILD_EXTENSION_LLM}
91+
-DEXECUTORCH_BUILD_NEURON=${EXECUTORCH_BUILD_NEURON}
92+
-DNEURON_BUFFER_ALLOCATOR_LIB=${NEURON_BUFFER_ALLOCATOR_LIB}
93+
-DEXECUTORCH_BUILD_QNN=${EXECUTORCH_BUILD_QNN}
94+
-DQNN_SDK_ROOT=${QNN_SDK_ROOT}
95+
-DEXECUTORCH_BUILD_VULKAN=${EXECUTORCH_BUILD_VULKAN}
96+
)
97+
6498
target_link_options_shared_lib(executorch)
6599

66100
add_library(executorch_jni SHARED jni/jni_layer.cpp jni/log.cpp)
@@ -134,44 +168,6 @@ if(EXECUTORCH_JNI_CUSTOM_LIBRARY)
134168
)
135169
endif()
136170

137-
if(EXECUTORCH_BUILD_LLAMA_JNI)
138-
target_sources(executorch_jni PRIVATE jni/jni_layer_llama.cpp jni/log.cpp)
139-
list(APPEND link_libraries llama_runner llava_runner)
140-
target_compile_definitions(executorch_jni PUBLIC EXECUTORCH_BUILD_LLAMA_JNI=1)
141-
add_subdirectory(
142-
${EXECUTORCH_ROOT}/examples/models/llava/runner
143-
${CMAKE_CURRENT_BINARY_DIR}/examples/models/llava/runner
144-
)
145-
146-
add_subdirectory(
147-
${EXECUTORCH_ROOT}/examples/models/llama/runner
148-
${CMAKE_CURRENT_BINARY_DIR}/examples/models/llama/runner
149-
)
150-
151-
if(NEURON_BUFFER_ALLOCATOR_LIB)
152-
target_sources(
153-
executorch_jni PRIVATE
154-
${EXECUTORCH_ROOT}/examples/mediatek/executor_runner/mtk_llama_runner.cpp
155-
${EXECUTORCH_ROOT}/examples/mediatek/executor_runner/llama_runner/LlamaModelChunk.cpp
156-
${EXECUTORCH_ROOT}/examples/mediatek/executor_runner/llama_runner/LlamaRuntime.cpp
157-
${EXECUTORCH_ROOT}/examples/mediatek/executor_runner/llama_runner/ModelChunk.cpp
158-
${EXECUTORCH_ROOT}/examples/mediatek/executor_runner/llama_runner/MultiModelLoader.cpp
159-
${EXECUTORCH_ROOT}/examples/mediatek/executor_runner/llama_runner/llm_helper/mask_builder.cpp
160-
${EXECUTORCH_ROOT}/examples/mediatek/executor_runner/llama_runner/llm_helper/rotary_embedding.cpp
161-
${EXECUTORCH_ROOT}/examples/mediatek/executor_runner/llama_runner/llm_helper/token_embedding.cpp
162-
)
163-
target_include_directories(
164-
executorch_jni PRIVATE
165-
${EXECUTORCH_ROOT}/examples/mediatek/executor_runner/
166-
${EXECUTORCH_ROOT}/examples/mediatek/executor_runner/llama_runner
167-
)
168-
add_library(libneuron_buffer_allocator SHARED IMPORTED)
169-
set_property(TARGET libneuron_buffer_allocator PROPERTY IMPORTED_LOCATION ${NEURON_BUFFER_ALLOCATOR_LIB})
170-
list(APPEND link_libraries neuron_backend libneuron_buffer_allocator)
171-
target_compile_definitions(executorch_jni PRIVATE EXECUTORCH_BUILD_MEDIATEK=1)
172-
endif()
173-
endif()
174-
175171
target_include_directories(
176172
executorch_jni PRIVATE ${_common_include_directories}
177173
"${CMAKE_CURRENT_BINARY_DIR}/third-party/fbjni/prefab/modules/fbjni/include/"

scripts/build_android_library.sh

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,15 @@ build_android_native_library() {
3434

3535
EXECUTORCH_BUILD_VULKAN="${EXECUTORCH_BUILD_VULKAN:-OFF}"
3636

37-
cmake . -DCMAKE_INSTALL_PREFIX="${CMAKE_OUT}" \
38-
-DCMAKE_TOOLCHAIN_FILE="${ANDROID_NDK}/build/cmake/android.toolchain.cmake" \
37+
cmake extension/android \
38+
-DCMAKE_TOOLCHAIN_FILE=${ANDROID_NDK}/build/cmake/android.toolchain.cmake \
3939
-DANDROID_ABI="${ANDROID_ABI}" \
4040
-DANDROID_PLATFORM=android-26 \
4141
-DBUILD_TESTING=OFF \
42+
-DCMAKE_INSTALL_PREFIX="${CMAKE_OUT}" \
4243
-DEXECUTORCH_ENABLE_LOGGING=ON \
4344
-DEXECUTORCH_LOG_LEVEL=Info \
45+
-DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=BOTH \
4446
-DEXECUTORCH_BUILD_XNNPACK=ON \
4547
-DEXECUTORCH_XNNPACK_SHARED_WORKSPACE=ON \
4648
-DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON \
@@ -56,15 +58,15 @@ build_android_native_library() {
5658
-DEXECUTORCH_BUILD_QNN="${EXECUTORCH_BUILD_QNN}" \
5759
-DQNN_SDK_ROOT="${QNN_SDK_ROOT}" \
5860
-DEXECUTORCH_BUILD_VULKAN="${EXECUTORCH_BUILD_VULKAN}" \
59-
-DCMAKE_BUILD_TYPE="${EXECUTORCH_CMAKE_BUILD_TYPE}" \
60-
-B"${CMAKE_OUT}"
61+
-B"${CMAKE_OUT}"/extension/android
6162

6263
if [ "$(uname)" == "Darwin" ]; then
6364
CMAKE_JOBS=$(( $(sysctl -n hw.ncpu) - 1 ))
6465
else
6566
CMAKE_JOBS=$(( $(nproc) - 1 ))
6667
fi
67-
cmake --build "${CMAKE_OUT}" -j "${CMAKE_JOBS}" --target install --config "${EXECUTORCH_CMAKE_BUILD_TYPE}"
68+
69+
cmake --build "${CMAKE_OUT}"/extension/android -j "${CMAKE_JOBS}" --config "${EXECUTORCH_CMAKE_BUILD_TYPE}"
6870

6971
# Copy artifacts to ABI specific directory
7072
local SO_STAGE_DIR="cmake-out-android-so/${ANDROID_ABI}"

0 commit comments

Comments
 (0)