Skip to content

Commit 6c50f12

Browse files
author
Mateusz Kopciński
committed
cleaned up jitpack and build for android, added dynamic threadpool settings
1 parent 6d7d336 commit 6c50f12

File tree

4 files changed

+25
-21
lines changed

4 files changed

+25
-21
lines changed

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

Lines changed: 2 additions & 8 deletions
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 = ["x86_64", "arm64-v8a"]
28+
def defaultArchitectures = ["arm64-v8a"]
2929
if(!value) {
3030
return defaultArchitectures
3131
}
@@ -110,12 +110,6 @@ android {
110110
}
111111
}
112112

113-
packagingOptions {
114-
excludes = [
115-
"**/libexecutorch.so"
116-
]
117-
}
118-
119113
compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")
120114

121115
defaultConfig {
@@ -173,7 +167,7 @@ dependencies {
173167
implementation "com.facebook.react:react-native:+"
174168
implementation 'com.facebook.fbjni:fbjni:0.6.0'
175169
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
176-
implementation("com.github.software-mansion:react-native-executorch:main-SNAPSHOT")
170+
implementation files('libs/classes.jar')
177171
implementation 'org.opencv:opencv:4.10.0'
178172
implementation("com.squareup.okhttp3:okhttp:4.9.2")
179173
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,16 @@ set(RN_VERSION_LINK_LIBRARIES
3737
add_library(pthreadpool SHARED IMPORTED)
3838

3939
set_target_properties(pthreadpool PROPERTIES
40-
IMPORTED_LOCATION "${LIBS_DIR}/pthreadpool/${ANDROID_ABI}/libpthreadpool.so")
40+
IMPORTED_LOCATION "${LIBS_DIR}/pthreadpool/${ANDROID_ABI}/libpthreadpool.so"
41+
INTERFACE_INCLUDE_DIRECTORIES "${LIBS_DIR}/../../include/pthreadpool/")
4142
# INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../third-party/executorch/backends/xnnpack/third-party/pthreadpool/include")
4243

4344
# ------- cpuinfo -------
4445
add_library(cpuinfo SHARED IMPORTED)
4546

4647
set_target_properties(cpuinfo PROPERTIES
47-
IMPORTED_LOCATION "${LIBS_DIR}/cpuinfo/${ANDROID_ABI}/libcpuinfo.so")
48+
IMPORTED_LOCATION "${LIBS_DIR}/cpuinfo/${ANDROID_ABI}/libcpuinfo.so"
49+
INTERFACE_INCLUDE_DIRECTORIES "${LIBS_DIR}/../../include/cpu-info/")
4850
# INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../third-party/executorch/backends/xnnpack/third-party/cpuinfo/include")
4951

5052
# ------- Executorch -------

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

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "RnExecutorchInstaller.h"
22

3+
#include <rnexecutorch/Log.h>
34
#include <rnexecutorch/TokenizerModule.h>
45
#include <rnexecutorch/host_objects/JsiConversions.h>
56
#include <rnexecutorch/models/classification/Classification.h>
@@ -12,6 +13,10 @@
1213
#include <rnexecutorch/models/speech_to_text/SpeechToText.h>
1314
#include <rnexecutorch/models/style_transfer/StyleTransfer.h>
1415
#include <rnexecutorch/models/vertical_ocr/VerticalOCR.h>
16+
#ifdef __ANDROID__
17+
#include <executorch/extension/threadpool/cpuinfo_utils.h>
18+
#include <executorch/extension/threadpool/threadpool.h>
19+
#endif
1520

1621
namespace rnexecutorch {
1722

@@ -65,10 +70,6 @@ void RnExecutorchInstaller::injectJSIBindings(
6570
RnExecutorchInstaller::loadModel<TextEmbeddings>(
6671
jsiRuntime, jsCallInvoker, "loadTextEmbeddings"));
6772

68-
jsiRuntime->global().setProperty(
69-
*jsiRuntime, "loadSpeechToText",
70-
RnExecutorchInstaller::loadModel<SpeechToText>(jsiRuntime, jsCallInvoker,
71-
"loadSpeechToText"));
7273
jsiRuntime->global().setProperty(*jsiRuntime, "loadLLM",
7374
RnExecutorchInstaller::loadModel<LLM>(
7475
jsiRuntime, jsCallInvoker, "loadLLM"));
@@ -80,5 +81,19 @@ void RnExecutorchInstaller::injectJSIBindings(
8081
*jsiRuntime, "loadVerticalOCR",
8182
RnExecutorchInstaller::loadModel<VerticalOCR>(jsiRuntime, jsCallInvoker,
8283
"loadVerticalOCR"));
84+
85+
jsiRuntime->global().setProperty(
86+
*jsiRuntime, "loadSpeechToText",
87+
RnExecutorchInstaller::loadModel<SpeechToText>(jsiRuntime, jsCallInvoker,
88+
"loadSpeechToText"));
89+
90+
#ifdef __ANDROID__
91+
auto num_of_cores =
92+
::executorch::extension::cpuinfo::get_num_performant_cores();
93+
::executorch::extension::threadpool::get_threadpool()
94+
->_unsafe_reset_threadpool(num_of_cores);
95+
log(LOG_LEVEL::Info, "Configuring xnnpack for ", num_of_cores, "threads");
96+
#endif
8397
}
98+
8499
} // namespace rnexecutorch

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,6 @@ LLM::LLM(const std::string &modelSource, const std::string &tokenizerSource,
1616
: runner(std::make_unique<example::Runner>(modelSource, tokenizerSource)),
1717
callInvoker(callInvoker) {
1818

19-
auto num_of_cores =
20-
::executorch::extension::cpuinfo::get_num_performant_cores();
21-
log(LOG_LEVEL::Error, "num_of_cores", num_of_cores);
22-
23-
log(LOG_LEVEL::Error, "_unsafe_reset_threadpool",
24-
::executorch::extension::threadpool::get_threadpool()
25-
->_unsafe_reset_threadpool(num_of_cores));
2619
auto loadResult = runner->load();
2720
if (loadResult != Error::Ok) {
2821
throw std::runtime_error("Failed to load LLM runner, error code: " +

0 commit comments

Comments
 (0)