From ae299cf917bad8923c0ee0fd02342ed608f25fad Mon Sep 17 00:00:00 2001 From: Dave Bort Date: Thu, 15 Aug 2024 15:17:40 -0700 Subject: [PATCH] [executorch] Migrate runtime/core to new namespace Differential Revision: D60428951 Pull Request resolved: https://github.com/pytorch/executorch/pull/4607 --- .../runtime/sdk/model_event_logger_impl.h | 6 +-- extension/evalue_util/print_evalue.cpp | 46 +++++++++++-------- extension/evalue_util/print_evalue.h | 19 ++++++-- runtime/core/array_ref.h | 14 +++++- runtime/core/data_loader.h | 12 ++++- runtime/core/error.h | 33 ++++++++----- runtime/core/evalue.cpp | 8 ++-- runtime/core/evalue.h | 35 ++++++++++---- runtime/core/event_tracer.h | 26 +++++++++-- runtime/core/event_tracer_hooks.h | 27 ++++++++++- runtime/core/event_tracer_hooks_delegate.h | 21 +++++++-- runtime/core/freeable_buffer.h | 12 ++++- runtime/core/hierarchical_allocator.h | 12 ++++- runtime/core/memory_allocator.h | 24 ++++++---- runtime/core/result.h | 12 ++++- runtime/core/span.h | 12 ++++- runtime/core/tag.h | 16 ++++++- runtime/core/tensor_shape_dynamism.h | 30 ++++++------ runtime/executor/method.h | 3 +- 19 files changed, 269 insertions(+), 99 deletions(-) diff --git a/backends/apple/coreml/runtime/sdk/model_event_logger_impl.h b/backends/apple/coreml/runtime/sdk/model_event_logger_impl.h index e88d9754ee..66140ad508 100644 --- a/backends/apple/coreml/runtime/sdk/model_event_logger_impl.h +++ b/backends/apple/coreml/runtime/sdk/model_event_logger_impl.h @@ -10,7 +10,7 @@ #import #import -namespace torch::executor { +namespace executorch::runtime { class EventTracer; } @@ -21,7 +21,7 @@ namespace executorchcoreml { class ModelEventLoggerImpl final : public ModelEventLogger { public: /// Construct a `ModelEventLoggerImpl` from the `EventTracer`. - explicit ModelEventLoggerImpl(torch::executor::EventTracer* tracer) : tracer_(tracer) { } + explicit ModelEventLoggerImpl(::executorch::runtime::EventTracer* tracer) : tracer_(tracer) { } /// Logs profiling infos. /// @@ -44,6 +44,6 @@ class ModelEventLoggerImpl final : public ModelEventLogger { NSDictionary* op_path_to_debug_symbol_name_map) const noexcept override; private: - torch::executor::EventTracer* tracer_; + ::executorch::runtime::EventTracer* tracer_; }; } // namespace executorchcoreml diff --git a/extension/evalue_util/print_evalue.cpp b/extension/evalue_util/print_evalue.cpp index 21180cf5d2..7d29b5780c 100644 --- a/extension/evalue_util/print_evalue.cpp +++ b/extension/evalue_util/print_evalue.cpp @@ -16,8 +16,10 @@ #include #include -namespace torch { -namespace executor { +using exec_aten::ScalarType; + +namespace executorch { +namespace extension { namespace { @@ -102,7 +104,7 @@ void print_scalar_list( // We've printed a full line, so wrap and begin a new one. os << "\n "; } - os << EValue(exec_aten::Scalar(list[i])); + os << executorch::runtime::EValue(exec_aten::Scalar(list[i])); if (wrapping || i < list.size() - 1) { // No trailing comma when not wrapping. Always a trailing comma when // wrapping. This will leave a trailing space at the end of every wrapped @@ -149,12 +151,13 @@ void print_tensor(std::ostream& os, exec_aten::Tensor tensor) { // // TODO(T159700776): Format multidimensional data like numpy/PyTorch does. // https://github.com/pytorch/pytorch/blob/main/torch/_tensor_str.py -#define PRINT_TENSOR_DATA(ctype, dtype) \ - case ScalarType::dtype: \ - print_scalar_list( \ - os, \ - ArrayRef(tensor.const_data_ptr(), tensor.numel()), \ - /*print_length=*/false); \ +#define PRINT_TENSOR_DATA(ctype, dtype) \ + case ScalarType::dtype: \ + print_scalar_list( \ + os, \ + exec_aten::ArrayRef( \ + tensor.const_data_ptr(), tensor.numel()), \ + /*print_length=*/false); \ break; switch (tensor.scalar_type()) { @@ -211,7 +214,20 @@ void print_list_optional_tensor( } // namespace +void evalue_edge_items::set_edge_items(std::ostream& os, long edge_items) { + os.iword(get_edge_items_xalloc()) = edge_items; +} + +} // namespace extension +} // namespace executorch + +namespace executorch { +namespace runtime { + +// This needs to live in the same namespace as EValue. std::ostream& operator<<(std::ostream& os, const EValue& value) { + using namespace executorch::extension; + switch (value.tag) { case Tag::None: os << "None"; @@ -258,13 +274,5 @@ std::ostream& operator<<(std::ostream& os, const EValue& value) { return os; } -namespace util { - -void evalue_edge_items::set_edge_items(std::ostream& os, long edge_items) { - os.iword(get_edge_items_xalloc()) = edge_items; -} - -} // namespace util - -} // namespace executor -} // namespace torch +} // namespace runtime +} // namespace executorch diff --git a/extension/evalue_util/print_evalue.h b/extension/evalue_util/print_evalue.h index 8b9494f354..e7e8ea1561 100644 --- a/extension/evalue_util/print_evalue.h +++ b/extension/evalue_util/print_evalue.h @@ -12,16 +12,18 @@ #include -namespace torch { -namespace executor { - +namespace executorch { +namespace runtime { /** * Prints an Evalue to a stream. */ std::ostream& operator<<(std::ostream& os, const EValue& value); // Note that this must be declared in the same namespace as EValue. +} // namespace runtime +} // namespace executorch -namespace util { +namespace executorch { +namespace extension { /** * Sets the number of "edge items" when printing EValue lists to a stream. @@ -67,6 +69,15 @@ class evalue_edge_items final { const long edge_items_; }; +} // namespace extension +} // namespace executorch + +namespace torch { +namespace executor { +namespace util { +// TODO(T197294990): Remove these deprecated aliases once all users have moved +// to the new `::executorch` namespaces. +using ::executorch::extension::evalue_edge_items; } // namespace util } // namespace executor } // namespace torch diff --git a/runtime/core/array_ref.h b/runtime/core/array_ref.h index 07e7bf65c0..463284d9c6 100644 --- a/runtime/core/array_ref.h +++ b/runtime/core/array_ref.h @@ -31,8 +31,8 @@ #include -namespace torch { -namespace executor { +namespace executorch { +namespace runtime { /** * Represents a constant reference to an array (0 or more elements @@ -236,5 +236,15 @@ bool operator!=(ArrayRef a1, ArrayRef a2) { using IntArrayRef = ArrayRef; +} // namespace runtime +} // namespace executorch + +namespace torch { +namespace executor { +// TODO(T197294990): Remove these deprecated aliases once all users have moved +// to the new `::executorch` namespaces. +using ::executorch::runtime::ArrayRef; +using ::executorch::runtime::IntArrayRef; +using ::executorch::runtime::makeArrayRef; } // namespace executor } // namespace torch diff --git a/runtime/core/data_loader.h b/runtime/core/data_loader.h index b987ef8f40..2a55993d53 100644 --- a/runtime/core/data_loader.h +++ b/runtime/core/data_loader.h @@ -14,8 +14,8 @@ #include #include -namespace torch { -namespace executor { +namespace executorch { +namespace runtime { /** * Loads from a data source. @@ -125,5 +125,13 @@ class DataLoader { __ET_NODISCARD virtual Result size() const = 0; }; +} // namespace runtime +} // namespace executorch + +namespace torch { +namespace executor { +// TODO(T197294990): Remove these deprecated aliases once all users have moved +// to the new `::executorch` namespaces. +using ::executorch::runtime::DataLoader; } // namespace executor } // namespace torch diff --git a/runtime/core/error.h b/runtime/core/error.h index 889e5804d5..4babb4d148 100644 --- a/runtime/core/error.h +++ b/runtime/core/error.h @@ -17,8 +17,8 @@ #include -namespace torch { -namespace executor { +namespace executorch { +namespace runtime { // Alias error code integral type to minimal platform width (32-bits for now). typedef uint32_t error_code_t; @@ -92,13 +92,22 @@ enum class Error : error_code_t { }; +} // namespace runtime +} // namespace executorch + +namespace torch { +namespace executor { +// TODO(T197294990): Remove these deprecated aliases once all users have moved +// to the new `::executorch` namespaces. +using ::executorch::runtime::Error; +using ::executorch::runtime::error_code_t; } // namespace executor } // namespace torch /** * If cond__ is false, log the specified message and return the specified Error * from the current function, which must be of return type - * torch::executor::Error. + * executorch::runtime::Error. * * @param[in] cond__ The condition to be checked, asserted as true. * @param[in] error__ Error enum value to return without the `Error::` prefix, @@ -110,14 +119,14 @@ enum class Error : error_code_t { { \ if (!(cond__)) { \ ET_LOG(Error, message__, ##__VA_ARGS__); \ - return ::torch::executor::Error::error__; \ + return ::executorch::runtime::Error::error__; \ } \ } /** * If error__ is not Error::Ok, optionally log a message and return the error * from the current function, which must be of return type - * torch::executor::Error. + * executorch::runtime::Error. * * @param[in] error__ Error enum value asserted to be Error::Ok. * @param[in] ... Optional format string for the log error message and its @@ -161,19 +170,19 @@ enum class Error : error_code_t { ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_##N // Internal only: Use ET_CHECK_OK_OR_RETURN_ERROR() instead. -#define ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_1(error__) \ - do { \ - const auto et_error__ = (error__); \ - if (et_error__ != ::torch::executor::Error::Ok) { \ - return et_error__; \ - } \ +#define ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_1(error__) \ + do { \ + const auto et_error__ = (error__); \ + if (et_error__ != ::executorch::runtime::Error::Ok) { \ + return et_error__; \ + } \ } while (0) // Internal only: Use ET_CHECK_OK_OR_RETURN_ERROR() instead. #define ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_2(error__, message__, ...) \ do { \ const auto et_error__ = (error__); \ - if (et_error__ != ::torch::executor::Error::Ok) { \ + if (et_error__ != ::executorch::runtime::Error::Ok) { \ ET_LOG(Error, message__, ##__VA_ARGS__); \ return et_error__; \ } \ diff --git a/runtime/core/evalue.cpp b/runtime/core/evalue.cpp index b3ff59eff1..adc3c7f47b 100644 --- a/runtime/core/evalue.cpp +++ b/runtime/core/evalue.cpp @@ -8,8 +8,8 @@ #include -namespace torch { -namespace executor { +namespace executorch { +namespace runtime { template <> exec_aten::ArrayRef> BoxedEvalueList>::get() const { @@ -27,5 +27,5 @@ BoxedEvalueList>::get() const { return exec_aten::ArrayRef>{ unwrapped_vals_, wrapped_vals_.size()}; } -} // namespace executor -} // namespace torch +} // namespace runtime +} // namespace executorch diff --git a/runtime/core/evalue.h b/runtime/core/evalue.h index 2b3029971e..8aee5f399d 100644 --- a/runtime/core/evalue.h +++ b/runtime/core/evalue.h @@ -11,11 +11,13 @@ #include #include -namespace torch { -namespace executor { +namespace executorch { +namespace runtime { struct EValue; +namespace internal { + // Tensor gets proper reference treatment because its expensive to copy in aten // mode, all other types are just copied. template @@ -38,6 +40,8 @@ struct evalue_to_ref_overload_return { using type = exec_aten::Tensor&; }; +} // namespace internal + /* * Helper class used to correlate EValues in the executor table, with the * unwrapped list of the proper type. Because values in the runtime's values @@ -371,9 +375,9 @@ struct EValue { template T to() &&; template - typename evalue_to_const_ref_overload_return::type to() const&; + typename internal::evalue_to_const_ref_overload_return::type to() const&; template - typename evalue_to_ref_overload_return::type to() &; + typename internal::evalue_to_ref_overload_return::type to() &; /** * Converts the EValue to an optional object that can represent both T and @@ -441,13 +445,19 @@ struct EValue { return static_cast(std::move(*this).method_name()); \ } \ template <> \ - inline evalue_to_const_ref_overload_return::type EValue::to() const& { \ - typedef evalue_to_const_ref_overload_return::type return_type; \ + inline ::executorch::runtime::internal::evalue_to_const_ref_overload_return< \ + T>::type \ + EValue::to() const& { \ + typedef ::executorch::runtime::internal:: \ + evalue_to_const_ref_overload_return::type return_type; \ return static_cast(this->method_name()); \ } \ template <> \ - inline evalue_to_ref_overload_return::type EValue::to()& { \ - typedef evalue_to_ref_overload_return::type return_type; \ + inline ::executorch::runtime::internal::evalue_to_ref_overload_return< \ + T>::type \ + EValue::to()& { \ + typedef ::executorch::runtime::internal::evalue_to_ref_overload_return< \ + T>::type return_type; \ return static_cast(this->method_name()); \ } @@ -507,5 +517,14 @@ exec_aten::ArrayRef BoxedEvalueList::get() const { return exec_aten::ArrayRef{unwrapped_vals_, wrapped_vals_.size()}; } +} // namespace runtime +} // namespace executorch + +namespace torch { +namespace executor { +// TODO(T197294990): Remove these deprecated aliases once all users have moved +// to the new `::executorch` namespaces. +using ::executorch::runtime::BoxedEvalueList; +using ::executorch::runtime::EValue; } // namespace executor } // namespace torch diff --git a/runtime/core/event_tracer.h b/runtime/core/event_tracer.h index 55549ddea5..eb8ee1fefc 100644 --- a/runtime/core/event_tracer.h +++ b/runtime/core/event_tracer.h @@ -14,8 +14,8 @@ #pragma once -namespace torch { -namespace executor { +namespace executorch { +namespace runtime { /// Represents an allocator id returned by track_allocator. typedef uint32_t AllocatorID; @@ -275,7 +275,7 @@ class EventTracer { virtual void log_intermediate_output_delegate( const char* name, DebugHandle delegate_debug_index, - const Tensor& output) = 0; + const exec_aten::Tensor& output) = 0; /** * Log an intermediate tensor array output from a delegate. @@ -295,7 +295,7 @@ class EventTracer { virtual void log_intermediate_output_delegate( const char* name, DebugHandle delegate_debug_index, - const ArrayRef output) = 0; + const ArrayRef output) = 0; /** * Log an intermediate int output from a delegate. @@ -460,5 +460,23 @@ class EventTracer { EventTracerDebugLogLevel::kNoLogging; }; +} // namespace runtime +} // namespace executorch + +namespace torch { +namespace executor { +// TODO(T197294990): Remove these deprecated aliases once all users have moved +// to the new `::executorch` namespaces. +using ::executorch::runtime::AllocatorID; +using ::executorch::runtime::ChainID; +using ::executorch::runtime::DebugHandle; +using ::executorch::runtime::DelegateDebugIdType; +using ::executorch::runtime::EventTracer; +using ::executorch::runtime::EventTracerDebugLogLevel; +using ::executorch::runtime::EventTracerEntry; +using ::executorch::runtime::kUnsetBundledInputIndex; +using ::executorch::runtime::kUnsetChainId; +using ::executorch::runtime::kUnsetDebugHandle; +using ::executorch::runtime::LoggedEValueType; } // namespace executor } // namespace torch diff --git a/runtime/core/event_tracer_hooks.h b/runtime/core/event_tracer_hooks.h index 48ba694e61..76fa17f62a 100644 --- a/runtime/core/event_tracer_hooks.h +++ b/runtime/core/event_tracer_hooks.h @@ -23,10 +23,14 @@ * The benefit of defining these hooks is that we can easily control whether or * not we want to compile in the EventTracer code based on the status of the * ET_EVENT_TRACER_ENABLED flag. + * + * TODO(dbort): Make this a private header of runtime/executor. It only contains + * runtime-internal functions and should not be part of the public set of + * headers. */ -namespace torch { -namespace executor { +namespace executorch { +namespace runtime { namespace internal { /** @@ -249,6 +253,25 @@ inline void event_tracer_set_bundled_input_index( #endif } +} // namespace internal +} // namespace runtime +} // namespace executorch + +namespace torch { +namespace executor { +namespace internal { +// TODO(T197294990): Remove these deprecated aliases once all users have moved +// to the new `::executorch` namespaces. +using ::executorch::runtime::internal::event_tracer_begin_profiling_event; +using ::executorch::runtime::internal::event_tracer_create_event_block; +using ::executorch::runtime::internal::event_tracer_end_profiling_event; +using ::executorch::runtime::internal::event_tracer_log_evalue; +using ::executorch::runtime::internal::event_tracer_log_evalue_output; +using ::executorch::runtime::internal::event_tracer_set_bundled_input_index; +using ::executorch::runtime::internal::event_tracer_track_allocation; +using ::executorch::runtime::internal::event_tracer_track_allocator; +using ::executorch::runtime::internal::EventTracerProfileInstructionScope; +using ::executorch::runtime::internal::EventTracerProfileScope; } // namespace internal } // namespace executor } // namespace torch diff --git a/runtime/core/event_tracer_hooks_delegate.h b/runtime/core/event_tracer_hooks_delegate.h index 0229460942..477187e002 100644 --- a/runtime/core/event_tracer_hooks_delegate.h +++ b/runtime/core/event_tracer_hooks_delegate.h @@ -27,8 +27,8 @@ * ET_EVENT_TRACER_ENABLED flag. */ -namespace torch { -namespace executor { +namespace executorch { +namespace runtime { /** * Start the profiling of a delegate event. Similar to start_profiling it will @@ -62,6 +62,7 @@ inline EventTracerEntry event_tracer_start_profiling_delegate( // There is no active tracer; this value will be ignored. return EventTracerEntry(); } + /** * Signal the end of the delegate profiling event contained in * event_tracer_entry. Users also have the option to log some some free-from @@ -174,8 +175,9 @@ inline void event_tracer_log_output_delegate( if (event_tracer) { static_assert( std::is_same::value || std::is_same::value || - std::is_same::value || std::is_same::value || - std::is_same>::value, + std::is_same::value || + std::is_same::value || + std::is_same>::value, "Unsupported type for intermediate output"); event_tracer->log_intermediate_output_delegate( name, delegate_debug_id, output); @@ -187,5 +189,16 @@ inline void event_tracer_log_output_delegate( #endif } +} // namespace runtime +} // namespace executorch + +namespace torch { +namespace executor { +// TODO(T197294990): Remove these deprecated aliases once all users have moved +// to the new `::executorch` namespaces. +using ::executorch::runtime::event_tracer_end_profiling_delegate; +using ::executorch::runtime::event_tracer_log_output_delegate; +using ::executorch::runtime::event_tracer_log_profiling_delegate; +using ::executorch::runtime::event_tracer_start_profiling_delegate; } // namespace executor } // namespace torch diff --git a/runtime/core/freeable_buffer.h b/runtime/core/freeable_buffer.h index cb68b3b627..a90c899103 100644 --- a/runtime/core/freeable_buffer.h +++ b/runtime/core/freeable_buffer.h @@ -10,8 +10,8 @@ #include -namespace torch { -namespace executor { +namespace executorch { +namespace runtime { /** * A read-only buffer than can be freed. @@ -110,5 +110,13 @@ class FreeableBuffer final { size_t size_; }; +} // namespace runtime +} // namespace executorch + +namespace torch { +namespace executor { +// TODO(T197294990): Remove these deprecated aliases once all users have moved +// to the new `::executorch` namespaces. +using ::executorch::runtime::FreeableBuffer; } // namespace executor } // namespace torch diff --git a/runtime/core/hierarchical_allocator.h b/runtime/core/hierarchical_allocator.h index 8e7c61439c..33545915b0 100644 --- a/runtime/core/hierarchical_allocator.h +++ b/runtime/core/hierarchical_allocator.h @@ -16,8 +16,8 @@ #include #include -namespace torch { -namespace executor { +namespace executorch { +namespace runtime { /** * A group of buffers that can be used to represent a device's memory hierarchy. @@ -105,5 +105,13 @@ class HierarchicalAllocator final { Span> buffers_; }; +} // namespace runtime +} // namespace executorch + +namespace torch { +namespace executor { +// TODO(T197294990): Remove these deprecated aliases once all users have moved +// to the new `::executorch` namespaces. +using ::executorch::runtime::HierarchicalAllocator; } // namespace executor } // namespace torch diff --git a/runtime/core/memory_allocator.h b/runtime/core/memory_allocator.h index a36d8750fe..054745f5af 100644 --- a/runtime/core/memory_allocator.h +++ b/runtime/core/memory_allocator.h @@ -18,8 +18,8 @@ #include #include -namespace torch { -namespace executor { +namespace executorch { +namespace runtime { /** * A class that does simple allocation based on a size and returns the pointer @@ -319,7 +319,7 @@ class MemoryAllocator { * * - On success, returns a pointer to the allocated buffer. * - On failure, returns `Error::MemoryAllocationFailed` from the calling - * function, which must be declared to return `torch::executor::Error`. + * function, which must be declared to return `executorch::runtime::Error`. * * Example: * @code @@ -328,7 +328,7 @@ class MemoryAllocator { */ #define ET_ALLOCATE_OR_RETURN_ERROR(memory_allocator__, nbytes__) \ ET_TRY_ALLOCATE_OR(memory_allocator__, nbytes__, { \ - return torch::executor::Error::MemoryAllocationFailed; \ + return ::executorch::runtime::Error::MemoryAllocationFailed; \ }) /** @@ -337,7 +337,7 @@ class MemoryAllocator { * - On success, returns a pointer to the allocated buffer. Note that the memory * will not be initialized. * - On failure, returns `Error::MemoryAllocationFailed` from the calling - * function, which must be declared to return `torch::executor::Error`. + * function, which must be declared to return `executorch::runtime::Error`. * * Example: * @code @@ -346,7 +346,7 @@ class MemoryAllocator { */ #define ET_ALLOCATE_INSTANCE_OR_RETURN_ERROR(memory_allocator__, type__) \ ET_TRY_ALLOCATE_INSTANCE_OR(memory_allocator__, type__, { \ - return torch::executor::Error::MemoryAllocationFailed; \ + return ::executorch::runtime::Error::MemoryAllocationFailed; \ }) /** @@ -355,7 +355,7 @@ class MemoryAllocator { * * - On success, returns a pointer to the allocated buffer. * - On failure, returns `Error::MemoryAllocationFailed` from the calling - * function, which must be declared to return `torch::executor::Error`. + * function, which must be declared to return `executorch::runtime::Error`. * * Example: * @code @@ -365,8 +365,16 @@ class MemoryAllocator { */ #define ET_ALLOCATE_LIST_OR_RETURN_ERROR(memory_allocator__, type__, nelem__) \ ET_TRY_ALLOCATE_LIST_OR(memory_allocator__, type__, nelem__, { \ - return torch::executor::Error::MemoryAllocationFailed; \ + return ::executorch::runtime::Error::MemoryAllocationFailed; \ }) +} // namespace runtime +} // namespace executorch + +namespace torch { +namespace executor { +// TODO(T197294990): Remove these deprecated aliases once all users have moved +// to the new `::executorch` namespaces. +using ::executorch::runtime::MemoryAllocator; } // namespace executor } // namespace torch diff --git a/runtime/core/result.h b/runtime/core/result.h index b1fd6fea46..96c8979528 100644 --- a/runtime/core/result.h +++ b/runtime/core/result.h @@ -19,8 +19,8 @@ #include "executorch/runtime/core/error.h" #include "executorch/runtime/platform/assert.h" -namespace torch { -namespace executor { +namespace executorch { +namespace runtime { /** * Result type wrapping either a value of type T or an error. @@ -198,6 +198,14 @@ T* Result::operator->() { return &value_; } +} // namespace runtime +} // namespace executorch + +namespace torch { +namespace executor { +// TODO(T197294990): Remove these deprecated aliases once all users have moved +// to the new `::executorch` namespaces. +using ::executorch::runtime::Result; } // namespace executor } // namespace torch diff --git a/runtime/core/span.h b/runtime/core/span.h index c6dd76f710..b671f34095 100644 --- a/runtime/core/span.h +++ b/runtime/core/span.h @@ -12,8 +12,8 @@ #include -namespace torch { -namespace executor { +namespace executorch { +namespace runtime { /** * Represent a reference to an array (0 or more elements @@ -93,5 +93,13 @@ class Span final { size_type length_; }; +} // namespace runtime +} // namespace executorch + +namespace torch { +namespace executor { +// TODO(T197294990): Remove these deprecated aliases once all users have moved +// to the new `::executorch` namespaces. +using ::executorch::runtime::Span; } // namespace executor } // namespace torch diff --git a/runtime/core/tag.h b/runtime/core/tag.h index c81e9f58db..7dda80dd92 100644 --- a/runtime/core/tag.h +++ b/runtime/core/tag.h @@ -10,8 +10,9 @@ #include -namespace torch { -namespace executor { +namespace executorch { +namespace runtime { + #define EXECUTORCH_FORALL_TAGS(_) \ _(None) \ _(Tensor) \ @@ -26,11 +27,22 @@ namespace executor { _(ListScalar) \ _(ListOptionalTensor) +/** + * The dynamic type of an EValue. + */ enum class Tag : uint32_t { #define DEFINE_TAG(x) x, EXECUTORCH_FORALL_TAGS(DEFINE_TAG) #undef DEFINE_TAG }; +} // namespace runtime +} // namespace executorch + +namespace torch { +namespace executor { +// TODO(T197294990): Remove these deprecated aliases once all users have moved +// to the new `::executorch` namespaces. +using ::executorch::runtime::Tag; } // namespace executor } // namespace torch diff --git a/runtime/core/tensor_shape_dynamism.h b/runtime/core/tensor_shape_dynamism.h index 7e53473f5f..ee956288d7 100644 --- a/runtime/core/tensor_shape_dynamism.h +++ b/runtime/core/tensor_shape_dynamism.h @@ -10,30 +10,30 @@ #include -namespace torch { -namespace executor { +namespace executorch { +namespace runtime { /** - * Rank can never change in executorch. But shape sometimes can. - * This enum is used to help provide better safety in kernels on what - * tensors are resizable + * The resizing capabilities of a Tensor. * - * WARNING: This abstraction is only temporary. The long term vision is that - * this wont exist in the runtime. Instead the runtime will support a debug mode - * that allows for similar fail early patterns without having to pay the runtime - * cost of directly embedding this abstraction in tensor and performing checks - * against it during resizing. Adding this debug mode is non trivial though so - * for the short term this abstraction helps us move fast. TODO(jakeszwe): - * T134528146 + * The rank of an ExecuTorch Tensors can never change, but shape sometimes can. */ enum class TensorShapeDynamism : uint8_t { - /// Cannot change shape + /// Cannot change shape. STATIC = 0, - /// shape cannot exceed initial capacity + /// Shape cannot exceed initial capacity. DYNAMIC_BOUND = 1, - /// No restriction on shape and capacity + /// No restriction on shape and capacity. DYNAMIC_UNBOUND = 2, }; +} // namespace runtime +} // namespace executorch + +namespace torch { +namespace executor { +// TODO(T197294990): Remove these deprecated aliases once all users have moved +// to the new `::executorch` namespaces. +using ::executorch::runtime::TensorShapeDynamism; } // namespace executor } // namespace torch diff --git a/runtime/executor/method.h b/runtime/executor/method.h index edeaaac665..da97b35617 100644 --- a/runtime/executor/method.h +++ b/runtime/executor/method.h @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -32,8 +33,6 @@ class Program; // Forward declare internal types. class BackendDelegate; struct Chain; -template -class Span; class KernelRuntimeContext; using OpFunction = void (*)(KernelRuntimeContext&, EValue**); /// A list of pointers into the master values table that together compose the