Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions backends/apple/coreml/runtime/sdk/model_event_logger_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#import <CoreML/CoreML.h>
#import <model_event_logger.h>

namespace torch::executor {
namespace executorch::runtime {
class EventTracer;
}

Expand All @@ -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.
///
Expand All @@ -44,6 +44,6 @@ class ModelEventLoggerImpl final : public ModelEventLogger {
NSDictionary<ETCoreMLModelStructurePath*, NSString*>* op_path_to_debug_symbol_name_map) const noexcept override;

private:
torch::executor::EventTracer* tracer_;
::executorch::runtime::EventTracer* tracer_;
};
} // namespace executorchcoreml
46 changes: 27 additions & 19 deletions extension/evalue_util/print_evalue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
#include <ostream>
#include <sstream>

namespace torch {
namespace executor {
using exec_aten::ScalarType;

namespace executorch {
namespace extension {

namespace {

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<ctype>(tensor.const_data_ptr<ctype>(), tensor.numel()), \
/*print_length=*/false); \
#define PRINT_TENSOR_DATA(ctype, dtype) \
case ScalarType::dtype: \
print_scalar_list( \
os, \
exec_aten::ArrayRef<ctype>( \
tensor.const_data_ptr<ctype>(), tensor.numel()), \
/*print_length=*/false); \
break;

switch (tensor.scalar_type()) {
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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
19 changes: 15 additions & 4 deletions extension/evalue_util/print_evalue.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,18 @@

#include <executorch/runtime/core/evalue.h>

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.
Expand Down Expand Up @@ -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
14 changes: 12 additions & 2 deletions runtime/core/array_ref.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@

#include <executorch/runtime/platform/assert.h>

namespace torch {
namespace executor {
namespace executorch {
namespace runtime {

/**
* Represents a constant reference to an array (0 or more elements
Expand Down Expand Up @@ -236,5 +236,15 @@ bool operator!=(ArrayRef<T> a1, ArrayRef<T> a2) {

using IntArrayRef = ArrayRef<int64_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::ArrayRef;
using ::executorch::runtime::IntArrayRef;
using ::executorch::runtime::makeArrayRef;
} // namespace executor
} // namespace torch
12 changes: 10 additions & 2 deletions runtime/core/data_loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
#include <executorch/runtime/core/result.h>
#include <executorch/runtime/platform/compiler.h>

namespace torch {
namespace executor {
namespace executorch {
namespace runtime {

/**
* Loads from a data source.
Expand Down Expand Up @@ -125,5 +125,13 @@ class DataLoader {
__ET_NODISCARD virtual Result<size_t> 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
33 changes: 21 additions & 12 deletions runtime/core/error.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

#include <executorch/runtime/platform/log.h>

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;
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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__; \
} \
Expand Down
8 changes: 4 additions & 4 deletions runtime/core/evalue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

#include <executorch/runtime/core/evalue.h>

namespace torch {
namespace executor {
namespace executorch {
namespace runtime {
template <>
exec_aten::ArrayRef<exec_aten::optional<exec_aten::Tensor>>
BoxedEvalueList<exec_aten::optional<exec_aten::Tensor>>::get() const {
Expand All @@ -27,5 +27,5 @@ BoxedEvalueList<exec_aten::optional<exec_aten::Tensor>>::get() const {
return exec_aten::ArrayRef<exec_aten::optional<exec_aten::Tensor>>{
unwrapped_vals_, wrapped_vals_.size()};
}
} // namespace executor
} // namespace torch
} // namespace runtime
} // namespace executorch
35 changes: 27 additions & 8 deletions runtime/core/evalue.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@
#include <executorch/runtime/core/tag.h>
#include <executorch/runtime/platform/assert.h>

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 <typename T>
Expand All @@ -38,6 +40,8 @@ struct evalue_to_ref_overload_return<exec_aten::Tensor> {
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
Expand Down Expand Up @@ -371,9 +375,9 @@ struct EValue {
template <typename T>
T to() &&;
template <typename T>
typename evalue_to_const_ref_overload_return<T>::type to() const&;
typename internal::evalue_to_const_ref_overload_return<T>::type to() const&;
template <typename T>
typename evalue_to_ref_overload_return<T>::type to() &;
typename internal::evalue_to_ref_overload_return<T>::type to() &;

/**
* Converts the EValue to an optional object that can represent both T and
Expand Down Expand Up @@ -441,13 +445,19 @@ struct EValue {
return static_cast<T>(std::move(*this).method_name()); \
} \
template <> \
inline evalue_to_const_ref_overload_return<T>::type EValue::to<T>() const& { \
typedef evalue_to_const_ref_overload_return<T>::type return_type; \
inline ::executorch::runtime::internal::evalue_to_const_ref_overload_return< \
T>::type \
EValue::to<T>() const& { \
typedef ::executorch::runtime::internal:: \
evalue_to_const_ref_overload_return<T>::type return_type; \
return static_cast<return_type>(this->method_name()); \
} \
template <> \
inline evalue_to_ref_overload_return<T>::type EValue::to<T>()& { \
typedef evalue_to_ref_overload_return<T>::type return_type; \
inline ::executorch::runtime::internal::evalue_to_ref_overload_return< \
T>::type \
EValue::to<T>()& { \
typedef ::executorch::runtime::internal::evalue_to_ref_overload_return< \
T>::type return_type; \
return static_cast<return_type>(this->method_name()); \
}

Expand Down Expand Up @@ -507,5 +517,14 @@ exec_aten::ArrayRef<T> BoxedEvalueList<T>::get() const {
return exec_aten::ArrayRef<T>{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
Loading