react-native-executorch 0.5.15 → 0.6.0

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
@@ -1,26 +0,0 @@
1
- typedef NS_ENUM(NSUInteger, ETError) {
2
- UndefinedError = 0x65,
3
- ModuleNotLoaded = 0x66,
4
- FileWriteFailed = 0x67,
5
- InvalidModelSource = 0xff,
6
-
7
- Ok = 0x00,
8
- Internal = 0x01,
9
- InvalidState = 0x02,
10
- EndOfMethod = 0x03,
11
-
12
- NotSupported = 0x10,
13
- NotImplemented = 0x11,
14
- InvalidArgument = 0x12,
15
- InvalidType = 0x13,
16
- OperatorMissing = 0x14,
17
-
18
- NotFound = 0x20,
19
- MemoryAllocationFailed = 0x21,
20
- AccessFailed = 0x22,
21
- InvalidProgram = 0x23,
22
-
23
- DelegateInvalidCompatibility = 0x30,
24
- DelegateMemoryAllocationFailed = 0x31,
25
- DelegateInvalidHandle = 0x32
26
- };
@@ -1,15 +0,0 @@
1
- #import <opencv2/opencv.hpp>
2
-
3
- @interface ImageProcessor : NSObject
4
-
5
- + (NSArray *)matToNSArray:(const cv::Mat &)mat
6
- mean:(cv::Scalar)mean
7
- variance:(cv::Scalar)variance;
8
- + (NSArray *)matToNSArray:(const cv::Mat &)mat;
9
- + (cv::Mat)arrayToMat:(NSArray *)array width:(int)width height:(int)height;
10
- + (cv::Mat)arrayToMatGray:(NSArray *)array width:(int)width height:(int)height;
11
- + (NSArray *)matToNSArrayGray:(const cv::Mat &)mat;
12
- + (NSString *)saveToTempFile:(const cv::Mat &)image;
13
- + (cv::Mat)readImage:(NSString *)source;
14
-
15
- @end
@@ -1,147 +0,0 @@
1
- #import "ImageProcessor.h"
2
- #import "ETError.h"
3
-
4
- @implementation ImageProcessor
5
-
6
- + (NSArray *)matToNSArray:(const cv::Mat &)mat {
7
- return [ImageProcessor matToNSArray:mat
8
- mean:cv::Scalar(0.0, 0.0, 0.0)
9
- variance:cv::Scalar(1.0, 1.0, 1.0)];
10
- }
11
-
12
- + (NSArray *)matToNSArray:(const cv::Mat &)mat
13
- mean:(cv::Scalar)mean
14
- variance:(cv::Scalar)variance {
15
- int pixelCount = mat.cols * mat.rows;
16
- NSMutableArray *floatArray =
17
- [[NSMutableArray alloc] initWithCapacity:pixelCount * 3];
18
- for (NSUInteger k = 0; k < pixelCount * 3; k++) {
19
- [floatArray addObject:@0.0];
20
- }
21
-
22
- for (int i = 0; i < pixelCount; i++) {
23
- int row = i / mat.cols;
24
- int col = i % mat.cols;
25
- cv::Vec3b pixel = mat.at<cv::Vec3b>(row, col);
26
- floatArray[0 * pixelCount + i] =
27
- @((pixel[0] - mean[0] * 255.0) / (variance[0] * 255.0));
28
- floatArray[1 * pixelCount + i] =
29
- @((pixel[1] - mean[1] * 255.0) / (variance[1] * 255.0));
30
- floatArray[2 * pixelCount + i] =
31
- @((pixel[2] - mean[2] * 255.0) / (variance[2] * 255.0));
32
- }
33
-
34
- return floatArray;
35
- }
36
-
37
- + (NSArray *)matToNSArrayGray:(const cv::Mat &)mat {
38
- NSMutableArray *pixelArray =
39
- [[NSMutableArray alloc] initWithCapacity:mat.cols * mat.rows];
40
-
41
- for (int row = 0; row < mat.rows; row++) {
42
- for (int col = 0; col < mat.cols; col++) {
43
- float pixelValue = mat.at<float>(row, col);
44
- [pixelArray addObject:@(pixelValue)];
45
- }
46
- }
47
-
48
- return pixelArray;
49
- }
50
-
51
- + (cv::Mat)arrayToMat:(NSArray *)array width:(int)width height:(int)height {
52
- cv::Mat mat(height, width, CV_8UC3);
53
-
54
- int pixelCount = width * height;
55
- for (int i = 0; i < pixelCount; i++) {
56
- int row = i / width;
57
- int col = i % width;
58
- float r = 0, g = 0, b = 0;
59
-
60
- r = [[array objectAtIndex:0 * pixelCount + i] floatValue];
61
- g = [[array objectAtIndex:1 * pixelCount + i] floatValue];
62
- b = [[array objectAtIndex:2 * pixelCount + i] floatValue];
63
-
64
- cv::Vec3b color((uchar)(b * 255), (uchar)(g * 255), (uchar)(r * 255));
65
- mat.at<cv::Vec3b>(row, col) = color;
66
- }
67
-
68
- return mat;
69
- }
70
-
71
- + (cv::Mat)arrayToMatGray:(NSArray *)array width:(int)width height:(int)height {
72
- cv::Mat mat(height, width, CV_32F);
73
-
74
- int pixelCount = width * height;
75
- for (int i = 0; i < pixelCount; i++) {
76
- int row = i / width;
77
- int col = i % width;
78
- float value = [array[i] floatValue];
79
- mat.at<float>(row, col) = value;
80
- }
81
-
82
- return mat;
83
- }
84
-
85
- + (NSString *)saveToTempFile:(const cv::Mat &)image {
86
- NSString *uniqueID = [[NSUUID UUID] UUIDString];
87
- NSString *filename =
88
- [NSString stringWithFormat:@"rn_executorch_%@.png", uniqueID];
89
- NSString *outputPath =
90
- [NSTemporaryDirectory() stringByAppendingPathComponent:filename];
91
-
92
- std::string filePath = [outputPath UTF8String];
93
- if (!cv::imwrite(filePath, image)) {
94
- @throw [NSException
95
- exceptionWithName:@"ImageSaveException"
96
- reason:[NSString
97
- stringWithFormat:@"%ld", (long)FileWriteFailed]
98
- userInfo:nil];
99
- }
100
-
101
- return [NSString stringWithFormat:@"file://%@", outputPath];
102
- }
103
-
104
- + (cv::Mat)readImage:(NSString *)source {
105
- NSURL *url = [NSURL URLWithString:source];
106
-
107
- cv::Mat inputImage;
108
- if ([[url scheme] isEqualToString:@"data"]) {
109
- // base64
110
- NSArray *parts = [source componentsSeparatedByString:@","];
111
- if ([parts count] < 2) {
112
- @throw [NSException
113
- exceptionWithName:@"readImage_error"
114
- reason:[NSString
115
- stringWithFormat:@"%ld", (long)InvalidArgument]
116
- userInfo:nil];
117
- }
118
- NSString *encodedString = parts[1];
119
- NSData *data = [[NSData alloc]
120
- initWithBase64EncodedString:encodedString
121
- options:
122
- NSDataBase64DecodingIgnoreUnknownCharacters];
123
- cv::Mat encodedData(1, [data length], CV_8UC1, (void *)data.bytes);
124
- inputImage = cv::imdecode(encodedData, cv::IMREAD_COLOR);
125
- } else if ([[url scheme] isEqualToString:@"file"]) {
126
- // local file
127
- inputImage = cv::imread([[url path] UTF8String], cv::IMREAD_COLOR);
128
- } else {
129
- // external file
130
- NSData *data = [NSData dataWithContentsOfURL:url];
131
- inputImage =
132
- cv::imdecode(cv::Mat(1, [data length], CV_8UC1, (void *)data.bytes),
133
- cv::IMREAD_COLOR);
134
- }
135
-
136
- if (inputImage.empty()) {
137
- @throw [NSException
138
- exceptionWithName:@"readImage_error"
139
- reason:[NSString
140
- stringWithFormat:@"%ld", (long)InvalidArgument]
141
- userInfo:nil];
142
- }
143
-
144
- return inputImage;
145
- }
146
-
147
- @end
@@ -1,3 +0,0 @@
1
- #include <vector>
2
-
3
- std::vector<double> softmax(const std::vector<double> &v);
@@ -1,18 +0,0 @@
1
- #include "Utils.h"
2
-
3
- std::vector<double> softmax(const std::vector<double> &v) {
4
- std::vector<double> result(v.size());
5
- double maxVal = *std::max_element(v.begin(), v.end());
6
-
7
- double sumExp = 0.0;
8
- for (size_t i = 0; i < v.size(); ++i) {
9
- result[i] = std::exp(v[i] - maxVal);
10
- sumExp += result[i];
11
- }
12
-
13
- for (size_t i = 0; i < v.size(); ++i) {
14
- result[i] /= sumExp;
15
- }
16
-
17
- return result;
18
- }
@@ -1,14 +0,0 @@
1
- #ifndef ScalarType_h
2
- #define ScalarType_h
3
-
4
- @interface ScalarType : NSObject
5
-
6
- @property(class, nonatomic, readonly) NSNumber *Int8;
7
- @property(class, nonatomic, readonly) NSNumber *Int32;
8
- @property(class, nonatomic, readonly) NSNumber *Long;
9
- @property(class, nonatomic, readonly) NSNumber *Float;
10
- @property(class, nonatomic, readonly) NSNumber *Double;
11
-
12
- @end
13
-
14
- #endif /* ScalarType_h */
@@ -1,21 +0,0 @@
1
- #import "ScalarType.h"
2
-
3
- @implementation ScalarType
4
-
5
- + (NSNumber *)Int8 {
6
- return @1;
7
- }
8
- + (NSNumber *)Int32 {
9
- return @3;
10
- }
11
- + (NSNumber *)Long {
12
- return @4;
13
- }
14
- + (NSNumber *)Float {
15
- return @6;
16
- }
17
- + (NSNumber *)Double {
18
- return @7;
19
- }
20
-
21
- @end
@@ -1 +0,0 @@
1
- {"version":3,"names":["useEffect","useState","useMemo","ETError","getError","useNonStaticModule","module","model","preventLoad","error","setError","isReady","setIsReady","isGenerating","setIsGenerating","downloadProgress","setDownloadProgress","moduleInstance","load","err","message","delete","Object","values","forward","input","Error","ModuleNotLoaded","ModelGenerating"],"sourceRoot":"../../../src","sources":["hooks/useNonStaticModule.ts"],"mappings":";;AAAA,SAASA,SAAS,EAAEC,QAAQ,EAAEC,OAAO,QAAQ,OAAO;AACpD,SAASC,OAAO,EAAEC,QAAQ,QAAQ,UAAU;AAY5C,OAAO,MAAMC,kBAAkB,GAAGA,CAKhC;EACAC,MAAM;EACNC,KAAK;EACLC,WAAW,GAAG;AAKhB,CAAC,KAAK;EACJ,MAAM,CAACC,KAAK,EAAEC,QAAQ,CAAC,GAAGT,QAAQ,CAAgB,IAAI,CAAC;EACvD,MAAM,CAACU,OAAO,EAAEC,UAAU,CAAC,GAAGX,QAAQ,CAAC,KAAK,CAAC;EAC7C,MAAM,CAACY,YAAY,EAAEC,eAAe,CAAC,GAAGb,QAAQ,CAAC,KAAK,CAAC;EACvD,MAAM,CAACc,gBAAgB,EAAEC,mBAAmB,CAAC,GAAGf,QAAQ,CAAC,CAAC,CAAC;EAC3D,MAAMgB,cAAc,GAAGf,OAAO,CAAC,MAAM,IAAII,MAAM,CAAC,CAAC,EAAE,CAACA,MAAM,CAAC,CAAC;EAE5DN,SAAS,CAAC,MAAM;IACd,IAAIQ,WAAW,EAAE;IAEjB,CAAC,YAAY;MACXQ,mBAAmB,CAAC,CAAC,CAAC;MACtBN,QAAQ,CAAC,IAAI,CAAC;MACd,IAAI;QACFE,UAAU,CAAC,KAAK,CAAC;QACjB,MAAMK,cAAc,CAACC,IAAI,CAACX,KAAK,EAAES,mBAAmB,CAAC;QACrDJ,UAAU,CAAC,IAAI,CAAC;MAClB,CAAC,CAAC,OAAOO,GAAG,EAAE;QACZT,QAAQ,CAAES,GAAG,CAAWC,OAAO,CAAC;MAClC;IACF,CAAC,EAAE,CAAC;IAEJ,OAAO,MAAM;MACXH,cAAc,CAACI,MAAM,CAAC,CAAC;IACzB,CAAC;;IAED;EACF,CAAC,EAAE,CAACJ,cAAc,EAAE,GAAGK,MAAM,CAACC,MAAM,CAAChB,KAAK,CAAC,EAAEC,WAAW,CAAC,CAAC;EAE1D,MAAMgB,OAAO,GAAG,MAAAA,CAAO,GAAGC,KAAkB,KAA6B;IACvE,IAAI,CAACd,OAAO,EAAE,MAAM,IAAIe,KAAK,CAACtB,QAAQ,CAACD,OAAO,CAACwB,eAAe,CAAC,CAAC;IAChE,IAAId,YAAY,EAAE,MAAM,IAAIa,KAAK,CAACtB,QAAQ,CAACD,OAAO,CAACyB,eAAe,CAAC,CAAC;IACpE,IAAI;MACFd,eAAe,CAAC,IAAI,CAAC;MACrB,OAAO,MAAMG,cAAc,CAACO,OAAO,CAAC,GAAGC,KAAK,CAAC;IAC/C,CAAC,SAAS;MACRX,eAAe,CAAC,KAAK,CAAC;IACxB;EACF,CAAC;EAED,OAAO;IACLL,KAAK;IACLE,OAAO;IACPE,YAAY;IACZE,gBAAgB;IAChBS;EACF,CAAC;AACH,CAAC","ignoreList":[]}
@@ -1,21 +0,0 @@
1
- interface Module {
2
- load: (...args: any[]) => Promise<void>;
3
- forward: (...args: any[]) => Promise<any>;
4
- delete: () => void;
5
- }
6
- interface ModuleConstructor<M extends Module> {
7
- new (): M;
8
- }
9
- export declare const useNonStaticModule: <M extends Module, LoadArgs extends Parameters<M["load"]>, ForwardArgs extends Parameters<M["forward"]>, ForwardReturn extends Awaited<ReturnType<M["forward"]>>>({ module, model, preventLoad, }: {
10
- module: ModuleConstructor<M>;
11
- model: LoadArgs[0];
12
- preventLoad?: boolean;
13
- }) => {
14
- error: string | null;
15
- isReady: boolean;
16
- isGenerating: boolean;
17
- downloadProgress: number;
18
- forward: (...input: ForwardArgs) => Promise<ForwardReturn>;
19
- };
20
- export {};
21
- //# sourceMappingURL=useNonStaticModule.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useNonStaticModule.d.ts","sourceRoot":"","sources":["../../../src/hooks/useNonStaticModule.ts"],"names":[],"mappings":"AAGA,UAAU,MAAM;IACd,IAAI,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACxC,OAAO,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC;IAC1C,MAAM,EAAE,MAAM,IAAI,CAAC;CACpB;AAED,UAAU,iBAAiB,CAAC,CAAC,SAAS,MAAM;IAC1C,QAAQ,CAAC,CAAC;CACX;AAED,eAAO,MAAM,kBAAkB,GAC7B,CAAC,SAAS,MAAM,EAChB,QAAQ,SAAS,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,EACtC,WAAW,SAAS,UAAU,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,EAC5C,aAAa,SAAS,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EACvD,iCAIC;IACD,MAAM,EAAE,iBAAiB,CAAC,CAAC,CAAC,CAAC;IAC7B,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC;IACnB,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;;;;;wBA6BkC,WAAW,KAAG,OAAO,CAAC,aAAa,CAAC;CAkBtE,CAAC"}
@@ -1,74 +0,0 @@
1
- import { useEffect, useState, useMemo } from 'react';
2
- import { ETError, getError } from '../Error';
3
-
4
- interface Module {
5
- load: (...args: any[]) => Promise<void>;
6
- forward: (...args: any[]) => Promise<any>;
7
- delete: () => void;
8
- }
9
-
10
- interface ModuleConstructor<M extends Module> {
11
- new (): M;
12
- }
13
-
14
- export const useNonStaticModule = <
15
- M extends Module,
16
- LoadArgs extends Parameters<M['load']>,
17
- ForwardArgs extends Parameters<M['forward']>,
18
- ForwardReturn extends Awaited<ReturnType<M['forward']>>,
19
- >({
20
- module,
21
- model,
22
- preventLoad = false,
23
- }: {
24
- module: ModuleConstructor<M>;
25
- model: LoadArgs[0];
26
- preventLoad?: boolean;
27
- }) => {
28
- const [error, setError] = useState<null | string>(null);
29
- const [isReady, setIsReady] = useState(false);
30
- const [isGenerating, setIsGenerating] = useState(false);
31
- const [downloadProgress, setDownloadProgress] = useState(0);
32
- const moduleInstance = useMemo(() => new module(), [module]);
33
-
34
- useEffect(() => {
35
- if (preventLoad) return;
36
-
37
- (async () => {
38
- setDownloadProgress(0);
39
- setError(null);
40
- try {
41
- setIsReady(false);
42
- await moduleInstance.load(model, setDownloadProgress);
43
- setIsReady(true);
44
- } catch (err) {
45
- setError((err as Error).message);
46
- }
47
- })();
48
-
49
- return () => {
50
- moduleInstance.delete();
51
- };
52
-
53
- // eslint-disable-next-line react-hooks/exhaustive-deps
54
- }, [moduleInstance, ...Object.values(model), preventLoad]);
55
-
56
- const forward = async (...input: ForwardArgs): Promise<ForwardReturn> => {
57
- if (!isReady) throw new Error(getError(ETError.ModuleNotLoaded));
58
- if (isGenerating) throw new Error(getError(ETError.ModelGenerating));
59
- try {
60
- setIsGenerating(true);
61
- return await moduleInstance.forward(...input);
62
- } finally {
63
- setIsGenerating(false);
64
- }
65
- };
66
-
67
- return {
68
- error,
69
- isReady,
70
- isGenerating,
71
- downloadProgress,
72
- forward,
73
- };
74
- };
@@ -1,181 +0,0 @@
1
- /*
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- * All rights reserved.
4
- *
5
- * This source code is licensed under the BSD-style license found in the
6
- * LICENSE file in the root directory of this source tree.
7
- */
8
-
9
- //===----------------------------------------------------------------------===//
10
- /// \file extension/kernel_util/make_boxed_from_unboxed_functor.h
11
- /// Defines a template that can be used to create a boxed version of an unboxed
12
- /// functor.
13
- /// Example usage:
14
- /// ```
15
- /// Tensor&
16
- /// my_op(KernelRuntimeContext& ctx, const Tensor& self, const Tensor& other,
17
- /// Tensor& out)
18
- /// {
19
- /// // ...
20
- /// return out;
21
- /// }
22
- ///
23
- /// Kernel my_kernel = Kernel::make_boxed_kernel("my_ns::my_op",
24
- /// EXECUTORCH_FN(my_op));
25
- /// static auto res = register_kernels({my_kernel});
26
- /// ```
27
- /// Or simply:
28
- /// ```
29
- /// EXECUTORCH_LIBRARY(my_ns, "my_op", my_op);
30
- /// ```
31
- ///
32
- /// The trick here is to convert each EValue to inferred argument type. This
33
- /// uses a lot of C++17 features.
34
- //===----------------------------------------------------------------------===//
35
-
36
- #pragma once
37
- #if __cplusplus < 201703L
38
- #error "This header requires C++17"
39
- #endif
40
-
41
- #include <cstdlib>
42
- #include <executorch/extension/kernel_util/meta_programming.h>
43
- #include <executorch/extension/kernel_util/type_list.h>
44
- #include <executorch/runtime/core/evalue.h>
45
- #include <executorch/runtime/core/exec_aten/exec_aten.h>
46
- #include <executorch/runtime/kernel/operator_registry.h>
47
- #include <memory>
48
- #include <type_traits>
49
- #include <typeinfo>
50
-
51
- namespace executorch {
52
- namespace runtime {
53
- class KernelRuntimeContext; // Forward declaration
54
- } // namespace runtime
55
- } // namespace executorch
56
-
57
- namespace executorch {
58
- namespace extension {
59
-
60
- // This extension has a lot of generic internal names like "size"; use a unique
61
- // internal namespace to avoid conflicts with other extensions.
62
- namespace kernel_util_internal {
63
-
64
- template <class T> struct decay_if_not_tensor final {
65
- using type = std::decay_t<T>;
66
- };
67
- template <> struct decay_if_not_tensor<executorch::aten::Tensor &> final {
68
- using type = executorch::aten::Tensor &;
69
- };
70
- template <> struct decay_if_not_tensor<const executorch::aten::Tensor &> final {
71
- using type = const executorch::aten::Tensor &;
72
- };
73
-
74
- template <class T> struct evalue_to_arg final {
75
- static T call(executorch::runtime::EValue &v) { return std::move(v).to<T>(); }
76
- };
77
-
78
- template <> struct evalue_to_arg<executorch::aten::Tensor &> final {
79
- static executorch::aten::Tensor &call(executorch::runtime::EValue &v) {
80
- return v.toTensor();
81
- }
82
- };
83
-
84
- template <> struct evalue_to_arg<const executorch::aten::Tensor &> final {
85
- static const executorch::aten::Tensor &call(executorch::runtime::EValue &v) {
86
- return v.toTensor();
87
- }
88
- };
89
-
90
- template <class T> struct evalue_to_arg<std::optional<T>> final {
91
- static std::optional<T> call(executorch::runtime::EValue &v) {
92
- return v.toOptional<T>();
93
- }
94
- };
95
-
96
- template <class T>
97
- struct evalue_to_arg<executorch::aten::ArrayRef<std::optional<T>>> final {
98
- static executorch::aten::ArrayRef<std::optional<T>>
99
- call(executorch::runtime::EValue &v) {
100
- return v.toListOptionalTensor();
101
- }
102
- };
103
-
104
- template <class Functor, size_t... evalue_arg_indices, typename... ArgTypes>
105
- void call_functor_with_args_from_stack(
106
- ::executorch::runtime::KernelRuntimeContext &ctx,
107
- executorch::runtime::EValue **stack,
108
- std::index_sequence<evalue_arg_indices...>, typelist<ArgTypes...> *) {
109
- (*Functor::func_ptr())(
110
- ctx, evalue_to_arg<typename decay_if_not_tensor<ArgTypes>::type>::call(
111
- *stack[evalue_arg_indices])...);
112
- }
113
-
114
- } // namespace kernel_util_internal
115
-
116
- /**
117
- * WrapUnboxedIntoFunctor: Given a function pointer, wrap it into a functor that
118
- * takes EValues as input and returns void. The wrapped functor will unbox all
119
- * inputs and forward them to unboxed kernel.
120
- */
121
- template <class FuncType> struct WrapUnboxedIntoFunctor {
122
- static_assert(
123
- kernel_util_internal::is_compile_time_function_pointer<FuncType>::value,
124
- "Can't handle function other than EXECUTORCH_FN");
125
- using TrueType = typename FuncType::FuncType;
126
- using ReturnType = typename kernel_util_internal::infer_function_traits_t<
127
- TrueType>::return_type;
128
- using ArgsType = typename kernel_util_internal::infer_function_traits_t<
129
- TrueType>::parameter_types;
130
- // check if the first argument is KernelRuntimeContext, if so, remove it
131
- static constexpr bool first_arg_is_context = std::is_same<
132
- ::executorch::runtime::KernelRuntimeContext,
133
- std::remove_reference_t<
134
- kernel_util_internal::head_with_default_t<void, ArgsType>>>::value;
135
- using ContextRemovedArgsType =
136
- std::conditional_t<first_arg_is_context,
137
- kernel_util_internal::drop_if_nonempty_t<ArgsType, 1>,
138
- ArgsType>;
139
-
140
- static void call(::executorch::runtime::KernelRuntimeContext &ctx,
141
- executorch::runtime::EValue **stack) {
142
- constexpr size_t num_inputs =
143
- kernel_util_internal::size<ContextRemovedArgsType>::value;
144
- return kernel_util_internal::call_functor_with_args_from_stack<FuncType>(
145
- ctx, stack, std::make_index_sequence<num_inputs>(),
146
- static_cast<ContextRemovedArgsType *>(nullptr));
147
- }
148
- };
149
-
150
- template <typename FuncType>
151
- static executorch::runtime::Kernel make_boxed_kernel(const char *name,
152
- FuncType) {
153
- return executorch::runtime::Kernel(name,
154
- WrapUnboxedIntoFunctor<FuncType>::call);
155
- }
156
-
157
- } // namespace extension
158
- } // namespace executorch
159
-
160
- // Inspired from C10_CONCATENATE
161
- #define ET_CONCATENATE_IMPL(s1, s2) s1##s2
162
- #define ET_CONCATENATE(s1, s2) ET_CONCATENATE_IMPL(s1, s2)
163
- #define ET_UID __LINE__
164
-
165
- #define EXECUTORCH_LIBRARY(ns, op_name, func) \
166
- _EXECUTORCH_LIBRARY_IMPL(ns, op_name, func, ET_UID)
167
-
168
- #define _EXECUTORCH_LIBRARY_IMPL(ns, op_name, func, uid) \
169
- static auto ET_CONCATENATE(res_##ns##_, uid) = \
170
- ::executorch::runtime::register_kernel( \
171
- ::executorch::extension::make_boxed_kernel(#ns "::" op_name, \
172
- EXECUTORCH_FN(func)))
173
-
174
- namespace torch {
175
- namespace executor {
176
- // TODO(T197294990): Remove these deprecated aliases once all users have moved
177
- // to the new `::executorch` namespaces.
178
- using ::executorch::extension::make_boxed_kernel;
179
- using ::executorch::extension::WrapUnboxedIntoFunctor;
180
- } // namespace executor
181
- } // namespace torch
@@ -1,108 +0,0 @@
1
- /*
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- * All rights reserved.
4
- *
5
- * This source code is licensed under the BSD-style license found in the
6
- * LICENSE file in the root directory of this source tree.
7
- */
8
-
9
- #pragma once
10
- #if __cplusplus < 201703L
11
- #error "This header requires C++17"
12
- #endif
13
-
14
- #include <cstdlib>
15
- #include <executorch/extension/kernel_util/type_list.h>
16
- #include <memory>
17
- #include <type_traits>
18
- #include <typeinfo>
19
-
20
- namespace executorch {
21
- namespace extension {
22
- // This extension has a lot of generic internal names like "size"; use a unique
23
- // internal namespace to avoid conflicts with other extensions.
24
- namespace kernel_util_internal {
25
-
26
- // Check if a given type is a function
27
- template <class T> struct is_function_type : std::false_type {};
28
- template <class Result, class... Args>
29
- struct is_function_type<Result(Args...)> : std::true_type {};
30
- template <class T>
31
- using is_function_type_t = typename is_function_type<T>::type;
32
-
33
- // A compile-time wrapper around a function pointer
34
- template <class FuncType_, FuncType_ *func_ptr_>
35
- struct CompileTimeFunctionPointer final {
36
- static_assert(is_function_type<FuncType_>::value,
37
- "EXECUTORCH_FN can only wrap function types.");
38
- using FuncType = FuncType_;
39
-
40
- static constexpr FuncType *func_ptr() { return func_ptr_; }
41
- };
42
-
43
- // Check if a given type is a compile-time function pointer
44
- template <class T> struct is_compile_time_function_pointer : std::false_type {};
45
- template <class FuncType, FuncType *func_ptr>
46
- struct is_compile_time_function_pointer<
47
- CompileTimeFunctionPointer<FuncType, func_ptr>> : std::true_type {};
48
-
49
- #define EXECUTORCH_FN_TYPE(func) \
50
- ::executorch::extension::kernel_util_internal::CompileTimeFunctionPointer< \
51
- std::remove_pointer_t<std::remove_reference_t<decltype(func)>>, func>
52
- #define EXECUTORCH_FN(func) EXECUTORCH_FN_TYPE(func)()
53
-
54
- /**
55
- * strip_class: helper to remove the class type from pointers to `operator()`.
56
- */
57
- template <typename T> struct strip_class {};
58
- template <typename Class, typename Result, typename... Args>
59
- struct strip_class<Result (Class::*)(Args...)> {
60
- using type = Result(Args...);
61
- };
62
- template <typename Class, typename Result, typename... Args>
63
- struct strip_class<Result (Class::*)(Args...) const> {
64
- using type = Result(Args...);
65
- };
66
- template <typename T> using strip_class_t = typename strip_class<T>::type;
67
-
68
- /**
69
- * Access information about result type or arguments from a function type.
70
- * Example:
71
- * using A = function_traits<int (float, double)>::return_type // A == int
72
- * using A = function_traits<int (float, double)>::parameter_types::tuple_type
73
- * // A == tuple<float, double>
74
- */
75
- template <class Func> struct function_traits {
76
- static_assert(
77
- !std::is_same<Func, Func>::value,
78
- "In function_traits<Func>, Func must be a plain function type.");
79
- };
80
- template <class Result, class... Args> struct function_traits<Result(Args...)> {
81
- using func_type = Result(Args...);
82
- using return_type = Result;
83
- using parameter_types = typelist<Args...>;
84
- static constexpr auto number_of_parameters = sizeof...(Args);
85
- };
86
-
87
- /**
88
- * infer_function_traits: creates a `function_traits` type for a simple
89
- * function (pointer) or functor (lambda/struct). Currently does not support
90
- * class methods.
91
- */
92
- template <typename Functor> struct infer_function_traits {
93
- using type = function_traits<strip_class_t<decltype(&Functor::operator())>>;
94
- };
95
- template <typename Result, typename... Args>
96
- struct infer_function_traits<Result (*)(Args...)> {
97
- using type = function_traits<Result(Args...)>;
98
- };
99
- template <typename Result, typename... Args>
100
- struct infer_function_traits<Result(Args...)> {
101
- using type = function_traits<Result(Args...)>;
102
- };
103
- template <typename T>
104
- using infer_function_traits_t = typename infer_function_traits<T>::type;
105
-
106
- } // namespace kernel_util_internal
107
- } // namespace extension
108
- } // namespace executorch