Skip to content

[executorch] Migrate runtime/platform tests to new namespace #4606

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Aug 15, 2024
8 changes: 4 additions & 4 deletions runtime/platform/abort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
#include <executorch/runtime/platform/abort.h>
#include <executorch/runtime/platform/platform.h>

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

/**
* Trigger the ExecuTorch global runtime to immediately exit without cleaning
Expand All @@ -20,5 +20,5 @@ __ET_NORETURN void runtime_abort() {
et_pal_abort();
}

} // namespace executor
} // namespace torch
} // namespace runtime
} // namespace executorch
12 changes: 10 additions & 2 deletions runtime/platform/abort.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,22 @@

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

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

/**
* Trigger the ExecuTorch global runtime to immediately exit without cleaning
* up, and set an abnormal exit status (platform-defined).
*/
__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
4 changes: 2 additions & 2 deletions runtime/platform/assert.h
Original file line number Diff line number Diff line change
Expand Up @@ -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(); \
} \
})

Expand All @@ -51,7 +51,7 @@
({ \
if __ET_UNLIKELY (!(_cond)) { \
ET_ASSERT_MESSAGE_EMIT(": %s", #_cond); \
torch::executor::runtime_abort(); \
::executorch::runtime::runtime_abort(); \
} \
})

Expand Down
12 changes: 10 additions & 2 deletions runtime/platform/clock.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@

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

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

/**
* Convert an interval from units of system ticks to nanoseconds.
Expand All @@ -31,5 +31,13 @@ inline uint64_t ticks_to_ns(et_timestamp_t ticks) {
return static_cast<uint64_t>(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
10 changes: 5 additions & 5 deletions runtime/platform/log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@
#include <executorch/runtime/platform/compiler.h>
#include <executorch/runtime/platform/platform.h>

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

/**
* Get the current timestamp to construct a log event.
*
* @retval Monotonically non-decreasing timestamp in system ticks.
*/
et_timestamp_t getLogTimestamp() {
et_timestamp_t get_log_timestamp() {
return et_pal_current_ticks();
}

Expand Down Expand Up @@ -104,5 +104,5 @@ void vlogf(
}

} // namespace internal
} // namespace executor
} // namespace torch
} // namespace runtime
} // namespace executorch
46 changes: 28 additions & 18 deletions runtime/platform/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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

Expand All @@ -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<uint32_t>(_log_level) >= \
static_cast<uint32_t>(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<uint32_t>(_log_level) >= \
static_cast<uint32_t>( \
::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
Expand Down
6 changes: 3 additions & 3 deletions runtime/platform/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
8 changes: 4 additions & 4 deletions runtime/platform/profiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
#include <executorch/runtime/platform/profiler.h>
#include <inttypes.h>

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

namespace {
static uint8_t prof_buf[prof_buf_size * MAX_PROFILE_BLOCKS];
Expand Down Expand Up @@ -191,5 +191,5 @@ ExecutorchProfiler::~ExecutorchProfiler() {
end_profiling(prof_tok);
}

} // namespace executor
} // namespace torch
} // namespace runtime
} // namespace executorch
57 changes: 45 additions & 12 deletions runtime/platform/profiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
#include <stdlib.h>
#include <string.h>

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

// Version string used to check for compatibility with post-processing
// tool
Expand Down Expand Up @@ -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

Expand All @@ -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() \
{}
Expand Down
8 changes: 4 additions & 4 deletions runtime/platform/runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

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

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

/**
* Initialize the ExecuTorch global runtime.
Expand All @@ -22,5 +22,5 @@ void runtime_init() {
EXECUTORCH_PROFILE_CREATE_BLOCK("default");
}

} // namespace executor
} // namespace torch
} // namespace runtime
} // namespace executorch
12 changes: 10 additions & 2 deletions runtime/platform/runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,21 @@

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

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
4 changes: 2 additions & 2 deletions runtime/platform/test/clock_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Loading
Loading