Skip to content

Commit 2b9c4b2

Browse files
authored
[executorch] Migrate runtime/platform to new namespace
Differential Revision: D60418073 Pull Request resolved: #4605
1 parent ba2ff63 commit 2b9c4b2

File tree

11 files changed

+125
-58
lines changed

11 files changed

+125
-58
lines changed

runtime/platform/abort.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
#include <executorch/runtime/platform/abort.h>
1010
#include <executorch/runtime/platform/platform.h>
1111

12-
namespace torch {
13-
namespace executor {
12+
namespace executorch {
13+
namespace runtime {
1414

1515
/**
1616
* Trigger the ExecuTorch global runtime to immediately exit without cleaning
@@ -20,5 +20,5 @@ __ET_NORETURN void runtime_abort() {
2020
et_pal_abort();
2121
}
2222

23-
} // namespace executor
24-
} // namespace torch
23+
} // namespace runtime
24+
} // namespace executorch

runtime/platform/abort.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,22 @@
1515

1616
#include <executorch/runtime/platform/compiler.h>
1717

18-
namespace torch {
19-
namespace executor {
18+
namespace executorch {
19+
namespace runtime {
2020

2121
/**
2222
* Trigger the ExecuTorch global runtime to immediately exit without cleaning
2323
* up, and set an abnormal exit status (platform-defined).
2424
*/
2525
__ET_NORETURN void runtime_abort();
2626

27+
} // namespace runtime
28+
} // namespace executorch
29+
30+
namespace torch {
31+
namespace executor {
32+
// TODO(T197294990): Remove these deprecated aliases once all users have moved
33+
// to the new `::executorch` namespaces.
34+
using ::executorch::runtime::runtime_abort;
2735
} // namespace executor
2836
} // namespace torch

runtime/platform/assert.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
({ \
3838
if __ET_UNLIKELY (!(_cond)) { \
3939
ET_ASSERT_MESSAGE_EMIT(" (%s): " _format, #_cond, ##__VA_ARGS__); \
40-
torch::executor::runtime_abort(); \
40+
::executorch::runtime::runtime_abort(); \
4141
} \
4242
})
4343

@@ -51,7 +51,7 @@
5151
({ \
5252
if __ET_UNLIKELY (!(_cond)) { \
5353
ET_ASSERT_MESSAGE_EMIT(": %s", #_cond); \
54-
torch::executor::runtime_abort(); \
54+
::executorch::runtime::runtime_abort(); \
5555
} \
5656
})
5757

runtime/platform/clock.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515

1616
#include <executorch/runtime/platform/platform.h>
1717

18-
namespace torch {
19-
namespace executor {
18+
namespace executorch {
19+
namespace runtime {
2020

2121
/**
2222
* Convert an interval from units of system ticks to nanoseconds.
@@ -31,5 +31,13 @@ inline uint64_t ticks_to_ns(et_timestamp_t ticks) {
3131
return static_cast<uint64_t>(ticks) * ratio.numerator / ratio.denominator;
3232
}
3333

34+
} // namespace runtime
35+
} // namespace executorch
36+
37+
namespace torch {
38+
namespace executor {
39+
// TODO(T197294990): Remove these deprecated aliases once all users have moved
40+
// to the new `::executorch` namespaces.
41+
using ::executorch::runtime::ticks_to_ns;
3442
} // namespace executor
3543
} // namespace torch

runtime/platform/log.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@
1313
#include <executorch/runtime/platform/compiler.h>
1414
#include <executorch/runtime/platform/platform.h>
1515

16-
namespace torch {
17-
namespace executor {
16+
namespace executorch {
17+
namespace runtime {
1818
namespace internal {
1919

2020
/**
2121
* Get the current timestamp to construct a log event.
2222
*
2323
* @retval Monotonically non-decreasing timestamp in system ticks.
2424
*/
25-
et_timestamp_t getLogTimestamp() {
25+
et_timestamp_t get_log_timestamp() {
2626
return et_pal_current_ticks();
2727
}
2828

@@ -104,5 +104,5 @@ void vlogf(
104104
}
105105

106106
} // namespace internal
107-
} // namespace executor
108-
} // namespace torch
107+
} // namespace runtime
108+
} // namespace executorch

runtime/platform/log.h

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
#define ET_LOG_ENABLED 1
3434
#endif // !defined(ET_LOG_ENABLED)
3535

36-
namespace torch {
37-
namespace executor {
36+
namespace executorch {
37+
namespace runtime {
3838

3939
/**
4040
* Severity level of a log message. Must be ordered from lowest to highest
@@ -79,7 +79,7 @@ namespace internal {
7979
*
8080
* @retval Monotonically non-decreasing timestamp in system ticks.
8181
*/
82-
et_timestamp_t getLogTimestamp();
82+
et_timestamp_t get_log_timestamp();
8383

8484
/**
8585
* Log a string message.
@@ -135,6 +135,14 @@ inline void logf(
135135

136136
} // namespace internal
137137

138+
} // namespace runtime
139+
} // namespace executorch
140+
141+
namespace torch {
142+
namespace executor {
143+
// TODO(T197294990): Remove these deprecated aliases once all users have moved
144+
// to the new `::executorch` namespaces.
145+
using ::executorch::runtime::LogLevel;
138146
} // namespace executor
139147
} // namespace torch
140148

@@ -146,21 +154,23 @@ inline void logf(
146154
* @param[in] _level Log severity level.
147155
* @param[in] _format Log message format string.
148156
*/
149-
#define ET_LOG(_level, _format, ...) \
150-
({ \
151-
const auto _log_level = torch::executor::LogLevel::_level; \
152-
if (static_cast<uint32_t>(_log_level) >= \
153-
static_cast<uint32_t>(torch::executor::LogLevel::ET_MIN_LOG_LEVEL)) { \
154-
const auto _timestamp = torch::executor::internal::getLogTimestamp(); \
155-
torch::executor::internal::logf( \
156-
_log_level, \
157-
_timestamp, \
158-
__ET_SHORT_FILENAME, \
159-
__ET_FUNCTION, \
160-
__ET_LINE, \
161-
_format, \
162-
##__VA_ARGS__); \
163-
} \
157+
#define ET_LOG(_level, _format, ...) \
158+
({ \
159+
const auto _log_level = ::executorch::runtime::LogLevel::_level; \
160+
if (static_cast<uint32_t>(_log_level) >= \
161+
static_cast<uint32_t>( \
162+
::executorch::runtime::LogLevel::ET_MIN_LOG_LEVEL)) { \
163+
const auto _timestamp = \
164+
::executorch::runtime::internal::get_log_timestamp(); \
165+
::executorch::runtime::internal::logf( \
166+
_log_level, \
167+
_timestamp, \
168+
__ET_SHORT_FILENAME, \
169+
__ET_FUNCTION, \
170+
__ET_LINE, \
171+
_format, \
172+
##__VA_ARGS__); \
173+
} \
164174
})
165175

166176
#else // ET_LOG_ENABLED

runtime/platform/platform.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ et_timestamp_t et_pal_current_ticks(void) ET_INTERNAL_PLATFORM_WEAKNESS;
7373
* numerator and then divide by the denominator:
7474
* nanoseconds = ticks * numerator / denominator
7575
*
76-
* The utility method torch::executor::ticks_to_ns(et_timestamp_t) can also
77-
* be used to perform the conversion for a given tick count.
78-
* It is defined in torch/executor/runtime/platform/clock.h.
76+
* The utility method executorch::runtime::ticks_to_ns(et_timestamp_t) can also
77+
* be used to perform the conversion for a given tick count. It is defined in
78+
* torch/executor/runtime/platform/clock.h.
7979
*
8080
* @retval The ratio of nanoseconds to system ticks.
8181
*/

runtime/platform/profiler.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
#include <executorch/runtime/platform/profiler.h>
1414
#include <inttypes.h>
1515

16-
namespace torch {
17-
namespace executor {
16+
namespace executorch {
17+
namespace runtime {
1818

1919
namespace {
2020
static uint8_t prof_buf[prof_buf_size * MAX_PROFILE_BLOCKS];
@@ -191,5 +191,5 @@ ExecutorchProfiler::~ExecutorchProfiler() {
191191
end_profiling(prof_tok);
192192
}
193193

194-
} // namespace executor
195-
} // namespace torch
194+
} // namespace runtime
195+
} // namespace executorch

runtime/platform/profiler.h

Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
#include <stdlib.h>
1313
#include <string.h>
1414

15-
namespace torch {
16-
namespace executor {
15+
namespace executorch {
16+
namespace runtime {
1717

1818
// Version string used to check for compatibility with post-processing
1919
// tool
@@ -180,38 +180,71 @@ class ExecutorchProfilerInstructionScope {
180180
prof_state_t old_state_;
181181
};
182182

183+
} // namespace runtime
184+
} // namespace executorch
185+
186+
namespace torch {
187+
namespace executor {
188+
// TODO(T197294990): Remove these deprecated aliases once all users have moved
189+
// to the new `::executorch` namespaces.
190+
using ::executorch::runtime::begin_profiling;
191+
using ::executorch::runtime::dump_profile_stats;
192+
using ::executorch::runtime::end_profiling;
193+
using ::executorch::runtime::ExecutorchProfiler;
194+
using ::executorch::runtime::ExecutorchProfilerInstructionScope;
195+
using ::executorch::runtime::get_profile_tls_state;
196+
using ::executorch::runtime::mem_prof_event_t;
197+
using ::executorch::runtime::prof_allocator_t;
198+
using ::executorch::runtime::prof_buf_size;
199+
using ::executorch::runtime::prof_event_t;
200+
using ::executorch::runtime::prof_events_offset;
201+
using ::executorch::runtime::prof_header_offset;
202+
using ::executorch::runtime::prof_header_t;
203+
using ::executorch::runtime::prof_mem_alloc_events_offset;
204+
using ::executorch::runtime::prof_mem_alloc_info_offset;
205+
using ::executorch::runtime::prof_result_t;
206+
using ::executorch::runtime::prof_state_t;
207+
using ::executorch::runtime::profiler_init;
208+
using ::executorch::runtime::profiling_create_block;
209+
using ::executorch::runtime::reset_profile_stats;
210+
using ::executorch::runtime::set_profile_tls_state;
211+
using ::executorch::runtime::track_allocation;
212+
using ::executorch::runtime::track_allocator;
183213
} // namespace executor
184214
} // namespace torch
185215

186216
#ifdef PROFILING_ENABLED
187217

188218
#define EXECUTORCH_PROFILE_CREATE_BLOCK(name) \
189-
torch::executor::profiling_create_block(name);
219+
::executorch::runtime::profiling_create_block(name);
190220

191221
// Convenience macros to begin and end profiling. These can be inserted
192222
// anywhere as it'll be ensured that for the prod builds these will
193223
// essentially be noops.
194-
#define EXECUTORCH_BEGIN_PROF(name) torch::executor::begin_profiling(name);
224+
#define EXECUTORCH_BEGIN_PROF(name) \
225+
::executorch::runtime::begin_profiling(name);
195226

196-
#define EXECUTORCH_END_PROF(token_id) torch::executor::end_profiling(token_id);
227+
#define EXECUTORCH_END_PROF(token_id) \
228+
::executorch::runtime::end_profiling(token_id);
197229

198230
#define EXECUTORCH_SCOPE_PROF(name) \
199-
torch::executor::ExecutorchProfiler profiler(name);
231+
::executorch::runtime::ExecutorchProfiler profiler(name);
200232

201233
#define EXECUTORCH_PROFILE_INSTRUCTION_SCOPE(chain_idx, instruction_idx) \
202-
torch::executor::ExecutorchProfilerInstructionScope \
234+
::executorch::runtime::ExecutorchProfilerInstructionScope \
203235
__profiler_instruction_scope({chain_idx, instruction_idx});
204236

205237
#define EXECUTORCH_DUMP_PROFILE_RESULTS(prof_result) \
206-
torch::executor::dump_profile_stats(prof_result);
238+
::executorch::runtime::dump_profile_stats(prof_result);
207239

208240
#define EXECUTORCH_RESET_PROFILE_RESULTS() \
209-
torch::executor::reset_profile_stats();
241+
::executorch::runtime::reset_profile_stats();
210242

211-
#define EXECUTORCH_TRACK_ALLOCATOR(name) torch::executor::track_allocator(name);
243+
#define EXECUTORCH_TRACK_ALLOCATOR(name) \
244+
::executorch::runtime::track_allocator(name);
212245

213246
#define EXECUTORCH_TRACK_ALLOCATION(id, size) \
214-
torch::executor::track_allocation(id, size);
247+
::executorch::runtime::track_allocation(id, size);
215248

216249
#else
217250

@@ -231,7 +264,7 @@ class ExecutorchProfilerInstructionScope {
231264
})
232265

233266
#define EXECUTORCH_DUMP_PROFILE_RESULTS(prof_result_test) \
234-
memset(prof_result_test, 0, sizeof(torch::executor::prof_result_t));
267+
memset(prof_result_test, 0, sizeof(::executorch::runtime::prof_result_t));
235268

236269
#define EXECUTORCH_RESET_PROFILE_RESULTS() \
237270
{}

runtime/platform/runtime.cpp

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

1212
#include <executorch/runtime/platform/platform.h>
1313

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

1717
/**
1818
* Initialize the ExecuTorch global runtime.
@@ -22,5 +22,5 @@ void runtime_init() {
2222
EXECUTORCH_PROFILE_CREATE_BLOCK("default");
2323
}
2424

25-
} // namespace executor
26-
} // namespace torch
25+
} // namespace runtime
26+
} // namespace executorch

0 commit comments

Comments
 (0)