react-native-executorch 0.5.15 → 0.6.0-nightly-897eae9-20251213

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 (277) hide show
  1. package/README.md +42 -36
  2. package/android/CMakeLists.txt +13 -25
  3. package/android/build.gradle +2 -3
  4. package/android/libs/classes.jar +0 -0
  5. package/android/src/main/cpp/CMakeLists.txt +2 -1
  6. package/common/rnexecutorch/RnExecutorchInstaller.cpp +18 -0
  7. package/common/rnexecutorch/TokenizerModule.cpp +3 -3
  8. package/common/rnexecutorch/data_processing/Numerical.cpp +31 -23
  9. package/common/rnexecutorch/data_processing/Numerical.h +6 -1
  10. package/common/rnexecutorch/data_processing/dsp.cpp +0 -46
  11. package/common/rnexecutorch/host_objects/JsiConversions.h +16 -0
  12. package/common/rnexecutorch/host_objects/ModelHostObject.h +26 -11
  13. package/common/rnexecutorch/jsi/OwningArrayBuffer.h +19 -2
  14. package/common/rnexecutorch/metaprogramming/TypeConcepts.h +0 -20
  15. package/common/rnexecutorch/models/BaseModel.cpp +12 -11
  16. package/common/rnexecutorch/models/BaseModel.h +18 -10
  17. package/common/rnexecutorch/models/embeddings/BaseEmbeddings.cpp +3 -11
  18. package/common/rnexecutorch/models/embeddings/text/TextEmbeddings.cpp +0 -1
  19. package/common/rnexecutorch/models/image_segmentation/ImageSegmentation.cpp +6 -12
  20. package/common/rnexecutorch/models/llm/LLM.cpp +25 -8
  21. package/common/rnexecutorch/models/llm/LLM.h +4 -4
  22. package/common/rnexecutorch/models/ocr/CTCLabelConverter.h +1 -1
  23. package/common/rnexecutorch/models/ocr/utils/RecognitionHandlerUtils.cpp +7 -4
  24. package/common/rnexecutorch/models/speech_to_text/SpeechToText.cpp +8 -13
  25. package/common/rnexecutorch/models/speech_to_text/SpeechToText.h +1 -3
  26. package/common/rnexecutorch/models/speech_to_text/asr/ASR.cpp +12 -19
  27. package/common/rnexecutorch/models/speech_to_text/asr/ASR.h +4 -5
  28. package/common/rnexecutorch/models/text_to_image/Constants.h +9 -0
  29. package/common/rnexecutorch/models/text_to_image/Decoder.cpp +32 -0
  30. package/common/rnexecutorch/models/text_to_image/Decoder.h +24 -0
  31. package/common/rnexecutorch/models/text_to_image/Encoder.cpp +44 -0
  32. package/common/rnexecutorch/models/text_to_image/Encoder.h +32 -0
  33. package/common/rnexecutorch/models/text_to_image/Scheduler.cpp +152 -0
  34. package/common/rnexecutorch/models/text_to_image/Scheduler.h +41 -0
  35. package/common/rnexecutorch/models/text_to_image/TextToImage.cpp +141 -0
  36. package/common/rnexecutorch/models/text_to_image/TextToImage.h +64 -0
  37. package/common/rnexecutorch/models/text_to_image/UNet.cpp +38 -0
  38. package/common/rnexecutorch/models/text_to_image/UNet.h +28 -0
  39. package/common/rnexecutorch/models/voice_activity_detection/Constants.h +27 -0
  40. package/common/rnexecutorch/models/voice_activity_detection/Types.h +12 -0
  41. package/common/rnexecutorch/models/voice_activity_detection/Utils.cpp +15 -0
  42. package/common/rnexecutorch/models/voice_activity_detection/Utils.h +13 -0
  43. package/common/rnexecutorch/models/voice_activity_detection/VoiceActivityDetection.cpp +160 -0
  44. package/common/rnexecutorch/models/voice_activity_detection/VoiceActivityDetection.h +36 -0
  45. package/common/rnexecutorch/tests/CMakeLists.txt +30 -0
  46. package/common/rnexecutorch/tests/NumericalTest.cpp +110 -0
  47. package/common/rnexecutorch/tests/README.md +30 -13
  48. package/common/rnexecutorch/threads/GlobalThreadPool.h +4 -0
  49. package/common/runner/arange_util.cpp +44 -0
  50. package/common/runner/arange_util.h +37 -0
  51. package/common/runner/constants.h +28 -0
  52. package/common/runner/io_manager.h +240 -0
  53. package/common/runner/irunner.h +87 -16
  54. package/common/runner/kernel_includes.h +23 -0
  55. package/common/runner/runner.cpp +151 -66
  56. package/common/runner/runner.h +39 -22
  57. package/common/runner/sampler.cpp +8 -1
  58. package/common/runner/sampler.h +4 -2
  59. package/common/runner/stats.h +1 -4
  60. package/common/runner/text_decoder_runner.cpp +26 -12
  61. package/common/runner/text_decoder_runner.h +52 -31
  62. package/common/runner/text_prefiller.cpp +46 -12
  63. package/common/runner/text_prefiller.h +38 -4
  64. package/common/runner/text_token_generator.h +51 -26
  65. package/common/runner/util.h +53 -8
  66. package/ios/RnExecutorch.xcodeproj/project.pbxproj +0 -23
  67. package/lib/module/Error.js +1 -0
  68. package/lib/module/Error.js.map +1 -1
  69. package/lib/module/constants/directories.js +1 -1
  70. package/lib/module/constants/directories.js.map +1 -1
  71. package/lib/module/constants/modelUrls.js +32 -1
  72. package/lib/module/constants/modelUrls.js.map +1 -1
  73. package/lib/module/constants/ocr/models.js +7 -7
  74. package/lib/module/constants/ocr/models.js.map +1 -1
  75. package/lib/module/constants/ocr/symbols.js +3 -2
  76. package/lib/module/constants/ocr/symbols.js.map +1 -1
  77. package/lib/module/controllers/LLMController.js +10 -1
  78. package/lib/module/controllers/LLMController.js.map +1 -1
  79. package/lib/module/controllers/OCRController.js +3 -3
  80. package/lib/module/controllers/OCRController.js.map +1 -1
  81. package/lib/module/controllers/VerticalOCRController.js +2 -2
  82. package/lib/module/controllers/VerticalOCRController.js.map +1 -1
  83. package/lib/module/hooks/computer_vision/useOCR.js +3 -3
  84. package/lib/module/hooks/computer_vision/useOCR.js.map +1 -1
  85. package/lib/module/hooks/{useNonStaticModule.js → computer_vision/useTextToImage.js} +21 -16
  86. package/lib/module/hooks/computer_vision/useTextToImage.js.map +1 -0
  87. package/lib/module/hooks/computer_vision/useVerticalOCR.js +3 -3
  88. package/lib/module/hooks/computer_vision/useVerticalOCR.js.map +1 -1
  89. package/lib/module/hooks/natural_language_processing/useLLM.js +3 -3
  90. package/lib/module/hooks/natural_language_processing/useLLM.js.map +1 -1
  91. package/lib/module/hooks/natural_language_processing/useTokenizer.js +5 -5
  92. package/lib/module/hooks/natural_language_processing/useTokenizer.js.map +1 -1
  93. package/lib/module/hooks/natural_language_processing/useVAD.js +13 -0
  94. package/lib/module/hooks/natural_language_processing/useVAD.js.map +1 -0
  95. package/lib/module/index.js +7 -2
  96. package/lib/module/index.js.map +1 -1
  97. package/lib/module/modules/computer_vision/OCRModule.js +2 -2
  98. package/lib/module/modules/computer_vision/OCRModule.js.map +1 -1
  99. package/lib/module/modules/computer_vision/TextToImageModule.js +48 -0
  100. package/lib/module/modules/computer_vision/TextToImageModule.js.map +1 -0
  101. package/lib/module/modules/computer_vision/VerticalOCRModule.js +2 -2
  102. package/lib/module/modules/computer_vision/VerticalOCRModule.js.map +1 -1
  103. package/lib/module/modules/natural_language_processing/SpeechToTextModule.js +7 -4
  104. package/lib/module/modules/natural_language_processing/SpeechToTextModule.js.map +1 -1
  105. package/lib/module/modules/natural_language_processing/VADModule.js +19 -0
  106. package/lib/module/modules/natural_language_processing/VADModule.js.map +1 -0
  107. package/lib/module/types/llm.js.map +1 -1
  108. package/lib/module/types/vad.js +2 -0
  109. package/lib/module/types/vad.js.map +1 -0
  110. package/lib/module/utils/ResourceFetcher.js +2 -1
  111. package/lib/module/utils/ResourceFetcher.js.map +1 -1
  112. package/lib/module/utils/ResourceFetcherUtils.js +6 -6
  113. package/lib/module/utils/ResourceFetcherUtils.js.map +1 -1
  114. package/lib/typescript/Error.d.ts +1 -0
  115. package/lib/typescript/Error.d.ts.map +1 -1
  116. package/lib/typescript/constants/modelUrls.d.ts +23 -0
  117. package/lib/typescript/constants/modelUrls.d.ts.map +1 -1
  118. package/lib/typescript/constants/ocr/symbols.d.ts +1 -1
  119. package/lib/typescript/constants/ocr/symbols.d.ts.map +1 -1
  120. package/lib/typescript/controllers/LLMController.d.ts.map +1 -1
  121. package/lib/typescript/controllers/OCRController.d.ts +1 -1
  122. package/lib/typescript/controllers/OCRController.d.ts.map +1 -1
  123. package/lib/typescript/controllers/VerticalOCRController.d.ts +1 -1
  124. package/lib/typescript/controllers/VerticalOCRController.d.ts.map +1 -1
  125. package/lib/typescript/hooks/computer_vision/useOCR.d.ts +1 -1
  126. package/lib/typescript/hooks/computer_vision/useOCR.d.ts.map +1 -1
  127. package/lib/typescript/hooks/computer_vision/useTextToImage.d.ts +22 -0
  128. package/lib/typescript/hooks/computer_vision/useTextToImage.d.ts.map +1 -0
  129. package/lib/typescript/hooks/computer_vision/useVerticalOCR.d.ts +1 -1
  130. package/lib/typescript/hooks/computer_vision/useVerticalOCR.d.ts.map +1 -1
  131. package/lib/typescript/hooks/natural_language_processing/useLLM.d.ts.map +1 -1
  132. package/lib/typescript/hooks/natural_language_processing/useSpeechToText.d.ts +2 -2
  133. package/lib/typescript/hooks/natural_language_processing/useVAD.d.ts +16 -0
  134. package/lib/typescript/hooks/natural_language_processing/useVAD.d.ts.map +1 -0
  135. package/lib/typescript/index.d.ts +8 -1
  136. package/lib/typescript/index.d.ts.map +1 -1
  137. package/lib/typescript/modules/computer_vision/OCRModule.d.ts +1 -1
  138. package/lib/typescript/modules/computer_vision/OCRModule.d.ts.map +1 -1
  139. package/lib/typescript/modules/computer_vision/TextToImageModule.d.ts +16 -0
  140. package/lib/typescript/modules/computer_vision/TextToImageModule.d.ts.map +1 -0
  141. package/lib/typescript/modules/computer_vision/VerticalOCRModule.d.ts +1 -1
  142. package/lib/typescript/modules/computer_vision/VerticalOCRModule.d.ts.map +1 -1
  143. package/lib/typescript/modules/natural_language_processing/SpeechToTextModule.d.ts +3 -2
  144. package/lib/typescript/modules/natural_language_processing/SpeechToTextModule.d.ts.map +1 -1
  145. package/lib/typescript/modules/natural_language_processing/VADModule.d.ts +10 -0
  146. package/lib/typescript/modules/natural_language_processing/VADModule.d.ts.map +1 -0
  147. package/lib/typescript/types/llm.d.ts +2 -0
  148. package/lib/typescript/types/llm.d.ts.map +1 -1
  149. package/lib/typescript/types/vad.d.ts +5 -0
  150. package/lib/typescript/types/vad.d.ts.map +1 -0
  151. package/lib/typescript/utils/ResourceFetcher.d.ts +29 -0
  152. package/lib/typescript/utils/ResourceFetcher.d.ts.map +1 -1
  153. package/lib/typescript/utils/ResourceFetcherUtils.d.ts +2 -2
  154. package/lib/typescript/utils/ResourceFetcherUtils.d.ts.map +1 -1
  155. package/package.json +11 -8
  156. package/react-native-executorch.podspec +9 -9
  157. package/src/Error.ts +1 -0
  158. package/src/constants/directories.ts +1 -1
  159. package/src/constants/modelUrls.ts +36 -1
  160. package/src/constants/ocr/models.ts +7 -7
  161. package/src/constants/ocr/symbols.ts +3 -2
  162. package/src/controllers/LLMController.ts +12 -1
  163. package/src/controllers/OCRController.ts +3 -3
  164. package/src/controllers/VerticalOCRController.ts +2 -2
  165. package/src/hooks/computer_vision/useOCR.ts +4 -5
  166. package/src/hooks/computer_vision/useTextToImage.ts +92 -0
  167. package/src/hooks/computer_vision/useVerticalOCR.ts +4 -5
  168. package/src/hooks/natural_language_processing/useLLM.ts +3 -4
  169. package/src/hooks/natural_language_processing/useTokenizer.ts +5 -5
  170. package/src/hooks/natural_language_processing/useVAD.ts +15 -0
  171. package/src/index.ts +20 -1
  172. package/src/modules/computer_vision/OCRModule.ts +2 -2
  173. package/src/modules/computer_vision/TextToImageModule.ts +93 -0
  174. package/src/modules/computer_vision/VerticalOCRModule.ts +2 -2
  175. package/src/modules/natural_language_processing/SpeechToTextModule.ts +8 -4
  176. package/src/modules/natural_language_processing/VADModule.ts +27 -0
  177. package/src/types/llm.ts +2 -0
  178. package/src/types/vad.ts +4 -0
  179. package/src/utils/ResourceFetcher.ts +2 -1
  180. package/src/utils/ResourceFetcherUtils.ts +8 -8
  181. package/third-party/android/libs/cpuinfo/arm64-v8a/libcpuinfo.so +0 -0
  182. package/third-party/android/libs/executorch/arm64-v8a/libexecutorch.so +0 -0
  183. package/third-party/android/libs/executorch/x86_64/libexecutorch.so +0 -0
  184. package/third-party/android/libs/pthreadpool/arm64-v8a/libpthreadpool.so +0 -0
  185. package/third-party/include/c10/macros/Export.h +0 -78
  186. package/third-party/include/c10/macros/Macros.h +1 -520
  187. package/third-party/include/c10/util/BFloat16-inl.h +1 -339
  188. package/third-party/include/c10/util/BFloat16.h +1 -122
  189. package/third-party/include/c10/util/Half-inl.h +1 -347
  190. package/third-party/include/c10/util/Half.h +6 -419
  191. package/third-party/include/c10/util/TypeSafeSignMath.h +1 -133
  192. package/third-party/include/c10/util/bit_cast.h +1 -43
  193. package/third-party/include/c10/util/complex.h +1 -568
  194. package/third-party/include/c10/util/floating_point_utils.h +1 -33
  195. package/third-party/include/c10/util/irange.h +1 -1
  196. package/third-party/include/c10/util/llvmMathExtras.h +866 -0
  197. package/third-party/include/c10/util/safe_numerics.h +97 -0
  198. package/third-party/include/executorch/ExecuTorchError.h +6 -7
  199. package/third-party/include/executorch/ExecuTorchLLM/ExecuTorchLLM.h +12 -0
  200. package/third-party/include/executorch/ExecuTorchLLM/ExecuTorchLLMConfig.h +56 -0
  201. package/third-party/include/executorch/ExecuTorchLLM/ExecuTorchLLMError.h +16 -0
  202. package/third-party/include/executorch/ExecuTorchLLM/ExecuTorchLLMMultimodalRunner.h +227 -0
  203. package/third-party/include/executorch/ExecuTorchLLM/ExecuTorchLLMTextRunner.h +97 -0
  204. package/third-party/include/executorch/ExecuTorchLLM/module.modulemap +4 -0
  205. package/third-party/include/executorch/ExecuTorchLog.h +1 -0
  206. package/third-party/include/executorch/ExecuTorchModule.h +177 -4
  207. package/third-party/include/executorch/ExecuTorchTensor.h +3 -4
  208. package/third-party/include/executorch/ExecuTorchValue.h +1 -7
  209. package/third-party/include/executorch/extension/module/module.h +139 -8
  210. package/third-party/include/executorch/extension/tensor/tensor.h +1 -0
  211. package/third-party/include/executorch/extension/tensor/tensor_ptr.h +88 -26
  212. package/third-party/include/executorch/extension/threadpool/threadpool.h +4 -1
  213. package/third-party/include/executorch/runtime/backend/backend_init_context.h +6 -0
  214. package/third-party/include/executorch/runtime/backend/interface.h +1 -1
  215. package/third-party/include/executorch/runtime/core/error.h +76 -49
  216. package/third-party/include/executorch/runtime/core/exec_aten/util/scalar_type_util.h +18 -4
  217. package/third-party/include/executorch/runtime/core/memory_allocator.h +12 -2
  218. package/third-party/include/executorch/runtime/core/named_data_map.h +1 -11
  219. package/third-party/include/executorch/runtime/core/portable_type/c10/c10/macros/Export.h +0 -78
  220. package/third-party/include/executorch/runtime/core/portable_type/c10/c10/macros/Macros.h +1 -520
  221. package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/BFloat16-inl.h +1 -339
  222. package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/BFloat16.h +1 -122
  223. package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/Half-inl.h +1 -347
  224. package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/Half.h +6 -419
  225. package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/TypeSafeSignMath.h +1 -133
  226. package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/bit_cast.h +1 -43
  227. package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/complex.h +1 -568
  228. package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/floating_point_utils.h +1 -33
  229. package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/irange.h +1 -1
  230. package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/llvmMathExtras.h +866 -0
  231. package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/safe_numerics.h +97 -0
  232. package/third-party/include/executorch/runtime/core/portable_type/c10/torch/headeronly/macros/Export.h +66 -0
  233. package/third-party/include/executorch/runtime/core/portable_type/c10/torch/headeronly/macros/Macros.h +553 -0
  234. package/third-party/include/executorch/runtime/core/portable_type/c10/torch/headeronly/util/BFloat16.h +477 -0
  235. package/third-party/include/executorch/runtime/core/portable_type/c10/torch/headeronly/util/Half.h +781 -0
  236. package/third-party/include/executorch/runtime/core/portable_type/c10/torch/headeronly/util/TypeSafeSignMath.h +141 -0
  237. package/third-party/include/executorch/runtime/core/portable_type/c10/torch/headeronly/util/bit_cast.h +49 -0
  238. package/third-party/include/executorch/runtime/core/portable_type/c10/torch/headeronly/util/complex.h +593 -0
  239. package/third-party/include/executorch/runtime/core/portable_type/c10/torch/headeronly/util/floating_point_utils.h +38 -0
  240. package/third-party/include/executorch/runtime/core/tensor_layout.h +1 -1
  241. package/third-party/include/executorch/runtime/executor/merged_data_map.h +142 -0
  242. package/third-party/include/executorch/runtime/executor/method.h +21 -8
  243. package/third-party/include/executorch/runtime/executor/method_meta.h +20 -2
  244. package/third-party/include/executorch/runtime/executor/program.h +0 -10
  245. package/third-party/include/executorch/runtime/kernel/operator_registry.h +1 -1
  246. package/third-party/include/executorch/runtime/platform/compiler.h +2 -0
  247. package/third-party/include/executorch/schema/extended_header.h +10 -1
  248. package/third-party/include/torch/headeronly/macros/Export.h +66 -0
  249. package/third-party/include/torch/headeronly/macros/Macros.h +553 -0
  250. package/third-party/include/torch/headeronly/util/BFloat16.h +477 -0
  251. package/third-party/include/torch/headeronly/util/Half.h +781 -0
  252. package/third-party/include/torch/headeronly/util/TypeSafeSignMath.h +141 -0
  253. package/third-party/include/torch/headeronly/util/bit_cast.h +49 -0
  254. package/third-party/include/torch/headeronly/util/complex.h +593 -0
  255. package/third-party/include/torch/headeronly/util/floating_point_utils.h +38 -0
  256. package/third-party/ios/ExecutorchLib.xcframework/ios-arm64/ExecutorchLib.framework/ExecutorchLib +0 -0
  257. package/third-party/ios/ExecutorchLib.xcframework/ios-arm64/ExecutorchLib.framework/Info.plist +0 -0
  258. package/third-party/ios/ExecutorchLib.xcframework/ios-arm64-simulator/ExecutorchLib.framework/ExecutorchLib +0 -0
  259. package/third-party/ios/ExecutorchLib.xcframework/ios-arm64-simulator/ExecutorchLib.framework/Info.plist +0 -0
  260. package/common/rnexecutorch/tests/run_all_tests.sh +0 -14
  261. package/common/rnexecutorch/tests/run_test.sh +0 -18
  262. package/ios/RnExecutorch/utils/Conversions.h +0 -14
  263. package/ios/RnExecutorch/utils/ETError.h +0 -26
  264. package/ios/RnExecutorch/utils/ImageProcessor.h +0 -15
  265. package/ios/RnExecutorch/utils/ImageProcessor.mm +0 -147
  266. package/ios/RnExecutorch/utils/Numerical.h +0 -3
  267. package/ios/RnExecutorch/utils/Numerical.mm +0 -18
  268. package/ios/RnExecutorch/utils/ScalarType.h +0 -14
  269. package/ios/RnExecutorch/utils/ScalarType.mm +0 -21
  270. package/lib/module/hooks/useNonStaticModule.js.map +0 -1
  271. package/lib/typescript/hooks/useNonStaticModule.d.ts +0 -21
  272. package/lib/typescript/hooks/useNonStaticModule.d.ts.map +0 -1
  273. package/src/hooks/useNonStaticModule.ts +0 -74
  274. package/third-party/include/executorch/extension/kernel_util/make_boxed_from_unboxed_functor.h +0 -181
  275. package/third-party/include/executorch/extension/kernel_util/meta_programming.h +0 -108
  276. package/third-party/include/executorch/extension/kernel_util/type_list.h +0 -137
  277. package/third-party/include/executorch/extension/threadpool/threadpool_guard.h +0 -35
