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
|
@@ -34,12 +34,13 @@ typedef NSNumber *
|
|
|
34
34
|
ExecuTorchScalarValue NS_SWIFT_BRIDGED_TYPEDEF NS_SWIFT_NAME(ScalarValue);
|
|
35
35
|
typedef NSString *
|
|
36
36
|
ExecuTorchStringValue NS_SWIFT_BRIDGED_TYPEDEF NS_SWIFT_NAME(StringValue);
|
|
37
|
-
typedef BOOL
|
|
38
|
-
ExecuTorchBooleanValue NS_SWIFT_BRIDGED_TYPEDEF NS_SWIFT_NAME(BoolValue);
|
|
37
|
+
typedef BOOL ExecuTorchBooleanValue NS_SWIFT_NAME(BoolValue);
|
|
39
38
|
typedef NSInteger
|
|
40
39
|
ExecuTorchIntegerValue NS_SWIFT_BRIDGED_TYPEDEF NS_SWIFT_NAME(IntegerValue);
|
|
41
40
|
typedef double
|
|
42
41
|
ExecuTorchDoubleValue NS_SWIFT_BRIDGED_TYPEDEF NS_SWIFT_NAME(DoubleValue);
|
|
42
|
+
typedef float
|
|
43
|
+
ExecuTorchFloatValue NS_SWIFT_BRIDGED_TYPEDEF NS_SWIFT_NAME(FloatValue);
|
|
43
44
|
|
|
44
45
|
/**
|
|
45
46
|
* A dynamic value type used by ExecuTorch.
|
|
@@ -49,7 +50,7 @@ typedef double
|
|
|
49
50
|
*/
|
|
50
51
|
NS_SWIFT_NAME(Value)
|
|
51
52
|
__attribute__((deprecated("This API is experimental.")))
|
|
52
|
-
@interface ExecuTorchValue : NSObject
|
|
53
|
+
@interface ExecuTorchValue : NSObject<NSCopying>
|
|
53
54
|
|
|
54
55
|
/**
|
|
55
56
|
* The tag that indicates the dynamic type of the value.
|
|
@@ -64,7 +65,7 @@ __attribute__((deprecated("This API is experimental.")))
|
|
|
64
65
|
* @return A Tensor instance or nil.
|
|
65
66
|
*/
|
|
66
67
|
@property(nullable, nonatomic, readonly)
|
|
67
|
-
ExecuTorchTensor *tensorValue
|
|
68
|
+
ExecuTorchTensor *tensorValue NS_REFINED_FOR_SWIFT;
|
|
68
69
|
|
|
69
70
|
/**
|
|
70
71
|
* The string value if the tag is ExecuTorchValueTagString.
|
|
@@ -106,6 +107,14 @@ __attribute__((deprecated("This API is experimental.")))
|
|
|
106
107
|
@property(nonatomic, readonly)
|
|
107
108
|
ExecuTorchDoubleValue doubleValue NS_SWIFT_NAME(double);
|
|
108
109
|
|
|
110
|
+
/**
|
|
111
|
+
* The float value if the tag is ExecuTorchValueTagDouble.
|
|
112
|
+
*
|
|
113
|
+
* @return An float representing the float value.
|
|
114
|
+
*/
|
|
115
|
+
@property(nonatomic, readonly)
|
|
116
|
+
ExecuTorchFloatValue floatValue NS_SWIFT_NAME(float);
|
|
117
|
+
|
|
109
118
|
/**
|
|
110
119
|
* Returns YES if the value is of type None.
|
|
111
120
|
*
|
|
@@ -155,6 +164,16 @@ __attribute__((deprecated("This API is experimental.")))
|
|
|
155
164
|
*/
|
|
156
165
|
@property(nonatomic, readonly) BOOL isDouble;
|
|
157
166
|
|
|
167
|
+
/**
|
|
168
|
+
* Returns YES if the value's tag is Double.
|
|
169
|
+
*
|
|
170
|
+
* Note: Since float values are stored with a Double tag, this property will
|
|
171
|
+
* also be YES for values created from floats.
|
|
172
|
+
*
|
|
173
|
+
* @return A BOOL indicating whether the value is a float.
|
|
174
|
+
*/
|
|
175
|
+
@property(nonatomic, readonly) BOOL isFloat;
|
|
176
|
+
|
|
158
177
|
/**
|
|
159
178
|
* Creates an instance encapsulating a Tensor.
|
|
160
179
|
*
|
|
@@ -163,7 +182,7 @@ __attribute__((deprecated("This API is experimental.")))
|
|
|
163
182
|
* ExecuTorchValueTagTensor.
|
|
164
183
|
*/
|
|
165
184
|
+ (instancetype)valueWithTensor:(ExecuTorchTensor *)value
|
|
166
|
-
NS_SWIFT_NAME(init(_:));
|
|
185
|
+
NS_SWIFT_NAME(init(_:)) NS_RETURNS_RETAINED;
|
|
167
186
|
|
|
168
187
|
/**
|
|
169
188
|
* Creates an instance encapsulating a string.
|
|
@@ -173,7 +192,7 @@ __attribute__((deprecated("This API is experimental.")))
|
|
|
173
192
|
* ExecuTorchValueTagString.
|
|
174
193
|
*/
|
|
175
194
|
+ (instancetype)valueWithString:(ExecuTorchStringValue)value
|
|
176
|
-
NS_SWIFT_NAME(init(_:));
|
|
195
|
+
NS_SWIFT_NAME(init(_:)) NS_RETURNS_RETAINED;
|
|
177
196
|
|
|
178
197
|
/**
|
|
179
198
|
* Creates an instance encapsulating a boolean.
|
|
@@ -183,7 +202,7 @@ __attribute__((deprecated("This API is experimental.")))
|
|
|
183
202
|
* ExecuTorchValueTagBoolean.
|
|
184
203
|
*/
|
|
185
204
|
+ (instancetype)valueWithBoolean:(ExecuTorchBooleanValue)value
|
|
186
|
-
NS_SWIFT_NAME(init(_:));
|
|
205
|
+
NS_SWIFT_NAME(init(_:)) NS_RETURNS_RETAINED;
|
|
187
206
|
|
|
188
207
|
/**
|
|
189
208
|
* Creates an instance encapsulating an integer.
|
|
@@ -193,7 +212,7 @@ __attribute__((deprecated("This API is experimental.")))
|
|
|
193
212
|
* ExecuTorchValueTagInteger.
|
|
194
213
|
*/
|
|
195
214
|
+ (instancetype)valueWithInteger:(ExecuTorchIntegerValue)value
|
|
196
|
-
NS_SWIFT_NAME(init(_:));
|
|
215
|
+
NS_SWIFT_NAME(init(_:)) NS_RETURNS_RETAINED;
|
|
197
216
|
|
|
198
217
|
/**
|
|
199
218
|
* Creates an instance encapsulating a double value.
|
|
@@ -203,7 +222,40 @@ __attribute__((deprecated("This API is experimental.")))
|
|
|
203
222
|
* ExecuTorchValueTagDouble.
|
|
204
223
|
*/
|
|
205
224
|
+ (instancetype)valueWithDouble:(ExecuTorchDoubleValue)value
|
|
206
|
-
NS_SWIFT_NAME(init(_:));
|
|
225
|
+
NS_SWIFT_NAME(init(_:)) NS_RETURNS_RETAINED;
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Creates an instance encapsulating a float value.
|
|
229
|
+
*
|
|
230
|
+
* Note: The underlying value will be stored with a tag of
|
|
231
|
+
* ExecuTorchValueTagDouble, as there is no distinct float tag.
|
|
232
|
+
*
|
|
233
|
+
* @param value A float value.
|
|
234
|
+
* @return A new ExecuTorchValue instance with a tag of
|
|
235
|
+
* ExecuTorchValueTagDouble.
|
|
236
|
+
*/
|
|
237
|
+
+ (instancetype)valueWithFloat:(ExecuTorchFloatValue)value
|
|
238
|
+
NS_SWIFT_NAME(init(_:)) NS_RETURNS_RETAINED;
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Creates an instance encapsulating a scalar value.
|
|
242
|
+
*
|
|
243
|
+
* The value's tag will be set according to the type encoding of the
|
|
244
|
+
* ExecuTorchScalarValue.
|
|
245
|
+
*
|
|
246
|
+
* @param value An ExecuTorchScalarValue.
|
|
247
|
+
* @return A new ExecuTorchValue instance with the appropriate tag.
|
|
248
|
+
*/
|
|
249
|
+
+ (instancetype)valueWithScalar:(ExecuTorchScalarValue)value
|
|
250
|
+
NS_SWIFT_NAME(init(_:)) NS_RETURNS_RETAINED;
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* Returns a copy of the value.
|
|
254
|
+
*
|
|
255
|
+
* @return A new ExecuTorchValue instance that is a duplicate of the current
|
|
256
|
+
* value.
|
|
257
|
+
*/
|
|
258
|
+
- (instancetype)copy;
|
|
207
259
|
|
|
208
260
|
/**
|
|
209
261
|
* Determines whether the current Value is equal to another Value.
|
package/third-party/include/executorch/extension/kernel_util/make_boxed_from_unboxed_functor.h
ADDED
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
* All rights reserved.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the BSD-style license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
//===----------------------------------------------------------------------===//
|
|
10
|
+
/// \file extension/kernel_util/make_boxed_from_unboxed_functor.h
|
|
11
|
+
/// Defines a template that can be used to create a boxed version of an unboxed
|
|
12
|
+
/// functor.
|
|
13
|
+
/// Example usage:
|
|
14
|
+
/// ```
|
|
15
|
+
/// Tensor&
|
|
16
|
+
/// my_op(KernelRuntimeContext& ctx, const Tensor& self, const Tensor& other,
|
|
17
|
+
/// Tensor& out)
|
|
18
|
+
/// {
|
|
19
|
+
/// // ...
|
|
20
|
+
/// return out;
|
|
21
|
+
/// }
|
|
22
|
+
///
|
|
23
|
+
/// Kernel my_kernel = Kernel::make_boxed_kernel("my_ns::my_op",
|
|
24
|
+
/// EXECUTORCH_FN(my_op));
|
|
25
|
+
/// static auto res = register_kernels({my_kernel});
|
|
26
|
+
/// ```
|
|
27
|
+
/// Or simply:
|
|
28
|
+
/// ```
|
|
29
|
+
/// EXECUTORCH_LIBRARY(my_ns, "my_op", my_op);
|
|
30
|
+
/// ```
|
|
31
|
+
///
|
|
32
|
+
/// The trick here is to convert each EValue to inferred argument type. This
|
|
33
|
+
/// uses a lot of C++17 features.
|
|
34
|
+
//===----------------------------------------------------------------------===//
|
|
35
|
+
|
|
36
|
+
#pragma once
|
|
37
|
+
#if __cplusplus < 201703L
|
|
38
|
+
#error "This header requires C++17"
|
|
39
|
+
#endif
|
|
40
|
+
|
|
41
|
+
#include <cstdlib>
|
|
42
|
+
#include <executorch/extension/kernel_util/meta_programming.h>
|
|
43
|
+
#include <executorch/extension/kernel_util/type_list.h>
|
|
44
|
+
#include <executorch/runtime/core/evalue.h>
|
|
45
|
+
#include <executorch/runtime/core/exec_aten/exec_aten.h>
|
|
46
|
+
#include <executorch/runtime/kernel/operator_registry.h>
|
|
47
|
+
#include <memory>
|
|
48
|
+
#include <type_traits>
|
|
49
|
+
#include <typeinfo>
|
|
50
|
+
|
|
51
|
+
namespace executorch {
|
|
52
|
+
namespace runtime {
|
|
53
|
+
class KernelRuntimeContext; // Forward declaration
|
|
54
|
+
} // namespace runtime
|
|
55
|
+
} // namespace executorch
|
|
56
|
+
|
|
57
|
+
namespace executorch {
|
|
58
|
+
namespace extension {
|
|
59
|
+
|
|
60
|
+
// This extension has a lot of generic internal names like "size"; use a unique
|
|
61
|
+
// internal namespace to avoid conflicts with other extensions.
|
|
62
|
+
namespace kernel_util_internal {
|
|
63
|
+
|
|
64
|
+
template <class T> struct decay_if_not_tensor final {
|
|
65
|
+
using type = std::decay_t<T>;
|
|
66
|
+
};
|
|
67
|
+
template <> struct decay_if_not_tensor<executorch::aten::Tensor &> final {
|
|
68
|
+
using type = executorch::aten::Tensor &;
|
|
69
|
+
};
|
|
70
|
+
template <> struct decay_if_not_tensor<const executorch::aten::Tensor &> final {
|
|
71
|
+
using type = const executorch::aten::Tensor &;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
template <class T> struct evalue_to_arg final {
|
|
75
|
+
static T call(executorch::runtime::EValue &v) { return std::move(v).to<T>(); }
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
template <> struct evalue_to_arg<executorch::aten::Tensor &> final {
|
|
79
|
+
static executorch::aten::Tensor &call(executorch::runtime::EValue &v) {
|
|
80
|
+
return v.toTensor();
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
template <> struct evalue_to_arg<const executorch::aten::Tensor &> final {
|
|
85
|
+
static const executorch::aten::Tensor &call(executorch::runtime::EValue &v) {
|
|
86
|
+
return v.toTensor();
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
template <class T> struct evalue_to_arg<std::optional<T>> final {
|
|
91
|
+
static std::optional<T> call(executorch::runtime::EValue &v) {
|
|
92
|
+
return v.toOptional<T>();
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
template <class T>
|
|
97
|
+
struct evalue_to_arg<executorch::aten::ArrayRef<std::optional<T>>> final {
|
|
98
|
+
static executorch::aten::ArrayRef<std::optional<T>>
|
|
99
|
+
call(executorch::runtime::EValue &v) {
|
|
100
|
+
return v.toListOptionalTensor();
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
template <class Functor, size_t... evalue_arg_indices, typename... ArgTypes>
|
|
105
|
+
void call_functor_with_args_from_stack(
|
|
106
|
+
::executorch::runtime::KernelRuntimeContext &ctx,
|
|
107
|
+
executorch::runtime::EValue **stack,
|
|
108
|
+
std::index_sequence<evalue_arg_indices...>, typelist<ArgTypes...> *) {
|
|
109
|
+
(*Functor::func_ptr())(
|
|
110
|
+
ctx, evalue_to_arg<typename decay_if_not_tensor<ArgTypes>::type>::call(
|
|
111
|
+
*stack[evalue_arg_indices])...);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
} // namespace kernel_util_internal
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* WrapUnboxedIntoFunctor: Given a function pointer, wrap it into a functor that
|
|
118
|
+
* takes EValues as input and returns void. The wrapped functor will unbox all
|
|
119
|
+
* inputs and forward them to unboxed kernel.
|
|
120
|
+
*/
|
|
121
|
+
template <class FuncType> struct WrapUnboxedIntoFunctor {
|
|
122
|
+
static_assert(
|
|
123
|
+
kernel_util_internal::is_compile_time_function_pointer<FuncType>::value,
|
|
124
|
+
"Can't handle function other than EXECUTORCH_FN");
|
|
125
|
+
using TrueType = typename FuncType::FuncType;
|
|
126
|
+
using ReturnType = typename kernel_util_internal::infer_function_traits_t<
|
|
127
|
+
TrueType>::return_type;
|
|
128
|
+
using ArgsType = typename kernel_util_internal::infer_function_traits_t<
|
|
129
|
+
TrueType>::parameter_types;
|
|
130
|
+
// check if the first argument is KernelRuntimeContext, if so, remove it
|
|
131
|
+
static constexpr bool first_arg_is_context = std::is_same<
|
|
132
|
+
::executorch::runtime::KernelRuntimeContext,
|
|
133
|
+
std::remove_reference_t<
|
|
134
|
+
kernel_util_internal::head_with_default_t<void, ArgsType>>>::value;
|
|
135
|
+
using ContextRemovedArgsType =
|
|
136
|
+
std::conditional_t<first_arg_is_context,
|
|
137
|
+
kernel_util_internal::drop_if_nonempty_t<ArgsType, 1>,
|
|
138
|
+
ArgsType>;
|
|
139
|
+
|
|
140
|
+
static void call(::executorch::runtime::KernelRuntimeContext &ctx,
|
|
141
|
+
executorch::runtime::EValue **stack) {
|
|
142
|
+
constexpr size_t num_inputs =
|
|
143
|
+
kernel_util_internal::size<ContextRemovedArgsType>::value;
|
|
144
|
+
return kernel_util_internal::call_functor_with_args_from_stack<FuncType>(
|
|
145
|
+
ctx, stack, std::make_index_sequence<num_inputs>(),
|
|
146
|
+
static_cast<ContextRemovedArgsType *>(nullptr));
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
template <typename FuncType>
|
|
151
|
+
static executorch::runtime::Kernel make_boxed_kernel(const char *name,
|
|
152
|
+
FuncType) {
|
|
153
|
+
return executorch::runtime::Kernel(name,
|
|
154
|
+
WrapUnboxedIntoFunctor<FuncType>::call);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
} // namespace extension
|
|
158
|
+
} // namespace executorch
|
|
159
|
+
|
|
160
|
+
// Inspired from C10_CONCATENATE
|
|
161
|
+
#define ET_CONCATENATE_IMPL(s1, s2) s1##s2
|
|
162
|
+
#define ET_CONCATENATE(s1, s2) ET_CONCATENATE_IMPL(s1, s2)
|
|
163
|
+
#define ET_UID __LINE__
|
|
164
|
+
|
|
165
|
+
#define EXECUTORCH_LIBRARY(ns, op_name, func) \
|
|
166
|
+
_EXECUTORCH_LIBRARY_IMPL(ns, op_name, func, ET_UID)
|
|
167
|
+
|
|
168
|
+
#define _EXECUTORCH_LIBRARY_IMPL(ns, op_name, func, uid) \
|
|
169
|
+
static auto ET_CONCATENATE(res_##ns##_, uid) = \
|
|
170
|
+
::executorch::runtime::register_kernel( \
|
|
171
|
+
::executorch::extension::make_boxed_kernel(#ns "::" op_name, \
|
|
172
|
+
EXECUTORCH_FN(func)))
|
|
173
|
+
|
|
174
|
+
namespace torch {
|
|
175
|
+
namespace executor {
|
|
176
|
+
// TODO(T197294990): Remove these deprecated aliases once all users have moved
|
|
177
|
+
// to the new `::executorch` namespaces.
|
|
178
|
+
using ::executorch::extension::make_boxed_kernel;
|
|
179
|
+
using ::executorch::extension::WrapUnboxedIntoFunctor;
|
|
180
|
+
} // namespace executor
|
|
181
|
+
} // namespace torch
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
* All rights reserved.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the BSD-style license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
#pragma once
|
|
10
|
+
#if __cplusplus < 201703L
|
|
11
|
+
#error "This header requires C++17"
|
|
12
|
+
#endif
|
|
13
|
+
|
|
14
|
+
#include <cstdlib>
|
|
15
|
+
#include <executorch/extension/kernel_util/type_list.h>
|
|
16
|
+
#include <memory>
|
|
17
|
+
#include <type_traits>
|
|
18
|
+
#include <typeinfo>
|
|
19
|
+
|
|
20
|
+
namespace executorch {
|
|
21
|
+
namespace extension {
|
|
22
|
+
// This extension has a lot of generic internal names like "size"; use a unique
|
|
23
|
+
// internal namespace to avoid conflicts with other extensions.
|
|
24
|
+
namespace kernel_util_internal {
|
|
25
|
+
|
|
26
|
+
// Check if a given type is a function
|
|
27
|
+
template <class T> struct is_function_type : std::false_type {};
|
|
28
|
+
template <class Result, class... Args>
|
|
29
|
+
struct is_function_type<Result(Args...)> : std::true_type {};
|
|
30
|
+
template <class T>
|
|
31
|
+
using is_function_type_t = typename is_function_type<T>::type;
|
|
32
|
+
|
|
33
|
+
// A compile-time wrapper around a function pointer
|
|
34
|
+
template <class FuncType_, FuncType_ *func_ptr_>
|
|
35
|
+
struct CompileTimeFunctionPointer final {
|
|
36
|
+
static_assert(is_function_type<FuncType_>::value,
|
|
37
|
+
"EXECUTORCH_FN can only wrap function types.");
|
|
38
|
+
using FuncType = FuncType_;
|
|
39
|
+
|
|
40
|
+
static constexpr FuncType *func_ptr() { return func_ptr_; }
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
// Check if a given type is a compile-time function pointer
|
|
44
|
+
template <class T> struct is_compile_time_function_pointer : std::false_type {};
|
|
45
|
+
template <class FuncType, FuncType *func_ptr>
|
|
46
|
+
struct is_compile_time_function_pointer<
|
|
47
|
+
CompileTimeFunctionPointer<FuncType, func_ptr>> : std::true_type {};
|
|
48
|
+
|
|
49
|
+
#define EXECUTORCH_FN_TYPE(func) \
|
|
50
|
+
::executorch::extension::kernel_util_internal::CompileTimeFunctionPointer< \
|
|
51
|
+
std::remove_pointer_t<std::remove_reference_t<decltype(func)>>, func>
|
|
52
|
+
#define EXECUTORCH_FN(func) EXECUTORCH_FN_TYPE(func)()
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* strip_class: helper to remove the class type from pointers to `operator()`.
|
|
56
|
+
*/
|
|
57
|
+
template <typename T> struct strip_class {};
|
|
58
|
+
template <typename Class, typename Result, typename... Args>
|
|
59
|
+
struct strip_class<Result (Class::*)(Args...)> {
|
|
60
|
+
using type = Result(Args...);
|
|
61
|
+
};
|
|
62
|
+
template <typename Class, typename Result, typename... Args>
|
|
63
|
+
struct strip_class<Result (Class::*)(Args...) const> {
|
|
64
|
+
using type = Result(Args...);
|
|
65
|
+
};
|
|
66
|
+
template <typename T> using strip_class_t = typename strip_class<T>::type;
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Access information about result type or arguments from a function type.
|
|
70
|
+
* Example:
|
|
71
|
+
* using A = function_traits<int (float, double)>::return_type // A == int
|
|
72
|
+
* using A = function_traits<int (float, double)>::parameter_types::tuple_type
|
|
73
|
+
* // A == tuple<float, double>
|
|
74
|
+
*/
|
|
75
|
+
template <class Func> struct function_traits {
|
|
76
|
+
static_assert(
|
|
77
|
+
!std::is_same<Func, Func>::value,
|
|
78
|
+
"In function_traits<Func>, Func must be a plain function type.");
|
|
79
|
+
};
|
|
80
|
+
template <class Result, class... Args> struct function_traits<Result(Args...)> {
|
|
81
|
+
using func_type = Result(Args...);
|
|
82
|
+
using return_type = Result;
|
|
83
|
+
using parameter_types = typelist<Args...>;
|
|
84
|
+
static constexpr auto number_of_parameters = sizeof...(Args);
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* infer_function_traits: creates a `function_traits` type for a simple
|
|
89
|
+
* function (pointer) or functor (lambda/struct). Currently does not support
|
|
90
|
+
* class methods.
|
|
91
|
+
*/
|
|
92
|
+
template <typename Functor> struct infer_function_traits {
|
|
93
|
+
using type = function_traits<strip_class_t<decltype(&Functor::operator())>>;
|
|
94
|
+
};
|
|
95
|
+
template <typename Result, typename... Args>
|
|
96
|
+
struct infer_function_traits<Result (*)(Args...)> {
|
|
97
|
+
using type = function_traits<Result(Args...)>;
|
|
98
|
+
};
|
|
99
|
+
template <typename Result, typename... Args>
|
|
100
|
+
struct infer_function_traits<Result(Args...)> {
|
|
101
|
+
using type = function_traits<Result(Args...)>;
|
|
102
|
+
};
|
|
103
|
+
template <typename T>
|
|
104
|
+
using infer_function_traits_t = typename infer_function_traits<T>::type;
|
|
105
|
+
|
|
106
|
+
} // namespace kernel_util_internal
|
|
107
|
+
} // namespace extension
|
|
108
|
+
} // namespace executorch
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
* All rights reserved.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the BSD-style license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
///
|
|
10
|
+
/// \file runtime/kernel/type_list.h
|
|
11
|
+
/// Forked from pytorch/c10/util/TypeList.h
|
|
12
|
+
/// \brief Utilities for working with type lists.
|
|
13
|
+
#pragma once
|
|
14
|
+
#if __cplusplus < 201703L
|
|
15
|
+
#error "This header requires C++17"
|
|
16
|
+
#endif
|
|
17
|
+
|
|
18
|
+
#include <algorithm>
|
|
19
|
+
#include <cstddef>
|
|
20
|
+
#include <type_traits>
|
|
21
|
+
#include <utility>
|
|
22
|
+
|
|
23
|
+
namespace executorch {
|
|
24
|
+
namespace extension {
|
|
25
|
+
// This extension has a lot of generic internal names like "size"; use a unique
|
|
26
|
+
// internal namespace to avoid conflicts with other extensions.
|
|
27
|
+
namespace kernel_util_internal {
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Type holding a list of types for compile time type computations
|
|
31
|
+
* constexpr size_t num = size<typelist<int, double>>::value;
|
|
32
|
+
* static_assert(num == 2, "");
|
|
33
|
+
*/
|
|
34
|
+
template <class... T> struct false_t : std::false_type {};
|
|
35
|
+
|
|
36
|
+
template <class... Items> struct typelist final {
|
|
37
|
+
public:
|
|
38
|
+
typelist() = delete; // not for instantiation
|
|
39
|
+
};
|
|
40
|
+
template <class TypeList> struct size final {
|
|
41
|
+
static_assert(false_t<TypeList>::value,
|
|
42
|
+
"In typelist::size<T>, T must be typelist<...>.");
|
|
43
|
+
};
|
|
44
|
+
template <class... Types> struct size<typelist<Types...>> final {
|
|
45
|
+
static constexpr size_t value = sizeof...(Types);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* is_instantiation_of<T, I> is true_type iff I is a template instantiation of T
|
|
50
|
+
* (e.g. vector<int> is an instantiation of vector) Example:
|
|
51
|
+
* is_instantiation_of_t<vector, vector<int>> // true
|
|
52
|
+
* is_instantiation_of_t<pair, pair<int, string>> // true
|
|
53
|
+
* is_instantiation_of_t<vector, pair<int, string>> // false
|
|
54
|
+
*/
|
|
55
|
+
template <template <class...> class Template, class T>
|
|
56
|
+
struct is_instantiation_of : std::false_type {};
|
|
57
|
+
template <template <class...> class Template, class... Args>
|
|
58
|
+
struct is_instantiation_of<Template, Template<Args...>> : std::true_type {};
|
|
59
|
+
template <template <class...> class Template, class T>
|
|
60
|
+
using is_instantiation_of_t = typename is_instantiation_of<Template, T>::type;
|
|
61
|
+
|
|
62
|
+
/// Base template.
|
|
63
|
+
template <size_t Index, class TypeList> struct element final {
|
|
64
|
+
static_assert(
|
|
65
|
+
false_t<TypeList>::value,
|
|
66
|
+
"In typelist::element<T>, the T argument must be typelist<...>.");
|
|
67
|
+
};
|
|
68
|
+
/// Successful case, we have reached the zero index and can "return" the head
|
|
69
|
+
/// type.
|
|
70
|
+
template <class Head, class... Tail>
|
|
71
|
+
struct element<0, typelist<Head, Tail...>> {
|
|
72
|
+
using type = Head;
|
|
73
|
+
};
|
|
74
|
+
/// Error case, we have an index but ran out of types! It will only be selected
|
|
75
|
+
/// if `Ts...` is actually empty!
|
|
76
|
+
template <size_t Index, class... Ts> struct element<Index, typelist<Ts...>> {
|
|
77
|
+
static_assert(Index < sizeof...(Ts),
|
|
78
|
+
"Index is out of bounds in typelist::element");
|
|
79
|
+
};
|
|
80
|
+
/// Shave off types until we hit the <0, Head, Tail...> or <Index> case.
|
|
81
|
+
template <size_t Index, class Head, class... Tail>
|
|
82
|
+
struct element<Index, typelist<Head, Tail...>>
|
|
83
|
+
: element<Index - 1, typelist<Tail...>> {};
|
|
84
|
+
/// Convenience alias.
|
|
85
|
+
template <size_t Index, class TypeList>
|
|
86
|
+
using element_t = typename element<Index, TypeList>::type;
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Returns the first element of a type list, or the specified default if the
|
|
90
|
+
* type list is empty. Example: int == head_t<bool, typelist<int, string>>
|
|
91
|
+
* bool == head_t<bool, typelist<>>
|
|
92
|
+
*/
|
|
93
|
+
template <class Default, class TypeList> struct head_with_default final {
|
|
94
|
+
using type = Default;
|
|
95
|
+
};
|
|
96
|
+
template <class Default, class Head, class... Tail>
|
|
97
|
+
struct head_with_default<Default, typelist<Head, Tail...>> final {
|
|
98
|
+
using type = Head;
|
|
99
|
+
};
|
|
100
|
+
template <class Default, class TypeList>
|
|
101
|
+
using head_with_default_t = typename head_with_default<Default, TypeList>::type;
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Take/drop a number of arguments from a typelist.
|
|
105
|
+
* Example:
|
|
106
|
+
* typelist<int, string> == take_t<typelist<int, string, bool>, 2>
|
|
107
|
+
* typelist<bool> == drop_t<typelist<int, string, bool>, 2>
|
|
108
|
+
*/
|
|
109
|
+
template <class TypeList, size_t offset, class IndexSequence>
|
|
110
|
+
struct take_elements final {};
|
|
111
|
+
template <class TypeList, size_t offset, size_t... Indices>
|
|
112
|
+
struct take_elements<TypeList, offset, std::index_sequence<Indices...>> final {
|
|
113
|
+
using type = typelist<typename element<offset + Indices, TypeList>::type...>;
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Like drop, but returns an empty list rather than an assertion error if `num`
|
|
118
|
+
* is larger than the size of the TypeList.
|
|
119
|
+
* Example:
|
|
120
|
+
* typelist<> == drop_if_nonempty_t<typelist<string, bool>, 2>
|
|
121
|
+
* typelist<> == drop_if_nonempty_t<typelist<int, string, bool>, 3>
|
|
122
|
+
*/
|
|
123
|
+
template <class TypeList, size_t num> struct drop_if_nonempty final {
|
|
124
|
+
static_assert(
|
|
125
|
+
is_instantiation_of<typelist, TypeList>::value,
|
|
126
|
+
"In typelist::drop<T, num>, the T argument must be typelist<...>.");
|
|
127
|
+
using type = typename take_elements<
|
|
128
|
+
TypeList, std::min(num, size<TypeList>::value),
|
|
129
|
+
std::make_index_sequence<size<TypeList>::value -
|
|
130
|
+
std::min(num, size<TypeList>::value)>>::type;
|
|
131
|
+
};
|
|
132
|
+
template <class TypeList, size_t num>
|
|
133
|
+
using drop_if_nonempty_t = typename drop_if_nonempty<TypeList, num>::type;
|
|
134
|
+
|
|
135
|
+
} // namespace kernel_util_internal
|
|
136
|
+
} // namespace extension
|
|
137
|
+
} // namespace executorch
|