react-native-executorch 0.5.6 → 0.5.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/libs/classes.jar +0 -0
- package/android/src/main/cpp/CMakeLists.txt +23 -14
- package/common/rnexecutorch/RnExecutorchInstaller.cpp +4 -21
- package/common/rnexecutorch/host_objects/ModelHostObject.h +67 -51
- package/common/rnexecutorch/models/llm/LLM.cpp +24 -1
- package/common/rnexecutorch/models/llm/LLM.h +4 -1
- package/common/rnexecutorch/threads/GlobalThreadPool.h +79 -0
- package/common/rnexecutorch/threads/HighPerformanceThreadPool.h +364 -0
- package/common/rnexecutorch/threads/utils/ThreadUtils.h +29 -0
- package/common/runner/runner.cpp +9 -3
- package/common/runner/runner.h +4 -3
- package/common/runner/text_token_generator.h +28 -10
- package/lib/module/controllers/LLMController.js +21 -2
- package/lib/module/controllers/LLMController.js.map +1 -1
- package/lib/module/hooks/natural_language_processing/useLLM.js +6 -2
- package/lib/module/hooks/natural_language_processing/useLLM.js.map +1 -1
- package/lib/module/modules/natural_language_processing/LLMModule.js +4 -2
- package/lib/module/modules/natural_language_processing/LLMModule.js.map +1 -1
- package/lib/module/types/llm.js.map +1 -1
- package/lib/typescript/controllers/LLMController.d.ts +4 -2
- package/lib/typescript/controllers/LLMController.d.ts.map +1 -1
- package/lib/typescript/hooks/natural_language_processing/useLLM.d.ts.map +1 -1
- package/lib/typescript/modules/natural_language_processing/LLMModule.d.ts +3 -2
- package/lib/typescript/modules/natural_language_processing/LLMModule.d.ts.map +1 -1
- package/lib/typescript/types/llm.d.ts +7 -1
- package/lib/typescript/types/llm.d.ts.map +1 -1
- package/package.json +3 -1
- package/react-native-executorch.podspec +12 -31
- package/src/controllers/LLMController.ts +29 -5
- package/src/hooks/natural_language_processing/useLLM.ts +15 -1
- package/src/modules/natural_language_processing/LLMModule.ts +10 -2
- package/src/types/llm.ts +8 -0
- package/third-party/android/libs/cpuinfo/arm64-v8a/libcpuinfo.so +0 -0
- package/third-party/android/libs/executorch/arm64-v8a/libexecutorch.so +0 -0
- package/third-party/android/libs/executorch/x86_64/libexecutorch.so +0 -0
- package/third-party/android/libs/pthreadpool/arm64-v8a/libpthreadpool.so +0 -0
- package/third-party/android/libs/tokenizers-cpp/arm64-v8a/libsentencepiece.a +0 -0
- package/third-party/android/libs/tokenizers-cpp/arm64-v8a/libtokenizers_c.a +0 -0
- package/third-party/android/libs/tokenizers-cpp/arm64-v8a/libtokenizers_cpp.a +0 -0
- package/third-party/android/libs/tokenizers-cpp/x86_64/libsentencepiece.a +0 -0
- package/third-party/android/libs/tokenizers-cpp/x86_64/libtokenizers_c.a +0 -0
- package/third-party/android/libs/tokenizers-cpp/x86_64/libtokenizers_cpp.a +0 -0
- package/third-party/include/c10/macros/Export.h +2 -86
- package/third-party/include/c10/macros/Macros.h +28 -5
- package/third-party/include/c10/util/BFloat16-inl.h +1 -4
- package/third-party/include/c10/util/BFloat16.h +5 -8
- package/third-party/include/c10/util/Half.h +5 -0
- package/third-party/include/c10/util/bit_cast.h +1 -1
- package/third-party/include/c10/util/complex.h +639 -0
- package/third-party/include/c10/util/complex_math.h +399 -0
- package/third-party/include/c10/util/complex_utils.h +41 -0
- package/third-party/include/c10/util/irange.h +2 -2
- package/third-party/include/c10/util/overflows.h +95 -0
- package/third-party/include/executorch/ExecuTorchError.h +75 -0
- package/third-party/include/executorch/ExecuTorchModule.h +115 -11
- package/third-party/include/executorch/ExecuTorchTensor.h +731 -51
- package/third-party/include/executorch/ExecuTorchValue.h +61 -9
- package/third-party/include/executorch/extension/kernel_util/make_boxed_from_unboxed_functor.h +181 -0
- package/third-party/include/executorch/extension/kernel_util/meta_programming.h +108 -0
- package/third-party/include/executorch/extension/kernel_util/type_list.h +137 -0
- package/third-party/include/executorch/extension/module/bundled_module.h +131 -0
- package/third-party/include/executorch/extension/module/module.h +46 -20
- package/third-party/include/executorch/extension/threadpool/cpuinfo_utils.h +1 -3
- package/third-party/include/executorch/extension/threadpool/threadpool.h +1 -3
- package/third-party/include/executorch/extension/threadpool/threadpool_guard.h +35 -0
- package/third-party/include/executorch/runtime/backend/backend_execution_context.h +3 -3
- package/third-party/include/executorch/runtime/backend/backend_init_context.h +12 -6
- package/third-party/include/executorch/runtime/backend/backend_option_context.h +34 -0
- package/third-party/include/executorch/runtime/backend/interface.h +70 -9
- package/third-party/include/executorch/runtime/backend/options.h +206 -0
- package/third-party/include/executorch/runtime/core/evalue.h +19 -25
- package/third-party/include/executorch/runtime/core/event_tracer.h +32 -17
- package/third-party/include/executorch/runtime/core/event_tracer_hooks.h +23 -14
- package/third-party/include/executorch/runtime/core/exec_aten/exec_aten.h +32 -9
- package/third-party/include/executorch/runtime/core/exec_aten/util/dim_order_util.h +3 -2
- package/third-party/include/executorch/runtime/core/exec_aten/util/scalar_type_util.h +43 -75
- package/third-party/include/executorch/runtime/core/exec_aten/util/tensor_util.h +88 -87
- package/third-party/include/executorch/runtime/core/function_ref.h +100 -0
- package/third-party/include/executorch/runtime/core/named_data_map.h +14 -14
- package/third-party/include/executorch/runtime/core/portable_type/c10/c10/macros/Export.h +2 -86
- package/third-party/include/executorch/runtime/core/portable_type/c10/c10/macros/Macros.h +28 -5
- package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/BFloat16-inl.h +1 -4
- package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/BFloat16.h +5 -8
- package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/Half.h +5 -0
- package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/bit_cast.h +1 -1
- package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/complex.h +639 -0
- package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/complex_math.h +399 -0
- package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/complex_utils.h +41 -0
- package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/irange.h +2 -2
- package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/overflows.h +95 -0
- package/third-party/include/executorch/runtime/core/portable_type/c10/torch/headeronly/macros/Export.h +88 -0
- package/third-party/include/executorch/runtime/core/portable_type/complex.h +6 -29
- package/third-party/include/executorch/runtime/core/portable_type/tensor_impl.h +20 -0
- package/third-party/include/executorch/runtime/core/span.h +4 -0
- package/third-party/include/executorch/runtime/core/tag.h +19 -0
- package/third-party/include/executorch/runtime/core/tensor_layout.h +2 -2
- package/third-party/include/executorch/runtime/executor/method.h +15 -3
- package/third-party/include/executorch/runtime/executor/method_meta.h +34 -5
- package/third-party/include/executorch/runtime/executor/program.h +3 -4
- package/third-party/include/executorch/runtime/executor/pte_data_map.h +9 -8
- package/third-party/include/executorch/runtime/executor/tensor_parser.h +14 -13
- package/third-party/include/executorch/runtime/kernel/kernel_runtime_context.h +5 -5
- package/third-party/include/executorch/runtime/kernel/operator_registry.h +21 -19
- package/third-party/include/executorch/runtime/platform/compiler.h +8 -0
- package/third-party/include/executorch/runtime/platform/platform.h +126 -0
- package/third-party/include/headeronly/macros/Export.h +88 -0
- package/third-party/include/tokenizers-cpp/tokenizers_c.h +61 -0
- package/third-party/include/torch/headeronly/macros/Export.h +88 -0
- package/third-party/ios/ExecutorchLib.xcframework/Info.plist +43 -0
- package/third-party/ios/ExecutorchLib.xcframework/ios-arm64/ExecutorchLib.framework/ExecutorchLib +0 -0
- package/third-party/ios/ExecutorchLib.xcframework/ios-arm64/ExecutorchLib.framework/Info.plist +0 -0
- package/third-party/ios/ExecutorchLib.xcframework/ios-arm64-simulator/ExecutorchLib.framework/ExecutorchLib +0 -0
- package/third-party/ios/ExecutorchLib.xcframework/ios-arm64-simulator/ExecutorchLib.framework/Info.plist +0 -0
- package/third-party/ios/libs/cpuinfo/libcpuinfo.a +0 -0
- package/third-party/ios/libs/pthreadpool/physical-arm64-release/libpthreadpool.a +0 -0
- package/third-party/ios/libs/pthreadpool/simulator-arm64-debug/libpthreadpool.a +0 -0
- package/ios/libs/executorch/libbackend_coreml_ios.a +0 -0
- package/ios/libs/executorch/libbackend_coreml_simulator.a +0 -0
- package/ios/libs/executorch/libbackend_mps_ios.a +0 -0
- package/ios/libs/executorch/libbackend_mps_simulator.a +0 -0
- package/ios/libs/executorch/libbackend_xnnpack_ios.a +0 -0
- package/ios/libs/executorch/libbackend_xnnpack_simulator.a +0 -0
- package/ios/libs/executorch/libexecutorch_ios.a +0 -0
- package/ios/libs/executorch/libexecutorch_simulator.a +0 -0
- package/ios/libs/executorch/libkernels_custom_ios.a +0 -0
- package/ios/libs/executorch/libkernels_custom_simulator.a +0 -0
- package/ios/libs/executorch/libkernels_optimized_ios.a +0 -0
- package/ios/libs/executorch/libkernels_optimized_simulator.a +0 -0
- package/ios/libs/executorch/libkernels_portable_ios.a +0 -0
- package/ios/libs/executorch/libkernels_portable_simulator.a +0 -0
- package/ios/libs/executorch/libkernels_quantized_ios.a +0 -0
- package/ios/libs/executorch/libkernels_quantized_simulator.a +0 -0
- package/third-party/ios/ios.toolchain.cmake +0 -1122
- /package/{ios → third-party/ios}/libs/tokenizers-cpp/physical-arm64-release/libsentencepiece.a +0 -0
- /package/{ios → third-party/ios}/libs/tokenizers-cpp/physical-arm64-release/libtokenizers_c.a +0 -0
- /package/{ios → third-party/ios}/libs/tokenizers-cpp/physical-arm64-release/libtokenizers_cpp.a +0 -0
- /package/{ios → third-party/ios}/libs/tokenizers-cpp/simulator-arm64-debug/libsentencepiece.a +0 -0
- /package/{ios → third-party/ios}/libs/tokenizers-cpp/simulator-arm64-debug/libtokenizers_c.a +0 -0
- /package/{ios → third-party/ios}/libs/tokenizers-cpp/simulator-arm64-debug/libtokenizers_cpp.a +0 -0
|
@@ -11,6 +11,10 @@
|
|
|
11
11
|
* Platform abstraction layer to allow individual platform libraries to override
|
|
12
12
|
* symbols in ExecuTorch. PAL functions are defined as C functions so a platform
|
|
13
13
|
* library implementer can use C in lieu of C++.
|
|
14
|
+
*
|
|
15
|
+
* The et_pal_ methods should not be called directly. Use the corresponding
|
|
16
|
+
* methods in the executorch::runtime namespace instead to appropriately
|
|
17
|
+
* dispatch through the PAL function table.
|
|
14
18
|
*/
|
|
15
19
|
|
|
16
20
|
#pragma once
|
|
@@ -53,12 +57,14 @@ typedef struct {
|
|
|
53
57
|
* to initialize any global state. Typically overridden by PAL implementer.
|
|
54
58
|
*/
|
|
55
59
|
void et_pal_init(void) ET_INTERNAL_PLATFORM_WEAKNESS;
|
|
60
|
+
using pal_init_method = void (*)();
|
|
56
61
|
|
|
57
62
|
/**
|
|
58
63
|
* Immediately abort execution, setting the device into an error state, if
|
|
59
64
|
* available.
|
|
60
65
|
*/
|
|
61
66
|
ET_NORETURN void et_pal_abort(void) ET_INTERNAL_PLATFORM_WEAKNESS;
|
|
67
|
+
using pal_abort_method = void (*)();
|
|
62
68
|
|
|
63
69
|
/**
|
|
64
70
|
* Return a monotonically non-decreasing timestamp in system ticks.
|
|
@@ -66,6 +72,8 @@ ET_NORETURN void et_pal_abort(void) ET_INTERNAL_PLATFORM_WEAKNESS;
|
|
|
66
72
|
* @retval Timestamp value in system ticks.
|
|
67
73
|
*/
|
|
68
74
|
et_timestamp_t et_pal_current_ticks(void) ET_INTERNAL_PLATFORM_WEAKNESS;
|
|
75
|
+
typedef et_timestamp_t (*et_pal_current_ticks_t)(void);
|
|
76
|
+
using pal_current_ticks_method = et_timestamp_t (*)();
|
|
69
77
|
|
|
70
78
|
/**
|
|
71
79
|
* Return the conversion rate from system ticks to nanoseconds as a fraction.
|
|
@@ -81,6 +89,7 @@ et_timestamp_t et_pal_current_ticks(void) ET_INTERNAL_PLATFORM_WEAKNESS;
|
|
|
81
89
|
*/
|
|
82
90
|
et_tick_ratio_t
|
|
83
91
|
et_pal_ticks_to_ns_multiplier(void) ET_INTERNAL_PLATFORM_WEAKNESS;
|
|
92
|
+
using pal_ticks_to_ns_multiplier_method = et_tick_ratio_t (*)();
|
|
84
93
|
|
|
85
94
|
/**
|
|
86
95
|
* Severity level of a log message. Values must map to printable 7-bit ASCII
|
|
@@ -110,6 +119,9 @@ void et_pal_emit_log_message(et_timestamp_t timestamp, et_pal_log_level_t level,
|
|
|
110
119
|
const char *filename, const char *function,
|
|
111
120
|
size_t line, const char *message,
|
|
112
121
|
size_t length) ET_INTERNAL_PLATFORM_WEAKNESS;
|
|
122
|
+
using pal_emit_log_message_method = void (*)(
|
|
123
|
+
et_timestamp_t timestamp, et_pal_log_level_t level, const char *filename,
|
|
124
|
+
const char *function, size_t line, const char *message, size_t length);
|
|
113
125
|
|
|
114
126
|
/**
|
|
115
127
|
* NOTE: Core runtime code must not call this directly. It may only be called by
|
|
@@ -122,6 +134,7 @@ void et_pal_emit_log_message(et_timestamp_t timestamp, et_pal_log_level_t level,
|
|
|
122
134
|
* et_pal_free().
|
|
123
135
|
*/
|
|
124
136
|
void *et_pal_allocate(size_t size) ET_INTERNAL_PLATFORM_WEAKNESS;
|
|
137
|
+
using pal_allocate_method = void *(*)(size_t size);
|
|
125
138
|
|
|
126
139
|
/**
|
|
127
140
|
* Frees memory allocated by et_pal_allocate().
|
|
@@ -129,5 +142,118 @@ void *et_pal_allocate(size_t size) ET_INTERNAL_PLATFORM_WEAKNESS;
|
|
|
129
142
|
* @param[in] ptr Pointer to memory to free. May be nullptr.
|
|
130
143
|
*/
|
|
131
144
|
void et_pal_free(void *ptr) ET_INTERNAL_PLATFORM_WEAKNESS;
|
|
145
|
+
using pal_free_method = void (*)(void *ptr);
|
|
132
146
|
|
|
133
147
|
} // extern "C"
|
|
148
|
+
|
|
149
|
+
namespace executorch::runtime {
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Table of pointers to platform abstraction layer functions.
|
|
153
|
+
*/
|
|
154
|
+
struct PalImpl {
|
|
155
|
+
// Note that this struct cannot contain constructors in order to ensure that
|
|
156
|
+
// the singleton instance can be initialized without relying on a global
|
|
157
|
+
// constructor. If it does require a global constructor, there can be a race
|
|
158
|
+
// between the init of the default PAL and the user static registration code.
|
|
159
|
+
static PalImpl create(pal_emit_log_message_method emit_log_message,
|
|
160
|
+
const char *source_filename);
|
|
161
|
+
|
|
162
|
+
static PalImpl
|
|
163
|
+
create(pal_init_method init, pal_abort_method abort,
|
|
164
|
+
pal_current_ticks_method current_ticks,
|
|
165
|
+
pal_ticks_to_ns_multiplier_method ticks_to_ns_multiplier,
|
|
166
|
+
pal_emit_log_message_method emit_log_message,
|
|
167
|
+
pal_allocate_method allocate, pal_free_method free,
|
|
168
|
+
const char *source_filename);
|
|
169
|
+
|
|
170
|
+
pal_init_method init = nullptr;
|
|
171
|
+
pal_abort_method abort = nullptr;
|
|
172
|
+
pal_current_ticks_method current_ticks = nullptr;
|
|
173
|
+
pal_ticks_to_ns_multiplier_method ticks_to_ns_multiplier = nullptr;
|
|
174
|
+
pal_emit_log_message_method emit_log_message = nullptr;
|
|
175
|
+
pal_allocate_method allocate = nullptr;
|
|
176
|
+
pal_free_method free = nullptr;
|
|
177
|
+
|
|
178
|
+
// An optional metadata field, indicating the name of the source
|
|
179
|
+
// file that registered the PAL implementation.
|
|
180
|
+
const char *source_filename;
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Override the PAL functions with user implementations. Any null entries in the
|
|
185
|
+
* table are unchanged and will keep the default implementation.
|
|
186
|
+
*
|
|
187
|
+
* Returns true if the registration was successful, false otherwise.
|
|
188
|
+
*/
|
|
189
|
+
bool register_pal(PalImpl impl);
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Returns the PAL function table, which contains function pointers to the
|
|
193
|
+
* active implementation of each PAL function.
|
|
194
|
+
*/
|
|
195
|
+
const PalImpl *get_pal_impl();
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Initialize the platform abstraction layer.
|
|
199
|
+
*
|
|
200
|
+
* This function should be called before any other function provided by the PAL
|
|
201
|
+
* to initialize any global state. Typically overridden by PAL implementer.
|
|
202
|
+
*/
|
|
203
|
+
void pal_init();
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Immediately abort execution, setting the device into an error state, if
|
|
207
|
+
* available.
|
|
208
|
+
*/
|
|
209
|
+
ET_NORETURN void pal_abort();
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Return a monotonically non-decreasing timestamp in system ticks.
|
|
213
|
+
*
|
|
214
|
+
* @retval Timestamp value in system ticks.
|
|
215
|
+
*/
|
|
216
|
+
et_timestamp_t pal_current_ticks();
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Return the conversion rate from system ticks to nanoseconds as a fraction.
|
|
220
|
+
* To convert a system ticks to nanoseconds, multiply the tick count by the
|
|
221
|
+
* numerator and then divide by the denominator:
|
|
222
|
+
* nanoseconds = ticks * numerator / denominator
|
|
223
|
+
*
|
|
224
|
+
* The utility method executorch::runtime::ticks_to_ns(et_timestamp_t) can also
|
|
225
|
+
* be used to perform the conversion for a given tick count. It is defined in
|
|
226
|
+
* torch/executor/runtime/platform/clock.h.
|
|
227
|
+
*
|
|
228
|
+
* @retval The ratio of nanoseconds to system ticks.
|
|
229
|
+
*/
|
|
230
|
+
et_tick_ratio_t pal_ticks_to_ns_multiplier();
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* Severity level of a log message. Values must map to printable 7-bit ASCII
|
|
234
|
+
* uppercase letters.
|
|
235
|
+
*/
|
|
236
|
+
void pal_emit_log_message(et_timestamp_t timestamp, et_pal_log_level_t level,
|
|
237
|
+
const char *filename, const char *function,
|
|
238
|
+
size_t line, const char *message, size_t length);
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* NOTE: Core runtime code must not call this directly. It may only be called by
|
|
242
|
+
* a MemoryAllocator wrapper.
|
|
243
|
+
*
|
|
244
|
+
* Allocates size bytes of memory.
|
|
245
|
+
*
|
|
246
|
+
* @param[in] size Number of bytes to allocate.
|
|
247
|
+
* @returns the allocated memory, or nullptr on failure. Must be freed using
|
|
248
|
+
* et_pal_free().
|
|
249
|
+
*/
|
|
250
|
+
void *pal_allocate(size_t size);
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* Frees memory allocated by et_pal_allocate().
|
|
254
|
+
*
|
|
255
|
+
* @param[in] ptr Pointer to memory to free. May be nullptr.
|
|
256
|
+
*/
|
|
257
|
+
void pal_free(void *ptr);
|
|
258
|
+
|
|
259
|
+
} // namespace executorch::runtime
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
#define C10_USING_CUSTOM_GENERATED_MACROS
|
|
2
|
+
#pragma once
|
|
3
|
+
|
|
4
|
+
/* Header file to define the common scaffolding for exported symbols.
|
|
5
|
+
*
|
|
6
|
+
* Export is by itself a quite tricky situation to deal with, and if you are
|
|
7
|
+
* hitting this file, make sure you start with the background here:
|
|
8
|
+
* - Linux: https://gcc.gnu.org/wiki/Visibility
|
|
9
|
+
* - Windows:
|
|
10
|
+
* https://docs.microsoft.com/en-us/cpp/cpp/dllexport-dllimport?view=vs-2017
|
|
11
|
+
*
|
|
12
|
+
* Do NOT include this file directly. Instead, use c10/macros/Macros.h
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
// You do not need to edit this part of file unless you are changing the core
|
|
16
|
+
// pytorch export abstractions.
|
|
17
|
+
//
|
|
18
|
+
// This part defines the C10 core export and import macros. This is controlled
|
|
19
|
+
// by whether we are building shared libraries or not, which is determined
|
|
20
|
+
// during build time and codified in c10/core/cmake_macros.h.
|
|
21
|
+
// When the library is built as a shared lib, EXPORT and IMPORT will contain
|
|
22
|
+
// visibility attributes. If it is being built as a static lib, then EXPORT
|
|
23
|
+
// and IMPORT basically have no effect.
|
|
24
|
+
|
|
25
|
+
// As a rule of thumb, you should almost NEVER mix static and shared builds for
|
|
26
|
+
// libraries that depend on c10. AKA, if c10 is built as a static library, we
|
|
27
|
+
// recommend everything dependent on c10 to be built statically. If c10 is built
|
|
28
|
+
// as a shared library, everything dependent on it should be built as shared. In
|
|
29
|
+
// the PyTorch project, all native libraries shall use the macro
|
|
30
|
+
// C10_BUILD_SHARED_LIB to check whether pytorch is building shared or static
|
|
31
|
+
// libraries.
|
|
32
|
+
|
|
33
|
+
// For build systems that do not directly depend on CMake and directly build
|
|
34
|
+
// from the source directory (such as Buck), one may not have a cmake_macros.h
|
|
35
|
+
// file at all. In this case, the build system is responsible for providing
|
|
36
|
+
// correct macro definitions corresponding to the cmake_macros.h.in file.
|
|
37
|
+
//
|
|
38
|
+
// In such scenarios, one should define the macro
|
|
39
|
+
// C10_USING_CUSTOM_GENERATED_MACROS
|
|
40
|
+
// to inform this header that it does not need to include the cmake_macros.h
|
|
41
|
+
// file.
|
|
42
|
+
|
|
43
|
+
#ifdef _WIN32
|
|
44
|
+
#define C10_HIDDEN
|
|
45
|
+
#if defined(C10_BUILD_SHARED_LIBS)
|
|
46
|
+
#define C10_EXPORT __declspec(dllexport)
|
|
47
|
+
#define C10_IMPORT __declspec(dllimport)
|
|
48
|
+
#else
|
|
49
|
+
#define C10_EXPORT
|
|
50
|
+
#define C10_IMPORT
|
|
51
|
+
#endif
|
|
52
|
+
#else // _WIN32
|
|
53
|
+
#if defined(__GNUC__)
|
|
54
|
+
#define C10_EXPORT __attribute__((__visibility__("default")))
|
|
55
|
+
#define C10_HIDDEN __attribute__((__visibility__("hidden")))
|
|
56
|
+
#else // defined(__GNUC__)
|
|
57
|
+
#define C10_EXPORT
|
|
58
|
+
#define C10_HIDDEN
|
|
59
|
+
#endif // defined(__GNUC__)
|
|
60
|
+
#define C10_IMPORT C10_EXPORT
|
|
61
|
+
#endif // _WIN32
|
|
62
|
+
|
|
63
|
+
#ifdef NO_EXPORT
|
|
64
|
+
#undef C10_EXPORT
|
|
65
|
+
#define C10_EXPORT
|
|
66
|
+
#endif
|
|
67
|
+
|
|
68
|
+
// Definition of an adaptive XX_API macro, that depends on whether you are
|
|
69
|
+
// building the library itself or not, routes to XX_EXPORT and XX_IMPORT.
|
|
70
|
+
// Basically, you will need to do this for each shared library that you are
|
|
71
|
+
// building, and the instruction is as follows: assuming that you are building
|
|
72
|
+
// a library called libawesome.so. You should:
|
|
73
|
+
// (1) for your cmake target (usually done by "add_library(awesome, ...)"),
|
|
74
|
+
// define a macro called AWESOME_BUILD_MAIN_LIB using
|
|
75
|
+
// target_compile_options.
|
|
76
|
+
// (2) define the AWESOME_API macro similar to the one below.
|
|
77
|
+
// And in the source file of your awesome library, use AWESOME_API to
|
|
78
|
+
// annotate public symbols.
|
|
79
|
+
|
|
80
|
+
// Here, for the C10 library, we will define the macro C10_API for both import
|
|
81
|
+
// and export.
|
|
82
|
+
|
|
83
|
+
// This one is being used by libc10.so
|
|
84
|
+
#ifdef C10_BUILD_MAIN_LIB
|
|
85
|
+
#define C10_API C10_EXPORT
|
|
86
|
+
#else
|
|
87
|
+
#define C10_API C10_IMPORT
|
|
88
|
+
#endif
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) 2023 by Contributors
|
|
3
|
+
* \file tokenizers_c.h
|
|
4
|
+
* \brief C binding to tokenizers rust library
|
|
5
|
+
*/
|
|
6
|
+
#ifndef TOKENIZERS_C_H_
|
|
7
|
+
#define TOKENIZERS_C_H_
|
|
8
|
+
|
|
9
|
+
// The C API
|
|
10
|
+
#ifdef __cplusplus
|
|
11
|
+
extern "C" {
|
|
12
|
+
#endif
|
|
13
|
+
|
|
14
|
+
#include <stddef.h>
|
|
15
|
+
#include <stdint.h>
|
|
16
|
+
|
|
17
|
+
typedef void *TokenizerHandle;
|
|
18
|
+
|
|
19
|
+
typedef struct {
|
|
20
|
+
int *token_ids;
|
|
21
|
+
size_t len;
|
|
22
|
+
} TokenizerEncodeResult;
|
|
23
|
+
|
|
24
|
+
TokenizerHandle tokenizers_new_from_str(const char *json, size_t len);
|
|
25
|
+
|
|
26
|
+
TokenizerHandle byte_level_bpe_tokenizers_new_from_str(
|
|
27
|
+
const char *vocab, size_t vocab_len, const char *merges, size_t merges_len,
|
|
28
|
+
const char *added_tokens, size_t added_tokens_len);
|
|
29
|
+
|
|
30
|
+
void tokenizers_encode(TokenizerHandle handle, const char *data, size_t len,
|
|
31
|
+
int add_special_token, TokenizerEncodeResult *result);
|
|
32
|
+
|
|
33
|
+
void tokenizers_encode_batch(TokenizerHandle handle, const char **data,
|
|
34
|
+
size_t *len, size_t num_seqs,
|
|
35
|
+
int add_special_token,
|
|
36
|
+
TokenizerEncodeResult *results);
|
|
37
|
+
|
|
38
|
+
void tokenizers_free_encode_results(TokenizerEncodeResult *results,
|
|
39
|
+
size_t num_seqs);
|
|
40
|
+
|
|
41
|
+
void tokenizers_decode(TokenizerHandle handle, const uint32_t *data, size_t len,
|
|
42
|
+
int skip_special_token);
|
|
43
|
+
|
|
44
|
+
void tokenizers_get_decode_str(TokenizerHandle handle, const char **data,
|
|
45
|
+
size_t *len);
|
|
46
|
+
|
|
47
|
+
void tokenizers_get_vocab_size(TokenizerHandle handle, size_t *size);
|
|
48
|
+
|
|
49
|
+
void tokenizers_id_to_token(TokenizerHandle handle, uint32_t id,
|
|
50
|
+
const char **data, size_t *len);
|
|
51
|
+
|
|
52
|
+
// tokenizers_token_to_id stores -1 to *id if the token is not in the vocab
|
|
53
|
+
void tokenizers_token_to_id(TokenizerHandle handle, const char *token,
|
|
54
|
+
size_t len, int32_t *id);
|
|
55
|
+
|
|
56
|
+
void tokenizers_free(TokenizerHandle handle);
|
|
57
|
+
|
|
58
|
+
#ifdef __cplusplus
|
|
59
|
+
}
|
|
60
|
+
#endif
|
|
61
|
+
#endif // TOKENIZERS_C_H_
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
#define C10_USING_CUSTOM_GENERATED_MACROS
|
|
2
|
+
#pragma once
|
|
3
|
+
|
|
4
|
+
/* Header file to define the common scaffolding for exported symbols.
|
|
5
|
+
*
|
|
6
|
+
* Export is by itself a quite tricky situation to deal with, and if you are
|
|
7
|
+
* hitting this file, make sure you start with the background here:
|
|
8
|
+
* - Linux: https://gcc.gnu.org/wiki/Visibility
|
|
9
|
+
* - Windows:
|
|
10
|
+
* https://docs.microsoft.com/en-us/cpp/cpp/dllexport-dllimport?view=vs-2017
|
|
11
|
+
*
|
|
12
|
+
* Do NOT include this file directly. Instead, use c10/macros/Macros.h
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
// You do not need to edit this part of file unless you are changing the core
|
|
16
|
+
// pytorch export abstractions.
|
|
17
|
+
//
|
|
18
|
+
// This part defines the C10 core export and import macros. This is controlled
|
|
19
|
+
// by whether we are building shared libraries or not, which is determined
|
|
20
|
+
// during build time and codified in c10/core/cmake_macros.h.
|
|
21
|
+
// When the library is built as a shared lib, EXPORT and IMPORT will contain
|
|
22
|
+
// visibility attributes. If it is being built as a static lib, then EXPORT
|
|
23
|
+
// and IMPORT basically have no effect.
|
|
24
|
+
|
|
25
|
+
// As a rule of thumb, you should almost NEVER mix static and shared builds for
|
|
26
|
+
// libraries that depend on c10. AKA, if c10 is built as a static library, we
|
|
27
|
+
// recommend everything dependent on c10 to be built statically. If c10 is built
|
|
28
|
+
// as a shared library, everything dependent on it should be built as shared. In
|
|
29
|
+
// the PyTorch project, all native libraries shall use the macro
|
|
30
|
+
// C10_BUILD_SHARED_LIB to check whether pytorch is building shared or static
|
|
31
|
+
// libraries.
|
|
32
|
+
|
|
33
|
+
// For build systems that do not directly depend on CMake and directly build
|
|
34
|
+
// from the source directory (such as Buck), one may not have a cmake_macros.h
|
|
35
|
+
// file at all. In this case, the build system is responsible for providing
|
|
36
|
+
// correct macro definitions corresponding to the cmake_macros.h.in file.
|
|
37
|
+
//
|
|
38
|
+
// In such scenarios, one should define the macro
|
|
39
|
+
// C10_USING_CUSTOM_GENERATED_MACROS
|
|
40
|
+
// to inform this header that it does not need to include the cmake_macros.h
|
|
41
|
+
// file.
|
|
42
|
+
|
|
43
|
+
#ifdef _WIN32
|
|
44
|
+
#define C10_HIDDEN
|
|
45
|
+
#if defined(C10_BUILD_SHARED_LIBS)
|
|
46
|
+
#define C10_EXPORT __declspec(dllexport)
|
|
47
|
+
#define C10_IMPORT __declspec(dllimport)
|
|
48
|
+
#else
|
|
49
|
+
#define C10_EXPORT
|
|
50
|
+
#define C10_IMPORT
|
|
51
|
+
#endif
|
|
52
|
+
#else // _WIN32
|
|
53
|
+
#if defined(__GNUC__)
|
|
54
|
+
#define C10_EXPORT __attribute__((__visibility__("default")))
|
|
55
|
+
#define C10_HIDDEN __attribute__((__visibility__("hidden")))
|
|
56
|
+
#else // defined(__GNUC__)
|
|
57
|
+
#define C10_EXPORT
|
|
58
|
+
#define C10_HIDDEN
|
|
59
|
+
#endif // defined(__GNUC__)
|
|
60
|
+
#define C10_IMPORT C10_EXPORT
|
|
61
|
+
#endif // _WIN32
|
|
62
|
+
|
|
63
|
+
#ifdef NO_EXPORT
|
|
64
|
+
#undef C10_EXPORT
|
|
65
|
+
#define C10_EXPORT
|
|
66
|
+
#endif
|
|
67
|
+
|
|
68
|
+
// Definition of an adaptive XX_API macro, that depends on whether you are
|
|
69
|
+
// building the library itself or not, routes to XX_EXPORT and XX_IMPORT.
|
|
70
|
+
// Basically, you will need to do this for each shared library that you are
|
|
71
|
+
// building, and the instruction is as follows: assuming that you are building
|
|
72
|
+
// a library called libawesome.so. You should:
|
|
73
|
+
// (1) for your cmake target (usually done by "add_library(awesome, ...)"),
|
|
74
|
+
// define a macro called AWESOME_BUILD_MAIN_LIB using
|
|
75
|
+
// target_compile_options.
|
|
76
|
+
// (2) define the AWESOME_API macro similar to the one below.
|
|
77
|
+
// And in the source file of your awesome library, use AWESOME_API to
|
|
78
|
+
// annotate public symbols.
|
|
79
|
+
|
|
80
|
+
// Here, for the C10 library, we will define the macro C10_API for both import
|
|
81
|
+
// and export.
|
|
82
|
+
|
|
83
|
+
// This one is being used by libc10.so
|
|
84
|
+
#ifdef C10_BUILD_MAIN_LIB
|
|
85
|
+
#define C10_API C10_EXPORT
|
|
86
|
+
#else
|
|
87
|
+
#define C10_API C10_IMPORT
|
|
88
|
+
#endif
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
3
|
+
<plist version="1.0">
|
|
4
|
+
<dict>
|
|
5
|
+
<key>AvailableLibraries</key>
|
|
6
|
+
<array>
|
|
7
|
+
<dict>
|
|
8
|
+
<key>BinaryPath</key>
|
|
9
|
+
<string>ExecutorchLib.framework/ExecutorchLib</string>
|
|
10
|
+
<key>LibraryIdentifier</key>
|
|
11
|
+
<string>ios-arm64</string>
|
|
12
|
+
<key>LibraryPath</key>
|
|
13
|
+
<string>ExecutorchLib.framework</string>
|
|
14
|
+
<key>SupportedArchitectures</key>
|
|
15
|
+
<array>
|
|
16
|
+
<string>arm64</string>
|
|
17
|
+
</array>
|
|
18
|
+
<key>SupportedPlatform</key>
|
|
19
|
+
<string>ios</string>
|
|
20
|
+
</dict>
|
|
21
|
+
<dict>
|
|
22
|
+
<key>BinaryPath</key>
|
|
23
|
+
<string>ExecutorchLib.framework/ExecutorchLib</string>
|
|
24
|
+
<key>LibraryIdentifier</key>
|
|
25
|
+
<string>ios-arm64-simulator</string>
|
|
26
|
+
<key>LibraryPath</key>
|
|
27
|
+
<string>ExecutorchLib.framework</string>
|
|
28
|
+
<key>SupportedArchitectures</key>
|
|
29
|
+
<array>
|
|
30
|
+
<string>arm64</string>
|
|
31
|
+
</array>
|
|
32
|
+
<key>SupportedPlatform</key>
|
|
33
|
+
<string>ios</string>
|
|
34
|
+
<key>SupportedPlatformVariant</key>
|
|
35
|
+
<string>simulator</string>
|
|
36
|
+
</dict>
|
|
37
|
+
</array>
|
|
38
|
+
<key>CFBundlePackageType</key>
|
|
39
|
+
<string>XFWK</string>
|
|
40
|
+
<key>XCFrameworkFormatVersion</key>
|
|
41
|
+
<string>1.0</string>
|
|
42
|
+
</dict>
|
|
43
|
+
</plist>
|
package/third-party/ios/ExecutorchLib.xcframework/ios-arm64/ExecutorchLib.framework/ExecutorchLib
ADDED
|
Binary file
|
package/third-party/ios/ExecutorchLib.xcframework/ios-arm64/ExecutorchLib.framework/Info.plist
ADDED
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|