Skip to content

Commit c03b233

Browse files
author
Mateusz Kopciński
committed
added threadpool extension, partially fixed perf problems
1 parent ab0550d commit c03b233

File tree

7 files changed

+30
-11
lines changed

7 files changed

+30
-11
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
kotlin version: 2.0.21
2+
error message: The daemon has terminated unexpectedly on startup attempt #1 with error code: 0. The daemon process output:
3+
1. Kotlin compile daemon is ready
4+

apps/llm/app/llm/index.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ function LLMScreen() {
6868
keyboardVerticalOffset={Platform.OS === 'ios' ? 120 : 40}
6969
>
7070
<View style={styles.container}>
71-
{/* {llm.messageHistory.length ? (
71+
{llm.messageHistory.length ? (
7272
<View style={styles.chatContainer}>
7373
<Messages
7474
chatHistory={llm.messageHistory}
@@ -84,13 +84,13 @@ function LLMScreen() {
8484
What can I help you with?
8585
</Text>
8686
</View>
87-
)} */}
88-
<View style={styles.helloMessageContainer}>
87+
)}
88+
{/* <View style={styles.helloMessageContainer}>
8989
<Text style={styles.helloText}>Hello! 👋</Text>
9090
<Text style={styles.bottomHelloText}>
9191
What can I help you with?
9292
</Text>
93-
</View>
93+
</View> */}
9494

9595
<View style={styles.bottomContainer}>
9696
<TextInput

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

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

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

3748
# ------- Executorch -------
3849

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
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>
46
#include <filesystem>
57
#include <rnexecutorch/Log.h>
68

@@ -31,15 +33,12 @@ void LLM::generate(std::string input, std::shared_ptr<jsi::Function> callback) {
3133

3234
// Create a native callback that will invoke the JS callback on the JS thread
3335
auto nativeCallback = [this, callback](const std::string &token) {
34-
log(LOG_LEVEL::Error, token);
35-
36-
// callInvoker->invokeAsync([callback, token](jsi::Runtime &runtime) {
37-
// callback->call(runtime, jsi::String::createFromUtf8(runtime,
38-
// token));
39-
// });
36+
callInvoker->invokeAsync([callback, token](jsi::Runtime &runtime) {
37+
callback->call(runtime, jsi::String::createFromUtf8(runtime, token));
38+
});
4039
};
4140

42-
auto error = runner->generate(input, {}, {}, false);
41+
auto error = runner->generate(input, nativeCallback, {}, false);
4342
if (error != executorch::runtime::Error::Ok) {
4443
throw std::runtime_error("Failed to generate text, error code: " +
4544
std::to_string(static_cast<int>(error)));

packages/react-native-executorch/src/constants/modelUrls.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Platform } from 'react-native';
33
const URL_PREFIX =
44
'https://huggingface.co/software-mansion/react-native-executorch';
55
const VERSION_TAG = 'resolve/v0.5.0';
6+
const NEXT_VERSION_TAG = 'resolve/v0.5.0';
67

78
// LLMs
89

packages/react-native-executorch/third-party/include/executorch/extension/threadpool/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+
#if 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+
#if 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)