react-native-executorch 0.5.6 → 0.5.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (139) hide show
  1. package/android/libs/classes.jar +0 -0
  2. package/android/src/main/cpp/CMakeLists.txt +23 -14
  3. package/common/rnexecutorch/RnExecutorchInstaller.cpp +4 -21
  4. package/common/rnexecutorch/host_objects/ModelHostObject.h +67 -51
  5. package/common/rnexecutorch/models/llm/LLM.cpp +24 -1
  6. package/common/rnexecutorch/models/llm/LLM.h +4 -1
  7. package/common/rnexecutorch/threads/GlobalThreadPool.h +79 -0
  8. package/common/rnexecutorch/threads/HighPerformanceThreadPool.h +364 -0
  9. package/common/rnexecutorch/threads/utils/ThreadUtils.h +29 -0
  10. package/common/runner/runner.cpp +9 -3
  11. package/common/runner/runner.h +4 -3
  12. package/common/runner/text_token_generator.h +28 -10
  13. package/lib/module/controllers/LLMController.js +21 -2
  14. package/lib/module/controllers/LLMController.js.map +1 -1
  15. package/lib/module/hooks/natural_language_processing/useLLM.js +6 -2
  16. package/lib/module/hooks/natural_language_processing/useLLM.js.map +1 -1
  17. package/lib/module/modules/natural_language_processing/LLMModule.js +4 -2
  18. package/lib/module/modules/natural_language_processing/LLMModule.js.map +1 -1
  19. package/lib/module/types/llm.js.map +1 -1
  20. package/lib/typescript/controllers/LLMController.d.ts +4 -2
  21. package/lib/typescript/controllers/LLMController.d.ts.map +1 -1
  22. package/lib/typescript/hooks/natural_language_processing/useLLM.d.ts.map +1 -1
  23. package/lib/typescript/modules/natural_language_processing/LLMModule.d.ts +3 -2
  24. package/lib/typescript/modules/natural_language_processing/LLMModule.d.ts.map +1 -1
  25. package/lib/typescript/types/llm.d.ts +7 -1
  26. package/lib/typescript/types/llm.d.ts.map +1 -1
  27. package/package.json +3 -1
  28. package/react-native-executorch.podspec +12 -31
  29. package/src/controllers/LLMController.ts +29 -5
  30. package/src/hooks/natural_language_processing/useLLM.ts +15 -1
  31. package/src/modules/natural_language_processing/LLMModule.ts +10 -2
  32. package/src/types/llm.ts +8 -0
  33. package/third-party/android/libs/cpuinfo/arm64-v8a/libcpuinfo.so +0 -0
  34. package/third-party/android/libs/executorch/arm64-v8a/libexecutorch.so +0 -0
  35. package/third-party/android/libs/executorch/x86_64/libexecutorch.so +0 -0
  36. package/third-party/android/libs/pthreadpool/arm64-v8a/libpthreadpool.so +0 -0
  37. package/third-party/android/libs/tokenizers-cpp/arm64-v8a/libsentencepiece.a +0 -0
  38. package/third-party/android/libs/tokenizers-cpp/arm64-v8a/libtokenizers_c.a +0 -0
  39. package/third-party/android/libs/tokenizers-cpp/arm64-v8a/libtokenizers_cpp.a +0 -0
  40. package/third-party/android/libs/tokenizers-cpp/x86_64/libsentencepiece.a +0 -0
  41. package/third-party/android/libs/tokenizers-cpp/x86_64/libtokenizers_c.a +0 -0
  42. package/third-party/android/libs/tokenizers-cpp/x86_64/libtokenizers_cpp.a +0 -0
  43. package/third-party/include/c10/macros/Export.h +2 -86
  44. package/third-party/include/c10/macros/Macros.h +28 -5
  45. package/third-party/include/c10/util/BFloat16-inl.h +1 -4
  46. package/third-party/include/c10/util/BFloat16.h +5 -8
  47. package/third-party/include/c10/util/Half.h +5 -0
  48. package/third-party/include/c10/util/bit_cast.h +1 -1
  49. package/third-party/include/c10/util/complex.h +639 -0
  50. package/third-party/include/c10/util/complex_math.h +399 -0
  51. package/third-party/include/c10/util/complex_utils.h +41 -0
  52. package/third-party/include/c10/util/irange.h +2 -2
  53. package/third-party/include/c10/util/overflows.h +95 -0
  54. package/third-party/include/executorch/ExecuTorchError.h +75 -0
  55. package/third-party/include/executorch/ExecuTorchModule.h +115 -11
  56. package/third-party/include/executorch/ExecuTorchTensor.h +731 -51
  57. package/third-party/include/executorch/ExecuTorchValue.h +61 -9
  58. package/third-party/include/executorch/extension/kernel_util/make_boxed_from_unboxed_functor.h +181 -0
  59. package/third-party/include/executorch/extension/kernel_util/meta_programming.h +108 -0
  60. package/third-party/include/executorch/extension/kernel_util/type_list.h +137 -0
  61. package/third-party/include/executorch/extension/module/bundled_module.h +131 -0
  62. package/third-party/include/executorch/extension/module/module.h +46 -20
  63. package/third-party/include/executorch/extension/threadpool/cpuinfo_utils.h +1 -3
  64. package/third-party/include/executorch/extension/threadpool/threadpool.h +1 -3
  65. package/third-party/include/executorch/extension/threadpool/threadpool_guard.h +35 -0
  66. package/third-party/include/executorch/runtime/backend/backend_execution_context.h +3 -3
  67. package/third-party/include/executorch/runtime/backend/backend_init_context.h +12 -6
  68. package/third-party/include/executorch/runtime/backend/backend_option_context.h +34 -0
  69. package/third-party/include/executorch/runtime/backend/interface.h +70 -9
  70. package/third-party/include/executorch/runtime/backend/options.h +206 -0
  71. package/third-party/include/executorch/runtime/core/evalue.h +19 -25
  72. package/third-party/include/executorch/runtime/core/event_tracer.h +32 -17
  73. package/third-party/include/executorch/runtime/core/event_tracer_hooks.h +23 -14
  74. package/third-party/include/executorch/runtime/core/exec_aten/exec_aten.h +32 -9
  75. package/third-party/include/executorch/runtime/core/exec_aten/util/dim_order_util.h +3 -2
  76. package/third-party/include/executorch/runtime/core/exec_aten/util/scalar_type_util.h +43 -75
  77. package/third-party/include/executorch/runtime/core/exec_aten/util/tensor_util.h +88 -87
  78. package/third-party/include/executorch/runtime/core/function_ref.h +100 -0
  79. package/third-party/include/executorch/runtime/core/named_data_map.h +14 -14
  80. package/third-party/include/executorch/runtime/core/portable_type/c10/c10/macros/Export.h +2 -86
  81. package/third-party/include/executorch/runtime/core/portable_type/c10/c10/macros/Macros.h +28 -5
  82. package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/BFloat16-inl.h +1 -4
  83. package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/BFloat16.h +5 -8
  84. package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/Half.h +5 -0
  85. package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/bit_cast.h +1 -1
  86. package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/complex.h +639 -0
  87. package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/complex_math.h +399 -0
  88. package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/complex_utils.h +41 -0
  89. package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/irange.h +2 -2
  90. package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/overflows.h +95 -0
  91. package/third-party/include/executorch/runtime/core/portable_type/c10/torch/headeronly/macros/Export.h +88 -0
  92. package/third-party/include/executorch/runtime/core/portable_type/complex.h +6 -29
  93. package/third-party/include/executorch/runtime/core/portable_type/tensor_impl.h +20 -0
  94. package/third-party/include/executorch/runtime/core/span.h +4 -0
  95. package/third-party/include/executorch/runtime/core/tag.h +19 -0
  96. package/third-party/include/executorch/runtime/core/tensor_layout.h +2 -2
  97. package/third-party/include/executorch/runtime/executor/method.h +15 -3
  98. package/third-party/include/executorch/runtime/executor/method_meta.h +34 -5
  99. package/third-party/include/executorch/runtime/executor/program.h +3 -4
  100. package/third-party/include/executorch/runtime/executor/pte_data_map.h +9 -8
  101. package/third-party/include/executorch/runtime/executor/tensor_parser.h +14 -13
  102. package/third-party/include/executorch/runtime/kernel/kernel_runtime_context.h +5 -5
  103. package/third-party/include/executorch/runtime/kernel/operator_registry.h +21 -19
  104. package/third-party/include/executorch/runtime/platform/compiler.h +8 -0
  105. package/third-party/include/executorch/runtime/platform/platform.h +126 -0
  106. package/third-party/include/headeronly/macros/Export.h +88 -0
  107. package/third-party/include/tokenizers-cpp/tokenizers_c.h +61 -0
  108. package/third-party/include/torch/headeronly/macros/Export.h +88 -0
  109. package/third-party/ios/ExecutorchLib.xcframework/Info.plist +43 -0
  110. package/third-party/ios/ExecutorchLib.xcframework/ios-arm64/ExecutorchLib.framework/ExecutorchLib +0 -0
  111. package/third-party/ios/ExecutorchLib.xcframework/ios-arm64/ExecutorchLib.framework/Info.plist +0 -0
  112. package/third-party/ios/ExecutorchLib.xcframework/ios-arm64-simulator/ExecutorchLib.framework/ExecutorchLib +0 -0
  113. package/third-party/ios/ExecutorchLib.xcframework/ios-arm64-simulator/ExecutorchLib.framework/Info.plist +0 -0
  114. package/third-party/ios/libs/cpuinfo/libcpuinfo.a +0 -0
  115. package/third-party/ios/libs/pthreadpool/physical-arm64-release/libpthreadpool.a +0 -0
  116. package/third-party/ios/libs/pthreadpool/simulator-arm64-debug/libpthreadpool.a +0 -0
  117. package/ios/libs/executorch/libbackend_coreml_ios.a +0 -0
  118. package/ios/libs/executorch/libbackend_coreml_simulator.a +0 -0
  119. package/ios/libs/executorch/libbackend_mps_ios.a +0 -0
  120. package/ios/libs/executorch/libbackend_mps_simulator.a +0 -0
  121. package/ios/libs/executorch/libbackend_xnnpack_ios.a +0 -0
  122. package/ios/libs/executorch/libbackend_xnnpack_simulator.a +0 -0
  123. package/ios/libs/executorch/libexecutorch_ios.a +0 -0
  124. package/ios/libs/executorch/libexecutorch_simulator.a +0 -0
  125. package/ios/libs/executorch/libkernels_custom_ios.a +0 -0
  126. package/ios/libs/executorch/libkernels_custom_simulator.a +0 -0
  127. package/ios/libs/executorch/libkernels_optimized_ios.a +0 -0
  128. package/ios/libs/executorch/libkernels_optimized_simulator.a +0 -0
  129. package/ios/libs/executorch/libkernels_portable_ios.a +0 -0
  130. package/ios/libs/executorch/libkernels_portable_simulator.a +0 -0
  131. package/ios/libs/executorch/libkernels_quantized_ios.a +0 -0
  132. package/ios/libs/executorch/libkernels_quantized_simulator.a +0 -0
  133. package/third-party/ios/ios.toolchain.cmake +0 -1122
  134. /package/{ios → third-party/ios}/libs/tokenizers-cpp/physical-arm64-release/libsentencepiece.a +0 -0
  135. /package/{ios → third-party/ios}/libs/tokenizers-cpp/physical-arm64-release/libtokenizers_c.a +0 -0
  136. /package/{ios → third-party/ios}/libs/tokenizers-cpp/physical-arm64-release/libtokenizers_cpp.a +0 -0
  137. /package/{ios → third-party/ios}/libs/tokenizers-cpp/simulator-arm64-debug/libsentencepiece.a +0 -0
  138. /package/{ios → third-party/ios}/libs/tokenizers-cpp/simulator-arm64-debug/libtokenizers_c.a +0 -0
  139. /package/{ios → third-party/ios}/libs/tokenizers-cpp/simulator-arm64-debug/libtokenizers_cpp.a +0 -0
