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
|
@@ -0,0 +1,131 @@
|
|
|
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
|
+
|
|
11
|
+
#include <executorch/extension/module/module.h>
|
|
12
|
+
|
|
13
|
+
#ifdef USE_ATEN_LIB
|
|
14
|
+
#define ET_BUNDLED_MODULE_NAMESPACE bundled_module::aten
|
|
15
|
+
#else // !USE_ATEN_LIB
|
|
16
|
+
#define ET_BUNDLED_MODULE_NAMESPACE bundled_module
|
|
17
|
+
#endif // USE_ATEN_LIB
|
|
18
|
+
|
|
19
|
+
namespace executorch {
|
|
20
|
+
namespace extension {
|
|
21
|
+
|
|
22
|
+
using ET_MODULE_NAMESPACE::Module;
|
|
23
|
+
|
|
24
|
+
namespace ET_BUNDLED_MODULE_NAMESPACE {
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* A facade class for loading bundled programs and executing methods within
|
|
28
|
+
* them.
|
|
29
|
+
*/
|
|
30
|
+
class BundledModule : public Module {
|
|
31
|
+
public:
|
|
32
|
+
/**
|
|
33
|
+
* Constructs an instance with the bundled program buffer pointer.
|
|
34
|
+
*
|
|
35
|
+
* This constructor reads the program from bundled program buffer to load the
|
|
36
|
+
* module with data loader. The bundled program pointer is preserved so that
|
|
37
|
+
* the portion outside of program is accessible.
|
|
38
|
+
*
|
|
39
|
+
* @param[in] bundled_program_ptr A DataLoader used for loading program data.
|
|
40
|
+
* @param[in] memory_allocator A MemoryAllocator used for memory management.
|
|
41
|
+
* @param[in] temp_allocator A MemoryAllocator to use when allocating
|
|
42
|
+
* temporary data during kernel or delegate execution.
|
|
43
|
+
* @param[in] event_tracer A EventTracer used for tracking and logging events.
|
|
44
|
+
* @param[in] data_map_loader A DataLoader used for loading external weights.
|
|
45
|
+
*/
|
|
46
|
+
explicit BundledModule(
|
|
47
|
+
const void *bundled_program_ptr,
|
|
48
|
+
std::unique_ptr<runtime::MemoryAllocator> memory_allocator = nullptr,
|
|
49
|
+
std::unique_ptr<runtime::MemoryAllocator> temp_allocator = nullptr,
|
|
50
|
+
std::unique_ptr<runtime::EventTracer> event_tracer = nullptr,
|
|
51
|
+
std::unique_ptr<runtime::DataLoader> data_map_loader = nullptr);
|
|
52
|
+
|
|
53
|
+
// Disallow copying
|
|
54
|
+
BundledModule(const BundledModule &) = delete;
|
|
55
|
+
BundledModule &operator=(const BundledModule &) = delete;
|
|
56
|
+
// Disallow copying
|
|
57
|
+
BundledModule(BundledModule &&) = delete;
|
|
58
|
+
BundledModule &operator=(BundledModule &&) = delete;
|
|
59
|
+
// Default destructor
|
|
60
|
+
~BundledModule() {
|
|
61
|
+
if (is_loaded_from_file_) {
|
|
62
|
+
delete[] static_cast<const uint8_t *>(bundled_program_ptr_);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Constructs an instance by loading a bundled program from a file with
|
|
68
|
+
* specified memory locking behavior.
|
|
69
|
+
*
|
|
70
|
+
* @param[in] file_path The path to the ExecuTorch bundled program file to
|
|
71
|
+
* load.
|
|
72
|
+
* @param[in] memory_allocator A MemoryAllocator used for memory management.
|
|
73
|
+
* @param[in] temp_allocator A MemoryAllocator to use when allocating
|
|
74
|
+
* temporary data during kernel or delegate execution.
|
|
75
|
+
* @param[in] event_tracer A EventTracer used for tracking and logging events.
|
|
76
|
+
* @param[in] data_map_loader A DataLoader used for loading external weights.
|
|
77
|
+
*/
|
|
78
|
+
ET_NODISCARD static runtime::Result<std::unique_ptr<BundledModule>> from_file(
|
|
79
|
+
const std::string &file_path,
|
|
80
|
+
std::unique_ptr<runtime::MemoryAllocator> memory_allocator = nullptr,
|
|
81
|
+
std::unique_ptr<runtime::MemoryAllocator> temp_allocator = nullptr,
|
|
82
|
+
std::unique_ptr<runtime::EventTracer> event_tracer = nullptr,
|
|
83
|
+
std::unique_ptr<runtime::DataLoader> data_map_loader = nullptr);
|
|
84
|
+
|
|
85
|
+
using Module::execute;
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Execute a specific method with the input value at the given `testset_idx`
|
|
89
|
+
* from the bundle to the method. Loads the program and method before
|
|
90
|
+
* executing if needed.
|
|
91
|
+
*
|
|
92
|
+
* This function is a wrapper of `load_bundled_input` in `bundled_program`.
|
|
93
|
+
*
|
|
94
|
+
* @param[in] method_name The name of the method to execute.
|
|
95
|
+
* @param[in] testset_idx The index of the input value to be passed to the
|
|
96
|
+
* method.
|
|
97
|
+
*
|
|
98
|
+
* @returns Return Error::Ok on a successful load, or the error happens during
|
|
99
|
+
* execution.
|
|
100
|
+
*/
|
|
101
|
+
ET_NODISCARD
|
|
102
|
+
runtime::Result<std::vector<runtime::EValue>>
|
|
103
|
+
execute(const std::string &method_name, const size_t testset_idx);
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Verify the output of a specific method with the expected output from the
|
|
107
|
+
* program bundle at the given `testset_idx`.
|
|
108
|
+
*
|
|
109
|
+
* This function is a wrapper of `verify_method_outputs` in `bundled_program`.
|
|
110
|
+
*
|
|
111
|
+
* @param[in] method_name The name of the method to extract outputs from.
|
|
112
|
+
* @param[in] testset_idx The index of expected output needs to be compared.
|
|
113
|
+
* @param[in] rtol Relative tolerance used for data comparsion.
|
|
114
|
+
* @param[in] atol Absolute tolerance used for data comparsion.
|
|
115
|
+
*
|
|
116
|
+
* @returns Return Error::Ok if two outputs match, or the error happens during
|
|
117
|
+
* execution.
|
|
118
|
+
*/
|
|
119
|
+
ET_NODISCARD
|
|
120
|
+
runtime::Error verify_method_outputs(const std::string &method_name,
|
|
121
|
+
const size_t testset_idx,
|
|
122
|
+
double rtol = 1e-5, double atol = 1e-8);
|
|
123
|
+
|
|
124
|
+
private:
|
|
125
|
+
const void *bundled_program_ptr_;
|
|
126
|
+
bool is_loaded_from_file_ = false;
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
} // namespace ET_BUNDLED_MODULE_NAMESPACE
|
|
130
|
+
} // namespace extension
|
|
131
|
+
} // namespace executorch
|
|
@@ -16,9 +16,23 @@
|
|
|
16
16
|
|
|
17
17
|
#include <executorch/runtime/executor/program.h>
|
|
18
18
|
|
|
19
|
+
#ifdef USE_ATEN_LIB
|
|
20
|
+
#define ET_MODULE_NAMESPACE module::aten
|
|
21
|
+
#else // !USE_ATEN_LIB
|
|
22
|
+
#define ET_MODULE_NAMESPACE module
|
|
23
|
+
#endif // USE_ATEN_LIB
|
|
24
|
+
|
|
19
25
|
namespace executorch {
|
|
20
26
|
namespace extension {
|
|
21
27
|
|
|
28
|
+
using ET_RUNTIME_NAMESPACE::Method;
|
|
29
|
+
using ET_RUNTIME_NAMESPACE::MethodMeta;
|
|
30
|
+
using ET_RUNTIME_NAMESPACE::NamedDataMap;
|
|
31
|
+
using ET_RUNTIME_NAMESPACE::Program;
|
|
32
|
+
|
|
33
|
+
class ExecuTorchJni;
|
|
34
|
+
|
|
35
|
+
namespace ET_MODULE_NAMESPACE {
|
|
22
36
|
/**
|
|
23
37
|
* A facade class for loading programs and executing methods within them.
|
|
24
38
|
*/
|
|
@@ -47,7 +61,7 @@ public:
|
|
|
47
61
|
* @param[in] event_tracer A EventTracer used for tracking and logging events.
|
|
48
62
|
*/
|
|
49
63
|
explicit Module(const std::string &file_path,
|
|
50
|
-
const LoadMode load_mode = LoadMode::
|
|
64
|
+
const LoadMode load_mode = LoadMode::File,
|
|
51
65
|
std::unique_ptr<runtime::EventTracer> event_tracer = nullptr);
|
|
52
66
|
|
|
53
67
|
/**
|
|
@@ -61,7 +75,7 @@ public:
|
|
|
61
75
|
*/
|
|
62
76
|
explicit Module(const std::string &file_path,
|
|
63
77
|
const std::string &data_map_path,
|
|
64
|
-
const LoadMode load_mode = LoadMode::
|
|
78
|
+
const LoadMode load_mode = LoadMode::File,
|
|
65
79
|
std::unique_ptr<runtime::EventTracer> event_tracer = nullptr);
|
|
66
80
|
|
|
67
81
|
/**
|
|
@@ -93,7 +107,7 @@ public:
|
|
|
93
107
|
* @param[in] data_map_loader A DataLoader used for loading external weights.
|
|
94
108
|
*/
|
|
95
109
|
explicit Module(
|
|
96
|
-
std::shared_ptr<
|
|
110
|
+
std::shared_ptr<Program> program,
|
|
97
111
|
std::unique_ptr<runtime::MemoryAllocator> memory_allocator = nullptr,
|
|
98
112
|
std::unique_ptr<runtime::MemoryAllocator> temp_allocator = nullptr,
|
|
99
113
|
std::unique_ptr<runtime::EventTracer> event_tracer = nullptr,
|
|
@@ -103,7 +117,7 @@ public:
|
|
|
103
117
|
Module &operator=(const Module &) = delete;
|
|
104
118
|
Module(Module &&) = delete;
|
|
105
119
|
Module &operator=(Module &&) = delete;
|
|
106
|
-
|
|
120
|
+
virtual ~Module() = default;
|
|
107
121
|
/**
|
|
108
122
|
* Loads the program if needed.
|
|
109
123
|
*
|
|
@@ -112,16 +126,16 @@ public:
|
|
|
112
126
|
*
|
|
113
127
|
* @returns An Error to indicate success or failure of the loading process.
|
|
114
128
|
*/
|
|
115
|
-
ET_NODISCARD
|
|
116
|
-
|
|
117
|
-
|
|
129
|
+
ET_NODISCARD virtual runtime::Error
|
|
130
|
+
load(const Program::Verification verification =
|
|
131
|
+
Program::Verification::Minimal);
|
|
118
132
|
|
|
119
133
|
/**
|
|
120
134
|
* Checks if the program is loaded.
|
|
121
135
|
*
|
|
122
136
|
* @returns true if the program is loaded, false otherwise.
|
|
123
137
|
*/
|
|
124
|
-
inline bool is_loaded() const { return program_ != nullptr; }
|
|
138
|
+
virtual inline bool is_loaded() const { return program_ != nullptr; }
|
|
125
139
|
|
|
126
140
|
/**
|
|
127
141
|
* Get the program. The data loader used by the program is guaranteed to be
|
|
@@ -129,7 +143,7 @@ public:
|
|
|
129
143
|
*
|
|
130
144
|
* @returns Shared pointer to the program or nullptr if it's not yet loaded.
|
|
131
145
|
*/
|
|
132
|
-
inline std::shared_ptr<
|
|
146
|
+
inline std::shared_ptr<Program> program() const { return program_; }
|
|
133
147
|
|
|
134
148
|
/**
|
|
135
149
|
* Get the number of methods available in the loaded program.
|
|
@@ -210,15 +224,14 @@ public:
|
|
|
210
224
|
|
|
211
225
|
/**
|
|
212
226
|
* Get a method metadata struct by method name.
|
|
213
|
-
* Loads the program
|
|
227
|
+
* Loads the program if needed.
|
|
214
228
|
*
|
|
215
229
|
* @param[in] method_name The name of the method to get the metadata for.
|
|
216
230
|
*
|
|
217
231
|
* @returns A method metadata, or an error if the program or method failed to
|
|
218
232
|
* load.
|
|
219
233
|
*/
|
|
220
|
-
runtime::Result<
|
|
221
|
-
method_meta(const std::string &method_name);
|
|
234
|
+
runtime::Result<MethodMeta> method_meta(const std::string &method_name);
|
|
222
235
|
|
|
223
236
|
/**
|
|
224
237
|
* Execute a specific method with the given input values and retrieve the
|
|
@@ -231,8 +244,7 @@ public:
|
|
|
231
244
|
* @returns A Result object containing either a vector of output values
|
|
232
245
|
* from the method or an error to indicate failure.
|
|
233
246
|
*/
|
|
234
|
-
ET_NODISCARD
|
|
235
|
-
runtime::Result<std::vector<runtime::EValue>>
|
|
247
|
+
ET_NODISCARD virtual runtime::Result<std::vector<runtime::EValue>>
|
|
236
248
|
execute(const std::string &method_name,
|
|
237
249
|
const std::vector<runtime::EValue> &input_values);
|
|
238
250
|
|
|
@@ -453,33 +465,40 @@ public:
|
|
|
453
465
|
return event_tracer_.get();
|
|
454
466
|
}
|
|
455
467
|
|
|
468
|
+
ET_NODISCARD
|
|
469
|
+
runtime::Span<uint8_t> debug_buffer() {
|
|
470
|
+
return runtime::Span<uint8_t>(debug_buffer_.data(), debug_buffer_.size());
|
|
471
|
+
}
|
|
472
|
+
|
|
456
473
|
private:
|
|
457
474
|
struct MethodHolder {
|
|
458
475
|
std::vector<std::vector<uint8_t>> planned_buffers;
|
|
459
476
|
std::vector<runtime::Span<uint8_t>> planned_spans;
|
|
460
477
|
std::unique_ptr<runtime::HierarchicalAllocator> planned_memory;
|
|
461
478
|
std::unique_ptr<runtime::MemoryManager> memory_manager;
|
|
462
|
-
std::unique_ptr<
|
|
479
|
+
std::unique_ptr<Method> method;
|
|
463
480
|
std::vector<runtime::EValue> inputs;
|
|
464
481
|
};
|
|
465
482
|
|
|
466
483
|
std::string file_path_;
|
|
467
484
|
std::string data_map_path_;
|
|
468
|
-
LoadMode load_mode_{LoadMode::
|
|
469
|
-
std::shared_ptr<
|
|
485
|
+
LoadMode load_mode_{LoadMode::File};
|
|
486
|
+
std::shared_ptr<Program> program_;
|
|
470
487
|
std::unique_ptr<runtime::DataLoader> data_loader_;
|
|
471
488
|
std::unique_ptr<runtime::MemoryAllocator> memory_allocator_;
|
|
472
489
|
std::unique_ptr<runtime::MemoryAllocator> temp_allocator_;
|
|
473
490
|
std::unique_ptr<runtime::EventTracer> event_tracer_;
|
|
474
491
|
std::unique_ptr<runtime::DataLoader> data_map_loader_;
|
|
475
|
-
std::unique_ptr<
|
|
492
|
+
std::unique_ptr<NamedDataMap> data_map_;
|
|
493
|
+
std::vector<uint8_t> debug_buffer_;
|
|
476
494
|
|
|
477
495
|
protected:
|
|
478
496
|
std::unordered_map<std::string, MethodHolder> methods_;
|
|
479
497
|
|
|
480
|
-
friend class ExecuTorchJni;
|
|
498
|
+
friend class executorch::extension::ExecuTorchJni;
|
|
481
499
|
};
|
|
482
500
|
|
|
501
|
+
} // namespace ET_MODULE_NAMESPACE
|
|
483
502
|
} // namespace extension
|
|
484
503
|
} // namespace executorch
|
|
485
504
|
|
|
@@ -487,6 +506,13 @@ namespace torch {
|
|
|
487
506
|
namespace executor {
|
|
488
507
|
// TODO(T197294990): Remove these deprecated aliases once all users have moved
|
|
489
508
|
// to the new `::executorch` namespaces.
|
|
490
|
-
using ::executorch::extension::Module;
|
|
509
|
+
using ::executorch::extension::ET_MODULE_NAMESPACE::Module;
|
|
491
510
|
} // namespace executor
|
|
492
511
|
} // namespace torch
|
|
512
|
+
|
|
513
|
+
namespace executorch {
|
|
514
|
+
namespace extension {
|
|
515
|
+
// backward compatible namespace alias
|
|
516
|
+
using ::executorch::extension::ET_MODULE_NAMESPACE::Module;
|
|
517
|
+
} // namespace extension
|
|
518
|
+
} // namespace executorch
|
|
@@ -7,9 +7,8 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
#pragma once
|
|
10
|
-
#if defined(__ANDROID__) && defined(__aarch64__)
|
|
11
10
|
|
|
12
|
-
#include <cpuinfo.h>
|
|
11
|
+
#include <cpuinfo/cpuinfo.h>
|
|
13
12
|
|
|
14
13
|
namespace executorch::extension::cpuinfo {
|
|
15
14
|
|
|
@@ -23,4 +22,3 @@ namespace torch::executorch::cpuinfo { // DEPRECATED
|
|
|
23
22
|
// the namespace `torch::executorch` instead of `torch::executor`.
|
|
24
23
|
using ::executorch::extension::cpuinfo::get_num_performant_cores; // DEPRECATED
|
|
25
24
|
} // namespace torch::executorch::cpuinfo
|
|
26
|
-
#endif
|
|
@@ -7,13 +7,12 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
#pragma once
|
|
10
|
-
#if defined(__ANDROID__) && defined(__aarch64__)
|
|
11
10
|
|
|
12
11
|
#include <functional>
|
|
13
12
|
#include <memory>
|
|
14
13
|
#include <mutex>
|
|
15
14
|
|
|
16
|
-
#include <pthreadpool.h>
|
|
15
|
+
#include <pthreadpool/pthreadpool.h>
|
|
17
16
|
|
|
18
17
|
namespace executorch::extension::threadpool {
|
|
19
18
|
|
|
@@ -91,4 +90,3 @@ using ::executorch::extension::threadpool::get_pthreadpool; // DEPRECATED
|
|
|
91
90
|
using ::executorch::extension::threadpool::get_threadpool; // DEPRECATED
|
|
92
91
|
using ::executorch::extension::threadpool::ThreadPool; // DEPRECATED
|
|
93
92
|
} // namespace torch::executorch::threadpool
|
|
94
|
-
#endif
|
|
@@ -0,0 +1,35 @@
|
|
|
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
|
+
|
|
11
|
+
namespace executorch::extension::threadpool {
|
|
12
|
+
|
|
13
|
+
// A RAII, thread local (!) guard that enables or disables guard upon
|
|
14
|
+
// construction, and sets it back to the original value upon destruction.
|
|
15
|
+
struct NoThreadPoolGuard {
|
|
16
|
+
static bool is_enabled();
|
|
17
|
+
static void set_enabled(bool enabled);
|
|
18
|
+
|
|
19
|
+
NoThreadPoolGuard() : prev_mode_(NoThreadPoolGuard::is_enabled()) {
|
|
20
|
+
NoThreadPoolGuard::set_enabled(true);
|
|
21
|
+
}
|
|
22
|
+
~NoThreadPoolGuard() { NoThreadPoolGuard::set_enabled(prev_mode_); }
|
|
23
|
+
|
|
24
|
+
private:
|
|
25
|
+
const bool prev_mode_;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
} // namespace executorch::extension::threadpool
|
|
29
|
+
|
|
30
|
+
namespace torch::executorch::threadpool { // DEPRECATED
|
|
31
|
+
// TODO(T197294990): Remove these deprecated aliases once all users have moved
|
|
32
|
+
// to the new `::executorch` namespaces. Note that threadpool incorrectly used
|
|
33
|
+
// the namespace `torch::executorch` instead of `torch::executor`.
|
|
34
|
+
using ::executorch::extension::threadpool::NoThreadPoolGuard; // DEPRECATED
|
|
35
|
+
} // namespace torch::executorch::threadpool
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
#include <executorch/runtime/core/memory_allocator.h>
|
|
13
13
|
|
|
14
14
|
namespace executorch {
|
|
15
|
-
namespace
|
|
15
|
+
namespace ET_RUNTIME_NAMESPACE {
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* BackendExecutionContext will be used to inject run time context.
|
|
@@ -59,13 +59,13 @@ private:
|
|
|
59
59
|
const char *method_name_ = nullptr;
|
|
60
60
|
};
|
|
61
61
|
|
|
62
|
-
} // namespace
|
|
62
|
+
} // namespace ET_RUNTIME_NAMESPACE
|
|
63
63
|
} // namespace executorch
|
|
64
64
|
|
|
65
65
|
namespace torch {
|
|
66
66
|
namespace executor {
|
|
67
67
|
// TODO(T197294990): Remove these deprecated aliases once all users have moved
|
|
68
68
|
// to the new `::executorch` namespaces.
|
|
69
|
-
using ::executorch::
|
|
69
|
+
using ::executorch::ET_RUNTIME_NAMESPACE::BackendExecutionContext;
|
|
70
70
|
} // namespace executor
|
|
71
71
|
} // namespace torch
|
|
@@ -7,12 +7,12 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
#pragma once
|
|
10
|
+
#include <executorch/runtime/core/event_tracer.h>
|
|
10
11
|
#include <executorch/runtime/core/memory_allocator.h>
|
|
11
12
|
#include <executorch/runtime/core/named_data_map.h>
|
|
12
13
|
|
|
13
14
|
namespace executorch {
|
|
14
|
-
namespace
|
|
15
|
-
|
|
15
|
+
namespace ET_RUNTIME_NAMESPACE {
|
|
16
16
|
/**
|
|
17
17
|
* BackendInitContext will be used to inject runtime info for to initialize
|
|
18
18
|
* delegate.
|
|
@@ -23,8 +23,14 @@ public:
|
|
|
23
23
|
EventTracer *event_tracer = nullptr,
|
|
24
24
|
const char *method_name = nullptr,
|
|
25
25
|
const NamedDataMap *named_data_map = nullptr)
|
|
26
|
-
: runtime_allocator_(runtime_allocator),
|
|
27
|
-
|
|
26
|
+
: runtime_allocator_(runtime_allocator),
|
|
27
|
+
#ifdef ET_EVENT_TRACER_ENABLED
|
|
28
|
+
event_tracer_(event_tracer),
|
|
29
|
+
#else
|
|
30
|
+
event_tracer_(nullptr),
|
|
31
|
+
#endif
|
|
32
|
+
method_name_(method_name), named_data_map_(named_data_map) {
|
|
33
|
+
}
|
|
28
34
|
|
|
29
35
|
/** Get the runtime allocator passed from Method. It's the same runtime
|
|
30
36
|
* executor used by the standard executor runtime and the life span is the
|
|
@@ -60,13 +66,13 @@ private:
|
|
|
60
66
|
const NamedDataMap *named_data_map_ = nullptr;
|
|
61
67
|
};
|
|
62
68
|
|
|
63
|
-
} // namespace
|
|
69
|
+
} // namespace ET_RUNTIME_NAMESPACE
|
|
64
70
|
} // namespace executorch
|
|
65
71
|
|
|
66
72
|
namespace torch {
|
|
67
73
|
namespace executor {
|
|
68
74
|
// TODO(T197294990): Remove these deprecated aliases once all users have moved
|
|
69
75
|
// to the new `::executorch` namespaces.
|
|
70
|
-
using ::executorch::
|
|
76
|
+
using ::executorch::ET_RUNTIME_NAMESPACE::BackendInitContext;
|
|
71
77
|
} // namespace executor
|
|
72
78
|
} // namespace torch
|
|
@@ -0,0 +1,34 @@
|
|
|
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
|
+
#include <executorch/runtime/core/event_tracer.h>
|
|
11
|
+
#include <executorch/runtime/core/memory_allocator.h>
|
|
12
|
+
#include <executorch/runtime/core/named_data_map.h>
|
|
13
|
+
|
|
14
|
+
namespace executorch {
|
|
15
|
+
namespace ET_RUNTIME_NAMESPACE {
|
|
16
|
+
/**
|
|
17
|
+
* BackendOptionContext will be used to inject runtime info for to initialize
|
|
18
|
+
* delegate.
|
|
19
|
+
*/
|
|
20
|
+
class BackendOptionContext final {
|
|
21
|
+
public:
|
|
22
|
+
explicit BackendOptionContext() {}
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
} // namespace ET_RUNTIME_NAMESPACE
|
|
26
|
+
} // namespace executorch
|
|
27
|
+
|
|
28
|
+
namespace torch {
|
|
29
|
+
namespace executor {
|
|
30
|
+
// TODO(T197294990): Remove these deprecated aliases once all users have moved
|
|
31
|
+
// to the new `::executorch` namespaces.
|
|
32
|
+
using ::executorch::ET_RUNTIME_NAMESPACE::BackendOptionContext;
|
|
33
|
+
} // namespace executor
|
|
34
|
+
} // namespace torch
|
|
@@ -12,6 +12,8 @@
|
|
|
12
12
|
|
|
13
13
|
#include <executorch/runtime/backend/backend_execution_context.h>
|
|
14
14
|
#include <executorch/runtime/backend/backend_init_context.h>
|
|
15
|
+
#include <executorch/runtime/backend/backend_option_context.h>
|
|
16
|
+
#include <executorch/runtime/backend/options.h>
|
|
15
17
|
#include <executorch/runtime/core/array_ref.h>
|
|
16
18
|
#include <executorch/runtime/core/error.h>
|
|
17
19
|
#include <executorch/runtime/core/evalue.h>
|
|
@@ -22,7 +24,7 @@
|
|
|
22
24
|
#include <executorch/runtime/platform/compiler.h>
|
|
23
25
|
|
|
24
26
|
namespace executorch {
|
|
25
|
-
namespace
|
|
27
|
+
namespace ET_RUNTIME_NAMESPACE {
|
|
26
28
|
|
|
27
29
|
struct SizedBuffer {
|
|
28
30
|
void *buffer;
|
|
@@ -97,6 +99,37 @@ public:
|
|
|
97
99
|
DelegateHandle *handle,
|
|
98
100
|
EValue **args) const = 0;
|
|
99
101
|
|
|
102
|
+
/**
|
|
103
|
+
* Responsible update the backend status, if any. The backend options are
|
|
104
|
+
* passed in by users, and the backend can update its internal status based on
|
|
105
|
+
* the options.
|
|
106
|
+
*
|
|
107
|
+
* @param[in] context Runtime context if any. Currently it's not used.
|
|
108
|
+
* @param[in] args A list of BackendOptions passed in by users.
|
|
109
|
+
* @retval Error::Ok if successful.
|
|
110
|
+
*/
|
|
111
|
+
ET_NODISCARD virtual Error
|
|
112
|
+
set_option(__ET_UNUSED BackendOptionContext &context,
|
|
113
|
+
const executorch::runtime::Span<BackendOption> &backend_options) {
|
|
114
|
+
return Error::Ok;
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Responsible update the backend status, if any. The backend options are
|
|
119
|
+
* passed in by users, and the backend can update its internal status based on
|
|
120
|
+
* the options.
|
|
121
|
+
*
|
|
122
|
+
* @param[in] context Runtime context if any. Currently it's not used.
|
|
123
|
+
* @param[in] args A list of BackendOptions passed in by users, that will be
|
|
124
|
+
* filled by the backend
|
|
125
|
+
* @retval Error::Ok if successful.
|
|
126
|
+
*/
|
|
127
|
+
ET_NODISCARD virtual Error
|
|
128
|
+
get_option(__ET_UNUSED BackendOptionContext &context,
|
|
129
|
+
executorch::runtime::Span<BackendOption> &backend_options) {
|
|
130
|
+
return Error::Ok;
|
|
131
|
+
};
|
|
132
|
+
|
|
100
133
|
/**
|
|
101
134
|
* Responsible for destroying a handle, if it's required for some backend.
|
|
102
135
|
* It may be needed for some backends. For example, resources associated with
|
|
@@ -148,19 +181,47 @@ size_t get_num_registered_backends();
|
|
|
148
181
|
*/
|
|
149
182
|
Result<const char *> get_backend_name(size_t index);
|
|
150
183
|
|
|
151
|
-
|
|
184
|
+
/**
|
|
185
|
+
* Sets backend options for a specific backend.
|
|
186
|
+
*
|
|
187
|
+
* @param backend_name The name of the backend to set options for
|
|
188
|
+
* @param backend_options The backend option list containing the options
|
|
189
|
+
* to set
|
|
190
|
+
* @return Error::Ok on success, Error::NotFound if backend is not found, or
|
|
191
|
+
* other error codes on failure
|
|
192
|
+
*/
|
|
193
|
+
Error set_option(
|
|
194
|
+
const char *backend_name,
|
|
195
|
+
const executorch::runtime::Span<executorch::runtime::BackendOption>
|
|
196
|
+
backend_options);
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Retrieves backend options for a specific backend.
|
|
200
|
+
*
|
|
201
|
+
* @param backend_name The name of the backend to get options from
|
|
202
|
+
* @param backend_options The backend option objects that will be filled with
|
|
203
|
+
* the populated values from the backend
|
|
204
|
+
* @return Error::Ok on success, Error::NotFound if backend is not found, or
|
|
205
|
+
* other error codes on failure
|
|
206
|
+
*/
|
|
207
|
+
Error get_option(const char *backend_name,
|
|
208
|
+
executorch::runtime::Span<executorch::runtime::BackendOption>
|
|
209
|
+
backend_options);
|
|
210
|
+
|
|
211
|
+
} // namespace ET_RUNTIME_NAMESPACE
|
|
152
212
|
} // namespace executorch
|
|
153
213
|
|
|
154
214
|
namespace torch {
|
|
155
215
|
namespace executor {
|
|
156
216
|
// TODO(T197294990): Remove these deprecated aliases once all users have moved
|
|
157
217
|
// to the new `::executorch` namespaces.
|
|
158
|
-
using ::executorch::
|
|
159
|
-
using ::executorch::
|
|
160
|
-
using ::executorch::
|
|
161
|
-
using ::executorch::
|
|
162
|
-
using ::executorch::
|
|
163
|
-
using ::executorch::
|
|
164
|
-
using PyTorchBackendInterface =
|
|
218
|
+
using ::executorch::ET_RUNTIME_NAMESPACE::Backend;
|
|
219
|
+
using ::executorch::ET_RUNTIME_NAMESPACE::CompileSpec;
|
|
220
|
+
using ::executorch::ET_RUNTIME_NAMESPACE::DelegateHandle;
|
|
221
|
+
using ::executorch::ET_RUNTIME_NAMESPACE::get_backend_class;
|
|
222
|
+
using ::executorch::ET_RUNTIME_NAMESPACE::register_backend;
|
|
223
|
+
using ::executorch::ET_RUNTIME_NAMESPACE::SizedBuffer;
|
|
224
|
+
using PyTorchBackendInterface =
|
|
225
|
+
::executorch::ET_RUNTIME_NAMESPACE::BackendInterface;
|
|
165
226
|
} // namespace executor
|
|
166
227
|
} // namespace torch
|