@@ -63,6 +63,12 @@ enum class Error : error_code_t {
63
63
  /// Operator(s) missing in the operator registry.
64
64
  OperatorMissing = 0x14,
65
65
 
66
+ /// Registration error: Exceeding the maximum number of kernels.
67
+ RegistrationExceedingMaxKernels = 0x15,
68
+
69
+ /// Registration error: The kernel is already registered.
70
+ RegistrationAlreadyRegistered = 0x16,
71
+
66
72
  /*
67
73
  * Resource errors.
68
74
  */
@@ -95,9 +101,54 @@ enum class Error : error_code_t {
95
101
  DelegateMemoryAllocationFailed = 0x31,
96
102
  /// Execute stage: The handle is invalid.
97
103
  DelegateInvalidHandle = 0x32,
98
-
99
104
  };
100
105
 
106
+ // Stringify the Error enum.
107
+ constexpr const char *to_string(const Error error) {
108
+ switch (error) {
109
+ case Error::Ok:
110
+ return "Error::Ok";
111
+ case Error::Internal:
112
+ return "Error::Internal";
113
+ case Error::InvalidState:
114
+ return "Error::InvalidState";
115
+ case Error::EndOfMethod:
116
+ return "Error::EndOfMethod";
117
+ case Error::NotSupported:
118
+ return "Error::NotSupported";
119
+ case Error::NotImplemented:
120
+ return "Error::NotImplemented";
121
+ case Error::InvalidArgument:
122
+ return "Error::InvalidArgument";
123
+ case Error::InvalidType:
124
+ return "Error::InvalidType";
125
+ case Error::OperatorMissing:
126
+ return "Error::OperatorMissing";
127
+ case Error::NotFound:
128
+ return "Error::NotFound";
129
+ case Error::MemoryAllocationFailed:
130
+ return "Error::MemoryAllocationFailed";
131
+ case Error::AccessFailed:
132
+ return "Error::AccessFailed";
133
+ case Error::InvalidProgram:
134
+ return "Error::InvalidProgram";
135
+ case Error::InvalidExternalData:
136
+ return "Error::InvalidExternalData";
137
+ case Error::OutOfResources:
138
+ return "Error::OutOfResources";
139
+ case Error::DelegateInvalidCompatibility:
140
+ return "Error::DelegateInvalidCompatibility";
141
+ case Error::DelegateMemoryAllocationFailed:
142
+ return "Error::DelegateMemoryAllocationFailed";
143
+ case Error::DelegateInvalidHandle:
144
+ return "Error::DelegateInvalidHandle";
145
+ case Error::RegistrationExceedingMaxKernels:
146
+ return "Error::RegistrationExceedingMaxKernels";
147
+ case Error::RegistrationAlreadyRegistered:
148
+ return "Error::RegistrationAlreadyRegistered";
149
+ }
150
+ }
151
+
101
152
  } // namespace runtime