@@ -247,6 +247,26 @@ ssize_t compute_numel(
247
247
  const ::executorch::runtime::etensor::TensorImpl::SizesType *sizes,
248
248
  ssize_t dim);
249
249
 
250
+ /// Appropriate format specifier for the result of calling
251
+ /// size(). Must be used instead of using zd directly to support ATen
252
+ /// mode.
253
+ #define ET_PRI_TENSOR_SIZE "zd"
254
+
255
+ /// Appropriate format specifier for the result of calling
256
+ /// dim(). Must be used instead of using zd directly to support ATen
257
+ /// mode.
258
+ #define ET_PRI_TENSOR_DIM "zd"
259
+
260
+ /// Appropriate format specifier for the result of calling
261
+ /// numel(). Must be used instead of using zd directly to support ATen
262
+ /// mode.
263
+ #define ET_PRI_TENSOR_NUMEL "zd"
264
+
265
+ // Appropriate format specifier for elements of sizes() and
266
+ // strides(). Must be used instead of using d directly to support ATen
267
+ // mode.
268
+ #define ET_PRI_SIZES_AND_STRIDES "d"
269
+
250
270
  } // namespace etensor
251
271
  } // namespace runtime
252
272
  } // namespace executorch
@@ -54,6 +54,10 @@ public:
54
54
  template <size_t N>
