diff --git a/runtime/platform/abort.cpp b/runtime/platform/abort.cpp index b1d62bc5c39..7220404c0a5 100644 --- a/runtime/platform/abort.cpp +++ b/runtime/platform/abort.cpp @@ -9,8 +9,8 @@ #include #include -namespace torch { -namespace executor { +namespace executorch { +namespace runtime { /** * Trigger the ExecuTorch global runtime to immediately exit without cleaning @@ -20,5 +20,5 @@ __ET_NORETURN void runtime_abort() { et_pal_abort(); } -} // namespace executor -} // namespace torch +} // namespace runtime +} // namespace executorch diff --git a/runtime/platform/abort.h b/runtime/platform/abort.h index 72acb07521b..c032c014b12 100644 --- a/runtime/platform/abort.h +++ b/runtime/platform/abort.h @@ -15,8 +15,8 @@ #include -namespace torch { -namespace executor { +namespace executorch { +namespace runtime { /** * Trigger the ExecuTorch global runtime to immediately exit without cleaning @@ -24,5 +24,13 @@ namespace executor { */ __ET_NORETURN void runtime_abort(); +} // 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::runtime_abort; } // namespace executor } // namespace torch diff --git a/runtime/platform/assert.h b/runtime/platform/assert.h index 9222b8ed7fa..5af474ec2a7 100644 --- a/runtime/platform/assert.h +++ b/runtime/platform/assert.h @@ -37,7 +37,7 @@ ({ \ if __ET_UNLIKELY (!(_cond)) { \ ET_ASSERT_MESSAGE_EMIT(" (%s): " _format, #_cond, ##__VA_ARGS__); \ - torch::executor::runtime_abort(); \ + ::executorch::runtime::runtime_abort(); \ } \ }) @@ -51,7 +51,7 @@ ({ \ if __ET_UNLIKELY (!(_cond)) { \ ET_ASSERT_MESSAGE_EMIT(": %s", #_cond); \ - torch::executor::runtime_abort(); \ + ::executorch::runtime::runtime_abort(); \ } \ }) diff --git a/runtime/platform/clock.h b/runtime/platform/clock.h index 608b18d6ca8..36c25d90c47 100644 --- a/runtime/platform/clock.h +++ b/runtime/platform/clock.h @@ -15,8 +15,8 @@ #include -namespace torch { -namespace executor { +namespace executorch { +namespace runtime { /** * Convert an interval from units of system ticks to nanoseconds. @@ -31,5 +31,13 @@ inline uint64_t ticks_to_ns(et_timestamp_t ticks) { return static_cast(ticks) * ratio.numerator / ratio.denominator; } +} // 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::ticks_to_ns; } // namespace executor } // namespace torch diff --git a/runtime/platform/log.cpp b/runtime/platform/log.cpp index 2c618e8fd9d..161a4268db0 100644 --- a/runtime/platform/log.cpp +++ b/runtime/platform/log.cpp @@ -13,8 +13,8 @@ #include #include -namespace torch { -namespace executor { +namespace executorch { +namespace runtime { namespace internal { /** @@ -22,7 +22,7 @@ namespace internal { * * @retval Monotonically non-decreasing timestamp in system ticks. */ -et_timestamp_t getLogTimestamp() { +et_timestamp_t get_log_timestamp() { return et_pal_current_ticks(); } @@ -104,5 +104,5 @@ void vlogf( } } // namespace internal -} // namespace executor -} // namespace torch +} // namespace runtime +} // namespace executorch diff --git a/runtime/platform/log.h b/runtime/platform/log.h index f6b986d6bfd..0642623f817 100644 --- a/runtime/platform/log.h +++ b/runtime/platform/log.h @@ -33,8 +33,8 @@ #define ET_LOG_ENABLED 1 #endif // !defined(ET_LOG_ENABLED) -namespace torch { -namespace executor { +namespace executorch { +namespace runtime { /** * Severity level of a log message. Must be ordered from lowest to highest @@ -79,7 +79,7 @@ namespace internal { * * @retval Monotonically non-decreasing timestamp in system ticks. */ -et_timestamp_t getLogTimestamp(); +et_timestamp_t get_log_timestamp(); /** * Log a string message. @@ -135,6 +135,14 @@ inline void logf( } // namespace internal +} // 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::LogLevel; } // namespace executor } // namespace torch @@ -146,21 +154,23 @@ inline void logf( * @param[in] _level Log severity level. * @param[in] _format Log message format string. */ -#define ET_LOG(_level, _format, ...) \ - ({ \ - const auto _log_level = torch::executor::LogLevel::_level; \ - if (static_cast(_log_level) >= \ - static_cast(torch::executor::LogLevel::ET_MIN_LOG_LEVEL)) { \ - const auto _timestamp = torch::executor::internal::getLogTimestamp(); \ - torch::executor::internal::logf( \ - _log_level, \ - _timestamp, \ - __ET_SHORT_FILENAME, \ - __ET_FUNCTION, \ - __ET_LINE, \ - _format, \ - ##__VA_ARGS__); \ - } \ +#define ET_LOG(_level, _format, ...) \ + ({ \ + const auto _log_level = ::executorch::runtime::LogLevel::_level; \ + if (static_cast(_log_level) >= \ + static_cast( \ + ::executorch::runtime::LogLevel::ET_MIN_LOG_LEVEL)) { \ + const auto _timestamp = \ + ::executorch::runtime::internal::get_log_timestamp(); \ + ::executorch::runtime::internal::logf( \ + _log_level, \ + _timestamp, \ + __ET_SHORT_FILENAME, \ + __ET_FUNCTION, \ + __ET_LINE, \ + _format, \ + ##__VA_ARGS__); \ + } \ }) #else // ET_LOG_ENABLED diff --git a/runtime/platform/platform.h b/runtime/platform/platform.h index 1f1b3b4c173..013e6e89d8f 100644 --- a/runtime/platform/platform.h +++ b/runtime/platform/platform.h @@ -73,9 +73,9 @@ et_timestamp_t et_pal_current_ticks(void) ET_INTERNAL_PLATFORM_WEAKNESS; * numerator and then divide by the denominator: * nanoseconds = ticks * numerator / denominator * - * The utility method torch::executor::ticks_to_ns(et_timestamp_t) can also - * be used to perform the conversion for a given tick count. - * It is defined in torch/executor/runtime/platform/clock.h. + * The utility method executorch::runtime::ticks_to_ns(et_timestamp_t) can also + * be used to perform the conversion for a given tick count. It is defined in + * torch/executor/runtime/platform/clock.h. * * @retval The ratio of nanoseconds to system ticks. */ diff --git a/runtime/platform/profiler.cpp b/runtime/platform/profiler.cpp index ac2e8e187ba..2f514286aa1 100644 --- a/runtime/platform/profiler.cpp +++ b/runtime/platform/profiler.cpp @@ -13,8 +13,8 @@ #include #include -namespace torch { -namespace executor { +namespace executorch { +namespace runtime { namespace { static uint8_t prof_buf[prof_buf_size * MAX_PROFILE_BLOCKS]; @@ -191,5 +191,5 @@ ExecutorchProfiler::~ExecutorchProfiler() { end_profiling(prof_tok); } -} // namespace executor -} // namespace torch +} // namespace runtime +} // namespace executorch diff --git a/runtime/platform/profiler.h b/runtime/platform/profiler.h index 3358ca75df0..07ffd9c349c 100644 --- a/runtime/platform/profiler.h +++ b/runtime/platform/profiler.h @@ -12,8 +12,8 @@ #include #include -namespace torch { -namespace executor { +namespace executorch { +namespace runtime { // Version string used to check for compatibility with post-processing // tool @@ -180,38 +180,71 @@ class ExecutorchProfilerInstructionScope { prof_state_t old_state_; }; +} // 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::begin_profiling; +using ::executorch::runtime::dump_profile_stats; +using ::executorch::runtime::end_profiling; +using ::executorch::runtime::ExecutorchProfiler; +using ::executorch::runtime::ExecutorchProfilerInstructionScope; +using ::executorch::runtime::get_profile_tls_state; +using ::executorch::runtime::mem_prof_event_t; +using ::executorch::runtime::prof_allocator_t; +using ::executorch::runtime::prof_buf_size; +using ::executorch::runtime::prof_event_t; +using ::executorch::runtime::prof_events_offset; +using ::executorch::runtime::prof_header_offset; +using ::executorch::runtime::prof_header_t; +using ::executorch::runtime::prof_mem_alloc_events_offset; +using ::executorch::runtime::prof_mem_alloc_info_offset; +using ::executorch::runtime::prof_result_t; +using ::executorch::runtime::prof_state_t; +using ::executorch::runtime::profiler_init; +using ::executorch::runtime::profiling_create_block; +using ::executorch::runtime::reset_profile_stats; +using ::executorch::runtime::set_profile_tls_state; +using ::executorch::runtime::track_allocation; +using ::executorch::runtime::track_allocator; } // namespace executor } // namespace torch #ifdef PROFILING_ENABLED #define EXECUTORCH_PROFILE_CREATE_BLOCK(name) \ - torch::executor::profiling_create_block(name); + ::executorch::runtime::profiling_create_block(name); // Convenience macros to begin and end profiling. These can be inserted // anywhere as it'll be ensured that for the prod builds these will // essentially be noops. -#define EXECUTORCH_BEGIN_PROF(name) torch::executor::begin_profiling(name); +#define EXECUTORCH_BEGIN_PROF(name) \ + ::executorch::runtime::begin_profiling(name); -#define EXECUTORCH_END_PROF(token_id) torch::executor::end_profiling(token_id); +#define EXECUTORCH_END_PROF(token_id) \ + ::executorch::runtime::end_profiling(token_id); #define EXECUTORCH_SCOPE_PROF(name) \ - torch::executor::ExecutorchProfiler profiler(name); + ::executorch::runtime::ExecutorchProfiler profiler(name); #define EXECUTORCH_PROFILE_INSTRUCTION_SCOPE(chain_idx, instruction_idx) \ - torch::executor::ExecutorchProfilerInstructionScope \ + ::executorch::runtime::ExecutorchProfilerInstructionScope \ __profiler_instruction_scope({chain_idx, instruction_idx}); #define EXECUTORCH_DUMP_PROFILE_RESULTS(prof_result) \ - torch::executor::dump_profile_stats(prof_result); + ::executorch::runtime::dump_profile_stats(prof_result); #define EXECUTORCH_RESET_PROFILE_RESULTS() \ - torch::executor::reset_profile_stats(); + ::executorch::runtime::reset_profile_stats(); -#define EXECUTORCH_TRACK_ALLOCATOR(name) torch::executor::track_allocator(name); +#define EXECUTORCH_TRACK_ALLOCATOR(name) \ + ::executorch::runtime::track_allocator(name); #define EXECUTORCH_TRACK_ALLOCATION(id, size) \ - torch::executor::track_allocation(id, size); + ::executorch::runtime::track_allocation(id, size); #else @@ -231,7 +264,7 @@ class ExecutorchProfilerInstructionScope { }) #define EXECUTORCH_DUMP_PROFILE_RESULTS(prof_result_test) \ - memset(prof_result_test, 0, sizeof(torch::executor::prof_result_t)); + memset(prof_result_test, 0, sizeof(::executorch::runtime::prof_result_t)); #define EXECUTORCH_RESET_PROFILE_RESULTS() \ {} diff --git a/runtime/platform/runtime.cpp b/runtime/platform/runtime.cpp index ffc3a9171d7..2ccb41f21a2 100644 --- a/runtime/platform/runtime.cpp +++ b/runtime/platform/runtime.cpp @@ -11,8 +11,8 @@ #include -namespace torch { -namespace executor { +namespace executorch { +namespace runtime { /** * Initialize the ExecuTorch global runtime. @@ -22,5 +22,5 @@ void runtime_init() { EXECUTORCH_PROFILE_CREATE_BLOCK("default"); } -} // namespace executor -} // namespace torch +} // namespace runtime +} // namespace executorch diff --git a/runtime/platform/runtime.h b/runtime/platform/runtime.h index d260be8d384..375ae7959a8 100644 --- a/runtime/platform/runtime.h +++ b/runtime/platform/runtime.h @@ -15,13 +15,21 @@ #include -namespace torch { -namespace executor { +namespace executorch { +namespace runtime { /** * Initialize the ExecuTorch global runtime. */ void runtime_init(); +} // 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::runtime_init; } // namespace executor } // namespace torch diff --git a/runtime/platform/test/clock_test.cpp b/runtime/platform/test/clock_test.cpp index f319d23022e..396a4a4c85a 100644 --- a/runtime/platform/test/clock_test.cpp +++ b/runtime/platform/test/clock_test.cpp @@ -28,10 +28,10 @@ TEST(ClockTest, ConvertTicksToNsSanity) { InterceptWith iw(spy); spy.tick_ns_multiplier = {3, 2}; - auto ns = torch::executor::ticks_to_ns(10); + auto ns = executorch::runtime::ticks_to_ns(10); ASSERT_EQ(15, ns); // 10 ticks * 3/2 = 15 ns spy.tick_ns_multiplier = {2, 7}; - ns = torch::executor::ticks_to_ns(14); + ns = executorch::runtime::ticks_to_ns(14); ASSERT_EQ(4, ns); // 14 ticks * 2/7 = 4 ns } diff --git a/runtime/platform/test/executor_pal_override_test.cpp b/runtime/platform/test/executor_pal_override_test.cpp index 60a9424e67d..bb9ea2ce589 100644 --- a/runtime/platform/test/executor_pal_override_test.cpp +++ b/runtime/platform/test/executor_pal_override_test.cpp @@ -14,7 +14,7 @@ #include using namespace ::testing; -using torch::executor::LogLevel; +using executorch::runtime::LogLevel; class PalSpy : public PlatformIntercept { public: @@ -75,7 +75,8 @@ class PalSpy : public PlatformIntercept { // Demonstrate what would happen if we didn't intercept the PAL calls. TEST(ExecutorPalOverrideTest, DiesIfNotIntercepted) { ET_EXPECT_DEATH( - torch::executor::runtime_init(), "et_pal_init call was not intercepted"); + executorch::runtime::runtime_init(), + "et_pal_init call was not intercepted"); } TEST(ExecutorPalOverrideTest, InitIsRegistered) { @@ -83,7 +84,7 @@ TEST(ExecutorPalOverrideTest, InitIsRegistered) { InterceptWith iw(spy); EXPECT_EQ(spy.init_call_count, 0); - torch::executor::runtime_init(); + executorch::runtime::runtime_init(); EXPECT_EQ(spy.init_call_count, 1); } diff --git a/runtime/platform/test/logging_test.cpp b/runtime/platform/test/logging_test.cpp index 335d4621ad6..d44cd2d5e71 100644 --- a/runtime/platform/test/logging_test.cpp +++ b/runtime/platform/test/logging_test.cpp @@ -11,8 +11,7 @@ #include #include -namespace torch { -namespace executor { +using namespace executorch::runtime; class LoggingTest : public ::testing::Test { public: @@ -32,6 +31,3 @@ TEST_F(LoggingTest, LogLevels) { TEST_F(LoggingTest, LogFormatting) { ET_LOG(Info, "Sample log with integer: %u", 100); } - -} // namespace executor -} // namespace torch