102
153
  } // namespace executorch
103
154
 
@@ -154,42 +205,36 @@ using ::executorch::runtime::error_code_t;
154
205
  * @param[in] ... Optional format string for the log error message and its
155
206
  * arguments.
156
207
  */
157
- #define ET_CHECK_OK_OR_RETURN_ERROR(error__, ...) \
158
- ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR(error__, ##__VA_ARGS__)
159
-
160
- // Internal only: Use ET_CHECK_OK_OR_RETURN_ERROR() instead.
161
- #define ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR(...) \
162
- ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_SELECT(__VA_ARGS__, 10, 9, 8, 7, 6, 5, \
163
- 4, 3, 2, 1) \
164
- (__VA_ARGS__)
208
+ #define ET_CHECK_OK_OR_RETURN_ERROR(...) \
209
+ ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR(__VA_ARGS__)
165
210
 
166
211
  /**
167
212
  * Internal only: Use ET_CHECK_OK_OR_RETURN_ERROR() instead.
168
213
  * This macro selects the correct version of
169
214
  * ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR based on the number of arguments passed.
170
- * It uses a trick with the preprocessor to count the number of arguments and
171
- * then selects the appropriate macro.
172
- *
173
- * The macro expansion uses __VA_ARGS__ to accept any number of arguments and
174
- * then appends them to ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_, followed by the
175
- * count of arguments. The count is determined by the macro
176
- * ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_SELECT which takes the arguments and
177
- * passes them along with a sequence of numbers (2, 1). The preprocessor then
178
- * matches this sequence to the correct number of arguments provided.
179
- *
180
- * If two arguments are passed, ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_2 is
181
- * selected, suitable for cases where an error code and a custom message are
182
- * provided. If only one argument is passed,
183
- * ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_1 is selected, which is used for cases
184
- * with just an error code.
185
- *
186
- * Usage:
187
- * ET_CHECK_OK_OR_RETURN_ERROR(error_code); // Calls v1
188
- * ET_CHECK_OK_OR_RETURN_ERROR(error_code, "Error message", ...); // Calls v2
215
+ * It uses a helper that reliably picks the 1-arg or 2+-arg form on
216
+ * MSVC/Clang/GCC.
189
217
  */
190
- #define ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_SELECT(_1, _2, _3, _4, _5, _6, \
191
- _7, _8, _9, _10, N, ...) \
192
- ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_##N
218
+ #define ET_INTERNAL_EXPAND(x) x
219
+ #define ET_INTERNAL_GET_MACRO(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, NAME, \
220
+ ...) \
221
+ NAME
222
+
223
+ // Internal only: Use ET_CHECK_OK_OR_RETURN_ERROR() instead.
224
+ // Picks _2 for 2..10 args, _1 for exactly 1 arg.
225
+ #define ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR(...) \
226
+ ET_INTERNAL_EXPAND(ET_INTERNAL_GET_MACRO( \
227
+ __VA_ARGS__, ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_2, /* 10 */ \
228
+ ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_2, /* 9 */ \
229
+ ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_2, /* 8 */ \
230
+ ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_2, /* 7 */ \
231
+ ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_2, /* 6 */ \
232
+ ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_2, /* 5 */ \
233
+ ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_2, /* 4 */ \
234
+ ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_2, /* 3 */ \
235
+ ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_2, /* 2 */ \
236
+ ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_1 /* 1 */ \
237
+ )(__VA_ARGS__))
193
238
 