55
55
  /* implicit */ constexpr Span(T (&Arr)[N]) : data_(Arr), length_(N) {}
56
56
 
57
+ /// Construct a Span from a single element reference.
58
+ /* implicit */ constexpr Span(T &single_element)
59
+ : data_(&single_element), length_(1) {}
60
+
57
61
  /// @returns a pointer to the start of the underlying element buffer.
58
62
  iterator begin() const noexcept { return data_; }
59
63
 
@@ -12,6 +12,11 @@
12
12
  #include <executorch/runtime/core/defines.h>
13
13
  #include <executorch/runtime/platform/compiler.h>
14
14
 
15
+ // X11 headers via volk define None, so we need to undef it
16
+ #if defined(__linux__)
17
+ #undef None
18
+ #endif
19
+
15
20
  namespace executorch {
16
21
  namespace runtime {
17
22
 
@@ -38,6 +43,20 @@ enum class Tag : uint32_t {
38
43
  #undef DEFINE_TAG
39
44
  };
40
45
 
46
+ #if ET_ENABLE_ENUM_STRINGS
47
+ inline const char *tag_to_string(Tag tag) {
48
+ switch (tag) {
49
+ #define CASE_TAG(x) \
50
+ case Tag::x: \
51
+ return #x;
52
+ EXECUTORCH_FORALL_TAGS(CASE_TAG)
53
+ #undef CASE_TAG
54
+ default:
55
+ return "Unknown";
56
+ }
57
+ }
58
+ #endif // ET_ENABLE_ENUM_STRINGS
59
+
41
60
  /**
42
61
  * Convert a tag value to a string representation. If ET_ENABLE_ENUM_STRINGS is
43
62
  * set (it is on by default), this will return a string name (for example,
@@ -14,7 +14,7 @@
14
14
  #include <executorch/runtime/core/span.h>
15
15
 
16
16
  namespace executorch {
17
- namespace runtime {
17
+ namespace ET_RUNTIME_NAMESPACE {
18
18
 
19
19
  /**
20
20
  * Describes the layout of a tensor.
@@ -75,5 +75,5 @@ private:
75
75
  const size_t nbytes_;
76
76
  };
77
77
 
78
- } // namespace runtime
78
+ } // namespace ET_RUNTIME_NAMESPACE
79
79
  } // namespace executorch
@@ -32,7 +32,7 @@ struct EValue;
32
32
  } // namespace executorch_flatbuffer
33
33
 
34
34
  namespace executorch {
35
- namespace runtime {
35
+ namespace ET_RUNTIME_NAMESPACE {
36
36
 
37
37
  // Forward declare NamedData. This is a public header and must not include
38
38
  // internal data types.
@@ -187,6 +187,18 @@ public:
187
187
  */
188
188
  ET_NODISCARD Error get_inputs(EValue *input_evalues, size_t length);
189
189
 
190
+ /**
191
+ *
192
+ * Retrieves the attribute tensor associated with the given name.
193
+ *
194
+ * @param[in] name The name of the attribute tensor to retrieve.
195
+ *
196
+ * @returns Result containing the attribute tensor on success, non-Ok on
197
+ * failure.
198
+ */
199
+ ET_NODISCARD Result<executorch::aten::Tensor>
200
+ get_attribute(std::string_view name);
201
+
190
202
  /**
191
203
  * Execute the method.
192
204
  *
@@ -371,14 +383,14 @@ private:
371
383
  void log_outputs();
372
384
  };
373
385
 
374
- } // namespace runtime
386
+ } // namespace ET_RUNTIME_NAMESPACE
375
387
  } // namespace executorch
376
388
 
377
389
  namespace torch {
378
390
  namespace executor {
379
391
  // TODO(T197294990): Remove these deprecated aliases once all users have moved
380
392
  // to the new `::executorch` namespaces.
381
- using ::executorch::runtime::Method;
393
+ using ::executorch::ET_RUNTIME_NAMESPACE::Method;
382
394
  } // namespace executor
383
395
  } // namespace torch
384
396
 
@@ -20,7 +20,11 @@ struct ExecutionPlan;
20
20
  } // namespace executorch_flatbuffer
21
21
 
22
22
  namespace executorch {
23
- namespace runtime {
23
+ namespace ET_RUNTIME_NAMESPACE {
24
+ namespace testing {
25
+ // Provides test access to private Program methods.
26
+ class TensorInfoTestFriend;
27
+ } // namespace testing
24
28
 
25
29
  /**
26
30
  * Metadata about a specific tensor of an ExecuTorch Program.
@@ -62,13 +66,20 @@ public:
62
66
  */
63
67
  size_t nbytes() const;
64
68
 
69
+ /**
70
+ * Returns the fully qualified name of the Tensor might be empty if the tensor
71
+ * is nameless.
72
+ */
73
+ std::string_view name() const;
74
+
65
75
  private:
66
76
  // Let MethodMeta create TensorInfo.
67
77
  friend class MethodMeta;
78
+ friend class testing::TensorInfoTestFriend;
68
79
 
69
80
  TensorInfo(Span<const int32_t> sizes, Span<const uint8_t> dim_order,
70
81
  executorch::aten::ScalarType scalar_type,
71
- const bool is_memory_planned);
82
+ const bool is_memory_planned, std::string_view name);
72
83
 
73
84
  /**
74
85
  * The sizes of the tensor.
@@ -86,6 +97,9 @@ private:
86
97
  */
87
98
  Span<const uint8_t> dim_order_;
88
99
 
100
+ /// The fully qualified name of the Tensor.
101
+ std::string_view name_;
102
+
89
103
  /// The scalar type of the tensor.
90
104
  executorch::aten::ScalarType scalar_type_;
91
105
 
@@ -168,6 +182,21 @@ public:
168
182
  */
169
183
  Result<TensorInfo> output_tensor_meta(size_t index) const;
170
184
 
185
+ /**
186
+ * Get the number of attribute tensors in this method.
187
+ *
188
+ * @returns The number of attribute tensors.
189
+ */
190
+ size_t num_attributes() const;
191
+
192
+ /**
193
+ * Get metadata about the specified attribute tensor.
194
+ *
195
+ * @param[in] index The index of the attribute tensor to look up.
196
+ * @returns The metadata on success, or an error on failure.
197
+ */
198
+ Result<TensorInfo> attribute_tensor_meta(size_t index) const;
199
+
171
200
  /**
172
201
  * Get the number of memory-planned buffers this method requires.
173
202
  *
@@ -238,14 +267,14 @@ private:
238
267
  const executorch_flatbuffer::ExecutionPlan *s_plan_;
239
268
  };
240
269
 
241
- } // namespace runtime
270
+ } // namespace ET_RUNTIME_NAMESPACE
242
271
  } // namespace executorch
243
272
 
244
273
  namespace torch {
245
274
  namespace executor {
246
275
  // TODO(T197294990): Remove these deprecated aliases once all users have moved
247
276
  // to the new `::executorch` namespaces.
248
- using ::executorch::runtime::MethodMeta;
249
- using ::executorch::runtime::TensorInfo;
277
+ using ::executorch::ET_RUNTIME_NAMESPACE::MethodMeta;
278
+ using ::executorch::ET_RUNTIME_NAMESPACE::TensorInfo;
250
279
  } // namespace executor
251
280
  } // namespace torch
@@ -36,8 +36,7 @@ struct Program;
36
36
  } // namespace executorch_flatbuffer
37
37
 
38
38
  namespace executorch {
39
- namespace runtime {
40
-
39
+ namespace ET_RUNTIME_NAMESPACE {
41
40
  namespace testing {
42
41
  // Provides test access to private Program methods.
43
42
  class ProgramTestFriend;
@@ -304,14 +303,14 @@ private:
304
303
  std::optional<internal::PteDataMap> pte_data_map_;
305
304
  };
306
305
 
307
- } // namespace runtime
306
+ } // namespace ET_RUNTIME_NAMESPACE
308
307
  } // namespace executorch
309
308
 
310
309
  namespace torch {
311
310
  namespace executor {
312
311
  // TODO(T197294990): Remove these deprecated aliases once all users have moved
313
312
  // to the new `::executorch` namespaces.
314
- using ::executorch::runtime::Program;
313
+ using ::executorch::ET_RUNTIME_NAMESPACE::Program;
315
314
  } // namespace executor
316
315
  } // namespace torch
317
316
 
@@ -45,7 +45,7 @@ using FlatbufferDataSegment =
45
45
  #endif
46
46
 
47
47
  namespace executorch {
48
- namespace runtime {
48
+ namespace ET_RUNTIME_NAMESPACE {
49
49
  namespace internal {
50
50
 
51
51
  /**
@@ -76,8 +76,8 @@ public:
76
76
  * tensor-specific metadata.
77
77
  */
78
78
  ET_NODISCARD
79
- Result<const TensorLayout>
80
- get_metadata(ET_UNUSED const char *key) const override {
79
+ Result<const TensorLayout> get_tensor_layout(
80
+ ET_UNUSED executorch::aten::string_view key) const override {
81
81
  return Error::NotImplemented;
82
82
  }
83
83
 
@@ -89,12 +89,13 @@ public:
89
89
  * @return error if the key is not present or data cannot be loaded.
90
90
  */
91
91
  ET_NODISCARD
92
- Result<FreeableBuffer> get_data(const char *key) const override;
92
+ Result<FreeableBuffer>
93
+ get_data(executorch::aten::string_view key) const override;
93
94
 
94
95
  /**
95
96
  * The PteDataMap currently does not implement load_into.
96
97
  */
97
- ET_NODISCARD Error load_data_into(ET_UNUSED const char *key,
98
+ ET_NODISCARD Error load_data_into(ET_UNUSED executorch::aten::string_view key,
98
99
  ET_UNUSED void *buffer,
99
100
  ET_UNUSED size_t size) const override {
100
101
  return Error::NotImplemented;
@@ -103,12 +104,12 @@ public:
103
104
  /**
104
105
  * @returns The number of keys in the map.
105
106
  */
106
- ET_NODISCARD Result<size_t> get_num_keys() const override;
107
+ ET_NODISCARD Result<uint32_t> get_num_keys() const override;
107
108
 
108
109
  /**
109
110
  * @returns The key at the specified index, error if index out of bounds.
110
111
  */
111
- ET_NODISCARD Result<const char *> get_key(size_t index) const override;
112
+ ET_NODISCARD Result<const char *> get_key(uint32_t index) const override;
112
113
 
113
114
  // Moveable, to be compatible with Result.
114
115
  PteDataMap(PteDataMap &&) noexcept = default;
@@ -140,5 +141,5 @@ private:
140
141
  };
141
142
 
142
143
  } // namespace internal
143
- } // namespace runtime
144
+ } // namespace ET_RUNTIME_NAMESPACE
144
145
  } // namespace executorch
