Repository navigation
Expand file tree
/
Copy pathRnExecutorchInstaller.cpp
More file actions
152 lines (125 loc) · 6.4 KB
/
Copy pathRnExecutorchInstaller.cpp
File metadata and controls
152 lines (125 loc) · 6.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#include "RnExecutorchInstaller.h"
#include <rnexecutorch/TokenizerModule.h>
#include <rnexecutorch/host_objects/JsiConversions.h>
#include <rnexecutorch/models/classification/Classification.h>
#include <rnexecutorch/models/embeddings/image/ImageEmbeddings.h>
#include <rnexecutorch/models/embeddings/text/TextEmbeddings.h>
#include <rnexecutorch/models/instance_segmentation/BaseInstanceSegmentation.h>
#include <rnexecutorch/models/llm/LLM.h>
#include <rnexecutorch/models/object_detection/ObjectDetection.h>
#include <rnexecutorch/models/ocr/OCR.h>
#include <rnexecutorch/models/pose_estimation/PoseEstimation.h>
#include <rnexecutorch/models/privacy_filter/PrivacyFilter.h>
#include <rnexecutorch/models/semantic_segmentation/BaseSemanticSegmentation.h>
#include <rnexecutorch/models/speech_to_text/SpeechToText.h>
#include <rnexecutorch/models/style_transfer/StyleTransfer.h>
#include <rnexecutorch/models/text_to_image/TextToImage.h>
#include <rnexecutorch/models/text_to_speech/TextToSpeech.h>
#include <rnexecutorch/models/vertical_ocr/VerticalOCR.h>
#include <rnexecutorch/models/voice_activity_detection/VoiceActivityDetection.h>
#include <rnexecutorch/threads/GlobalThreadPool.h>
#include <rnexecutorch/threads/utils/ThreadUtils.h>
#if defined(__ANDROID__) && defined(__aarch64__)
#include <executorch/extension/threadpool/cpuinfo_utils.h>
#include <executorch/extension/threadpool/threadpool.h>
#include <rnexecutorch/Log.h>
#endif
namespace rnexecutorch {
// This function fetches data from a url address. It is implemented in
// Kotlin/ObjectiveC++ and then bound to this variable. It's done to not handle
// SSL intricacies manually, as it is done automagically in ObjC++/Kotlin.
FetchUrlFunc_t fetchUrlFunc;
// App-private writable directory provided by the platform layer. Android
// passes reactApplicationContext.cacheDir; iOS passes NSTemporaryDirectory().
// std::filesystem::temp_directory_path() resolves to /data/local/tmp on
// Android <13, which is not writable by app processes — so we pipe the
// platform-provided path through explicitly.
std::string cacheDir;
void RnExecutorchInstaller::injectJSIBindings(
jsi::Runtime *jsiRuntime, std::shared_ptr<react::CallInvoker> jsCallInvoker,
FetchUrlFunc_t fetchDataFromUrl, const std::string &cacheDirPath,
bool isEmulator) {
fetchUrlFunc = fetchDataFromUrl;
cacheDir = cacheDirPath;
jsiRuntime->global().setProperty(*jsiRuntime, "__rne_isEmulator",
jsi::Value(isEmulator));
jsiRuntime->global().setProperty(
*jsiRuntime, "loadStyleTransfer",
RnExecutorchInstaller::loadModel<models::style_transfer::StyleTransfer>(
jsiRuntime, jsCallInvoker, "loadStyleTransfer"));
jsiRuntime->global().setProperty(
*jsiRuntime, "loadSemanticSegmentation",
RnExecutorchInstaller::loadModel<
models::semantic_segmentation::BaseSemanticSegmentation>(
jsiRuntime, jsCallInvoker, "loadSemanticSegmentation"));
jsiRuntime->global().setProperty(
*jsiRuntime, "loadInstanceSegmentation",
RnExecutorchInstaller::loadModel<
models::instance_segmentation::BaseInstanceSegmentation>(
jsiRuntime, jsCallInvoker, "loadInstanceSegmentation"));
jsiRuntime->global().setProperty(
*jsiRuntime, "loadTextToImage",
RnExecutorchInstaller::loadModel<models::text_to_image::TextToImage>(
jsiRuntime, jsCallInvoker, "loadTextToImage"));
jsiRuntime->global().setProperty(
*jsiRuntime, "loadClassification",
RnExecutorchInstaller::loadModel<models::classification::Classification>(
jsiRuntime, jsCallInvoker, "loadClassification"));
jsiRuntime->global().setProperty(
*jsiRuntime, "loadObjectDetection",
RnExecutorchInstaller::loadModel<
models::object_detection::ObjectDetection>(jsiRuntime, jsCallInvoker,
"loadObjectDetection"));
jsiRuntime->global().setProperty(
*jsiRuntime, "loadPoseEstimation",
RnExecutorchInstaller::loadModel<models::pose_estimation::PoseEstimation>(
jsiRuntime, jsCallInvoker, "loadPoseEstimation"));
jsiRuntime->global().setProperty(
*jsiRuntime, "loadExecutorchModule",
RnExecutorchInstaller::loadModel<models::BaseModel>(
jsiRuntime, jsCallInvoker, "loadExecutorchModule"));
jsiRuntime->global().setProperty(
*jsiRuntime, "loadTokenizerModule",
RnExecutorchInstaller::loadModel<TokenizerModule>(
jsiRuntime, jsCallInvoker, "loadTokenizerModule"));
jsiRuntime->global().setProperty(
*jsiRuntime, "loadImageEmbeddings",
RnExecutorchInstaller::loadModel<models::embeddings::ImageEmbeddings>(
jsiRuntime, jsCallInvoker, "loadImageEmbeddings"));
jsiRuntime->global().setProperty(
*jsiRuntime, "loadTextEmbeddings",
RnExecutorchInstaller::loadModel<models::embeddings::TextEmbeddings>(
jsiRuntime, jsCallInvoker, "loadTextEmbeddings"));
jsiRuntime->global().setProperty(
*jsiRuntime, "loadLLM",
RnExecutorchInstaller::loadModel<models::llm::LLM>(
jsiRuntime, jsCallInvoker, "loadLLM"));
jsiRuntime->global().setProperty(
*jsiRuntime, "loadPrivacyFilter",
RnExecutorchInstaller::loadModel<models::privacy_filter::PrivacyFilter>(
jsiRuntime, jsCallInvoker, "loadPrivacyFilter"));
jsiRuntime->global().setProperty(
*jsiRuntime, "loadOCR",
RnExecutorchInstaller::loadModel<models::ocr::OCR>(
jsiRuntime, jsCallInvoker, "loadOCR"));
jsiRuntime->global().setProperty(
*jsiRuntime, "loadVerticalOCR",
RnExecutorchInstaller::loadModel<models::ocr::VerticalOCR>(
jsiRuntime, jsCallInvoker, "loadVerticalOCR"));
jsiRuntime->global().setProperty(
*jsiRuntime, "loadSpeechToText",
RnExecutorchInstaller::loadModel<models::speech_to_text::SpeechToText>(
jsiRuntime, jsCallInvoker, "loadSpeechToText"));
jsiRuntime->global().setProperty(
*jsiRuntime, "loadTextToSpeechKokoro",
RnExecutorchInstaller::loadModel<models::text_to_speech::kokoro::Kokoro>(
jsiRuntime, jsCallInvoker, "loadTextToSpeechKokoro"));
jsiRuntime->global().setProperty(
*jsiRuntime, "loadVAD",
RnExecutorchInstaller::loadModel<
models::voice_activity_detection::VoiceActivityDetection>(
jsiRuntime, jsCallInvoker, "loadVAD"));
threads::utils::unsafeSetupThreadPool();
threads::GlobalThreadPool::initialize();
}
} // namespace rnexecutorch