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.
- package/README.md +42 -36
- package/android/CMakeLists.txt +13 -25
- package/android/build.gradle +2 -3
- package/android/libs/classes.jar +0 -0
- package/android/src/main/cpp/CMakeLists.txt +2 -1
- package/common/rnexecutorch/RnExecutorchInstaller.cpp +18 -0
- package/common/rnexecutorch/TokenizerModule.cpp +3 -3
- package/common/rnexecutorch/data_processing/Numerical.cpp +31 -23
- package/common/rnexecutorch/data_processing/Numerical.h +6 -1
- package/common/rnexecutorch/data_processing/dsp.cpp +0 -46
- package/common/rnexecutorch/host_objects/JsiConversions.h +16 -0
- package/common/rnexecutorch/host_objects/ModelHostObject.h +26 -11
- package/common/rnexecutorch/jsi/OwningArrayBuffer.h +19 -2
- package/common/rnexecutorch/metaprogramming/TypeConcepts.h +0 -20
- package/common/rnexecutorch/models/BaseModel.cpp +12 -11
- package/common/rnexecutorch/models/BaseModel.h +18 -10
- package/common/rnexecutorch/models/embeddings/BaseEmbeddings.cpp +3 -11
- package/common/rnexecutorch/models/embeddings/text/TextEmbeddings.cpp +0 -1
- package/common/rnexecutorch/models/image_segmentation/ImageSegmentation.cpp +6 -12
- package/common/rnexecutorch/models/llm/LLM.cpp +25 -8
- package/common/rnexecutorch/models/llm/LLM.h +4 -4
- package/common/rnexecutorch/models/ocr/CTCLabelConverter.h +1 -1
- package/common/rnexecutorch/models/ocr/utils/RecognitionHandlerUtils.cpp +7 -4
- package/common/rnexecutorch/models/speech_to_text/SpeechToText.cpp +8 -13
- package/common/rnexecutorch/models/speech_to_text/SpeechToText.h +1 -3
- package/common/rnexecutorch/models/speech_to_text/asr/ASR.cpp +12 -19
- package/common/rnexecutorch/models/speech_to_text/asr/ASR.h +4 -5
- package/common/rnexecutorch/models/text_to_image/Constants.h +9 -0
- package/common/rnexecutorch/models/text_to_image/Decoder.cpp +32 -0
- package/common/rnexecutorch/models/text_to_image/Decoder.h +24 -0
- package/common/rnexecutorch/models/text_to_image/Encoder.cpp +44 -0
- package/common/rnexecutorch/models/text_to_image/Encoder.h +32 -0
- package/common/rnexecutorch/models/text_to_image/Scheduler.cpp +152 -0
- package/common/rnexecutorch/models/text_to_image/Scheduler.h +41 -0
- package/common/rnexecutorch/models/text_to_image/TextToImage.cpp +141 -0
- package/common/rnexecutorch/models/text_to_image/TextToImage.h +64 -0
- package/common/rnexecutorch/models/text_to_image/UNet.cpp +38 -0
- package/common/rnexecutorch/models/text_to_image/UNet.h +28 -0
- package/common/rnexecutorch/models/voice_activity_detection/Constants.h +27 -0
- package/common/rnexecutorch/models/voice_activity_detection/Types.h +12 -0
- package/common/rnexecutorch/models/voice_activity_detection/Utils.cpp +15 -0
- package/common/rnexecutorch/models/voice_activity_detection/Utils.h +13 -0
- package/common/rnexecutorch/models/voice_activity_detection/VoiceActivityDetection.cpp +160 -0
- package/common/rnexecutorch/models/voice_activity_detection/VoiceActivityDetection.h +36 -0
- package/common/rnexecutorch/tests/CMakeLists.txt +30 -0
- package/common/rnexecutorch/tests/NumericalTest.cpp +110 -0
- package/common/rnexecutorch/tests/README.md +30 -13
- package/common/rnexecutorch/threads/GlobalThreadPool.h +4 -0
- package/common/runner/arange_util.cpp +44 -0
- package/common/runner/arange_util.h +37 -0
- package/common/runner/constants.h +28 -0
- package/common/runner/io_manager.h +240 -0
- package/common/runner/irunner.h +87 -16
- package/common/runner/kernel_includes.h +23 -0
- package/common/runner/runner.cpp +151 -66
- package/common/runner/runner.h +39 -22
- package/common/runner/sampler.cpp +8 -1
- package/common/runner/sampler.h +4 -2
- package/common/runner/stats.h +1 -4
- package/common/runner/text_decoder_runner.cpp +26 -12
- package/common/runner/text_decoder_runner.h +52 -31
- package/common/runner/text_prefiller.cpp +46 -12
- package/common/runner/text_prefiller.h +38 -4
- package/common/runner/text_token_generator.h +51 -26
- package/common/runner/util.h +53 -8
- package/ios/RnExecutorch.xcodeproj/project.pbxproj +0 -23
- package/lib/module/Error.js +1 -0
- package/lib/module/Error.js.map +1 -1
- package/lib/module/constants/directories.js +1 -1
- package/lib/module/constants/directories.js.map +1 -1
- package/lib/module/constants/modelUrls.js +32 -1
- package/lib/module/constants/modelUrls.js.map +1 -1
- package/lib/module/constants/ocr/models.js +7 -7
- package/lib/module/constants/ocr/models.js.map +1 -1
- package/lib/module/constants/ocr/symbols.js +3 -2
- package/lib/module/constants/ocr/symbols.js.map +1 -1
- package/lib/module/controllers/LLMController.js +10 -1
- package/lib/module/controllers/LLMController.js.map +1 -1
- package/lib/module/controllers/OCRController.js +3 -3
- package/lib/module/controllers/OCRController.js.map +1 -1
- package/lib/module/controllers/VerticalOCRController.js +2 -2
- package/lib/module/controllers/VerticalOCRController.js.map +1 -1
- package/lib/module/hooks/computer_vision/useOCR.js +3 -3
- package/lib/module/hooks/computer_vision/useOCR.js.map +1 -1
- package/lib/module/hooks/{useNonStaticModule.js → computer_vision/useTextToImage.js} +21 -16
- package/lib/module/hooks/computer_vision/useTextToImage.js.map +1 -0
- package/lib/module/hooks/computer_vision/useVerticalOCR.js +3 -3
- package/lib/module/hooks/computer_vision/useVerticalOCR.js.map +1 -1
- package/lib/module/hooks/natural_language_processing/useLLM.js +3 -3
- package/lib/module/hooks/natural_language_processing/useLLM.js.map +1 -1
- package/lib/module/hooks/natural_language_processing/useTokenizer.js +5 -5
- package/lib/module/hooks/natural_language_processing/useTokenizer.js.map +1 -1
- package/lib/module/hooks/natural_language_processing/useVAD.js +13 -0
- package/lib/module/hooks/natural_language_processing/useVAD.js.map +1 -0
- package/lib/module/index.js +7 -2
- package/lib/module/index.js.map +1 -1
- package/lib/module/modules/computer_vision/OCRModule.js +2 -2
- package/lib/module/modules/computer_vision/OCRModule.js.map +1 -1
- package/lib/module/modules/computer_vision/TextToImageModule.js +48 -0
- package/lib/module/modules/computer_vision/TextToImageModule.js.map +1 -0
- package/lib/module/modules/computer_vision/VerticalOCRModule.js +2 -2
- package/lib/module/modules/computer_vision/VerticalOCRModule.js.map +1 -1
- package/lib/module/modules/natural_language_processing/SpeechToTextModule.js +7 -4
- package/lib/module/modules/natural_language_processing/SpeechToTextModule.js.map +1 -1
- package/lib/module/modules/natural_language_processing/VADModule.js +19 -0
- package/lib/module/modules/natural_language_processing/VADModule.js.map +1 -0
- package/lib/module/types/llm.js.map +1 -1
- package/lib/module/types/vad.js +2 -0
- package/lib/module/types/vad.js.map +1 -0
- package/lib/module/utils/ResourceFetcher.js +2 -1
- package/lib/module/utils/ResourceFetcher.js.map +1 -1
- package/lib/module/utils/ResourceFetcherUtils.js +6 -6
- package/lib/module/utils/ResourceFetcherUtils.js.map +1 -1
- package/lib/typescript/Error.d.ts +1 -0
- package/lib/typescript/Error.d.ts.map +1 -1
- package/lib/typescript/constants/modelUrls.d.ts +23 -0
- package/lib/typescript/constants/modelUrls.d.ts.map +1 -1
- package/lib/typescript/constants/ocr/symbols.d.ts +1 -1
- package/lib/typescript/constants/ocr/symbols.d.ts.map +1 -1
- package/lib/typescript/controllers/LLMController.d.ts.map +1 -1
- package/lib/typescript/controllers/OCRController.d.ts +1 -1
- package/lib/typescript/controllers/OCRController.d.ts.map +1 -1
- package/lib/typescript/controllers/VerticalOCRController.d.ts +1 -1
- package/lib/typescript/controllers/VerticalOCRController.d.ts.map +1 -1
- package/lib/typescript/hooks/computer_vision/useOCR.d.ts +1 -1
- package/lib/typescript/hooks/computer_vision/useOCR.d.ts.map +1 -1
- package/lib/typescript/hooks/computer_vision/useTextToImage.d.ts +22 -0
- package/lib/typescript/hooks/computer_vision/useTextToImage.d.ts.map +1 -0
- package/lib/typescript/hooks/computer_vision/useVerticalOCR.d.ts +1 -1
- package/lib/typescript/hooks/computer_vision/useVerticalOCR.d.ts.map +1 -1
- package/lib/typescript/hooks/natural_language_processing/useLLM.d.ts.map +1 -1
- package/lib/typescript/hooks/natural_language_processing/useSpeechToText.d.ts +2 -2
- package/lib/typescript/hooks/natural_language_processing/useVAD.d.ts +16 -0
- package/lib/typescript/hooks/natural_language_processing/useVAD.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +8 -1
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/modules/computer_vision/OCRModule.d.ts +1 -1
- package/lib/typescript/modules/computer_vision/OCRModule.d.ts.map +1 -1
- package/lib/typescript/modules/computer_vision/TextToImageModule.d.ts +16 -0
- package/lib/typescript/modules/computer_vision/TextToImageModule.d.ts.map +1 -0
- package/lib/typescript/modules/computer_vision/VerticalOCRModule.d.ts +1 -1
- package/lib/typescript/modules/computer_vision/VerticalOCRModule.d.ts.map +1 -1
- package/lib/typescript/modules/natural_language_processing/SpeechToTextModule.d.ts +3 -2
- package/lib/typescript/modules/natural_language_processing/SpeechToTextModule.d.ts.map +1 -1
- package/lib/typescript/modules/natural_language_processing/VADModule.d.ts +10 -0
- package/lib/typescript/modules/natural_language_processing/VADModule.d.ts.map +1 -0
- package/lib/typescript/types/llm.d.ts +2 -0
- package/lib/typescript/types/llm.d.ts.map +1 -1
- package/lib/typescript/types/vad.d.ts +5 -0
- package/lib/typescript/types/vad.d.ts.map +1 -0
- package/lib/typescript/utils/ResourceFetcher.d.ts +29 -0
- package/lib/typescript/utils/ResourceFetcher.d.ts.map +1 -1
- package/lib/typescript/utils/ResourceFetcherUtils.d.ts +2 -2
- package/lib/typescript/utils/ResourceFetcherUtils.d.ts.map +1 -1
- package/package.json +11 -8
- package/react-native-executorch.podspec +9 -9
- package/src/Error.ts +1 -0
- package/src/constants/directories.ts +1 -1
- package/src/constants/modelUrls.ts +36 -1
- package/src/constants/ocr/models.ts +7 -7
- package/src/constants/ocr/symbols.ts +3 -2
- package/src/controllers/LLMController.ts +12 -1
- package/src/controllers/OCRController.ts +3 -3
- package/src/controllers/VerticalOCRController.ts +2 -2
- package/src/hooks/computer_vision/useOCR.ts +4 -5
- package/src/hooks/computer_vision/useTextToImage.ts +92 -0
- package/src/hooks/computer_vision/useVerticalOCR.ts +4 -5
- package/src/hooks/natural_language_processing/useLLM.ts +3 -4
- package/src/hooks/natural_language_processing/useTokenizer.ts +5 -5
- package/src/hooks/natural_language_processing/useVAD.ts +15 -0
- package/src/index.ts +20 -1
- package/src/modules/computer_vision/OCRModule.ts +2 -2
- package/src/modules/computer_vision/TextToImageModule.ts +93 -0
- package/src/modules/computer_vision/VerticalOCRModule.ts +2 -2
- package/src/modules/natural_language_processing/SpeechToTextModule.ts +8 -4
- package/src/modules/natural_language_processing/VADModule.ts +27 -0
- package/src/types/llm.ts +2 -0
- package/src/types/vad.ts +4 -0
- package/src/utils/ResourceFetcher.ts +2 -1
- package/src/utils/ResourceFetcherUtils.ts +8 -8
- package/third-party/android/libs/cpuinfo/arm64-v8a/libcpuinfo.so +0 -0
- package/third-party/android/libs/executorch/arm64-v8a/libexecutorch.so +0 -0
- package/third-party/android/libs/executorch/x86_64/libexecutorch.so +0 -0
- package/third-party/android/libs/pthreadpool/arm64-v8a/libpthreadpool.so +0 -0
- package/third-party/include/c10/macros/Export.h +0 -78
- package/third-party/include/c10/macros/Macros.h +1 -520
- package/third-party/include/c10/util/BFloat16-inl.h +1 -339
- package/third-party/include/c10/util/BFloat16.h +1 -122
- package/third-party/include/c10/util/Half-inl.h +1 -347
- package/third-party/include/c10/util/Half.h +6 -419
- package/third-party/include/c10/util/TypeSafeSignMath.h +1 -133
- package/third-party/include/c10/util/bit_cast.h +1 -43
- package/third-party/include/c10/util/complex.h +1 -568
- package/third-party/include/c10/util/floating_point_utils.h +1 -33
- package/third-party/include/c10/util/irange.h +1 -1
- package/third-party/include/c10/util/llvmMathExtras.h +866 -0
- package/third-party/include/c10/util/safe_numerics.h +97 -0
- package/third-party/include/executorch/ExecuTorchError.h +6 -7
- package/third-party/include/executorch/ExecuTorchLLM/ExecuTorchLLM.h +12 -0
- package/third-party/include/executorch/ExecuTorchLLM/ExecuTorchLLMConfig.h +56 -0
- package/third-party/include/executorch/ExecuTorchLLM/ExecuTorchLLMError.h +16 -0
- package/third-party/include/executorch/ExecuTorchLLM/ExecuTorchLLMMultimodalRunner.h +227 -0
- package/third-party/include/executorch/ExecuTorchLLM/ExecuTorchLLMTextRunner.h +97 -0
- package/third-party/include/executorch/ExecuTorchLLM/module.modulemap +4 -0
- package/third-party/include/executorch/ExecuTorchLog.h +1 -0
- package/third-party/include/executorch/ExecuTorchModule.h +177 -4
- package/third-party/include/executorch/ExecuTorchTensor.h +3 -4
- package/third-party/include/executorch/ExecuTorchValue.h +1 -7
- package/third-party/include/executorch/extension/module/module.h +139 -8
- package/third-party/include/executorch/extension/tensor/tensor.h +1 -0
- package/third-party/include/executorch/extension/tensor/tensor_ptr.h +88 -26
- package/third-party/include/executorch/extension/threadpool/threadpool.h +4 -1
- package/third-party/include/executorch/runtime/backend/backend_init_context.h +6 -0
- package/third-party/include/executorch/runtime/backend/interface.h +1 -1
- package/third-party/include/executorch/runtime/core/error.h +76 -49
- package/third-party/include/executorch/runtime/core/exec_aten/util/scalar_type_util.h +18 -4
- package/third-party/include/executorch/runtime/core/memory_allocator.h +12 -2
- package/third-party/include/executorch/runtime/core/named_data_map.h +1 -11
- package/third-party/include/executorch/runtime/core/portable_type/c10/c10/macros/Export.h +0 -78
- package/third-party/include/executorch/runtime/core/portable_type/c10/c10/macros/Macros.h +1 -520
- package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/BFloat16-inl.h +1 -339
- package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/BFloat16.h +1 -122
- package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/Half-inl.h +1 -347
- package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/Half.h +6 -419
- package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/TypeSafeSignMath.h +1 -133
- package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/bit_cast.h +1 -43
- package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/complex.h +1 -568
- package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/floating_point_utils.h +1 -33
- package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/irange.h +1 -1
- package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/llvmMathExtras.h +866 -0
- package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/safe_numerics.h +97 -0
- package/third-party/include/executorch/runtime/core/portable_type/c10/torch/headeronly/macros/Export.h +66 -0
- package/third-party/include/executorch/runtime/core/portable_type/c10/torch/headeronly/macros/Macros.h +553 -0
- package/third-party/include/executorch/runtime/core/portable_type/c10/torch/headeronly/util/BFloat16.h +477 -0
- package/third-party/include/executorch/runtime/core/portable_type/c10/torch/headeronly/util/Half.h +781 -0
- package/third-party/include/executorch/runtime/core/portable_type/c10/torch/headeronly/util/TypeSafeSignMath.h +141 -0
- package/third-party/include/executorch/runtime/core/portable_type/c10/torch/headeronly/util/bit_cast.h +49 -0
- package/third-party/include/executorch/runtime/core/portable_type/c10/torch/headeronly/util/complex.h +593 -0
- package/third-party/include/executorch/runtime/core/portable_type/c10/torch/headeronly/util/floating_point_utils.h +38 -0
- package/third-party/include/executorch/runtime/core/tensor_layout.h +1 -1
- package/third-party/include/executorch/runtime/executor/merged_data_map.h +142 -0
- package/third-party/include/executorch/runtime/executor/method.h +21 -8
- package/third-party/include/executorch/runtime/executor/method_meta.h +20 -2
- package/third-party/include/executorch/runtime/executor/program.h +0 -10
- package/third-party/include/executorch/runtime/kernel/operator_registry.h +1 -1
- package/third-party/include/executorch/runtime/platform/compiler.h +2 -0
- package/third-party/include/executorch/schema/extended_header.h +10 -1
- package/third-party/include/torch/headeronly/macros/Export.h +66 -0
- package/third-party/include/torch/headeronly/macros/Macros.h +553 -0
- package/third-party/include/torch/headeronly/util/BFloat16.h +477 -0
- package/third-party/include/torch/headeronly/util/Half.h +781 -0
- package/third-party/include/torch/headeronly/util/TypeSafeSignMath.h +141 -0
- package/third-party/include/torch/headeronly/util/bit_cast.h +49 -0
- package/third-party/include/torch/headeronly/util/complex.h +593 -0
- package/third-party/include/torch/headeronly/util/floating_point_utils.h +38 -0
- package/third-party/ios/ExecutorchLib.xcframework/ios-arm64/ExecutorchLib.framework/ExecutorchLib +0 -0
- package/third-party/ios/ExecutorchLib.xcframework/ios-arm64/ExecutorchLib.framework/Info.plist +0 -0
- package/third-party/ios/ExecutorchLib.xcframework/ios-arm64-simulator/ExecutorchLib.framework/ExecutorchLib +0 -0
- package/third-party/ios/ExecutorchLib.xcframework/ios-arm64-simulator/ExecutorchLib.framework/Info.plist +0 -0
- package/common/rnexecutorch/tests/run_all_tests.sh +0 -14
- package/common/rnexecutorch/tests/run_test.sh +0 -18
- package/ios/RnExecutorch/utils/Conversions.h +0 -14
- package/ios/RnExecutorch/utils/ETError.h +0 -26
- package/ios/RnExecutorch/utils/ImageProcessor.h +0 -15
- package/ios/RnExecutorch/utils/ImageProcessor.mm +0 -147
- package/ios/RnExecutorch/utils/Numerical.h +0 -3
- package/ios/RnExecutorch/utils/Numerical.mm +0 -18
- package/ios/RnExecutorch/utils/ScalarType.h +0 -14
- package/ios/RnExecutorch/utils/ScalarType.mm +0 -21
- package/lib/module/hooks/useNonStaticModule.js.map +0 -1
- package/lib/typescript/hooks/useNonStaticModule.d.ts +0 -21
- package/lib/typescript/hooks/useNonStaticModule.d.ts.map +0 -1
- package/src/hooks/useNonStaticModule.ts +0 -74
- package/third-party/include/executorch/extension/kernel_util/make_boxed_from_unboxed_functor.h +0 -181
- package/third-party/include/executorch/extension/kernel_util/meta_programming.h +0 -108
- package/third-party/include/executorch/extension/kernel_util/type_list.h +0 -137
- package/third-party/include/executorch/extension/threadpool/threadpool_guard.h +0 -35
|
@@ -16,7 +16,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|
|
16
16
|
* and its debug name.
|
|
17
17
|
*/
|
|
18
18
|
NS_SWIFT_NAME(TensorMetadata)
|
|
19
|
-
__attribute__((
|
|
19
|
+
__attribute__((objc_subclassing_restricted))
|
|
20
20
|
@interface ExecuTorchTensorMetadata : NSObject
|
|
21
21
|
|
|
22
22
|
/** The size of each dimension. */
|
|
@@ -46,7 +46,7 @@ __attribute__((deprecated("This API is experimental.")))
|
|
|
46
46
|
* per-tensor metadata, buffer sizes, backends, and instruction count.
|
|
47
47
|
*/
|
|
48
48
|
NS_SWIFT_NAME(MethodMetadata)
|
|
49
|
-
__attribute__((
|
|
49
|
+
__attribute__((objc_subclassing_restricted))
|
|
50
50
|
@interface ExecuTorchMethodMetadata : NSObject
|
|
51
51
|
|
|
52
52
|
/** The method’s name. */
|
|
@@ -123,22 +123,48 @@ typedef NS_ENUM(uint8_t, ExecuTorchVerification) {
|
|
|
123
123
|
* them.
|
|
124
124
|
*/
|
|
125
125
|
NS_SWIFT_NAME(Module)
|
|
126
|
-
__attribute__((deprecated("This API is experimental.")))
|
|
127
126
|
@interface ExecuTorchModule : NSObject
|
|
128
127
|
|
|
129
128
|
/**
|
|
130
|
-
* Initializes a module with a file path and a specified load mode.
|
|
129
|
+
* Initializes a module with a file path, data path and a specified load mode.
|
|
131
130
|
*
|
|
132
131
|
* @param filePath A string representing the path to the ExecuTorch program
|
|
133
132
|
* file.
|
|
133
|
+
* @param dataFilePaths A list of strings representing paths to .ptd files with
|
|
134
|
+
* external tensors and external data.
|
|
134
135
|
* @param loadMode A value from ExecuTorchModuleLoadMode that determines the
|
|
135
136
|
* file loading behavior.
|
|
136
137
|
* @return An initialized ExecuTorchModule instance.
|
|
137
138
|
*/
|
|
138
139
|
- (instancetype)initWithFilePath:(NSString *)filePath
|
|
140
|
+
dataFilePaths:(NSArray<NSString *> *)dataFilePaths
|
|
139
141
|
loadMode:(ExecuTorchModuleLoadMode)loadMode
|
|
140
142
|
NS_DESIGNATED_INITIALIZER;
|
|
141
143
|
|
|
144
|
+
/**
|
|
145
|
+
* Initializes a module with a file path, data path and a specified load mode.
|
|
146
|
+
*
|
|
147
|
+
* @param filePath A string representing the path to the ExecuTorch program
|
|
148
|
+
* file.
|
|
149
|
+
* @param dataFilePaths A list of strings representing paths to .ptd files with
|
|
150
|
+
* external tensors and external data.
|
|
151
|
+
* @return An initialized ExecuTorchModule instance.
|
|
152
|
+
*/
|
|
153
|
+
- (instancetype)initWithFilePath:(NSString *)filePath
|
|
154
|
+
dataFilePaths:(NSArray<NSString *> *)dataFilePaths;
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Initializes a module with a file path and a specified load mode.
|
|
158
|
+
*
|
|
159
|
+
* @param filePath A string representing the path to the ExecuTorch program
|
|
160
|
+
* file.
|
|
161
|
+
* @param loadMode A value from ExecuTorchModuleLoadMode that determines the
|
|
162
|
+
* file loading behavior.
|
|
163
|
+
* @return An initialized ExecuTorchModule instance.
|
|
164
|
+
*/
|
|
165
|
+
- (instancetype)initWithFilePath:(NSString *)filePath
|
|
166
|
+
loadMode:(ExecuTorchModuleLoadMode)loadMode;
|
|
167
|
+
|
|
142
168
|
/**
|
|
143
169
|
* Initializes a module with a file path using the default load mode (File
|
|
144
170
|
* mode).
|
|
@@ -197,6 +223,14 @@ __attribute__((deprecated("This API is experimental.")))
|
|
|
197
223
|
*/
|
|
198
224
|
- (BOOL)isMethodLoaded:(NSString *)methodName NS_SWIFT_NAME(isLoaded(_:));
|
|
199
225
|
|
|
226
|
+
/**
|
|
227
|
+
* Unloads a method and releases its native resources and planned buffers.
|
|
228
|
+
*
|
|
229
|
+
* @param methodName The method to unload.
|
|
230
|
+
* @return YES if the method was unloaded; NO if it was not loaded at all.
|
|
231
|
+
*/
|
|
232
|
+
- (BOOL)unloadMethod:(NSString *)methodName NS_SWIFT_NAME(unload(_:));
|
|
233
|
+
|
|
200
234
|
/**
|
|
201
235
|
* Retrieves the set of method names available in the loaded program.
|
|
202
236
|
*
|
|
@@ -382,6 +416,145 @@ __attribute__((deprecated("This API is experimental.")))
|
|
|
382
416
|
error:(NSError **)error
|
|
383
417
|
NS_SWIFT_UNAVAILABLE("")NS_RETURNS_RETAINED;
|
|
384
418
|
|
|
419
|
+
/**
|
|
420
|
+
* Sets a single input value for the "forward" method at index 0.
|
|
421
|
+
*
|
|
422
|
+
* @param value The input value.
|
|
423
|
+
* @param error On failure, set to an NSError describing the issue.
|
|
424
|
+
* @return YES on success; NO otherwise.
|
|
425
|
+
*/
|
|
426
|
+
- (BOOL)setInput:(ExecuTorchValue *)value
|
|
427
|
+
error:(NSError **)error NS_SWIFT_UNAVAILABLE("");
|
|
428
|
+
|
|
429
|
+
/**
|
|
430
|
+
* Sets a single input value for the "forward" method at the specified index.
|
|
431
|
+
*
|
|
432
|
+
* @param value The input value.
|
|
433
|
+
* @param index Zero-based input index.
|
|
434
|
+
* @param error On failure, set to an NSError describing the issue.
|
|
435
|
+
* @return YES on success; NO otherwise.
|
|
436
|
+
*/
|
|
437
|
+
- (BOOL)setInput:(ExecuTorchValue *)value
|
|
438
|
+
atIndex:(NSInteger)index
|
|
439
|
+
error:(NSError **)error NS_SWIFT_UNAVAILABLE("");
|
|
440
|
+
|
|
441
|
+
/**
|
|
442
|
+
* Sets a single input value for the specified method at index 0.
|
|
443
|
+
*
|
|
444
|
+
* @param value The input value.
|
|
445
|
+
* @param methodName The method name.
|
|
446
|
+
* @param error On failure, set to an NSError describing the issue.
|
|
447
|
+
* @return YES on success; NO otherwise.
|
|
448
|
+
*/
|
|
449
|
+
- (BOOL)setInput:(ExecuTorchValue *)value
|
|
450
|
+
forMethod:(NSString *)methodName
|
|
451
|
+
error:(NSError **)error NS_SWIFT_UNAVAILABLE("");
|
|
452
|
+
|
|
453
|
+
/**
|
|
454
|
+
* Sets a single input value for the specified method at the given index.
|
|
455
|
+
*
|
|
456
|
+
* The module retains the provided value to keep its backing storage alive
|
|
457
|
+
* until the value is overwritten or the module is deallocated.
|
|
458
|
+
*
|
|
459
|
+
* @param value The input value.
|
|
460
|
+
* @param methodName The method name.
|
|
461
|
+
* @param index Zero-based input index.
|
|
462
|
+
* @param error On failure, set to an NSError describing the issue.
|
|
463
|
+
* @return YES on success; NO otherwise.
|
|
464
|
+
*/
|
|
465
|
+
- (BOOL)setInput:(ExecuTorchValue *)value
|
|
466
|
+
forMethod:(NSString *)methodName
|
|
467
|
+
atIndex:(NSInteger)index
|
|
468
|
+
error:(NSError **)error NS_REFINED_FOR_SWIFT;
|
|
469
|
+
|
|
470
|
+
/**
|
|
471
|
+
* Sets all input values for the "forward" method.
|
|
472
|
+
*
|
|
473
|
+
* The number and types of values must match the method’s declared inputs.
|
|
474
|
+
*
|
|
475
|
+
* @param values The input values, one per declared input.
|
|
476
|
+
* @param error On failure, set to an NSError describing the issue.
|
|
477
|
+
* @return YES on success; NO otherwise.
|
|
478
|
+
*/
|
|
479
|
+
- (BOOL)setInputs:(NSArray<ExecuTorchValue *> *)values
|
|
480
|
+
error:(NSError **)error NS_SWIFT_UNAVAILABLE("");
|
|
481
|
+
|
|
482
|
+
/**
|
|
483
|
+
* Sets all input values for the specified method.
|
|
484
|
+
*
|
|
485
|
+
* The module retains the provided values to keep their backing storage alive
|
|
486
|
+
* until the values are overwritten or the module is deallocated.
|
|
487
|
+
*
|
|
488
|
+
* @param values The input values, one per declared input.
|
|
489
|
+
* @param methodName The method name.
|
|
490
|
+
* @param error On failure, set to an NSError describing the issue.
|
|
491
|
+
* @return YES on success; NO otherwise.
|
|
492
|
+
*/
|
|
493
|
+
- (BOOL)setInputs:(NSArray<ExecuTorchValue *> *)values
|
|
494
|
+
forMethod:(NSString *)methodName
|
|
495
|
+
error:(NSError **)error NS_REFINED_FOR_SWIFT;
|
|
496
|
+
|
|
497
|
+
/**
|
|
498
|
+
* Sets the output buffer for the "forward" method at index 0.
|
|
499
|
+
*
|
|
500
|
+
* Only tensor outputs are supported. The provided value must wrap a tensor
|
|
501
|
+
* compatible with the method’s output slot.
|
|
502
|
+
*
|
|
503
|
+
* @param value The output buffer (must wrap a tensor).
|
|
504
|
+
* @param error On failure, set to an NSError describing the issue.
|
|
505
|
+
* @return YES on success; NO otherwise.
|
|
506
|
+
*/
|
|
507
|
+
- (BOOL)setOutput:(ExecuTorchValue *)value
|
|
508
|
+
error:(NSError **)error NS_SWIFT_UNAVAILABLE("");
|
|
509
|
+
|
|
510
|
+
/**
|
|
511
|
+
* Sets the output buffer for the "forward" method at the specified index.
|
|
512
|
+
*
|
|
513
|
+
* Only tensor outputs are supported. The provided value must wrap a tensor
|
|
514
|
+
* compatible with the method’s output slot.
|
|
515
|
+
*
|
|
516
|
+
* @param value The output buffer (must wrap a tensor).
|
|
517
|
+
* @param index Zero-based output index.
|
|
518
|
+
* @param error On failure, set to an NSError describing the issue.
|
|
519
|
+
* @return YES on success; NO otherwise.
|
|
520
|
+
*/
|
|
521
|
+
- (BOOL)setOutput:(ExecuTorchValue *)value
|
|
522
|
+
atIndex:(NSInteger)index
|
|
523
|
+
error:(NSError **)error NS_SWIFT_UNAVAILABLE("");
|
|
524
|
+
|
|
525
|
+
/**
|
|
526
|
+
* Sets the output buffer for the specified method at index 0.
|
|
527
|
+
*
|
|
528
|
+
* Only tensor outputs are supported. The provided value must wrap a tensor
|
|
529
|
+
* compatible with the method’s output slot.
|
|
530
|
+
*
|
|
531
|
+
* @param value The output buffer (must wrap a tensor).
|
|
532
|
+
* @param methodName The method name.
|
|
533
|
+
* @param error On failure, set to an NSError describing the issue.
|
|
534
|
+
* @return YES on success; NO otherwise.
|
|
535
|
+
*/
|
|
536
|
+
- (BOOL)setOutput:(ExecuTorchValue *)value
|
|
537
|
+
forMethod:(NSString *)methodName
|
|
538
|
+
error:(NSError **)error NS_SWIFT_UNAVAILABLE("");
|
|
539
|
+
|
|
540
|
+
/**
|
|
541
|
+
* Sets the output buffer for the specified method at the given index.
|
|
542
|
+
*
|
|
543
|
+
* The module retains the provided value to keep its backing storage alive
|
|
544
|
+
* until the value is overwritten or the module is deallocated.
|
|
545
|
+
* Only tensor outputs are supported.
|
|
546
|
+
*
|
|
547
|
+
* @param value The output buffer (must wrap a tensor).
|
|
548
|
+
* @param methodName The method name.
|
|
549
|
+
* @param index Zero-based output index.
|
|
550
|
+
* @param error On failure, set to an NSError describing the issue.
|
|
551
|
+
* @return YES on success; NO otherwise.
|
|
552
|
+
*/
|
|
553
|
+
- (BOOL)setOutput:(ExecuTorchValue *)value
|
|
554
|
+
forMethod:(NSString *)methodName
|
|
555
|
+
atIndex:(NSInteger)index
|
|
556
|
+
error:(NSError **)error NS_REFINED_FOR_SWIFT;
|
|
557
|
+
|
|
385
558
|
+ (instancetype)new NS_UNAVAILABLE;
|
|
386
559
|
- (instancetype)init NS_UNAVAILABLE;
|
|
387
560
|
|
|
@@ -69,8 +69,7 @@ typedef NS_ENUM(uint8_t, ExecuTorchShapeDynamism) {
|
|
|
69
69
|
* @return An NSInteger indicating the size in bytes.
|
|
70
70
|
*/
|
|
71
71
|
FOUNDATION_EXPORT
|
|
72
|
-
|
|
73
|
-
ExecuTorchSizeOfDataType(ExecuTorchDataType dataType)
|
|
72
|
+
NSInteger ExecuTorchSizeOfDataType(ExecuTorchDataType dataType)
|
|
74
73
|
NS_SWIFT_NAME(size(ofDataType:));
|
|
75
74
|
|
|
76
75
|
/**
|
|
@@ -81,7 +80,7 @@ ExecuTorchSizeOfDataType(ExecuTorchDataType dataType)
|
|
|
81
80
|
* @return An NSInteger equal to the product of the sizes of all dimensions.
|
|
82
81
|
*/
|
|
83
82
|
FOUNDATION_EXPORT
|
|
84
|
-
|
|
83
|
+
NSInteger
|
|
85
84
|
ExecuTorchElementCountOfShape(NSArray<NSNumber *> *shape) NS_REFINED_FOR_SWIFT;
|
|
86
85
|
|
|
87
86
|
/**
|
|
@@ -91,7 +90,7 @@ ExecuTorchElementCountOfShape(NSArray<NSNumber *> *shape) NS_REFINED_FOR_SWIFT;
|
|
|
91
90
|
* initializers and utility methods to work with tensor data.
|
|
92
91
|
*/
|
|
93
92
|
NS_SWIFT_NAME(AnyTensor)
|
|
94
|
-
__attribute__((
|
|
93
|
+
__attribute__((objc_subclassing_restricted))
|
|
95
94
|
@interface ExecuTorchTensor : NSObject<NSCopying>
|
|
96
95
|
|
|
97
96
|
/**
|
|
@@ -22,12 +22,6 @@ typedef NS_ENUM(uint32_t, ExecuTorchValueTag) {
|
|
|
22
22
|
ExecuTorchValueTagDouble,
|
|
23
23
|
ExecuTorchValueTagInteger,
|
|
24
24
|
ExecuTorchValueTagBoolean,
|
|
25
|
-
ExecuTorchValueTagBooleanList,
|
|
26
|
-
ExecuTorchValueTagDoubleList,
|
|
27
|
-
ExecuTorchValueTagIntegerList,
|
|
28
|
-
ExecuTorchValueTagTensorList,
|
|
29
|
-
ExecuTorchValueTagScalarList,
|
|
30
|
-
ExecuTorchValueTagOptionalTensorList,
|
|
31
25
|
} NS_SWIFT_NAME(ValueTag);
|
|
32
26
|
|
|
33
27
|
typedef NSNumber *
|
|
@@ -49,7 +43,7 @@ typedef float
|
|
|
49
43
|
* a tensor or a scalar. The value’s type is indicated by its tag.
|
|
50
44
|
*/
|
|
51
45
|
NS_SWIFT_NAME(Value)
|
|
52
|
-
__attribute__((
|
|
46
|
+
__attribute__((objc_subclassing_restricted))
|
|
53
47
|
@interface ExecuTorchValue : NSObject<NSCopying>
|
|
54
48
|
|
|
55
49
|
/**
|
|
@@ -69,7 +69,7 @@ public:
|
|
|
69
69
|
* memory locking behavior.
|
|
70
70
|
*
|
|
71
71
|
* @param[in] file_path The path to the ExecuTorch program file to load.
|
|
72
|
-
* @param[in] data_map_path The path to a .ptd file
|
|
72
|
+
* @param[in] data_map_path The path to a .ptd file.
|
|
73
73
|
* @param[in] load_mode The loading mode to use.
|
|
74
74
|
* @param[in] event_tracer A EventTracer used for tracking and logging events.
|
|
75
75
|
*/
|
|
@@ -78,6 +78,20 @@ public:
|
|
|
78
78
|
const LoadMode load_mode = LoadMode::File,
|
|
79
79
|
std::unique_ptr<runtime::EventTracer> event_tracer = nullptr);
|
|
80
80
|
|
|
81
|
+
/**
|
|
82
|
+
* Constructs an instance by loading a program from a file with specified
|
|
83
|
+
* memory locking behavior.
|
|
84
|
+
*
|
|
85
|
+
* @param[in] file_path The path to the ExecuTorch program file to load.
|
|
86
|
+
* @param[in] data_files The path to one or more .ptd file/s.
|
|
87
|
+
* @param[in] load_mode The loading mode to use.
|
|
88
|
+
* @param[in] event_tracer A EventTracer used for tracking and logging events.
|
|
89
|
+
*/
|
|
90
|
+
explicit Module(const std::string &file_path,
|
|
91
|
+
std::vector<std::string> data_files,
|
|
92
|
+
const LoadMode load_mode = LoadMode::File,
|
|
93
|
+
std::unique_ptr<runtime::EventTracer> event_tracer = nullptr);
|
|
94
|
+
|
|
81
95
|
/**
|
|
82
96
|
* Constructs an instance with the provided data loader and memory allocator.
|
|
83
97
|
*
|
|
@@ -188,6 +202,32 @@ public:
|
|
|
188
202
|
return load_method(method_name, nullptr, event_tracer);
|
|
189
203
|
}
|
|
190
204
|
|
|
205
|
+
/**
|
|
206
|
+
* Unload a specific method from the program.
|
|
207
|
+
*
|
|
208
|
+
* @param[in] method_name The name of the method to unload.
|
|
209
|
+
*
|
|
210
|
+
* @returns True if the method is unloaded, false if no-op.
|
|
211
|
+
*/
|
|
212
|
+
inline bool unload_method(const std::string &method_name) {
|
|
213
|
+
return methods_.erase(method_name);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* DEPRECATED: Module manages each Method exclusively.
|
|
218
|
+
*
|
|
219
|
+
* Get a method by it's name. Not recommended to use this method directly as
|
|
220
|
+
* an end user. It's exposed to allow for composability of module in apis that
|
|
221
|
+
* operate on method.
|
|
222
|
+
*
|
|
223
|
+
* @param[in] method_name The name of the method to get.
|
|
224
|
+
*
|
|
225
|
+
* @returns A Result object containing either a pointer to the requested
|
|
226
|
+
* method or an error to indicate failure.
|
|
227
|
+
*/
|
|
228
|
+
ET_DEPRECATED ET_NODISCARD runtime::Result<Method *>
|
|
229
|
+
method(const std::string &method_name);
|
|
230
|
+
|
|
191
231
|
/**
|
|
192
232
|
* Load the 'forward' method from the program and set up memory management if
|
|
193
233
|
* needed. The loaded method is cached to reuse the next time it's executed.
|
|
@@ -210,6 +250,13 @@ public:
|
|
|
210
250
|
return load_forward(nullptr, event_tracer);
|
|
211
251
|
}
|
|
212
252
|
|
|
253
|
+
/**
|
|
254
|
+
* Unload the 'forward' method from the program.
|
|
255
|
+
*
|
|
256
|
+
* @returns True if the 'forward' method is unloaded, false if no-op.
|
|
257
|
+
*/
|
|
258
|
+
inline bool unload_forward() { return unload_method("forward"); }
|
|
259
|
+
|
|
213
260
|
/**
|
|
214
261
|
* Checks if a specific method is loaded.
|
|
215
262
|
*
|
|
@@ -453,6 +500,89 @@ public:
|
|
|
453
500
|
return set_output("forward", std::move(output_value), output_index);
|
|
454
501
|
}
|
|
455
502
|
|
|
503
|
+
/**
|
|
504
|
+
* Sets all output tensors for a specific method.
|
|
505
|
+
*
|
|
506
|
+
* Loads the program and method if needed, and for each output uses
|
|
507
|
+
* the provided tensor's data buffer as the method's output buffer.
|
|
508
|
+
*
|
|
509
|
+
* @param[in] method_name The name of the method.
|
|
510
|
+
* @param[in] output_values A vector of EValues to set as the method outputs.
|
|
511
|
+
*
|
|
512
|
+
* @returns An Error to indicate success or failure.
|
|
513
|
+
*
|
|
514
|
+
* @note Only Tensor outputs are currently supported for setting.
|
|
515
|
+
* @note Will fail for outputs that are memory-planned or constants.
|
|
516
|
+
*/
|
|
517
|
+
ET_NODISCARD
|
|
518
|
+
runtime::Error set_outputs(const std::string &method_name,
|
|
519
|
+
const std::vector<runtime::EValue> &output_values);
|
|
520
|
+
|
|
521
|
+
/**
|
|
522
|
+
* Sets all output tensors for the "forward" method.
|
|
523
|
+
*
|
|
524
|
+
* @param[in] output_values A vector of EValues to set as the method outputs.
|
|
525
|
+
*
|
|
526
|
+
* @returns An Error to indicate success or failure.
|
|
527
|
+
*
|
|
528
|
+
* @note Only Tensor outputs are currently supported for setting.
|
|
529
|
+
* @note Will fail for outputs that are memory-planned or constants.
|
|
530
|
+
*/
|
|
531
|
+
ET_NODISCARD
|
|
532
|
+
inline runtime::Error
|
|
533
|
+
set_outputs(const std::vector<runtime::EValue> &output_values) {
|
|
534
|
+
return set_outputs("forward", output_values);
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
/**
|
|
538
|
+
* Retrieve all current output values of a specific method without executing
|
|
539
|
+
* it. Loads the program and method before retrieval if needed.
|
|
540
|
+
*
|
|
541
|
+
* @param[in] method_name The name of the method.
|
|
542
|
+
*
|
|
543
|
+
* @returns A Result containing the vector of output values, or an error.
|
|
544
|
+
*/
|
|
545
|
+
ET_NODISCARD
|
|
546
|
+
runtime::Result<std::vector<runtime::EValue>>
|
|
547
|
+
get_outputs(const std::string &method_name);
|
|
548
|
+
|
|
549
|
+
/**
|
|
550
|
+
* Retrieve all current output values of the "forward" method without
|
|
551
|
+
* executing it. Loads the program and method before retrieval if needed.
|
|
552
|
+
*
|
|
553
|
+
* @returns A Result containing the vector of output values, or an error.
|
|
554
|
+
*/
|
|
555
|
+
ET_NODISCARD
|
|
556
|
+
inline runtime::Result<std::vector<runtime::EValue>> get_outputs() {
|
|
557
|
+
return get_outputs("forward");
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
/**
|
|
561
|
+
* Retrieve a single current output value of a specific method without
|
|
562
|
+
* executing it. Loads the program and method before retrieval if needed.
|
|
563
|
+
*
|
|
564
|
+
* @param[in] method_name The name of the method.
|
|
565
|
+
* @param[in] output_index Zero-based index of the output to retrieve.
|
|
566
|
+
*
|
|
567
|
+
* @returns A Result containing the requested output value, or an error.
|
|
568
|
+
*/
|
|
569
|
+
ET_NODISCARD
|
|
570
|
+
runtime::Result<runtime::EValue> get_output(const std::string &method_name,
|
|
571
|
+
size_t output_index = 0);
|
|
572
|
+
|
|
573
|
+
/**
|
|
574
|
+
* Retrieve a single current output value of the "forward" method without
|
|
575
|
+
* executing it. Loads the program and method before retrieval if needed.
|
|
576
|
+
*
|
|
577
|
+
* @param[in] output_index Zero-based index of the output to retrieve.
|
|
578
|
+
*
|
|
579
|
+
* @returns A Result containing the requested output value, or an error.
|
|
580
|
+
*/
|
|
581
|
+
ET_NODISCARD
|
|
582
|
+
inline runtime::Result<runtime::EValue> get_output(size_t output_index = 0) {
|
|
583
|
+
return get_output("forward", output_index);
|
|
584
|
+
}
|
|
585
|
+
|
|
456
586
|
/**
|
|
457
587
|
* Retrieves the EventTracer instance being used by the Module.
|
|
458
588
|
* EventTracer is used for tracking and logging events during the execution
|
|
@@ -465,8 +595,9 @@ public:
|
|
|
465
595
|
return event_tracer_.get();
|
|
466
596
|
}
|
|
467
597
|
|
|
468
|
-
|
|
469
|
-
|
|
598
|
+
// Note: this debug_buffer will always be empty. The one being used is in
|
|
599
|
+
// the event_tracer attached to module. Please use that one.
|
|
600
|
+
ET_DEPRECATED ET_NODISCARD runtime::Span<uint8_t> debug_buffer() {
|
|
470
601
|
return runtime::Span<uint8_t>(debug_buffer_.data(), debug_buffer_.size());
|
|
471
602
|
}
|
|
472
603
|
|
|
@@ -477,20 +608,20 @@ private:
|
|
|
477
608
|
std::unique_ptr<runtime::HierarchicalAllocator> planned_memory;
|
|
478
609
|
std::unique_ptr<runtime::MemoryManager> memory_manager;
|
|
479
610
|
std::unique_ptr<Method> method;
|
|
480
|
-
std::vector<runtime::EValue> inputs;
|
|
481
611
|
};
|
|
482
612
|
|
|
483
613
|
std::string file_path_;
|
|
484
|
-
std::string
|
|
614
|
+
std::vector<std::string> data_files_;
|
|
485
615
|
LoadMode load_mode_{LoadMode::File};
|
|
486
616
|
std::shared_ptr<Program> program_;
|
|
487
617
|
std::unique_ptr<runtime::DataLoader> data_loader_;
|
|
488
618
|
std::unique_ptr<runtime::MemoryAllocator> memory_allocator_;
|
|
489
619
|
std::unique_ptr<runtime::MemoryAllocator> temp_allocator_;
|
|
490
620
|
std::unique_ptr<runtime::EventTracer> event_tracer_;
|
|
491
|
-
std::unique_ptr<runtime::DataLoader
|
|
492
|
-
std::unique_ptr<NamedDataMap
|
|
493
|
-
std::
|
|
621
|
+
std::vector<std::unique_ptr<runtime::DataLoader>> data_map_loaders_;
|
|
622
|
+
std::vector<std::unique_ptr<NamedDataMap>> named_data_maps_;
|
|
623
|
+
std::unique_ptr<NamedDataMap> merged_data_map_;
|
|
624
|
+
ET_DEPRECATED std::vector<uint8_t> debug_buffer_;
|
|
494
625
|
|
|
495
626
|
protected:
|
|
496
627
|
std::unordered_map<std::string, MethodHolder> methods_;
|
|
@@ -102,15 +102,27 @@ make_tensor_ptr(std::vector<executorch::aten::SizesType> sizes,
|
|
|
102
102
|
executorch::aten::ScalarType type = deduced_type,
|
|
103
103
|
executorch::aten::TensorShapeDynamism dynamism =
|
|
104
104
|
executorch::aten::TensorShapeDynamism::DYNAMIC_BOUND) {
|
|
105
|
+
ET_CHECK_MSG(data.size() ==
|
|
106
|
+
executorch::aten::compute_numel(sizes.data(), sizes.size()),
|
|
107
|
+
"Data size does not match tensor size.");
|
|
105
108
|
if (type != deduced_type) {
|
|
106
109
|
ET_CHECK_MSG(runtime::canCast(deduced_type, type),
|
|
107
110
|
"Cannot cast deduced type to specified type.");
|
|
108
111
|
std::vector<uint8_t> casted_data(data.size() * runtime::elementSize(type));
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
112
|
+
|
|
113
|
+
// Create a minimal context for error handling in ET_SWITCH
|
|
114
|
+
struct {
|
|
115
|
+
[[noreturn]] void fail(torch::executor::Error /* error */) {
|
|
116
|
+
ET_CHECK_MSG(false, "Unsupported dtype in make_tensor_ptr");
|
|
117
|
+
}
|
|
118
|
+
} ctx;
|
|
119
|
+
|
|
120
|
+
ET_SWITCH_REALHBBF16_AND_UINT_TYPES(
|
|
121
|
+
type, ctx, "make_tensor_ptr", CTYPE, [&] {
|
|
122
|
+
std::transform(data.begin(), data.end(),
|
|
123
|
+
reinterpret_cast<CTYPE *>(casted_data.data()),
|
|
124
|
+
[](const T &val) { return static_cast<CTYPE>(val); });
|
|
125
|
+
});
|
|
114
126
|
const auto raw_data_ptr = casted_data.data();
|
|
115
127
|
auto data_ptr =
|
|
116
128
|
std::make_shared<std::vector<uint8_t>>(std::move(casted_data));
|
|
@@ -232,7 +244,8 @@ make_tensor_ptr(std::initializer_list<T> list,
|
|
|
232
244
|
* @return A TensorPtr that manages the newly created TensorImpl.
|
|
233
245
|
*/
|
|
234
246
|
template <typename T> inline TensorPtr make_tensor_ptr(T value) {
|
|
235
|
-
return make_tensor_ptr(
|
|
247
|
+
return make_tensor_ptr(std::vector<executorch::aten::SizesType>{},
|
|
248
|
+
std::vector<T>{value});
|
|
236
249
|
}
|
|
237
250
|
|
|
238
251
|
/**
|
|
@@ -281,31 +294,80 @@ inline TensorPtr make_tensor_ptr(
|
|
|
281
294
|
}
|
|
282
295
|
|
|
283
296
|
/**
|
|
284
|
-
* Creates a TensorPtr to manage a new Tensor
|
|
285
|
-
*
|
|
297
|
+
* Creates a TensorPtr to manage a new Tensor that aliases the given Tensor's
|
|
298
|
+
* storage, with optional metadata overrides. Shape dynamism is inherited from
|
|
299
|
+
* the source tensor.
|
|
300
|
+
*
|
|
301
|
+
* If an override is provided (non-empty), it is passed as-is. If an override is
|
|
302
|
+
* empty, the corresponding metadata is reused from the source tensor when it
|
|
303
|
+
* fits; otherwise it is left empty for the core factory to derive a valid
|
|
304
|
+
* configuration. If `dim_order` is empty but `strides` is provided, `dim_order`
|
|
305
|
+
* is left empty so the core may infer it from the provided strides.
|
|
286
306
|
*
|
|
287
|
-
* @param tensor The
|
|
288
|
-
* @
|
|
289
|
-
*
|
|
307
|
+
* @param tensor The source tensor to alias.
|
|
308
|
+
* @param sizes Optional sizes override.
|
|
309
|
+
* @param dim_order Optional dimension order override.
|
|
310
|
+
* @param strides Optional strides override.
|
|
311
|
+
* @param deleter A custom deleter function for managing the lifetime of the
|
|
312
|
+
* original Tensor.
|
|
313
|
+
* @return A TensorPtr aliasing the same storage with requested metadata.
|
|
290
314
|
*/
|
|
291
|
-
inline TensorPtr
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
315
|
+
inline TensorPtr
|
|
316
|
+
make_tensor_ptr(const executorch::aten::Tensor &tensor,
|
|
317
|
+
std::vector<executorch::aten::SizesType> sizes = {},
|
|
318
|
+
std::vector<executorch::aten::DimOrderType> dim_order = {},
|
|
319
|
+
std::vector<executorch::aten::StridesType> strides = {},
|
|
320
|
+
std::function<void(void *)> deleter = nullptr) {
|
|
321
|
+
if (sizes.empty()) {
|
|
322
|
+
sizes.assign(tensor.sizes().begin(), tensor.sizes().end());
|
|
323
|
+
}
|
|
324
|
+
const auto same_rank = sizes.size() == static_cast<size_t>(tensor.dim());
|
|
325
|
+
const auto same_shape = same_rank && std::equal(sizes.begin(), sizes.end(),
|
|
326
|
+
tensor.sizes().begin());
|
|
327
|
+
const auto element_count =
|
|
328
|
+
executorch::aten::compute_numel(sizes.data(), sizes.size());
|
|
329
|
+
const auto parent_element_count = tensor.numel();
|
|
330
|
+
ET_CHECK_MSG(
|
|
331
|
+
element_count <= parent_element_count,
|
|
332
|
+
"Requested view has %zd elements, but source tensor only has %zd.",
|
|
333
|
+
static_cast<ssize_t>(element_count),
|
|
334
|
+
static_cast<ssize_t>(parent_element_count));
|
|
296
335
|
#ifndef USE_ATEN_LIB
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
336
|
+
if (dim_order.empty() && strides.empty() && same_rank) {
|
|
337
|
+
dim_order.assign(tensor.dim_order().begin(), tensor.dim_order().end());
|
|
338
|
+
}
|
|
339
|
+
#endif // USE_ATEN_LIB
|
|
340
|
+
if (strides.empty() && dim_order.empty() && same_shape) {
|
|
341
|
+
strides.assign(tensor.strides().begin(), tensor.strides().end());
|
|
342
|
+
}
|
|
343
|
+
return make_tensor_ptr(std::move(sizes), tensor.mutable_data_ptr(),
|
|
344
|
+
std::move(dim_order), std::move(strides),
|
|
345
|
+
tensor.scalar_type(),
|
|
346
|
+
#ifndef USE_ATEN_LIB
|
|
347
|
+
tensor.shape_dynamism(),
|
|
302
348
|
#else // USE_ATEN_LIB
|
|
303
|
-
|
|
304
|
-
std::vector<executorch::aten::StridesType>(tensor.strides().begin(),
|
|
305
|
-
tensor.strides().end()),
|
|
306
|
-
tensor.scalar_type()
|
|
349
|
+
executorch::aten::TensorShapeDynamism::DYNAMIC_BOUND,
|
|
307
350
|
#endif // USE_ATEN_LIB
|
|
308
|
-
|
|
351
|
+
std::move(deleter));
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
/**
|
|
355
|
+
* Convenience overload identical to make_tensor_ptr(*tensor_ptr, ...).
|
|
356
|
+
* Keeps the original TensorPtr alive until the returned TensorPtr is destroyed.
|
|
357
|
+
*
|
|
358
|
+
* @param tensor_ptr The source tensor pointer to alias.
|
|
359
|
+
* @param sizes Optional sizes override.
|
|
360
|
+
* @param dim_order Optional dimension order override.
|
|
361
|
+
* @param strides Optional strides override.
|
|
362
|
+
* @return A TensorPtr aliasing the same storage with requested metadata.
|
|
363
|
+
*/
|
|
364
|
+
inline TensorPtr
|
|
365
|
+
make_tensor_ptr(const TensorPtr &tensor_ptr,
|
|
366
|
+
std::vector<executorch::aten::SizesType> sizes = {},
|
|
367
|
+
std::vector<executorch::aten::DimOrderType> dim_order = {},
|
|
368
|
+
std::vector<executorch::aten::StridesType> strides = {}) {
|
|
369
|
+
return make_tensor_ptr(*tensor_ptr, std::move(sizes), std::move(dim_order),
|
|
370
|
+
std::move(strides), [tensor_ptr](void *) {});
|
|
309
371
|
}
|
|
310
372
|
|
|
311
373
|
/**
|
|
@@ -42,8 +42,11 @@ public:
|
|
|
42
42
|
* is a private API, which will later be replaced by something that allows
|
|
43
43
|
* creating of threadpool with requested size and use such a threadpool with
|
|
44
44
|
* backend delegates, custom ops or optimized lib.
|
|
45
|
+
* For Meta internal use, there is
|
|
46
|
+
* executorch::extension::threadpool::UseNThreadsThreadPoolGuard API that
|
|
47
|
+
* provides a safer way to select a subset of threads, from threadpool, to run
|
|
48
|
+
* the model on.
|
|
45
49
|
*/
|
|
46
|
-
[[deprecated("This API is experimental and may change without notice.")]]
|
|
47
50
|
bool _unsafe_reset_threadpool(uint32_t num_threads);
|
|
48
51
|
|
|
49
52
|
/**
|
|
@@ -11,6 +11,12 @@
|
|
|
11
11
|
#include <executorch/runtime/core/memory_allocator.h>
|
|
12
12
|
#include <executorch/runtime/core/named_data_map.h>
|
|
13
13
|
|
|
14
|
+
#ifdef __GNUC__
|
|
15
|
+
// Disable -Wdeprecated-declarations, as some builds use 'Werror'.
|
|
16
|
+
#pragma GCC diagnostic push
|
|
17
|
+
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
|
18
|
+
#endif
|
|
19
|
+
|
|
14
20
|
namespace executorch {
|
|
15
21
|
namespace ET_RUNTIME_NAMESPACE {
|
|
16
22
|
/**
|
|
@@ -97,7 +97,7 @@ public:
|
|
|
97
97
|
*/
|
|
98
98
|
ET_NODISCARD virtual Error execute(BackendExecutionContext &context,
|
|
99
99
|
DelegateHandle *handle,
|
|
100
|
-
EValue
|
|
100
|
+
Span<EValue *> args) const = 0;
|
|
101
101
|
|
|
102
102
|
/**
|
|
103
103
|
* Responsible update the backend status, if any. The backend options are
|