194
239
  // Internal only: Use ET_CHECK_OK_OR_RETURN_ERROR() instead.
195
240
  #define ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_1(error__) \
@@ -209,21 +254,3 @@ using ::executorch::runtime::error_code_t;
209
254
  return et_error__; \
210
255
  } \
211
256
  } while (0)
212
-
213
- // Internal only: Use ET_CHECK_OK_OR_RETURN_ERROR() instead.
214
- #define ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_3 \
215
- ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_2
216
- #define ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_4 \
217
- ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_2
218
- #define ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_5 \
219
- ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_2
220
- #define ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_6 \
221
- ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_2
222
- #define ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_7 \
223
- ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_2
224
- #define ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_8 \
225
- ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_2
226
- #define ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_9 \
227
- ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_2
228
- #define ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_10 \
229
- ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_2
@@ -867,14 +867,14 @@ public:
867
867
  #define ET_INTERNAL_SWITCH_CASE(enum_type, CTYPE_ALIAS, ...) \
868
868
  case enum_type: { \
869
869
  ET_INTERNAL_CHECK_SELECTIVE_BUILD(enum_type); \
870
- using CTYPE_ALIAS = \
870
+ using CTYPE_ALIAS [[maybe_unused]] = \
871
871
  ::executorch::runtime::ScalarTypeToCppType<enum_type>::type; \
872
872
  return __VA_ARGS__(); \
873
873
  }
