Skip to content

Commit 24b8943

Browse files
author
Mateusz Kopciński
committed
minor cleanup, changed the configurable threads to aarch64 only
1 parent 6c50f12 commit 24b8943

File tree

8 files changed

+35
-28
lines changed

8 files changed

+35
-28
lines changed

apps/llm/android/.kotlin/errors/errors-1754380687676.log

Lines changed: 0 additions & 4 deletions
This file was deleted.

packages/react-native-executorch/android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def reactNativeArchitectures() {
2525
def value = rootProject.getProperties().get("reactNativeArchitectures")
2626
// react-native-executorch supports only these architectures. This is due to
2727
// Executorch not supporting anything else.
28-
def defaultArchitectures = ["arm64-v8a"]
28+
def defaultArchitectures = ["x86_64", "arm64-v8a"]
2929
if(!value) {
3030
return defaultArchitectures
3131
}

packages/react-native-executorch/android/src/main/cpp/CMakeLists.txt

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,6 @@ set(RN_VERSION_LINK_LIBRARIES
3333
)
3434

3535
# Dependencies:
36-
# ------- pthreadpool -------
37-
add_library(pthreadpool SHARED IMPORTED)
38-
39-
set_target_properties(pthreadpool PROPERTIES
40-
IMPORTED_LOCATION "${LIBS_DIR}/pthreadpool/${ANDROID_ABI}/libpthreadpool.so"
41-
INTERFACE_INCLUDE_DIRECTORIES "${LIBS_DIR}/../../include/pthreadpool/")
42-
# INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../third-party/executorch/backends/xnnpack/third-party/pthreadpool/include")
43-
44-
# ------- cpuinfo -------
45-
add_library(cpuinfo SHARED IMPORTED)
46-
47-
set_target_properties(cpuinfo PROPERTIES
48-
IMPORTED_LOCATION "${LIBS_DIR}/cpuinfo/${ANDROID_ABI}/libcpuinfo.so"
49-
INTERFACE_INCLUDE_DIRECTORIES "${LIBS_DIR}/../../include/cpu-info/")
50-
# INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../third-party/executorch/backends/xnnpack/third-party/cpuinfo/include")
5136

5237
# ------- Executorch -------
5338

@@ -56,6 +41,29 @@ add_library(executorch SHARED IMPORTED)
5641
set_target_properties(executorch PROPERTIES
5742
IMPORTED_LOCATION "${LIBS_DIR}/executorch/${ANDROID_ABI}/libexecutorch.so")
5843

44+
45+
if(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64")
46+
target_compile_definitions(react-native-executorch PRIVATE ARCH_ARM64)
47+
48+
# ------- pthreadpool -------
49+
add_library(pthreadpool SHARED IMPORTED)
50+
51+
set_target_properties(pthreadpool PROPERTIES
52+
IMPORTED_LOCATION "${LIBS_DIR}/pthreadpool/${ANDROID_ABI}/libpthreadpool.so"
53+
INTERFACE_INCLUDE_DIRECTORIES "${LIBS_DIR}/../../include/pthreadpool/")
54+
55+
# ------- cpuinfo -------
56+
add_library(cpuinfo SHARED IMPORTED)
57+
58+
set_target_properties(cpuinfo PROPERTIES
59+
IMPORTED_LOCATION "${LIBS_DIR}/cpuinfo/${ANDROID_ABI}/libcpuinfo.so"
60+
INTERFACE_INCLUDE_DIRECTORIES "${LIBS_DIR}/../../include/cpuinfo/")
61+
set(EXECUTORCH_LIBS
62+
"pthreadpool"
63+
"cpuinfo"
64+
)
65+
endif()
66+
5967
# ------- OpenCV -------
6068

6169
set(OPENCV_LIBS
@@ -86,6 +94,5 @@ target_link_libraries(
8694
${OPENCV_LIBS}
8795
${OPENCV_THIRD_PARTY_LIBS}
8896
executorch
89-
pthreadpool
90-
cpuinfo
97+
${EXECUTORCH_LIBS}
9198
)

packages/react-native-executorch/common/rnexecutorch/RnExecutorchInstaller.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
#include <rnexecutorch/models/speech_to_text/SpeechToText.h>
1414
#include <rnexecutorch/models/style_transfer/StyleTransfer.h>
1515
#include <rnexecutorch/models/vertical_ocr/VerticalOCR.h>
16-
#ifdef __ANDROID__
16+
17+
#ifdef defined(__ANDROID__) && defined(__aarch64__)
18+
#include <algorithm>
1719
#include <executorch/extension/threadpool/cpuinfo_utils.h>
1820
#include <executorch/extension/threadpool/threadpool.h>
1921
#endif
@@ -87,9 +89,9 @@ void RnExecutorchInstaller::injectJSIBindings(
8789
RnExecutorchInstaller::loadModel<SpeechToText>(jsiRuntime, jsCallInvoker,
8890
"loadSpeechToText"));
8991

90-
#ifdef __ANDROID__
91-
auto num_of_cores =
92-
::executorch::extension::cpuinfo::get_num_performant_cores();
92+
#ifdef defined(__ANDROID__) && defined(__aarch64__)
93+
auto num_of_cores = std::min(
94+
::executorch::extension::cpuinfo::get_num_performant_cores(), 3u);
9395
::executorch::extension::threadpool::get_threadpool()
9496
->_unsafe_reset_threadpool(num_of_cores);
9597
log(LOG_LEVEL::Info, "Configuring xnnpack for ", num_of_cores, "threads");

packages/react-native-executorch/common/rnexecutorch/models/llm/LLM.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
#include "LLM.h"
22

33
#include <executorch/extension/tensor/tensor.h>
4-
#include <executorch/extension/threadpool/cpuinfo_utils.h>
5-
#include <executorch/extension/threadpool/threadpool.h>
64
#include <filesystem>
75
#include <rnexecutorch/Log.h>
86

packages/react-native-executorch/third-party/include/cpu-info/cpuinfo.h renamed to packages/react-native-executorch/third-party/include/cpuinfo/cpuinfo.h

File renamed without changes.

packages/react-native-executorch/third-party/include/executorch/extension/threadpool/cpuinfo_utils.h renamed to packages/react-native-executorch/third-party/include/executorch/extension/cpuinfo/cpuinfo_utils.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88

99
#pragma once
10+
#ifdef defined(__ANDROID__) && defined(__aarch64__)
1011

1112
#include <cpuinfo.h>
1213

@@ -22,3 +23,4 @@ namespace torch::executorch::cpuinfo { // DEPRECATED
2223
// the namespace `torch::executorch` instead of `torch::executor`.
2324
using ::executorch::extension::cpuinfo::get_num_performant_cores; // DEPRECATED
2425
} // namespace torch::executorch::cpuinfo
26+
#endif

packages/react-native-executorch/third-party/include/executorch/extension/threadpool/threadpool.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88

99
#pragma once
10+
#ifdef defined(__ANDROID__) && defined(__aarch64__)
1011

1112
#include <functional>
1213
#include <memory>
@@ -90,3 +91,4 @@ using ::executorch::extension::threadpool::get_pthreadpool; // DEPRECATED
9091
using ::executorch::extension::threadpool::get_threadpool; // DEPRECATED
9192
using ::executorch::extension::threadpool::ThreadPool; // DEPRECATED
9293
} // namespace torch::executorch::threadpool
94+
#endif

0 commit comments

Comments
 (0)