react-native-executorch 0.5.6 → 0.5.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/libs/classes.jar +0 -0
- package/android/src/main/cpp/CMakeLists.txt +23 -14
- package/common/rnexecutorch/RnExecutorchInstaller.cpp +4 -21
- package/common/rnexecutorch/host_objects/ModelHostObject.h +67 -51
- package/common/rnexecutorch/models/llm/LLM.cpp +24 -1
- package/common/rnexecutorch/models/llm/LLM.h +4 -1
- package/common/rnexecutorch/threads/GlobalThreadPool.h +79 -0
- package/common/rnexecutorch/threads/HighPerformanceThreadPool.h +364 -0
- package/common/rnexecutorch/threads/utils/ThreadUtils.h +29 -0
- package/common/runner/runner.cpp +9 -3
- package/common/runner/runner.h +4 -3
- package/common/runner/text_token_generator.h +28 -10
- package/lib/Error.js +53 -0
- package/lib/ThreadPool.d.ts +10 -0
- package/lib/ThreadPool.js +28 -0
- package/lib/common/Logger.d.ts +8 -0
- package/lib/common/Logger.js +19 -0
- package/lib/constants/directories.js +2 -0
- package/lib/constants/llmDefaults.d.ts +6 -0
- package/lib/constants/llmDefaults.js +16 -0
- package/lib/constants/modelUrls.d.ts +223 -0
- package/lib/constants/modelUrls.js +322 -0
- package/lib/constants/ocr/models.d.ts +882 -0
- package/lib/constants/ocr/models.js +182 -0
- package/lib/constants/ocr/symbols.js +139 -0
- package/lib/constants/sttDefaults.d.ts +28 -0
- package/lib/constants/sttDefaults.js +68 -0
- package/lib/controllers/LLMController.d.ts +47 -0
- package/lib/controllers/LLMController.js +213 -0
- package/lib/controllers/OCRController.js +67 -0
- package/lib/controllers/SpeechToTextController.d.ts +56 -0
- package/lib/controllers/SpeechToTextController.js +349 -0
- package/lib/controllers/VerticalOCRController.js +70 -0
- package/lib/hooks/computer_vision/useClassification.d.ts +15 -0
- package/lib/hooks/computer_vision/useClassification.js +7 -0
- package/lib/hooks/computer_vision/useImageEmbeddings.d.ts +15 -0
- package/lib/hooks/computer_vision/useImageEmbeddings.js +7 -0
- package/lib/hooks/computer_vision/useImageSegmentation.d.ts +38 -0
- package/lib/hooks/computer_vision/useImageSegmentation.js +7 -0
- package/lib/hooks/computer_vision/useOCR.d.ts +20 -0
- package/lib/hooks/computer_vision/useOCR.js +41 -0
- package/lib/hooks/computer_vision/useObjectDetection.d.ts +15 -0
- package/lib/hooks/computer_vision/useObjectDetection.js +7 -0
- package/lib/hooks/computer_vision/useStyleTransfer.d.ts +15 -0
- package/lib/hooks/computer_vision/useStyleTransfer.js +7 -0
- package/lib/hooks/computer_vision/useVerticalOCR.d.ts +21 -0
- package/lib/hooks/computer_vision/useVerticalOCR.js +43 -0
- package/lib/hooks/general/useExecutorchModule.d.ts +13 -0
- package/lib/hooks/general/useExecutorchModule.js +7 -0
- package/lib/hooks/natural_language_processing/useLLM.d.ts +10 -0
- package/lib/hooks/natural_language_processing/useLLM.js +78 -0
- package/lib/hooks/natural_language_processing/useSpeechToText.d.ts +27 -0
- package/lib/hooks/natural_language_processing/useSpeechToText.js +49 -0
- package/lib/hooks/natural_language_processing/useTextEmbeddings.d.ts +16 -0
- package/lib/hooks/natural_language_processing/useTextEmbeddings.js +7 -0
- package/lib/hooks/natural_language_processing/useTokenizer.d.ts +17 -0
- package/lib/hooks/natural_language_processing/useTokenizer.js +52 -0
- package/lib/hooks/useModule.js +45 -0
- package/lib/hooks/useNonStaticModule.d.ts +20 -0
- package/lib/hooks/useNonStaticModule.js +49 -0
- package/lib/index.d.ts +48 -0
- package/lib/index.js +58 -0
- package/lib/module/controllers/LLMController.js +21 -2
- package/lib/module/controllers/LLMController.js.map +1 -1
- package/lib/module/hooks/natural_language_processing/useLLM.js +6 -2
- package/lib/module/hooks/natural_language_processing/useLLM.js.map +1 -1
- package/lib/module/modules/natural_language_processing/LLMModule.js +7 -2
- package/lib/module/modules/natural_language_processing/LLMModule.js.map +1 -1
- package/lib/module/types/llm.js.map +1 -1
- package/lib/modules/BaseModule.js +25 -0
- package/lib/modules/BaseNonStaticModule.js +14 -0
- package/lib/modules/computer_vision/ClassificationModule.d.ts +8 -0
- package/lib/modules/computer_vision/ClassificationModule.js +17 -0
- package/lib/modules/computer_vision/ImageEmbeddingsModule.d.ts +8 -0
- package/lib/modules/computer_vision/ImageEmbeddingsModule.js +17 -0
- package/lib/modules/computer_vision/ImageSegmentationModule.d.ts +11 -0
- package/lib/modules/computer_vision/ImageSegmentationModule.js +27 -0
- package/lib/modules/computer_vision/OCRModule.d.ts +14 -0
- package/lib/modules/computer_vision/OCRModule.js +17 -0
- package/lib/modules/computer_vision/ObjectDetectionModule.d.ts +9 -0
- package/lib/modules/computer_vision/ObjectDetectionModule.js +17 -0
- package/lib/modules/computer_vision/StyleTransferModule.d.ts +8 -0
- package/lib/modules/computer_vision/StyleTransferModule.js +17 -0
- package/lib/modules/computer_vision/VerticalOCRModule.d.ts +14 -0
- package/lib/modules/computer_vision/VerticalOCRModule.js +19 -0
- package/lib/modules/general/ExecutorchModule.d.ts +7 -0
- package/lib/modules/general/ExecutorchModule.js +14 -0
- package/lib/modules/natural_language_processing/LLMModule.d.ts +28 -0
- package/lib/modules/natural_language_processing/LLMModule.js +45 -0
- package/lib/modules/natural_language_processing/SpeechToTextModule.d.ts +24 -0
- package/lib/modules/natural_language_processing/SpeechToTextModule.js +36 -0
- package/lib/modules/natural_language_processing/TextEmbeddingsModule.d.ts +9 -0
- package/lib/modules/natural_language_processing/TextEmbeddingsModule.js +21 -0
- package/lib/modules/natural_language_processing/TokenizerModule.d.ts +12 -0
- package/lib/modules/natural_language_processing/TokenizerModule.js +30 -0
- package/lib/native/NativeETInstaller.js +2 -0
- package/lib/native/NativeOCR.js +2 -0
- package/lib/native/NativeVerticalOCR.js +2 -0
- package/lib/native/RnExecutorchModules.d.ts +7 -0
- package/lib/native/RnExecutorchModules.js +18 -0
- package/lib/tsconfig.tsbuildinfo +1 -0
- package/lib/types/common.d.ts +32 -0
- package/lib/types/common.js +25 -0
- package/lib/types/imageSegmentation.js +26 -0
- package/lib/types/llm.d.ts +46 -0
- package/lib/types/llm.js +9 -0
- package/lib/types/objectDetection.js +94 -0
- package/lib/types/ocr.js +1 -0
- package/lib/types/stt.d.ts +94 -0
- package/lib/types/stt.js +85 -0
- package/lib/typescript/controllers/LLMController.d.ts +4 -2
- package/lib/typescript/controllers/LLMController.d.ts.map +1 -1
- package/lib/typescript/hooks/natural_language_processing/useLLM.d.ts.map +1 -1
- package/lib/typescript/modules/natural_language_processing/LLMModule.d.ts +4 -2
- package/lib/typescript/modules/natural_language_processing/LLMModule.d.ts.map +1 -1
- package/lib/typescript/types/llm.d.ts +7 -1
- package/lib/typescript/types/llm.d.ts.map +1 -1
- package/lib/utils/ResourceFetcher.d.ts +24 -0
- package/lib/utils/ResourceFetcher.js +305 -0
- package/lib/utils/ResourceFetcherUtils.d.ts +54 -0
- package/lib/utils/ResourceFetcherUtils.js +127 -0
- package/lib/utils/llm.d.ts +6 -0
- package/lib/utils/llm.js +72 -0
- package/lib/utils/stt.js +21 -0
- package/package.json +3 -1
- package/react-native-executorch.podspec +12 -31
- package/src/controllers/LLMController.ts +29 -5
- package/src/hooks/natural_language_processing/useLLM.ts +15 -1
- package/src/modules/natural_language_processing/LLMModule.ts +14 -2
- package/src/types/llm.ts +8 -0
- package/third-party/android/libs/cpuinfo/arm64-v8a/libcpuinfo.so +0 -0
- package/third-party/android/libs/executorch/arm64-v8a/libexecutorch.so +0 -0
- package/third-party/android/libs/executorch/x86_64/libexecutorch.so +0 -0
- package/third-party/android/libs/pthreadpool/arm64-v8a/libpthreadpool.so +0 -0
- package/third-party/android/libs/tokenizers-cpp/arm64-v8a/libsentencepiece.a +0 -0
- package/third-party/android/libs/tokenizers-cpp/arm64-v8a/libtokenizers_c.a +0 -0
- package/third-party/android/libs/tokenizers-cpp/arm64-v8a/libtokenizers_cpp.a +0 -0
- package/third-party/android/libs/tokenizers-cpp/x86_64/libsentencepiece.a +0 -0
- package/third-party/android/libs/tokenizers-cpp/x86_64/libtokenizers_c.a +0 -0
- package/third-party/android/libs/tokenizers-cpp/x86_64/libtokenizers_cpp.a +0 -0
- package/third-party/include/c10/macros/Export.h +2 -86
- package/third-party/include/c10/macros/Macros.h +28 -5
- package/third-party/include/c10/util/BFloat16-inl.h +1 -4
- package/third-party/include/c10/util/BFloat16.h +5 -8
- package/third-party/include/c10/util/Half.h +5 -0
- package/third-party/include/c10/util/bit_cast.h +1 -1
- package/third-party/include/c10/util/complex.h +639 -0
- package/third-party/include/c10/util/complex_math.h +399 -0
- package/third-party/include/c10/util/complex_utils.h +41 -0
- package/third-party/include/c10/util/irange.h +2 -2
- package/third-party/include/c10/util/overflows.h +95 -0
- package/third-party/include/executorch/ExecuTorchError.h +75 -0
- package/third-party/include/executorch/ExecuTorchModule.h +115 -11
- package/third-party/include/executorch/ExecuTorchTensor.h +731 -51
- package/third-party/include/executorch/ExecuTorchValue.h +61 -9
- package/third-party/include/executorch/extension/kernel_util/make_boxed_from_unboxed_functor.h +181 -0
- package/third-party/include/executorch/extension/kernel_util/meta_programming.h +108 -0
- package/third-party/include/executorch/extension/kernel_util/type_list.h +137 -0
- package/third-party/include/executorch/extension/module/bundled_module.h +131 -0
- package/third-party/include/executorch/extension/module/module.h +46 -20
- package/third-party/include/executorch/extension/threadpool/cpuinfo_utils.h +1 -3
- package/third-party/include/executorch/extension/threadpool/threadpool.h +1 -3
- package/third-party/include/executorch/extension/threadpool/threadpool_guard.h +35 -0
- package/third-party/include/executorch/runtime/backend/backend_execution_context.h +3 -3
- package/third-party/include/executorch/runtime/backend/backend_init_context.h +12 -6
- package/third-party/include/executorch/runtime/backend/backend_option_context.h +34 -0
- package/third-party/include/executorch/runtime/backend/interface.h +70 -9
- package/third-party/include/executorch/runtime/backend/options.h +206 -0
- package/third-party/include/executorch/runtime/core/evalue.h +19 -25
- package/third-party/include/executorch/runtime/core/event_tracer.h +32 -17
- package/third-party/include/executorch/runtime/core/event_tracer_hooks.h +23 -14
- package/third-party/include/executorch/runtime/core/exec_aten/exec_aten.h +32 -9
- package/third-party/include/executorch/runtime/core/exec_aten/util/dim_order_util.h +3 -2
- package/third-party/include/executorch/runtime/core/exec_aten/util/scalar_type_util.h +43 -75
- package/third-party/include/executorch/runtime/core/exec_aten/util/tensor_util.h +88 -87
- package/third-party/include/executorch/runtime/core/function_ref.h +100 -0
- package/third-party/include/executorch/runtime/core/named_data_map.h +14 -14
- package/third-party/include/executorch/runtime/core/portable_type/c10/c10/macros/Export.h +2 -86
- package/third-party/include/executorch/runtime/core/portable_type/c10/c10/macros/Macros.h +28 -5
- package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/BFloat16-inl.h +1 -4
- package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/BFloat16.h +5 -8
- package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/Half.h +5 -0
- package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/bit_cast.h +1 -1
- package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/complex.h +639 -0
- package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/complex_math.h +399 -0
- package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/complex_utils.h +41 -0
- package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/irange.h +2 -2
- package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/overflows.h +95 -0
- package/third-party/include/executorch/runtime/core/portable_type/c10/torch/headeronly/macros/Export.h +88 -0
- package/third-party/include/executorch/runtime/core/portable_type/complex.h +6 -29
- package/third-party/include/executorch/runtime/core/portable_type/tensor_impl.h +20 -0
- package/third-party/include/executorch/runtime/core/span.h +4 -0
- package/third-party/include/executorch/runtime/core/tag.h +19 -0
- package/third-party/include/executorch/runtime/core/tensor_layout.h +2 -2
- package/third-party/include/executorch/runtime/executor/method.h +15 -3
- package/third-party/include/executorch/runtime/executor/method_meta.h +34 -5
- package/third-party/include/executorch/runtime/executor/program.h +3 -4
- package/third-party/include/executorch/runtime/executor/pte_data_map.h +9 -8
- package/third-party/include/executorch/runtime/executor/tensor_parser.h +14 -13
- package/third-party/include/executorch/runtime/kernel/kernel_runtime_context.h +5 -5
- package/third-party/include/executorch/runtime/kernel/operator_registry.h +21 -19
- package/third-party/include/executorch/runtime/platform/compiler.h +8 -0
- package/third-party/include/executorch/runtime/platform/platform.h +126 -0
- package/third-party/include/headeronly/macros/Export.h +88 -0
- package/third-party/include/tokenizers-cpp/tokenizers_c.h +61 -0
- package/third-party/include/torch/headeronly/macros/Export.h +88 -0
- package/third-party/ios/ExecutorchLib.xcframework/Info.plist +43 -0
- package/third-party/ios/ExecutorchLib.xcframework/ios-arm64/ExecutorchLib.framework/ExecutorchLib +0 -0
- package/third-party/ios/ExecutorchLib.xcframework/ios-arm64/ExecutorchLib.framework/Info.plist +0 -0
- package/third-party/ios/ExecutorchLib.xcframework/ios-arm64-simulator/ExecutorchLib.framework/ExecutorchLib +0 -0
- package/third-party/ios/ExecutorchLib.xcframework/ios-arm64-simulator/ExecutorchLib.framework/Info.plist +0 -0
- package/third-party/ios/libs/cpuinfo/libcpuinfo.a +0 -0
- package/third-party/ios/libs/pthreadpool/physical-arm64-release/libpthreadpool.a +0 -0
- package/third-party/ios/libs/pthreadpool/simulator-arm64-debug/libpthreadpool.a +0 -0
- package/ios/libs/executorch/libbackend_coreml_ios.a +0 -0
- package/ios/libs/executorch/libbackend_coreml_simulator.a +0 -0
- package/ios/libs/executorch/libbackend_mps_ios.a +0 -0
- package/ios/libs/executorch/libbackend_mps_simulator.a +0 -0
- package/ios/libs/executorch/libbackend_xnnpack_ios.a +0 -0
- package/ios/libs/executorch/libbackend_xnnpack_simulator.a +0 -0
- package/ios/libs/executorch/libexecutorch_ios.a +0 -0
- package/ios/libs/executorch/libexecutorch_simulator.a +0 -0
- package/ios/libs/executorch/libkernels_custom_ios.a +0 -0
- package/ios/libs/executorch/libkernels_custom_simulator.a +0 -0
- package/ios/libs/executorch/libkernels_optimized_ios.a +0 -0
- package/ios/libs/executorch/libkernels_optimized_simulator.a +0 -0
- package/ios/libs/executorch/libkernels_portable_ios.a +0 -0
- package/ios/libs/executorch/libkernels_portable_simulator.a +0 -0
- package/ios/libs/executorch/libkernels_quantized_ios.a +0 -0
- package/ios/libs/executorch/libkernels_quantized_simulator.a +0 -0
- package/third-party/ios/ios.toolchain.cmake +0 -1122
- /package/{ios → third-party/ios}/libs/tokenizers-cpp/physical-arm64-release/libsentencepiece.a +0 -0
- /package/{ios → third-party/ios}/libs/tokenizers-cpp/physical-arm64-release/libtokenizers_c.a +0 -0
- /package/{ios → third-party/ios}/libs/tokenizers-cpp/physical-arm64-release/libtokenizers_cpp.a +0 -0
- /package/{ios → third-party/ios}/libs/tokenizers-cpp/simulator-arm64-debug/libsentencepiece.a +0 -0
- /package/{ios → third-party/ios}/libs/tokenizers-cpp/simulator-arm64-debug/libtokenizers_c.a +0 -0
- /package/{ios → third-party/ios}/libs/tokenizers-cpp/simulator-arm64-debug/libtokenizers_cpp.a +0 -0
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
* All rights reserved.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the BSD-style license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
#pragma once
|
|
10
|
+
#include <array>
|
|
11
|
+
#include <cstddef>
|
|
12
|
+
#include <cstring>
|
|
13
|
+
#include <executorch/runtime/core/error.h>
|
|
14
|
+
#include <executorch/runtime/core/span.h>
|
|
15
|
+
#include <variant>
|
|
16
|
+
|
|
17
|
+
namespace executorch {
|
|
18
|
+
namespace runtime {
|
|
19
|
+
|
|
20
|
+
static constexpr size_t kMaxOptionKeyLength = 64;
|
|
21
|
+
static constexpr size_t kMaxOptionValueLength = 256;
|
|
22
|
+
|
|
23
|
+
// All string keys and values must have static storage duration (string
|
|
24
|
+
// literals, static const char arrays, or global constants). The BackendOptions
|
|
25
|
+
// class does NOT take ownership of strings.
|
|
26
|
+
using OptionValue =
|
|
27
|
+
std::variant<bool, int, std::array<char, kMaxOptionValueLength>>;
|
|
28
|
+
|
|
29
|
+
struct BackendOption {
|
|
30
|
+
// key is the name of the backend option, like num_threads, enable_profiling,
|
|
31
|
+
// etc
|
|
32
|
+
char key[kMaxOptionKeyLength]{};
|
|
33
|
+
// value is the value of the backend option, like 4, true, etc
|
|
34
|
+
OptionValue value;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* A template class for storing and managing backend-specific configuration
|
|
39
|
+
* options.
|
|
40
|
+
*
|
|
41
|
+
* This class provides a type-safe way to store key-value pairs for backend
|
|
42
|
+
* configuration, with compile-time capacity limits and runtime type checking.
|
|
43
|
+
* It supports bool, int, and const char* value types.
|
|
44
|
+
*
|
|
45
|
+
* @tparam MaxCapacity The maximum number of options that can be stored
|
|
46
|
+
*/
|
|
47
|
+
template <size_t MaxCapacity> class BackendOptions {
|
|
48
|
+
public:
|
|
49
|
+
/**
|
|
50
|
+
* Copy constructor
|
|
51
|
+
*/
|
|
52
|
+
BackendOptions(const BackendOptions &other) : size_(other.size_) {
|
|
53
|
+
for (size_t i = 0; i < size_; ++i) {
|
|
54
|
+
options_[i] = other.options_[i];
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Copy assignment operator
|
|
60
|
+
*/
|
|
61
|
+
BackendOptions &operator=(const BackendOptions &other) {
|
|
62
|
+
if (this != &other) {
|
|
63
|
+
size_ = other.size_;
|
|
64
|
+
for (size_t i = 0; i < size_; ++i) {
|
|
65
|
+
options_[i] = other.options_[i];
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return *this;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Default constructor - initializes with zero options.
|
|
73
|
+
*/
|
|
74
|
+
BackendOptions() : size_(0) {}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Returns a mutable view of all stored options as a Span.
|
|
78
|
+
*
|
|
79
|
+
* @return A mutable Span containing all BackendOption entries
|
|
80
|
+
*/
|
|
81
|
+
executorch::runtime::Span<BackendOption> view() {
|
|
82
|
+
return executorch::runtime::Span<BackendOption>(options_, size_);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Sets a boolean option value for the given key.
|
|
87
|
+
* If the key already exists, updates its value. Otherwise, adds a new option.
|
|
88
|
+
*
|
|
89
|
+
* @tparam N The length of the key string (automatically deduced)
|
|
90
|
+
* @param key The option key (must be a string literal or array)
|
|
91
|
+
* @param value The boolean value to set
|
|
92
|
+
* @return Error::Ok on success, Error::InvalidArgument if storage is full
|
|
93
|
+
*/
|
|
94
|
+
template <size_t N>
|
|
95
|
+
Error set_option(const char (&key)[N], bool value) noexcept {
|
|
96
|
+
static_assert(N <= kMaxOptionKeyLength, "Option key is too long");
|
|
97
|
+
return set_option_impl(key, value);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Sets an integer option value for the given key.
|
|
102
|
+
* If the key already exists, updates its value. Otherwise, adds a new option.
|
|
103
|
+
*
|
|
104
|
+
* @tparam N The length of the key string (automatically deduced)
|
|
105
|
+
* @param key The option key (must be a string literal or array)
|
|
106
|
+
* @param value The integer value to set
|
|
107
|
+
* @return Error::Ok on success, Error::InvalidArgument if storage is full
|
|
108
|
+
*/
|
|
109
|
+
template <size_t N>
|
|
110
|
+
Error set_option(const char (&key)[N], int value) noexcept {
|
|
111
|
+
static_assert(N <= kMaxOptionKeyLength, "Option key is too long");
|
|
112
|
+
return set_option_impl(key, value);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Sets a string option value for the given key.
|
|
117
|
+
* If the key already exists, updates its value. Otherwise, adds a new option.
|
|
118
|
+
*
|
|
119
|
+
* Note: The string value must have static storage duration. This class does
|
|
120
|
+
* NOT take ownership of the string - it only stores the pointer.
|
|
121
|
+
*
|
|
122
|
+
* @tparam N The length of the key string (automatically deduced)
|
|
123
|
+
* @param key The option key (must be a string literal or array)
|
|
124
|
+
* @param value The string value to set (must have static storage duration)
|
|
125
|
+
* @return Error::Ok on success, Error::InvalidArgument if storage is full
|
|
126
|
+
*/
|
|
127
|
+
template <size_t N>
|
|
128
|
+
Error set_option(const char (&key)[N], const char *value) noexcept {
|
|
129
|
+
static_assert(N <= kMaxOptionKeyLength, "Option key is too long");
|
|
130
|
+
// Create a fixed-size array and copy the string
|
|
131
|
+
std::array<char, kMaxOptionValueLength> arr{};
|
|
132
|
+
strncpy(arr.data(), value, kMaxOptionValueLength - 1);
|
|
133
|
+
arr[kMaxOptionValueLength - 1] = '\0'; // Ensure null termination
|
|
134
|
+
return set_option_impl(key, arr);
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Retrieves an option value by key and type.
|
|
138
|
+
*
|
|
139
|
+
* @tparam T The expected type of the option value (bool, int, or const char*)
|
|
140
|
+
* @tparam KeyLen The length of the key string (automatically deduced)
|
|
141
|
+
* @param key The option key to look up
|
|
142
|
+
* @param out Reference to store the retrieved value
|
|
143
|
+
* @return Error::Ok if found and type matches, Error::NotFound if key doesn't
|
|
144
|
+
* exist, Error::InvalidArgument if type doesn't match
|
|
145
|
+
*/
|
|
146
|
+
template <typename T, size_t KeyLen>
|
|
147
|
+
Error get_option(const char (&key)[KeyLen], T &out) const {
|
|
148
|
+
static_assert(KeyLen <= kMaxOptionKeyLength, "Option key is too long");
|
|
149
|
+
for (size_t i = 0; i < size_; ++i) {
|
|
150
|
+
if (std::strcmp(options_[i].key, key) == 0) {
|
|
151
|
+
// Special handling for string (convert array to const char*)
|
|
152
|
+
if constexpr (std::is_same_v<T, const char *>) {
|
|
153
|
+
if (auto *arr = std::get_if<std::array<char, kMaxOptionValueLength>>(
|
|
154
|
+
&options_[i].value)) {
|
|
155
|
+
out = arr->data(); // Return pointer to stored array
|
|
156
|
+
return Error::Ok;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
// Default handling for bool/int
|
|
160
|
+
else if (auto *val = std::get_if<T>(&options_[i].value)) {
|
|
161
|
+
out = *val;
|
|
162
|
+
return Error::Ok;
|
|
163
|
+
}
|
|
164
|
+
return Error::InvalidArgument;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
return Error::NotFound;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
private:
|
|
171
|
+
BackendOption options_[MaxCapacity]{}; // Storage for backend options
|
|
172
|
+
size_t size_; // Current number of options
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Internal implementation for setting option values.
|
|
176
|
+
* Handles both updating existing options and adding new ones.
|
|
177
|
+
*
|
|
178
|
+
* @tparam T The type of the value (bool, int, or const char*)
|
|
179
|
+
* @param key The option key
|
|
180
|
+
* @param value The value to set
|
|
181
|
+
* @return Error::Ok on success, Error::InvalidArgument if storage is full
|
|
182
|
+
*/
|
|
183
|
+
template <typename T> Error set_option_impl(const char *key, T value) {
|
|
184
|
+
// Update existing if found
|
|
185
|
+
for (size_t i = 0; i < size_; ++i) {
|
|
186
|
+
if (strcmp(options_[i].key, key) == 0) {
|
|
187
|
+
options_[i].value = value;
|
|
188
|
+
return Error::Ok;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
if (size_ < MaxCapacity) {
|
|
192
|
+
BackendOption new_option;
|
|
193
|
+
const size_t key_len = std::strlen(key);
|
|
194
|
+
const size_t copy_len = std::min(key_len, kMaxOptionKeyLength - 1);
|
|
195
|
+
std::memcpy(new_option.key, key, copy_len);
|
|
196
|
+
new_option.key[copy_len] = '\0';
|
|
197
|
+
new_option.value = value; // Restored value assignment
|
|
198
|
+
options_[size_++] = new_option; // Store option and increment size
|
|
199
|
+
return Error::Ok;
|
|
200
|
+
}
|
|
201
|
+
return Error::InvalidArgument;
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
} // namespace runtime
|
|
206
|
+
} // namespace executorch
|
|
@@ -73,9 +73,8 @@ private:
|
|
|
73
73
|
};
|
|
74
74
|
|
|
75
75
|
template <>
|
|
76
|
-
executorch::aten::ArrayRef<
|
|
77
|
-
BoxedEvalueList<
|
|
78
|
-
const;
|
|
76
|
+
executorch::aten::ArrayRef<std::optional<executorch::aten::Tensor>>
|
|
77
|
+
BoxedEvalueList<std::optional<executorch::aten::Tensor>>::get() const;
|
|
79
78
|
|
|
80
79
|
// Aggregate typing system similar to IValue only slimmed down with less
|
|
81
80
|
// functionality, no dependencies on atomic, and fewer supported types to better
|
|
@@ -98,7 +97,7 @@ struct EValue {
|
|
|
98
97
|
executorch::aten::ArrayRef<bool> as_bool_list;
|
|
99
98
|
BoxedEvalueList<int64_t> as_int_list;
|
|
100
99
|
BoxedEvalueList<executorch::aten::Tensor> as_tensor_list;
|
|
101
|
-
BoxedEvalueList<
|
|
100
|
+
BoxedEvalueList<std::optional<executorch::aten::Tensor>>
|
|
102
101
|
as_list_optional_tensor;
|
|
103
102
|
} copyable_union;
|
|
104
103
|
|
|
@@ -267,11 +266,10 @@ struct EValue {
|
|
|
267
266
|
|
|
268
267
|
bool isString() const { return tag == Tag::String; }
|
|
269
268
|
|
|
270
|
-
|
|
269
|
+
std::string_view toString() const {
|
|
271
270
|
ET_CHECK_MSG(isString(), "EValue is not a String.");
|
|
272
|
-
return
|
|
273
|
-
|
|
274
|
-
payload.copyable_union.as_string.size());
|
|
271
|
+
return std::string_view(payload.copyable_union.as_string.data(),
|
|
272
|
+
payload.copyable_union.as_string.size());
|
|
275
273
|
}
|
|
276
274
|
|
|
277
275
|
/****** Int List Type ******/
|
|
@@ -326,15 +324,14 @@ struct EValue {
|
|
|
326
324
|
|
|
327
325
|
/****** List Optional Tensor Type ******/
|
|
328
326
|
/*implicit*/ EValue(
|
|
329
|
-
BoxedEvalueList<
|
|
327
|
+
BoxedEvalueList<std::optional<executorch::aten::Tensor>> t)
|
|
330
328
|
: tag(Tag::ListOptionalTensor) {
|
|
331
329
|
payload.copyable_union.as_list_optional_tensor = t;
|
|
332
330
|
}
|
|
333
331
|
|
|
334
332
|
bool isListOptionalTensor() const { return tag == Tag::ListOptionalTensor; }
|
|
335
333
|
|
|
336
|
-
executorch::aten::ArrayRef<
|
|
337
|
-
executorch::aten::optional<executorch::aten::Tensor>>
|
|
334
|
+
executorch::aten::ArrayRef<std::optional<executorch::aten::Tensor>>
|
|
338
335
|
toListOptionalTensor() const {
|
|
339
336
|
return payload.copyable_union.as_list_optional_tensor.get();
|
|
340
337
|
}
|
|
@@ -377,8 +374,7 @@ struct EValue {
|
|
|
377
374
|
* Converts the EValue to an optional object that can represent both T and
|
|
378
375
|
* an uninitialized state.
|
|
379
376
|
*/
|
|
380
|
-
template <typename T>
|
|
381
|
-
inline executorch::aten::optional<T> toOptional() const {
|
|
377
|
+
template <typename T> inline std::optional<T> toOptional() const {
|
|
382
378
|
if (this->isNone()) {
|
|
383
379
|
return executorch::aten::nullopt;
|
|
384
380
|
}
|
|
@@ -458,44 +454,42 @@ EVALUE_DEFINE_TO(executorch::aten::Scalar, toScalar)
|
|
|
458
454
|
EVALUE_DEFINE_TO(int64_t, toInt)
|
|
459
455
|
EVALUE_DEFINE_TO(bool, toBool)
|
|
460
456
|
EVALUE_DEFINE_TO(double, toDouble)
|
|
461
|
-
EVALUE_DEFINE_TO(
|
|
457
|
+
EVALUE_DEFINE_TO(std::string_view, toString)
|
|
462
458
|
EVALUE_DEFINE_TO(executorch::aten::ScalarType, toScalarType)
|
|
463
459
|
EVALUE_DEFINE_TO(executorch::aten::MemoryFormat, toMemoryFormat)
|
|
464
460
|
EVALUE_DEFINE_TO(executorch::aten::Layout, toLayout)
|
|
465
461
|
EVALUE_DEFINE_TO(executorch::aten::Device, toDevice)
|
|
466
462
|
// Tensor and Optional Tensor
|
|
467
|
-
EVALUE_DEFINE_TO(
|
|
463
|
+
EVALUE_DEFINE_TO(std::optional<executorch::aten::Tensor>,
|
|
468
464
|
toOptional<executorch::aten::Tensor>)
|
|
469
465
|
EVALUE_DEFINE_TO(executorch::aten::Tensor, toTensor)
|
|
470
466
|
|
|
471
467
|
// IntList and Optional IntList
|
|
472
468
|
EVALUE_DEFINE_TO(executorch::aten::ArrayRef<int64_t>, toIntList)
|
|
473
|
-
EVALUE_DEFINE_TO(
|
|
474
|
-
|
|
475
|
-
toOptional<executorch::aten::ArrayRef<int64_t>>)
|
|
469
|
+
EVALUE_DEFINE_TO(std::optional<executorch::aten::ArrayRef<int64_t>>,
|
|
470
|
+
toOptional<executorch::aten::ArrayRef<int64_t>>)
|
|
476
471
|
|
|
477
472
|
// DoubleList and Optional DoubleList
|
|
478
473
|
EVALUE_DEFINE_TO(executorch::aten::ArrayRef<double>, toDoubleList)
|
|
479
|
-
EVALUE_DEFINE_TO(
|
|
474
|
+
EVALUE_DEFINE_TO(std::optional<executorch::aten::ArrayRef<double>>,
|
|
480
475
|
toOptional<executorch::aten::ArrayRef<double>>)
|
|
481
476
|
|
|
482
477
|
// BoolList and Optional BoolList
|
|
483
478
|
EVALUE_DEFINE_TO(executorch::aten::ArrayRef<bool>, toBoolList)
|
|
484
|
-
EVALUE_DEFINE_TO(
|
|
479
|
+
EVALUE_DEFINE_TO(std::optional<executorch::aten::ArrayRef<bool>>,
|
|
485
480
|
toOptional<executorch::aten::ArrayRef<bool>>)
|
|
486
481
|
|
|
487
482
|
// TensorList and Optional TensorList
|
|
488
483
|
EVALUE_DEFINE_TO(executorch::aten::ArrayRef<executorch::aten::Tensor>,
|
|
489
484
|
toTensorList)
|
|
490
485
|
EVALUE_DEFINE_TO(
|
|
491
|
-
executorch::aten::
|
|
492
|
-
executorch::aten::ArrayRef<executorch::aten::Tensor>>,
|
|
486
|
+
std::optional<executorch::aten::ArrayRef<executorch::aten::Tensor>>,
|
|
493
487
|
toOptional<executorch::aten::ArrayRef<executorch::aten::Tensor>>)
|
|
494
488
|
|
|
495
489
|
// List of Optional Tensor
|
|
496
|
-
EVALUE_DEFINE_TO(
|
|
497
|
-
|
|
498
|
-
|
|
490
|
+
EVALUE_DEFINE_TO(
|
|
491
|
+
executorch::aten::ArrayRef<std::optional<executorch::aten::Tensor>>,
|
|
492
|
+
toListOptionalTensor)
|
|
499
493
|
#undef EVALUE_DEFINE_TO
|
|
500
494
|
|
|
501
495
|
template <typename T>
|
|
@@ -26,10 +26,14 @@ typedef int32_t ChainID;
|
|
|
26
26
|
/// Represents the debug handle that is generally associated with each
|
|
27
27
|
/// op executed in the runtime.
|
|
28
28
|
typedef uint32_t DebugHandle;
|
|
29
|
+
// Represents the delegate debug id that is generally associated with each
|
|
30
|
+
// delegate event.
|
|
31
|
+
typedef int32_t DelegateDebugIntId;
|
|
29
32
|
|
|
30
33
|
/// Default id's for chain id and debug handle.
|
|
31
34
|
constexpr ChainID kUnsetChainId = -1;
|
|
32
35
|
constexpr DebugHandle kUnsetDebugHandle = 0;
|
|
36
|
+
constexpr DelegateDebugIntId kUnsetDelegateDebugIntId = -1;
|
|
33
37
|
// Default bundled input index to indicate that it hasn't been set yet.
|
|
34
38
|
constexpr int kUnsetBundledInputIndex = -1;
|
|
35
39
|
|
|
@@ -96,13 +100,14 @@ public:
|
|
|
96
100
|
* - False if the event does not match or is unknown.
|
|
97
101
|
* - An error code if an error occurs during filtering.
|
|
98
102
|
*/
|
|
99
|
-
virtual Result<bool> filter(char *name,
|
|
103
|
+
virtual Result<bool> filter(const char *name,
|
|
104
|
+
DelegateDebugIntId delegate_debug_index) = 0;
|
|
100
105
|
|
|
101
106
|
/**
|
|
102
107
|
* Virtual destructor for the EventTracerFilterBase class.
|
|
103
108
|
* Ensures proper cleanup of derived class objects.
|
|
104
109
|
*/
|
|
105
|
-
virtual ~EventTracerFilterBase();
|
|
110
|
+
virtual ~EventTracerFilterBase() = default;
|
|
106
111
|
};
|
|
107
112
|
|
|
108
113
|
/**
|
|
@@ -122,6 +127,11 @@ enum class EventTracerProfilingLevel {
|
|
|
122
127
|
* started. This is used to uniquely identify that profiling event and will be
|
|
123
128
|
* required to be passed into the end_profiling call to signal that the event
|
|
124
129
|
* identified by this struct has completed.
|
|
130
|
+
*
|
|
131
|
+
* TODO(gasoonjia): Now this struct is mix-used for both delegate and
|
|
132
|
+
*non-delegate events. In the future we should separate them into two different
|
|
133
|
+
*structs: EventTracerEntry for non-delegate events holding DebugHandle, and
|
|
134
|
+
*DelegateEventTracerEntry for delegate events holding DelegateDebugIntId.
|
|
125
135
|
**/
|
|
126
136
|
struct EventTracerEntry {
|
|
127
137
|
/// An event id to uniquely identify this event that was generated during a
|
|
@@ -207,7 +217,7 @@ public:
|
|
|
207
217
|
*/
|
|
208
218
|
virtual EventTracerEntry
|
|
209
219
|
start_profiling_delegate(const char *name,
|
|
210
|
-
|
|
220
|
+
DelegateDebugIntId delegate_debug_index) = 0;
|
|
211
221
|
|
|
212
222
|
/**
|
|
213
223
|
* Signal the end of the delegate profiling event contained in
|
|
@@ -253,7 +263,7 @@ public:
|
|
|
253
263
|
* @param[in] metadata_len Length of the metadata buffer.
|
|
254
264
|
*/
|
|
255
265
|
virtual void log_profiling_delegate(const char *name,
|
|
256
|
-
|
|
266
|
+
DelegateDebugIntId delegate_debug_index,
|
|
257
267
|
et_timestamp_t start_time,
|
|
258
268
|
et_timestamp_t end_time,
|
|
259
269
|
const void *metadata = nullptr,
|
|
@@ -299,9 +309,12 @@ public:
|
|
|
299
309
|
* @param[in] evalue The value to be logged.
|
|
300
310
|
* @param[in] evalue_type Indicates what type of output this is logging e.g.
|
|
301
311
|
* an intermediate output, program output etc.
|
|
312
|
+
* @return A Result<bool> indicating the status of the logging operation.
|
|
313
|
+
* - True if the evalue output was successfully logged.
|
|
314
|
+
* - An error code if an error occurs during logging.
|
|
302
315
|
*/
|
|
303
|
-
virtual
|
|
304
|
-
|
|
316
|
+
virtual Result<bool> log_evalue(const EValue &evalue,
|
|
317
|
+
LoggedEValueType evalue_type) = 0;
|
|
305
318
|
|
|
306
319
|
/**
|
|
307
320
|
* Log an intermediate tensor output from a delegate.
|
|
@@ -324,7 +337,7 @@ public:
|
|
|
324
337
|
*/
|
|
325
338
|
virtual Result<bool>
|
|
326
339
|
log_intermediate_output_delegate(const char *name,
|
|
327
|
-
|
|
340
|
+
DelegateDebugIntId delegate_debug_index,
|
|
328
341
|
const executorch::aten::Tensor &output) = 0;
|
|
329
342
|
|
|
330
343
|
/**
|
|
@@ -348,7 +361,7 @@ public:
|
|
|
348
361
|
* - An error code if an error occurs during logging.
|
|
349
362
|
*/
|
|
350
363
|
virtual Result<bool> log_intermediate_output_delegate(
|
|
351
|
-
const char *name,
|
|
364
|
+
const char *name, DelegateDebugIntId delegate_debug_index,
|
|
352
365
|
const ArrayRef<executorch::aten::Tensor> output) = 0;
|
|
353
366
|
|
|
354
367
|
/**
|
|
@@ -372,7 +385,7 @@ public:
|
|
|
372
385
|
*/
|
|
373
386
|
virtual Result<bool>
|
|
374
387
|
log_intermediate_output_delegate(const char *name,
|
|
375
|
-
|
|
388
|
+
DelegateDebugIntId delegate_debug_index,
|
|
376
389
|
const int &output) = 0;
|
|
377
390
|
|
|
378
391
|
/**
|
|
@@ -396,7 +409,7 @@ public:
|
|
|
396
409
|
*/
|
|
397
410
|
virtual Result<bool>
|
|
398
411
|
log_intermediate_output_delegate(const char *name,
|
|
399
|
-
|
|
412
|
+
DelegateDebugIntId delegate_debug_index,
|
|
400
413
|
const bool &output) = 0;
|
|
401
414
|
|
|
402
415
|
/**
|
|
@@ -420,9 +433,15 @@ public:
|
|
|
420
433
|
*/
|
|
421
434
|
virtual Result<bool>
|
|
422
435
|
log_intermediate_output_delegate(const char *name,
|
|
423
|
-
|
|
436
|
+
DelegateDebugIntId delegate_debug_index,
|
|
424
437
|
const double &output) = 0;
|
|
425
438
|
|
|
439
|
+
/**
|
|
440
|
+
* Set the filter of event tracer for delegation intermediate outputs.
|
|
441
|
+
*/
|
|
442
|
+
virtual void set_delegation_intermediate_output_filter(
|
|
443
|
+
EventTracerFilterBase *event_tracer_filter) = 0;
|
|
444
|
+
|
|
426
445
|
/**
|
|
427
446
|
* Helper function to set the chain id ands debug handle. Users have two
|
|
428
447
|
* options, the first is that they can directly pass in the chain id and debug
|
|
@@ -495,12 +514,6 @@ public:
|
|
|
495
514
|
event_tracer_profiling_level_ = profiling_level;
|
|
496
515
|
}
|
|
497
516
|
|
|
498
|
-
/**
|
|
499
|
-
* Set the filter of event tracer for delegation intermediate outputs.
|
|
500
|
-
*/
|
|
501
|
-
void set_delegation_intermediate_output_filter(
|
|
502
|
-
EventTracerFilterBase *event_tracer_filter);
|
|
503
|
-
|
|
504
517
|
/**
|
|
505
518
|
* Return the current level of event tracer profiling.
|
|
506
519
|
*/
|
|
@@ -554,12 +567,14 @@ using ::executorch::runtime::AllocatorID;
|
|
|
554
567
|
using ::executorch::runtime::ChainID;
|
|
555
568
|
using ::executorch::runtime::DebugHandle;
|
|
556
569
|
using ::executorch::runtime::DelegateDebugIdType;
|
|
570
|
+
using ::executorch::runtime::DelegateDebugIntId;
|
|
557
571
|
using ::executorch::runtime::EventTracer;
|
|
558
572
|
using ::executorch::runtime::EventTracerDebugLogLevel;
|
|
559
573
|
using ::executorch::runtime::EventTracerEntry;
|
|
560
574
|
using ::executorch::runtime::kUnsetBundledInputIndex;
|
|
561
575
|
using ::executorch::runtime::kUnsetChainId;
|
|
562
576
|
using ::executorch::runtime::kUnsetDebugHandle;
|
|
577
|
+
using ::executorch::runtime::kUnsetDelegateDebugIntId;
|
|
563
578
|
using ::executorch::runtime::LoggedEValueType;
|
|
564
579
|
} // namespace executor
|
|
565
580
|
} // namespace torch
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
*/
|
|
31
31
|
|
|
32
32
|
namespace executorch {
|
|
33
|
-
namespace
|
|
33
|
+
namespace ET_RUNTIME_NAMESPACE {
|
|
34
34
|
namespace internal {
|
|
35
35
|
|
|
36
36
|
/**
|
|
@@ -297,7 +297,7 @@ inline void event_tracer_set_bundled_input_index(EventTracer *event_tracer,
|
|
|
297
297
|
}
|
|
298
298
|
|
|
299
299
|
} // namespace internal
|
|
300
|
-
} // namespace
|
|
300
|
+
} // namespace ET_RUNTIME_NAMESPACE
|
|
301
301
|
} // namespace executorch
|
|
302
302
|
|
|
303
303
|
namespace torch {
|
|
@@ -305,18 +305,27 @@ namespace executor {
|
|
|
305
305
|
namespace internal {
|
|
306
306
|
// TODO(T197294990): Remove these deprecated aliases once all users have moved
|
|
307
307
|
// to the new `::executorch` namespaces.
|
|
308
|
-
using ::executorch::
|
|
309
|
-
|
|
310
|
-
using ::executorch::
|
|
311
|
-
|
|
312
|
-
using ::executorch::
|
|
313
|
-
|
|
314
|
-
using ::executorch::
|
|
315
|
-
using ::executorch::
|
|
316
|
-
|
|
317
|
-
using ::executorch::
|
|
318
|
-
|
|
319
|
-
using ::executorch::
|
|
308
|
+
using ::executorch::ET_RUNTIME_NAMESPACE::internal::
|
|
309
|
+
event_tracer_begin_profiling_event;
|
|
310
|
+
using ::executorch::ET_RUNTIME_NAMESPACE::internal::
|
|
311
|
+
event_tracer_create_event_block;
|
|
312
|
+
using ::executorch::ET_RUNTIME_NAMESPACE::internal::
|
|
313
|
+
event_tracer_end_profiling_event;
|
|
314
|
+
using ::executorch::ET_RUNTIME_NAMESPACE::internal::event_tracer_log_evalue;
|
|
315
|
+
using ::executorch::ET_RUNTIME_NAMESPACE::internal::
|
|
316
|
+
event_tracer_log_evalue_output;
|
|
317
|
+
using ::executorch::ET_RUNTIME_NAMESPACE::internal::
|
|
318
|
+
event_tracer_set_bundled_input_index;
|
|
319
|
+
using ::executorch::ET_RUNTIME_NAMESPACE::internal::
|
|
320
|
+
event_tracer_track_allocation;
|
|
321
|
+
using ::executorch::ET_RUNTIME_NAMESPACE::internal::
|
|
322
|
+
event_tracer_track_allocator;
|
|
323
|
+
using ::executorch::ET_RUNTIME_NAMESPACE::internal::
|
|
324
|
+
EventTracerProfileInstructionScope;
|
|
325
|
+
using ::executorch::ET_RUNTIME_NAMESPACE::internal::
|
|
326
|
+
EventTracerProfileMethodScope;
|
|
327
|
+
using ::executorch::ET_RUNTIME_NAMESPACE::internal::EventTracerProfileOpScope;
|
|
328
|
+
using ::executorch::ET_RUNTIME_NAMESPACE::internal::EventTracerProfileScope;
|
|
320
329
|
|
|
321
330
|
} // namespace internal
|
|
322
331
|
} // namespace executor
|
|
@@ -47,21 +47,37 @@
|
|
|
47
47
|
|
|
48
48
|
#endif
|
|
49
49
|
|
|
50
|
+
/**
|
|
51
|
+
* This hack is for separating out ATen mode vs non-ATen mode. In ATen mode,
|
|
52
|
+
* we use the ATen types directly. In non-ATen mode, we use the portable types.
|
|
53
|
+
* To avoid duplicate symbols and/or duplicate operator registration, when a
|
|
54
|
+
* user depends on both the ATen mode and non-ATen mode versions of the
|
|
55
|
+
* ExecuTorch library.
|
|
56
|
+
*/
|
|
57
|
+
#ifndef ET_RUNTIME_NAMESPACE
|
|
58
|
+
#if defined(USE_ATEN_LIB)
|
|
59
|
+
#define ET_RUNTIME_NAMESPACE runtime::aten
|
|
60
|
+
#else
|
|
61
|
+
#define ET_RUNTIME_NAMESPACE runtime
|
|
62
|
+
#endif
|
|
63
|
+
#endif
|
|
64
|
+
|
|
50
65
|
namespace executorch {
|
|
51
66
|
namespace aten {
|
|
52
67
|
|
|
53
68
|
using TensorShapeDynamism = executorch::runtime::TensorShapeDynamism;
|
|
54
69
|
|
|
70
|
+
using std::nullopt;
|
|
71
|
+
using std::nullopt_t;
|
|
72
|
+
using std::optional;
|
|
73
|
+
using std::string_view;
|
|
74
|
+
|
|
55
75
|
#ifdef USE_ATEN_LIB
|
|
56
76
|
|
|
57
77
|
using Tensor = at::Tensor;
|
|
58
78
|
using TensorList = at::TensorList;
|
|
59
79
|
using TensorImpl = at::TensorImpl;
|
|
60
|
-
using string_view = std::string_view;
|
|
61
80
|
template <typename T> using ArrayRef = c10::ArrayRef<T>;
|
|
62
|
-
template <typename T> using optional = std::optional<T>;
|
|
63
|
-
using nullopt_t = std::nullopt_t;
|
|
64
|
-
using std::nullopt;
|
|
65
81
|
using ScalarType = at::ScalarType;
|
|
66
82
|
using Scalar = c10::Scalar;
|
|
67
83
|
using MemoryFormat = c10::MemoryFormat;
|
|
@@ -91,16 +107,23 @@ inline ssize_t compute_numel(const SizesType *sizes, ssize_t dim) {
|
|
|
91
107
|
c10::multiply_integers(c10::ArrayRef<SizesType>(sizes, dim)));
|
|
92
108
|
}
|
|
93
109
|
|
|
110
|
+
#undef ET_PRI_TENSOR_SIZE
|
|
111
|
+
#define ET_PRI_TENSOR_SIZE PRId64
|
|
112
|
+
|
|
113
|
+
#undef ET_PRI_TENSOR_DIM
|
|
114
|
+
#define ET_PRI_TENSOR_DIM PRId64
|
|
115
|
+
|
|
116
|
+
#undef ET_PRI_TENSOR_NUMEL
|
|
117
|
+
#define ET_PRI_TENSOR_NUMEL PRId64
|
|
118
|
+
|
|
119
|
+
#undef ET_PRI_SIZES_AND_STRIDES
|
|
120
|
+
#define ET_PRI_SIZES_AND_STRIDES PRId64
|
|
121
|
+
|
|
94
122
|
#else // Use executor types
|
|
95
123
|
|
|
96
124
|
using Tensor = torch::executor::Tensor;
|
|
97
125
|
using TensorImpl = torch::executor::TensorImpl;
|
|
98
|
-
using string_view = torch::executor::string_view;
|
|
99
126
|
template <typename T> using ArrayRef = torch::executor::ArrayRef<T>;
|
|
100
|
-
template <typename T> using optional = torch::executor::optional<T>;
|
|
101
|
-
using nullopt_t = torch::executor::nullopt_t;
|
|
102
|
-
// NOLINTNEXTLINE(facebook-hte-NamespaceScopedStaticDeclaration)
|
|
103
|
-
using std::nullopt;
|
|
104
127
|
using ScalarType = torch::executor::ScalarType;
|
|
105
128
|
using TensorList = ArrayRef<Tensor>;
|
|
106
129
|
using Scalar = torch::executor::Scalar;
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
#include <cstdio>
|
|
14
14
|
#include <cstring>
|
|
15
15
|
|
|
16
|
+
#include <c10/util/irange.h>
|
|
16
17
|
#include <executorch/runtime/core/error.h>
|
|
17
18
|
#include <executorch/runtime/platform/assert.h>
|
|
18
19
|
#include <executorch/runtime/platform/compiler.h>
|
|
@@ -23,7 +24,7 @@ namespace runtime {
|
|
|
23
24
|
namespace {
|
|
24
25
|
template <typename DimOrderType>
|
|
25
26
|
bool validate_dim_order(const DimOrderType *dim_order, const size_t dims) {
|
|
26
|
-
for (
|
|
27
|
+
for (const auto i : c10::irange(dims)) {
|
|
27
28
|
if (dim_order[i] >= static_cast<DimOrderType>(dims)) {
|
|
28
29
|
return false;
|
|
29
30
|
}
|
|
@@ -42,7 +43,7 @@ bool validate_dim_order(const DimOrderType *dim_order, const size_t dims) {
|
|
|
42
43
|
template <typename DimOrderType>
|
|
43
44
|
inline bool is_contiguous_dim_order(const DimOrderType *dim_order,
|
|
44
45
|
const size_t dims) {
|
|
45
|
-
for (
|
|
46
|
+
for (const auto i : c10::irange(dims)) {
|
|
46
47
|
if (dim_order[i] != static_cast<DimOrderType>(i)) {
|
|
47
48
|
return false;
|
|
48
49
|
}
|