Skip to content

Commit ae299cf

Browse files
authored
[executorch] Migrate runtime/core to new namespace
Differential Revision: D60428951 Pull Request resolved: #4607
1 parent 2dcf0f3 commit ae299cf

19 files changed

+269
-99
lines changed

backends/apple/coreml/runtime/sdk/model_event_logger_impl.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#import <CoreML/CoreML.h>
1111
#import <model_event_logger.h>
1212

13-
namespace torch::executor {
13+
namespace executorch::runtime {
1414
class EventTracer;
1515
}
1616

@@ -21,7 +21,7 @@ namespace executorchcoreml {
2121
class ModelEventLoggerImpl final : public ModelEventLogger {
2222
public:
2323
/// Construct a `ModelEventLoggerImpl` from the `EventTracer`.
24-
explicit ModelEventLoggerImpl(torch::executor::EventTracer* tracer) : tracer_(tracer) { }
24+
explicit ModelEventLoggerImpl(::executorch::runtime::EventTracer* tracer) : tracer_(tracer) { }
2525

2626
/// Logs profiling infos.
2727
///
@@ -44,6 +44,6 @@ class ModelEventLoggerImpl final : public ModelEventLogger {
4444
NSDictionary<ETCoreMLModelStructurePath*, NSString*>* op_path_to_debug_symbol_name_map) const noexcept override;
4545

4646
private:
47-
torch::executor::EventTracer* tracer_;
47+
::executorch::runtime::EventTracer* tracer_;
4848
};
4949
} // namespace executorchcoreml

extension/evalue_util/print_evalue.cpp

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@
1616
#include <ostream>
1717
#include <sstream>
1818

19-
namespace torch {
20-
namespace executor {
19+
using exec_aten::ScalarType;
20+
21+
namespace executorch {
22+
namespace extension {
2123

2224
namespace {
2325

@@ -102,7 +104,7 @@ void print_scalar_list(
102104
// We've printed a full line, so wrap and begin a new one.
103105
os << "\n ";
104106
}
105-
os << EValue(exec_aten::Scalar(list[i]));
107+
os << executorch::runtime::EValue(exec_aten::Scalar(list[i]));
106108
if (wrapping || i < list.size() - 1) {
107109
// No trailing comma when not wrapping. Always a trailing comma when
108110
// 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) {
149151
//
150152
// TODO(T159700776): Format multidimensional data like numpy/PyTorch does.
151153
// https://github.com/pytorch/pytorch/blob/main/torch/_tensor_str.py
152-
#define PRINT_TENSOR_DATA(ctype, dtype) \
153-
case ScalarType::dtype: \
154-
print_scalar_list( \
155-
os, \
156-
ArrayRef<ctype>(tensor.const_data_ptr<ctype>(), tensor.numel()), \
157-
/*print_length=*/false); \
154+
#define PRINT_TENSOR_DATA(ctype, dtype) \
155+
case ScalarType::dtype: \
156+
print_scalar_list( \
157+
os, \
158+
exec_aten::ArrayRef<ctype>( \
159+
tensor.const_data_ptr<ctype>(), tensor.numel()), \
160+
/*print_length=*/false); \
158161
break;
159162

160163
switch (tensor.scalar_type()) {
@@ -211,7 +214,20 @@ void print_list_optional_tensor(
211214

212215
} // namespace
213216

217+
void evalue_edge_items::set_edge_items(std::ostream& os, long edge_items) {
218+
os.iword(get_edge_items_xalloc()) = edge_items;
219+
}
220+
221+
} // namespace extension
222+
} // namespace executorch
223+
224+
namespace executorch {
225+
namespace runtime {
226+
227+
// This needs to live in the same namespace as EValue.
214228
std::ostream& operator<<(std::ostream& os, const EValue& value) {
229+
using namespace executorch::extension;
230+
215231
switch (value.tag) {
216232
case Tag::None:
217233
os << "None";
@@ -258,13 +274,5 @@ std::ostream& operator<<(std::ostream& os, const EValue& value) {
258274
return os;
259275
}
260276

261-
namespace util {
262-
263-
void evalue_edge_items::set_edge_items(std::ostream& os, long edge_items) {
264-
os.iword(get_edge_items_xalloc()) = edge_items;
265-
}
266-
267-
} // namespace util
268-
269-
} // namespace executor
270-
} // namespace torch
277+
} // namespace runtime
278+
} // namespace executorch

extension/evalue_util/print_evalue.h

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,18 @@
1212

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

15-
namespace torch {
16-
namespace executor {
17-
15+
namespace executorch {
16+
namespace runtime {
1817
/**
1918
* Prints an Evalue to a stream.
2019
*/
2120
std::ostream& operator<<(std::ostream& os, const EValue& value);
2221
// Note that this must be declared in the same namespace as EValue.
22+
} // namespace runtime
23+
} // namespace executorch
2324

24-
namespace util {
25+
namespace executorch {
26+
namespace extension {
2527

2628
/**
2729
* Sets the number of "edge items" when printing EValue lists to a stream.
@@ -67,6 +69,15 @@ class evalue_edge_items final {
6769
const long edge_items_;
6870
};
6971

72+
} // namespace extension
73+
} // namespace executorch
74+
75+
namespace torch {
76+
namespace executor {
77+
namespace util {
78+
// TODO(T197294990): Remove these deprecated aliases once all users have moved
79+
// to the new `::executorch` namespaces.
80+
using ::executorch::extension::evalue_edge_items;
7081
} // namespace util
7182
} // namespace executor
7283
} // namespace torch

runtime/core/array_ref.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131

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

34-
namespace torch {
35-
namespace executor {
34+
namespace executorch {
35+
namespace runtime {
3636

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

237237
using IntArrayRef = ArrayRef<int64_t>;
238238

239+
} // namespace runtime
240+
} // namespace executorch
241+
242+
namespace torch {
243+
namespace executor {
244+
// TODO(T197294990): Remove these deprecated aliases once all users have moved
245+
// to the new `::executorch` namespaces.
246+
using ::executorch::runtime::ArrayRef;
247+
using ::executorch::runtime::IntArrayRef;
248+
using ::executorch::runtime::makeArrayRef;
239249
} // namespace executor
240250
} // namespace torch

runtime/core/data_loader.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
#include <executorch/runtime/core/result.h>
1515
#include <executorch/runtime/platform/compiler.h>
1616

17-
namespace torch {
18-
namespace executor {
17+
namespace executorch {
18+
namespace runtime {
1919

2020
/**
2121
* Loads from a data source.
@@ -125,5 +125,13 @@ class DataLoader {
125125
__ET_NODISCARD virtual Result<size_t> size() const = 0;
126126
};
127127

128+
} // namespace runtime
129+
} // namespace executorch
130+
131+
namespace torch {
132+
namespace executor {
133+
// TODO(T197294990): Remove these deprecated aliases once all users have moved
134+
// to the new `::executorch` namespaces.
135+
using ::executorch::runtime::DataLoader;
128136
} // namespace executor
129137
} // namespace torch

runtime/core/error.h

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717

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

20-
namespace torch {
21-
namespace executor {
20+
namespace executorch {
21+
namespace runtime {
2222

2323
// Alias error code integral type to minimal platform width (32-bits for now).
2424
typedef uint32_t error_code_t;
@@ -92,13 +92,22 @@ enum class Error : error_code_t {
9292

9393
};
9494

95+
} // namespace runtime
96+
} // namespace executorch
97+
98+
namespace torch {
99+
namespace executor {
100+
// TODO(T197294990): Remove these deprecated aliases once all users have moved
101+
// to the new `::executorch` namespaces.
102+
using ::executorch::runtime::Error;
103+
using ::executorch::runtime::error_code_t;
95104
} // namespace executor
96105
} // namespace torch
97106

98107
/**
99108
* If cond__ is false, log the specified message and return the specified Error
100109
* from the current function, which must be of return type
101-
* torch::executor::Error.
110+
* executorch::runtime::Error.
102111
*
103112
* @param[in] cond__ The condition to be checked, asserted as true.
104113
* @param[in] error__ Error enum value to return without the `Error::` prefix,
@@ -110,14 +119,14 @@ enum class Error : error_code_t {
110119
{ \
111120
if (!(cond__)) { \
112121
ET_LOG(Error, message__, ##__VA_ARGS__); \
113-
return ::torch::executor::Error::error__; \
122+
return ::executorch::runtime::Error::error__; \
114123
} \
115124
}
116125

117126
/**
118127
* If error__ is not Error::Ok, optionally log a message and return the error
119128
* from the current function, which must be of return type
120-
* torch::executor::Error.
129+
* executorch::runtime::Error.
121130
*
122131
* @param[in] error__ Error enum value asserted to be Error::Ok.
123132
* @param[in] ... Optional format string for the log error message and its
@@ -161,19 +170,19 @@ enum class Error : error_code_t {
161170
ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_##N
162171

163172
// Internal only: Use ET_CHECK_OK_OR_RETURN_ERROR() instead.
164-
#define ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_1(error__) \
165-
do { \
166-
const auto et_error__ = (error__); \
167-
if (et_error__ != ::torch::executor::Error::Ok) { \
168-
return et_error__; \
169-
} \
173+
#define ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_1(error__) \
174+
do { \
175+
const auto et_error__ = (error__); \
176+
if (et_error__ != ::executorch::runtime::Error::Ok) { \
177+
return et_error__; \
178+
} \
170179
} while (0)
171180

172181
// Internal only: Use ET_CHECK_OK_OR_RETURN_ERROR() instead.
173182
#define ET_INTERNAL_CHECK_OK_OR_RETURN_ERROR_2(error__, message__, ...) \
174183
do { \
175184
const auto et_error__ = (error__); \
176-
if (et_error__ != ::torch::executor::Error::Ok) { \
185+
if (et_error__ != ::executorch::runtime::Error::Ok) { \
177186
ET_LOG(Error, message__, ##__VA_ARGS__); \
178187
return et_error__; \
179188
} \

runtime/core/evalue.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

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

11-
namespace torch {
12-
namespace executor {
11+
namespace executorch {
12+
namespace runtime {
1313
template <>
1414
exec_aten::ArrayRef<exec_aten::optional<exec_aten::Tensor>>
1515
BoxedEvalueList<exec_aten::optional<exec_aten::Tensor>>::get() const {
@@ -27,5 +27,5 @@ BoxedEvalueList<exec_aten::optional<exec_aten::Tensor>>::get() const {
2727
return exec_aten::ArrayRef<exec_aten::optional<exec_aten::Tensor>>{
2828
unwrapped_vals_, wrapped_vals_.size()};
2929
}
30-
} // namespace executor
31-
} // namespace torch
30+
} // namespace runtime
31+
} // namespace executorch

runtime/core/evalue.h

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@
1111
#include <executorch/runtime/core/tag.h>
1212
#include <executorch/runtime/platform/assert.h>
1313

14-
namespace torch {
15-
namespace executor {
14+
namespace executorch {
15+
namespace runtime {
1616

1717
struct EValue;
1818

19+
namespace internal {
20+
1921
// Tensor gets proper reference treatment because its expensive to copy in aten
2022
// mode, all other types are just copied.
2123
template <typename T>
@@ -38,6 +40,8 @@ struct evalue_to_ref_overload_return<exec_aten::Tensor> {
3840
using type = exec_aten::Tensor&;
3941
};
4042

43+
} // namespace internal
44+
4145
/*
4246
* Helper class used to correlate EValues in the executor table, with the
4347
* unwrapped list of the proper type. Because values in the runtime's values
@@ -371,9 +375,9 @@ struct EValue {
371375
template <typename T>
372376
T to() &&;
373377
template <typename T>
374-
typename evalue_to_const_ref_overload_return<T>::type to() const&;
378+
typename internal::evalue_to_const_ref_overload_return<T>::type to() const&;
375379
template <typename T>
376-
typename evalue_to_ref_overload_return<T>::type to() &;
380+
typename internal::evalue_to_ref_overload_return<T>::type to() &;
377381

378382
/**
379383
* Converts the EValue to an optional object that can represent both T and
@@ -441,13 +445,19 @@ struct EValue {
441445
return static_cast<T>(std::move(*this).method_name()); \
442446
} \
443447
template <> \
444-
inline evalue_to_const_ref_overload_return<T>::type EValue::to<T>() const& { \
445-
typedef evalue_to_const_ref_overload_return<T>::type return_type; \
448+
inline ::executorch::runtime::internal::evalue_to_const_ref_overload_return< \
449+
T>::type \
450+
EValue::to<T>() const& { \
451+
typedef ::executorch::runtime::internal:: \
452+
evalue_to_const_ref_overload_return<T>::type return_type; \
446453
return static_cast<return_type>(this->method_name()); \
447454
} \
448455
template <> \
449-
inline evalue_to_ref_overload_return<T>::type EValue::to<T>()& { \
450-
typedef evalue_to_ref_overload_return<T>::type return_type; \
456+
inline ::executorch::runtime::internal::evalue_to_ref_overload_return< \
457+
T>::type \
458+
EValue::to<T>()& { \
459+
typedef ::executorch::runtime::internal::evalue_to_ref_overload_return< \
460+
T>::type return_type; \
451461
return static_cast<return_type>(this->method_name()); \
452462
}
453463

@@ -507,5 +517,14 @@ exec_aten::ArrayRef<T> BoxedEvalueList<T>::get() const {
507517
return exec_aten::ArrayRef<T>{unwrapped_vals_, wrapped_vals_.size()};
508518
}
509519

520+
} // namespace runtime
521+
} // namespace executorch
522+
523+
namespace torch {
524+
namespace executor {
525+
// TODO(T197294990): Remove these deprecated aliases once all users have moved
526+
// to the new `::executorch` namespaces.
527+
using ::executorch::runtime::BoxedEvalueList;
528+
using ::executorch::runtime::EValue;
510529
} // namespace executor
511530
} // namespace torch

0 commit comments

Comments
 (0)