react-native-executorch 0.5.6 → 0.5.8

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.
Files changed (237) hide show
  1. package/android/libs/classes.jar +0 -0
  2. package/android/src/main/cpp/CMakeLists.txt +23 -14
  3. package/common/rnexecutorch/RnExecutorchInstaller.cpp +4 -21
  4. package/common/rnexecutorch/host_objects/ModelHostObject.h +67 -51
  5. package/common/rnexecutorch/models/llm/LLM.cpp +24 -1
  6. package/common/rnexecutorch/models/llm/LLM.h +4 -1
  7. package/common/rnexecutorch/threads/GlobalThreadPool.h +79 -0
  8. package/common/rnexecutorch/threads/HighPerformanceThreadPool.h +364 -0
  9. package/common/rnexecutorch/threads/utils/ThreadUtils.h +29 -0
  10. package/common/runner/runner.cpp +9 -3
  11. package/common/runner/runner.h +4 -3
  12. package/common/runner/text_token_generator.h +28 -10
  13. package/lib/Error.js +53 -0
  14. package/lib/ThreadPool.d.ts +10 -0
  15. package/lib/ThreadPool.js +28 -0
  16. package/lib/common/Logger.d.ts +8 -0
  17. package/lib/common/Logger.js +19 -0
  18. package/lib/constants/directories.js +2 -0
  19. package/lib/constants/llmDefaults.d.ts +6 -0
  20. package/lib/constants/llmDefaults.js +16 -0
  21. package/lib/constants/modelUrls.d.ts +223 -0
  22. package/lib/constants/modelUrls.js +322 -0
  23. package/lib/constants/ocr/models.d.ts +882 -0
  24. package/lib/constants/ocr/models.js +182 -0
  25. package/lib/constants/ocr/symbols.js +139 -0
  26. package/lib/constants/sttDefaults.d.ts +28 -0
  27. package/lib/constants/sttDefaults.js +68 -0
  28. package/lib/controllers/LLMController.d.ts +47 -0
  29. package/lib/controllers/LLMController.js +213 -0
  30. package/lib/controllers/OCRController.js +67 -0
  31. package/lib/controllers/SpeechToTextController.d.ts +56 -0
  32. package/lib/controllers/SpeechToTextController.js +349 -0
  33. package/lib/controllers/VerticalOCRController.js +70 -0
  34. package/lib/hooks/computer_vision/useClassification.d.ts +15 -0
  35. package/lib/hooks/computer_vision/useClassification.js +7 -0
  36. package/lib/hooks/computer_vision/useImageEmbeddings.d.ts +15 -0
  37. package/lib/hooks/computer_vision/useImageEmbeddings.js +7 -0
  38. package/lib/hooks/computer_vision/useImageSegmentation.d.ts +38 -0
  39. package/lib/hooks/computer_vision/useImageSegmentation.js +7 -0
  40. package/lib/hooks/computer_vision/useOCR.d.ts +20 -0
  41. package/lib/hooks/computer_vision/useOCR.js +41 -0
  42. package/lib/hooks/computer_vision/useObjectDetection.d.ts +15 -0
  43. package/lib/hooks/computer_vision/useObjectDetection.js +7 -0
  44. package/lib/hooks/computer_vision/useStyleTransfer.d.ts +15 -0
  45. package/lib/hooks/computer_vision/useStyleTransfer.js +7 -0
  46. package/lib/hooks/computer_vision/useVerticalOCR.d.ts +21 -0
  47. package/lib/hooks/computer_vision/useVerticalOCR.js +43 -0
  48. package/lib/hooks/general/useExecutorchModule.d.ts +13 -0
  49. package/lib/hooks/general/useExecutorchModule.js +7 -0
  50. package/lib/hooks/natural_language_processing/useLLM.d.ts +10 -0
  51. package/lib/hooks/natural_language_processing/useLLM.js +78 -0
  52. package/lib/hooks/natural_language_processing/useSpeechToText.d.ts +27 -0
  53. package/lib/hooks/natural_language_processing/useSpeechToText.js +49 -0
  54. package/lib/hooks/natural_language_processing/useTextEmbeddings.d.ts +16 -0
  55. package/lib/hooks/natural_language_processing/useTextEmbeddings.js +7 -0
  56. package/lib/hooks/natural_language_processing/useTokenizer.d.ts +17 -0
  57. package/lib/hooks/natural_language_processing/useTokenizer.js +52 -0
  58. package/lib/hooks/useModule.js +45 -0
  59. package/lib/hooks/useNonStaticModule.d.ts +20 -0
  60. package/lib/hooks/useNonStaticModule.js +49 -0
  61. package/lib/index.d.ts +48 -0
  62. package/lib/index.js +58 -0
  63. package/lib/module/controllers/LLMController.js +21 -2
  64. package/lib/module/controllers/LLMController.js.map +1 -1
  65. package/lib/module/hooks/natural_language_processing/useLLM.js +6 -2
  66. package/lib/module/hooks/natural_language_processing/useLLM.js.map +1 -1
  67. package/lib/module/modules/natural_language_processing/LLMModule.js +7 -2
  68. package/lib/module/modules/natural_language_processing/LLMModule.js.map +1 -1
  69. package/lib/module/types/llm.js.map +1 -1
  70. package/lib/modules/BaseModule.js +25 -0
  71. package/lib/modules/BaseNonStaticModule.js +14 -0
  72. package/lib/modules/computer_vision/ClassificationModule.d.ts +8 -0
  73. package/lib/modules/computer_vision/ClassificationModule.js +17 -0
  74. package/lib/modules/computer_vision/ImageEmbeddingsModule.d.ts +8 -0
  75. package/lib/modules/computer_vision/ImageEmbeddingsModule.js +17 -0
  76. package/lib/modules/computer_vision/ImageSegmentationModule.d.ts +11 -0
  77. package/lib/modules/computer_vision/ImageSegmentationModule.js +27 -0
  78. package/lib/modules/computer_vision/OCRModule.d.ts +14 -0
  79. package/lib/modules/computer_vision/OCRModule.js +17 -0
  80. package/lib/modules/computer_vision/ObjectDetectionModule.d.ts +9 -0
  81. package/lib/modules/computer_vision/ObjectDetectionModule.js +17 -0
  82. package/lib/modules/computer_vision/StyleTransferModule.d.ts +8 -0
  83. package/lib/modules/computer_vision/StyleTransferModule.js +17 -0
  84. package/lib/modules/computer_vision/VerticalOCRModule.d.ts +14 -0
  85. package/lib/modules/computer_vision/VerticalOCRModule.js +19 -0
  86. package/lib/modules/general/ExecutorchModule.d.ts +7 -0
  87. package/lib/modules/general/ExecutorchModule.js +14 -0
  88. package/lib/modules/natural_language_processing/LLMModule.d.ts +28 -0
  89. package/lib/modules/natural_language_processing/LLMModule.js +45 -0
  90. package/lib/modules/natural_language_processing/SpeechToTextModule.d.ts +24 -0
  91. package/lib/modules/natural_language_processing/SpeechToTextModule.js +36 -0
  92. package/lib/modules/natural_language_processing/TextEmbeddingsModule.d.ts +9 -0
  93. package/lib/modules/natural_language_processing/TextEmbeddingsModule.js +21 -0
  94. package/lib/modules/natural_language_processing/TokenizerModule.d.ts +12 -0
  95. package/lib/modules/natural_language_processing/TokenizerModule.js +30 -0
  96. package/lib/native/NativeETInstaller.js +2 -0
  97. package/lib/native/NativeOCR.js +2 -0
  98. package/lib/native/NativeVerticalOCR.js +2 -0
  99. package/lib/native/RnExecutorchModules.d.ts +7 -0
  100. package/lib/native/RnExecutorchModules.js +18 -0
  101. package/lib/tsconfig.tsbuildinfo +1 -0
  102. package/lib/types/common.d.ts +32 -0
  103. package/lib/types/common.js +25 -0
  104. package/lib/types/imageSegmentation.js +26 -0
  105. package/lib/types/llm.d.ts +46 -0
  106. package/lib/types/llm.js +9 -0
  107. package/lib/types/objectDetection.js +94 -0
  108. package/lib/types/ocr.js +1 -0
  109. package/lib/types/stt.d.ts +94 -0
  110. package/lib/types/stt.js +85 -0
  111. package/lib/typescript/controllers/LLMController.d.ts +4 -2
  112. package/lib/typescript/controllers/LLMController.d.ts.map +1 -1
  113. package/lib/typescript/hooks/natural_language_processing/useLLM.d.ts.map +1 -1
  114. package/lib/typescript/modules/natural_language_processing/LLMModule.d.ts +4 -2
  115. package/lib/typescript/modules/natural_language_processing/LLMModule.d.ts.map +1 -1
  116. package/lib/typescript/types/llm.d.ts +7 -1
  117. package/lib/typescript/types/llm.d.ts.map +1 -1
  118. package/lib/utils/ResourceFetcher.d.ts +24 -0
  119. package/lib/utils/ResourceFetcher.js +305 -0
  120. package/lib/utils/ResourceFetcherUtils.d.ts +54 -0
  121. package/lib/utils/ResourceFetcherUtils.js +127 -0
  122. package/lib/utils/llm.d.ts +6 -0
  123. package/lib/utils/llm.js +72 -0
  124. package/lib/utils/stt.js +21 -0
  125. package/package.json +3 -1
  126. package/react-native-executorch.podspec +12 -31
  127. package/src/controllers/LLMController.ts +29 -5
  128. package/src/hooks/natural_language_processing/useLLM.ts +15 -1
  129. package/src/modules/natural_language_processing/LLMModule.ts +14 -2
  130. package/src/types/llm.ts +8 -0
  131. package/third-party/android/libs/cpuinfo/arm64-v8a/libcpuinfo.so +0 -0
  132. package/third-party/android/libs/executorch/arm64-v8a/libexecutorch.so +0 -0
  133. package/third-party/android/libs/executorch/x86_64/libexecutorch.so +0 -0
  134. package/third-party/android/libs/pthreadpool/arm64-v8a/libpthreadpool.so +0 -0
  135. package/third-party/android/libs/tokenizers-cpp/arm64-v8a/libsentencepiece.a +0 -0
  136. package/third-party/android/libs/tokenizers-cpp/arm64-v8a/libtokenizers_c.a +0 -0
  137. package/third-party/android/libs/tokenizers-cpp/arm64-v8a/libtokenizers_cpp.a +0 -0
  138. package/third-party/android/libs/tokenizers-cpp/x86_64/libsentencepiece.a +0 -0
  139. package/third-party/android/libs/tokenizers-cpp/x86_64/libtokenizers_c.a +0 -0
  140. package/third-party/android/libs/tokenizers-cpp/x86_64/libtokenizers_cpp.a +0 -0
  141. package/third-party/include/c10/macros/Export.h +2 -86
  142. package/third-party/include/c10/macros/Macros.h +28 -5
  143. package/third-party/include/c10/util/BFloat16-inl.h +1 -4
  144. package/third-party/include/c10/util/BFloat16.h +5 -8
  145. package/third-party/include/c10/util/Half.h +5 -0
  146. package/third-party/include/c10/util/bit_cast.h +1 -1
  147. package/third-party/include/c10/util/complex.h +639 -0
  148. package/third-party/include/c10/util/complex_math.h +399 -0
  149. package/third-party/include/c10/util/complex_utils.h +41 -0
  150. package/third-party/include/c10/util/irange.h +2 -2
  151. package/third-party/include/c10/util/overflows.h +95 -0
  152. package/third-party/include/executorch/ExecuTorchError.h +75 -0
  153. package/third-party/include/executorch/ExecuTorchModule.h +115 -11
  154. package/third-party/include/executorch/ExecuTorchTensor.h +731 -51
  155. package/third-party/include/executorch/ExecuTorchValue.h +61 -9
  156. package/third-party/include/executorch/extension/kernel_util/make_boxed_from_unboxed_functor.h +181 -0
  157. package/third-party/include/executorch/extension/kernel_util/meta_programming.h +108 -0
  158. package/third-party/include/executorch/extension/kernel_util/type_list.h +137 -0
  159. package/third-party/include/executorch/extension/module/bundled_module.h +131 -0
  160. package/third-party/include/executorch/extension/module/module.h +46 -20
  161. package/third-party/include/executorch/extension/threadpool/cpuinfo_utils.h +1 -3
  162. package/third-party/include/executorch/extension/threadpool/threadpool.h +1 -3
  163. package/third-party/include/executorch/extension/threadpool/threadpool_guard.h +35 -0
  164. package/third-party/include/executorch/runtime/backend/backend_execution_context.h +3 -3
  165. package/third-party/include/executorch/runtime/backend/backend_init_context.h +12 -6
  166. package/third-party/include/executorch/runtime/backend/backend_option_context.h +34 -0
  167. package/third-party/include/executorch/runtime/backend/interface.h +70 -9
  168. package/third-party/include/executorch/runtime/backend/options.h +206 -0
  169. package/third-party/include/executorch/runtime/core/evalue.h +19 -25
  170. package/third-party/include/executorch/runtime/core/event_tracer.h +32 -17
  171. package/third-party/include/executorch/runtime/core/event_tracer_hooks.h +23 -14
  172. package/third-party/include/executorch/runtime/core/exec_aten/exec_aten.h +32 -9
  173. package/third-party/include/executorch/runtime/core/exec_aten/util/dim_order_util.h +3 -2
  174. package/third-party/include/executorch/runtime/core/exec_aten/util/scalar_type_util.h +43 -75
  175. package/third-party/include/executorch/runtime/core/exec_aten/util/tensor_util.h +88 -87
  176. package/third-party/include/executorch/runtime/core/function_ref.h +100 -0
  177. package/third-party/include/executorch/runtime/core/named_data_map.h +14 -14
  178. package/third-party/include/executorch/runtime/core/portable_type/c10/c10/macros/Export.h +2 -86
  179. package/third-party/include/executorch/runtime/core/portable_type/c10/c10/macros/Macros.h +28 -5
  180. package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/BFloat16-inl.h +1 -4
  181. package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/BFloat16.h +5 -8
  182. package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/Half.h +5 -0
  183. package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/bit_cast.h +1 -1
  184. package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/complex.h +639 -0
  185. package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/complex_math.h +399 -0
  186. package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/complex_utils.h +41 -0
  187. package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/irange.h +2 -2
  188. package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/overflows.h +95 -0
  189. package/third-party/include/executorch/runtime/core/portable_type/c10/torch/headeronly/macros/Export.h +88 -0
  190. package/third-party/include/executorch/runtime/core/portable_type/complex.h +6 -29
  191. package/third-party/include/executorch/runtime/core/portable_type/tensor_impl.h +20 -0
  192. package/third-party/include/executorch/runtime/core/span.h +4 -0
  193. package/third-party/include/executorch/runtime/core/tag.h +19 -0
  194. package/third-party/include/executorch/runtime/core/tensor_layout.h +2 -2
  195. package/third-party/include/executorch/runtime/executor/method.h +15 -3
  196. package/third-party/include/executorch/runtime/executor/method_meta.h +34 -5
  197. package/third-party/include/executorch/runtime/executor/program.h +3 -4
  198. package/third-party/include/executorch/runtime/executor/pte_data_map.h +9 -8
  199. package/third-party/include/executorch/runtime/executor/tensor_parser.h +14 -13
  200. package/third-party/include/executorch/runtime/kernel/kernel_runtime_context.h +5 -5
  201. package/third-party/include/executorch/runtime/kernel/operator_registry.h +21 -19
  202. package/third-party/include/executorch/runtime/platform/compiler.h +8 -0
  203. package/third-party/include/executorch/runtime/platform/platform.h +126 -0
  204. package/third-party/include/headeronly/macros/Export.h +88 -0
  205. package/third-party/include/tokenizers-cpp/tokenizers_c.h +61 -0
  206. package/third-party/include/torch/headeronly/macros/Export.h +88 -0
  207. package/third-party/ios/ExecutorchLib.xcframework/Info.plist +43 -0
  208. package/third-party/ios/ExecutorchLib.xcframework/ios-arm64/ExecutorchLib.framework/ExecutorchLib +0 -0
  209. package/third-party/ios/ExecutorchLib.xcframework/ios-arm64/ExecutorchLib.framework/Info.plist +0 -0
  210. package/third-party/ios/ExecutorchLib.xcframework/ios-arm64-simulator/ExecutorchLib.framework/ExecutorchLib +0 -0
  211. package/third-party/ios/ExecutorchLib.xcframework/ios-arm64-simulator/ExecutorchLib.framework/Info.plist +0 -0
  212. package/third-party/ios/libs/cpuinfo/libcpuinfo.a +0 -0
  213. package/third-party/ios/libs/pthreadpool/physical-arm64-release/libpthreadpool.a +0 -0
  214. package/third-party/ios/libs/pthreadpool/simulator-arm64-debug/libpthreadpool.a +0 -0
  215. package/ios/libs/executorch/libbackend_coreml_ios.a +0 -0
  216. package/ios/libs/executorch/libbackend_coreml_simulator.a +0 -0
  217. package/ios/libs/executorch/libbackend_mps_ios.a +0 -0
  218. package/ios/libs/executorch/libbackend_mps_simulator.a +0 -0
  219. package/ios/libs/executorch/libbackend_xnnpack_ios.a +0 -0
  220. package/ios/libs/executorch/libbackend_xnnpack_simulator.a +0 -0
  221. package/ios/libs/executorch/libexecutorch_ios.a +0 -0
  222. package/ios/libs/executorch/libexecutorch_simulator.a +0 -0
  223. package/ios/libs/executorch/libkernels_custom_ios.a +0 -0
  224. package/ios/libs/executorch/libkernels_custom_simulator.a +0 -0
  225. package/ios/libs/executorch/libkernels_optimized_ios.a +0 -0
  226. package/ios/libs/executorch/libkernels_optimized_simulator.a +0 -0
  227. package/ios/libs/executorch/libkernels_portable_ios.a +0 -0
  228. package/ios/libs/executorch/libkernels_portable_simulator.a +0 -0
  229. package/ios/libs/executorch/libkernels_quantized_ios.a +0 -0
  230. package/ios/libs/executorch/libkernels_quantized_simulator.a +0 -0
  231. package/third-party/ios/ios.toolchain.cmake +0 -1122
  232. /package/{ios → third-party/ios}/libs/tokenizers-cpp/physical-arm64-release/libsentencepiece.a +0 -0
  233. /package/{ios → third-party/ios}/libs/tokenizers-cpp/physical-arm64-release/libtokenizers_c.a +0 -0
  234. /package/{ios → third-party/ios}/libs/tokenizers-cpp/physical-arm64-release/libtokenizers_cpp.a +0 -0
  235. /package/{ios → third-party/ios}/libs/tokenizers-cpp/simulator-arm64-debug/libsentencepiece.a +0 -0
  236. /package/{ios → third-party/ios}/libs/tokenizers-cpp/simulator-arm64-debug/libtokenizers_c.a +0 -0
  237. /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::MmapUseMlock,
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::MmapUseMlock,
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<runtime::Program> program,
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
- runtime::Error load(const runtime::Program::Verification verification =
117
- runtime::Program::Verification::Minimal);
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<runtime::Program> program() const { return program_; }
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 and method if needed.
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<runtime::MethodMeta>
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<runtime::Method> method;
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::MmapUseMlock};
469
- std::shared_ptr<runtime::Program> program_;
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<runtime::NamedDataMap> data_map_;
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 runtime {
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 runtime
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::runtime::BackendExecutionContext;
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 runtime {
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), method_name_(method_name),
27
- named_data_map_(named_data_map) {}
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 runtime
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::runtime::BackendInitContext;
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 runtime {
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
- } // namespace runtime
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::runtime::Backend;
159
- using ::executorch::runtime::CompileSpec;
160
- using ::executorch::runtime::DelegateHandle;
161
- using ::executorch::runtime::get_backend_class;
162
- using ::executorch::runtime::register_backend;
163
- using ::executorch::runtime::SizedBuffer;
164
- using PyTorchBackendInterface = ::executorch::runtime::BackendInterface;
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