874
874
  #else
875
875
  #define ET_INTERNAL_SWITCH_CASE(enum_type, CTYPE_ALIAS, ...) \
876
876
  case enum_type: { \
877
- using CTYPE_ALIAS = \
877
+ using CTYPE_ALIAS [[maybe_unused]] = \
878
878
  ::executorch::runtime::ScalarTypeToCppType<enum_type>::type; \
879
879
  return __VA_ARGS__(); \
880
880
  }
@@ -888,8 +888,9 @@ public:
888
888
  switch (_st) { \
889
889
  __VA_ARGS__ \
890
890
  default: \
891
- ET_CHECK_MSG(false, "Unhandled dtype %s for %s", \
892
- ::executorch::runtime::toString(_st), et_switch_name); \
891
+ CONTEXT.fail(torch::executor::Error::InvalidArgument); \
892
+ ET_LOG(Error, "Unhandled dtype %s for %s", \
893
+ ::executorch::runtime::toString(_st), et_switch_name); \
893
894
  } \
894
895
  }()
895
896
 
@@ -1236,6 +1237,19 @@ public:
1236
1237
  ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::T3, \
1237
1238
  CTYPE_ALIAS, __VA_ARGS__))
1238
1239
 
1240
+ #define ET_SWITCH_FOUR_TYPES(T1, T2, T3, T4, TYPE, CONTEXT, NAME, CTYPE_ALIAS, \
1241
+ ...) \
1242
+ ET_INTERNAL_SWITCH( \
1243
+ TYPE, CONTEXT, NAME, \
1244
+ ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::T1, CTYPE_ALIAS, \
1245
+ __VA_ARGS__) \
1246
+ ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::T2, \
1247
+ CTYPE_ALIAS, __VA_ARGS__) \
1248
+ ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::T3, \
1249
+ CTYPE_ALIAS, __VA_ARGS__) \
1250
+ ET_INTERNAL_SWITCH_CASE(::executorch::aten::ScalarType::T4, \
1251
+ CTYPE_ALIAS, __VA_ARGS__))
1252
+
1239
1253
  } // namespace runtime
