Skip to content

introduce DelegateDebugIntId #9832

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 1 commit into from
Apr 2, 2025
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
26 changes: 14 additions & 12 deletions devtools/etdump/etdump_flatcc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ using ::executorch::runtime::ArrayRef;
using ::executorch::runtime::ChainID;
using ::executorch::runtime::DebugHandle;
using ::executorch::runtime::DelegateDebugIdType;
using ::executorch::runtime::DelegateDebugIntId;
using ::executorch::runtime::EValue;
using ::executorch::runtime::EventTracerEntry;
using ::executorch::runtime::kUnsetDelegateDebugIntId;
using ::executorch::runtime::LoggedEValueType;
using ::executorch::runtime::Result;
using ::executorch::runtime::Span;
Expand Down Expand Up @@ -223,9 +225,9 @@ EventTracerEntry ETDumpGen::start_profiling(
// EventTracerEntry struct is updated.
EventTracerEntry ETDumpGen::start_profiling_delegate(
const char* name,
DebugHandle delegate_debug_index) {
DelegateDebugIntId delegate_debug_index) {
ET_CHECK_MSG(
(name == nullptr) ^ (delegate_debug_index == -1),
(name == nullptr) ^ (delegate_debug_index == kUnsetDelegateDebugIntId),
"Only name or delegate_debug_index can be valid. Check DelegateMappingBuilder documentation for more details.");
check_ready_to_add_events();
EventTracerEntry prof_entry;
Expand All @@ -234,7 +236,7 @@ EventTracerEntry ETDumpGen::start_profiling_delegate(
prof_entry.delegate_event_id_type = delegate_event_id_type;
prof_entry.chain_id = chain_id_;
prof_entry.debug_handle = debug_handle_;
prof_entry.event_id = delegate_debug_index == static_cast<unsigned int>(-1)
prof_entry.event_id = delegate_debug_index == kUnsetDelegateDebugIntId
? create_string_entry(name)
: delegate_debug_index;
prof_entry.start_time = et_pal_current_ticks();
Expand Down Expand Up @@ -276,13 +278,13 @@ void ETDumpGen::end_profiling_delegate(

void ETDumpGen::log_profiling_delegate(
const char* name,
DebugHandle delegate_debug_index,
DelegateDebugIntId delegate_debug_index,
et_timestamp_t start_time,
et_timestamp_t end_time,
const void* metadata,
size_t metadata_len) {
ET_CHECK_MSG(
(name == nullptr) ^ (delegate_debug_index == -1),
(name == nullptr) ^ (delegate_debug_index == kUnsetDelegateDebugIntId),
"Only name or delegate_debug_index can be valid. Check DelegateMappingBuilder documentation for more details.");
check_ready_to_add_events();
int64_t string_id = name != nullptr ? create_string_entry(name) : -1;
Expand All @@ -308,7 +310,7 @@ void ETDumpGen::log_profiling_delegate(

Result<bool> ETDumpGen::log_intermediate_output_delegate(
const char* name,
DebugHandle delegate_debug_index,
DelegateDebugIntId delegate_debug_index,
const Tensor& output) {
Result<bool> result = log_intermediate_output_delegate_helper(
name, delegate_debug_index, output);
Expand All @@ -317,7 +319,7 @@ Result<bool> ETDumpGen::log_intermediate_output_delegate(

Result<bool> ETDumpGen::log_intermediate_output_delegate(
const char* name,
DebugHandle delegate_debug_index,
DelegateDebugIntId delegate_debug_index,
const ArrayRef<Tensor> output) {
log_intermediate_output_delegate_helper(name, delegate_debug_index, output);
Result<bool> result = log_intermediate_output_delegate_helper(
Expand All @@ -327,7 +329,7 @@ Result<bool> ETDumpGen::log_intermediate_output_delegate(

Result<bool> ETDumpGen::log_intermediate_output_delegate(
const char* name,
DebugHandle delegate_debug_index,
DelegateDebugIntId delegate_debug_index,
const int& output) {
log_intermediate_output_delegate_helper(name, delegate_debug_index, output);
Result<bool> result = log_intermediate_output_delegate_helper(
Expand All @@ -337,7 +339,7 @@ Result<bool> ETDumpGen::log_intermediate_output_delegate(

Result<bool> ETDumpGen::log_intermediate_output_delegate(
const char* name,
DebugHandle delegate_debug_index,
DelegateDebugIntId delegate_debug_index,
const bool& output) {
log_intermediate_output_delegate_helper(name, delegate_debug_index, output);
Result<bool> result = log_intermediate_output_delegate_helper(
Expand All @@ -347,7 +349,7 @@ Result<bool> ETDumpGen::log_intermediate_output_delegate(

Result<bool> ETDumpGen::log_intermediate_output_delegate(
const char* name,
DebugHandle delegate_debug_index,
DelegateDebugIntId delegate_debug_index,
const double& output) {
log_intermediate_output_delegate_helper(name, delegate_debug_index, output);
Result<bool> result = log_intermediate_output_delegate_helper(
Expand All @@ -358,10 +360,10 @@ Result<bool> ETDumpGen::log_intermediate_output_delegate(
template <typename T>
Result<bool> ETDumpGen::log_intermediate_output_delegate_helper(
const char* name,
DebugHandle delegate_debug_index,
DelegateDebugIntId delegate_debug_index,
const T& output) {
ET_CHECK_OR_RETURN_ERROR(
(name == nullptr) ^ (delegate_debug_index == -1),
(name == nullptr) ^ (delegate_debug_index == kUnsetDelegateDebugIntId),
InvalidArgument,
"Only name or delegate_debug_index can be valid. Check DelegateMappingBuilder documentation for more details.");

Expand Down
17 changes: 9 additions & 8 deletions devtools/etdump/etdump_flatcc.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ struct flatcc_builder;
namespace executorch {
namespace etdump {

using ::executorch::runtime::DelegateDebugIntId;
using ::executorch::runtime::Result;

namespace internal {
Expand Down Expand Up @@ -84,14 +85,14 @@ class ETDumpGen : public ::executorch::runtime::EventTracer {
::executorch::runtime::EventTracerEntry prof_entry) override;
virtual ::executorch::runtime::EventTracerEntry start_profiling_delegate(
const char* name,
::executorch::runtime::DebugHandle delegate_debug_index) override;
DelegateDebugIntId delegate_debug_index) override;
virtual void end_profiling_delegate(
::executorch::runtime::EventTracerEntry prof_entry,
const void* metadata,
size_t metadata_len) override;
virtual void log_profiling_delegate(
const char* name,
::executorch::runtime::DebugHandle delegate_debug_index,
DelegateDebugIntId delegate_debug_index,
et_timestamp_t start_time,
et_timestamp_t end_time,
const void* metadata,
Expand All @@ -111,15 +112,15 @@ class ETDumpGen : public ::executorch::runtime::EventTracer {
*/
virtual Result<bool> log_intermediate_output_delegate(
const char* name,
::executorch::runtime::DebugHandle delegate_debug_index,
DelegateDebugIntId delegate_debug_index,
const executorch::aten::Tensor& output) override;

/**
* Log an intermediate tensor array output from a delegate.
*/
virtual Result<bool> log_intermediate_output_delegate(
const char* name,
::executorch::runtime::DebugHandle delegate_debug_index,
DelegateDebugIntId delegate_debug_index,
const ::executorch::runtime::ArrayRef<executorch::aten::Tensor> output)
override;

Expand All @@ -128,23 +129,23 @@ class ETDumpGen : public ::executorch::runtime::EventTracer {
*/
virtual Result<bool> log_intermediate_output_delegate(
const char* name,
::executorch::runtime::DebugHandle delegate_debug_index,
DelegateDebugIntId delegate_debug_index,
const int& output) override;

/**
* Log an intermediate bool output from a delegate.
*/
virtual Result<bool> log_intermediate_output_delegate(
const char* name,
::executorch::runtime::DebugHandle delegate_debug_index,
DelegateDebugIntId delegate_debug_index,
const bool& output) override;

/**
* Log an intermediate double output from a delegate.
*/
virtual Result<bool> log_intermediate_output_delegate(
const char* name,
::executorch::runtime::DebugHandle delegate_debug_index,
DelegateDebugIntId delegate_debug_index,
const double& output) override;
void set_debug_buffer(::executorch::runtime::Span<uint8_t> buffer);
void set_data_sink(DataSinkBase* data_sink);
Expand Down Expand Up @@ -173,7 +174,7 @@ class ETDumpGen : public ::executorch::runtime::EventTracer {
template <typename T>
Result<bool> log_intermediate_output_delegate_helper(
const char* name,
::executorch::runtime::DebugHandle delegate_debug_index,
DelegateDebugIntId delegate_debug_index,
const T& output);

long write_tensor_or_raise_error(executorch::aten::Tensor tensor);
Expand Down
42 changes: 14 additions & 28 deletions devtools/etdump/tests/etdump_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ using ::executorch::runtime::DelegateDebugIdType;
using ::executorch::runtime::Error;
using ::executorch::runtime::EValue;
using ::executorch::runtime::EventTracerEntry;
using ::executorch::runtime::kUnsetDelegateDebugIntId;
using ::executorch::runtime::LoggedEValueType;
using ::executorch::runtime::Span;
using ::executorch::runtime::Tag;
Expand Down Expand Up @@ -70,9 +71,7 @@ class ProfilerETDumpTest : public ::testing::Test {
TensorFactory<ScalarType::Float>& tf) {
ET_EXPECT_DEATH(
gen->log_intermediate_output_delegate(
"test_event_tensor",
static_cast<torch::executor::DebugHandle>(-1),
tf.ones({3, 2})),
"test_event_tensor", kUnsetDelegateDebugIntId, tf.ones({3, 2})),
"Must set data sink before writing tensor-like data");
}

Expand Down Expand Up @@ -582,7 +581,7 @@ TEST_F(ProfilerETDumpTest, LogDelegateIntermediateOutput) {
Result<bool> log_tensor_list_result =
etdump_gen[i]->log_intermediate_output_delegate(
nullptr,
static_cast<torch::executor::DebugHandle>(-1),
kUnsetDelegateDebugIntId,
ArrayRef<Tensor>(tensors.data(), tensors.size()));

Result<bool> log_int_result =
Expand All @@ -599,7 +598,7 @@ TEST_F(ProfilerETDumpTest, LogDelegateIntermediateOutput) {

Result<bool> log_bool_result =
etdump_gen[i]->log_intermediate_output_delegate(
nullptr, static_cast<torch::executor::DebugHandle>(-1), 29.82);
nullptr, kUnsetDelegateDebugIntId, 29.82);

ASSERT_EQ(log_tensor_result.error(), Error::InvalidArgument);
ASSERT_EQ(log_tensor_list_result.error(), Error::InvalidArgument);
Expand All @@ -611,33 +610,25 @@ TEST_F(ProfilerETDumpTest, LogDelegateIntermediateOutput) {

// Log a tensor
etdump_gen[i]->log_intermediate_output_delegate(
"test_event_tensor",
static_cast<torch::executor::DebugHandle>(-1),
tf.ones({3, 2}));
"test_event_tensor", kUnsetDelegateDebugIntId, tf.ones({3, 2}));

// Log a tensor list
etdump_gen[i]->log_intermediate_output_delegate(
"test_event_tensorlist",
static_cast<torch::executor::DebugHandle>(-1),
kUnsetDelegateDebugIntId,
ArrayRef<Tensor>(tensors.data(), tensors.size()));

// Log an int
etdump_gen[i]->log_intermediate_output_delegate(
"test_event_tensorlist",
static_cast<torch::executor::DebugHandle>(-1),
10);
"test_event_tensorlist", kUnsetDelegateDebugIntId, 10);

// Log a double
etdump_gen[i]->log_intermediate_output_delegate(
"test_event_tensorlist",
static_cast<torch::executor::DebugHandle>(-1),
20.75);
"test_event_tensorlist", kUnsetDelegateDebugIntId, 20.75);

// Log a bool
etdump_gen[i]->log_intermediate_output_delegate(
"test_event_tensorlist",
static_cast<torch::executor::DebugHandle>(-1),
true);
"test_event_tensorlist", kUnsetDelegateDebugIntId, true);

ETDumpResult result = etdump_gen[i]->get_etdump_data();
ASSERT_TRUE(result.buf != nullptr);
Expand Down Expand Up @@ -762,23 +753,18 @@ TEST_F(ProfilerETDumpTest, LogDelegateEvents) {
etdump_gen[i]->log_profiling_delegate(
nullptr, 278, 1, 2, metadata, strlen(metadata) + 1);
EventTracerEntry entry = etdump_gen[i]->start_profiling_delegate(
"test_event", static_cast<torch::executor::DebugHandle>(-1));
"test_event", kUnsetDelegateDebugIntId);
EXPECT_NE(entry.delegate_event_id_type, DelegateDebugIdType::kNone);
// Event 2
etdump_gen[i]->end_profiling_delegate(
entry, metadata, strlen(metadata) + 1);
// Event 3
etdump_gen[i]->log_profiling_delegate(
"test_event",
static_cast<torch::executor::DebugHandle>(-1),
1,
2,
nullptr,
0);
"test_event", kUnsetDelegateDebugIntId, 1, 2, nullptr, 0);
// Event 4
etdump_gen[i]->log_profiling_delegate(
"test_event",
static_cast<torch::executor::DebugHandle>(-1),
kUnsetDelegateDebugIntId,
1,
2,
metadata,
Expand Down Expand Up @@ -856,11 +842,11 @@ TEST_F(ProfilerETDumpTest, LogDelegateEvents) {
std::string(delegate_debug_id_name, strlen(delegate_debug_id_name)),
"test_event");
// Event 2 used a string delegate debug identifier, so delegate_debug_id_int
// should be -1.
// should be kUnsetDelegateDebugIntId.
EXPECT_EQ(
etdump_ProfileEvent_delegate_debug_id_int(
etdump_Event_profile_event(event)),
-1);
kUnsetDelegateDebugIntId);
if (!etdump_gen[i]->is_static_etdump()) {
free(result.buf);
}
Expand Down
Loading
Loading