@@ -21,7 +21,7 @@
21
21
  #include <executorch/schema/program_generated.h>
22
22
 
23
23
  namespace executorch {
24
- namespace runtime {
24
+ namespace ET_RUNTIME_NAMESPACE {
25
25
  namespace deserialization {
26
26
 
27
27
  /// Data structure to hold key and data buffer for external data used
@@ -54,7 +54,7 @@ validateTensorLayout(const executorch_flatbuffer::Tensor *s_tensor,
54
54
  // list of optionals: list of optional Tensor, list of optional float etc, so we
55
55
  // just use a template to avoid boilerplate.
56
56
  template <typename T>
57
- ET_NODISCARD Result<BoxedEvalueList<executorch::aten::optional<T>>>
57
+ ET_NODISCARD Result<BoxedEvalueList<std::optional<T>>>
58
58
  parseListOptionalType(const flatbuffers::Vector<int32_t> *value_indices,
59
59
  EValue *values, size_t values_len,
60
60
  MemoryManager *memory_manager) {
@@ -65,8 +65,8 @@ parseListOptionalType(const flatbuffers::Vector<int32_t> *value_indices,
65
65
  }
66
66
 
67
67
  auto *optional_tensor_list =
68
- memory_manager->method_allocator()
69
- ->allocateList<executorch::aten::optional<T>>(value_indices->size());
68
+ memory_manager->method_allocator()->allocateList<std::optional<T>>(
69
+ value_indices->size());
70
70
  if (optional_tensor_list == nullptr) {
71
71
  return Error::MemoryAllocationFailed;
72
72
  }
@@ -83,7 +83,7 @@ parseListOptionalType(const flatbuffers::Vector<int32_t> *value_indices,
83
83
  // copy assignment is not defined if its non trivial.
84
84
  if (index == -1) {
85
85
  new (&optional_tensor_list[output_idx])
86
- executorch::aten::optional<T>(executorch::aten::nullopt);
86
+ std::optional<T>(executorch::aten::nullopt);
87
87
  // no value to point to. BoxedEvalueList for optional tensor will convert
88
88
  // this to nullopt.
89
89
  // TODO(T161156879): do something less hacky here.
@@ -93,13 +93,13 @@ parseListOptionalType(const flatbuffers::Vector<int32_t> *value_indices,
93
93
  index >= 0 && static_cast<size_t>(index) < values_len, InvalidProgram,
94
94
  "Invalid value index %" PRId32 " for ListOptional", index);
95
95
  new (&optional_tensor_list[output_idx])
96
- executorch::aten::optional<T>(values[index].toOptional<T>());
96
+ std::optional<T>(values[index].toOptional<T>());
97
97
  evalp_list[output_idx] = &values[static_cast<size_t>(index)];
98
98
  }
99
99
  output_idx++;
100
100
  }
101
- return BoxedEvalueList<executorch::aten::optional<T>>(
102
- evalp_list, optional_tensor_list, value_indices->size());
101
+ return BoxedEvalueList<std::optional<T>>(evalp_list, optional_tensor_list,
102
+ value_indices->size());
103
103
  }
104
104
 
105
105
  /**
@@ -135,7 +135,7 @@ getTensorDataPtr(const executorch_flatbuffer::Tensor *s_tensor,
135
135
  Span<NamedData> external_constants = {});
136
136
 
137
137
  } // namespace deserialization
138
- } // namespace runtime
138
+ } // namespace ET_RUNTIME_NAMESPACE
139
139
  } // namespace executorch
140
140
 
141
141
  namespace torch {
@@ -143,10 +143,11 @@ namespace executor {
143
143
  namespace deserialization {
144
144
  // TODO(T197294990): Remove these deprecated aliases once all users have moved
145
145
  // to the new `::executorch` namespaces.
146
- using ::executorch::runtime::deserialization::getTensorDataPtr;
147
- using ::executorch::runtime::deserialization::parseListOptionalType;
148
- using ::executorch::runtime::deserialization::parseTensor;
149
- using ::executorch::runtime::deserialization::parseTensorList;
146
+ using ::executorch::ET_RUNTIME_NAMESPACE::deserialization::getTensorDataPtr;
147
+ using ::executorch::ET_RUNTIME_NAMESPACE::deserialization::
148
+ parseListOptionalType;
149
+ using ::executorch::ET_RUNTIME_NAMESPACE::deserialization::parseTensor;
150
+ using ::executorch::ET_RUNTIME_NAMESPACE::deserialization::parseTensorList;
150
151
  } // namespace deserialization
151
152
  } // namespace executor
152
153
  } // namespace torch
@@ -15,7 +15,7 @@
15
15
  #include <executorch/runtime/platform/compiler.h>
16
16
 
17
17
  namespace executorch {
18
- namespace runtime {
18
+ namespace ET_RUNTIME_NAMESPACE {
19
19
 
20
20
  /**
21
21
  * Runtime state and functionality for kernel implementations.
@@ -98,7 +98,7 @@ private:
98
98
  Error failure_state_ = Error::Ok;
99
99
  };
100
100
 
101
- } // namespace runtime
101
+ } // namespace ET_RUNTIME_NAMESPACE
102
102
  } // namespace executorch
103
103
 
104
104
  // TODO(T197294990): Remove these deprecated aliases once all users have moved
@@ -106,15 +106,15 @@ private:
106
106
  namespace torch {
107
107
  namespace executor {
108
108
  /// DEPRECATED: Use ::executorch::runtime::KernelRuntimeContext instead.
109
- using ::executorch::runtime::KernelRuntimeContext;
109
+ using ::executorch::ET_RUNTIME_NAMESPACE::KernelRuntimeContext;
110
110
  /// DEPRECATED: Use ::executorch::runtime::KernelRuntimeContext instead.
111
- using RuntimeContext = ::executorch::runtime::KernelRuntimeContext;
111
+ using RuntimeContext = ::executorch::ET_RUNTIME_NAMESPACE::KernelRuntimeContext;
112
112
  } // namespace executor
113
113
  } // namespace torch
114
114
  namespace executorch {
115
115
  namespace aten {
116
116
  /// DEPRECATED: Use ::executorch::runtime::KernelRuntimeContext instead.
117
- using RuntimeContext = ::executorch::runtime::KernelRuntimeContext;
117
+ using RuntimeContext = ::executorch::ET_RUNTIME_NAMESPACE::KernelRuntimeContext;
118
118
  } // namespace aten
119
119
  } // namespace executorch
120
120
  // DEPRECATED: The executorch::aten:: namespace is deprecated. Use
@@ -37,7 +37,7 @@
37
37
  }
38
38
 
39
39
  namespace executorch {
40
- namespace runtime {
40
+ namespace ET_RUNTIME_NAMESPACE {
41
41
 
42
42
  class KernelRuntimeContext; // Forward declaration
43
43
  using OpFunction = void (*)(KernelRuntimeContext &, EValue **);
@@ -117,7 +117,7 @@ public:
117
117
  * for all input tensor dtypes and dim orders if the specialized kernel is not
118
118
  * registered.
119
119
  */
120
- KernelKey() : is_fallback_(true) {}
120
+ KernelKey() = default;
121
121
 
122
122
  /**
123
123
  * Creates a specialized (non-fallback) kernel key that matches a specific
@@ -125,23 +125,23 @@ public:
125
125
  * expected format of `kernel_key_data`.
126
126
  */
127
127
  /* implicit */ KernelKey(const char *kernel_key_data)
128
- : kernel_key_data_(kernel_key_data), is_fallback_(false) {}
128
+ : kernel_key_data_(kernel_key_data) {}
129
129
 
130
130
  bool operator==(const KernelKey &other) const { return this->equals(other); }
131
131
 
132
132
  bool operator!=(const KernelKey &other) const { return !this->equals(other); }
133
133
 
134
134
  bool equals(const KernelKey &other) const {
135
- if (is_fallback_ != other.is_fallback_) {
135
+ if (is_fallback() != other.is_fallback()) {
136
136
  return false;
137
137
  }
138
- if (is_fallback_) {
138
+ if (is_fallback()) {
139
139
  return true;
140
140
  }
141
141
  return strcmp(kernel_key_data_, other.kernel_key_data_) == 0;
142
142
  }
143
143
 
144
- bool is_fallback() const { return is_fallback_; }
144
+ bool is_fallback() const { return kernel_key_data_ == nullptr; }
145
145
 
146
146
  const char *data() const { return kernel_key_data_; }
147
147
 
@@ -154,7 +154,6 @@ public:
154
154
 
155
155
  private:
156
156
  const char *kernel_key_data_ = nullptr;
157
- bool is_fallback_;
158
157
  };
159
158
 
160
159
  /**
@@ -241,37 +240,40 @@ ET_NODISCARD inline Error register_kernel(const Kernel &kernel) {
241
240
  return register_kernels({&kernel, 1});
242
241
  };
243
242
 
244
- } // namespace runtime
243
+ } // namespace ET_RUNTIME_NAMESPACE
245
244
  } // namespace executorch
246
245
 
247
246
  namespace torch {
248
247
  namespace executor {
249
248
  // TODO(T197294990): Remove these deprecated aliases once all users have moved
250
249
  // to the new `::executorch` namespaces.
251
- using ::executorch::runtime::Kernel;
252
- using ::executorch::runtime::KernelKey;
253
- using ::executorch::runtime::KernelRuntimeContext;
254
- using ::executorch::runtime::OpFunction;
255
- using ::executorch::runtime::TensorMeta;
256
- using KernelRuntimeContext = ::executorch::runtime::KernelRuntimeContext;
250
+ using ::executorch::ET_RUNTIME_NAMESPACE::Kernel;
251
+ using ::executorch::ET_RUNTIME_NAMESPACE::KernelKey;
252
+ using ::executorch::ET_RUNTIME_NAMESPACE::KernelRuntimeContext;
253
+ using ::executorch::ET_RUNTIME_NAMESPACE::OpFunction;
254
+ using ::executorch::ET_RUNTIME_NAMESPACE::TensorMeta;
255
+ using KernelRuntimeContext =
256
+ ::executorch::ET_RUNTIME_NAMESPACE::KernelRuntimeContext;
257
257
 
258
258
  inline ::executorch::runtime::Error register_kernels(ArrayRef<Kernel> kernels) {
259
- return ::executorch::runtime::register_kernels(
259
+ return ::executorch::ET_RUNTIME_NAMESPACE::register_kernels(
260
260
  {kernels.data(), kernels.size()});
261
261
  }
262
262
  inline OpFunction getOpsFn(const char *name,
263
263
  ArrayRef<TensorMeta> meta_list = {}) {
264
- auto result = ::executorch::runtime::get_op_function_from_registry(
265
- name, {meta_list.data(), meta_list.size()});
264
+ auto result =
265
+ ::executorch::ET_RUNTIME_NAMESPACE::get_op_function_from_registry(
266
+ name, {meta_list.data(), meta_list.size()});
266
267
  ET_CHECK(result.ok()); // get_op_function_from_registry() logs details.
267
268
  return *result;
268
269
  }
269
270
  inline bool hasOpsFn(const char *name, ArrayRef<TensorMeta> meta_list = {}) {
270
- return ::executorch::runtime::registry_has_op_function(
271
+ return ::executorch::ET_RUNTIME_NAMESPACE::registry_has_op_function(
271
272
  name, {meta_list.data(), meta_list.size()});
272
273
  }
273
274
  inline ArrayRef<Kernel> get_kernels() {
274
- Span<const Kernel> kernels = ::executorch::runtime::get_registered_kernels();
275
+ Span<const Kernel> kernels =
276
+ ::executorch::ET_RUNTIME_NAMESPACE::get_registered_kernels();
275
277
  return ArrayRef<Kernel>(kernels.data(), kernels.size());
276
278
  }
277
279
  } // namespace executor
@@ -171,6 +171,14 @@
171
171
  using ssize_t = ptrdiff_t;
172
172
  #endif
173
173
 
174
+ #ifdef __EXCEPTIONS
175
+ #define ET_HAS_EXCEPTIONS 1
176
+ #elif defined(_MSC_VER) && defined(_HAS_EXCEPTIONS) && _HAS_EXCEPTIONS
177
+ #define ET_HAS_EXCEPTIONS 1
178
+ #else
179
+ #define ET_HAS_EXCEPTIONS 0
180
+ #endif
181
+
174
182
  // DEPRECATED: Use the non-underscore-prefixed versions instead.
175
183
  // TODO(T199005537): Remove these once all users have stopped using them.
176
184
  #define __ET_DEPRECATED ET_DEPRECATED