1240
1254
  } // namespace executorch
1241
1255
 
@@ -12,6 +12,8 @@
12
12
  #include <cstdint>
13
13
  #include <stdio.h>
14
14
 
15
+ #include <c10/util/safe_numerics.h>
16
+
15
17
  #include <executorch/runtime/core/error.h>
16
18
  #include <executorch/runtime/platform/assert.h>
17
19
  #include <executorch/runtime/platform/compiler.h>
@@ -82,7 +84,7 @@ public:
82
84
 
83
85
  // If the end of this allocation exceeds the end of this allocator, print
84
86
  // error messages and return nullptr
85
- if (end > end_) {
87
+ if (end > end_ || end < start) {
86
88
  ET_LOG(Error,
87
89
  "Memory allocation failed: %zuB requested (adjusted for "
88
90
  "alignment), %zuB available",
@@ -133,7 +135,15 @@ public:
133
135
  // Some users of this method allocate lists of pointers, causing the next
134
136
  // line to expand to `sizeof(type *)`, which triggers a clang-tidy warning.
135
137
  // NOLINTNEXTLINE(bugprone-sizeof-expression)
136
- return static_cast<T *>(this->allocate(size * sizeof(T), alignment));
138
+ size_t bytes_size = 0;
139
+ bool overflow = c10::mul_overflows(size, sizeof(T), &bytes_size);
140
+ if (overflow) {
141
+ ET_LOG(Error,
142
+ "Failed to allocate list of type %zu: size * sizeof(T) overflowed",
143
+ size);
144
+ return nullptr;
145
+ }
146
+ return static_cast<T *>(this->allocate(bytes_size, alignment));
137
147
  }
138
148
 
139
149
  // Returns the allocator memory's base address.
@@ -8,12 +8,6 @@
8
8
 
9
9
  #pragma once
10
10
 
11
- #ifdef __GNUC__
12
- // Disable -Wdeprecated-declarations, as some builds use 'Werror'.
13
- #pragma GCC diagnostic push
14
- #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
15
- #endif
16
-
17
11
  #include <executorch/runtime/core/exec_aten/exec_aten.h>
18
12
  #include <executorch/runtime/core/freeable_buffer.h>
19
13
  #include <executorch/runtime/core/result.h>
@@ -27,7 +21,7 @@ namespace ET_RUNTIME_NAMESPACE {
27
21
  * Interface to access and retrieve data via name.
28
22
  * See executorch/extension/flat_tensor/ for an example.
29
23
  */
30
- class ET_EXPERIMENTAL NamedDataMap {
24
+ class NamedDataMap {
31
25
  public:
32
26
  virtual ~NamedDataMap() = default;
33
27
  /**
@@ -80,7 +74,3 @@ public:
80
74
 
81
75
  } // namespace ET_RUNTIME_NAMESPACE
82
76
  } // namespace executorch
83
-
84
- #ifdef __GNUC__
85
- #pragma GCC diagnostic pop
86
- #endif
@@ -1,79 +1 @@
1
- #define C10_USING_CUSTOM_GENERATED_MACROS
2
- #ifndef C10_MACROS_EXPORT_H_
3
- #define C10_MACROS_EXPORT_H_
4
-
5
- #ifndef C10_USING_CUSTOM_GENERATED_MACROS
6
- #include <c10/macros/cmake_macros.h>
7
- #endif // C10_USING_CUSTOM_GENERATED_MACROS
8
-
9
1
  #include <torch/headeronly/macros/Export.h>
10
-
11
- // This one is being used by libtorch.so
12
- #ifdef CAFFE2_BUILD_MAIN_LIB
13
- #define TORCH_API C10_EXPORT
14
- #else
15
- #define TORCH_API C10_IMPORT
16
- #endif
17
-
18
- // You may be wondering: Whose brilliant idea was it to split torch_cuda into
19
- // two pieces with confusing names?
20
- // Once upon a time, there _was_ only TORCH_CUDA_API. All was happy until we
21
- // tried to compile PyTorch for CUDA 11.1, which ran into relocation marker
22
- // issues when linking big binaries.
23
- // (https://github.com/pytorch/pytorch/issues/39968) We had two choices:
24
- // (1) Stop supporting so many GPU architectures
25
- // (2) Do something else
26
- // We chose #2 and decided to split the behemoth that was torch_cuda into two
27
- // smaller libraries, one with most of the core kernel functions (torch_cuda_cu)
28
- // and the other that had..well..everything else (torch_cuda_cpp). The idea was
29
- // this: instead of linking our static libraries (like the hefty
30
- // libcudnn_static.a) with another huge library, torch_cuda, and run into pesky
31
- // relocation marker issues, we could link our static libraries to a smaller
32
- // part of torch_cuda (torch_cuda_cpp) and avoid the issues.
33
-
34
- // libtorch_cuda_cu.so
35
- #ifdef TORCH_CUDA_CU_BUILD_MAIN_LIB
36
- #define TORCH_CUDA_CU_API C10_EXPORT
37
- #elif defined(BUILD_SPLIT_CUDA)
38
- #define TORCH_CUDA_CU_API C10_IMPORT
39
- #endif
40
-
41
- // libtorch_cuda_cpp.so
42
- #ifdef TORCH_CUDA_CPP_BUILD_MAIN_LIB
43
- #define TORCH_CUDA_CPP_API C10_EXPORT
44
- #elif defined(BUILD_SPLIT_CUDA)
45
- #define TORCH_CUDA_CPP_API C10_IMPORT
46
- #endif
47
-
48
- // libtorch_cuda.so (where torch_cuda_cu and torch_cuda_cpp are a part of the
49
- // same api)
50
- #ifdef TORCH_CUDA_BUILD_MAIN_LIB
51
- #define TORCH_CUDA_CPP_API C10_EXPORT
52
- #define TORCH_CUDA_CU_API C10_EXPORT
53
- #elif !defined(BUILD_SPLIT_CUDA)
54
- #define TORCH_CUDA_CPP_API C10_IMPORT
55
- #define TORCH_CUDA_CU_API C10_IMPORT
56
- #endif
57
-
58
- #if defined(TORCH_HIP_BUILD_MAIN_LIB)
59
- #define TORCH_HIP_CPP_API C10_EXPORT
60
- #define TORCH_HIP_API C10_EXPORT
61
- #else
62
- #define TORCH_HIP_CPP_API C10_IMPORT
63
- #define TORCH_HIP_API C10_IMPORT
64
- #endif
65
-
66
- #if defined(TORCH_XPU_BUILD_MAIN_LIB)
67
- #define TORCH_XPU_API C10_EXPORT
68
- #else
69
- #define TORCH_XPU_API C10_IMPORT
70
- #endif
71
-
72
- // Enums only need to be exported on windows for non-CUDA files
73
- #if defined(_WIN32) && defined(__CUDACC__)
74
- #define C10_API_ENUM C10_API
75
- #else
76
- #define C10_API_ENUM
77
- #endif
78
-
79
- #endif // C10_MACROS_EXPORT_H_